ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 28 Nov 2016 02:28:50 -0600Constant coefficient of Laurent Polynomialshttp://ask.sagemath.org/question/35746/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
Then I ask
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.
Thanks in advanceSat, 26 Nov 2016 17:35:11 -0600http://ask.sagemath.org/question/35746/constant-coefficient-of-laurent-polynomials/Answer by castor for <p>I am looking for the constant coefficient of a Laurent polynomial, the issue I am having is that sage is not simplifying the polynomial. </p>
<p>An example:</p>
<pre><code>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
</code></pre>
<p>Then I ask</p>
<pre><code>f/(x^1*y^0) # (The powers have to be in this way, just from the context of the work I am doing)
</code></pre>
<p>and it outputs:</p>
<pre><code>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
</code></pre>
<p>Now when I ask for the constant coefficient of this LP it tells me its 0 when it is a6.</p>
<p>How can I fix this.</p>
<p>Thanks in advance</p>
http://ask.sagemath.org/question/35746/constant-coefficient-of-laurent-polynomials/?answer=35751#post-id-35751You 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.Sun, 27 Nov 2016 05:23:33 -0600http://ask.sagemath.org/question/35746/constant-coefficient-of-laurent-polynomials/?answer=35751#post-id-35751Answer by tmonteil for <p>I am looking for the constant coefficient of a Laurent polynomial, the issue I am having is that sage is not simplifying the polynomial. </p>
<p>An example:</p>
<pre><code>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
</code></pre>
<p>Then I ask</p>
<pre><code>f/(x^1*y^0) # (The powers have to be in this way, just from the context of the work I am doing)
</code></pre>
<p>and it outputs:</p>
<pre><code>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
</code></pre>
<p>Now when I ask for the constant coefficient of this LP it tells me its 0 when it is a6.</p>
<p>How can I fix this.</p>
<p>Thanks in advance</p>
http://ask.sagemath.org/question/35746/constant-coefficient-of-laurent-polynomials/?answer=35750#post-id-35750First, 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`.Sun, 27 Nov 2016 05:16:43 -0600http://ask.sagemath.org/question/35746/constant-coefficient-of-laurent-polynomials/?answer=35750#post-id-35750Comment by Ed Cal for <p>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.</p>
<p>In your description, there is no difference between <code>x</code> and <code>a6</code>, they are all symbols, at equality. If you agree that the constant coefficient of <code>3*x+y+1</code> is <code>1</code>, then you should agree that the constant coefficient of <code>3*x+a6+1</code> is <code>1</code>, not <code>a6+1</code>.</p>
<p>How to make <code>x</code> and <code>y</code> the undeterminates of your laurent polynomial, and let the <code>ai</code> be part or the coefficients ?</p>
<p>Just define the laurent polynomial ring in <code>x,y</code> on the ring which is the polynomial ring with indeterminates <code>a0,....,a6</code> over <code>QQ</code>:</p>
<pre><code>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
</code></pre>
<p>Now, you can do:</p>
<pre><code>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
</code></pre>
<p>I used the field of rationals <code>QQ</code> for the base ring of the polynomial ring <code>R</code>, but if you want floating-point numbers (as you wrote <code>1.00000000000000</code>), you replace it by the real double field <code>RDF</code>.</p>
http://ask.sagemath.org/question/35746/constant-coefficient-of-laurent-polynomials/?comment=35764#post-id-35764Thanks, 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.Mon, 28 Nov 2016 02:28:50 -0600http://ask.sagemath.org/question/35746/constant-coefficient-of-laurent-polynomials/?comment=35764#post-id-35764