ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 22 May 2011 09:11:39 -0500coerce pari type or string to rational function workaround?http://ask.sagemath.org/question/8114/coerce-pari-type-or-string-to-rational-function-workaround/I am getting some rational functions from pari/gp and want to work with them in Sage. I can't figure out how to do the coercion. I tried coercing them directly, and even via a string.
Here's what I've tried:
Make a pari type rational function:
sage: test = gp.simplify((x+y)/y)
This is the field I want to put it in:
sage: R.<x,y> = PolynomialRing(QQ)
sage: S = R.fraction_field()
coercing directly doesn't work:
sage: S(test)
Traceback (most recent call last):
...
TypeError: unable to convert 1/y*x + 1 to a rational
So I tried making a string out of it:
sage: str(test)
'1/y*x + 1'
Of course, sage would accept that string if I typed it in directly:
sage: S(1/y*x + 1)
(x + y)/y
But it won't accept it as a string:
sage: S(str(test))
Traceback (most recent call last):
...
TypeError: no canonical coercion from Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field to Rational Field
sage: S('1/y*x + 1')
Traceback (most recent call last):
...
TypeError: no canonical coercion from Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field to Rational Field
All of this works fine for polynomials (just remove the denominator of y from the example above). I think these are bugs and I will report them as such, if you agree. But in the meantime, does anyone have a workaround I can use?Kate StangeSun, 22 May 2011 09:11:39 -0500http://ask.sagemath.org/question/8114/