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 R1 We can produce a CFG G1 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 Si for each state qi of the DFA.
  2. Add the rule SiaSj to the CFG if δ(qi,a)=qj is a transition in the DFA.
  3. Add the rule Si → ε if qi is an accept state of the DFA.
  4. Make S0 the start variable of the grammar, where q0 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Σ|w has an odd number of 1s}
(Wait; then Click)



OddOnes-to-CFG



if A is S0 and B is S1: SgSASAg0SASAg1SBSBgϵSBg0SBSBg1SA



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 uvi) 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 uvixyiz
    is the length of w plus any added repetitions of v and y
  2. So, uvixyiz is w+(i1)vy
  3. Since we said w is in PRIMEAL, then w is some prime number pN.
  4. Then, uvixyiz∣=∣w+(i1)vy∣=p+(i1)vy
  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 i1 is equal to p in the following expression:
uvixyiz∣=∣w+(i1)vy∣=p+(i1)vy
Then substituting i1 for p ( by making i=p1), we would get: uvixyiz∣=∣w+(i1)vy∣=p+pvy=p(1+vy) 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? {ϵ,01,0011,}
  • 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