Progesterone Induction of the 11 -Hydroxysteroid Dehydrogenase

# CSCI 3434: Theory of Computationastr3586/courses/csci3434/lec03.pdf · Ashutosh Trivedi – 6 of 28...

### Transcript of CSCI 3434: Theory of Computationastr3586/courses/csci3434/lec03.pdf · Ashutosh Trivedi – 6 of 28...

Ashutosh Trivedi – 1 of 28

CSCI 3434: Theory of ComputationLecture 3: Nondeterminism

Ashutosh Trivedi

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

Department of Computer ScienceUNIVERSITY OF COLORADO BOULDER

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 2 of 28

Recursive Definitions and Structural Induction

Regular Languages: Nondeterminism

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 3 of 28

Recursive Definitions

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 3 of 28

Recursive Definitions

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 4 of 28

Recursive Definitions

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 5 of 28

Recursive Definitions

Definition (Recursive Definitions.)1. Defining an object using recursion.2. Defining an object in terms of itself.

– Expressions over + and ∗:– Base case: Any number of a variable is an expression.– Induction: If E and F are expressions then so are E + F, E ∗ F, and (E).

– Set of Natural numbers N:– Base case: 0 ∈ N.– Induction: If k ∈ N then k + 1 ∈ N.

– Definitions of the factorial function and Fibonacci sequence– Definition of a singly-linked list or trees.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 5 of 28

Recursive Definitions

Definition (Recursive Definitions.)1. Defining an object using recursion.2. Defining an object in terms of itself.

– Expressions over + and ∗:– Base case: Any number of a variable is an expression.– Induction: If E and F are expressions then so are E + F, E ∗ F, and (E).

– Set of Natural numbers N:– Base case: 0 ∈ N.– Induction: If k ∈ N then k + 1 ∈ N.

– Definitions of the factorial function and Fibonacci sequence– Definition of a singly-linked list or trees.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 5 of 28

Recursive Definitions

Definition (Recursive Definitions.)1. Defining an object using recursion.2. Defining an object in terms of itself.

– Expressions over + and ∗:– Base case: Any number of a variable is an expression.– Induction: If E and F are expressions then so are E + F, E ∗ F, and (E).

– Set of Natural numbers N:– Base case: 0 ∈ N.– Induction: If k ∈ N then k + 1 ∈ N.

– Definitions of the factorial function and Fibonacci sequence– Definition of a singly-linked list or trees.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 5 of 28

Recursive Definitions

– Set of Natural numbers N:– Base case: 0 ∈ N.– Induction: If k ∈ N then k + 1 ∈ N.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 6 of 28

Structural Induction

Principle of Structural Induction1. Let R be a recursive definition.2. Let S be a statement about the elements defined by R.

3. If the following hypotheses hold:– S is True for every element b1, . . . , bm in the base case of the definition R.– For every element E constructed by the recursive definition from some

elements e1, . . . , en

S is True for e1, . . . en =⇒ S is true for E

4. Then we can conclude that:S is True for Every Element E defined by the recursive definition R.

Examples:– For all n ≥ 0 we have that

∑ni=0 i = n(n + 1)/2.

– Every expression defined has an equal number of left and rightparenthesis.

– Every tree has one more node than the edges.– Other examples

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 6 of 28

Structural Induction

Principle of Structural Induction1. Let R be a recursive definition.2. Let S be a statement about the elements defined by R.3. If the following hypotheses hold:

– S is True for every element b1, . . . , bm in the base case of the definition R.

– For every element E constructed by the recursive definition from someelements e1, . . . , en

S is True for e1, . . . en =⇒ S is true for E

4. Then we can conclude that:S is True for Every Element E defined by the recursive definition R.

Examples:– For all n ≥ 0 we have that

∑ni=0 i = n(n + 1)/2.

– Every expression defined has an equal number of left and rightparenthesis.

– Every tree has one more node than the edges.– Other examples

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 6 of 28

Structural Induction

Principle of Structural Induction1. Let R be a recursive definition.2. Let S be a statement about the elements defined by R.3. If the following hypotheses hold:

– S is True for every element b1, . . . , bm in the base case of the definition R.– For every element E constructed by the recursive definition from some

elements e1, . . . , en

S is True for e1, . . . en =⇒ S is true for E

4. Then we can conclude that:S is True for Every Element E defined by the recursive definition R.

Examples:– For all n ≥ 0 we have that

∑ni=0 i = n(n + 1)/2.

– Every expression defined has an equal number of left and rightparenthesis.

– Every tree has one more node than the edges.– Other examples

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 6 of 28

Structural Induction

Principle of Structural Induction1. Let R be a recursive definition.2. Let S be a statement about the elements defined by R.3. If the following hypotheses hold:

– S is True for every element b1, . . . , bm in the base case of the definition R.– For every element E constructed by the recursive definition from some

elements e1, . . . , en

S is True for e1, . . . en =⇒ S is true for E

4. Then we can conclude that:S is True for Every Element E defined by the recursive definition R.

Examples:– For all n ≥ 0 we have that

∑ni=0 i = n(n + 1)/2.

– Every expression defined has an equal number of left and rightparenthesis.

– Every tree has one more node than the edges.– Other examples

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 6 of 28

Structural Induction

– S is True for every element b1, . . . , bm in the base case of the definition R.– For every element E constructed by the recursive definition from some

elements e1, . . . , en

S is True for e1, . . . en =⇒ S is true for E

4. Then we can conclude that:S is True for Every Element E defined by the recursive definition R.

Examples:– For all n ≥ 0 we have that

∑ni=0 i = n(n + 1)/2.

– Every expression defined has an equal number of left and rightparenthesis.

– Every tree has one more node than the edges.– Other examples

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 6 of 28

Structural Induction

elements e1, . . . , en

S is True for e1, . . . en =⇒ S is true for E

4. Then we can conclude that:S is True for Every Element E defined by the recursive definition R.

Examples:– For all n ≥ 0 we have that

∑ni=0 i = n(n + 1)/2.

– Every expression defined has an equal number of left and rightparenthesis.

– Every tree has one more node than the edges.– Other examples

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 6 of 28

Structural Induction

elements e1, . . . , en

S is True for e1, . . . en =⇒ S is true for E

4. Then we can conclude that:S is True for Every Element E defined by the recursive definition R.

Examples:– For all n ≥ 0 we have that

∑ni=0 i = n(n + 1)/2.

– Every expression defined has an equal number of left and rightparenthesis.

– Every tree has one more node than the edges.

– Other examples

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 6 of 28

Structural Induction

elements e1, . . . , en

S is True for e1, . . . en =⇒ S is true for E

4. Then we can conclude that:S is True for Every Element E defined by the recursive definition R.

Examples:– For all n ≥ 0 we have that

∑ni=0 i = n(n + 1)/2.

– Every expression defined has an equal number of left and rightparenthesis.

– Every tree has one more node than the edges.– Other examples

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 7 of 28

Recursive Definitions and Structural Induction

Regular Languages: Nondeterminism

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 8 of 28

What are Regular Languages?

– An alphabet Σ = {a, b, c} is a finite set of letters,

– The set of all strings (aka, words) Σ∗ over an alphabet Σ can berecursively defined as: as :

– Base case: ε ∈ Σ∗ (empty string),– Induction: If w ∈ Σ∗ then wa ∈ Σ∗ for all a ∈ Σ.

– A language L over some alphabet Σ is a set of strings, i.e. L ⊆ Σ∗.– Some examples:

– Leven = {w ∈ Σ∗ : w is of even length}– La∗b∗ = {w ∈ Σ∗ : w is of the form anbm for n,m ≥ 0}– Lanbn = {w ∈ Σ∗ : w is of the form anbn for n ≥ 0}– Lprime = {w ∈ Σ∗ : w has a prime number of a′s}

– Deterministic finite state automata define languages that require finiteresources (states) to recognize.

Definition (Regular Languages)We call a language regular if it can be accepted by a deterministic finitestate automaton.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 8 of 28

What are Regular Languages?

– An alphabet Σ = {a, b, c} is a finite set of letters,– The set of all strings (aka, words) Σ∗ over an alphabet Σ can be

recursively defined as: as :– Base case: ε ∈ Σ∗ (empty string),– Induction: If w ∈ Σ∗ then wa ∈ Σ∗ for all a ∈ Σ.

– A language L over some alphabet Σ is a set of strings, i.e. L ⊆ Σ∗.– Some examples:

– Leven = {w ∈ Σ∗ : w is of even length}– La∗b∗ = {w ∈ Σ∗ : w is of the form anbm for n,m ≥ 0}– Lanbn = {w ∈ Σ∗ : w is of the form anbn for n ≥ 0}– Lprime = {w ∈ Σ∗ : w has a prime number of a′s}

– Deterministic finite state automata define languages that require finiteresources (states) to recognize.

Definition (Regular Languages)We call a language regular if it can be accepted by a deterministic finitestate automaton.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 8 of 28

What are Regular Languages?

– An alphabet Σ = {a, b, c} is a finite set of letters,– The set of all strings (aka, words) Σ∗ over an alphabet Σ can be

recursively defined as: as :– Base case: ε ∈ Σ∗ (empty string),– Induction: If w ∈ Σ∗ then wa ∈ Σ∗ for all a ∈ Σ.

– A language L over some alphabet Σ is a set of strings, i.e. L ⊆ Σ∗.– Some examples:

– Leven = {w ∈ Σ∗ : w is of even length}– La∗b∗ = {w ∈ Σ∗ : w is of the form anbm for n,m ≥ 0}– Lanbn = {w ∈ Σ∗ : w is of the form anbn for n ≥ 0}– Lprime = {w ∈ Σ∗ : w has a prime number of a′s}

– Deterministic finite state automata define languages that require finiteresources (states) to recognize.

Definition (Regular Languages)We call a language regular if it can be accepted by a deterministic finitestate automaton.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 8 of 28

What are Regular Languages?

– An alphabet Σ = {a, b, c} is a finite set of letters,– The set of all strings (aka, words) Σ∗ over an alphabet Σ can be

recursively defined as: as :– Base case: ε ∈ Σ∗ (empty string),– Induction: If w ∈ Σ∗ then wa ∈ Σ∗ for all a ∈ Σ.

– A language L over some alphabet Σ is a set of strings, i.e. L ⊆ Σ∗.– Some examples:

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 9 of 28

Why they are “Regular”

– A number of widely different and equi-expressive formalismsprecisely capture the same class of languages:

– Deterministic finite state automata– Nondeterministic finite state automata (also with ε-transitions)– Kleene’s regular expressions, also appeared as Type-3 languages in

Chomsky’s hierarchy [Cho59].– Monadic second-order logic definable languages [B60, Elg61, Tra62]– Certain Algebraic connection (acceptability via finite semi-group) [RS59]

Today we show that:

Theorem (DFA=NFA=ε-NFA)A language is accepted by a deterministic finite automaton if and only if it isaccepted by a non-deterministic finite automaton.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 9 of 28

Why they are “Regular”

– A number of widely different and equi-expressive formalismsprecisely capture the same class of languages:

– Deterministic finite state automata– Nondeterministic finite state automata (also with ε-transitions)– Kleene’s regular expressions, also appeared as Type-3 languages in

Chomsky’s hierarchy [Cho59].– Monadic second-order logic definable languages [B60, Elg61, Tra62]– Certain Algebraic connection (acceptability via finite semi-group) [RS59]

Today we show that:

Theorem (DFA=NFA=ε-NFA)A language is accepted by a deterministic finite automaton if and only if it isaccepted by a non-deterministic finite automaton.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 10 of 28

Finite State Automata

Estart O

01

0

1

Warren S. McCullough Walter Pitts

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 11 of 28

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 ∈ Σ.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 11 of 28

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 ∈ Σ.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 11 of 28

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 ∈ Σ.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 12 of 28

Deterministic Finite State Automata (DFA)

Estart O

01

0

1

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

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

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 13 of 28

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

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 14 of 28

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.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 15 of 28

Nondeterministic Finite State Automata

s1start s2 s3 s4

0, 1

1 0, ε 1

0, 1

Michael O. Rabin Dana Scott

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 16 of 28

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.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 17 of 28

ε-closure ECLOS

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

– ε-closure ECLOS(s) of a state s is the set of states that can be reachedfrom s (including itself) via ε-transitions. E.g.

ECLOS(s2) = {s2, s3, s4} and ECLOS(s3) = {s3, s4}

– ECLOS(R) = ∪s∈RECLOS(R). E.g.

ECLOS({s1, s2}) = {s1, s2, s3, s4}

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 17 of 28

ε-closure ECLOS

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

– ε-closure ECLOS(s) of a state s is the set of states that can be reachedfrom s (including itself) via ε-transitions. E.g.

ECLOS(s2) = {s2, s3, s4} and ECLOS(s3) = {s3, s4}

– ECLOS(R) = ∪s∈RECLOS(R). E.g.

ECLOS({s1, s2}) = {s1, s2, s3, s4}

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 17 of 28

ε-closure ECLOS

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

– ε-closure ECLOS(s) of a state s is the set of states that can be reachedfrom s (including itself) via ε-transitions. E.g.

ECLOS(s2) = {s2, s3, s4} and ECLOS(s3) = {s3, s4}

– ECLOS(R) = ∪s∈RECLOS(R). E.g.

ECLOS({s1, s2}) = {s1, s2, s3, s4}

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 17 of 28

ε-closure ECLOS

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

ECLOS(s2) = {s2, s3, s4} and ECLOS(s3) = {s3, s4}

– ECLOS(R) = ∪s∈RECLOS(R). E.g.

ECLOS({s1, s2}) = {s1, s2, s3, s4}

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 17 of 28

ε-closure ECLOS

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

ECLOS(s2) = {s2, s3, s4} and ECLOS(s3) = {s3, s4}

– ECLOS(R) = ∪s∈RECLOS(R). E.g.

ECLOS({s1, s2}) = {s1, s2, s3, s4}

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 18 of 28

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) =

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

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

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 18 of 28

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) =

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

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

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 19 of 28

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:

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

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

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 20 of 28

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

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 21 of 28

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.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 22 of 28

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.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 22 of 28

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.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 23 of 28

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

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 24 of 28

ε-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).

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 25 of 28

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 w be ε. The base case follows immediately from thedefinition of extended transition functions:

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

– Induction Step: Let w = xa where x ∈ Σ∗ and a ∈ Σ. 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 δ′.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 25 of 28

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 w be ε. The base case follows immediately from thedefinition of extended transition functions:

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

– Induction Step: Let w = xa where x ∈ Σ∗ and a ∈ Σ. 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 δ′.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 25 of 28

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 w be ε. The base case follows immediately from thedefinition of extended transition functions:

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

– Induction Step: Let w = xa where x ∈ Σ∗ and a ∈ Σ. 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 δ′.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 25 of 28

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.

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

– Induction Step: Let w = xa where x ∈ Σ∗ and a ∈ Σ. 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 δ′.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 25 of 28

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

– Induction Step: Let w = xa where x ∈ Σ∗ and a ∈ Σ. 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 δ′.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 25 of 28

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

– Induction Step: Let w = xa where x ∈ Σ∗ and a ∈ Σ. 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 δ′.

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 26 of 28

Equivalence of NFA and DFA

Exercise (In class)Determinize the following automaton:

s1start s2 s3 s4

0, 1

1 0, 1 0, 1

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 27 of 28

NFA with ε transitions = DFA

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

ECLOS(s2) = {s2, s3, s4} and ECLOS(s3) = {s3, s4}

– ECLOS(R) = ∪s∈RECLOS(R). E.g.

ECLOS({s1, s2}) = {s1, s2, s3, s4}

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 27 of 28

NFA with ε transitions = DFA

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

ECLOS(s2) = {s2, s3, s4} and ECLOS(s3) = {s3, s4}

– ECLOS(R) = ∪s∈RECLOS(R). E.g.

ECLOS({s1, s2}) = {s1, s2, s3, s4}

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 27 of 28

NFA with ε transitions = DFA

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

ECLOS(s2) = {s2, s3, s4} and ECLOS(s3) = {s3, s4}

– ECLOS(R) = ∪s∈RECLOS(R). E.g.

ECLOS({s1, s2}) = {s1, s2, s3, s4}

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 27 of 28

NFA with ε transitions = DFA

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

ECLOS(s2) = {s2, s3, s4} and ECLOS(s3) = {s3, s4}

– ECLOS(R) = ∪s∈RECLOS(R). E.g.

ECLOS({s1, s2}) = {s1, s2, s3, s4}

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 27 of 28

NFA with ε transitions = DFA

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

ECLOS(s2) = {s2, s3, s4} and ECLOS(s3) = {s3, s4}

– ECLOS(R) = ∪s∈RECLOS(R). E.g.

ECLOS({s1, s2}) = {s1, s2, s3, s4}

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 28 of 28

NFA with ε transitions = DFA

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

– 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 ECLOS(δ(s, a)),

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

Theorem (NFA with ε-transitions = DFA)

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

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 28 of 28

NFA with ε transitions = DFA

s1start s2 s3 s4

0, 1

1 0, ε 1, ε

0, 1

– 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 ECLOS(δ(s, a)),

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

Theorem (NFA with ε-transitions = DFA)

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

Ashutosh Trivedi Lecture 3: Nondeterminism

Ashutosh Trivedi – 28 of 28

J. R. Buchi.Weak second-order arithmetic and finite automata.Zeitschrift fur Mathematische Logik und Grundlagen der Mathematik,6(1–6):66–92, 1960.

Noam Chomsky.On certain formal properties of grammars.Information and Control, 2(2):137 – 167, 1959.

C. C. Elgot.Decision problems of finite automata design and related arithmetics.In Transactions of the American Mathematical Society, 98(1):21–51, 1961.

M. O. Rabin and D. Scott.Finite automata and their decision problems.IBM Journal of Research and Developmen, 3(2):114–125, 1959.

B. A. Trakhtenbrot.Finite automata and monadic second order logic.Siberian Mathematical Journal, 3:101–131, 1962.

Ashutosh Trivedi Lecture 3: Nondeterminism