# Is there a way to have MMA simplify (1+x)^p to 1+x^p modulo p, p a prime?

As the title suggests, I want to have Mathematica resolve

Element[p, Primes]
PolynomialMod[(1+x)^p, p]


to $1+x^p$. I have a massive symbolic function I would like to reduce in this fashion, and it involves many terms of the form above for two arbitrary primes $p$ and $q$. I can do a replace all with the reductions above, but that'll involve going through the pages of output and manually finding things to replace. I was hoping for something more automatic and elegant. Also, is it possible to have the above reduction occur within a square root?

## 1 Answer

If I'm understanding the documentation for PolynomialMod correctly, it appears to be treating (1+x)^p as a polynomial where the order p term has a coefficient of 1. Hence, that coefficient won't be reduced further modulo anything and MMA just spits back the polynomial you started with.

One simple solution might be to just use ReplaceAll like this:

(1+x)^p /. Power[1 + y_,q_] -> 1 + Power[y,q]


This can also be extended to square roots (I'm assuming you mean $\sqrt{(1+x)^p} \rightarrow \sqrt{1 + x^p}$), for example:

 {(1 + x)^p, (1 + z)^t + (1 + r)^m, Sqrt[(1 + tasty)^taco]} /. {Sqrt[Power[1 + y_, q_]] -> Sqrt[1 + y^q], Power[1 + y_, q_] -> 1 + y^q}

(*{1 + x^p, 2 + r^m + z^t, Sqrt[1 + tasty^taco]}*)


As long as you know what the relevant transformations should be, you should be able to use them to define patterns and rules that will give you what you want. This approach won't be able to automate any mathematics behind the scenes if there are other transformations you don't already know.