1 | initial version |
First, you are working with symbolic expressions, which is a very fuzzy place. Since your objects are of algebraic nature and Sage is good at it, let us work there.
In your description, there is no difference between x
and a6
, they are all symbols, at equality. If you agree that the constant coefficient of 3*x+y+1
is 1
, then you should agree that the constant coefficient of 3*x+a6+1
is 1
, not a6+1
.
How to make x
and y
the undeterminates of your laurent polynomial, and let the ai
be part or thh coefficients ?
Just define the laurent polynomial ring in x,y
on the ring which is the polynomial ring with indeterminates a0,....,a6
over QQ
:
sage: R = PolynomialRing(QQ,'a',7); R
Multivariate Polynomial Ring in a0, a1, a2, a3, a4, a5, a6 over Rational Field
sage: R.inject_variables()
Defining a0, a1, a2, a3, a4, a5, a6
sage: L = LaurentPolynomialRing(R,['x','y']) ; L
Multivariate Laurent Polynomial Ring in x, y over Multivariate Polynomial Ring in a0, a1, a2, a3, a4, a5, a6 over Rational Field
sage: L.inject_variables()
Defining x, y
Now, you can do:
sage: f = x*y + a6*x + a4*y + x*y^-1 + x^-1*y + a3*y^-1 + a1*x^-1 + x^-1*y^-1 ; f
x*y + a6*x + a4*y + x*y^-1 + x^-1*y + a3*y^-1 + a1*x^-1 + x^-1*y^-1
sage: f.parent()
Multivariate Laurent Polynomial Ring in x, y over Multivariate Polynomial Ring in a0, a1, a2, a3, a4, a5, a6 over Rational Field
sage: g = f/(x^1*y^0) ; g
y + a6 + a4*x^-1*y + y^-1 + x^-2*y + a3*x^-1*y^-1 + a1*x^-2 + x^-2*y^-1
sage: g.parent()
Multivariate Laurent Polynomial Ring in x, y over Multivariate Polynomial Ring in a0, a1, a2, a3, a4, a5, a6 over Rational Field
sage: g.constant_coefficient()
a6
I used the field of rationals QQ
for the base ring of the polynomial ring R
, but if you want floating-point numbers (as i see 1.00000000000000
), you replace it by the real double field RDF
.
2 | No.2 Revision |
First, you are working with symbolic expressions, which is a very fuzzy place. Since your objects are of algebraic nature and Sage is good at it, let us work there.
In your description, there is no difference between x
and a6
, they are all symbols, at equality. If you agree that the constant coefficient of 3*x+y+1
is 1
, then you should agree that the constant coefficient of 3*x+a6+1
is 1
, not a6+1
.
How to make x
and y
the undeterminates of your laurent polynomial, and let the ai
be part or thh the coefficients ?
Just define the laurent polynomial ring in x,y
on the ring which is the polynomial ring with indeterminates a0,....,a6
over QQ
:
sage: R = PolynomialRing(QQ,'a',7); R
Multivariate Polynomial Ring in a0, a1, a2, a3, a4, a5, a6 over Rational Field
sage: R.inject_variables()
Defining a0, a1, a2, a3, a4, a5, a6
sage: L = LaurentPolynomialRing(R,['x','y']) ; L
Multivariate Laurent Polynomial Ring in x, y over Multivariate Polynomial Ring in a0, a1, a2, a3, a4, a5, a6 over Rational Field
sage: L.inject_variables()
Defining x, y
Now, you can do:
sage: f = x*y + a6*x + a4*y + x*y^-1 + x^-1*y + a3*y^-1 + a1*x^-1 + x^-1*y^-1 ; f
x*y + a6*x + a4*y + x*y^-1 + x^-1*y + a3*y^-1 + a1*x^-1 + x^-1*y^-1
sage: f.parent()
Multivariate Laurent Polynomial Ring in x, y over Multivariate Polynomial Ring in a0, a1, a2, a3, a4, a5, a6 over Rational Field
sage: g = f/(x^1*y^0) ; g
y + a6 + a4*x^-1*y + y^-1 + x^-2*y + a3*x^-1*y^-1 + a1*x^-2 + x^-2*y^-1
sage: g.parent()
Multivariate Laurent Polynomial Ring in x, y over Multivariate Polynomial Ring in a0, a1, a2, a3, a4, a5, a6 over Rational Field
sage: g.constant_coefficient()
a6
I used the field of rationals QQ
for the base ring of the polynomial ring R
, but if you want floating-point numbers (as i see you wrote 1.00000000000000
), you replace it by the real double field RDF
.