BU CS 332 – Theory of Computation
Lecture 6:
- NFAs ‐> Regular expressions
- Context‐free grammars
- Pumping lemma for CFLs
Reading: Sipser Ch 1.3, 2.1, 2.3
Mark Bun February 10, 2020
BU CS 332 Theory of Computation Lecture 6: Reading: NFAs > - - PowerPoint PPT Presentation
BU CS 332 Theory of Computation Lecture 6: Reading: NFAs > Regular expressions Sipser Ch 1.3, Context free grammars 2.1, 2.3 Pumping lemma for CFLs Mark Bun February 10, 2020 Regular Expressions Syntax A regular
Reading: Sipser Ch 1.3, 2.1, 2.3
Mark Bun February 10, 2020
A regular expression is defined recursively using the following rules: 1. , , and are regular expressions for every
and are regular expressions, then so are
Examples: (over )
∗ ∗ ∗ ∗
2/10/2020 CS332 ‐ Theory of Computation 2
the language a regular expression describes 1. 2. 3. for every
Example:
∗ ∗
CS332 ‐ Theory of Computation 3
Theorem: A language is regular if and only if it is described by a regular expression Theorem 1: Every regular expression has an equivalent NFA Theorem 2: Every NFA has an equivalent regular expression
2/10/2020 CS332 ‐ Theory of Computation 4
Theorem 2: Every NFA has an equivalent regex Proof idea: Simplify NFA by “ripping out” states one at a time and replacing with regexes
2/10/2020 CS332 ‐ Theory of Computation 5
1 01*0
2/10/2020 CS332 ‐ Theory of Computation 6
∗
𝑡 𝑏
2/10/2020 CS332 ‐ Theory of Computation 7
𝑡 𝑏
∗
𝑡 𝑏
2/10/2020 CS332 ‐ Theory of Computation 8
NFA GNFA GNFA GNFA Regex 𝑙 states 𝑙 2 states 𝑙 1 states 2 states …
2/10/2020 CS332 ‐ Theory of Computation 9
ε ε ε ε
Idea: While the machine has more than 2 states, rip one
missing state
2/10/2020 CS332 ‐ Theory of Computation 10
∗
1 3 2 1 3
Idea: While the machine has more than 2 states, rip one
missing state
2/10/2020 CS332 ‐ Theory of Computation 11
∗
1 3 2 1 3
Idea: While the machine has more than 2 states, rip one
missing state
2/10/2020 CS332 ‐ Theory of Computation 12
∗
1 3 2 1 3
Idea: While the machine has more than 2 states, rip one
missing state
2/10/2020 CS332 ‐ Theory of Computation 13
1 3 2 1 2 3 4 1 3
2/10/2020 CS332 ‐ Theory of Computation 14
2/10/2020 CS332 ‐ Theory of Computation 15
2/10/2020 CS332 ‐ Theory of Computation 16
2/10/2020 CS332 ‐ Theory of Computation 17
An abstract model for two distinct problems Rules for parsing natural languages
2/10/2020 CS332 ‐ Theory of Computation 18
An abstract model for two distinct problems Specification of syntax and compilation for programming languages
2/10/2020 CS332 ‐ Theory of Computation 19
1977 ACM Turing Award citation (John Backus) For profound, influential, and lasting contributions to the design of practical high‐ level programming systems, notably through his work on FORTRAN, and for seminal publication of formal procedures for the specification of programming languages.
Example Grammar Derivation
2/10/2020 CS332 ‐ Theory of Computation 20
Example Grammar 𝐻 𝐹 → 𝐹 𝑈 𝐹 → 𝑈 𝑈 → 𝑈 𝐺 𝑈 → 𝐺 𝐺 → 𝐹 𝐺 → 𝑏 𝐺 → 𝑐 Derivation 𝑀𝐻
2/10/2020 CS332 ‐ Theory of Computation 21
2/10/2020 CS332 ‐ Theory of Computation 22
<PHRASE> → <START><END> <PHRASE> → <FILLER><PHRASE> <FILLER> → LIKE <FILLER> → UMM <START> → YOU KNOW <END> → WHOOPS <START> → ε <END> → SORRY <END> → $#@!
2/10/2020 CS332 ‐ Theory of Computation 23
<PHRASE> → <FILLER><PHRASE> | <START><END> <FILLER> → LIKE | UMM <START> → YOU KNOW | ε <END> → WHOOPS | SORRY | $#@!
A CFG is a 4‐tuple
, where and
∗
Example: where
2/10/2020 CS332 ‐ Theory of Computation 24
A CFG is a 4‐tuple = variables = terminals = rules = start
(“ yields ”) if is a rule of the grammar
⇒ ∗
(“ derives ”) if
sequence such that
∗ ⇒ ∗
Example: where
CS332 ‐ Theory of Computation 25
Give context‐free grammars for the following languages
2/10/2020 CS332 ‐ Theory of Computation 26
2/10/2020 CS332 ‐ Theory of Computation 27
2/10/2020 CS332 ‐ Theory of Computation 28
2/10/2020 CS332 ‐ Theory of Computation 29
Let be a regular language. Then there exists a “pumping length” such that 1. 2. 3.
𝑗
for all For every where , can be split into three parts where:
2/10/2020 CS332 ‐ Theory of Computation 30
Let be a context‐free language. Then there exists a “pumping length” such that 1. 2. 3.
𝑗 𝑗
for all For every where , can be split into five parts where: Example:
∗
2/10/2020 CS332 ‐ Theory of Computation 31
Let be a context‐free language. Then there exists a “pumping length” such that 1. 2. 3.
𝑗 𝑗
for all For every where , can be split into five parts where: Example:
∗
2/10/2020 CS332 ‐ Theory of Computation 32
Pumping Lemma: |𝑤𝑧| 0 and |𝑤𝑦𝑧| 𝑞.
If regardless of how the ADVERSARY plays this game, you can always win, then is non context‐free
2/10/2020 CS332 ‐ Theory of Computation 33
Claim:
Proof: Assume is regular with pumping length
with
cannot be pumped If = with | | , then…