Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A hack would be to factor e and get the unit and the factors. For instance:

sage: R.<x> = ZZ[]
sage: F = R.fraction_field()
sage: e = (1/2)/(x+1)
sage: ef = e.factor()    # e factorized, as an instance of the class
sage: ef.parent()
<class 'sage.structure.factorization.Factorization'>
sage: ef.unit()
1/2
sage: ef.__dict__
{'_Factorization__cr': False,
 '_Factorization__unit': 1/2,
 '_Factorization__universe': Univariate Polynomial Ring in x over Rational Field,
 '_Factorization__x': [(x + 1, -1)]

Just a hack. An other one would be to get the lcm of the denominators of the coefficients appearing in the fraction. Explicitly. Here is an awful example, taken so to test if things work in a real mess.

sage: v = ( 1/6 * x^2 + 1/7 *x - 1/199 ) / (x+1/17) / 6 / (1/11*x+3/29)
sage: v
(1/6*x^2 + 1/7*x - 1/199)/(6/11*x^2 + 3540/5423*x + 18/493)
sage: vn = v.numerator()
sage: vd = v.denominator()
sage: vn, vd
(1/6*x^2 + 1/7*x - 1/199, 6/11*x^2 + 3540/5423*x + 18/493)
sage: vn.coefficients(), vd.coefficients()
([-1/199, 1/7, 1/6], [18/493, 3540/5423, 6/11])
sage: vnlcm = lcm( [ c.denominator() for c in vn.coefficients() ] )
sage: vdlcm = lcm( [ c.denominator() for c in vd.coefficients() ] )
sage: vnlcm, vdlcm
(8358, 5423)
sage: F( (vn*vnlcm) / (vd*vdlcm) )
(1393*x^2 + 1194*x - 42)/(2958*x^2 + 3540*x + 198)
sage: vdlcm / vnlcm * _ == v
True