Regular Language + Pushdown automatA
memory of Pushdown Automata (PDA) class is structured as
"STACK". Both deterministic and nondeterministic PDAs can be defined
How PDAs Reject Strings
*They do NOT halt. ≡ ~h OR At least one symbol of w is NOT consumed. ≡ ~c OR They are NOT in an accepting (final) state. ≡ ~f
How PDAs Accept Strings
*They halt. ≡ h AND All symbols of w are consumed. ≡ c AND They are in an accepting (final) state. ≡ f
Stack structure(LIFO) The basic operations on stacks are "pop" and "push
- divided into cells and each cell can hold one symbol.. - The SPECIAL SYMBOL 'Z' is written at the bottom of the stack by the machine at timeframe 0. - When stack pointer is pointing to 'Z', it means that the stack is empty.
How PDAs Work 1. What is the "starting configuration"? 2. What would happen during a timeframe? 3. When would the machines halt (stop)? 4. How would a string be Accepted/Rejected?
1. - Clock: timeframe 0. - Input tape: --> Input string already written on the tape --> cursor is pointing to the left-most symbol. - Stack: initialized by the special symbol 'Z'. stack-pointer is pointing to the 'Z'. - Control Unit: initial state. 2. During a timeframe, the machine "makes a decision" and "transits" (aka "moves") from one configuration to another. Several tasks happen during a timeframe. combination of these tasks is called "transition". --> A symbol at which the cursor is pointing, is consumed. --> A symbol at which stack-pointer is pointing, is popped. --> A string will be pushed into the stack. IF_THEN statement.
What info do we need for the configuration? PDAs' Configuration
1. Current state of transition graph 2. Input string + Position of the cursor 3. Stack and its content
Procedure of Initiating New Processes
1. It replicates its entire structure (transition graph + input tape + stack) 2. It initializes the new process with the current configuration. 3. The new process independently continues processing the rest of the input string.
Push
1. Move the stack-pointer one cell up2. Put the string w in the stack, the right symbol goes first(e.g. if w = cd, push d first, then 'c') ▪ All of these phases happen during one timeframe.
Pop
1. Remove the symbol at which the stack-pointer is pointing 2. Move the stack-pointer one cell down ▪ All of these phases happen during one timeframe.
Stack Notes
1. The "stack's alphabet" and the "input tape's alphabet" can be totally different. . 2. If your algorithm requires, you can push 'Z' as many times as you like, and you can pop even the bottom one!− Therefore, it's designer's responsibility to take care of the contents of the stack. 3. JFLAP works in two modes: "Multiple Character", or "Single Character "We'll use "Multiple Character", means you can push a string.− If you choose "single character", then it does not allow you to put string.
Summary of Transition
1. Zero or one symbol at which cursor is pointing, is consumed. 2. Zero or one symbol at which stack pointer is pointing, is popped. 3. A string (could be empty) is pushed into the stack. 4. The control unit makes its decision and moves based on the "logic of the transition".
▪ What could be those violations?
1. λ-transition 2. When δ is multifunction
multiple labels
A transition might have multiple labels. we stack them over the edge in either conditions, the machine transits and follows the appropriate operations.
How NPDAs Behave If They Have Multiple Choices All types of nondeterministic machines start parallel processing when they have multiple choices.
All types of nondeterministic machines start parallel processing when they have multiple choices. for every possible choice, they create a new process, and . every process independently continues processing the string. ▪ The procedure of initiating new processes is exactly the same as NFAs.
DFAs and NFAs have equal power.
Both recognize regular languages.
NPDAs vs NFAs NFAs Can be Converted Directly to NPDAs
Change all NFAs' sub-rules to NPDAs format by adding λ in the pop and push parts. i.e.: δ (qi , x) = {qj , qj+1 , ... , qj+n} changes to δ (qi , x , λ) = { (qj , λ), (qj+1 , λ), ... , (qj+n , λ) } ▪ Set Γ = {Z}. ▪ Set the stack start symbol as Z. ▪ The rest of the items, (i.e. Q, Σ, q0, F) are the same.
Determinism
During any timeframe, there is no more than one transition. Any violation of this makes a machine nondeterministic.
NPDAs: λ-Transitions
For NPDAs, a transition is called λ-transition ifboth input and pop parts of the label are λ. Note▪ If the machine unconditionally transits to qj, then it should push w.
Reversal
If L is regular language, then L^R is regular language
Complement
If L isregular language, t L̅ is regular language.
Minus
If L1 and L2 are regular languages, then L1 - L2 is regular language.
Concatenation
If L1 and L2 are regular languages, then L1 L2 is regular language.
closure under union
L1 and L2 are regular languages, then L1 ⋃ L2 is regular language
Formal Definition of NPDAs An NPDA M is defined by the septuple (7-tuple): M = (Q, Σ, Γ, δ, q0, Z, F)
M = (Q, Σ, Γ, δ, q0, Z, F) ‒ Q is a finite and nonempty set of states of the transition graph. ‒ Σ is a finite and nonempty set of symbols called input alphabet. ‒ Γ is a finite and nonempty set of symbols called stack alphabet. ‒ δ is called transition function and is defined as: δ: Q x (Σ ⋃ {λ}) x (Γ ⋃ {λ}) → 2Q x Γ* δ is total function. ‒ q0 ∈ Q is the initial state of the transition graph. ‒ Z ∈ Γ is a special symbol called stack start symbol. ‒ F ⊆ Q is the set of accepting states of the transition graph.
Formal Definition of DPDAs DPDA M is defined by the septuple (7-tuple):
M = (Q, Σ, Γ, δ, q0, Z, F) ▪ Where: ‒ Q is a finite and nonempty set of states of the transition graph. ‒ Σ is a finite and nonempty set of symbols called input alphabet. ‒ Γ is a finite and nonempty set of symbols called stack alphabet. ‒ δ is called transition function and is defined as: δ: Q x (Σ ⋃ {λ}) x (Γ ⋃ {λ}) → Q x Γ* δ is partial or total function. ‒ q0 ∈ Q is the initial state of the transition graph. ‒ Z ∈ Γ is a special symbol called stack start symbol. ‒ F ⊆ Q is the set of accepting states of the transition graph.
What was missing in NFAs that made them incapable of recognizing non-regular languages?
Memory!
Are the following transitions violations for determinism NO
NO
Can NFAs Simulate NPDAs? NO
NO▪ There is no way to simulate the stack operations by NFAs!
How NPDAs reject a string
NPDAs reject a string when all processes reject it.
(q2)--m , c ; λ-->(q5)
No further transition : the condition (stack='c') for the next transition is not present. So, it halts in state q2.
(q2)--a , λ ; λ-->(q5)
No further transition: the condition (input='a') for the next transition is not present. So, it halts in state q2.
How NPDAs accept a string
Rule is the same as NFAs': NPDAs accept a string when at least one process accept it.
Write the sub-rule of the following transition over Σ = {a , b} and Γ = {x , y} q2--a , x ; yx-->q5
Solution δ (q2 , a , x) = (q5 , yx) δ (q2 , b , x) = Undefined δ (q2 , a , y) = Undefined δ (q2 , b , y) = Undefined
▪ Write the sub-rule of the following transition of an NPDA over Σ = {a , b} and Γ = {x , y}
Solution ▪ The condition for transition for both edges are the same. ▪ Therefore, we need only one sub-rule. δ (q1 , a , x) = { (q2 , yx) , (q3 , λ) }
PDAs are more powerful than NFAs. TRUE
TRue The set of languages that NFAs recognize is a proper subset of the set of languages that PDAs recognize.
λ-transition in automata theory:
The machine can unconditionally transit. If we put λ in the condition places, we make a λ-transition.
final contents of the stack is NOT important in accepting or rejecting a string.
True
there is no way to simulate a read/write memorylike stack with a read-only memory.
True
Are the following transitions violations for determinism? YES
YES
regular language
a language is called regular if there exists a DFA/NFA to recognize it.
All finite languages are regular.
if L is finite, then L is regular
a , b ; w
input symbol = 'a' AND top of the stack = 'b'
Control Unit: Structure of PDAs
look pretty much like NFAs' represented by "transition graphs only difference is how the edges are labeled.
Relaxing the Conditions and Operations by λ
we put λ in any part of the labels, it means "no condition" or "no action" in that part.
When PDAs Halt
when the next transition conditions are NOT satisfied. they halt when there is ZERO transition. *They do NOT halt. ≡ ~h OR At least one symbol of w is NOT consumed. ≡ ~c OR They are NOT in an accepting (final) state. ≡ ~f
Write the sub-rule of the following transition over Σ = {a , b} and Γ = {x , y} q2-- a ,x, yx ; -->q5
δ (q2 , a , x) = { (q5 , yx) } δ (q2 , b , x) = {} δ (q2 , a , y) = {} δ (q2 , b , y) = {}
Write the sub-rule of the following transition over Σ = {a , b} and Γ = {x , y} q2--a, λ ; yx-->q5
δ (q2 , a , λ) = (q5 , yx) ▪ For the same reason, this is NOT equivalent to: δ (q2 , a , x) = (q5 , yx) δ (q2 , a , y) = (q5 , yx)
Write the sub-rule of the following transition over Σ = {a , b} and Γ = {x , y} q2--λ , x ; yx-->q5
δ (q2 , λ , x) = (q5 , yx) ▪ Is this equivalent to the following two subrules? δ (q2 , a , x) = (q5 , yx) δ (q2 , b , x) = (q5 , yx) -->NO
Write the sub-rule of the following transition over Σ = {a , b} and Γ = {x , y} q2-- λ,x,λ ; -->q5
δ (q2 , λ , x) = (q5 , λ)
if we put λ in the conditions parts, we make a λ-transition.
λ , λ ; w
w is a string and can be λ.
λ , λ ; λ In this case, the machine does not need to do anything if it transits to qj.
λ , a ; λ
‒ Do NOT consume any input symbol AND do NOT push anything! ‒ If the top of the stack is 'a', (Condition) ‒ then pop 'a' AND make the move. (Operation)
λ , a ; xy
‒ Do NOT consume any input symbol! ‒ If top of the stack is 'a', (Condition) ‒ then pop 'a' AND push 'xy' AND make the move. (Operation)
a, λ ; xy
‒ If the input symbol is 'a', (Condition) ‒ Do NOT pop anything! ‒ then consume 'a' AND push 'xy' AND make the move. (Operation)
c , a ; λ
‒ If the input symbol is 'c' AND the top of the stack is 'a', (Condition) ‒ then consume 'c' AND pop 'a' AND make the move. (Operation) ‒ Do NOT push anything!
c , λ ; λ
‒ If the input symbol is 'c', (Condition) ‒ then consume 'c' AND make the move. (Operation) ‒ Do NOT pop anything AND do NOT push anything!
Moreover, we know at least the following languages for which we can construct NPDAs but it is impossible to construct NFAs.
‒ L = {a^nb^n : n ≥ 0} ‒ L = {ww^R : w ∈ Σ*}
Design a PDA to accept the following language: L = {a^nb^n : n ≥ 0} over Σ = {a , b}.
▪ Strategy: read a's and push them in the stack regardless of top of the stack. ▪ When the first b is sensed, start popping a's to match them with b's. ▪ Continue popping a's until you are out of b. ▪ If end of stack is reached, it means the number of a's and b's are equal, so, accept the string.
Control Unit: Labels
▪ The label has 3 parts delimited by comma and semicolon: read, pop; push 1. The input symbol (e.g. 'c') that IS READ from the tape 2. The symbol at the top of the stack (e.g. 'a') that IS POPPED 3. The string (e.g. 'xyz') that WILL BE PUSHED into the stack