I'm looking into modular polynomial rings over the integers (if that's the right term?) i.e. $\mathbb{Z}_m[X]/P(X)$ where $\mathbb{Z}_m$ is the ring of integers modulo m, and P(X) is some polynomial with coefficients in $\mathbb{Z}_m$. Note that m is not necessarily prime so $\mathbb{Z}_m[X]$ may not be a field.
I wish to understand how to calculate the multiplicative inverse of polynomials (or should I call it polynomial classes) in such rings. I think I understand how to use the Extended Euclidean Algorithm, which works fine if m is prime. But if m is not prime I run astray.
For example: say R=$\mathbb{Z}_4[X]/(X^3-1)$ and find the inverse of $2x+1$ in R.
I know that the solution is $2x+1$, since $(2x+1)^2=1$ in R.
But right in the first step I need to multiply $2x+1$ with something and subtract that from $x^3-1$ to reduce its degree. But this is impossible since 2 is invertible (mod 4).
Another example: same R=$\mathbb{Z}_4[X]/(X^3-1)$ and find the inverse of $3x^2+2x+2$ in R.
I know that the solution is $2x^2+3x+2$, since $(3x^2+2x+2)\cdot(2x^2+3x+2)=1$ in R.
In the first step I multiply $3x^2+2x+2$ by $3x$ and subtract that from $x^3-1$ which leaves $2x2+2x+3$. And now I run into the same problem.
Am I doing it wrong, or is there a better way to either find an inverse in such cases or find that it doesn't exist?
Given $f\in \Bbb{Z}[x]/(p^2,U)$ using the extended euclidean algorithm find some $g$ (if it exists, otherwise $f$ is not a unit) such that $fg=1\in \Bbb{Z}[x]/(p,U)$
So there is some $r$ such that $fg=1+pr$ in $\Bbb{Z}[x]/(p^2,U)$.
The inverse of $f\in \Bbb{Z}[x]/(p^2,U)$ is of the form $g+ph$.
Since $f(g+ph) = 1+p r+fph$, we want $fph=-pr$ in $\Bbb{Z}[x]/(p^2,U)$ ie. $fh =-r$ in $\Bbb{Z}[x]/(p,U)$,
ie. $h = -rg$ in $\Bbb{Z}[x]/(p,U)$ and the inverse of $f$ in $\Bbb{Z}[x]/(p^2,U)$ is $$g-prg$$
It works the same way, repeating the same idea $n$ times, for finding the inverse of $f\in \Bbb{Z}[x]/(p^n,U)$.
For the inverse of $f\in \Bbb{Z}[x]/(m,U)$ factorize $m$ in prime powers, solve for the inverse modulo each prime power, then mix the inverses using the isomorphism $\Bbb{Z}[x]/(m,U)\to \prod_j \Bbb{Z}[x]/(p_j^{n_j},U)$.