Hi Marco,

- making the "in" keyword treat infinity as a special case.
>>
>
> Either Sage's RR has an infinity element or it does not. And in this case 
> the coercion framework correctly recognizes this and gives the output 
> accordingly.
>

I think it is more subtle than that.  The current RR does have _an_ 
infinity element, and this should of course map to Infinity in the 
InfinityRing under the canonical coercion map.  What is not so clear to me 
is why the +infinity element of RR should compare _equal_ to Infinity (i.e. 
whether the fact that RR(oo) == oo yields True, as William noted, is a good 
thing).

Actually, I'm starting to think that once you allow RR(oo) as a valid 
construction, you should indeed let the coercion framework evaluate RR(oo) 
== oo to True, *but* that the user should be able to construct a variant of 
RR that forbids RR(oo).  I'm thinking of something like the following:

sage: R = RealField(prec=53, exceptions=True)
sage: R(oo)
TypeError: unable to coerce +Infinity (<class 
'sage.rings.infinity.PlusInfinity'>) to a real number
sage: RR(oo)
+infinity
sage: oo in R
False
sage: oo in RR
True
sage: R(NaN)
TypeError: unable to coerce <class 'sage.symbolic.constants.NotANumber'> to 
a real number
sage: RR(NaN)
NaN
sage: 1/R(0.)
ZeroDivisionError
sage: 1/RR(0.)
+infinity

If you are to introduce special cases, then some things are much worse:
>
> sage: Zmod(5)(3) in ZZ
> True
>

Hmm.  This would almost be an argument for more restrictive equality and 
containment testing.  I just discovered this:

sage: Mod(2,6)==Mod(4,8)
True

On the other hand, the following extremely similar example gives the 
opposite (and in my opinion more correct) result:

sage: Mod(1,3)==Mod(2,4)
False

Unfortunately it is hard to think of a simple rule that gives the desired 
behaviour in all of the following cases:

sage: Mod(1, 3) == ZZ(1)
True  # current behaviour; certainly OK
sage: Mod(1, 3) == QQ(1)
False  # current behaviour; probably OK, but True wouldn't be completely 
wrong
sage: Mod(1, 3) == Mod(1, 4)
False  # current behaviour; certainly OK
sage: Mod(1,3) == Mod(1, 6)
True  # current behaviour; probably OK, but False wouldn't be completely 
wrong
sage: Mod(2, 6)==Mod(4, 8)
False  # currently yields True
sage: 2/1 in ZZ
True
sage: Mod(3, 5) in ZZ
False  # currently yields True
sage: Mod(1,3) in Zmod(6)
False  # currently yields True
sage: Mod(2,4) in Zmod(6)
False  # currently yields True

Peter

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to