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/29/2020 CS332


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/29/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/29/2020 CS332 ‐ Theory of Computation 3

slide-4
SLIDE 4

Machine Models

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

unstructured memory

1/29/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/29/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/29/2020 CS332 ‐ Theory of Computation 6

slide-7
SLIDE 7

Anatomy of a DFA

1/29/2020 CS332 ‐ Theory of Computation 7

𝒓𝟑 0,1 1 1 1 𝒓𝟏 𝒓𝟐 𝒓𝟒

slide-8
SLIDE 8

Formal Definition of a DFA

1/29/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 

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/29/2020 CS332 ‐ Theory of Computation 9

1

State set = Alphabet = Transition function Start state Set of accept states =

𝜀 𝑏 𝑐 𝑟0 𝑟1

slide-10
SLIDE 10

Formal Definition of DFA Computation

1/29/2020 CS332 ‐ Theory of Computation 10

= the language of machine = set of all (finite) strings machine accepts recognizes the language A DFA  accepts a string

  • ∗ (where each
  • ) if there exist

, . . . ,

such that 1.

  • 2.
  • for each

and 3.

slide-11
SLIDE 11

Ex Exam ample: ple: Computing with the Parity DFA

1/29/2020 CS332 ‐ Theory of Computation 11

1

A DFA  accepts a string

  • ∗ (where each
  • ) if there exist

, . . . ,

such that 1.

  • 2.
  • for each

and 3.

Let 𝑥 𝑏𝑐𝑐𝑏 Does 𝑁 accept 𝑥?

slide-12
SLIDE 12

Automata Tutor

1/29/2020 CS332 ‐ Theory of Computation 12

http://automatatutor.com/

slide-13
SLIDE 13

Regular Languages

1/29/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/29/2020 CS332 ‐ Theory of Computation 14

Let TCPS = { | is a complete TCP Session}

  • Theorem. TCPS is regular
slide-15
SLIDE 15

Compilers

1/29/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/29/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/29/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/29/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/29/2020 CS332 ‐ Theory of Computation 19

Example: The integers 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/29/2020 CS332 ‐ Theory of Computation 20

slide-21
SLIDE 21

Other operations

Let

∗ be languages. Define

Complement: Intersection: Reverse:

  • 1/29/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/29/2020 CS332 ‐ Theory of Computation 22

slide-23
SLIDE 23

Proving Closure Properties

1/29/2020 CS332 ‐ Theory of Computation 23

slide-24
SLIDE 24

Complement

Complement: Theorem: If is regular, then is also regular Proof idea:

1/29/2020 CS332 ‐ Theory of Computation 24

slide-25
SLIDE 25

Union

1/29/2020 CS332 ‐ Theory of Computation 25

Union:

  • r

Theorem: If and are regular, then so is Proof: Let

𝐵 𝐵

𝐵

  • 𝐵

be a DFA recognizing and

𝐶 𝐶

𝐶

  • 𝐶

be a DFA recognizing Goal: Construct a DFA 

  • that recognizes
slide-26
SLIDE 26

Example

1/29/2020 CS332 ‐ Theory of Computation 26

  • 1

1

  • 1

1

𝑩 𝑪

?

slide-27
SLIDE 27

Closure under union proof (cont’d)

Idea: Run both

𝐵 and 𝐶 at the same time

“Cross‐product construction”

𝐵 × 𝐶

,

𝐵 𝐶

 𝐵

𝐵  𝐶 𝐶 

  • ,
  • 𝐵
  • 𝐶

𝐵 × 𝐶 𝐵 × 𝐶

1/29/2020 CS332 ‐ Theory of Computation 27

slide-28
SLIDE 28

Example (cont’d)

1/29/2020 CS332 ‐ Theory of Computation 28

  • 1

1

  • 1

1

𝑩 𝑪

slide-29
SLIDE 29

Intersection

1/29/2020 CS332 ‐ Theory of Computation 29

Intersection: and Theorem: If and are regular, then so is Proof: Let

𝐵 𝐵

𝐵

  • 𝐵

be a DFA recognizing and

𝐶 𝐶

𝐶

  • 𝐶

be a DFA recognizing Goal: Construct a DFA 

  • that recognizes
slide-30
SLIDE 30

Intersection

1/29/2020 CS332 ‐ Theory of Computation 30

Intersection: and Theorem: If and are regular, then so is Another Proof: =

slide-31
SLIDE 31

Reverse

1/29/2020 CS332 ‐ Theory of Computation 31

Reverse:

  • Theorem: If

is regular, then

is also regular

Proof idea: Let 

  • be a DFA recognizing

Goal: Construct a DFA 

  • that recognizes
  • Define

as but

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

Example (Reverse)

1/29/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/29/2020 CS332 ‐ Theory of Computation 33

slide-34
SLIDE 34

Non Nondeterminism

1/29/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.