Ask Your Question

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

asked 2011-05-21 16:03:27 -0500

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2011-05-21 17:53:39 -0500

Kelvin Li gravatar image

updated 2011-05-23 08:47:40 -0500

Calling simplify is a hack:

sage: f(x) = ceil(sqrt(2*x) - 1/2)
sage: [0 .. f(3).simplify()]
[0, 1, 2]
edit flag offensive delete link more


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 ( 2011-05-23 02:14:50 -0500 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2011-05-21 16:03:27 -0500

Seen: 246 times

Last updated: May 23 '11