Expression to polynomial

31 views
Skip to first unread message

Néstor

unread,
Jun 12, 2015, 5:17:37 AM6/12/15
to sage-s...@googlegroups.com
Hello,

I've got a rational expression in sage and I would like to convert it to a polynomial with coefficients in some fraction field.

More precisely, I've got something like this:

a , x = var( 'a , x' ) ;
P = x/a ;

and I would like to see it like a polynomial in the polynomial ring in the variable x with coefficients on the fraction field Q(a) of rational expressions in the variable a:

C.<a> = PolynomialRing(QQ) ;
B = FractionField(C) ;
A.<x> = PolynomialRing(B) ;

But when I try

P.polynomial(A)

I get the following error
TypeError: unable to coerce since the denominator is not 1


Could somebody help me?  Thanks in advance!
Néstor

luisfe

unread,
Jun 12, 2015, 6:07:09 AM6/12/15
to sage-s...@googlegroups.com
try

    sage: A(P)
    1/a*x
    sage: _.parent()
    Univariate Polynomial Ring in x over Fraction Field of Univariate Polynomial Ring in a over Rational Field

Sometimes, when Sage is not smart enough to perform a conversion between complicated rings, I where able to perform the conversion with the ugly hack:

    sage: A(str(P))

 
Reply all
Reply to author
Forward
0 new messages