On Feb 1, 2008 12:52 AM, Nils Bruin <[EMAIL PROTECTED]> wrote:
>
> On Jan 31, 6:50 pm, "William Stein" <[EMAIL PROTECTED]> wrote:
>
> [...]
> > Also, in your posted patch you emphasize that forall and exists
> > are *NOT* suitable for use in an if, etc.  I would have written that
> > to use them thus you have to use the ugly forall(...)[0], and it is
> > much nicer to use all(...) and any(...).
> [...]
>
> sage: L=[1..10^6]
> sage: L[10^6-3]=-1
> sage: %timeit any(a<0 for a in L)
> 10 loops, best of 3: 2.44 s per loop
> sage: %timeit exists(L, lambda a: a<0)
> 10 loops, best of 3: 2.84 s per loop
> sage: g=lambda a: a<0
> sage: %timeit any(g(a) for a in L)
> 10 loops, best of 3: 1.14 s per loop
>
> If you don't need the witness, you should not be using "exists". It's
> a bit weird the lambda clause actually speeds things up in "any".

It's because here 0 is created a million times (because the preparser
turns this into a<Integer(0)):

    sage: any(a<0 for a in L)

and here 0 is created only once:

    sage: g=lambda a: a<0
    sage: any(g(a) for a in L)

And yes, we do plan to sometime make it so the preparser intelligently factors
out constants, but haven't done this yet.

William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to