finite automata and languages - iit bombaytrivedi/courses/cs620/lecture08.pdf · a. trivedi – 3...

55
A. Trivedi – 1 of 39 CS620, IIT BOMBAY Finite Automata and Languages Ashutosh Trivedi Department of Computer Science and Engineering, IIT Bombay CS620: New Trends in IT: Modeling and Verification of Cyber-Physical Systems (2 August 2013) A. Trivedi Hybrid Systems

Upload: hoangkien

Post on 07-Aug-2019

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 1 of 39

CS620, IIT BOMBAY

Finite Automata and Languages

Ashutosh TrivediDepartment of Computer Science and Engineering,

IIT Bombay

CS620: New Trends in IT: Modeling and Verification of Cyber-Physical Systems(2 August 2013)

A. Trivedi Hybrid Systems

Page 2: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 2 of 39

Computation With Finitely Many States

Nondeterministic Finite State Automata

Alternation

A. Trivedi Hybrid Systems

Page 3: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 3 of 39

Machines and their Mathematical Abstractions

Finite instruction machine with finite memory (Finite State Automata)

Sstart C

no coincoin

ready dispense

not ready

Finite instruction machine with unbounded memory (Turing machine)

b. . .⊥ . . . $

P Q

b/a,Rb/a,R

a/⊥,L

a/⊥,L

A. Trivedi Hybrid Systems

Page 4: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 4 of 39

Finite State Automata

Sstart C

no coincoin

ready dispense

not ready

– Introduced first by two neuro-psychologists WarrenS. McCullough and Walter Pitts in 1943 as a modelfor human brain!

– Finite automata can naturally modelmicroprocessors and even software programsworking on variables with bounded domain

– Capture so-called regular sets of sequences thatoccur in many different fields (logic, algebra, regEx)

– Nice theoretical properties– Applications in digital circuit/protocol verification,

compilers, pattern recognition, etc.

A. Trivedi Hybrid Systems

Page 5: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 5 of 39

Calculemus! — Gottfried Wilhelm von Leibniz

Let us observe our mental process while we compute the following:– Recognize a string of an even length.– Recognize a binary string of an even number of 0’s.– Recognize a binary string of an odd number of 0’s.– Recognize a string that contains your roll number.– Recognize a binary (decimal) string that is a multiple of 2.– Recognize a binary (decimal) string that is a multiple of 3.– Recognize a string with well-matched parenthesis.– Recognize a # separated string of the form w#w.– Recognize a string with a prime number of 1’s

A. Trivedi Hybrid Systems

Page 6: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 5 of 39

Calculemus! — Gottfried Wilhelm von Leibniz

Let us observe our mental process while we compute the following:– Recognize a string of an even length.

– Recognize a binary string of an even number of 0’s.– Recognize a binary string of an odd number of 0’s.– Recognize a string that contains your roll number.– Recognize a binary (decimal) string that is a multiple of 2.– Recognize a binary (decimal) string that is a multiple of 3.– Recognize a string with well-matched parenthesis.– Recognize a # separated string of the form w#w.– Recognize a string with a prime number of 1’s

A. Trivedi Hybrid Systems

Page 7: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 5 of 39

Calculemus! — Gottfried Wilhelm von Leibniz

Let us observe our mental process while we compute the following:– Recognize a string of an even length.– Recognize a binary string of an even number of 0’s.

– Recognize a binary string of an odd number of 0’s.– Recognize a string that contains your roll number.– Recognize a binary (decimal) string that is a multiple of 2.– Recognize a binary (decimal) string that is a multiple of 3.– Recognize a string with well-matched parenthesis.– Recognize a # separated string of the form w#w.– Recognize a string with a prime number of 1’s

A. Trivedi Hybrid Systems

Page 8: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 5 of 39

Calculemus! — Gottfried Wilhelm von Leibniz

Let us observe our mental process while we compute the following:– Recognize a string of an even length.– Recognize a binary string of an even number of 0’s.– Recognize a binary string of an odd number of 0’s.

– Recognize a string that contains your roll number.– Recognize a binary (decimal) string that is a multiple of 2.– Recognize a binary (decimal) string that is a multiple of 3.– Recognize a string with well-matched parenthesis.– Recognize a # separated string of the form w#w.– Recognize a string with a prime number of 1’s

A. Trivedi Hybrid Systems

Page 9: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 5 of 39

Calculemus! — Gottfried Wilhelm von Leibniz

Let us observe our mental process while we compute the following:– Recognize a string of an even length.– Recognize a binary string of an even number of 0’s.– Recognize a binary string of an odd number of 0’s.– Recognize a string that contains your roll number.

– Recognize a binary (decimal) string that is a multiple of 2.– Recognize a binary (decimal) string that is a multiple of 3.– Recognize a string with well-matched parenthesis.– Recognize a # separated string of the form w#w.– Recognize a string with a prime number of 1’s

A. Trivedi Hybrid Systems

Page 10: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 5 of 39

Calculemus! — Gottfried Wilhelm von Leibniz

Let us observe our mental process while we compute the following:– Recognize a string of an even length.– Recognize a binary string of an even number of 0’s.– Recognize a binary string of an odd number of 0’s.– Recognize a string that contains your roll number.– Recognize a binary (decimal) string that is a multiple of 2.

– Recognize a binary (decimal) string that is a multiple of 3.– Recognize a string with well-matched parenthesis.– Recognize a # separated string of the form w#w.– Recognize a string with a prime number of 1’s

A. Trivedi Hybrid Systems

Page 11: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 5 of 39

Calculemus! — Gottfried Wilhelm von Leibniz

Let us observe our mental process while we compute the following:– Recognize a string of an even length.– Recognize a binary string of an even number of 0’s.– Recognize a binary string of an odd number of 0’s.– Recognize a string that contains your roll number.– Recognize a binary (decimal) string that is a multiple of 2.– Recognize a binary (decimal) string that is a multiple of 3.

– Recognize a string with well-matched parenthesis.– Recognize a # separated string of the form w#w.– Recognize a string with a prime number of 1’s

A. Trivedi Hybrid Systems

Page 12: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 5 of 39

Calculemus! — Gottfried Wilhelm von Leibniz

Let us observe our mental process while we compute the following:– Recognize a string of an even length.– Recognize a binary string of an even number of 0’s.– Recognize a binary string of an odd number of 0’s.– Recognize a string that contains your roll number.– Recognize a binary (decimal) string that is a multiple of 2.– Recognize a binary (decimal) string that is a multiple of 3.– Recognize a string with well-matched parenthesis.

– Recognize a # separated string of the form w#w.– Recognize a string with a prime number of 1’s

A. Trivedi Hybrid Systems

Page 13: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 5 of 39

Calculemus! — Gottfried Wilhelm von Leibniz

Let us observe our mental process while we compute the following:– Recognize a string of an even length.– Recognize a binary string of an even number of 0’s.– Recognize a binary string of an odd number of 0’s.– Recognize a string that contains your roll number.– Recognize a binary (decimal) string that is a multiple of 2.– Recognize a binary (decimal) string that is a multiple of 3.– Recognize a string with well-matched parenthesis.– Recognize a # separated string of the form w#w.

– Recognize a string with a prime number of 1’s

A. Trivedi Hybrid Systems

Page 14: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 5 of 39

Calculemus! — Gottfried Wilhelm von Leibniz

Let us observe our mental process while we compute the following:– Recognize a string of an even length.– Recognize a binary string of an even number of 0’s.– Recognize a binary string of an odd number of 0’s.– Recognize a string that contains your roll number.– Recognize a binary (decimal) string that is a multiple of 2.– Recognize a binary (decimal) string that is a multiple of 3.– Recognize a string with well-matched parenthesis.– Recognize a # separated string of the form w#w.– Recognize a string with a prime number of 1’s

A. Trivedi Hybrid Systems

Page 15: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 6 of 39

Finite State AutomataAutomaton accepting strings of even length:

Estart O

0, 1

0, 1

Automaton accepting strings with an even number of 1’s:

Estart O

01

1

0

Automaton accepting even strings (multiple of 2):

Estart O

01

0

1

A. Trivedi Hybrid Systems

Page 16: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 7 of 39

Deterministic Finite State Automata (DFA)

Estart O

01

0

1

A finite state automaton is a tuple A = (S,Σ, δ, s0,F), where:– S is a finite set called the states;– Σ is a finite set called the alphabet;– δ : S× Σ→ S is the transition function;– s0 ∈ S is the start state; and– F ⊆ S is the set of accept states.

For a function δ : S× Σ→ S we define extended transition functionδ̂ : S× Σ∗ → S using the following inductive definition:

δ̂(q,w) =

{q if w = ε

δ(δ̂(q, x), a) if w = xa s.t. x ∈ Σ∗ and a ∈ Σ.

A. Trivedi Hybrid Systems

Page 17: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 7 of 39

Deterministic Finite State Automata (DFA)

Estart O

01

0

1

A finite state automaton is a tuple A = (S,Σ, δ, s0,F), where:– S is a finite set called the states;– Σ is a finite set called the alphabet;– δ : S× Σ→ S is the transition function;– s0 ∈ S is the start state; and– F ⊆ S is the set of accept states.

For a function δ : S× Σ→ S we define extended transition functionδ̂ : S× Σ∗ → S using the following inductive definition:

δ̂(q,w) =

{q if w = ε

δ(δ̂(q, x), a) if w = xa s.t. x ∈ Σ∗ and a ∈ Σ.

A. Trivedi Hybrid Systems

Page 18: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 8 of 39

Deterministic Finite State Automata (DFA)

Estart O

01

0

1

A finite state automaton is a tuple A = (S,Σ, δ, s0,F), where:– S is a finite set called the states;– Σ is a finite set called the alphabet;– δ : S× Σ→ S is the transition function;– s0 ∈ S is the start state; and– F ⊆ S is the set of accept states.

The language L(A) accepted by a DFA A = (S,Σ, δ, s0,F) is defined as:

L(A)def= {w : δ̂(w) ∈ F}.

A. Trivedi Hybrid Systems

Page 19: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 9 of 39

Computation or Run of a DFA

Estart O

01

0

1

computation

Estart

E

O

E

string

.

.

.

.

0

1

0

computation

Estart

E

E

O

string

.

.

.

.

0

0

1

A. Trivedi Hybrid Systems

Page 20: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 10 of 39

Deterministic Finite State AutomataSemantics using extended transition function:

– The language L(A) accepted by a DFA A = (S,Σ, δ, s0,F) is defined as:

L(A)def= {w : δ̂(w) ∈ F}.

Semantics using accepting computation:– A computation or a run of a DFA A = (S,Σ, δ, s0,F) on a string

w = a0a1 . . . an−1 is the finite sequence

s0, a1s1, a2, . . . , an−1, sn

where s0 is the starting state, and δ(si−1, ai) = si+1.– A string w is accepted by a DFA A if the last state of the unique

computation of A on w is an accept state, i.e. sn ∈ F.– Language of a DFA A

L(A) = {w : string w is accepted by DFA A}.

Proposition

Both semantics define the same language. Proof by induction.

A. Trivedi Hybrid Systems

Page 21: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 11 of 39

Properties of Regular Languages

Definition (Regular Languages)A language is called regular if it is accepted by a finite state automaton.

Let A and B be languages (remember they are sets). We define thefollowing operations on them:

– Union: A ∪ B = {w : w ∈ A or w ∈ B}– Concatenation: AB = {wv : w ∈ A and v ∈ B}– Closure (Kleene Closure, or Star):

A∗ = {w1w2 . . .wk : k ≥ 0 and wi ∈ A}. In other words:

A∗ = ∪i≥0Ai

where A0 = ∅, A1 = A, A2 = AA, and so on.– Complementation Σ∗ \ A = {w ∈ Σ∗ : w 6∈ A}.

A. Trivedi Hybrid Systems

Page 22: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 12 of 39

Properties of Regular Languages

– The class of regular languages is closed under– union,– intersection,– complementation– concatenation, and– Kleene closure.

– Decidability of language-theoretic problems– Emptiness Problem– Membership Problem– Universality Problem– Equivalence Problem– Language Inclusion Problem– Minimization Problem

Goal: To study these problems for timed automata

A. Trivedi Hybrid Systems

Page 23: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 13 of 39

Closure under Union

LemmaThe class of regular languages is closed under union.

Proof.– Let A1 and A1 be regular languages.

– Let M1 = (S1,Σ, δ1, s1,F1) and M2 = (S2,Σ, δ2, s2,F2) be finiteautomata accepting these languages.

– Simulate both automata together!– The language A ∪ B is accept by the resulting finite state automaton,

and hence is regular.

Class Exercise: Extend this construction for intersection.

A. Trivedi Hybrid Systems

Page 24: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 13 of 39

Closure under Union

LemmaThe class of regular languages is closed under union.

Proof.– Let A1 and A1 be regular languages.– Let M1 = (S1,Σ, δ1, s1,F1) and M2 = (S2,Σ, δ2, s2,F2) be finite

automata accepting these languages.

– Simulate both automata together!– The language A ∪ B is accept by the resulting finite state automaton,

and hence is regular.

Class Exercise: Extend this construction for intersection.

A. Trivedi Hybrid Systems

Page 25: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 13 of 39

Closure under Union

LemmaThe class of regular languages is closed under union.

Proof.– Let A1 and A1 be regular languages.– Let M1 = (S1,Σ, δ1, s1,F1) and M2 = (S2,Σ, δ2, s2,F2) be finite

automata accepting these languages.– Simulate both automata together!– The language A ∪ B is accept by the resulting finite state automaton,

and hence is regular.

Class Exercise: Extend this construction for intersection.

A. Trivedi Hybrid Systems

Page 26: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 13 of 39

Closure under Union

LemmaThe class of regular languages is closed under union.

Proof.– Let A1 and A1 be regular languages.– Let M1 = (S1,Σ, δ1, s1,F1) and M2 = (S2,Σ, δ2, s2,F2) be finite

automata accepting these languages.– Simulate both automata together!– The language A ∪ B is accept by the resulting finite state automaton,

and hence is regular.

Class Exercise: Extend this construction for intersection.

A. Trivedi Hybrid Systems

Page 27: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 14 of 39

Closure under Concatenation

LemmaThe class of regular languages is closed under concatenation.

Proof.(Attempt).

– Let A1 and A1 be regular languages.– Let M1 = (S1,Σ, δ1, s1,F1) and M2 = (S2,Σ, δ2, s2,F2) be finite

automata accepting these languages.– How can we find an automaton that accepts the concatenation?– Does this automaton fit our definition of a finite state automaton?– Determinism vs Non-determinism

A. Trivedi Hybrid Systems

Page 28: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 15 of 39

Nondeterministic Finite State Automata

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

Michael O. Rabin Dana Scott

A. Trivedi Hybrid Systems

Page 29: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 16 of 39

Non-deterministic Finite State Automata

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

A non-deterministic finite state automaton (NFA) is a tupleA = (S,Σ, δ, s0,F), where:

– S is a finite set called the states;– Σ is a finite set called the alphabet;– δ : S× (Σ ∪ {ε})→ 2S is the transition function;– s0 ∈ S is the start state; and– F ⊆ S is the set of accept states.

For a function δ : S× Σ→ 2S we define extended transition functionδ̂ : S× Σ∗ → 2S using the following inductive definition:

δ̂(q,w) =

{q} if w = ε⋃p∈δ̂(q,x)

δ(p, a) if w = xa s.t. x ∈ Σ∗ and a ∈ Σ.

A. Trivedi Hybrid Systems

Page 30: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 16 of 39

Non-deterministic Finite State Automata

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

A non-deterministic finite state automaton (NFA) is a tupleA = (S,Σ, δ, s0,F), where:

– S is a finite set called the states;– Σ is a finite set called the alphabet;– δ : S× (Σ ∪ {ε})→ 2S is the transition function;– s0 ∈ S is the start state; and– F ⊆ S is the set of accept states.

For a function δ : S× Σ→ 2S we define extended transition functionδ̂ : S× Σ∗ → 2S using the following inductive definition:

δ̂(q,w) =

{q} if w = ε⋃p∈δ̂(q,x)

δ(p, a) if w = xa s.t. x ∈ Σ∗ and a ∈ Σ.

A. Trivedi Hybrid Systems

Page 31: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 17 of 39

Non-deterministic Finite State Automata

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

A non-deterministic finite state automaton (NFA) is a tupleA = (S,Σ, δ, s0,F), where:

– S is a finite set called the states;– Σ is a finite set called the alphabet;– δ : S× (Σ ∪ {ε})→ 2S is the transition function;– s0 ∈ S is the start state; and– F ⊆ S is the set of accept states.

The language L(A) accepted by an NFA A = (S,Σ, δ, s0,F) is defined as:

L(A)def= {w : δ̂(w) ∩ F 6= ∅}.

A. Trivedi Hybrid Systems

Page 32: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 18 of 39

Computation or Run of an NFA

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

s1start

s1

s1 s2 s3

s1 s2 s3 A s4

s1s2s3 A s4s4

.

.

.

.

.

0

1

1

1

A. Trivedi Hybrid Systems

Page 33: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 19 of 39

Non-deterministic Finite State AutomataSemantics using extended transition function:

– The language L(A) accepted by an NFA A = (S,Σ, δ, s0,F) is defined:

L(A)def= {w : δ̂(w) ∩ F 6= ∅}.

Semantics using accepting computation:– A computation or a run of a NFA on a string w = a0a1 . . . an−1 is a

finite sequences0, r1, s1, r2, . . . , rk−1, sn

where s0 is the starting state, and si+1 ∈ δ(si−1, ri) andr0r1 . . . rk−1 = a0a1 . . . an−1.

– A string w is accepted by an NFA A if the last state of somecomputation of A on w is an accept state sn ∈ F.

– Language of an NFA A

L(A) = {w : string w is accepted by NFA A}.

Proposition

Both semantics define the same language. Proof by induction.

A. Trivedi Hybrid Systems

Page 34: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 20 of 39

Why study NFA?

NFA are often more convenient to design than DFA, e.g.:– {w : w contains 1 in the third last position}.– {w : : w is a multiple of 2 or a multiple of 3}.– Union and intersection of two DFAs as an NFA– Exponentially succinct than DFA

– Consider the language of strings having n-th symbol from the end is 1.– DFA has to remember last n symbols, and– hence any DFA needs at least 2n states to accept this language.

And, surprisingly perhaps:

Theorem (DFA=NFA)Every non-deterministic finite automaton has an equivalent (accepting the samelanguage) deterministic finite automaton. Subset construction.

A. Trivedi Hybrid Systems

Page 35: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 20 of 39

Why study NFA?

NFA are often more convenient to design than DFA, e.g.:– {w : w contains 1 in the third last position}.– {w : : w is a multiple of 2 or a multiple of 3}.– Union and intersection of two DFAs as an NFA– Exponentially succinct than DFA

– Consider the language of strings having n-th symbol from the end is 1.– DFA has to remember last n symbols, and– hence any DFA needs at least 2n states to accept this language.

And, surprisingly perhaps:

Theorem (DFA=NFA)Every non-deterministic finite automaton has an equivalent (accepting the samelanguage) deterministic finite automaton. Subset construction.

A. Trivedi Hybrid Systems

Page 36: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 21 of 39

Computation of an NFA: An observation

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

s1start

s1

s1 s2 s3

s1 s2 s3 A s4

s1s2s3 A s4s4

.

.

.

.

.

0

1

1

1

A. Trivedi Hybrid Systems

Page 37: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 22 of 39

ε-free NFA = DFA

Let A = (S,Σ, δ, s0,F) be an ε-free NFA. Consider the DFADet(A) = (S′,Σ′, δ′, s′0,F

′) where– S′ = 2S,– Σ′ = Σ,– δ′ : 2S × Σ→ 2S such that δ′(P, a) =

⋃s∈P δ(s, a),

– s′0 = {s0}, and– F′ ⊆ S′ is such that F′ = {P : P ∩ F 6= ∅}.

Theorem (ε-free NFA = DFA)

L(A) = L(Det(A)). By induction, hint δ̂(s0,w) = δ̂′({s0},w).

Exercise (3.1)Extend the proof for NFA with ε transitions. hint: ε-closure

A. Trivedi Hybrid Systems

Page 38: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 23 of 39

Proof of correctness: L(A) = L(Det(A)).The proof follows from the observation that δ̂(s0,w) = δ̂′({s0},w). Weprove it by induction on the length of w.

– Base case: Let the size of w be 0, i.e. w = ε. The base case followsimmediately from the definition of extended transition functions:

δ̂(s0, ε) = ε and δ̂′({s0},w) = ε.

– Induction Hypothesis: Assume that for all strings w ∈ Σ∗ of size n wehave that δ̂(s0,w) = δ̂′({s0},w).

– Induction Step: Let w = xa where x ∈ Σ∗ and a ∈ Σ be a string of sizen + 1, and hence x is of size n. Now observe,

δ̂(s0, xa) =⋃

s∈δ̂(s0,x)

δ(s, a), by definition of δ̂.

=⋃

s∈δ̂′({s0},x)

δ(s, a), from inductive hypothesis.

= δ′(δ̂′({s0}, x), a), from definition δ′(P, a) =⋃s∈P

δ(s, a).

= δ̂′({s0}, xa), by definition of δ̂′.

A. Trivedi Hybrid Systems

Page 39: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 24 of 39

Equivalence of NFA and DFA

Exercise (In class)Determinize the following automaton:

s1start s2 s3 s4

0, 1

1 0, 1 0, 1

A. Trivedi Hybrid Systems

Page 40: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 25 of 39

Complementation of the Language of a DFA

Estart O

01

0

1

computation

Estart

E

O

E

string

.

.

.

.

0

1

0

computation

Estart

E

E

O

string

.

.

.

.

0

0

1

Hint: Simply swap the accepting and non-accepting states!

A. Trivedi Hybrid Systems

Page 41: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 26 of 39

Complementation of a DFA

TheoremComplementation of the language of a DFA A = (S,Σ, δ, s0,F) is the languageaccepted by the DFA A′ = (S,Σ, δ, s0,S \ F).

Proof.– L(A) = {w ∈ Σ∗ : δ̂(s0,w) ∈ F},– Σ∗ \ L(A) = {w ∈ Σ∗ : δ̂(s0,w) 6∈ F},– L(A′) = {w ∈ Σ∗ : δ̂(s0,w) ∈ S \ F}, and– transition function is total.

A. Trivedi Hybrid Systems

Page 42: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 27 of 39

Complementation of the language of an NFA

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

s1start

s1

s1 s2 s3

s1 s2 s3 A s4

s1s2s3 A s4s4

.

.

.

.

.

0

1

1

1

Question: Can we simply swap the accepting and non-accepting states?

A. Trivedi Hybrid Systems

Page 43: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 28 of 39

Complementation of the language of a NFA

Question: Can we simply swap the accepting and non-accepting states?

Let the NFA A be (S,Σ, δ, s0,F) and let the NFA A′ be (S,Σ, δ, s0,S \ F) theNFA after swapping the accepting states.

– L(A) = {w ∈ Σ∗ : δ̂(s0,w) ∩ F 6= ∅},– L(A′) = {w ∈ Σ∗ : δ̂(s0,w) ∩ (S \ F) 6= ∅}.– Consider, the complement language of A

Σ∗ \ L(A) = {w ∈ Σ∗ : δ̂(s0,w) ∩ F = ∅}= {w ∈ Σ∗ : δ̂(s0,w) ⊆ S \ F}.

– Hence L(A′) does not quite capture the complement. Moreover, thecondition for Σ∗ \ L(A) is not quite captured by either DFA or NFA.

A. Trivedi Hybrid Systems

Page 44: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 29 of 39

Computation With Finitely Many States

Nondeterministic Finite State Automata

Alternation

A. Trivedi Hybrid Systems

Page 45: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 30 of 39

Universal Non-deterministic Finite Automata

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

A universal non-deterministic finite state automaton (UNFA) is a tupleA = (S,Σ, δ, s0,F), where:

– S is a finite set called the states;– Σ is a finite set called the alphabet;– δ : S× (Σ ∪ {ε})→ 2S is the transition function;– s0 ∈ S is the start state; and– F ⊆ S is the set of accept states.

The language L(A) accepted by a UNFA A = (S,Σ, δ, s0,F) is defined as:

L(A)def= {w : δ̂(w) ⊆ F}.

A. Trivedi Hybrid Systems

Page 46: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 31 of 39

Computation or Run of an UNFA

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

s1start

s1

s1 s2 s3

s1 s2 s3 A s4

s1s2s3 A s4s4

.

.

.

.

.

0

1

1

1

A. Trivedi Hybrid Systems

Page 47: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 32 of 39

Universal Non-deterministic Finite AutomataSemantics using extended transition function:

– The language L(A) accepted by an NFA A = (S,Σ, δ, s0,F) is definedas:

L(A)def= {w : δ̂(w) ⊆ F}.

Semantics using accepting computation:– A computation or a run of a NFA on a string w = a0a1 . . . an−1 is a

finite sequences0, r1, s1, r2, . . . , rk−1, sn

where s0 is the starting state, and si+1 ∈ δ(si−1, ri) andr0r1 . . . rk−1 = a0a1 . . . an−1.

– A string w is accepted by an NFA A if the last state of allcomputations of A on w is an accept state sn ∈ F.

– Language of an NFA A

L(A) = {w : string w is accepted by NFA A}.

Proposition

Both semantics define the same language. Proof by induction.

A. Trivedi Hybrid Systems

Page 48: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 33 of 39

ε-free UNFA = DFA

Let A = (S,Σ, δ, s0,F) be an ε-free UNFA. Consider the DFADet(A) = (S′,Σ′, δ′, s′0,F

′) where– S′ = 2S,– Σ′ = Σ,– δ′ : 2S × Σ→ 2S such that δ′(P, a) =

⋃s∈P δ(s, a),

– s′0 = {s0}, and– F′ ⊆ S′ is such that F′ = {P : P ⊆ F}.

Theorem (ε-free UNFA = DFA)

L(A) = L(Det(A)). By induction, hint δ̂(s0,w) = δ̂′(s0,w).

Exercise (3.2)Extend the proof for UNFA with ε transitions.

A. Trivedi Hybrid Systems

Page 49: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 33 of 39

ε-free UNFA = DFA

Let A = (S,Σ, δ, s0,F) be an ε-free UNFA. Consider the DFADet(A) = (S′,Σ′, δ′, s′0,F

′) where– S′ = 2S,– Σ′ = Σ,– δ′ : 2S × Σ→ 2S such that δ′(P, a) =

⋃s∈P δ(s, a),

– s′0 = {s0}, and– F′ ⊆ S′ is such that F′ = {P : P ⊆ F}.

Theorem (ε-free UNFA = DFA)

L(A) = L(Det(A)). By induction, hint δ̂(s0,w) = δ̂′(s0,w).

Exercise (3.2)Extend the proof for UNFA with ε transitions.

A. Trivedi Hybrid Systems

Page 50: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 34 of 39

Complementation of an NFA

TheoremComplementation of the language of an NFA A = (S,Σ, δ, s0,F) is the languageaccepted by the UNFA A′ = (S,Σ, δ, s0,S \ F).

Exercise (3.3)Write a formal proof for this theorem.

A. Trivedi Hybrid Systems

Page 51: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 35 of 39

Alternating Finite State Automata

Estart O

01

0

1

Ashok K. Chandra Larry J. Stockmeyer

A. Trivedi Hybrid Systems

Page 52: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 36 of 39

Alternating Finite State Automata

Estart O

01

0

1

An alternating finite state automaton (AFA) is a tupleA = (S,S∃,S∀,Σ, δ, s0,F), where:

– S is a finite set called the states with a partition S∃ and S∀;– Σ is a finite set called the alphabet;– δ : S× (Σ ∪ {ε})→ 2S is the transition function;– s0 ∈ S is the start state; and– F ⊆ S is the set of accept states.

A. Trivedi Hybrid Systems

Page 53: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 37 of 39

Computation or Run of an AFA

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

s1start

s1

s1 s2 s3

s1 s2 s3 A s4

s1s2s3 A s4s4

.

.

.

.

.

0

1

1

1

A. Trivedi Hybrid Systems

Page 54: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 38 of 39

Universal Non-deterministic Finite Automata

– A computation or a run of a AFA on a string w = a0a1 . . . an−1 is agame graph G(A,w) = (S× {0, 1, 2, . . . ,n− 1},E) where:

– Nodes in S∃ × {0, 1, 2, . . . , n− 1} are controlled by Eva and nodes inS∀ × {0, 1, 2, . . . , n} are controlled by Adam; and

– ((s, i), (s′, i + 1)) ∈ E if s′ ∈ δ(s, ai).

– Initially a token is in (s0, 0) node, and at every step the controller ofthe current node chooses the successor node.

– Eva wins if the node reached at level i is an accepting state node,otherwise Adam wins.

– We say that Eva has a winning strategy if she can make her decisionsno matter how Adam plays.

– A string w is accepted by an AFA A if Eva has a winning strategy inthe graph G(A,w).

– Language of an AFA A L(A) = {w : string w is accepted by AFA A}.– Example.

A. Trivedi Hybrid Systems

Page 55: Finite Automata and Languages - IIT Bombaytrivedi/courses/cs620/lecture08.pdf · A. Trivedi – 3 of 39 Machines and their Mathematical Abstractions Finite instruction machine with

A. Trivedi – 39 of 39

ε-free AFA = NFA

Let A = (S,S∃,S∀,Σ, δ, s0,F) be an ε-free AFA. Consider the NFANDet(A) = (S′,Σ′, δ′, s′0,F

′) where– S′ = 2S,– Σ′ = Σ,

– δ′ : 2S × Σ→ 22Ssuch that Q ∈ δ′(P, a) if

– for all universal states p ∈ P ∩ S∀ we have that δ(p, a) ⊆ Q and– for all existential states p ∈ P ∩ S∃ we have that δ(p, a) ∩Q 6= ∅,

– s′0 = {s0}, and– F′ ⊆ S′ is such that F′ = 2F \ ∅.

Theorem (ε-free AFA = NFA)L(A) = L(Det(A)).

A. Trivedi Hybrid Systems