# Constant coefficient of Laurent Polynomials

I am looking for the constant coefficient of a Laurent polynomial, the issue I am having is that sage is not simplifying the polynomial.

An example:

a = var(",".join( "a%i" %i for i in range(0, 6)))
f = x*y + 1.00000000000000*a6*x + 1.00000000000000*a4*y + x*y^-1 + x^-1*y + 1.00000000000000*a3*y^-1 + 1.00000000000000*a1*x^-1 + x^-1*y^-1


f/(x^1*y^0)  #  (The powers have to be in this way, just from the context of the work I am doing)


and it outputs:

1.00000000000000/x*x*y + 1.00000000000000*a6/x*x + 1.00000000000000*a4/x*y + 1.00000000000000/x*x*y^-1 + 1.00000000000000/x*x^-1*y + 1.00000000000000*a3/x*y^-1 + 1.00000000000000*a1/x*x^-1 + 1.00000000000000/x*x^-1*y^-1


Now when I ask for the constant coefficient of this LP it tells me its 0 when it is a6.

How can I fix this.

edit retag close merge delete

Sort by » oldest newest most voted

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 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 you wrote 1.00000000000000), you replace it by the real double field RDF.

more

Thanks, this explains both how to fix and why it was not working which is what I wanted. I thought the fact that a6 was not a variable in my ring was implicit but evidently not. Thanks.

You may try the following:

a = var(",".join( "a%i" %i for i in range(0, 7)))
R.<x,y> = LaurentPolynomialRing(SR,2)
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^1*y^0)).constant_coefficient()


It gives a6 as you expect and e.g.

 (f/(x^0*y^1)).constant_coefficient()


is equal to a4. Also you can determine the coefficient of any monomial:

(f/(x^0*y^1)).coefficient(x^-1*y^-2)


is 1.

more