On Wednesday, 16 April 2025 at 04:55:39 UTC-7 Peter Mueller wrote:
The following code
K.<x, y> = QQ[]
K = K.fraction_field()
print(len({x/y, (2*x)/(2*y)}))
gives the answer 2, even though the two elements of course are the same! Is
this a bug or a feature for a reason I cannot guess? Same on the SageMath
Cell.
I don't think it's a feature but it might be that you're hitting general
code that can't do much more than it does. In that case we should probably
have a specialization that deals with that particular situation.
In your case, we can just force the denominator to be monic. It can make
for less nice representations because it might cause fractional
coefficients in the numerator and denominator:
f.numerator()/(c:=f.denominator().leading_coefficient())/(f.denominator()/c)
For this standardization, we need that there's a monomial ordering (which
would generally be met) and that the leading coefficient is a unit (true
over a field). It's the last one that is generally problematic. In
ZZ["x,y"].fraction_field(), you'd already need a different approach and
over domains with more complicated unit groups and/or without unique
factorization, normalizing the denominator is going to be very expensive.
Note that it doesn't affect the ability to compute in the field of
fractions: equality testing is still easy. It's just the normal form that's
hard (and which is necessary to get to a well-defined hash).
Funniliy enough:
K.<x, y> = ZZ[]
K = K.fraction_field()
print(len({x/y, (2*x)/(2*y)}))
so it seems that the extra work was already done in that case. And that's
also the representation in which you'll avoid denominators in the
denominator! So probably it's better to switch to that representation. If
you need polynomials you can use
QQ['x,y'](f)
when the denominator has degree 0.
--
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 view this discussion visit
https://groups.google.com/d/msgid/sage-support/d1ba72f6-09ab-4791-9435-5456a1e38854n%40googlegroups.com.