On 29 April 2014 15:16, Volker Braun <[email protected]> wrote:
> 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.


That is a *very* unsatisfactory explanation for anyone actually
wanting to use Sage to do mathematics.

In this case the elements are rational functions in one variable over
a field which could easily (mathematically) be put into canonical
form, by dividing numerator and denominator by their gcd and then
scaling so that the denominator is monic.  But I suppose that there
are efficiency reasons not to do this after every arithmetic
operations.  There is a reduce() operation which is called
automatically and does the first of these, but not the second.  That
function could easily be amended to do the second step, which would
make it more useful.  Shall I open a ticket for that?

John

>
>
>
> 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.

-- 
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.

Reply via email to