Ask Your Question

# 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 appreciated

edit retag close merge delete

## Comments

Why not define it as function?

def mypow(k):
return expr^k

( 2021-12-05 21:06:36 +0200 )edit

I want a general expression for it, like when applying the binomial formula.

( 2021-12-06 08:39:19 +0200 )edit

Can you give an example of what you want to achieve?

( 2021-12-06 15:55:13 +0200 )edit

## 1 Answer

Sort by ยป oldest newest most voted

Possible 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.

more

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2021-12-05 20:08:53 +0200

Seen: 55 times

Last updated: Dec 06 '21