Gret Theoreticl Ides In Computer Science Steven Rudich CS 15-251 Spring 2005 Lecture 9 Fe 8 2005 Crnegie Mellon University One Minute To Lern Progrmming: Finite Automt
Let me tech you progrmming lnguge so simple tht you cn lern it in less thn minute.
Meet ABA The Automton! Input String ε Result Accept Reject Accept Accept
The Simplest Interesting Mchine: Finite Stte Mchine OR Finite Automton
Finite Automton Finite set of sttes o 1 2 A strt stte Q = { q, q, q,, q } q o k A set of ccepting sttes A finite lphet Stte trnsition instructions # qi x 1 q j { } i i i F = q, q,, q 1 2 r : Q ( q, ) = i Σ q j Q
How Mchine M opertes. M reds one letter t time from the input string (going from left to right) M strts in stte q 0. If M is in stte q i reds the letter then If δ(q i. ) is undefined then CRASH. Otherwise M moves to stte δ(q i,)
Let M=(Q,S,F,d) e finite utomton. M ccepts the string x if when M reds x it ends in n ccepting stte. M rejects the string x if when M reds x it ends in nonccepting stte. M crshes on x if M crshes while reding x.
The set (or lnguge) ccepted y M is: M { * } L = x M ccepts x k All length k strings over the lphet * 0 1 2 3... Notice tht this is {ε}
Wht is the lnguge ccepted y this mchine?, L = {,}* = ll finite strings of s nd s
Wht is the lnguge ccepted y this mchine?,, L = ll even length strings of s nd s
Wht mchine ccepts this lnguge? L = ll strings in {,}* tht contin t lest one,
Wht mchine ccepts this lnguge? L = strings with n odd numer of s nd ny numer of s
Wht is the lnguge ccepted y this mchine? L = ny string ending with
Wht is the lnguge ccepted y this mchine?, L = ny string with t lest two s
Wht mchine ccepts this lnguge? L = ny string with n nd,
Wht mchine ccepts this lnguge? L = strings with n even numer of pirs
L = ll strings contining s consecutive sustring, ε Invrint: I m stte s exctly when s is the longest suffix of the input (so fr) tht forms prefix of.
The grep Prolem Input: text T of length t string S of length n Nïve method: Prolem: Does the string S pper inside the text T? n symols,,,, 1 2 3 t Cost: O(nt) comprisons
Automt Solution Build mchine M tht ccepts ny string with S s consecutive sustring. Feed the text to M. Cost: t comprisons + time to uild M. As luck would hve it, the Knuth, Morris, Prtt lgorithm uilds M quickly. By the wy, it cn e done with fewer thn t comprisons in the worst cse!
Rel-life uses of finite stte mchines grep coke mchines thermostts (fridge) elevtors trin trck switches lexicl nlyzers for prsers
Any L Σ is defined to e lnguge. L is just set of strings. It is clled lnguge for historicl resons.
Let L Σ e lnguge. L is clled regulr lnguge if there is some finite utomton tht ccepts L. In this lecture we hve seen mny regulr lnguges. Σ even length strings strings contining
Theorem: Any finite lngge is regulr. Proof: Mke mchine with pth for ech string in the lnguge. Exmple: L = {, cd, c, } c c d
Are ll lnguges regulr?
Consider the lnguge n n = { ε,,,, } i.e., unch of s followed y n equl numer of s No finite utomton ccepts this lnguge. Cn you prove this?
n n is not regulr. No mchine hs enough sttes to keep trck of the numer of s it might encounter.
Tht is firly wek rgument. Consider the following exmple
L = strings where the # of occurrences of the pttern is equl to the numer of occurrences of the pttern Cn t e regulr. No mchine hs enough sttes to keep trck of the numer of occurrences of.
Rememer ABA? ABA ccepts only the strings with n equl numer of s nd s!
Let me show you professionl strength proof tht n n is not regulr.
Professionl Strength Proof Theorem: n n is not regulr. Proof: Assume tht it is. Then M with k sttes tht ccepts it. For ech 0 i k, let S i e the stte M is in fter reding i. i,j k s.t. S i = S j, ut i j M will do the sme thing on i i nd j i. But vlid M must reject j i nd ccept i i.
MORAL: Finite utomt cn t count.
Advertisement You cn lern much more out these cretures in the FLAC course. Forml Lnguges, Automt, nd Computtion There is unique smllest utomton for ny regulr lnguge It cn e found y fst lgorithm.
Cellulr Automt Line up unch of identicl finite utomt in stright line. qi q k q j Trnsitions re sed on the sttes of the mchine s two neighors or n indictor tht neighor is missing. (There is no other input.) Q Q Q Q ( q, q, q ) k i j l = q qk q, q i j ql All cells move to their Steven next Rudich: sttes t the sme time: synchronous trnsition
The Firing Squd Prolem Five soldiers ll strt in the stte. You chnge the one on the left to the wke stte. All five must get to the fire stte t the sme time (for the first time). wke fire wke fire wke fire wke fire wke fire wke fire wke fire wke fire wke fire wke fire
Shorthnd { d} Q,,, Mens use this trnsition when your left neighor is in ny stte t ll nd your right neighor is in stte,, or d.
{,fire,end},q {w},q {w2},q {w3},q {w4},q wke wke2 wke3 wke4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5
{,fire,end},q {w},q {w2},q {w3},q {w4},q wke wke2 wke3 wke4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 wke
{,fire,end},q {w},q {w2},q {w3},q {w4},q wke wke2 wke3 wke4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 wke wke2 wke2
{,fire,end},q {w},q {w2},q {w3},q {w4},q wke wke2 wke3 wke4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 wke wke2 wke2 wke3 wke3 wke3
{,fire,end},q {w},q {w2},q {w3},q {w4},q wke wke2 wke3 wke4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 wke wke2 wke2 wke3 wke3 wke3 wke4 wke4 wke4 wke4
{,fire,end},q {w},q {w2},q {w3},q {w4},q wke wke2 wke3 wke4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 wke wke2 wke2 wke3 wke3 wke3 wke4 wke4 wke4 wke4 fire fire fire fire fire
Question Cn you uild the soldier s finite utomton rin efore you know how mny soldiers will e in the line? No. Finite utomt cn t count!
Don t jump to conclusions! It is possile to design single cellulr utomton tht works for ny numer of soldiers!