computational models — lecture 2tau-cm2019.wdfiles.com/local--files/course-schedule/dfa2.pdf ·...

64
Computational Models Lecture 2 Handout Mode Roded Sharan. Tel Aviv University. March, 2019 Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 1 / 64

Upload: others

Post on 31-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Computational Models — Lecture 2

Handout Mode

Roded Sharan.

Tel Aviv University.

March, 2019

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 1 / 64

Computational Models - Lecture 2

I Non-Deterministic Finite Automata (NFA)

I Closure of Regular Languages Under⋃, ‖, ∗

I Regular expressions

I Equivalence with finite automata

I Sipser’s book, 1.1− 1.3

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 2 / 64

Part I

Non-Deterministic Finite Automata

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 3 / 64

DFA – formal definition, (reminder)

Definition 1 (DFA)

A deterministic finite automaton (DFA) is a 5-tuple (Q,Σ, δ,q0,F ), where

I Q is a finite set called the states,

I Σ is a finite set called the alphabet,

I δ : Q × Σ 7→ Q is the transition function,

I q0 ∈ Q is the start state, and

I F ⊆ Q is the set of accept states.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 4 / 64

Formal model of computation, (reminder)

Definition 2

M = (Q,Σ, δ,q0,F ) accepts w ∈ Σ∗ if δ̂(q0,w) ∈ F .

Definition 3 (δ̂)

For DFA M = (Q,Σ, δ,q0,F ), define δ̂ : Q × Σ∗ 7→ Q by

δ̂(q,w) =

{δ(δ̂(q,w1,...,n−1),wn), n = |w | ≥ 1q, w = ε.

.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 5 / 64

The language of a DFA, (reminder)

Definition 4The language of a DFA M, denoted L(M), is the set of strings that M accepts.

Definition 5A language is called regular, if some deterministic finite automaton accepts it.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 6 / 64

NFA — non-deterministic Finite Automata

q4

q1

q2

q3

0

0,1 0,1

10

I May have more than one transition labeled with the same symbol,

I May have no transitions labeled with a certain symbol,

I The machine “splits” into multiple copies covering all possibilities

I Each branch follows one possibility

I If the input doesn’t appear, that branch “dies”.

I Automaton accepts if some branch accepts.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 7 / 64

Computation on 1001

q4

q1

q2

q3

0

0,1 0,1

10

q1

q1

q2

q1

q2

q1

q3

q1

q4

1

0

0

1

symbol

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 8 / 64

NFA – Formal Definition

Let P(Q) denote the powerset of Q (i.e., all subsets of Q).

Definition 6 (NFA)

A non-deterministic finite automaton is a 5-tuple (Q,Σ, δ,S,F ), where

I Q is a finite set called the states

I Σ is a finite set called the alphabet

I δ : Q × Σ 7→ P(Q) is the transition function

I S ⊆ Q is the set of starting states

I F ⊆ Q are the set of accepting states

We sometimes consider an NFA (Q,Σ, δ,q0,F ).This is merely a “syntactic sugar” for the NFA (Q,Σ, δ, {q0},F )

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 9 / 64

Example

q4

q1

q2

q3

0

0,1 0,1

10

N1 = (Q = {q1,q2,q3,q4},Σ = {0,1}, δ,S = {q1},F = {q4})

for δ defined by

0 1q1 {q1,q2} {q1}q2 {q3} ∅q3 ∅ {q4}q4 {q4} {q4}

Note that ∅ is a valid output for δ

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 10 / 64

Formal model of computation

Definition 7

N = (Q,Σ, δ,S,F ) accepts w ∈ Σ∗, if δ̂N(S,w) ∩ F 6= ∅.

Definition 8 (δ̂)

For NFA N = (Q,Σ, δ,S,F ), define δ̂N : P(Q)× Σ∗ 7→ P(Q) by:

for Q′ ⊆ Q, δ̂N(Q′,w) =

{Q′, w = ε,⋃

q∈δ̂N (Q′,w1,...,n−1)δ(q,wn), n = |w | ≥ 1. .

When clear from the context we will write δ̂ (i.e., omitting the N ).

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 11 / 64

An equivalent definition

Definition 9 (Equivalent definition)

N = (Q,Σ, δ,S,F ) accepts w = w1, . . . ,wn ∈ Σn, if if ∃r0, . . . , rn ∈ Q s.t.

I r0 ∈ S

I rn ∈ F

I ri+1∈δ(ri ,wi+1), for all 0 ≤ i < n.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 12 / 64

Equivalence of NFA’s and DFA’s

Easy: For any DFA M there exists a NFA N such that L(N) = L(M).

Other direction is also true.

Theorem 10For any NFA N there exists a DFA M such that L(N) = L(M).

I Given an NFA N, we construct a DFA M, that accepts the samelanguage.

I Make DFA emulates all possible NFA states.

I As consequence of the construction, if the NFA has k states, the DFAhas 2k states (an exponential blow up).

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 13 / 64

Equivalence of NFA’s and DFA’s, the DFA

Let N = (Q,Σ, δ,S,F ).

Construction 11 (M = (QM ,Σ, δM ,d0,FM))

I QM = {[R] : R ⊆ Q}.I d0 = [S]

I FM = {[R] ∈ QM : R ∩ F 6= ∅}

I For [R] ∈ QM and σ ∈ Σ, let δM([R], σ) = [δ̂N(R, σ)] (=[⋃

r∈R δ(r , σ)]).

To prove equivalence, we need to prove that

δ̂N(S,w) ∩ F 6= ∅ ⇐⇒ δ̂M(d0,w) ∈ FM

The above is an immediate corollary of the following claim:

Claim 12

[δ̂N(S,w)] = δ̂M(d0,w) for every w ∈ Σ∗.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 14 / 64

Proving [δ̂N(S,w)] = δ̂M(d0,w)

The proof is by induction on the length of w .

I |w | = 0, by definition.

I Assume for words of length (m− 1), and let x = yσ, where y is a word oflength (m − 1) and σ ∈ Σ.

I Let Qy = δ̂N(S, y) and dy = δ̂M(d0, y).

I Compute

δ̂M(d0, x) = δM(dy , σ) (By definition of δ̂M )= δM([Qy ], σ) (By i.h)

= [δ̂N(Qy , σ)] (By definition of δM )

=[ ⋃

q∈Qy

δ(q, σ)]

(By definition of δ̂N )

=[ ⋃

q∈δ̂N (S,y)

δ(q, σ)]

= [δ̂N(S, x)]. (By definition of δ̂N )

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 15 / 64

Example: NFA⇒ DFA

Non-Deterministic Automata:

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 16 / 64

Example: NFA⇒ DFA

Deterministic automata - set of states:

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 17 / 64

Example: NFA⇒ DFA

Transitions from [{q0}]:

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 18 / 64

Example: NFA⇒ DFA

Transitions from [{q0,q1}]:

Transitions from [∅] and [{q1}]?

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 19 / 64

NFA with ε-moves

q4

q1

q2

q3

0

0,1 0,1

10,ε

What is the interpretation of ε transitions ?What will happen with 101 ?

We will distinguish ε (that stands for the empty word) from the ε above (thatstands for “free transition”) by context

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 20 / 64

Example: NFA with ε-moves

L = {aibjck |i , j , k ≥ 0}

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 21 / 64

NFA — Formal definition with ε-moves

Transition function δ is going to be different.

I Let P(Q) denote the powerset of Q.

I Let Σε denote the set Σ ∪ {ε}.

Definition 13 (NFA, with ε-moves)

A non-deterministic finite automaton is a 5-tuple (Q,Σ, δ,S,F ):

I Q is a finite set called the states

I Σ is a finite set called the alphabet

I δ : Q × Σε 7→ P(Q) is the transition function

I S ⊆ Q is the set of starting state

I F ⊆ Q is the set of accepting states

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 22 / 64

Example

q4

q1

q2

q3

0

0,1 0,1

10,ε

N1 = (Q,Σ, δ,S,F ):

I Q = {q1,q2,q3,q4}, Σ = {0,1}, S = {q1} and F = {q4}.

I δ is

0 1 εq1 {q1,q2} {q1} ∅q2 {q3} ∅ {q3}q3 ∅ {q4} ∅q4 {q4} {q4} ∅

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 23 / 64

Formal model of computation, with ε-moves

Definition 14

N = (Q,Σ, δ,S,F ) accepts w ∈ Σ∗, if δ̂N(S,w) ∩ F 6= ∅.

Definition 15For NFA N = (Q,Σ, δ,S,F ), letE(q) = {q′ ∈ Q : q′ can be reached from q by 0 or more ε transitions}(i.e., {q′ : ∃q1, . . . , qk ∈ Q s.t.q1 = q ∧ qk = q′ ∧ ∀i ∈ [k − 1] qi+1 ∈ δ(qi , ε)})

E(Q′) =⋃

q∈Q′ E(q).

In particular, q ∈ E(q).

Definition 16 (δ̂)

For NFA N = (Q,Σ, δ,S,F ), define δ̂N : P(Q)× Σ∗ 7→ P(Q) by:

for Q′ ⊆ Q, δ̂N(Q′,w) =

{E(Q′), w = ε,

E(⋃

r∈δ̂(Q′,w1,...,wn−1)δ(r ,wn)

), n = |w | ≥ 1. .

When does N accept the empty string?Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 24 / 64

An equivalent definition

For a ∈ (Σε)∗, let d(a) ∈ Σ∗ be a without the ε symbols.

Example: d(ε01εε3ε) = 013

Definition 17 (Equivalent definition)

N = (Q,Σ, δ,S,F ) accepts w ∈ Σ∗, if exist a = (a1a2 . . . ak ) ∈ (Σε)k and

r0, . . . , rk ∈ Q s.t.

I w = d(a).

I r0 ∈ S

I rk ∈ F

I ri+1 ∈ δ(ri ,ai+1), for all 0 ≤ i < k .

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 25 / 64

Removing ε-transitions

Given NFA N = (Q,Σ, δ,S,F ) with ε-transitions, we create an equivalent NFAN ′ = (Q,Σ, δ′,S′,F ) with no ε-transitions.

I S′ = E(S)

I δ′(q,a) = E(δ(q,a))

It is not hard to prove that δ̂N(S,w) = δ̂N′(S′,w) for any w ∈ Σ∗.

Thus, L(N) = L(N ′).

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 26 / 64

Example: Removing ε-transitions

Non-Deterministic Automata with ε-transitions

The non-Deterministic automata without ε-transitions

I S′ = {q0,q1,q2,q3}

I δ′ is

a b cq0 ∅ ∅ ∅q1 {q1,q2,q3} ∅ ∅q2 ∅ {q2,q3} ∅q3 ∅ ∅ {q3}

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 27 / 64

Part II

Closure of Regular Languages, Revisited

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 28 / 64

Regular languages, revisited

By definition, a language is regular if it is accepted by some DFA.

Corollary 18

A language is regular if and only if it is accepted by some NFA.

This is an alternative way of characterizing regular languages.

We will now use the equivalence to show that regular languages are closedunder the regular operations (union, concatenation, star).

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 29 / 64

Closure under union (alternative proof)

N1

N2

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 30 / 64

Closure under union, cont.

N1

N2

ε

ε

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 31 / 64

Closure under union cont..

I NFA N1 = (Q1,Σ, δ1,S1,F1) accept L1, and

I NFA N2 = (Q2,Σ, δ2,S2,F2) accept L2.

wlg. Q1 ∩Q2 = ∅.(?)

Define NFA N = (Q = {q0} ∪Q1 ∪Q2,Σ, δ,S = {q0},F = F1 ∪ F2),

for δ(q,a) =

δ1(q,a) q ∈ Q1δ2(q,a) q ∈ Q2S1 ∪ S2 q = q0 and a = ε

Alternatively, let S = S1 ∪ S2 and omit the last line of δ.

Claim 19L(N) = L(N1) ∪ L(N2).

Proof: Easily follows by the the alternative definition of acceptance by NFA,DIY...

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 32 / 64

Closure under concatenation

N2

N1

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 33 / 64

Closure under concatenation, cont.

N2N

1

ε

ε

Remark: Accepting states are exactly those of N2.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 34 / 64

Closure under concatenation, cont..

I NFA N1 = (Q1,Σ, δ1,S1,F1) accept L1

I NFA N2 = (Q2,Σ, δ2,S2,F2) accept L2

Define NFA N = (Q1 ∪Q2,Σ, δ,S1,F2):

δ(q,a) =

δ1(q,a) q ∈ Q1 ∧ a 6= εδ1(q,a) (q ∈ Q1 \ F1) ∧ a = εδ1(q,a) ∪ S2 q ∈ F1 ∧ a = εδ2(q,a) q ∈ Q2

Claim 20L(N) = L1‖L2.

Proof: Need to prove w ∈ L(N)⇐⇒ w ∈ L1‖L2.

We assume wlg. that N1 and N2 have no ε moves.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 35 / 64

Proving w ∈ L(N)⇐⇒ L1‖L2

Let w ∈ L1‖L2:

=⇒ ∃w1 ∈ L1 and w2 ∈ L2, s.t. w = w1w2

=⇒ ∃ r10 , . . . r

1|w1| and r2

0 , . . . r2|w2|, s.t.

I r10 ∈ S1 (2) r1

|w1| ∈ F1 (3) ∀i : r1i+1 ∈ δ1(r1

i ,w1i+1).

I r20 ∈ S2 (2) r2

|w2| ∈ F2 (3) ∀i : r2i+1 ∈ δ2(r2

i ,w2i+1).

=⇒ r10 , . . . r

1|w1|, r

20 , . . . r

2|w2| proves that w ∈ L(N)

Let w ∈ L(N) be of length k :

=⇒ ∃j and r0 . . . rk+1 s.t. for (a1, . . . ,ak+1) = (w1, . . . ,wj , ε,wj+1, . . .wk ):

I r0 ∈ S1 and rk+1 ∈ F2I ∀i : ri+1 ∈ δ(ri ,ai+1).

I r0 . . . rj proves that (w1, . . . ,wj ) ∈ L1

I rj+1 . . . rk proves that (wj+1, . . . ,wk ) ∈ L2

=⇒ w ∈ L1‖L2

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 36 / 64

Closure under star

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 37 / 64

Closure under star, cont.

Let N = (Q,Σ, δ,S,F ) accepting L, assuming wlg. that q0 /∈ Q.

Define N ′ = (Q′ = Q ∪ {q0},Σ, δ′,S′ = {q0},F ′ = {q0}):

δ′(q,a) =

δ(q,a) q ∈ Q ∧ a 6= εδ(q, ε) q /∈ F ∧ a = εδ(q, ε) ∪ {q0} q ∈ F ∧ a = εS q = q0 ∧ a = ε

Claim 21L(N ′) = L(N)∗.

Proof: DIY

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 38 / 64

Summary

I Regular languages are closed under

I unionI concatenationI star

I Non-deterministic finite automata

I are equivalent to deterministic finite automataI but much easier to use in some proofs and constructions.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 39 / 64

Part III

Regular Expressions

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 40 / 64

Regular expressions

Notation for building up languages by describing them as expressions, e.g.,(0 ∪ 1)0∗.

I 0 and 1 are shorthand for the set (languages) {0} and {1}I so 0 ∪ 1 = {0,1}.I 0∗ is shorthand for {0}∗.I Concatenation, is implicit. So 0∗10∗ stands for{w ∈ {0,1} : w has exactly a single 1}.

I Just like in arithmetic, operations have precedence:I star firstI concatenation nextI union lastI parentheses used to change default order i.e., ab∗ 6= (ab)∗

Q.: What does (0 ∪ 1)0∗ stand for?

Remark: Regular expressions are often used in text editors or shell scripts.Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 41 / 64

Regular expressions – formal definition

Definition 22A string R is a regular expression over alphabet Σ, if R is of form

I a for some a ∈ Σ

I ε

I ∅I (R1 ∪ R2) for regular expressions R1 and R2

I (R1‖R2) for regular expressions R1 and R2

I (R∗1 ) for regular expression R1

R(Σ) denotes all (finite) regular expression over Σ.

Parenthesis and ‖ are omitted when their role is clear from the context.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 42 / 64

Formal definition, cont.

Definition 23The language L(R) of regular expression R, is defined by

R L(R)a {a}ε {ε}∅ ∅(R1 ∪ R2) L(R1) ∪ L(R2)(R1R2) L(R1)‖L(R2)(R∗1 ) L(R1)∗

Isn’t this definition circular?

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 43 / 64

Examples of regular expressions

For Σ = {0,1}, write regular expression for the following languages:

I The third letter from the end is 1

(0 ∪ 1)∗1(0 ∪ 1)2

I The number of 1’s is even

(0 ∪ 10∗1)∗

I The number of 1’s is odd

(0 ∪ 10∗1)∗10∗

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 44 / 64

Part IV

Regular Expressions and Regular Languages

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 45 / 64

A remarkable fact

Theorem 24A language is described by a regular expression iff it is regular.

⇐=: Given a regular language, construct a regular expression describing it.

=⇒: Given a regular expression, construct an NFA accepting its language.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 46 / 64

Given RE R, build NFA accepting it (=⇒)

1. R = a , for some a ∈ Σ

a

2. R = ε

3. R = ∅

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 47 / 64

Given R, Build NFA Accepting It (=⇒), cont.

N1

N2

ε

ε

N2N

1

ε

ε

R = (R1 ∪ R2) R = (R1‖R2)

R = (R1)∗

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 48 / 64

Examplesa

a

b

b

ab ε

ba

ab ε

a

ε

ε

ba U a

Formal proof by induction on the length of the regular expression

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 49 / 64

Regular expression from a DFA (⇐=)

Proof relies on a generalization of NFAs.

NFA:

I Each transition is labeled with a symbol or ε.

I Reads zero or one symbols.

I Takes matching transition, if any.

Generalized non-deterministic finite automata (GNFA):

I Each transition is labeled with a regular expression.

I Reads zero or more symbols.

I Takes matching regular expression, if any.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 50 / 64

GNFA – Formal Definition

Let R(Σ) be the set of regular expressions over Σ.

Definition 25A generalized deterministic finite automaton (GNFA) is (Q,Σ, δ,qs,qa)

I Q is a finite set of states

I Σ is the alphabet

I δ : (Q \ {qa})× (Q \ {qs}) 7→ R(Σ) is the transition function.

I qs ∈ Q is the start state

I qa ∈ Q is the unique accept state

It is a special type of GNFA, but still it is easy to transform any DFA/NFA intothis form.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 51 / 64

GNFA – Model of Computation

Definition 26A GNFA G = (Q,Σ, δ,qs,qa) accepts a string w ∈ Σ∗, if there exists

I parsing w = a1a2 · · · ak ∈ (Σ∗)k , and

I r0, . . . , rk ∈ Q,

such that

I r0 = qs

I rk = qa

I ai ∈ L(δ(ri−1, ri )), for every 0 < i ≤ k .

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 52 / 64

The Transformation: DFA→ Regular Expression

Strategy – sequence of equivalent transformations

I Given a k -state DFA

I Transform into (k + 2)-state GNFA (how?)

I While GNFA has more than 2 states, transform it into equivalent GNFAwith one fewer state

I Eventually reach 2-state GNFA (states are just start and accept).

I Label of single transition is the desired regular expression. ♠

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 53 / 64

Removing a state

We remove one state qr , and then repair the machine by altering regularexpression of other transitions.

qi jq

qr

R1 3R

4R

qi jq

2R

2R*R1 3R U 4R

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 54 / 64

Conversion - Example

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 55 / 64

Conversion - Example

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 56 / 64

Conversion - Example

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 57 / 64

Conversion - Example

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 58 / 64

The StateReduce and Convert algorithms

Algorithm 27 (StateReduce)

Input: a (k > 2)-state GNFA G = (Q,Σ, δ,qs,qa).

I Select any state qr ∈ Q \ {qs,qa}.I Let Q′ = Q \ {qr}.I For any qi ∈ Q′ \ {qa} and qj ∈ Q′ \ {qs}, let

I R1 = δ(qi ,qr ), R2 = δ(qr ,qr ), R3 = δ(qr ,qj ) and R4 = δ(qi ,qj ).

I Define δ′(qi ,qj ) = (R1)(R2)∗(R3) ∪ (R4).

I Return the resulting (k − 1)-state GNFA G′ = (Q′,Σ, δ′,qs,qa).

Algorithm 28 (Convert)

Input: a (k ≥ 2)-state GNFA G.

I If k = 2, return the regular expression labeling the only arrow of G.

I Otherwise, return Convert(StateReduce(G)).

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 59 / 64

Correctness proof

Claim 29G and Convert(G) accept the same language.

Proof: By induction on k – the number of states of G.

Basis. k = 2: Immediate by the definition of GFNA.

Induction step: Assume claim for (k − 1)-state GNFA, where k > 2, prove fork -state GNFA.

Let G′ = StateReduce(G) (note that G′ has k − 1 states), and let qr be theremoved state.We prove (in a very high level) that L(G) = L(G′).

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 60 / 64

w ∈ L(G) =⇒ w ∈ L(G′)

Let w ∈ L(G) and let p = qs, . . . ,qa be (a possible) “path of states” traversedby G on w .

I If qr /∈ p, then G′ accepts w (the new regular expression on each edgeof G′ contains the old regular expression in the “union part”.)

I If p = qS, . . . ,qi ,qr ,qj , . . . ,qa, the regular expression (Ri,r )(Rr ,r )∗(Rr ,j )linking qi and qj in G′, causes G′ to accept w .

Hence, w ∈ L(G′).

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 61 / 64

w ∈ L(G′) =⇒ w ∈ L(G)

I Let qs = qj0 ,qj1 , . . . ,qjn = qa be (a possible) “path of states” traversed byG′ on w .

∃ parsing w = w1, . . . ,wn s.t. wi ∈ L(δG′(qji−1 ,qji )).

I For every i ∈ [n]:δG′(qji−1 ,qji ) =

(δG(qji−1 ,qr )δG(qr ,qr )∗δG(qr ,qji )

)∪ (δG(qji−1 ,qJi ).

I Hence for all i ∈ [n], the word wi corresponds to a possible traverse fromqji−1 to qji in G.

I Hence, w ∈ L(G′) =⇒ w ∈ L(G).

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 62 / 64

Summing it up

I We proved L(G) = L(G′).

I Hence, G and (the regular expression) Convert(G) accept the samelanguage.

I Thus, we proved: Every regular language can be described by a regularexpression.

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 63 / 64

Summary

I Non-Deterministic Automata (with ε-moves)

I Equivalence to DFA

I Closure properties

I unionI concatenationI star

I Regular expressions.

I Equivalence to DFA

Roded Sharan (TAU) Computational Models, Lecture 2 March, 2019 64 / 64