On Jan 22, 2009, at 10:25 PM, kcrisman wrote:

> In 3.3.alpha0, the following works fine:
>
> sage: list= [[i,j] for i in [-3..3] for j in [-3..3]]
> sage: [coords for coords in list if (coords[0])^2+(coords[1])^2-1==0]
> [[-1, 0], [0, -1], [0, 1], [1, 0]]
>
> The following doesn't terminate in a reasonable amount of time:
>
> sage: f(x,y)=x^2+y^2-1
> sage: list= [[i,j] for i in [-3..3] for j in [-3..3]]
> sage: [coords for coords in list if f(coords[0],coords[1])==0]
>
> In the notebook I can't even interrupt it; I have to restart the
> worksheet, so maybe there's some horrible recursion going on, but ...
> I mean, there are only 49 points to check ... right?  What am I doing
> wrong in using a function this way?

You could try letting f be a multi-variate polynomial rather than a  
symbolic maxima expression.

sage: R.<x,y> = ZZ[]
sage: f = x^2+y^2-1
sage: list= [[i,j] for i in [-3..3] for j in [-3..3]]
sage: time [coords for coords in list if f(coords[0],coords[1])==0]
CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s
Wall time: 0.01 s
[[-1, 0], [0, -1], [0, 1], [1, 0]]

Searching an even larger range:

sage: list= [[i,j] for i in [-30..30] for j in [-30..30]]
sage: time [coords for coords in list if f(coords[0],coords[1])==0]
CPU times: user 0.69 s, sys: 0.01 s, total: 0.70 s
Wall time: 0.74 s
[[-1, 0], [0, -1], [0, 1], [1, 0]]

- Robert


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to