Finite Automt Prt Three
Hello Hello Wonderful Wonderful Condensed Condensed Slide Slide Reders! Reders! The The first first hlf hlf of of this this lecture lecture consists consists lmost lmost exclusively exclusively of of nimtions nimtions of of the the subset subset construction, construction, which which ren t ren t present present in in these these condensed condensed slides. slides. You You might might wnt wnt to to red red over over the the full full version version of of these these slides slides to to get get better better sense sense for for how how tht tht construction construction works. works. Hope Hope this this helps! helps! -Keith -Keith
Recp from Lst Time
Tbulr DFAs strt 1 q 0 0 1 0 q 1 q 2 q 3 0 q 3 1 Σ 0 1 *q 0 q 1 q 0 These These strs strs indicte indicte ccepting ccepting sttes. sttes. q 1 q 2 *q 3 q 3 q 3 q 3 q 3 q2 q 0
Tbulr DFAs strt 1 q 0 0 1 0 q 1 q 2 q 3 0 q 3 1 Σ 0 1 *q 0 q 1 q 0 Since Since this this is is the the first first row, row, it's it's the the strt strt stte. stte. q 1 q 2 *q 3 q 3 q 3 q 3 q 3 q2 q 0
A lnguge L is clled regulr lnguge if there exists DFA D such tht L( D) = L.
NFAs An NFA is Nondeterministic Finite Automton Cn hve missing trnsitions or multiple trnsitions defined on the sme input symbol. Accepts if ny possible series of choices leds to n ccepting stte.
ε-trnsitions NFAs hve specil type of trnsition clled the ε-trnsition. An NFA my follow ny number of ε-trnsitions t ny time without consuming ny input. strt q 0 q 1 q 2 ε q 03 ε b, ε q 4 b q 5 b b b b
Perfect Guessing We cn view nondeterministic mchines s hving Mgic Superpowers tht enble them to guess the correct choice of moves to mke. If there is t lest one choice tht leds to n ccepting stte, the mchine will guess it. If there re no choices, the mchine guesses ny one of the wrong guesses. No known physicl nlog for this style of computtion this is totlly new!
Mssive Prllelism An NFA cn be thought of s DFA tht cn be in mny sttes t once. At ech point in time, when the NFA needs to follow trnsition, it tries ll the options t the sme time. The NFA ccepts if ny of the sttes tht re ctive t the end re ccepting sttes. It rejects otherwise.
Just how powerful re NFAs?
New Stuff!
NFAs nd DFAs Any lnguge tht cn be ccepted by DFA cn be ccepted by n NFA. Why? Every DFA essentilly lredy is n NFA! Question: Cn ny lnguge ccepted by n NFA lso be ccepted by DFA? Surprisingly, the nswer is yes!
Thought Experiment: How would you simulte n NFA in softwre?
Σ strt b q₀ q₁ q₂ q₃ strt {q₀} {q₀, q₁} b {q₀} {q₀, q₁} {q₀, q₁} {q₀, q₂} {q₀, q₂} {q₀, q₁, q₃} {q₀} *{q₀, q₁, q₃} {q₀, q₁} {q₀, q₂} b {q₀} {q₀, q₁} b b {q₀, q₂} b {q₀, q₁, q₃}
Once More, With Epsilons! strt Σ q₀ ε q₃ q₂ Σ b b q₁ q₄ b *{q₀, q₃} {q₁, q₄} {q₄} *{q₁, q₄} Ø {q₂, q₃} {q₄} Ø {q₃} *{q₂, q₃} {q₀, q₃, q₄} {q₀, q₃, q₄} *{q₃} {q₄} {q₄} *{q₀, q₃, q₄} {q₁, q₄} {q₃, q₄} *{q₃, q₄} {q₄} {q₃, q₄} Ø Ø Ø
The Subset Construction This construction for trnsforming n NFA into DFA is clled the subset construction (or sometimes the powerset construction). Ech stte in the DFA is ssocited with set of sttes in the NFA. The strt stte in the DFA corresponds to the strt stte of the NFA, plus ll sttes rechble vi ε-trnsitions. If stte q in the DFA corresponds to set of sttes S in the NFA, then the trnsition from stte q on chrcter is found s follows: Let S' be the set of sttes in the NFA tht cn be reched by following trnsition lbeled from ny of the sttes in S. (This set my be empty.) Let S'' be the set of sttes in the NFA rechble from some stte in S' by following zero or more epsilon trnsitions. The stte q in the DFA trnsitions on to DFA stte corresponding to the set of sttes S''. Red Sipser for forml ccount.
The Subset Construction In converting n NFA to DFA, the DFA's sttes correspond to sets of NFA sttes. Useful fct: (S) = 2 S for ny finite set S. In the worst-cse, the construction cn result in DFA tht is exponentilly lrger thn the originl NFA. Interesting chllenge: Find lnguge for which this worst-cse behvior occurs (there re infinitely mny of them!)
A lnguge L is clled regulr lnguge if there exists DFA D such tht L( D) = L.
An Importnt Result Theorem: A lnguge L is regulr iff there is some NFA N such tht L( N) = L. Proof Sketch: If L is regulr, there exists some DFA for it, which we cn esily convert into n NFA. If L is ccepted by some NFA, we cn use the subset construction to convert it into DFA tht ccepts the sme lnguge, so L is regulr.
Why This Mtters We now hve two perspectives on regulr lnguges: Regulr lnguges re lnguges ccepted by DFAs. Regulr lnguges re lnguges ccepted by NFAs. We cn now reson bout the regulr lnguges in two different wys.
Time-Out for Announcements!
Problem Set Five PS5 is due this Fridy t the strt of clss. Need help? Stop by office hours! Ask question on Pizz! We ve relesed new Inductive Proofwriting Checklist contining some common mistkes on PS5. Tke minute or two to red through it before submitting.
Extr Prctice Problems We ve relesed four more sets of extr prctice problems (EPP4 EPP7) in cse you d like to get some extr prctice with the topics from PS3 PS5. We ll relese solutions next week.
SLAE Monthly Event SLAE (Stnford LtinA Engineers) is holding their Very First Monthly Event this Fridy from 8PM 10PM in the Centro Lounge. They re providing sncks nd Netflix.
Your Questions
Wht do you think is the idel role of technology in eduction? I I hve hve to to prefce prefce this this by by sying sying I m I m not not n n expert, expert, becuse becuse I m I m definitely definitely not. not. From From experience, experience, technology technology works works well well in in eduction eduction when when it it (1) (1) cts cts s s force force multiplier multiplier or or (2) (2) mkes mkes the the bstrct bstrct tngible. tngible. We ll We ll be be relesing relesing tools tools for for designing designing nd nd testing testing DFAs, DFAs, which which is is (1) (1) on on the the bckend bckend nd nd (2) (2) on on the the frontend. frontend. Chris Chris Piech Piech is is doing doing some some truly truly groundbreking groundbreking work work on on option option (1). (1). Khn Khn Acdemy Acdemy is is both both (1) (1) nd nd (2), (2), nd nd MooCs MooCs re re (very (very wek) wek) (1). (1). You You should should be be skepticl skepticl when when someone someone sys sys tht tht they they hve hve new new technology technology tht tht will will revolutionize revolutionize eduction. eduction. All All technology technology does does is is chnge chnge the the cost cost of of things. things. It s It s not not going going to to fix fix highly highly troubled troubled nd nd complicted complicted system system overnight. overnight.
Keith. According to the midterm, I m terrible t CS 103 but I love thinking bout computers, mchines nd this clss. How do I reconcile the love nd the grde A A single single low low exm exm score score does does not not men men tht tht you you re re terrible terrible t t this. this. It s It s single single dt dt point point sying sying how how you you did did t t specific specific point point in in time. time. Tret Tret it it s s signl signl tlking tlking bout bout where where to to focus focus your your efforts efforts nd nd improve. improve. If If you you like like thinking thinking bout bout this this stuff, stuff, tht s tht s gret! gret! Keep Keep doing doing so. so. Use Use your your curiosity curiosity to to drive drive your your explortion explortion of of these these topics. topics. Hng Hng in in there. there. You You cn cn do do this! this!
Bck to CS103!
Properties of Regulr Lnguges
The Union of Two Lnguges If L1 nd L 2 re lnguges over the lphbet Σ, the lnguge L 1 L 2 is the lnguge of ll strings in t lest one of the two lnguges. If L1 nd L 2 re regulr lnguges, is L 1 L 2?
The Union of Two Lnguges If L1 nd L 2 re lnguges over the lphbet Σ, the lnguge L 1 L 2 is the lnguge of ll strings in t lest one of the two lnguges. If L1 nd L 2 re regulr lnguges, is L 1 L 2? strt Mchine for L 1 strt Mchine for L 2
The Union of Two Lnguges If L1 nd L 2 re lnguges over the lphbet Σ, the lnguge L 1 L 2 is the lnguge of ll strings in t lest one of the two lnguges. If L1 nd L 2 re regulr lnguges, is L 1 L 2? ε Mchine for L 1 strt Mchine for L 1 L 2 ε Mchine for L 2
The Intersection of Two Lnguges If L1 nd L 2 re lnguges over Σ, then L 1 L 2 is the lnguge of strings in both L 1 nd L 2. Question: If L1 nd L 2 re regulr, is L 1 L 2 regulr s well? L 1 L 2 Hey, Hey, it's it's De De Morgn's Morgn's lws! lws!
Conctention
String Conctention If w Σ* nd x Σ*, the conctention of w nd x, denoted wx, is the string formed by tcking ll the chrcters of x onto the end of w. Exmple: if w = quo nd x = kk, the conctention wx = quokk. Anlogous to the + opertor for strings in mny progrmming lnguges. Some fcts bout conctention: The empty string ε is the identity element for conctention: Conctention is ssocitive: wε = εw = w wxy = w(xy) = (wx)y
Conctention The conctention of two lnguges L₁ nd L₂ over the lphbet Σ is the lnguge L₁L₂ = { wx Σ* w L₁ x L₂ } =Two views of L₁L₂: The set of ll strings tht cn be mde by conctenting string in L₁ with string in L₂. The set of strings tht cn be split into two pieces: piece from L₁ nd piece from L₂. Conceptully similr to the Crtesin product of two sets, only with strings.
Conctention Exmple Let Σ = {, b,, z, A, B,, Z } nd consider these lnguges over Σ: Noun = { Puppy, Rinbow, Whle, } Verb = { Hugs, Juggles, Loves, } The = { The } The lnguge TheNounVerbTheNoun is { ThePuppyHugsTheWhle, TheWhleLovesTheRinbow, TheRinbowJugglesTheRinbow, }
Conctention The conctention of two lnguges L₁ nd L₂ over the lphbet Σ is the lnguge L₁L₂ = { wx Σ* w L₁ x L₂ } Two views of L₁L₂: The set of ll strings tht cn be mde by conctenting string in L₁ with string in L₂. The set of strings tht cn be split into two pieces: piece from L₁ nd piece from L₂. Conceptully similr to the Crtesin product of two sets, only with strings.
Conctenting Regulr Lnguges If L1 nd L 2 re regulr lnguges, is L 1 L 2? Intuition cn we split string w into two strings xy such tht x L 1 nd y L 2? Ide: Run the utomton for L1 on w, nd whenever L 1 reches n ccepting stte, strt strt optionlly hnd the rest off w to L 2. If L2 ccepts the reminder, then L 1 ccepted the first prt nd the string is in L 1 L 2. Mchine for L 1 Mchine for L 2 If L2 rejects the reminder, then the split ws incorrect. b o o k k e e p e r
Conctenting Regulr Lnguges If L1 nd L 2 re regulr lnguges, is L 1 L 2? Intuition cn we split string w into two strings xy such tht x L 1 nd y L 2? Ide: Run the utomton for L1 on w, nd whenever L 1 reches n ccepting stte, optionlly hnd the rest off w to L 2. If L2 ccepts the reminder, then L 1 ccepted the first prt nd the string is in L 1 L 2. If L2 rejects the reminder, then the split ws incorrect.
Conctenting Regulr Lnguges ε strt ε ε Mchine for L 1 Mchine for L 2 Mchine for L 1 L 2
Summry NFAs re powerful type of utomton tht llows for nondeterministic choices. NFAs cn lso hve ε-trnsitions tht move from stte to stte without consuming ny input. The subset construction shows tht NFAs re not more powerful thn DFAs, becuse ny NFA cn be converted into DFA tht ccepts the sme lnguge. The union, intersection, complement, nd conctention of regulr lnguges re ll regulr lnguges.