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

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 close merge delete

Sort by » oldest newest most voted

Calling simplify is a hack:

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

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.