On Feb 19, 12:29 pm, ObsessiveMathsFreak
<[email protected]> wrote:
> Sage doesn't seem to like these
>
> f(x,y)=pi*x^10*y+3*x
> B=f(x,y).polynomial(SR)

This doesn't work for a couple of reasons:
 * f(x,y) already lies in SR, so this could just return a constant
polynomial in, say, 'z'.
 * sage doesn't have enough info to represent pi exactly outside of SR

The easy way is probably to combine some .coefficients(x)
and .coefficients(y) calls on the SR object. If you absolutely want to
go the other route, you can use sage's coercion framework:

 - first get the thing as a polynomial over Q. You'll need to replace
pi with a generic transcendental element in order to dissuade sage
from trying to be too smart:

sage: var('PI')
sage: F=f(x,y).subs(pi==PI)
sage: FQ=F.polynomial(QQ)
sage: FQ
PI*x^10*y + 3*x

now if you want to consider this as a bivariate polynomial over Q(PI),
you'll have to build the right parent for that:

sage: K=PolynomialRing(QQ,'PI').fraction_field()
sage: K
Fraction Field of Univariate Polynomial Ring in PI over Rational Field
sage: R=PolynomialRing(K,['x','y'])
sage: R
Multivariate Polynomial Ring in x, y over Fraction Field of Univariate
Polynomial Ring in PI over Rational Field

That's a lot of work, but now getting the right object is trivial

sage: FR=R(FQ)
sage: FR
PI*x^10*y + 3*x
sage: FR.coefficients()
[PI, 3]
sage: FR.monomials()
[x^10*y, x]

As you see, the idea is to construct the desired object in sage while
keeping the names of generators and variables the same. That way,
sage's coercion and conversion framework can figure out what you want
to send where.

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to