• Keine Ergebnisse gefunden

Pumping Lemma für reguläre Sprachen

N/A
N/A
Protected

Academic year: 2022

Aktie "Pumping Lemma für reguläre Sprachen"

Copied!
46
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

FORMAL LANGUAGES, AUTOMATA, AND

COMPUTABILITY

15-453

(2)

Q Σ q0 F

M = ({p,q}, {0,1}, , p, {q}) 0 1

p p q

q q p

0

1 1

0

p q

THEOREM:

L(M) = {w | w has odd

number of 1s }

Induction Step: Suppose for all w  Σ*, |w| = n, w  L(M) if w has odd number of 1s Any string of length n+1 has the form w0 or w1

If w has odd # of 1’s, M is in state q after reading w

 M is in state p after reading w1  M rejects w1

 M is in state q after reading w0  M accepts w0 Proof: By induction on n, the length of a string.

Base Case: n=0: ε  L and ε  L(M).

(3)

UNION THEOREM

The union of two regular languages is also a regular language

INTERSECTION THEOREM

The intersection of two regular languages is also a regular language

“Regular Languages Are Closed Under Union”

(4)

Complement THEOREM

The complement of a regular

language is also a regular language In other words,

if L is regular than so is L, where L= { w  Σ* | w  L }

Proof ?

(5)

THE REGULAR OPERATIONS

Union: A  B = { w | w  A or w  B }

Intersection: A  B = { w | w  A and w  B } Negation: A = { w  Σ* | w  A }

Reverse: AR = { w1 …wk | wk …w1  A }

Concatenation: A  B = { vw | v  A and w  B } Star: A* = { s1 … sk | k ≥ 0 and each si  A }

(6)

REVERSE THEOREM

The reverse of a regular language is also a regular language

``Regular Languages Are Closed Under Reverse”

If a language can be recognized by a DFA that reads strings from right to left,

then there is an “normal” DFA that accepts the same language

Counterintuitive! DFAs have finite memory…

(7)

REVERSING DFAs

Assume L is a regular language.

Let M be a DFA that recognizes L

We’ll build a machine MR that accepts LR If M accepts w, then w describes a

directed path in M from start to an accept First Attempt: Try to define MR as M with the arrows reversed, turn start state into a final state, turn final states into starts

(8)

M

R

IS NOT ALWAYS A DFA!

It could have many start states Some states may have too

many outgoing edges, or none at all!

(9)

1 0

1

0 1

0,1

0

(10)

NON DETERMINISM

1 0

1

0 1

0,1

0

What happens with 100?

We will say that this machine accepts a string if there is some path that reaches an accept state

from a start state

(11)

IBM JOURNAL APRIL 1959 Turing Award winning paper

(12)

0,1

0, ε 0

0,1

At each state, we can have any number of out arrows for some letter   Σ, including ε

NFA EXAMPLES

(13)

1

ε 0

1 0,1

0

Possibly many start states

NFA EXAMPLES

L(M) = {0

i

1

j

| i  {0,1}, j ≥ 0}

(14)

1

0

0

L(M)={1,00}

NFA EXAMPLES

(15)

Q is the set of states Σ is the alphabet

 : Q  Σε → 2Q is the transition function Q0  Q is the set of start states

F  Q is the set of accept states

A non-deterministic finite automaton (NFA) is a 5-tuple N = (Q, Σ, , Q0, F)

2Q is the set of all possible subsets of Q Σε = Σ  {ε}

(16)

Let w Σ* and suppose w can be written as w1... wn where wi  Σε = empty string)

Then N accepts w if there are r0, r1, ..., rn  Q

such that

r0  Q0

ri+1  (ri, wi+1 ) for i = 0, ..., n-1, and

rn  F

A language L is recognized by an NFA N if L = L(N).

L(N) = the language recognized by N

= set of all strings machine N accepts

(17)

1

0

0

(q3,1) = q1

q2

q3

q4

N = (Q, Σ, , Q0, F) Q = {q1, q2, q3, q4}

Σ = {0,1}

Q0 = {q1, q2} F = {q4}  Q

(q2,1) = {q4}

ε

(q1,0) = { q3} 00  L(N)?

01  L(N)?

(18)

Deterministic Computation

Non-Deterministic Computation

accept or reject accept

reject

(19)

MULTIPLE START STATES

We allow multiple start states for NFAs,

Can easily convert NFA with many start states into one with a single start state:

ε ε ε

(20)

UNION THEOREM FOR NFAs?

0 0

1 1

0

(21)

NFAs ARE SIMPLER THAN DFAs

An NFA that recognizes the language {1}:

1

1 0,1

0 0,1 A DFA that recognizes the language {1}:

(22)

Theorem: Every NFA has an equivalent* DFA

Corollary: A language is regular iff it is recognized by an NFA

Corollary: L is regular iff LR is regular

* N is equivalent to M if L(N) = L (M)

BUT DFAs CAN SIMULATE NFAs!

(23)

FROM NFA TO DFA

Input: N = (Q, Σ, , Q0, F)

Output: M = (Q, Σ, , q0, F)

accept

reject

To learn if NFA accepts, we could do the computation in parallel, maintaining the

set of all possible states that can be reached

Q = 2

Idea: Q

Q = 2Q

(24)

Q = 2Q

 : Q  Σ →

Q(R,) =

ε( (r,) )

rR

q0 = ε(Q0)

F = { R  Q | f  R for some f  F }

FROM NFA TO DFA

Input: NFA N = (Q, Σ, , Q0, F)

Output: DFA M = (Q, Σ, , q0, F)

*

For R  Q, the ε-closure of R, ε(R) = {q that can be reached from some r R by traveling along zero or more ε arrows}

*

(25)

0,1

0,ε 0,ε

0,1

EXAMPLE OF ε-CLOSURE

q0 q1 q2

ε({q0}) = {q0 , q1, q2} ε({q1}) = {q1, q2}

ε({q2}) = {q2}

(26)

a

a , b

a

2 3

1 b

ε

Given: NFA N = ( {1,2,3}, {a,b},  , {1}, {1} ) Construct: Equivalent DFA M

ε({1}) = {1,3}

N

M = (2{1,2,3}, {a,b}, , {1,3}, …) {1,3}

a

b

{2} a {2,3}

b

{3}

a

{1,2,3}

b a b

a

a,b

{1}, {1,2} ?

b

(27)

NFAs CAN MAKE PROOFS MUCH

EASIER!

Remember this on your Homework!

(28)

REGULAR LANGUAGES ARE CLOSED UNDER THE REGULAR OPERATIONS

Union: A  B = { w | w  A or w  B }

Intersection: A  B = { w | w  A and w  B } Negation: A = { w  Σ* | w  A }

Reverse: AR = { w1 …wk | wk …w1  A }

Concatenation: A  B = { vw | v  A and w  B } Star: A* = { w1 …wk | k ≥ 0 and each wi  A }

(29)

SOME LANGUAGES ARE NOT REGULAR

B = {0

n

1

n

| n ≥ 0} is NOT regular!

(30)

WHICH OF THESE ARE REGULAR

C = { w | w has equal number of 1s and 0s}

D = { w | w has equal number of

occurrences of 01 and 10 } NOT REGULAR

REGULAR!!!

(31)

THE PUMPING LEMMA

Let L be a regular language with |L| =

Then there is a positive integer P s.t.

1. |y| > 0 (y isn’t ε) 2. |xy| ≤ P

3. For every i ≥ 0, xyiz  L if w  L and |w| ≥ P

then can write w = xyz, where:

Why is it called the pumping lemma? The word w gets PUMPED into something longer…

(32)

z Let P be the number of states in M

Assume w  L is such that |w| ≥ P

q0 qj qk q|w|

There must be j and k such that j < k ≤ P, and qj = qk

Proof: Let M be a DFA that recognizes L

1. |y| > 0 2. |xy| ≤ P

3. xyiz  L for all i ≥ 0 We show: w = xyz

x

y

(33)

USING THE PUMPING LEMMA

Let’s prove that

B = {0n1n | n ≥ 0} is not regular

Assume B is regular. Let w = 0P1P

If B is regular, can write w = xyz, |y| > 0,

|xy| ≤ P, and for any i ≥ 0, xyiz is also in B If y is all 0s: xyyz has more 0s than 1s

If y is all 1s: THIS CASE CAN’T HAPPEN!

If y has both 1s and 0s:

THIS CASE CAN’T HAPPEN!

|xy| ≤ P

Contradiction!

(34)

USING THE PUMPING LEMMA

Assume C is regular. Let w = 0P1P (w is in C!) If C is regular, can write w = xyz, |y| > 0,

|xy| ≤ P, where for any i ≥ 0, xyiz is also in C If y is all 0s: xyyz has more 0s than 1s If y is all 1s: CAN’T HAPPEN

If y has both 1s and 0s:

CAN’T HAPPEN C = { w | w has equal

number of 1s and 0s}

is not regular

(35)

FLAC

Read Chapters 1.3 and 2.1 of the book for next time

Referenzen

ÄHNLICHE DOKUMENTE

Es gibt somit eine Schleife, die beliebig oft durchlaufen werden kann; das Wort kann in dem Schleifenbereich aufgepumpt werden.. Wiebke Petersen Einführung

Das Pumping-Lemma f¨ ur regul¨ are Sprachen besagt, dass es f¨ ur jede unendliche regul¨ are Sprache eine Grenze n gibt, so daß es zu jedem Wort w der Sprache, das mindestens die

1 das pumpbare Teilwort kann nicht nur aus a's bestehen, sonst würden beim Pumpen auf einer Seite des b's zuviele a's entstehen (aa ( aa ) 2 baaaa = aaaaaabaaaa). 2 das

Auÿerdem können Grammatiken auch für die Analyse (Erkennung) formaler Sprachen und endliche Automaten für ihre Erzeugung genutzt werden... Formale Sprachen Reguläre Ausdrücke

Wenn man die Form der Regeln einschr¨ ankt erh¨ alt man Teilmen- gen der Menge aller durch eine Grammatik erzeugten Sprachen.. Wiebke Petersen – Formale Komplexit¨ at nat¨

mer d'chind em Hans es huus lönd hälfe aastriiche wir die Kinder-AKK Hans-DAT das Haus-AKK ließen helfen anstreichen. NP 1 NP 2 NP 3 VP 1 VP 2 VP 3

Picture courtesy of imagerymajestic / FreeDigitalPhotos.net Gabriele R¨ oger (University of Basel) Theory of Computer Science March 24, 2021 4 / 15...

Oct 14 agree with supervisor on project topic Oct 21 due date: initial version of report Oct 28 due date: peer review. Nov 5 meeting: seminar presentations Nov 11 due date: