BU CS 332 Theory of Computation Lecture 2: Reading: Deterministic - - PowerPoint PPT Presentation

โ–ถ
bu cs 332 theory of computation
SMART_READER_LITE
LIVE PREVIEW

BU CS 332 Theory of Computation Lecture 2: Reading: Deterministic - - PowerPoint PPT Presentation

BU CS 332 Theory of Computation Lecture 2: Reading: Deterministic Finite Automata Sipser Ch 1.1-1.2 Regular Operations Non-deterministic FAs Mark Bun January 27, 2020 Deterministic Finite Automata 1/26/2020 CS332 - Theory


slide-1
SLIDE 1

BU CS 332 โ€“ Theory of Computation

Lecture 2:

  • Deterministic Finite

Automata

  • Regular Operations
  • Non-deterministic FAs

Reading: Sipser Ch 1.1-1.2

Mark Bun January 27, 2020

slide-2
SLIDE 2

Deterministic Finite Automata

1/26/2020 CS332 - Theory of Computation 2

slide-3
SLIDE 3

A (Real-Life?) Example

  • Example: Car stereo
  • ๐‘„ = Power button (ON/OFF)
  • ๐‘‡ = Source button (cycles through Radio/Bluetooth/USB)

Only works when stereo is ON, but source remembered when stereo is OFF

  • Starts OFF in Radio mode
  • A computational problem: Does a sequence of button

presses in {๐‘„, ๐‘‡}โˆ— leave the stereo ON in USB mode?

1/26/2020 CS332 - Theory of Computation 3

slide-4
SLIDE 4

Machine Models

  • Finite Automata (FAs): Machine with a finite amount of

unstructured memory

1/26/2020 CS332 - Theory of Computation 4

Input ๐‘„ ๐‘‡ ๐‘„ ๐‘‡ Finite control โ€ฆ

Control scans left-to-right

slide-5
SLIDE 5

A DFA for the car stereo problem

1/26/2020 CS332 - Theory of Computation 5

slide-6
SLIDE 6

A DFA for Parity

Parity: Given a string consisting of ๐‘โ€™s and ๐‘โ€™s, does it contain an even number of ๐‘โ€™s? ฦฉ = {๐‘, ๐‘} ๐‘€ = {๐‘ฅ | ๐‘ฅ contains an even number of ๐‘โ€™s}

1/26/2020 CS332 - Theory of Computation 6

slide-7
SLIDE 7

Anatomy of a DFA

1/26/2020 CS332 - Theory of Computation 7

๐’“๐Ÿ‘ 0,1 1 1 1 ๐’“๐Ÿ ๐’“๐Ÿ ๐’“๐Ÿ’

slide-8
SLIDE 8

Formal Definition of a DFA

1/26/2020 CS332 - Theory of Computation 8

๐‘… is the set of states ฮฃ is the alphabet ๏ค โˆถ ๐‘… ร— ฮฃ โ†’ ๐‘… is the transition function ๐‘Ÿ0 ๏ƒŽ ๐‘… is the start state ๐บ โІ ๐‘… is the set of accept states

A finite automaton is a 5-tuple ๐‘ = (๐‘…, ฮฃ, ๏ค, ๐‘Ÿ0, ๐บ)

slide-9
SLIDE 9

A DFA for Parity

Parity: Given a string consisting of ๐‘โ€™s and ๐‘โ€™s, does it contain an even number of ๐‘โ€™s? ฦฉ = {๐‘, ๐‘} ๐‘€ = {๐‘ฅ | ๐‘ฅ contains an even number of ๐‘โ€™s}

1/26/2020 CS332 - Theory of Computation 9

๐‘Ÿ0 ๐‘Ÿ1 ๐‘ ๐‘ ๐‘ ๐‘ State set ๐‘… = Alphabet ฦฉ = Transition function ๐œ€ Start state ๐‘Ÿ0 Set of accept states ๐บ =

๐œ€ ๐‘ ๐‘ ๐‘Ÿ0 ๐‘Ÿ1

slide-10
SLIDE 10

Formal Definition of DFA Computation

1/26/2020 CS332 - Theory of Computation 10

๐‘€(๐‘) = the language of machine ๐‘ = set of all (finite) strings machine ๐‘ accepts ๐‘ recognizes the language ๐‘€(๐‘) A DFA ๐‘ = (๐‘…, ฮฃ, ๏ค, ๐‘Ÿ0, ๐บ) accepts a string ๐‘ฅ = ๐‘ฅ1๐‘ฅ2 ยท ยท ยท ๐‘ฅ๐‘œ โˆˆ ฮฃโˆ— (where each ๐‘ฅ๐‘— โˆˆ ฮฃ) if there exist ๐‘ 

0, . . . , ๐‘  ๐‘œ โˆˆ ๐‘… such that

1. ๐‘ 

0 = ๐‘Ÿ0

2. ๐œ€(๐‘ 

๐‘—, ๐‘ฅ๐‘—+1) = ๐‘  ๐‘—+1 for each ๐‘— = 0, . . . , ๐‘œ โˆ’ 1, and

  • 3. ๐‘ 

๐‘œ โˆˆ ๐บ

slide-11
SLIDE 11

Example: Computing with the Parity DFA

1/26/2020 CS332 - Theory of Computation 11

๐‘Ÿ0 ๐‘Ÿ1 ๐‘ ๐‘ ๐‘ ๐‘ A DFA ๐‘ = (๐‘…, ฮฃ, ๏ค, ๐‘Ÿ0, ๐บ) accepts a string ๐‘ฅ = ๐‘ฅ1๐‘ฅ2 ยท ยท ยท ๐‘ฅ๐‘œ โˆˆ ฮฃโˆ— (where each ๐‘ฅ๐‘— โˆˆ ฮฃ) if there exist ๐‘ 

0, . . . , ๐‘  ๐‘œ โˆˆ ๐‘… such that

1. ๐‘ 

0 = ๐‘Ÿ0

2. ๐œ€(๐‘ 

๐‘—, ๐‘ฅ๐‘—+1) = ๐‘  ๐‘—+1 for each ๐‘— = 0, . . . , ๐‘œ โˆ’ 1, and

  • 3. ๐‘ 

๐‘œ โˆˆ ๐บ

Let ๐‘ฅ = ๐‘๐‘๐‘๐‘ Does ๐‘ accept ๐‘ฅ?

slide-12
SLIDE 12

Automata Tutor

1/26/2020 CS332 - Theory of Computation 12

http://automatatutor.com/

slide-13
SLIDE 13

Regular Languages

1/26/2020 CS332 - Theory of Computation 13

Definition: A language is regular if it is recognized by a DFA

๐‘ด = { ๐’™ โˆˆ ๐Ÿ, ๐Ÿ โˆ—| ๐’™ contains ๐Ÿ๐Ÿ๐Ÿ } is regular ๐‘ด = { ๐’™ โˆˆ ๐’ƒ, ๐’„ โˆ— | ๐’™ has an even number of ๐’ƒโ€™s } is regular

Many interesting programs recognize regular languages

NETWORK PROTOCOLS COMPILERS GENETIC TESTING ARITHMETIC

slide-14
SLIDE 14

Internet Transmission Control Protocol

1/26/2020 CS332 - Theory of Computation 14

Let TCPS = { ๐‘ฅ | ๐‘ฅ is a complete TCP Session}

  • Theorem. TCPS is regular
slide-15
SLIDE 15

Compilers

1/26/2020 CS332 - Theory of Computation 15

Comments : Are delimited by /* */ Cannot have nested /* */ Must be closed by */ */ is illegal outside a comment

COMMENTS = {strings over {0,1, /, *} with legal comments}

  • Theorem. COMMENTS is regular.
slide-16
SLIDE 16

Genetic Testing

1/26/2020 CS332 - Theory of Computation 16

DNA sequences are strings over the alphabet {๐‘ฉ, ๐‘ซ, ๐‘ฏ, ๐‘ผ}. A gene ๐’‰ is a special substring over this alphabet. A genetic test searches a DNA sequence for a gene. GENETICTEST๐’‰ = {strings over {๐‘ฉ, ๐‘ซ, ๐‘ฏ, ๐‘ผ} containing ๐’‰ as a substring}

  • Theorem. GENETICTEST๐’‰is regular for every gene ๐’‰.
slide-17
SLIDE 17

Arithmetic

1/26/2020 CS332 - Theory of Computation 17

LET ๏“3 =

  • A string over ๏“3 has three ROWS (ROW1, ROW2, ROW3)
  • Each ROW ๐’„๐Ÿ๐’„๐Ÿ๐’„๐Ÿ‘ โ€ฆ ๐’„๐‘ถ represents the integer

๐’„๐Ÿ + ๐Ÿ‘๐’„๐Ÿ + โ€ฆ + ๐Ÿ‘๐‘ถ๐’„๐‘ถ.

  • Let ADD = {๐‘ป โˆˆ ๏“๐Ÿ’

โˆ— | ROW1 + ROW2 = ROW3 }

  • Theorem. ADD is regular.

{ [ ],[ ],[ ],[ ], [ ],[ ],[ ],[ ]}

1 1 1 1 1 1 1 1 1 1 1 1

slide-18
SLIDE 18

Regular Operations

1/26/2020 CS332 - Theory of Computation 18

slide-19
SLIDE 19

An Analogy

In algebra, we try to identify operations which are common to many different mathematical structures

1/26/2020 CS332 - Theory of Computation 19

Example: The integers โ„ค = {โ€ฆ โˆ’ 2, โˆ’1, 0, 1, 2, โ€ฆ } are closed under

  • Addition: ๐‘ฆ + ๐‘ง
  • Multiplication: ๐‘ฆ ร— ๐‘ง
  • Negation: โˆ’๐‘ฆ
  • โ€ฆbut NOT Division: ๐‘ฆ / ๐‘ง

Weโ€™d like to investigate similar closure properties of the class of regular languages

slide-20
SLIDE 20

Regular operations on languages

Let ๐ต, ๐ถ โІ ฮฃโˆ— be languages. Define Union: ๐ต โˆช ๐ถ = Concatenation: ๐ต โˆ˜ ๐ถ = Star: ๐ตโˆ— =

1/26/2020 CS332 - Theory of Computation 20

slide-21
SLIDE 21

Other operations

Let ๐ต, ๐ถ โІ ฮฃโˆ— be languages. Define Complement: าง ๐ต = Intersection: ๐ต โˆฉ ๐ถ = Reverse: ๐ต๐‘† =

1/26/2020 CS332 - Theory of Computation 21

slide-22
SLIDE 22

Closure properties of the regular languages

Theorem: The class of regular languages is closed under all three regular operations (union, concatenation, star), as well as under complement, intersection, and reverse. i.e., if ๐ต and ๐ถ are regular, applying any of these

  • perations yields a regular language

1/26/2020 CS332 - Theory of Computation 22

slide-23
SLIDE 23

Proving Closure Properties

1/26/2020 CS332 - Theory of Computation 23

slide-24
SLIDE 24

Complement

Complement: าง ๐ต = ๐‘ฅ ๐‘ฅ โˆ‰ ๐ต} Theorem: If ๐ต is regular, then าง ๐ต is also regular Proof idea:

1/26/2020 CS332 - Theory of Computation 24

slide-25
SLIDE 25

Union

1/26/2020 CS332 - Theory of Computation 25

Union: ๐ต โˆช ๐ถ = ๐‘ฅ ๐‘ฅ โˆˆ ๐ต or ๐‘ฅ โˆˆ ๐ถ} Theorem: If ๐ต and ๐ถ are regular, then so is ๐ต โˆช ๐ถ Proof: Let ๐‘๐ต = (๐‘…๐ต, ฮฃ, ๏ค๐ต, ๐‘Ÿ0

๐ต, ๐บ๐ต) be a DFA recognizing ๐ต and

๐‘๐ถ = (๐‘…๐ถ, ฮฃ, ๏ค๐ถ, ๐‘Ÿ0

๐ถ, ๐บ๐ถ) be a DFA recognizing ๐ถ

Goal: Construct a DFA ๐‘ = ๐‘…, ฮฃ, ๏ค, ๐‘Ÿ0, ๐บ that recognizes ๐ต โˆช ๐ถ

slide-26
SLIDE 26

Example

1/26/2020 CS332 - Theory of Computation 26

๐‘Ÿ0

๐ต

๐‘Ÿ1

๐ต

1 1

๐‘Ÿ0

๐ถ

๐‘Ÿ1

๐ถ

1 1

๐‘ต๐‘ฉ ๐‘ต๐‘ช

๐‘ต = ?

slide-27
SLIDE 27

Closure under union proof (contโ€™d)

Idea: Run both ๐‘๐ต and ๐‘๐ถ at the same time โ€œCross-product constructionโ€ ๐‘… = ๐‘…๐ต ร— ๐‘…๐ถ = {(๐‘Ÿ๐ต, ๐‘Ÿ๐ถ) |๐‘Ÿ๐ต โˆˆ ๐ต and ๐‘Ÿ๐ถ โˆˆ ๐ถ} ๏ค( (๐‘Ÿ๐ต, ๐‘Ÿ๐ถ), ๏ณ) = (๏ค๐ต(๐‘Ÿ๐ต, ๏ณ), ๏ค๐ถ(๐‘Ÿ๐ถ, ๏ณ)) ๐‘Ÿ0 = (๐‘Ÿ0

๐ต, ๐‘Ÿ0 ๐ถ)

๐บ = {(๐‘Ÿ๐ต, ๐‘Ÿ๐ถ) |๐‘Ÿ๐ต โˆˆ ๐บ๐ต or ๐‘Ÿ๐ถ โˆˆ ๐บ๐ถ} = ๐บ๐ต ร— ๐‘…๐ถ โˆช ๐‘…๐ต ร— ๐บ๐ถ

1/26/2020 CS332 - Theory of Computation 27

slide-28
SLIDE 28

Example (contโ€™d)

1/26/2020 CS332 - Theory of Computation 28

๐‘Ÿ0

๐ต

๐‘Ÿ1

๐ต

1 1

๐‘Ÿ0

๐ถ

๐‘Ÿ1

๐ถ

1 1

๐‘ต๐‘ฉ

๐‘ต

๐‘ต๐‘ช

slide-29
SLIDE 29

Intersection

1/26/2020 CS332 - Theory of Computation 29

Intersection: ๐ต โˆฉ ๐ถ = ๐‘ฅ ๐‘ฅ โˆˆ ๐ต and ๐‘ฅ โˆˆ ๐ถ} Theorem: If ๐ต and ๐ถ are regular, then so is ๐ต โˆฉ ๐ถ Proof: Let ๐‘๐ต = (๐‘…๐ต, ฮฃ, ๏ค๐ต, ๐‘Ÿ0

๐ต, ๐บ๐ต) be a DFA recognizing ๐ต and

๐‘๐ถ = (๐‘…๐ถ, ฮฃ, ๏ค๐ถ, ๐‘Ÿ0

๐ถ, ๐บ๐ถ) be a DFA recognizing ๐ถ

Goal: Construct a DFA ๐‘ = ๐‘…, ฮฃ, ๏ค, ๐‘Ÿ0, ๐บ that recognizes ๐ต โˆฉ ๐ถ

slide-30
SLIDE 30

Intersection

1/26/2020 CS332 - Theory of Computation 30

Intersection: ๐ต โˆฉ ๐ถ = ๐‘ฅ ๐‘ฅ โˆˆ ๐ต and ๐‘ฅ โˆˆ ๐ถ} Theorem: If ๐ต and ๐ถ are regular, then so is ๐ต โˆฉ ๐ถ Another Proof: ๐ต โˆฉ ๐ถ = าง ๐ต โˆช เดค ๐ถ

slide-31
SLIDE 31

Reverse

1/26/2020 CS332 - Theory of Computation 31

Reverse: ๐ต๐‘† = ๐‘ฅ1๐‘ฅ2 ยท ยท ยท ๐‘ฅ๐‘œ ๐‘ฅ๐‘œ ยท ยท ยท ๐‘ฅ1 โˆˆ ๐ต} Theorem: If ๐ต is regular, then ๐ต๐‘† is also regular Proof idea: Let ๐‘ = (๐‘…, ฮฃ, ๏ค, ๐‘Ÿ0, ๐บ) be a DFA recognizing ๐ต Goal: Construct a DFA ๐‘โ€ฒ = ๐‘…โ€ฒ, ฮฃ, ๏คโ€ฒ, ๐‘Ÿ0

โ€ฒ , ๐บโ€ฒ

that recognizes ๐ต๐‘† Define ๐‘โ€ฒ as ๐‘ but

  • With the arrows reversed
  • With start and accept states swapped
slide-32
SLIDE 32

Example (Reverse)

1/26/2020 CS332 - Theory of Computation 32

1 1 1 0,1

๐‘ต ๐‘ตโ€ฒ

slide-33
SLIDE 33

Closure under reverse

๐‘โ€™ is not always a DFA!

  • It might have many start states
  • Some states may have too many outgoing edges, or

none at all

1/26/2020 CS332 - Theory of Computation 33

slide-34
SLIDE 34

Nondeterminism

1/26/2020 CS332 - Theory of Computation 34

1 1 1 0,1 A Nondeterministic Finite Automaton (NFA) accepts if there is a way to make it reach an accept state.

slide-35
SLIDE 35

Example

1/26/2020 CS332 - Theory of Computation 35

1

๐‘ด(๐‘ต) =

๐œป ๐œป

slide-36
SLIDE 36

Example

1/26/2020 CS332 - Theory of Computation 36

0,1 0,๐œป 1 0,1 1

๐‘ด(๐‘ต) =

slide-37
SLIDE 37

Formal Definition of a NFA

1/26/2020 CS332 - Theory of Computation 37

๐‘… is the set of states ฮฃ is the alphabet ๏ค โˆถ ๐‘… ร— ฮฃ๐œ โ†’ ๐‘„(๐‘…) is the transition function ๐‘Ÿ0 ๏ƒŽ ๐‘… is the start state ๐บ โІ ๐‘… is the set of accept states

An NFA is a 5-tuple ๐‘ = (๐‘…, ฮฃ, ๏ค, ๐‘Ÿ0, ๐บ)

๐‘ accepts a string ๐‘ฅ if there exists a path from ๐‘Ÿ0 to an accept state that can be followed by reading ๐‘ฅ.

slide-38
SLIDE 38

Example

1/26/2020 CS332 - Theory of Computation 38

1 ๐œป ๐œป ๏ค(๐’“๐Ÿ’, ๐Ÿ) = ๐‘ต = (๐‘น, ๐šป, ๏ค, ๐‘น๐Ÿ, ๐‘ฎ) ๐‘น = {๐’“๐Ÿ, ๐’“๐Ÿ, ๐’“๐Ÿ‘, ๐’“๐Ÿ’, ๐’“๐Ÿ“} ๐šป = {๐Ÿ, ๐Ÿ} ๐‘ฎ = {๐’“๐Ÿ“} ๏ค(๐’“๐Ÿ‘, ๐Ÿ) = ๐’“๐Ÿ ๐’“๐Ÿ‘ ๐’“๐Ÿ’ ๐’“๐Ÿ“ ๐’“๐Ÿ

slide-39
SLIDE 39

Example

1/26/2020 CS332 - Theory of Computation 39

0,1 0,๐œป 1 0,1 1 ๐’“๐Ÿ ๐’“๐Ÿ‘ ๐’“๐Ÿ’ ๐’“๐Ÿ ๐‘ถ = (๐‘น, ๐šป, ๏ค, ๐’“๐Ÿ, ๐‘ฎ) ๐‘น = {๐’“๐Ÿ, ๐’“๐Ÿ, ๐’“๐Ÿ‘, ๐’“๐Ÿ’} ๐šป = {๐Ÿ, ๐Ÿ} ๐‘ฎ = {๐’“๐Ÿ’} ๏ค(๐’“๐Ÿ, ๐Ÿ) = ๏ค(๐’“๐Ÿ‘, ๐Ÿ) = ๏ค(๐’“๐Ÿ, ๐Ÿ) = ๏ค(๐’“๐Ÿ, ๐œป) =

slide-40
SLIDE 40

Nondeterminism

1/26/2020 CS332 - Theory of Computation 40

Ways to think about nondeterminism

  • (restricted)

parallel computation

  • tree of possible

computations

  • guessing and

verifying the โ€œrightโ€ choice Deterministic Computation Nondeterministic Computation accept or reject accept reject