# Reducing an expressing modulo a variable expression

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 close merge delete

( 2022-04-08 23:27:08 +0100 )edit

Sort by ยป oldest newest most voted

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)
print(f)
print(f.polynomial())

more

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.

more