Theory of Computation Course note based on Computability, Complexity, - - PowerPoint PPT Presentation

theory of computation
SMART_READER_LITE
LIVE PREVIEW

Theory of Computation Course note based on Computability, Complexity, - - PowerPoint PPT Presentation

Preliminaries (1) Regular Languages (9) Theory of Computation Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science , 2nd edition, authored by Martin Davis, Ron Sigal, and Elaine J. Weyuker.


slide-1
SLIDE 1

Preliminaries (1) Regular Languages (9)

Theory of Computation

Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science, 2nd edition, authored by Martin Davis, Ron Sigal, and Elaine J. Weyuker.

course note prepared by Tyng–Ruey Chuang

Institute of Information Science, Academia Sinica Department of Information Management, National Taiwan University

Week 8, Spring 2010

1 / 35

slide-2
SLIDE 2

Preliminaries (1) Regular Languages (9)

About This Course Note

◮ It is prepared for the course Theory of Computation taught at

the National Taiwan University in Spring 2010.

◮ It follows very closely the book Computability, Complexity,

and Languages: Fundamentals of Theoretical Computer Science, 2nd edition, by Martin Davis, Ron Sigal, and Elaine

  • J. Weyuker. Morgan Kaufmann Publishers. ISBN:

0-12-206382-1.

◮ It is available from Tyng-Ruey Chuang’s web site:

http://www.iis.sinica.edu.tw/~trc/ and released under a Creative Commons “Attribution-ShareAlike 3.0 Taiwan” license: http://creativecommons.org/licenses/by-sa/3.0/tw/

2 / 35

slide-3
SLIDE 3

Preliminaries (1) Regular Languages (9) Alphabets and Strings (1.3)

Alphabets and Strings

◮ An alphabet is a finite nonempty set A of symbols. ◮ An n-tuple of symbols of A is called a word or a string on A.

In stead of writing a word as (a1, a2, . . . , an) we write simply a1a2 . . . an.

◮ If u = a1a2 . . . an, then we say that n is the length of u and

we write |u| = n.

◮ We allow a unique null word, written 0, of length 0. ◮ The set of all words on the alphabet A is written as A∗. ◮ Any subset of A∗ is called a language on A or a language with

alphabet A.

3 / 35

slide-4
SLIDE 4

Preliminaries (1) Regular Languages (9) Alphabets and Strings (1.3)

Alphabets and Strings, More

◮ If u, v ∈ A∗, then we write

uv for the word obtained by placing the string v after the string u. For example, if A = {a, b, c}, u = bab, and v = caa, then uv = babcaa.

◮ Where no confusion can result, we write uv instead of

uv.

◮ It is obvious that, for all u, u0 = 0u = u, and that, for all

u, v, w, u(vw) = (uv)w.

◮ If u is a string, and n ∈ N, n > 0, we write

u[n] = uu . . . u

n

We also write n[0] = 0.

◮ If u ∈ A∗, we write uR for u written backward; i.e., if

u = a1a2 . . . an, then uR = an . . . a2a1. Clearly, 0R = 0, and (uv)R = vRuR for u, v ∈ A∗.

4 / 35

slide-5
SLIDE 5

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

The Concept of Finite Automata

◮ A finite automaton has a finite number of internal states that

control its behavior. The states function as memory in the sense that the current state keeps track of the progress of the computation.

5 / 35

slide-6
SLIDE 6

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

The Concept of Finite Automata

◮ A finite automaton has a finite number of internal states that

control its behavior. The states function as memory in the sense that the current state keeps track of the progress of the computation.

◮ The automaton begins by reading the leftmost symbol on a

finite input tape, in a specific state called the initial state.

5 / 35

slide-7
SLIDE 7

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

The Concept of Finite Automata

◮ A finite automaton has a finite number of internal states that

control its behavior. The states function as memory in the sense that the current state keeps track of the progress of the computation.

◮ The automaton begins by reading the leftmost symbol on a

finite input tape, in a specific state called the initial state.

◮ If at a given time, the automaton is in a state qi, reading a

given symbol sj on the input tape, the machine moves one square to the right on the tape and enters a state qk.

5 / 35

slide-8
SLIDE 8

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

The Concept of Finite Automata

◮ A finite automaton has a finite number of internal states that

control its behavior. The states function as memory in the sense that the current state keeps track of the progress of the computation.

◮ The automaton begins by reading the leftmost symbol on a

finite input tape, in a specific state called the initial state.

◮ If at a given time, the automaton is in a state qi, reading a

given symbol sj on the input tape, the machine moves one square to the right on the tape and enters a state qk.

◮ The current state plus the symbol being read from the tape

completely determine the automaton’s next state.

5 / 35

slide-9
SLIDE 9

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

The Concept of Finite Automata

◮ A finite automaton has a finite number of internal states that

control its behavior. The states function as memory in the sense that the current state keeps track of the progress of the computation.

◮ The automaton begins by reading the leftmost symbol on a

finite input tape, in a specific state called the initial state.

◮ If at a given time, the automaton is in a state qi, reading a

given symbol sj on the input tape, the machine moves one square to the right on the tape and enters a state qk.

◮ The current state plus the symbol being read from the tape

completely determine the automaton’s next state.

◮ When all symbols have been read, the automaton either stops

at an accepting state or a non-accepting state.

5 / 35

slide-10
SLIDE 10

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Definition of Finite Automaton

  • Definition. A finite automaton M consists of

◮ an alphabet A = {s1, s2, . . . , sn}, ◮ a set of states Q = {q1, q2, . . . , qm}, ◮ a transition function δ that maps each pair

(qi, sj), 1 ≤ i ≤ m, 1 ≤ j ≤ n, into a state qk,

◮ a set F ⊆ Q of final or accepting states, and ◮ an initial state q1 ∈ Q.

6 / 35

slide-11
SLIDE 11

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Definition of Finite Automaton

  • Definition. A finite automaton M consists of

◮ an alphabet A = {s1, s2, . . . , sn}, ◮ a set of states Q = {q1, q2, . . . , qm}, ◮ a transition function δ that maps each pair

(qi, sj), 1 ≤ i ≤ m, 1 ≤ j ≤ n, into a state qk,

◮ a set F ⊆ Q of final or accepting states, and ◮ an initial state q1 ∈ Q.

We can represent the transition function δ using a state versus symbol table.

6 / 35

slide-12
SLIDE 12

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Does This Automaton Do?

The finite automaton M has

◮ alphabet A = {a, b}, ◮ the set of states Q = {q1, q2, q3, q4}, ◮ the transition function δ defined by the following table:

δ a b q1 q2 q4 q2 q2 q3 q3 q4 q3 q4 q4 q4

◮ the set F = {q3} as the accepting states, and ◮ q1 as the initial state.

7 / 35

slide-13
SLIDE 13

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Does Automaton M Do?

For strings aabbb, baba, aaba, and abbb, the finite automaton M

8 / 35

slide-14
SLIDE 14

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Does Automaton M Do?

For strings aabbb, baba, aaba, and abbb, the finite automaton M

◮ accepts aabbb as M terminates in state q3, which is an

accepting state;

8 / 35

slide-15
SLIDE 15

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Does Automaton M Do?

For strings aabbb, baba, aaba, and abbb, the finite automaton M

◮ accepts aabbb as M terminates in state q3, which is an

accepting state;

◮ rejects baba as M terminates in state q4, which is not an

accepting state;

8 / 35

slide-16
SLIDE 16

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Does Automaton M Do?

For strings aabbb, baba, aaba, and abbb, the finite automaton M

◮ accepts aabbb as M terminates in state q3, which is an

accepting state;

◮ rejects baba as M terminates in state q4, which is not an

accepting state;

◮ rejects aaba as M terminates in state q4, which is not an

accepting state;

8 / 35

slide-17
SLIDE 17

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Does Automaton M Do?

For strings aabbb, baba, aaba, and abbb, the finite automaton M

◮ accepts aabbb as M terminates in state q3, which is an

accepting state;

◮ rejects baba as M terminates in state q4, which is not an

accepting state;

◮ rejects aaba as M terminates in state q4, which is not an

accepting state;

◮ accepts abbb as M terminates in state q3, which is an

accepting state.

8 / 35

slide-18
SLIDE 18

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Function δ∗(qi, u)

If qi is any state of M and u ∈ A∗, we shall write δ∗(qi, u) for the state which M will enter if it begins in state qi at the left end of the string u and moves across u until the entire string has been processed.

9 / 35

slide-19
SLIDE 19

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Function δ∗(qi, u)

If qi is any state of M and u ∈ A∗, we shall write δ∗(qi, u) for the state which M will enter if it begins in state qi at the left end of the string u and moves across u until the entire string has been processed.

◮ δ∗(q1, aabbb) = q3, ◮ δ∗(q1, baba) = q4, ◮ δ∗(q1, aaba) = q4, ◮ δ∗(q1, abbb) = q3.

9 / 35

slide-20
SLIDE 20

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Definition of Function δ∗(qi, u)

A formal definition of function δ∗(qi, u) is by the following recursion: δ∗(qi, 0) = qi, δ∗(qi, usj) = δ(δ∗(qi, u), sj).

10 / 35

slide-21
SLIDE 21

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Definition of Function δ∗(qi, u)

A formal definition of function δ∗(qi, u) is by the following recursion: δ∗(qi, 0) = qi, δ∗(qi, usj) = δ(δ∗(qi, u), sj). Obviously, δ∗(qi, sj) = δ(qi, sj).

10 / 35

slide-22
SLIDE 22

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Definition of Function δ∗(qi, u)

A formal definition of function δ∗(qi, u) is by the following recursion: δ∗(qi, 0) = qi, δ∗(qi, usj) = δ(δ∗(qi, u), sj). Obviously, δ∗(qi, sj) = δ(qi, sj). We say that M accepts a word u provided that δ∗(q1, u) ∈ F. M rejects a word u means that δ∗(q1, u) ∈ Q − F.

10 / 35

slide-23
SLIDE 23

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Regular Languages

The language accepted by a finite automaton M , written L(M ), is the set of all u ∈ A∗ accepted by M : L(M ) = {u ∈ A∗ | δ∗(q1, u) ∈ F}. A language is called regular if there exists a finite automaton that accepts it.

11 / 35

slide-24
SLIDE 24

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Language Does This Automaton Accept?

The finite automaton M has

◮ the alphabet A = {a, b}, ◮ the set of states Q = {q1, q2, q3, q4}, ◮ the transition function δ defined by the following table:

δ a b q1 q2 q4 q2 q2 q3 q3 q4 q3 q4 q4 q4

◮ the set F = {q3} as the accepting states, and ◮ q1 as the initial state.

12 / 35

slide-25
SLIDE 25

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Language Does Automaton M Accept?

The language it accepts is {a[n]b[m] | n, m > 0}.

13 / 35

slide-26
SLIDE 26

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Language Does Automaton M Accept?

The language it accepts is {a[n]b[m] | n, m > 0}. As the above language is accepted by a finite automaton, we say it is a regular language.

13 / 35

slide-27
SLIDE 27

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

State Transition Diagram

◮ Another way to represent the transition function δ is to draw

a graph in which each state is represented by a vertex.

◮ The fact that δ(qi, sj) = qk is represented by drawing an

arrow from vertex qi to vertex qk and labeling it sj.

◮ The diagram thus obtained is called the state transition

diagram for the given automaton.

◮ See Fig. 1.1 in the textbook (p. 240) for the state transition

diagram for the finite automaton we just showed in the previous two slides.

14 / 35

slide-28
SLIDE 28

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Nondeterministic Finite Automata

◮ We modify the definition of a finite automaton to permit

transitions at each stage to either zero, one, or more than one states.

15 / 35

slide-29
SLIDE 29

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Nondeterministic Finite Automata

◮ We modify the definition of a finite automaton to permit

transitions at each stage to either zero, one, or more than one states.

◮ That is, we make the the values of the transition function δ

be sets of states, i.e., sets of elements of Q (rather than members of Q).

15 / 35

slide-30
SLIDE 30

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Nondeterministic Finite Automata

◮ We modify the definition of a finite automaton to permit

transitions at each stage to either zero, one, or more than one states.

◮ That is, we make the the values of the transition function δ

be sets of states, i.e., sets of elements of Q (rather than members of Q).

◮ The devices so obtained are called nondeterministic finite

automata (ndfa).

15 / 35

slide-31
SLIDE 31

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Nondeterministic Finite Automata

◮ We modify the definition of a finite automaton to permit

transitions at each stage to either zero, one, or more than one states.

◮ That is, we make the the values of the transition function δ

be sets of states, i.e., sets of elements of Q (rather than members of Q).

◮ The devices so obtained are called nondeterministic finite

automata (ndfa).

◮ Sometimes the ordinary finite automata are then called

deterministic finite automata (dfa).

15 / 35

slide-32
SLIDE 32

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Definition of Nondeterministic Finite Automaton

  • Definition. A nondeterministic finite automaton M consists of

◮ an alphabet A = {s1, s2, . . . , sn}, ◮ a set of states Q = {q1, q2, . . . , qm}, ◮ a transition function δ that maps each pair

(qi, sj), 1 ≤ i ≤ m, 1 ≤ j ≤ n, into a subset of states Qk ⊆ Q,

◮ a set F ⊆ Q of final or accepting states, and ◮ an initial state q1 ∈ Q.

16 / 35

slide-33
SLIDE 33

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Definition of Function δ∗(qi, u)

The formal definition of function δ∗(qi, u) is now by: δ∗(qi, 0) = {qi}, δ∗(qi, usj) =

  • q∈δ∗(qi,u)

δ(q, sj).

17 / 35

slide-34
SLIDE 34

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Definition of Function δ∗(qi, u)

The formal definition of function δ∗(qi, u) is now by: δ∗(qi, 0) = {qi}, δ∗(qi, usj) =

  • q∈δ∗(qi,u)

δ(q, sj).

◮ A ndfa M with initial state q1 accepts u ∈ A∗ if

δ∗(q1, u) ∩ F = ∅.

◮ That is, at least one of the states at which M ultimately

arrives belongs to F.

◮ L(M ), the language accepted by M , is the set of all strings

accepted by M .

17 / 35

slide-35
SLIDE 35

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Does This Automaton Do?

The nondeterministic finite automaton M has

◮ the alphabet A = {a, b}, ◮ the set of states Q = {q1, q2, q3, q4}, ◮ the transition function δ defined by the following table:

δ a b q1 {q1, q2} {q1, q3} q2 {q4} ∅ q3 ∅ {q4} q4 {q4} {q4}

◮ the set F = {q4} as the accepting states, and ◮ q1 as the initial state. ◮ For the state transition diagram of M , see Fig. 2.1 in the

textbook (p. 243).

18 / 35

slide-36
SLIDE 36

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Strings Does Automaton M Accept?

M accepts a string on the alphabet {a, b} just in case at least one

  • f the symbols has two successive occurrence in the string.

19 / 35

slide-37
SLIDE 37

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

What Strings Does Automaton M Accept?

M accepts a string on the alphabet {a, b} just in case at least one

  • f the symbols has two successive occurrence in the string.

Why?

19 / 35

slide-38
SLIDE 38

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Viewing dfa as ndfa

◮ Strictly speaking, a dfa is not just a special kind of ndfa.

20 / 35

slide-39
SLIDE 39

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Viewing dfa as ndfa

◮ Strictly speaking, a dfa is not just a special kind of ndfa. ◮ This is because for a dfa, δ(q, s) is a state, where for a ndfa it

is a set of states.

20 / 35

slide-40
SLIDE 40

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Viewing dfa as ndfa

◮ Strictly speaking, a dfa is not just a special kind of ndfa. ◮ This is because for a dfa, δ(q, s) is a state, where for a ndfa it

is a set of states.

◮ But it is natural to identify a dfa M with transition function

δ, with the closely related ndfa ¯ M whose transition function ¯ δ is given by ¯ δ(q, s) = {δ(q, s)}, and which has the same final states as M .

20 / 35

slide-41
SLIDE 41

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Viewing dfa as ndfa

◮ Strictly speaking, a dfa is not just a special kind of ndfa. ◮ This is because for a dfa, δ(q, s) is a state, where for a ndfa it

is a set of states.

◮ But it is natural to identify a dfa M with transition function

δ, with the closely related ndfa ¯ M whose transition function ¯ δ is given by ¯ δ(q, s) = {δ(q, s)}, and which has the same final states as M .

◮ It is obviously that L(M ) = L(

¯ M ).

20 / 35

slide-42
SLIDE 42

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

dfa is as expressive as ndfa

Theorem 2.1. A language is accepted by a ndfa if and only if it is

  • regular. Equivalently, a language is accepted by an ndfa if and only

if it is accepted by a dfa. Proof Outline. As we have seen, a language accepted by a dfa is also accepted by an ndfa. Conversely, let L = L(M ), where M is an ndfa with transition function δ, set of states Q = {q1, . . . , qm}, and set of final states

  • F. We will construct a dfa

˜ M such that L( ˜ M ) = L(M ) = L. The idea of the construction is that the individual states of ˜ M will be sets of states of M .

21 / 35

slide-43
SLIDE 43

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Constructing ˜ M

The dfa ˜ M consists of

◮ the same alphabet A = {s1, s2, . . . , sn} of the ndfa M , ◮ the set of states ˜

Q = {Q1, Q2, . . . , Q2m} which consists of all the 2m subsets of the set of states of the ndfa M ,

◮ the transition function ˜

δ defined by ˜ δ(Qi, s) =

  • q∈Qi

δ(q, s),

◮ the set F of final states given by

F = {Qi | Qi ∩ F = ∅},

◮ the initial state Q1 = {q1}, where q1 is the initial state of M .

22 / 35

slide-44
SLIDE 44

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Lemma 1. Let R ⊆ ˜

  • Q. Then

˜ δ(

  • Qi∈R

Qi, s) =

  • Qi∈R

˜ δ(Qi, s).

  • Proof. Let

Qi∈R Qi = Q. Then by definition,

˜ δ(Q, s) =

  • q∈Q

δ(q, s) =

  • Qi∈R
  • q∈Qi

δ(q, s) =

  • Qi∈R

˜ δ(Qi, s). ✷

23 / 35

slide-45
SLIDE 45

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Lemma 2. For any string u, ˜ δ∗(Qi, u) =

  • q∈Qi

δ∗(q, u).

  • Proof. The proof is by induction on |u|. If |u| = 0, then u = 0 and

˜ δ∗(Qi, 0) = Qi =

  • q∈Qi

{q} =

  • q∈Qi

δ∗(q, 0)

24 / 35

slide-46
SLIDE 46

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

  • Proof. (Continued) If |u| = l + 1 and the result is known for

|u| = l, we write u = vs, where |v| = l, and observe that, using Lemma 1 and the induction hypothesis, ˜ δ∗(Qi, u) = ˜ δ∗(Qi, vs) = ˜ δ(˜ δ∗(Qi, v), s) = ˜ δ(

  • q∈Qi

δ∗(q, v), s) =

  • q∈Qi

˜ δ(δ∗(q, v), s) =

  • q∈Qi
  • r∈δ∗(q,v)

δ(r, s) =

  • q∈Qi

δ∗(q, vs) =

  • q∈Qi

δ∗(q, u). ✷

25 / 35

slide-47
SLIDE 47

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Lemma 3. L(M ) = L( ˜ M ).

  • Proof. u ∈ L(

˜ M ) if and only if ˜ δ∗(Q1, u) ∈ F. But, by Lemma 2, ˜ δ∗(Q1, u) = ˜ δ∗({q1}, u) = δ∗(q1, u). Hence, u ∈ L( ˜ M ) if and only if δ∗(q1, u) ∈ F if and only if δ∗(q1, u) ∩ F = ∅ if and only if u ∈ L(M ) ✷ Note that Theorem 2.1 is an immediate consequence of Lemma 3.

26 / 35

slide-48
SLIDE 48

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Additional Examples

◮ Construct a dfa that accepts the language:

{(11)[n] | n ≥ 0}

27 / 35

slide-49
SLIDE 49

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Additional Examples

◮ Construct a dfa that accepts the language:

{(11)[n] | n ≥ 0}

◮ The vendor machine example. (Fig. 3.2 in textbook, p. 248)

27 / 35

slide-50
SLIDE 50

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Additional Examples

◮ Construct a dfa that accepts the language:

{(11)[n] | n ≥ 0}

◮ The vendor machine example. (Fig. 3.2 in textbook, p. 248) ◮ Construct an ndfa that accepts all and only strings which end

in bab or aaba.

27 / 35

slide-51
SLIDE 51

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Additional Examples

◮ Construct a dfa that accepts the language:

{(11)[n] | n ≥ 0}

◮ The vendor machine example. (Fig. 3.2 in textbook, p. 248) ◮ Construct an ndfa that accepts all and only strings which end

in bab or aaba.

◮ Construct an ndfa that accepts the language:

{a[n1]b[m1] . . . a[nk]b[mk] | n1, m1, . . . , nk, mk > 0}.

27 / 35

slide-52
SLIDE 52

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Closure properties

◮ To show that the class of regular languages is closed under a

large number of operations.

◮ To use deterministic or nondeterministic finite automata

whenever necessary, as the two classes of automata are equivalent in expressiveness (Theorem 2.1).

28 / 35

slide-53
SLIDE 53

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Nonrestarting dfa

  • Definition. A dfa is called nonrestarting if there is no pair q, s for

which δ(q, s) = q1 where q1 is the initial state. Theorem 4.1. There is an algorithm that will transform a given dfa M into a nonrestarting dfa ˜ M such that L( ˜ M ) = L(M ).

29 / 35

slide-54
SLIDE 54

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Constructing a nonrestarting dfa from a dfa

Proof of Theorem 4.1. From a dfa M , we can construct an equivalent nonrestarting dfa ˜ M by adding a new “returning initial” state qn+1, and by redefining the transition function accordingly.

30 / 35

slide-55
SLIDE 55

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Constructing a nonrestarting dfa from a dfa

Proof of Theorem 4.1. From a dfa M , we can construct an equivalent nonrestarting dfa ˜ M by adding a new “returning initial” state qn+1, and by redefining the transition function accordingly. That is, for ˜ M , we define

◮ the set of states ˜

Q = Q ∪ {qn+1}

◮ the transition function ˜

δ by ˜ δ(q, s) = δ(q, s) if q ∈ Q and δ(q, s) = q1 qn+1 if q ∈ Q and δ(q, s) = q1 ˜ δ(qn+1, s) = ˜ δ(q1, s)

◮ the set of final states ˜

F = F if q1 ∈ F F ∪ {qn+1} if q1 ∈ F

30 / 35

slide-56
SLIDE 56

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Constructing a nonrestarting dfa from a dfa

Proof of Theorem 4.1. From a dfa M , we can construct an equivalent nonrestarting dfa ˜ M by adding a new “returning initial” state qn+1, and by redefining the transition function accordingly. That is, for ˜ M , we define

◮ the set of states ˜

Q = Q ∪ {qn+1}

◮ the transition function ˜

δ by ˜ δ(q, s) = δ(q, s) if q ∈ Q and δ(q, s) = q1 qn+1 if q ∈ Q and δ(q, s) = q1 ˜ δ(qn+1, s) = ˜ δ(q1, s)

◮ the set of final states ˜

F = F if q1 ∈ F F ∪ {qn+1} if q1 ∈ F To see that L(M ) = L( ˜ M ) we observe that ˜ M follows the same transitions as M except whenever M reenters q1, ˜ M enters qn+1. ✷

30 / 35

slide-57
SLIDE 57

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

L ∪ ˜ L

Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L.

31 / 35

slide-58
SLIDE 58

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

L ∪ ˜ L

Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L.

  • Proof. Let M and

˜ M be nonrestarting dfas that accept L and ˜ L

  • respectively. We now construct a ndfa

ˇ M by “merging” M and ˜ M but with a new initial state ˇ q1.

31 / 35

slide-59
SLIDE 59

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

L ∪ ˜ L

Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L.

  • Proof. Let M and

˜ M be nonrestarting dfas that accept L and ˜ L

  • respectively. We now construct a ndfa

ˇ M by “merging” M and ˜ M but with a new initial state ˇ

  • q1. That is, we define

ˇ M by

◮ the set of states ˇ

Q = Q ∪ ˜ Q ∪ {ˇ q1} − {q1, ˜ q1}

◮ the transition function ˇ

δ by ˇ δ(q, s) = {δ(q, s)} if q ∈ Q − {q1} {˜ δ(q, s)} if q ∈ ˜ Q − {˜ q1} ˇ δ(ˇ q1, s) = {δ(q1, s)} ∪ {˜ δ(˜ q1, s)}

◮ the set of final states

ˇ F = F ∪ ˜ F ∪ {ˇ q1} − {q1, ˜ q1} if q1 ∈ F or ˜ q1 ∈ ˜ F F ∪ ˜ F

  • therwise

31 / 35

slide-60
SLIDE 60

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

L ∪ ˜ L

Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L.

  • Proof. Let M and

˜ M be nonrestarting dfas that accept L and ˜ L

  • respectively. We now construct a ndfa

ˇ M by “merging” M and ˜ M but with a new initial state ˇ

  • q1. That is, we define

ˇ M by

◮ the set of states ˇ

Q = Q ∪ ˜ Q ∪ {ˇ q1} − {q1, ˜ q1}

◮ the transition function ˇ

δ by ˇ δ(q, s) = {δ(q, s)} if q ∈ Q − {q1} {˜ δ(q, s)} if q ∈ ˜ Q − {˜ q1} ˇ δ(ˇ q1, s) = {δ(q1, s)} ∪ {˜ δ(˜ q1, s)}

◮ the set of final states

ˇ F = F ∪ ˜ F ∪ {ˇ q1} − {q1, ˜ q1} if q1 ∈ F or ˜ q1 ∈ ˜ F F ∪ ˜ F

  • therwise

Note that once a first transition has been selected, ˇ M is locked into either M or ˜ M . Hence L( ˇ M ) = L ∪ ˜ L. ✷

31 / 35

slide-61
SLIDE 61

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

A∗ − L

Theorem 4.3. Let L ⊆ A∗ be a regular language. Then A∗ − L is regular.

32 / 35

slide-62
SLIDE 62

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

A∗ − L

Theorem 4.3. Let L ⊆ A∗ be a regular language. Then A∗ − L is regular.

  • Proof. Let M be a dfa that accept L. Let dfa

¯ M be exactly like M except that it accepts precisely when M rejects. That is, the set of accepting states of ¯ M is Q − F. Then L( ¯ M ) = A∗ − L. ✷

32 / 35

slide-63
SLIDE 63

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

L1 ∩ L2

Theorem 4.4. If L1 and L2 are regular languages, then so is L1 ∩ L2.

33 / 35

slide-64
SLIDE 64

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

L1 ∩ L2

Theorem 4.4. If L1 and L2 are regular languages, then so is L1 ∩ L2.

  • Proof. Let L1, L2 ⊆ A∗. Then, by the De Morgan identity, we have

L1 ∩ L2 = A∗ − ((A∗ − L1) ∪ (A∗ − L2)) Theorem 4.2 and 4.3 then give the result. ✷

33 / 35

slide-65
SLIDE 65

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

∅ and {0}

Theorem 4.5. ∅ and {0} are regular languages.

34 / 35

slide-66
SLIDE 66

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

∅ and {0}

Theorem 4.5. ∅ and {0} are regular languages.

  • Proof. ∅ is clearly the language accepted by any automaton whose

set of accepting states is empty.

34 / 35

slide-67
SLIDE 67

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

∅ and {0}

Theorem 4.5. ∅ and {0} are regular languages.

  • Proof. ∅ is clearly the language accepted by any automaton whose

set of accepting states is empty. For {0}, we can construct a two-state dfa such that F = {q1} and δ(q1, a) = δ(q2, a) = q2 for every symbol a ∈ A, the alphabet. Clearly this dfa accepts {0}. ✷

34 / 35

slide-68
SLIDE 68

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Every finite subset of A∗ is regular

Theorem 4.5. Let u ∈ A∗. Then {u} is a regular language.

35 / 35

slide-69
SLIDE 69

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Every finite subset of A∗ is regular

Theorem 4.5. Let u ∈ A∗. Then {u} is a regular language.

  • Proof. Theorem 4.4 proves the case for u = 0. For the other case,

let u = a1a2 . . . al where l ≥ 1, a1, a2, . . . al ∈ A. We now construct a (l + 1)–state ndfa M with initial state q1, accepting state ql+1, and the transition function δ given by δ(qi, ai) = {qi+1}, i = 1, . . . , l δ(qi, a) = ∅ for a ∈ A − {ai}, i = 1, . . . , l Clearly L(M ) = {u}. ✷

35 / 35

slide-70
SLIDE 70

Preliminaries (1) Regular Languages (9) Finite Automata (9.1) Nondeterministic Finite Automata (9.2) Additional Examples (9.3) Closure Properties (9.4)

Every finite subset of A∗ is regular

Theorem 4.5. Let u ∈ A∗. Then {u} is a regular language.

  • Proof. Theorem 4.4 proves the case for u = 0. For the other case,

let u = a1a2 . . . al where l ≥ 1, a1, a2, . . . al ∈ A. We now construct a (l + 1)–state ndfa M with initial state q1, accepting state ql+1, and the transition function δ given by δ(qi, ai) = {qi+1}, i = 1, . . . , l δ(qi, a) = ∅ for a ∈ A − {ai}, i = 1, . . . , l Clearly L(M ) = {u}. ✷ Corollary 4.7. Every finite subset of A∗ is regular. ✷

35 / 35