Solution (source code)

= Solution
{c}

First extract the <polynomial content> from $f$:
$$
\boxed{f(X)=2\bigl(X^4-2X^3+4X^2-2X+2\bigr).}
$$
The primitive quartic is <Eisenstein> at the prime $2$: every nonleading coefficient is divisible by $2$, while the constant term is not divisible by $4$. <Eisenstein's criterion> makes it irreducible over $\mathbb Q$, and <Gauss's lemma> makes it irreducible in $\mathbb Z[X]$. The constant factor $2$ is itself irreducible in $\mathbb Z[X]$.

The polynomial $g$ is already irreducible over $\mathbb Q$: it is <Eisenstein> at $3$. Its nonleading coefficients, including the missing zero coefficients, are divisible by $3$, and $-21$ is not divisible by $9$. Thus \b[$g$ is its own sole nonconstant irreducible factor] over $\mathbb Q$.

Over the field $\mathbb Z_3$, grouping terms gives
$$
\boxed{h(X)=X(X+2)(X^2+1).}
$$
The first two factors are linear and therefore irreducible. The quadratic takes the values $1,2,2$ at $0,1,2$ respectively, so it has no root in $\mathbb Z_3$. A degree-two polynomial over a field is reducible exactly when it has a root, proving its irreducibility.

All three factorizations are \b[unique up to order and multiplication by units]. The ring $\mathbb Z$ is a <unique factorization domain>, hence so is $\mathbb Z[X]$ by <Gauss's lemma>. A polynomial ring over a field is a <Euclidean domain>, so both $\mathbb Q[X]$ and $\mathbb Z_3[X]$ have unique factorization. The units are $\pm1$ in the first ring, nonzero rational constants in the second, and $1,2$ in the third.