Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Symbolic integer arithmetic

It's not that hard to find a closed expression for the remainder of the polynomial $x^n$ modulo $x^2-5x-2$. But I don't seem to manage it in SAGE.

n=var('n')
R=PolynomialRing(RationalField(),'x');R
x=R.gen();x
mp=x^2-5*x-2
S=R.quotient(mp,'a')
a=S.gen();a^2
a^5

works as expected, but replacing the last line with a^n gives an error (non-integral exponents not supported). I understand a general variable is not a SAGE integer, but how DO I make clear n is supposed to be an integer?

In the same way, it's not that hard to calculate the symbolic n-the power of a small, say 2x2, matrix, but the straightforward aproach of simplifying A^n gives the same error (non-integral exponents not supported).

Symbolic integer arithmetic

It's not that hard to find a closed expression for the remainder of the polynomial $x^n$ modulo $x^2-5x-2$. But I don't seem to manage it in SAGE.

n=var('n')
R=PolynomialRing(RationalField(),'x');R
x=R.gen();x
mp=x^2-5*x-2
S=R.quotient(mp,'a')
a=S.gen();a^2
a^5

works as expected, but replacing the last line with a^n gives an error (non-integral exponents not supported). I understand a general variable is not a SAGE integer, but how DO I make clear n is supposed to be an integer?

In the same way, it's not that hard to calculate the symbolic n-the power of a small, say 2x2, matrix, but the straightforward aproach of simplifying A^n gives the same error (non-integral exponents not supported).

I checked wolfram alpha for the symbolic power of a matrix, and immediately got the expected answer.

Wolfram alpha answer

Symbolic integer arithmetic

It's not that hard to find a closed expression for the remainder of the polynomial $x^n$ modulo $x^2-5x-2$. But I don't seem to manage it in SAGE.

n=var('n')
R=PolynomialRing(RationalField(),'x');R
x=R.gen();x
mp=x^2-5*x-2
S=R.quotient(mp,'a')
a=S.gen();a^2
a^5

works as expected, but replacing the last line with a^n gives an error (non-integral exponents not supported). I understand a general variable is not a SAGE integer, but how DO I make clear n is supposed to be an integer?

In the same way, it's not that hard to calculate the symbolic n-the power of a small, say 2x2, matrix, but the straightforward aproach of simplifying A^n gives the same error (non-integral exponents not supported).

I checked wolfram alpha for the symbolic power of a matrix, and immediately got the expected answer.answer for [[1,2],[3,4]]^n .

Wolfram alpha answer