CS3102 Theory of Computation

CS3102 Theory of Computation

CS3102 Theory of Computation Warm up: What’s the language of this NFA? 0, 휀 start final 1 Logistics 2 Last Time • Non-determinism 3 Showing Regex ≤ FSA • Show how to convert any regex into a FSA for the same language • Idea: show how to build each “piece” of a regex using FSA 4 Proof “Storyboard” FSA = Regex Computability by How to build FSA closed under 휀, literal, union, a Regex concat, * Makes that easy Non- determinism 5 “Pieces” of a Regex • Empty String: – Matches just the string of length 0 – Notation: 휀 or “” • Literal Character – Matches a specific string of length 1 – Example: the regex 푎 will match just the string 푎 • Alternation/Union – Matches strings that match at least one of the two parts – Example: the regex 푎|푏 will match 푎 and 푏 • Concatenation – Matches strings that can be dividing into 2 parts to match the things concatenated – Example: the regex 푎 푏 푐 will match the strings 푎푐 and 푏푐 • Kleene Star – Matches strings that are 0 or more copies of the thing starred ∗ – Example: 푎 푏 푐 will match 푎, 푏, or either followed by any number of 푐’s 6 Non-determinism • Things could get easier if we “relax” our automata • So far: – Must have exactly one transition per character per state – Can only be in one state at a time • Non-deterministic Finite Automata: – Allowed to be in multiple (or zero) states! – Can have multiple or zero transitions for a character – Can take transitions without using a character – Models parallel computing 7 Nondeterminism Driving to a friend’s house Friend forgets to mention a fork in the directions Which way do you go? Why not both? ? 8 Example Non-deterministic Finite Automaton • 푆푒푐표푛푑퐿푎푠푡1 = ∗ 푤 ∈ 0,1 the second from last character is a 1} 0,1 1 0,1 start 표푛푒 푛푒푥푡 9 Non-Deterministic Finite State Automaton • Implementation: – Finite number of states – One start state – “Final” states – Transitions: (partial) function mapping state-character (or epsilon) pairs to sets of states • Execution: – Start in the initial “state” – Enter every state reachable without consuming input (휺-transitions) – Read each character once, in order (no looking back) – Transition to new states once per character (based on current states and character) – Enter every state reachable without consuming input (휺-transitions) – Return True if any state you end is final • Return False if every state you end in is non-final 10 NFA = DFA • DFA ≤ NFA: – Can we convert any DFA into an NFA? • NFA ≤ DFA: – Can we convert any NFA into a DFA? – Strategy: NFAs can be in any subset of states, make a DFA where each state represents a set of states 11 Powerset Construction 0,1 1 0,1 start one next start one next Start, {} One, next Start, Start, One, one next next 12 Powerset Construction 0,1 1 0,1 start one next 0 start one next 1 Start, {} One, 0 next 1 1 Start, Start, One, one next next 0 0 1 13 Powerset Construction (symbolic) • NFA 푀 = (푄, Σ, 훿, 푞0, 퐹) • As a DFA: 푄 – 푀퐷 = (2 , Σ, 훿퐷, 푞퐷, 퐹퐷) • 푞퐷 = 푞0 ∪ 훿(푞0, 휀) – start state and everything reachable using empty transitions 푄 • 퐹퐷 = 푠 ∈ 2 ∃푞 ∈ 푠 . 푞 ∈ 퐹} – All states with a start state in them • 훿퐷 푠, 휎 = 푞∈푠 훿 푠, 휎 – Transition to the stateset of everything any current state transitions to 14 Union Using Non-Determinism Some 0s 0,1 Goal: Return 1 if either machine 0 returns 1 new Strategy: Run both machines in start 0 parallel (non-deterministically) by transitioning to the start states 1 for both without using input No 0s 1 1 0 Even Odd 0 15 1 Union Using Non-Determinism 푀1 Some 0s 0,1 0 e 휀 e new 푀2 start 0 휀 푀∪ = 푄1 ∪ 푄2 ∪ 푛푒푤 , Σ, 훿∪, 푛푒푤, 퐹1 ∪ 퐹2 1 훿1 푞, 휎 if 푞 ∈ 푄1 No 0s 1 훿∪(푞, 휎) = {훿2 푞, 휎 } if 푞 ∈ 푄2 1 훿∪ 푛푒푤, 휀 = {푠푡푎푟푡, 푒푣푒푛} 0 Even Odd 0 16 1 Language Concatenation ∗ • 퐿1퐿2 = {푤 ∈ Σ |∃푥 ∈ 퐿1, ∃푦 ∈ 퐿2. 푥푦 = 푤} • The set of all strings I can create by concatenating a string from 퐿1 with a string from 퐿2 (in that order) • 휀, 0, 10 ⋅ 0,00 = {0, 00, 000, 100, 1000} 17 Concatenation using NFA 푀2 푀1 e e Goal: Return 1 if the input Some 0s 0,1 can be broken into 2 0 chunks, 푀1 returns 1 on the 1 first chunk, 푀2 on the 0 second start 0 Even Odd 0 Strategy: Every time we enter a final state in 푀1, 1 1 non-deterministically run No 0s 1 the rest of the string on 푀2. Return 1 if 푀2 does. 18 Concatenation using NFA 푀2 푀1 e e 푀푐 = 푄1 ∪ 푄2, Σ, 훿푐, 푞01, 퐹2 훿1 푞, 휎 if 푞 ∈ 푄1 − 퐹1 Some 0s 0,1 훿 (푞, 휎) = 훿 푞, 휎 , 푞 if 푞 ∈ 퐹 0 푐 1 0,2 1 1 {훿2 푞, 휎 } if 푞 ∈ 푄2 0 start 휀 Even Odd 0 0 1 휀 1 No 0s 1 19 Kleene Star • 퐿∗ = 퐿0 ∪ 퐿1 ∪ 퐿2 ∪ ⋯ • 퐿0 = {휀} • 퐿푘 = (퐿 concatenated 푘 times) • 00, 11 ∗ = {휀, 00, 11, 0011, 1100, 0000, 1111, 110011, … } 20 e Kleene Star using NFA 푀1 e e Goal: Return 1 if the input can Some 0s 0,1 be broken into chunks such that 0 푀1 returns 1 for every chunk Strategy: Every time we enter a start 0 final state in 푀1, non- deterministically “restart” the 1 machine to run on the rest of 1 No 0s the string, make sure we return 1 on 휀 21 e Kleene Star using NFA 푀1 e e Goal: Return 1 if the input can Some 0s 0,1 be broken into chunks such that 0 푀1 returns 1 for every chunk 휀 start 0 Strategy: Every time we enter a 휀 final state in 푀1, non- deterministically “restart” the 휀 1 machine to run on the rest of 1 No 0s the string, make sure we return empty 1 on 휀 22 Conclusion • Any language expressible as a regular expression is computable by a NFA • Any language computable by a NFA is computable by a DFA • NFA = Regex = DFA • Call any such language a “regular language” 23 Characterizing What’s computable • Things that are computable by FSA: – Functions that don’t need “memory” – Languages expressible as Regular Expressions • Things that aren’t computable by FSA: – Things that require more than finitely many states – Intuitive example: Majority 24 Majority with FSA? • Consider an inputs with lots of 0s 000...0000 111...1111 000...0000 111...1111 000...0000 111...1111 ×49,999 ×50,000 ×50,000 ×50,000 ×50,000 ×50,001 • Recall: we read 1 bit at a time, no going back! • To count to 50,000, we'll need 50,000 states! 25 .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    25 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us