BU CS 332 Theory of Computation Lecture 5: Reading: More on - - PowerPoint PPT Presentation

bu cs 332 theory of computation
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

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

slide-2
SLIDE 2

More on Pumping

2/5/2020 CS332 ‐ Theory of Computation 2

slide-3
SLIDE 3

Pumping Lemma (Formal)

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:

slide-4
SLIDE 4

General Strategy for proving is not regular

2/5/2020 CS332 ‐ Theory of Computation 4

Proof by contradiction: assume is regular. Then there is a pumping length .

  • 1. Find

with

  • 2. Show that

cannot be pumped

  • 3. Conclude must not have been regular
slide-5
SLIDE 5

Pumping down

2/5/2020 CS332 ‐ Theory of Computation 5

Claim:

  • is not regular

Proof: Assume is regular with pumping length

  • 1. Find

with

  • 2. Show that

cannot be pumped Formally If = with | | , then…

slide-6
SLIDE 6

Reusing a Proof

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?

slide-7
SLIDE 7

Using Closure Properties

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, for one language,

, R, * By contradiction: If is regular, then is regular. (regular) But is not regular so neither is !

slide-8
SLIDE 8

Example

2/5/2020 CS332 ‐ Theory of Computation 8

Prove

  • is not regular

using nonregular language

  • and regular language

all s in appear before all s

slide-9
SLIDE 9

Regular Expressions

2/5/2020 CS332 ‐ Theory of Computation 9

slide-10
SLIDE 10

Regular Expressions

  • A different way of describing regular languages
  • A regular expression expresses a (possibly complex)

language by combining simple languages using the regular operations “Simple” languages: for some Regular operations: Union: Concatenation: Star:

  • … |

and

  • 2/5/2020

CS332 ‐ Theory of Computation 10

slide-11
SLIDE 11

Regular Expressions – Syntax

A regular expression is defined recursively using the following rules: 1. , , and are regular expressions for every

  • 2. If

and are regular expressions, then so are

  • ,
  • , and

Examples: (over )

∗ ∗ ∗ ∗

2/5/2020 CS332 ‐ Theory of Computation 11

slide-12
SLIDE 12

Regular Expressions – Semantics

the language a regular expression describes 1. 2. 3. for every

  • 6.

Example:

∗ ∗

2/5/2020 CS332 ‐ Theory of Computation 12

slide-13
SLIDE 13

Simplifying Notation

  • Omit symbol:
  • Omit many parentheses, since union and concatenation

are associative: = =

  • Order of operations: Evaluate star, then concatenation,

then union

∗ ∗

2/5/2020 CS332 ‐ Theory of Computation 13

slide-14
SLIDE 14

Examples

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

slide-15
SLIDE 15

Syntactic Sugar

  • For alphabet , the regex represents
  • For regex , the regex

Not captured by regular expressions: Backreferences

2/5/2020 CS332 ‐ Theory of Computation 15

slide-16
SLIDE 16

Equivalence of Regular Expressions, NFAs, and DFAs

2/5/2020 CS332 ‐ Theory of Computation 16

slide-17
SLIDE 17

Regular Expressions Describe Regular Languages

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

slide-18
SLIDE 18

Regular expression ‐> NFA

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

slide-19
SLIDE 19

Regular expression ‐> NFA

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

slide-20
SLIDE 20

Example

Convert

∗ to an NFA

2/5/2020 CS332 ‐ Theory of Computation 20

slide-21
SLIDE 21

Example

2/5/2020 CS332 ‐ Theory of Computation 21