Proof (removing eps and unit productions from context-free grammar)

Expanding

Let $\hat P$ be the smallest set of rewrite rules containing $P$ and such that

  1. if $A\to ε\in \hat P$ and $B\to αAβ\in \hat P$, then $B \to αβ\in \hat P$; and

  2. if $A \to B\in \hat P$ and $B\to α\in \hat P$, then $A \to α\in \hat P$.

$\hat P$ is finite: starting with $P$, we add rewrite rules according to operations 1 and 2. Since the added rules have bounded lengths, this process must terminate.

Now we claim $\hat G := (Σ, N, \hat P, S)$ has the same language as $G$. Clearly since $\hat P \supseteq P$, $\mathcal{L}(\hat G) \supseteq \mathcal{L}(G)$. Conversely, if a derivation in $\hat G$ uses the added rules, we can expand it back to $P$ by operations 1 and 2, so $\mathcal{L}(G) \subseteq \mathcal{L}(\hat G)$.

Removing

Now remove all $ε$ and unit productions from $\hat P$, forming $\mathring P$. We claim $\mathcal{L}(\mathring G) = \mathcal{L}(\hat G) \setminus \set{ε}$. $\subseteq$ is clear.

For $\supseteq$, we will show a shortest $\hat G$-derivation of a sentence $σ\in Σ^+$ does not use any $ε$ or unit productions, and thus is a $\mathring G$-derivation.

Unit production

Suppose it uses a unit production $A\to B$, so it has the form $$ \begin{align*} S \xrightarrow{\hat G} αAβ \xrightarrow{\hat G}_1 αBβ \xrightarrow{\hat G} σ. \end{align*} $$ Since $σ$ has no non-terminal symbols, the $B$ is eventually replaced by $B\to γ$, so $$ \begin{align*} S \xrightarrow{\hat G}_m αAβ \xrightarrow{\hat G}_1 αBβ \xrightarrow{\hat G}_n α'Bβ' \xrightarrow{\hat G}_1 α'γβ' \xrightarrow{\hat G}_l σ. \end{align*} $$ Therefore using the rule $A\to γ\in \hat P$ (and noting the grammar is context-free so derivations involving disjoint substrings are independent), $$ \begin{align*} S \xrightarrow{\hat G}_m αAβ \xrightarrow{\hat G}_1 αγβ \xrightarrow{\hat G}_n α'Bβ' \xrightarrow{\hat G}_l σ \end{align*} $$ is a $\hat G$-derivation shorter than the original, which is a contradiction.

$ε$ production

Now suppose it uses a $ε$ production $A\to ε$, so it has the form $$ \begin{align*} S \xrightarrow{\hat G} α'Aβ' \xrightarrow{\hat G}_1 α'β' \xrightarrow{\hat G} σ. \end{align*} $$ Since $σ\neq ε$, the $A$ must be produced by a previous rewrite $B\to γAδ$: $$ \begin{align*} S \xrightarrow{\hat G}_m αBβ \xrightarrow{\hat G}_n αγAβδ \xrightarrow{\hat G}_l α'Aβ' \xrightarrow{\hat G}_1 α'β' \xrightarrow{\hat G}_p σ. \end{align*} $$ Using the rule $B\to γδ\in \hat P$, $$ \begin{align*} S \xrightarrow{\hat G}_m αBβ \xrightarrow{\hat G}_n αγβδ \xrightarrow{\hat G}_l α'β' \xrightarrow{\hat G}_p σ, \end{align*} $$ which is shorter, contradiction.