ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 06 Dec 2021 15:55:13 +0100variable size exponent for Polynomial Ringhttps://ask.sagemath.org/question/60105/variable-size-exponent-for-polynomial-ring/ Is it possible to use a positive variable size exponent in a expression from elements in a polynomial ring? I have the following expression:
P.<x> = PolynomialRing(ZZ)
R = P.quotient_by_principal_ideal(ideal(x^3 - 3))
expr = R(x)
and I want to calculate `expr^k` where `k` is some positive integer. What I have is the following:
k = var('k', domain='positive')
expr^k
But I get the error: `unsupported operand parent(s) for ^: 'Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^3 - 3' and 'Symbolic Ring'`
I'm very new to sage so any help or pointers to the documentation would be appreciatedSun, 05 Dec 2021 20:08:53 +0100https://ask.sagemath.org/question/60105/variable-size-exponent-for-polynomial-ring/Comment by Max Alekseyev for <p>Is it possible to use a positive variable size exponent in a expression from elements in a polynomial ring? I have the following expression:</p>
<pre><code>P.<x> = PolynomialRing(ZZ)
R = P.quotient_by_principal_ideal(ideal(x^3 - 3))
expr = R(x)
</code></pre>
<p>and I want to calculate <code>expr^k</code> where <code>k</code> is some positive integer. What I have is the following:</p>
<pre><code>k = var('k', domain='positive')
expr^k
</code></pre>
<p>But I get the error: <code>unsupported operand parent(s) for ^: 'Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^3 - 3' and 'Symbolic Ring'</code></p>
<p>I'm very new to sage so any help or pointers to the documentation would be appreciated</p>
https://ask.sagemath.org/question/60105/variable-size-exponent-for-polynomial-ring/?comment=60116#post-id-60116Can you give an example of what you want to achieve?Mon, 06 Dec 2021 15:55:13 +0100https://ask.sagemath.org/question/60105/variable-size-exponent-for-polynomial-ring/?comment=60116#post-id-60116Comment by kev for <p>Is it possible to use a positive variable size exponent in a expression from elements in a polynomial ring? I have the following expression:</p>
<pre><code>P.<x> = PolynomialRing(ZZ)
R = P.quotient_by_principal_ideal(ideal(x^3 - 3))
expr = R(x)
</code></pre>
<p>and I want to calculate <code>expr^k</code> where <code>k</code> is some positive integer. What I have is the following:</p>
<pre><code>k = var('k', domain='positive')
expr^k
</code></pre>
<p>But I get the error: <code>unsupported operand parent(s) for ^: 'Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^3 - 3' and 'Symbolic Ring'</code></p>
<p>I'm very new to sage so any help or pointers to the documentation would be appreciated</p>
https://ask.sagemath.org/question/60105/variable-size-exponent-for-polynomial-ring/?comment=60110#post-id-60110I want a general expression for it, like when applying the binomial formula.Mon, 06 Dec 2021 08:39:19 +0100https://ask.sagemath.org/question/60105/variable-size-exponent-for-polynomial-ring/?comment=60110#post-id-60110Comment by Max Alekseyev for <p>Is it possible to use a positive variable size exponent in a expression from elements in a polynomial ring? I have the following expression:</p>
<pre><code>P.<x> = PolynomialRing(ZZ)
R = P.quotient_by_principal_ideal(ideal(x^3 - 3))
expr = R(x)
</code></pre>
<p>and I want to calculate <code>expr^k</code> where <code>k</code> is some positive integer. What I have is the following:</p>
<pre><code>k = var('k', domain='positive')
expr^k
</code></pre>
<p>But I get the error: <code>unsupported operand parent(s) for ^: 'Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^3 - 3' and 'Symbolic Ring'</code></p>
<p>I'm very new to sage so any help or pointers to the documentation would be appreciated</p>
https://ask.sagemath.org/question/60105/variable-size-exponent-for-polynomial-ring/?comment=60107#post-id-60107Why not define it as function?
def mypow(k):
return expr^kSun, 05 Dec 2021 21:06:36 +0100https://ask.sagemath.org/question/60105/variable-size-exponent-for-polynomial-ring/?comment=60107#post-id-60107Answer by Emmanuel Charpentier for <p>Is it possible to use a positive variable size exponent in a expression from elements in a polynomial ring? I have the following expression:</p>
<pre><code>P.<x> = PolynomialRing(ZZ)
R = P.quotient_by_principal_ideal(ideal(x^3 - 3))
expr = R(x)
</code></pre>
<p>and I want to calculate <code>expr^k</code> where <code>k</code> is some positive integer. What I have is the following:</p>
<pre><code>k = var('k', domain='positive')
expr^k
</code></pre>
<p>But I get the error: <code>unsupported operand parent(s) for ^: 'Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^3 - 3' and 'Symbolic Ring'</code></p>
<p>I'm very new to sage so any help or pointers to the documentation would be appreciated</p>
https://ask.sagemath.org/question/60105/variable-size-exponent-for-polynomial-ring/?answer=60112#post-id-60112Possible workaround :
sage: var("k", domain="integer")
k
sage: assume(k>0)
sage: var("j")
j
sage: product(expr, j, 1, k)
xbar^k
which might be wrapped in a function... But be aware that the result is a symbolic expression, not an element of R.Mon, 06 Dec 2021 12:33:21 +0100https://ask.sagemath.org/question/60105/variable-size-exponent-for-polynomial-ring/?answer=60112#post-id-60112