22.04.2014 Views

Lecture 3

Lecture 3

Lecture 3

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CSC 341<br />

Automata etc<br />

Rhys Price Jones<br />

Week 3<br />

Friday, February 8, 13


Proving a Language is Regular<br />

Method 1<br />

Build a FA for it<br />

Example L = {w | w∊(0+1)*, binary number<br />

w is divisible by 5}<br />

Now convince<br />

me L = L(M)<br />

Friday, February 8, 13


Proving a Language is Regular<br />

Method 2<br />

Describe a FA for it<br />

Example L = {w | w∊(0..F)*, hex number w is<br />

divisible by 479}<br />

M has 480 states q1..q480<br />

qn corresponds to “The string so far is a binary number congruent to n mod 479”<br />

Except q480 corresponds to congruence to 0<br />

δ(qi,0) = qj iff j ≡ 16i mod 479<br />

Now convince<br />

δ(qi,1) = qj iff j ≡ 16i+1 mod 479...<br />

δ(qi,F) = me L = L(M)<br />

qj iff j ≡ 16i+15 mod 479<br />

Start state q0 has δ(q0,0) = q481, δ(q0,i) = qi<br />

Accept states q481 and q480<br />

Friday, February 8, 13


Proving a Language is Regular<br />

Method 3<br />

Give me a r.e. for it<br />

Example L = {w | w∊(0+1)*, w is a bunch of 0<br />

followed by a bunch of 1 followed by a bunch of 0}<br />

r = 0 * 1 * 0 *<br />

Now convince<br />

me L = L(r)<br />

Friday, February 8, 13


Proving a Language is Regular<br />

Method 4<br />

Describe a r.e. for it<br />

Example L is a finite language consisting of<br />

the strings w1,w2,..wn<br />

r = w1+w2+..wn<br />

Now convince<br />

me L = L(r)<br />

Friday, February 8, 13


Proving a Language is Regular<br />

Method 5<br />

Use closure properties<br />

Example L = {w∊(0+1)* | w is a binary<br />

number divisible by 5 consisting of a bunch of<br />

0s squeezed between two bunches of 1s}<br />

We know<br />

1) {binary numbers divisible by 5} is regular<br />

2) bunch of 0s squeezed between 1s is 1 * 0 * 1 *<br />

hence regular<br />

Cite closure under intersection and we’re done!<br />

Friday, February 8, 13


I like closure properties!!!<br />

How can we get more?<br />

Friday, February 8, 13


Proving new closure properties<br />

Method 1<br />

Use already derived closure properties<br />

Example: Closure under intersection<br />

We know<br />

1) Reg langs closed under ∪ and complement<br />

2) De Morgan’s laws<br />

If L1 and L2 are regular, so are<br />

C(L1) and C(L2) ..... closure under complement<br />

C(L1) ∪ C(L2) is regular ...... closure under ∪<br />

L1∩L2 = C(C(L1) ∪ C(L2)) ..... de Morgan<br />

and is regular by closure under complement<br />

Friday, February 8, 13


Proving new closure properties<br />

Method 2<br />

Adapt a machine<br />

Example: If L is regular so is L’ = {a1a3a5..a2n-1 | a1..a2n∊L}<br />

Let M be a DFA for L<br />

Define δ’(p,a) = {δ(p,ab) |<br />

b∊Σ}<br />

I extended δ:Q×Σ* → Q in the<br />

obvious way<br />

Make δ’ : 2 Q → 2 Q using union<br />

∀P⊆Q, δ’(P,a) = ∪p∊Pδ’(p,ab)<br />

F’ is subsets of Q containing<br />

a state of F<br />

M’ = (Q,Σ,δ’,{q0},F’) is an NFA for L’<br />

Proof ?<br />

Prove by induction on n that<br />

δ’(P,a1..an) = ∪q∊P{δ(q,a1b1a2b2..bn-1anbn) | bi∊Σ}<br />

Clearly if n=0, δ’(P,ε)={δ(q,ε) | q∊P}=P<br />

Assume ind.hyp. true ∀i


Short Diversion<br />

The regular languages are NOT closed under<br />

“subset”<br />

If L1 is regular and L2 ⊂ L1 it is not necessarily true<br />

that L2 is regular<br />

The regular languages are not closed under “infinite<br />

union”<br />

If L1,L2,...,Li,... are regular it is not necessarily the<br />

case that L1∪L2∪...∪Li∪... is regular<br />

Friday, February 8, 13


Sipser Problem 1.42<br />

A,B regular with DFAs MA,MB<br />

Show regular SHUFFLE(A,B) =<br />

{w=a1b1..akbk | a1..ak∊A, b1..bk∊B, each ai,bi ∊ Σ * }<br />

Q=QA×QB, q0=(qA0,qB0), F=FA×FB<br />

δ((qA,qB),a) = {(δA(qA,a),qB), (qA,δ(qB,a))}<br />

Friday, February 8, 13


Another example<br />

If L is regular, so is<br />

Cycle(L) = {a2a1a4a3..a2na2n-1 | a1a2a3a4..a2n-1a2n ∊ L}<br />

Let M be a DFA for L.<br />

M’ will be a DFA for Cycle(L) that uses a state to “remember” what symbol (a) it just<br />

read.<br />

Then, when it reads the next symbol b, M’ will simulate M on input ba. Formally<br />

Q’ = Q ∪ (Q×Σ)<br />

δ’(q,a) = (q,a)<br />

δ’((q,a),b) = δ(q,ba)<br />

Prove by induction on n that<br />

δ’(q,a2a1a4a3..a2na2n-1) = δ(q,a1a2a3a4..a2n-1a2n)<br />

Clearly true when n=0 since δ’(q,ε) = q = δ(q,ε)<br />

Assume true for n-1, so δ’(q,a2a1a4a3..a2n-2a2n-3) = δ(q,a1a2a3a4..a2n-3a2n-2) = p, say<br />

Then δ’(q,a2a1a4a3..a2na2n-1) = δ’(δ’(q,a2a1a4a3..a2n-2a2n-3), a2na2n-1)<br />

= δ(p, a2n-1a2n) = δ(δ(q,a1a2a3a4..a2n-3a2n-2), a2n-1a2n) = δ(q,a1a2a3a4..a2n-1a2n)<br />

We have proved that a2a1a4a3..a2na2n-1 is accepted by M’ if and only if<br />

a1a2a3a4..a2n-1a2n is accepted by M. So Cycle(L) = L(M’) is regular.<br />

Friday, February 8, 13


Similar examples<br />

Under which of these are reg langs closed?<br />

MAX(L) = {x∊L | xy ∊ L ⇒ y=ε}<br />

MIN(L) = {x∊L | (x=yz and y∊L) ⇒ z=ε}<br />

INIT(L) = {x∊L | ∃y and xy∊L}<br />

SQRT(L) = {x | for some y with |y|=|x| 2 xy∊L}<br />

Friday, February 8, 13


Similar examples<br />

MAX(L) = {x∊L | xy ∊ L ⇒ y=ε}<br />

What is MAX(1*0*1)?<br />

Friday, February 8, 13


Quotient of languages<br />

If L1 and L2 are languages then<br />

L1/L2 = {x | ∃y∊L2 such that xy∊L1}<br />

It’s true that if L1 and L2 are regular so is L1/L2<br />

But here’s a stronger result<br />

If L is a regular language and S is an arbitrary<br />

set then L/S is regular<br />

Friday, February 8, 13


Proof (not effective!)<br />

If L is a regular language and S is an arbitrary set then L/S is regular<br />

Let M = (Q,Σ,δ,q0,F) be a DFA for L<br />

There is a DFA M’= (Q,Σ,δ,q0,F’) that accepts L/S<br />

M’ behaves just like M, but F’ consists of just<br />

those states for which ∃y∊S such that δ(q,y)∊F<br />

I don’t (and cannot in general) know what F’ is<br />

but I know it exists!<br />

Friday, February 8, 13


Proving language no regular<br />

In general this is harder!<br />

We need a property that all regular languages<br />

possess<br />

And a way to show that a language does not<br />

possess that property<br />

The property: “pumpability”<br />

Friday, February 8, 13


Proof (before the theorem!)<br />

A DFA has a finite number (say N) of states<br />

If a string w of length n>N is accepted then<br />

some state (say p) is revisited<br />

Let x be the prefix of w eaten on the way from q0 to p(first visit)<br />

Let y be the middle part of w eaten on the way from p (first visit) to p<br />

(second visit)<br />

Let z be the rest of w<br />

So w = xyz with |xy|≦ N, |y|>0<br />

xy i z is accepted by the DFA ∀i≧0<br />

Friday, February 8, 13


Theorem (Pumping Lemma)<br />

If A is a regular language, then there is a<br />

number p (called the pumping length) such that<br />

whenever s is a string in A of length ≥ p, then s<br />

may be written s=xyz satisfying:<br />

for each i ≥ 0, xy i z ∊ A,<br />

|y| > 0, and<br />

|xy| ≤ p<br />

Friday, February 8, 13


Use to prove {0 n 1 n | n≥0} not reg<br />

EvilOne: Oh Yes it is regular!<br />

Me: OK, so give me p<br />

EvilOne (gives me a constant p)<br />

Me: You’ll agree s = 0 p 1 p ∊L with length ≥ p<br />

EvilOne: Of course<br />

Me: Now you split s = xyz according to the rules<br />

Friday, February 8, 13


The Battle Continues<br />

EvilOne must give me x=0 a , y=0 b ,z=0 p-(a+b) 1 p<br />

for some a≥0 and b≥1<br />

Me: You lose! Obviously xy 0 z = 0 a 0 p-(a+b) 1 p ∉ L<br />

since a+p-(a+b) = p ⇒ b=0<br />

and we know b>0<br />

EvilOne walks off with tail between legs<br />

Friday, February 8, 13


L = {ww R | w ∊ (0+1) * } is not reg<br />

Proof: We need to give EvilOne a string in that<br />

cannot be pumped without leaving the language.<br />

Pumping must occur within p of beginning<br />

So choose s carefully with a beginning portion:<br />

that is clearly identifiable<br />

clearly makes s be of the required form<br />

breaks the defining property when it’s pumped<br />

Friday, February 8, 13


Myhill-Nerode Theorem<br />

do by hand<br />

dealt with lightly in Sipser<br />

and then in JFLAP<br />

Exercise 1.51 and 1.52<br />

has as a consequence the<br />

basis of a minimization<br />

algorithm for DFAs<br />

Minimize this:<br />

toMinimize.jff<br />

Friday, February 8, 13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!