Definition 1.9.1 A domain $R$ is a unique factorization domain (UFD) or factorial ring if
 every $r\in R$, neither $0$ or a unit, is a product of irreducibles;
 if $p_1\cdots p_m=q_1\cdots q_n$ where all $p_i$ and $q_j$ are irreducible, then $m=n$ and there is a permutation $\sigma\in S_n$ with $p_i$ and $q_{\sigma(i)}$ associates for all $i$.
Proposition 1.9.1 Let $R$ be a domain in which every $r\in R$, neither $0$ nor a unit, is a product of irreducibles. Then $R$ is a UFD if and only if $(p)$ is a prime ideal in $R$ for every irreducible element $p\in R$.
Proof.

($\Rightarrow$).
Let $p\in R$ be an irreducible element.
$\forall ab\in (p)$, assume that $a\notin (p)$.
For $ab\in (p)$, $\exists r\in R$ with $ab=rp$.
Then let $a=p_1\cdots p_n,b=q_1\cdots q_m,$ and $r=r_1\cdots r_t$ with $p$'s, $q$'s, and $r$'s are irreducible.
$p_1\cdots p_nq_1\cdots q_m=r_1\cdots r_tp$, then $\exists j$ such that $q_j$ and $p$ associates.
Therefore $b\in (p)$, and $(p)$ is a prime ideal.

($\Leftarrow$).
Let $a\in R$ with $a=p_1\cdots p_n=q_1\cdots q_m$ in which $p$'s and $q$'s are irreducible.
By induction on $M=\max \{m,n\}$.
If $M=1$, we have $p_1=q_1$.
For inductive step, because $q_1\cdots q_m\in(p_n)$, $\exists j,q_j\in (p_n)$; that is $q_j$ and $p_n$ are associates.
By reindexing, let $q_m=up_n$, where $u$ is a unit.
Then by cancelling,we have $p_1\cdots p_{n1}=q_1\cdots (uq_{m1})$.
Since $q_{m1}u$ is irreducible, the inductive hypothesis gives $n1=m1$ (hence, $m=k$) and, after reindexing, $p_i$ and $q_i$ are associates for all $i$. $\square$
Lemma 1.9.1

If $R$ is a commutative ring and
$$I_1\subset I_2\subset \cdots\subset I_n\subset I_{n+1}\subset \cdots
$$
is a ascending chain of ideals in $R$, then $J=\bigcup_{n\ge 1} I_n$ is an ideal in $R$. 
If $R$ is a PID, then it has no infinite strictly ascending chain of ideals
$$I_1 \subsetneq I_2 \subsetneq \cdots \subsetneq I_{n}\subsetneq I_{n+1}\subsetneq \cdots.
$$ 
If $R$ is a PID and $r\in R$ is neither $0$ or a unit, then $r$ is a product of irreducibles.
Proof.


$\forall x,y\in \bigcup_{n\ge 1} I_n$, $\exists m,k\in \mathbb N_+$ with $x\in I_m,y\in I_k$.
Let $M=\max\{m,k\}$. Then $x,y\in I_M$.
We have $xy\in I_M\subset \bigcup_{n\ge 1} I_n$.

$\forall x\in \bigcup_{n\ge 1} I_n,\exists m\in \mathbb N_+$ with $x\in I_m$.
$\forall r\in R,rx\in I_m\subset \bigcup_{n\ge 1} I_n$ for $I_m$ is an ideal.
Therefore $\bigcup_{n\ge 1} I_n$ is an ideal.


Assume that $I_1\subset I_2\subset \cdots\subset I_n\subset I_{n+1}\subset \cdots$ is a ascending chain of ideals in $R$.
For $R$ is a PID, there is $p\in R$ with $\bigcup_{n\ge 1} I_n=(p)$.
Then we have $p\in \bigcup_{n\ge 1} I_n$; that is $\exists m$ with $p\in I_m$.
Therefore $(p)\subset I_m\subset (p)\Rightarrow I_m=(p)$, so does $I_{m+1}$.

A divisor $r$ of an element $a$ is called a proper divisor of $a$ if $r$ is neither a unit nor an associate of $a$.
If $r$ is a divisor of $a$, then $(a)\subset (r)$; if $r$ is a proper divisor, then $(a)\subsetneq (r)$, for f the inequality if not strict, then $(a)=(r)$, and this force $a$ and $r$ to be associates.
Call a nonzero nonunit $a\in R$ good, if it is a product of irreducibles; call it bad otherwise.
If $a$ is bad, it is not irreducible, and so $a=rs$, where $r$ and $s$ are proper divisors. But the product of good elements is good, and so at least one of the factors, say $r$, is bad. We can get $(a)\subsetneq (r)$. It follows, by induction, that there exists a sequence $a_1=1,a_2=r,a_3,\dots,a_n,\dots$ of bad elements with each $a_{n+1}$ a proper divisor of $a_n$, and this sequence yields a strictly ascending chain
$$ (a_1)\subsetneq (a_2)\subsetneq\cdots\subsetneq(a_n)\subsetneq(a_{n+1})\subsetneq\cdots,
$$
contradicting (2). $\square$
Theorem 1.9.1 Every PID is a UFD.
Proposition 1.9.2 If $R$ is a UFD, then a $\gcd(a_1,\dots,a_n)$ of any finite set of elements $a_1,\dots,a_n$ in $R$ exists.
Proof.
We prove first that a gcd of two elements $a$ and $b$ exists. There are distinct irreducibles $p_1,\dots,p_t$ with
$$a={p_1}^{e_1}p_2^{e_2}\cdots p_t^{e_t}\text{ and }b=p_1^{f_1}p_2^{f_2}\cdots p_t^{f_t},
$$
where $e_i\ge 0$ and $f_i\ge 0$ for all $i$. It is easy to see that if $c\mid a$, then the factorization of $c$ into irreducibles is $c=wp_1^{g_1}\cdots p_t^{g_t}$, where $0\le g_i\le e_i$ for all $i$ and $w$ is a unit. Thus, $c$ is a common divisor of $a$ and $b$ if $g_i<m_i$ for all $i$, where $m_i=\min\{e_i,f_i\}$.
It is now clear that $p_1^{m_1}p_2^{m_2}\cdots p_t^{m_t}$ is a gcd of $a$ and $b$.
More generally, if $a_i=u_ip_1^{e_{i1}}\dots p_t^{e_{it}}$, where $e_{ij}\ge 0$ and $i=1,\dots,n$ and $u_i$ are units, then
$$d=p_1^{\mu_1}\cdots p_t^{\mu_t}
$$
is a gcd of $a_1,\dots,a_n$, where $\mu_j=\min\{e_{1j},\dots,e_{nj}\}$. $\square$
Proposition 1.9.3 Let $R$ be a UFD, and let $a_1,\dots,a_n$ in $R$. An lcm of $a_1,\dots, a_n$ exists, and
$$a_1\cdots a_n=\gcd(a_1,\dots,a_n)\operatorname{lcm}(a_1,\dots,a_n).
$$
Definition 1.9.2 A polynomial $f(x)=a_nx^n+\cdots+a_1x+a_0\in R[x]$, where $R$ is a UFD, is called primitive if its coefficients are relatively prime; that is, the only common divisors of $a_n,\dots,a_1,a_0$ are units.
We can see that every monic polynomial is primitive. Observe that if $f(x)$ is not primitive, then there exists an irreducible $q\in R$ that divides each of its coefficients: if the gcd is a nonunit $d$, then take for $q$ any irreducible factor of $d$.
Lemma 1.9.2 (Gauss) If $R$ is a UFD and $f(x),g(x)\in R[x]$ are both primitive, then their product $fg$ is also primitive.
Proof.
If $fg$ is not primitive, there is an irreducible $p\in R$ which divides all its coefficients.
Let $P=(p)$ and let $\pi: R\to R/P$ be the natural map $a\mapsto a+P$.
By replacing each coefficient $c$ of a polynomial by $\pi(c)$, we have the homomorphism $\tilde\pi:R[x]\to (R/P)[x]$.
Now $\tilde\pi(fg)=0$ in $(R/P)[x]$. Since $P$ is a prime ideal, both $R/P$ and $(R/P)[x]$ are domains.
But neither $\tilde\pi(f)$ nor $\tilde\pi(g)$ is $0$ in $(R/P)[x]$, because $f$ and $g$ are primitive, and this contradicts $(R/P)[x]$ being a domain. $\square$
Proposition 1.9.4 Let $R$ be a UFD and let $Q=\operatorname{Frac}(R)$ be its fraction field. Each nonzero $a/b\in Q$ has an expression in lowest terms; that is, $a$ and $b$ are relatively prime.
Proof.
Since $R$ is a UFD, there is a gcd of $a$ and $b$ in $R$. Let $d$ be a gcd of $a$ and $b$.
Then there are $u,v\in R$ with $a=ud,b=vd$ and $u,v$ are relatively prime.
Therefore $u/v\in Q$ is the expression in lowest term of $a/b$. $\square$
Proposition 1.9.5 Let $R$ be a UFD. If $a,b,c\in R$ and $a$ and $b$ are relatively prime. Then $a\mid bc$ implies $a\mid c$.
Proof.
Since $R$ is a UFD, there are irreducibles $p_1,\dots,p_t$ with $a=p_1\cdots p_t$.
We will show $c=up_1\cdots p_t$ for some $u\in R$.
Let's prove by induction on $t$.
When $t=1$, since $a=p_1$ is an irreducible and $p_1\nmid b$, $p_1\mid c$.
Otherwise, $(p_t)$ is a prime ideal in $R$, then $c\in (p_t)$ for $bc\in (p_t)$ and $b\notin (p_t)$.
Therefore, $c=c'p_t$ with some $c'\in R$. By cancelling, we have $p_1\cdots p_{t1}\mid bc$.
By inductive suppose we have $c'=up_1\cdots p_{t1}$. Therefore $c=c'p_t=up_1\cdots p_{t}=ua$. $\square$
Lemma 1.9.3 Let $R$ be a UFD, let $Q=\operatorname{Frac}(R)$, and let $f(x)\in Q[x]$ be nonzero.

There is a factorization
$$
f(x)=c(f)f^*(x),
$$
where $c(f)\in Q$ and $f^*\in R[x]$ is primitive. This factorization is unique in the sense that if $f(x)=qg^*(x)$, where $q\in Q$ and $g^*\in R[x]$ is primitive, then there is a unit $w\in R$ with $q=wc(f)$ and $f^*=wg^*$. 
If $f(x),g(x)\in R[x]$, then $c(fg)$ and $c(f)c(g)$ are associates in $R$ and $(fg)^*$ and $f^*g^*$ are associates in $R[x]$.

Let $f(x)\in Q[x]$ have a factorization $f=qg^*$, where $q\in Q$ and $g^*\in R[x]$ is primitive. Then $f\in R[x]$ if and only if $q\in R$.

Let $g^*,f\in R[x]$. If $g^*$ is primitive and $g^*\mid bf$, where $b\in R$ and $b\ne 0$, then $g^*\mid f$.
Proof.

Clearing denominators, there is $b\in R$ with $bf\in R[x]$. If $d$ is the gcd of the coefficients of $bf$, then $f^*(x)=(b/d)f\in R[x]$ is a primitive polynomial. If we define $c(f)=d/b$, then $f=c(f)f^*$.
To prove uniqueness, suppose that $c(f)f^*=f=qg^*$, where $c(f),q\in Q$ and $f^*(x),g^*(x)\in R[x]$ are primitive. Proposition 1.9.4 allows us to write $q/c(f)$ in lowest terms: $q/c(f)=u/v$, where $u$ and $v$ are relatively prime elements of $R$.
The equation $vf^*(x)=ug^*(x)$ holds in $R[x]$. Since $u$ and $v$ are relatively prime, Proposition 1.9.5 says that $v$ is a common divisor of all the coefficients of $g^*$. But $g$ is primitive, and so $v$ is a unit.
A similar argument shows that $u$ is a unit. Therefore, $q/c(f)=u/v$ is a unit in $R$, call it $w$; we have $q=wc(f)$ and $f^*=wg^*$.

There are two factorizations of $f(x)g(x)$ in $R[x]$:
$$\begin{align}
fg&=c(fg)(fg)^*,\\
fg&=c(f)f^*c(g)g^*=c(f)c(g)f^*g^*.
\end{align}
$$
Since the product of primitive polynomials is primitive, each of these is a factorization as in (1); the uniqueness assertion there says that $c(fg)$ is an associate of $c(f)c(g)$ and $(fg)^*$ is an associate of $f^*g^*$. 
If $q\in R$, then it is obvious that $f=qg^*\in R[x]$. Conversely, if $f(x)\in R[x]$, then there is no need to clear denominators, and so $c(f)=d\in R$, where $d$ is the gcd of the coefficients of $f(x)$. Thus $f=df^*$. By uniqueness, there is a unit $w\in R$ with $q=wd\in R$.

Since $bf=hg^*$, we have $bc(f)f^*=c(h)h^*g^*=c(h)(hg)^*$. By uniqueness, $f^*$, $(hg)^*$ and $h^*g^*$ are associates, and so $g^*\mid f^*$, But $f=c(f)f^*$, and so $g^*\mid f$.
Definition 1.9.3 Let $R$ be a UFD with $Q=\operatorname{Frac}(R)$. If $f(x)\in Q[x]$, there is a factorization $f=c(f)f^*$, where $c(f)\in Q$ and $f^*\in R[x]$ is primitive. We call $c(f)$ the content of $f$ and $f^*$ the associated primitive polynomial.
Corollary 1.9.1 Let $k$ be a field, and let
$$f(x,y)=y^n+\frac{g_{n1}(x)}{h_{n1}(x)}y^{n1}+\cdots+\frac{g_0(x)}{h_0(x)}\in k(x)[y],
$$
where each $g_i/h_i$ is in lowest terms. If $f^*(x,y)\in k[x][y]$ is the associated primitive polynomial of $f$, then
$$\max_i\{\deg(g_i),\deg(h_i)\}\le \deg_x(f^*)\text{ and }n=\deg_y(f^*),
$$
where $\deg_x(f^*)$ (or $\deg_y(f^*)$) is the highest power of $x$ (or $y$) occurring in $f^*$.
Proof.
Let $l$ be the lcm of $h_0,\dots,h_{n1}\in k[x]$. Then, the associated primitive polynomial is
$$f^*(x,y)=lf(x,y)=ly^n+l\frac{g_{n1}}{h_{n1}}+\cdots+l\frac{g_0}{h_0}\in k[x,y].
$$
Since $l$ is the lcm, there are $u_i\in k[x]$ with $l=u_ih_i$ for all $i$. Hence, each coefficient $c(g_i/h_i)=u_ig_i\in k[x]$. If $m=\deg_x(f^*)$, then
$$m=\max\{\deg(l),\deg(c(g_i/h_i))\}=\max\{\deg(l),\deg(u_ig_i)\},
$$
for $l$ is a coefficient of $f^*$. Now $h_i\mid l$ for all $i$, so that $\deg(h_i)\le \deg(l)\le m$.
Also $\deg(g_i)\le \deg(u_ig_i)\le m$. We conclude that $\max_i\{\deg(g_i),\deg(h_i)\}\le m=\deg_x(f^*)$. $\square$
Theorem 1.9.1 (Gauss) If $R$ is a UFD, then $R[x]$ is also a UFD.
Proof.

First, let's prove that every $f(x)\in R[x]$, neither zero nor a unit, is a product of irreducibles by induction.
The base step $\deg(f)=0$ is true, because $f$ is a constant, hence lies in $R$, and hence is a product of irreducibles (for $R$ is a UFD).
For the inductive step $\deg(f)>0$, we have $f=c(f)f^*$, where $c(f)\in R$ and $f^*(x)$ is primitive.
Now $c(f)$ is either a unit or a product of irreducibles, by the base step.
If $f^*$ is irreducible, we are done. Otherwise, $f^*=gh$, where neither $g$ nor $h$ is a unit.
Since $f^*$ is primitive, however, neither $g$ nor $h$ is a constant; therefore, each of these has degree less than $\deg(f^*)=\deg(f)$.
By indective hypothesis, each of $g$ and $h$ is a product of irreducibles. Therefore, $f$ is a product of irreducibles.

Then, let's prove $R[x]$ is a UFD by Proposition 1.9.1; that is let $p$ be an irreducible, then $(p)$ is a prime ideal in $R[x]$.
Let $fg\in (p)$.
 Suppose that $\deg(p)=0$.
Now $f=c(f)f^*(x),g=c(g)g^*(x)$, where $f^*,g^*$ are primitive and $c(f),c(g)\in R$.
Since $p\mid fg$, we have $p\mid c(f)c(g)f^*g^*$. Write $f^*g^*=\sum_i a_ix^i$, where $a_i\in R$, so that $p\mid c(f)g(f)a_i$ in $R$ for all $i$.
Now $f^*g^*$ is primitive, so there is some $i$ with $p\nmid a_i$ in $R$. For $R$ is a UFD, $p\mid c(f)$ or $p\mid c(g)$.
Thus, $p\mid f$ or $p\mid g$.
 Suppose that $\deg(p)>0$ and $p\nmid f$.
Let $(p,f)=\{s(x)p(x)+t(x)f(x);s(x),t(x)\in R[x\}$; then $(p,f)$ is an ideal in $R[x]$ containing $p$ and $f$.
Choose $m(x)\in (p,f)$ of minimal degree. If $Q=\operatorname{Frac}(R)$ is the fraction field of $R$, then the division algorithm in $Q[x]$ gives polynomials $q(x),r(x)\in R[x]$ with
$$
f=mq'+r',
$$
where either $r'=0$ or $\deg(r')<\deg(m)$. Clearing denominators, there is a constant $b\in R$ and polynomials $q(x),r(x)\in R[x]$ with
$$
bf=qm+r,
$$
where $r=0$ or $\deg(r)<\deg(m)$.Since $m\in (p,f)$, there are polynomials $s(x),t(x)\in R[x]$ with $n=sp+tf$; hence $r=bfqm\in (q,f)$. Since $m$ has minimal degree in $(p,f)$, we must have $r=0$; that is $bf=mq$, and so $bf=c(m)m^*q$. But $m^*$ is primitive, and $m^*\mid bf$, so that $m^*\mid f$ for Lemma 1.9.3(4).
A similar argument, replacing $f$ by $p$, we have $m^*\mid p$. Since $p$ is irreducible, we have $m^*$ is a unit or $m^*$ and $p$ are associates. If $m^*$ were an associate of $p$, then $p\mid f$ contrary to out assumption that $p\nmid f$. Thus $m^*$ must be a unit. Therefore, $m\in R$.
We have $mg=(sf+pt)g=sfg+ptg$, so that $p\mid mg$. Since $p$ is an irreducible, we have $p$ is primitive. By Lemma 1.9.3, we have $p\mid g$. $\square$
Corollary 1.9.2 If $k$ is a field, then $k[x_1,\dots,x_n]$ is a UFD.
Corollary 1.9.3 If $k$ is a field, then $p=p(x_1,\dots,x_n)\in k[x_1,\dots,x_n]$ is irreducible if and only if $(p)$ is a prime ideal in $k[x_1,\dots,x_n]$.
Corollary 1.9.4 (Gauss's Lemma) Let $R$ be a UFD, let $Q=\operatorname{Frac}(R)$, and let $f(x)\in R[x]$. If $f=GH$ in $Q[x]$, then there is a factorization
$$f=gh \text{ in } R[x],
$$
where $\deg(g)=\deg(G)$ and $\deg(h)=\deg(H)$; in fact, $G$ is a constant multiple of $g$ and $H$ is a constant multiple of $h$. Therefore, if $f$ does not factor into polynomials of smaller degree in $R[x]$, then $f$ is irreducible in $Q[x]$.
Proof.
By Lemma 1.9.3(1), the factorization $f=GH$ in $Q[x]$ gives $q,q'\in Q$ with
$$f=qG^*q'H^*\text{ in } Q[x],
$$
where $G^*,H^*\in R[x]$ are primitive; thus, $G^*H^*$ is primitive.
Since $f\in R[x]$, by Lemma 1.9.3, the equation $f=(qq')(G^*H^*)$ shows that $qq'\in R$.
Therefore, a factorization of $f$ in $R[x]$ is $f=(qq'G^*)H^*$. $\square$
Proposition 1.9.6 Let $k$ be a field, and view $f(x_1,\dots,x_n)\in k[x_1,\dots,x_n]$ as a polynomial in $R[x_n]$, where $R=k[x_1,\dots,x_{n1}]$:
$$f(x_n)=a_0(x_1,\dots,x_{n1})+a_1(x_1,\dots,x_{n1})x_n+\cdots+a_m(x_1,\dots,x_{n1})x_n^m.
$$
If $f(x_n)$ is primitive and cannot be factored into two polynomials of lower degree in $R[x_n]$, then $f(x_1,\dots,x_n)$ is irreducible in $k[x_1,\dots,x_n]$.
Proof.
Suppose that $f(x_n)=g(x_n)h(x_n)$ in $R[x_n]$; by hypothesis, the degree of $g$ and $h$ in $x_n$ cannot both be less than $\deg(f)$; say, $\deg(g)=0$.
It follows, because $f$ is primitive, that $g$ is a unit in $k[x_1,\dots,x_{n1}]$. Therefore, $f(x_1,\dots,x_n)$ is irreducible in $R[x_n]=k[x_1,\dots,x_n]$. $\square$
Corollary 1.9.5 If $k$ is a field and $g(x_1,\dots,x_n),h(x_1,\dots,x_n)\in k[x_1,\dots,x_n]$ are relatively prime, then $f(x_1,\dots,x_n,y)=yg(x_1,\dots,x_n)+h(x_1,\dots,x_n)$ is irreducible in $k[x_1,\dots,x_n,y]$.