s and t are not the same expression, so they have different hashes. We
break Python by letting them compare equal. Hence the outcome of putting
them into sets is undefined. In CPython: if the hash collides, you get one
element. If the hash does not collide, you get two elements.
On Tuesday, April 29, 2014 2:59:20 PM UTC+1, John Cremona wrote:
>
> If this is not a bug then I don't know what a Set is in Sage! I
> define two objects which are equal as tested by == but when I put them
> into a Set I get two elements, not one:
>
> sage: K.<z> = CyclotomicField(3)
> sage: Ku.<u> = FractionField(PolynomialRing(K,'u'))
> sage: a = 27*u^2+81*u+243
> sage: b = 27*u-81
> sage: c = u^2 + 3*u + 9
> sage: d = u-3
> sage: s = a/b
> sage: t = c/d
> sage: s==t
> True
> sage: Set([s,t])
> {(27*u^2 + 81*u + 243)/(27*u - 81), (u^2 + 3*u + 9)/(u - 3)}
>
> In my application I have 12 such expressions (and some of them do
> involve the algebraic number z, but not all, as this example shows)
> and I wanted a quick way to see how many distinct ones there are. For
> simpler objects, Set() has done this. Obviously I can also manually
> test them for equality pairwise, but I would prefer not to.
>
> John
>
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.