Lecture Notes 13: More CFGs and Intro to Push-Down Automata
Outline
This class we'll discuss:
- More on CFGs
- Intro to Push-Down Automata
Recap: CFGs
All REs can be created with CFGs
Approach 1: Recursive creation of CFG from definition of REs
For any RE We can produce a CFG by applying the following steps:
- Any base cases can be writen as generation of
for all
- Defining the more complex rules requires combining two rules. The recursive expression based on these two base rules can start with:
(some expression)
(another expression)
and combined to generate more complex expressions:
- Alternation:
(equivalent to A + B for some A, B)
- Concatenation:
(equivalent to A B for some A, B)
- Kleene:
(equivalent to for some A)
Approach 2: RL's are a special case of CFLs
You can convert any DFA into an equivalent CFG as follows.
- Make a variable for each state of the DFA.
- Add the rule → to the CFG if is a transition in the DFA.
- Add the rule → ε if qi is an accept state of the DFA.
- Make the start variable of the grammar, where 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:
(Wait; then Click)
if A is and B is :
How do we prove there are languages that are NOT (beyond) CFLs?
How did we do this back when we did it for RLs?
- the middle part is not too big
- v and y (the repeating parts) are not both simultaneously empty
- repeating v and or y we will keep us in the language
Note that RLs are a special case of Context-Free-Languages (without the ) 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
What does your untuition say? Is it a CFL?
Remember:
- Given a structure of , and
- We want to find an for which a word
does not have a prime length ( is not prime ) after being "pumped" some number of times.
- Here, we can start with a word with length ( provided by the pumping Lemma)
- Now, the trick is to pump the pattern some number of times so that we can prove that the final length is NOT prime!
- Ideas?
(Wait; then Click)
Steps:
- The length of a word
is the length of plus any added repetitions of and
- So, is
- Since we said is in PRIMEAL, then is some prime number .
- Then,
- Now, What possible choice of could we choose to cause the overall length to be provably NOT prime?
(Wait; then Click)
If we choose so that the is equal to in the following expression:
Then substituting for ( by making ), we would get:
which means that, after pumping, the word is divisible by ! and therefore, not of prime length.
Why are CFGs important?
check the article out: https://www.nature.com/articles/nature04675
Push-Down Automata
Activity 1 [2 minutes]:
What is the language that these rules are describing?
(Wait; then Click)
- are these a valid words?
- We know this language!! What is it called?
Now, let's try to buid an automaton that can keep track of all of this
Notes
- we need a notation for READ, POP and PUSH... we'll use:
- we need a symbol for "The stack is currently empty!"... we'll use
- we need to be able to read a symbol without pushing ... we'll use in place of PUSH
- we need to be able to read a symbol without popping ... we'll use in place of POP
- we need to be able to push without reading a symbol ... we'll use in place of READ
- we need to be able to pop without reading a symbol ... we'll use in place of READ
So now, let's draw the PDA for HALF
An example for HALF:
And in a "compressed notation":
Note that we defined an Augmented NON-Deterministic Automaton
Tips:
- Think of phases:
- memorizing
- middle (even or odd)
- replicating in reverse
- write the PDA... and remember it is NON-Deterministic
Activity 2 [2 minutes]:
Build the PDA for PAL
(Wait; then Click)
Next class: Practice with CFGs and PDAs
Homework
[Due for everyone]
problem Set 4 due October 13th 11:59 PM
[Optional]
TODO