TITLE: Finding inverse of polynomial in a field
QUESTION [18 upvotes]: I'm having trouble with the procedure to find an inverse of a polynomial in a field. For example, take:

In $\frac{\mathbb{Z}_3[x]}{m(x)}$, where $m(x) = x^3 + 2x +1$, find the inverse of $x^2 + 1$.

My understanding is that one needs to use the (Extended?) Euclidean Algorithm and Bezout's Identity. Here's what I currently have:
Proceeding with Euclid's algorithm:
$$ x^3 + 2x + 1  =(x^2 + 1)(x) + (x + 1) \\\\
  x^2 + 1 = (x + 1)(2 + x) + 2$$
We stop here because 2 is invertible in $\mathbb{Z}_3[x]$. We rewrite it using a congruence:
$$(x+1)(2+x) \equiv 2 \mod{(x^2+1)}$$
I don't understand the high level concepts sufficiently well and I'm lost from here. Thoughts?
Wikipedia has a page on this we a decent explanation, but it's still not clear in my mind.
Note that this question has almost the same title, but it's a level of abstraction higher. It doesn't help me, as I don't understand the basic concepts.
Thanks.

REPLY [4 votes]: Another way to do this, is by representing the elements of your quotient field (which is a three-dimensional vector space with base field GF(3)) as matrices with respect to the basis 1, x, x^2. Multiplication by x sends 1 to x, x to x^2 and x^2 to x^3 = -2x - 1 = x + 2 (modulo 3). So (multiplication by) x is represented by the following matrix m:
\begin{pmatrix}
    0 & 0 & 2 \\
    1 & 0 & 1  \\
    0 & 1 & 0 
\end{pmatrix}
m^0 (corresponding to multiplication by x^0 = 1) is the identity matrix:
\begin{pmatrix}
    1 & 0 & 0 \\
    0 & 1 & 0  \\
    0 & 0 & 1 
\end{pmatrix}
and m^2 (multiplication by x^2) equals:
\begin{pmatrix}
    0 & 2 & 0 \\
    0 & 1 & 2  \\
    1 & 0 & 1 
\end{pmatrix}
The element (x^2 + 1)^-1 is represented by (m^2 + m^0)^-1, which equals
\begin{pmatrix}
    2 & 1 & 2 \\
    1 & 1 & 2  \\
    2 & 1 & 1 
\end{pmatrix}
The coefficients of (x^2 + 1)^-1 can be read off from the first column of this matrix: (m^2 + m^0)^-1 = 2m^0 + m + 2m^2, so (x^2 + 1)^-1 = 2 + x + 2x^2. Summarizing: your problem can be solved by adding, multiplying and inverting matrices.