CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 13
Exercises • Write Regular Expressions and construct FSA for each of the following languages over Σ = {𝑎 𝑏} • Language of all those strings which begin with aba • Language of all those strings which end with aba • Language of all those strings which contain odd number of b’s • Language of all those strings whose length is greater than 3 • Language of all those strings whose length is a multiple of 3 • Language of all those strings whose length is even and last symbol is b • Language of all those strings in which second last symbol is b • Language of all those strings whose length is odd and second last symbol is b • Language of all those strings which begin and end with different symbols • Language of all those strings in which number of a’s odd and number of b’s is even • Language of all those strings in which every third symbol is b
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 14
Non-deterministic FSA Non-deterministic Finite State Automata • A non-deterministic finite-state automaton (NFA) does not need to have a unique outgoing transition for each alphabet symbol from each state • There can be more than one outgoing transitions from same state having same label • There may be no outgoing transition for a symbol from a given state
• Transitions may have 𝜀 as transition label
• There may be more than one start states
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 16
Possible NFA transitions
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 17
Language of an NFA • When we run a string on an NFA • There can be multiple paths that can be followed • The string may get accepted on some paths • On some paths, the string may get rejected because a non-final state is reached • On some paths, the string may get rejected because NFA crashes
• A string is considered as accepted on an NFA if it is accepted on at
least one path • A string is considered as rejected on an NFA if it is rejected on all paths • Language of an NFA is the set of all strings accepted on the NFA
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 18
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 20
NFA – Examples • Example 3 Σ = {𝑎 𝑏} 𝐿𝑎𝑛𝑔𝑢𝑎𝑔𝑒?
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 21
Regular Languages Equivalence of DFA, NFA and RE • DFA, NFA and Regular Expressions are equivalent • In other words, any language that can be defined by one of these methods, can also be defined by other two • Every NFA can be converted to a DFA • Every DFA can be converted to a regular expression • Every regular expression can be converted to an NFA
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 23
Regular Languages • A language that can be defined by any of these methods: • Regular expression • DFA • NFA
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 24
Regular Languages Theorem: All finite languages are regular Proof: Let L be a finite language having n words as follows: 𝑤1 , 𝑤2 , 𝑤3 , … … , 𝑤𝑛 Then it is possible to write a regular expression for L as: 𝑤1 + 𝑤2 + 𝑤3 + … … + 𝑤𝑛 Therefore L is regular
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 25
Closure Properties of Regular Languages Operations on Languages • Basic operations on languages are: • Union • Intersection • Difference • Product • Complement • Kleene Closure
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 27
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 28
Closure w.r.t. Union Operation Theorem: Let 𝐿1 and 𝐿2 be two regular languages, then so is 𝐿1 ∪ 𝐿2 Proof: Let 𝐿1 and 𝐿2 be defined by regular expressions 𝑅1 and 𝑅2 respectively Then 𝐿1 ∪ 𝐿2 can be defined by regular expression 𝑅1 + 𝑅2 Therefore 𝐿1 ∪ 𝐿2 is regular
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 29
Closure w.r.t. Product Operation Theorem: Let 𝐿1 and 𝐿2 be two regular languages, then so is 𝐿1 𝐿2 Proof: Let 𝐿1 and 𝐿2 be defined by regular expressions 𝑅1 and 𝑅2 respectively Then 𝐿1 𝐿2 can be defined by regular expression 𝑅1 𝑅2 Therefore 𝐿1 𝐿2 is regular
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 30
Closure w.r.t. Kleene Closure Operation Theorem: Let 𝐿 be a regular language, then so is 𝐿∗ Proof: Let 𝐿 be defined by regular expression 𝑅 Then regular expression 𝑅∗ defines the language 𝐿∗ Therefore 𝐿∗ is regular
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 31
Closure w.r.t. Complement Operation Theorem: Let 𝐿 be a regular language, then so is 𝐿′ Proof: Let 𝐿 be defined by FSA 𝐹 Then FSA 𝐹 ′ obtained by making all final states non-final and all non-final states final will accept the language 𝐿′ Therefore 𝐿′ is regular
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 32
Closure w.r.t. Intersection Operation Theorem: Let 𝐿1 and 𝐿2 be two regular languages, then so is 𝐿1 ∩ 𝐿2 Proof: Let 𝐿1 and 𝐿2 be regular languages Then 𝐿′1 and 𝐿′2 both are regular languages 𝐿′1 ∪ 𝐿′2 is a regular language (𝐿′1 ∪ 𝐿′2 )′ is a regular language 𝐿1 ∩ 𝐿2 is a regular language [By DeMorgan’s Law]
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 33
Closure w.r.t. Difference Operation Theorem: Let 𝐿1 and 𝐿2 be two regular languages, then so is 𝐿1 − 𝐿2 Proof: Let 𝐿1 and 𝐿2 be regular languages Then 𝐿1 and 𝐿′2 both are regular languages 𝐿1 ∩ 𝐿′2 is a regular language 𝐿1 − 𝐿2 is a regular language [By Set Difference Law]
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 34
Non-Regular Languages Non-regular Languages • Languages which cannot be defined by DFA, NFA or regular expressions • Example 𝐿 = 𝑎𝑛 𝑏 𝑛 𝑛 ∈ 𝑁} • Why this language is non-regular? • How can we define this language?
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 36
Push Down Automata Push Down Automata • A Push Down Automaton (PDA) consists of • A state machine • A stack
• Each transition has 3 labels written as (𝑥, 𝑦/𝑧)
• 𝑥 is the input symbol; 𝑥 ∈ Σ where Σ is the alphabet set • 𝑦 is the stack symbol (popped); 𝑦 ∈ Γ where Γ is the stack alphabet • 𝑧 is the string pushed into stack; 𝑧 ∈ Γ ∗
• Two outgoing transitions from a state cannot have same 𝑥 𝑎𝑛𝑑 𝑦
• If 𝑥 is 𝜀, there can be no non-𝜀 outgoing transition from that state with same stack symbol 𝑦 • The stack has a special symbol 𝑍 at the bottom CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 38 PDA Example 1 𝐿 = 𝑎𝑛 𝑏 𝑛 𝑛 ∈ 𝑁}
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 39
PDA Example 2 • 𝐿 = 𝑎𝑛 𝑏 𝑛+2 𝑛 ∈ 𝑁}
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 40
PDA Exercise 1 • 𝐿 = 𝑎𝑛+2 𝑏 𝑛 𝑛 ∈ 𝑁}
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 41
PDA Example 3 • 𝐿 = 𝑎𝑛 𝑏 2𝑛 𝑛 ∈ 𝑁}
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 42
PDA Example 4 • 𝐿 = 𝑎2𝑛 𝑏 𝑛 𝑛 ∈ 𝑁}
CS5113 Advanced Theory of Computation – by Dr. Aamer Nadeem Spring 2022 43