First time here? Check out the FAQ!

Ask Your Question
1

Getting range from things which aren't integers yet, but will be

asked 13 years ago

kcrisman gravatar image

Consider the following:

sage: f(n)=ceil(sqrt(2*n)-1/2)
sage: g = lambda n: ceil(sqrt(2*n)-1/2)

Then we get

sage: [0..g(3)]
[0, 1, 2]
sage: [0..f(3)]
   1068     else:
-> 1069         icount = int(math.ceil(float(count) - endpoint_tolerance))
TypeError: unable to simplify to float approximation

And I understand why this is. But it's still annoying. We should be able to avoid lambda functions if at all possible.

Similarly, trying workarounds involving numerical evaluation like

sage: f(n)=ceil(RR(sqrt(2*n)-1/2))

cause problems about numerically evaluating symbolic expressions - rightly, though it would be nice to have a way to hold that evaluation.

So my two questions are, in both of these cases, is there a reasonable way to fix Sage so that these things work?

An accepted answer will include a link to an existing or newly created Trac ticket that has a concrete idea.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 13 years ago

Kelvin Li gravatar image

updated 13 years ago

Calling simplify is a hack:

sage: f(x) = ceil(sqrt(2*x) - 1/2)
sage: [0 .. f(3).simplify()]
[0, 1, 2]
Preview: (hide)
link

Comments

Nice for this case! Of course, in general (say if there was something other than square root) that might not work; I'm looking for a general solution. We shouldn't need this.

kcrisman gravatar imagekcrisman ( 13 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 513 times

Last updated: May 23 '11