comp-330 theory of computation - mcgill...

Post on 18-Mar-2020

10 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

COMP-330 Theory of Computation

Fall 2017 -- Prof. Claude Crépeau Lec. 7 : Regular

Expressions & GNFA

COMP 330 Fall 2012: Lectures Schedule

14. Context-free languages15. Pushdown automata16. Parsing17. The pumping lemma for CFLs18. Introduction to computability19. Models of computation Basic computability theory20. Reducibility, undecidability and Rice’s theorem21. Undecidable problems about CFGs22. Post Correspondence Problem23. Validity of FOL is RE / Gödel’s and Tarski’s thms24. Universality / The recursion theorem 25. Degrees of undecidability26. Introduction to complexity

1-2. Introduction 1.5. Some basic mathematics2-3. Deterministic finite automata +Closure properties,4. Nondeterministic finite automata5. Minimization 6. Determinization+Kleene’s theorem7. Regular Expressions+GNFA8. Regular Expressions and Languages

+ Myhill-Nerode theorem,9-10. The pumping lemma11. Duality12. Labelled transition systems13. MIDTERM

Regular Expressions

Regular Expressions

1*(01+)*

Regular Expressions vs Regular Languages

Regular Expressions vs Regular Languages

Regular Expressions vs Regular Languages

Let RA generating LA.

If RA is a symbol “a” then use .If RA is “𝞮” then use .If RA is “∅” then use .If RA is R1 ∪ R2 then use Thm 1.45 and recursively use N1 and N2 s.t. L(N1) = L(R1) and L(N2) = L(R2).If RA is R1 ∘ R2 then use Thm 1.47 and recursively use N1 and N2 s.t. L(N1) = L(R1) and L(N2) = L(R2).If RA is R* then use Thm 1.49 and recursively use N s.t. L(N)=L(R).

Regular Expressions generate Reg. Languages

a

Reg. Expression → NFA

Two examples

(ab∪a)*

(a∪b)*aba

Automata recognize Regular Expressions

Generalized NFA

Example of GNFA

q1

q2

Generalized NFA

Generalized NFA

Definition of GNFA

1. Q={qstart,q1,q2,qaccept}

2.∑={a,b}

3.δ is given as

4.qstart is the start state

5.qaccept is the (unique) accept state

q1

q2

δ q1 q2 qaccept

qstart ab* ∅ b

q1 aa a* ab∪ba

q2 (aa)* ab b*

Let G = (Q,∑,δ,qstart,qaccept) be a generalized nondeterministic finite state automaton and let w=w1w2...wn (n≥0) be a string where each sub-string wi∈∑*.

G accepts w if ∃ s0,s1,...,sn s.t. 1. s0 = qstart 2. wi ∈ L( δ(si-1,si) ) for i = 1 ... n, and 3. sn = qaccept

Definition of GNFA

Example of GNFA

q1

q2

abbbaaaababaaba

qstart

Example of GNFA

q1

q2

abbbaaaababaaba ab*

Example of GNFA

q1

q2

abbbaaaababaaba

a*

Example of GNFA

q1

q2

abbbaaaababaaba

ab

Example of GNFA

q1

q2

abbbaaaababaaba

ab

Example of GNFA

q1

q2

abbbaaaababaaba

(aa)*

Example of GNFA

q1

q2

abbbaaaababaaba

ab∪ba

qaccept

DFA → GNFA → Reg. Exp.

Example NFA→GNFA

N1

Example NFA→GNFA

N1qstart

Example NFA→GNFA

N1𝞮qstart

Example NFA→GNFA

N1𝞮qstart

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1

G1

𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

0∪1

Example NFA→GNFA

N1

G1

𝞮qstart

𝞮

qacc

0∪1

0∪𝞮

∅ ∅

0∪1

DFA → GNFA → Reg. Exp.

Ripping a state

GNFA→ Reg. Exp.

Ripping of a GNFA

q1

q2

Ripping q1

Ripping of a GNFA

q2

Ripping q1

R4

R1 R2

R3

Ripping of a GNFA

q2

Ripping q1

∅∪ab*(aa)*a*

Ripping of a GNFA

q2

Ripping q1

∅∪ab*(aa)*a*

R4

R1 R2

R3

Ripping of a GNFA

q2

Ripping q1

∅∪ab*(aa)*a*

b∪ab*(aa)*(ab∪ba)

Ripping of a GNFA

q2

Ripping q1

∅∪ab*(aa)*a*

b∪ab*(aa)*(ab∪ba)

R4

R1

R2

R3

Ripping of a GNFA

q2

Ripping q1

∅∪ab*(aa)*a*

b∪ab*(aa)*(ab∪ba)

ab∪(aa)*(aa)*a*

Ripping of a GNFA

q2

Ripping q1

∅∪ab*(aa)*a*

b∪ab*(aa)*(ab∪ba)

ab∪(aa)*(aa)*a*R4

R2

R3

R1

Ripping of a GNFA

q2

∅∪ab*(aa)*a*

b∪ab*(aa)*(ab∪ba)

ab∪(aa)*(aa)*a*b*∪(aa)*(aa)*(ab∪ba)

Ripping of a GNFA

q2

∅∪ab*(aa)*a*

b∪ab*(aa)*(ab∪ba)

ab∪(aa)*(aa)*a*b*∪(aa)*(aa)*(ab∪ba)

Ripping of a GNFA

q2

∅∪ab*(aa)*a*

b∪ab*(aa)*(ab∪ba)

Ripping q2ab∪(aa)*(aa)*a*b*∪(aa)*(aa)*(ab∪ba)

Ripping of a GNFA

q2

∅∪ab*(aa)*a*

b∪ab*(aa)*(ab∪ba)

Ripping q2ab∪(aa)*(aa)*a*b*∪(aa)*(aa)*(ab∪ba)

R4

R1

R2

R3

Ripping of a GNFA

q2(b∪ab*(aa)*(ab∪ba))

∪(∅∪ab*(aa)*a*)

(ab∪(aa)*(aa)*a*)*(b*∪(aa)*(aa)*(ab∪ba))

GNFA → Reg. Expression

“equivalent” means L( CONVERT(G) ) = L(G)

GNFA → Reg. Expression

Induction basis

Let G be a GNFA with exactly k=2 states. Because of the special form of our GNFA, the two states are the start and accept states. The regular expression on the transition from qstart to qaccept generates the language accepted by this GNFA.

Induction step

Let G be a GNFA with exactly k>2 states. We assume for induction hypothesis that all GNFA G’ of k-1 states accept the laguage defined by the regular expression obtained via CONVERT, i.e. L(G’)=L(CONVERT(G’)).

Since k>2 then there exists at least one state qrip which is neither qstart nor qaccept.

GNFA → Reg. Exp.

Induction step

Let G’ be, as in CONVERT, the GNFA obtained after ripping qrip from G.

Let w be a string accepted by G, w∈L(G). C o n s i d e r a n a c c e pt i n g s e q u e n c e qstart,q1,q2,...,qaccept for string w.

GNFA → Reg. Exp.

If qrip is not a state of the sequence, then the very same exact sequence will accept w in G’ because its transitions R4 contain all those R4 in G (except for qrip) in a union with new possibilities related to ripping qrip.

GNFA → Reg. Exp.

If qrip is a state of the sequence, then the same sequence (but with all qrip removed) will accept w in G’. That’s because any three elements in a row qi,qrip,qj (qi≠qrip≠qj) in G’s accepting sequence, will be processed identically through states qi,qj in G’. Remember that the transitions for qi,qj in G’ contain all those R1(R2)*R3 from G involving qrip in a union with older possibilities (R4). (we can deal with qi,qrip,...,qrip,qj similarly.)

GNFA → Reg. Exp.

This proved “if w∈L(G) then w∈L(G’)”. We should also prove “if w∈L(G’) then w∈L(G)”.

Let w be a string accepted by G’, i.e. w∈L(G’). Consider an accepting sequence qstart,q1,q2,...,qaccept for string w. Consider any two consecutive states qi,qi+1. The same portion of w is processed in G in either part of the union, R1(R2)*R3 or R4, along the transition between qi and qi+1.

GNFA → Reg. Exp.

If the portion of w is generated by R4 in G’ then it is also generated by R4 in G. If the portion of w is generated by R1(R2)*R3 in G’ then there exists an m such that it is generated by R1(R2)mR3 and it is also generated in G by R1, going through qrip m times via R2 and finally R3. Thus qi,qi+1 is replaced by qi,qrip,...,qrip,qi+1.

We conclude that if w∈L(G’) then w∈L(G).

GNFA → Reg. Exp.

GNFA → Reg. Exp.

Combining both statements we get L(G’)=L(G).

By induction hypothesis L(G’)=L(CONVERT(G’)) becau se G’ conta ins k-1 state s. By construction, CONVERT(G)=CONVERT(G’). Therefore L(CONVERT(G))=L(CONVERT(G’))=L(G’)=L(G). QED

COMP-330 Theory of Computation

Fall 2017 -- Prof. Claude Crépeau Lec. 7 : Regular

Expressions & GNFA

top related