SmithLogo

CSC 250

Theory of Computation

Smith Computer Science



Lecture Notes 13: More CFGs and Intro to Push-Down Automata


Outline

This class we'll discuss:




Recap: CFGs



CFGs!!!





All REs can be created with CFGs

Approach 1: Recursive creation of CFG from definition of REs

For any RE \(R_1\) We can produce a CFG \(G_1\) by applying the following steps:





Approach 2: RL's are a special case of CFLs

You can convert any DFA into an equivalent CFG as follows.

  1. Make a variable \(S_i\) for each state \(q_i\) of the DFA.
  2. Add the rule \(S_i\) ā†’ \(aS_j\) to the CFG if \(\delta (q_i,a) = q_j\) is a transition in the DFA.
  3. Add the rule \(S_i\) ā†’ Īµ if qi is an accept state of the DFA.
  4. Make \(S_0\) the start variable of the grammar, where \(q_0\) is the start state of the machine.


Verify on your own that the resulting CFG generates the same language that the DFA recognizes.



Activity 1 [2 minutes]:
Try to build your own CFG. One that "Accepts" the language: \[ L = \{ w \in \Sigma^* \vert w \ has \ an \ odd \ number \ of \ 1s \}\]
(Wait; then Click)



OddOnes-to-CFG



if A is \(S_0\) and B is \(S_1\): \[ \begin{alignat}{2} S &\rightarrow_g S_A \\ S_A &\rightarrow_g 0S_A \\ S_A &\rightarrow_g 1S_B \\ S_B &\rightarrow_g \epsilon \\ S_B &\rightarrow_g 0S_B \\ S_B &\rightarrow_g 1S_A \\ \end{alignat} \]



CFGs!!!

How do we prove there are languages that are NOT (beyond) CFLs?



How did we do this back when we did it for RLs?





CFGs!!!



Note that RLs are a special case of Context-Free-Languages (without the \(uv^i\)) part.



So, if we have a pumping lemma for CFGs, is there a "Machine" equivalent to the Finite Automatons as well?



We'll see those next class.




Proving a language is NOT context-free



CFGs!!!





What does your untuition say? Is it a CFL?





CFGs!!!



Remember:

(Wait; then Click)

Steps:
  1. The length of a word \(\mid uv^ixy^iz \mid \)
    is the length of \( \mid w \mid \) plus any added repetitions of \(v\) and \(y\)
  2. So, \( \mid uv^ixy^iz \mid \) is \( \mid w\mid + (i-1)\mid vy \mid \)
  3. Since we said \(w\) is in PRIMEAL, then \( \mid w\mid \) is some prime number \(p\geq N \).
  4. Then, \( \mid uv^ixy^iz \mid = \mid w\mid + (i-1)\mid vy \mid = p + (i-1)\mid vy \mid\)
  5. Now, What possible choice of \(i\) could we choose to cause the overall length to be provably NOT prime?
(Wait; then Click)

If we choose \(i\) so that the \(i-1\) is equal to \(p\) in the following expression:
\[ \mid uv^ixy^iz \mid = \mid w\mid + (i-1)\mid vy \mid = p + (i-1)\mid vy \mid \]
Then substituting \(i-1\) for \(p\) ( by making \(i = p-1\)), we would get: \[ \mid uv^ixy^iz \mid = \mid w \mid + (i-1)\mid vy \mid = p + p\mid vy \mid \\ = p (1+\mid vy \mid) \] which means that, after pumping, the word is divisible by \(p\)! and therefore, not of prime length.








Why are CFGs important?



CFGs!!!

check the article out: https://www.nature.com/articles/nature04675

PDAs!!!



PDAs!!!



PDAs!!!




Push-Down Automata



PDAs!!!



PDAs!!!



PDAs!!!



PDAs!!!

Activity 1 [2 minutes]:

What is the language that these rules are describing?
(Wait; then Click)

  • are these a valid words? \(\{ \epsilon, 01, 0011, \dots \} \)
  • We know this language!! What is it called?

Now, let's try to buid an automaton that can keep track of all of this


PDAs!!!

Notes

PDAs!!!







So now, let's draw the PDA for HALF



An example for HALF:



PDAs!!!

And in a "compressed notation":

PDAs!!!



PDAs!!!

Note that we defined an Augmented NON-Deterministic Automaton

PDAs!!!



PDAs!!!



PDAs!!!



PDAs!!!

Tips: Activity 2 [2 minutes]:
Build the PDA for PAL
(Wait; then Click)



PDAs!!!



PDAs!!!



PDAs!!!




Next class: Practice with CFGs and PDAs




Homework


[Due for everyone]
problem Set 4 due October 13th 11:59 PM

[Optional]
TODO