1 | initial version |
Rescaling numerator and denominator by the lcm of the denominators of the coefficients is the right thing to do:
sage: S=ZZ['x'].fraction_field()
sage: D=lcm([u.denominator() for u in e.numerator().coefficients() + e.denominator().coefficients()])
sage: S(D*e.numerator())/S(D*e.denominator())
1/(2*x + 2)
However, there is something much worse here:
sage: R=QQ['x'].fraction_field()
sage: a=(1/2)/(R.0+1)
sage: b=(1)/(2*R.0+2)
sage: a,b
(1/2/(x + 1), 1/(2*x + 2))
sage: a==b
True
sage: hash(a) == hash(b)
False
There's a report about this, though: https://trac.sagemath.org/ticket/15297