[step:Translate a $G$-derivation of $w$ into an accepting run of $D$]Conversely, suppose $w \in \mathcal{L}(G)$ with $|w| \geq 1$. By the [Structure of Terminal Derivations](/theorems/1787) theorem applied to the regular grammar $G$, any $G$-derivation of $w$ from $q_0$ has exactly $|w|$ steps, consisting of $|w| - 1$ nonterminal rules followed by a single terminal rule. Write $w = a_0 a_1 \cdots a_n$ with $n = |w| - 1$ as before.
By the shape theorem, the derivation takes the form
\begin{align*}
q_0 \to_G b_0 A_1 \to_G b_0 b_1 A_2 \to_G \cdots \to_G b_0 b_1 \cdots b_{n-1} A_n \to_G b_0 b_1 \cdots b_{n-1} b_n = w,
\end{align*}
where $A_1, A_2, \dots, A_n \in Q$ are variables (nonterminals of $G$, i.e., states of $D$), the first $n$ steps use nonterminal rules $A_{i-1} \to b_{i-1} A_i$ (with $A_0 := q_0$), and the final step uses a terminal rule $A_n \to b_n$. Matching against $w = a_0 a_1 \cdots a_n$, we read off $b_i = a_i$ for $i = 0, 1, \dots, n$.
We decode each rule back into a $D$-transition:
- The nonterminal rule $A_{i-1} \to a_{i-1} A_i$ (used at step $i - 1$ for $i = 1, \dots, n$) lies in $P$'s first clause, so $\delta(A_{i-1}, a_{i-1}) = A_i$. Setting $q_i := A_i$ for $i = 0, 1, \dots, n$ (with $q_0 = A_0$ matching the start state), we have $q_{i+1} = A_{i+1} = \delta(A_i, a_i) = \delta(q_i, a_i)$ for $i = 0, \dots, n - 1$.
- The terminal rule $A_n \to a_n$ (used at step $n$) lies in $P$'s second clause, so $\delta(A_n, a_n) \in F$. Setting $q_{n+1} := \delta(q_n, a_n)$, we have $q_{n+1} \in F$.
Hence the sequence $q_0, q_1, \dots, q_{n+1}$ is the run of $D$ on $w$, and $q_{n+1} = \hat{\delta}(q_0, w) \in F$. This establishes $w \in \mathcal{L}(D)$.
Hence $\mathcal{L}(G) \subseteq \{w \in \mathcal{L}(D) : |w| \geq 1\}$.[/step]