BU CS 332 – Theory of Computation
Lecture 5:
- More on pumping
- Regular expressions
- Regular expressions =
regular languages Reading: Sipser Ch 1.3
Mark Bun February 5, 2020
BU CS 332 Theory of Computation Lecture 5: Reading: More on - - PowerPoint PPT Presentation
BU CS 332 Theory of Computation Lecture 5: Reading: More on pumping Sipser Ch 1.3 Regular expressions Regular expressions = regular languages Mark Bun February 5, 2020 More on Pumping 2/5/2020 CS332 Theory of Computation 2
regular languages Reading: Sipser Ch 1.3
Mark Bun February 5, 2020
2/5/2020 CS332 ‐ Theory of Computation 2
2/5/2020 CS332 ‐ Theory of Computation 3
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/5/2020 CS332 ‐ Theory of Computation 4
with
cannot be pumped
2/5/2020 CS332 ‐ Theory of Computation 5
Claim:
Proof: Assume is regular with pumping length
with
cannot be pumped Formally If = with | | , then…
2/5/2020 CS332 ‐ Theory of Computation 6
Pumping a language can be lots of work… Let’s try to reuse that work!
0𝑜1𝑜 𝑜 0 = 𝐶𝐵𝑀𝐵𝑂𝐷𝐹𝐸 ∩ 𝑥 all 0s in 𝑥 appear before all 1s
How might we show that = has an equal # of s and s is not regular?
2/5/2020 CS332 ‐ Theory of Computation 7
∩ = (not regular) If is not regular, we can show a related language is not regular any of , ,
, R, * By contradiction: If is regular, then is regular. (regular) But is not regular so neither is !
2/5/2020 CS332 ‐ Theory of Computation 8
2/5/2020 CS332 ‐ Theory of Computation 9
language by combining simple languages using the regular operations “Simple” languages: for some Regular operations: Union: Concatenation: Star:
∗
and
CS332 ‐ Theory of Computation 10
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/5/2020 CS332 ‐ Theory of Computation 11
the language a regular expression describes 1. 2. 3. for every
Example:
∗ ∗
2/5/2020 CS332 ‐ Theory of Computation 12
are associative: = =
then union
∗ ∗
2/5/2020 CS332 ‐ Theory of Computation 13
Let 1. contains exactly one 2. has length at least 3 and its third symbol is 3. every odd position of is
2/5/2020 CS332 ‐ Theory of Computation 14
Not captured by regular expressions: Backreferences
2/5/2020 CS332 ‐ Theory of Computation 15
2/5/2020 CS332 ‐ Theory of Computation 16
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/5/2020 CS332 ‐ Theory of Computation 17
Theorem 1: Every regex has an equivalent NFA Proof: Induction on size of a regex Base cases:
2/5/2020 CS332 ‐ Theory of Computation 18
Theorem 1: Every regex has an equivalent NFA Proof: Induction on size of a regex Inductive step:
2/5/2020 CS332 ‐ Theory of Computation 19
Convert
∗ to an NFA
2/5/2020 CS332 ‐ Theory of Computation 20
2/5/2020 CS332 ‐ Theory of Computation 21