The timing differences between "any" and "exists" still bother me a
bit, so I tried plain sage -ipython:
sage: def exists(S, P):
...: for x in S:
...: if P(x): return True, x
...:
...: return False, None
sage: L=range(10^6)
sage: L[10^6-3]=-1
sage: g=lambda a: a<0
sage
On 01/02/2008, John Cremona <[EMAIL PROTECTED]> wrote:
> any() ans all() certainly deserve to be better known. In the patch I
> submitted yesterday including the file
> sage/rings/number_field/number_field_ideal.py there's a whole
> function, doctest and all, called
> def is_pari_zero_vector(z):
any() ans all() certainly deserve to be better known. In the patch I
submitted yesterday including the file
sage/rings/number_field/number_field_ideal.py there's a whole
function, doctest and all, called
def is_pari_zero_vector(z):
which can be replaced entirely by "not all(z)".
John
On 01/02/2
I forgot one case. This is weird. Exists seems *faster* than any. That
should never be happening!
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.47 s per loop
sage: %timeit exists(L, lambda a: a<0)
10 loops, best of 3: 2.83 s per loop
sage: g=lambda
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 t
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 a
On Jan 31, 2008 9:08 PM, Nils Bruin <[EMAIL PROTECTED]> wrote:
>
> OK, I changed the patch on http://trac.sagemath.org/sage_trac/ticket/1987
> so that "forall" and "exists" do not change functionality, but have a
> pointer to "all" and "any" in their docstrings. Incidentally, it is
> *crucial* to
OK, I changed the patch on http://trac.sagemath.org/sage_trac/ticket/1987
so that "forall" and "exists" do not change functionality, but have a
pointer to "all" and "any" in their docstrings. Incidentally, it is
*crucial* to *not* use square brackets inside any and all. If you do,
you destroy any
I agree with Nils. I just started using forall and exists and found
it stupid to have to append [0] to get the boolean value. And given
their existence I never looked further to find the python any() and
all() functions.
On 30/01/2008, Nils Bruin <[EMAIL PROTECTED]> wrote:
>
> On Jan 30, 2:49
On Jan 30, 2:49 pm, "Mike Hansen" <[EMAIL PROTECTED]> wrote:
[...]
> name. Also, there are functions in Python which have similar
> functionality.
>
> sage: l = [1,2,3]
> sage: any([i == 2 for i in l])
> True
> sage: all([i == 2 for i in l])
> False
That's instructive. In that case, forall and ex
Hmm... witness is very unintuitive; maybe we can think up a better
name. Also, there are functions in Python which have similar
functionality.
sage: l = [1,2,3]
sage: any([i == 2 for i in l])
True
sage: all([i == 2 for i in l])
False
--Mike
On Jan 30, 2008 2:45 PM, Nils Bruin <[EMAIL PROTECTED
11 matches
Mail list logo