Ask Your Question

Reducing an expressing modulo a variable expression

asked 2022-04-08 18:38:10 +0200

I have some integer matrices, and I am interested in their behaviour mod p^2. I have declared variables using var('p a11 a12 a13, ...') etc, and after multiplying my matrices I am left with some very messy entries, involving lots of p^2,p^3,... terms. Since I only care about behaviour mod p^2, I would like Sage to just ignore those higher order terms. I feel like there must be an easy way to do this, but I don't know what it is. Any help would be much appreciated!

edit retag flag offensive close merge delete


Welcome to Ask Sage! Thank you for your question.

slelievre gravatar imageslelievre ( 2022-04-08 23:27:08 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2022-04-09 13:46:29 +0200

rburing gravatar image

For a symbolic approach you can use a substitution with a wildcard:

sage: var('p,a')
sage: f = (a*p+1)^2
sage: w0 = SR.wild()
sage: f.expand().subs({p^w0 : 0})
2*a*p + 1

This makes use of the fact that p^1 does not appear in an expanded symbolic expression.

Using a different ring would probably be more efficient, though.

edit flag offensive delete link more

answered 2022-04-09 13:11:01 +0200

Max Alekseyev gravatar image

If you matrices have polynomial entries, a possible approach is to define a polynomial ring in all variables but p, and the power series ring in p over that ring like:

R.<a11,a12,a13> = PolynomialRing(QQ)
P.<p> = PowerSeriesRing(R,default_prec=2)

Then to ignore the powers p^2 and higher, one can add O(p^2} and convert the result to polynomial if needed:

f = a11 + a12*p + a13*p^2
f += O(p^2)
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2022-04-08 18:38:10 +0200

Seen: 50 times

Last updated: Apr 09