On Tue, 3 Jun 2008 22:13:25 -0700 (PDT)
Josh <[EMAIL PROTECTED]> wrote:

> I want to add elements of the fraction field of QQ[x,y] to a set,
> i.e., make sure there are no repeats.  However, set.add()ing an
> element that is equal to a previous element sometimes puts another
> copy of the element in.  Witness the following behavior:
> 
> > R = PolynomialRing(QQ,'x,y')
> > K = R.fraction_field()
> > x,y = gens(K)
> > (2*x)/(2*y) == x/y
> 
> True
> 
> > x/y in set([(2*x)/(2*y)])
> 
> False
> 
> > x/y in [(2*x)/(2*y)]
> 
> True
> 
> Why should these last two behaviors differ?  

Python's set uses the hash value of the elements for comparison, and
list just uses the cmp operator. Since we have mathematically
equivalent elements hashing to two different values, this fails.

The fraction field code in Sage is needs a makeover. I will probably do
some of that during (or maybe before) the developer days in Seattle
between June 13 and 20.

> And how do I get the
> second behavior out of a set without converting to a list and back?
> For example, is there some way to force elements of K into a canonical
> form?

You can construct the fraction field of ZZ[x,y]. The arithmetic is
slower than QQ[x,y] polynomials, but at least it works.

sage: K = ZZ[x,y].fraction_field()
sage: x,y = K.gens()
sage: (2*x)/(2*y)
x/y
sage: x/y in set([(2*x)/(2*y)])
True

Cheers,

Burcin

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to