\begin{frame}{Removal of Useless Variables}
    A variable $A$ is \emph{useless} for a context-free grammar 
    if there exists \alert{no} derivation of the form 
      S \; \Rightarrow^* \; uAv \; \Rightarrow^+ \; w \quad\quad \text{with $w \in T^*$.}
    Removing production rules that contain a useless variable from a grammar 
    does not change the generated language.
      S &\to aSb \mid BC \mid \lambda &
      A &\to Sb &
      B &\to a &
      C &\to C
    Which variables are useless?
      \item $A$ because there is no derivation $S \Rightarrow^* uAv$
      \item $C$ because there is no derivation $C \Rightarrow^* w$ with $w \in T^*$
      \item $B$ because $B$ can be reached only together with $C$
    The resulting grammar is \alert{$S \to aSb \mid \lambda$}.