On 25 Apr., 08:10, Robert Bradshaw <rober...@math.washington.edu>
wrote:
> On Apr 23, 2010, at 7:07 PM, Nathan O'Treally wrote:
> > The Tutorial (http://www.sagemath.org/doc/tutorial/
> > programming.html#loops-functions-control-statements-and-comparisons)
> > gives another example:
> > sage: GF(5)(1) == QQ(1); QQ(1) == GF(5)(1)
> > False
> > False
> > sage: GF(5)(1) == ZZ(1); ZZ(1) == GF(5)(1)
> > True
> > True
> > sage: ZZ(1) == QQ(1)
> > True
> > # This means a==b is False and a==c is True though c==b *is* True:
> > sage: a=GF(5)(1)
> > sage: b=QQ(1)
> > sage: c=ZZ(1)
> > # (scroll away these definitions to surprise somebody else)
> > sage: a==b , b==c , c==a
> > (False, True, True)
> > sage: b==a , c==b , a==c
> > (False, True, True)
> > # HELL! 8/
> > (The tutorial warns in contrast to Sage it *is* consistently defined
> > in Magma.)
>
>  > a := GF(5)!1;
>  > b := GF(7)!1;
>  > c := 1;
>
>  > a eq c;
> true
>  > b eq c;
> true
>  > a eq b;
>
>  >> a eq b;
>       ^
> Runtime error in 'eq': Arguments are not compatible
> Argument types given: FldFinElt, FldFinElt
>
> In Python, the convention is that == and != never raise an error, so  
> False is returned if coercion fails (the two domains are incompatible).

sage: a=GF(5)(1)
sage: b=QQ(1)
sage: a==b
False
sage: a!=b   # This then should return False because the coercion
failed
True             # Ouch!

Otherwise one could test with (a==b or a!=b)==False if the coercion
failed (like NaN==NaN is always false).

-Leif

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

Reply via email to