cs3102 theory of computation
play

CS3102 Theory of Computation Warm up: = { 0,1 | has an odd - PowerPoint PPT Presentation

CS3102 Theory of Computation Warm up: = { 0,1 | has an odd number of 1s} Write a regex for (i.e. , i.e. the complement of ) AND to NAND AND: =


  1. CS3102 Theory of Computation Warm up: π‘Œπ‘ƒπ‘† = {𝑦 ∈ 0,1 βˆ— |𝑦 has an odd number of 1s} Write a regex for π‘Œπ‘ƒπ‘† 𝑑 (i.e. π‘Œπ‘ƒπ‘† , i.e. the complement of π‘Œπ‘ƒπ‘† )

  2. AND to NAND β€’ AND: – 𝑅 = 𝑑𝑒𝑏𝑠𝑒, 𝑂𝑝0𝑑, 𝑇𝑝𝑛𝑓0𝑑 0,1 – π‘Ÿ 0 = 𝑑𝑒𝑏𝑠𝑒 Some 0s 0 – 𝐺 = {𝑑𝑒𝑏𝑠𝑒, 𝑂𝑝0𝑑} – πœ€ defined as the arrows 0 start β€’ NAND: – 𝑅, π‘Ÿ 0 , πœ€ don’t change – 𝐺 = 𝑅 βˆ’ 𝐺 1 1 β€’ In general, If we can compute a language 𝑀 No 0s with a FSA, we can compute 𝑀 𝑑 as well 2

  3. Logistics β€’ Homework due Tonight and Friday β€’ You’ll have an assignment due the Friday you return from the break (no early deadline) β€’ Quiz due Tuesday 3

  4. Last Time β€’ Regular Expressions – Equivalent to FSAs (but we haven’t shown that yet) 4

  5. Regular Expressions Name Decision Problem Function Language 𝑐 ∈ Ξ£ βˆ— 𝑐 matches the pattern} Regex Does this string 𝑔 𝑐 = α‰Š 0 the string matches the string doesn β€² t match this 1 pattern? β€’ A way of describing a language β€’ Give a β€œpattern” of the strings, every string matching that pattern is in the language β€’ Examples: – (𝑏|𝑐)𝑑 matches : 𝑏𝑑 and 𝑐𝑑 – 𝑏|𝑐 βˆ— 𝑑 matches : 𝑑 , 𝑏𝑑 , 𝑐𝑑 , 𝑏𝑏𝑑 , 𝑏𝑐𝑑 , 𝑐𝑏𝑑 , 𝑐𝑐𝑑 , … 5

  6. FSA = Regex β€’ Finite state Automata and Regular Expressions are equivalent models of computing β€’ Any language I can represent as a FSA I can also represent as a Regex (and vice versa) β€’ How would I show this? 6

  7. Showing FSA ≀ Regex β€’ Show how to convert any FSA into a Regex for the same language β€’ We’re going to skip this: – It’s tedious, and people virtually never go this direction in practice, but you can do it (see textbook theorem 9.12) 7

  8. 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 8

  9. β€œ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 9

  10. FSA for the empty string 10

  11. FSA for a literal character 11

  12. FSA for Alternation/Union β€’ Tricky… β€’ What does it need to do? 12

  13. Recall: AND to NAND β€’ AND: – 𝑅 = 𝑑𝑒𝑏𝑠𝑒, 𝑂𝑝0𝑑, 𝑇𝑝𝑛𝑓0𝑑 0,1 – π‘Ÿ 0 = 𝑑𝑒𝑏𝑠𝑒 Some 0s 0 – 𝐺 = {𝑑𝑒𝑏𝑠𝑒, 𝑂𝑝0𝑑} – πœ€ defined as the arrows 0 start β€’ NAND: – 𝑅, π‘Ÿ 0 , πœ€ don’t change – 𝐺 = 𝑅 βˆ’ 𝐺 1 1 β€’ In general, If we can compute a language 𝑀 No 0s with a FSA, we can compute 𝑀 𝑑 as well 13

  14. Computing Complement β€’ If FSA 𝑁 = (𝑅, Ξ£, πœ€, π‘Ÿ 0 , 𝐺) computes 𝑀 β€’ Then FSA 𝑁 β€² = (𝑅, Ξ£, πœ€, π‘Ÿ 0 , 𝑅 βˆ’ 𝐺) computes ΰ΄€ 𝑀 β€’ Why? – Consider string π‘₯ ∈ Ξ£ βˆ— – π‘₯ ∈ 𝑀 means it ends at some state 𝑔 ∈ 𝐺 , which will be non-final in 𝑁 β€² and therefore it will return False – π‘₯ βˆ‰ 𝑀 means it ends at some state π‘Ÿ βˆ‰ 𝐺 , which will be final in 𝑁 β€² and therefore it will return True 14

  15. Computing Union β€’ Let FSA 𝑁 1 = (𝑅 1 , Ξ£, πœ€ 1 , π‘Ÿ 01 , 𝐺 1 ) compute 𝑀 1 β€’ Let 𝑁 2 = (𝑅 2 , Ξ£, πœ€ 2 , π‘Ÿ 02 , 𝐺 2 ) compute 𝑀 1 β€’ Will there always be some automaton 𝑁 βˆͺ to compute 𝑀 1 βˆͺ 𝑀 2 β€’ What must 𝑁 βˆͺ do? – Somehow end up in a final state if either 𝑁 1 or 𝑁 2 did – Idea: build 𝑁 βˆͺ to β€œsimulate” both 𝑁 1 and 𝑁 2 15

  16. Example β€’ 𝐡𝑂𝐸 βˆͺ π‘Œπ‘ƒπ‘† – What is the resulting language? 𝑁 𝐡𝑂𝐸 0,1 Some 0s 0 𝑁 π‘Œπ‘ƒπ‘† 1 0 0 start Even 0 Odd 1 1 No 0s 1 16

  17. Cross-Product Construction β€’ 2 machines at once! Start Start Odd Even 𝑁 𝐡𝑂𝐸 0,1 Some 0s 0 start 0 Some0s Some0s Odd Even 1 No 0s 1 𝑁 π‘Œπ‘ƒπ‘† 1 No0s No0s 0 Even Odd Odd Even 0 17 1

  18. Cross-Product Construction β€’ 2 machines at once! Start Start Odd Even 𝑁 1 𝐡𝑂𝐸 0,1 Some 0s 0 0 1 start 0 0 0 Some0s Some0s Odd Even 1 1 No 0s 1 0 0 𝑁 π‘Œπ‘ƒπ‘† 1 1 No0s No0s 0 Even Odd Odd Even 1 0 18 1

  19. Cross Product Construction β€’ Let FSA 𝑁 1 = (𝑅 1 , Ξ£, πœ€ 1 , π‘Ÿ 01 , 𝐺 1 ) compute 𝑀 1 β€’ Let 𝑁 2 = (𝑅 2 , Ξ£, πœ€ 2 , π‘Ÿ 02 , 𝐺 2 ) compute 𝑀 1 β€’ 𝑁 βˆͺ = (𝑅 1 Γ— 𝑅 2 , Ξ£, πœ€ βˆͺ , (π‘Ÿ 01 , π‘Ÿ 02 ), 𝐺 βˆͺ ) computes 𝑀 1 βˆͺ 𝑀 2 – πœ€ βˆͺ π‘Ÿ 1 , π‘Ÿ 2 , 𝜏 = πœ€ 1 π‘Ÿ 1 , 𝜏 , πœ€ 2 π‘Ÿ 2 , 𝜏 – 𝐺 βˆͺ = π‘Ÿ 1 , π‘Ÿ 2 ∈ 𝑅 1 Γ— 𝑅 2 π‘Ÿ 1 ∈ 𝐺 1 or π‘Ÿ 2 ∈ 𝐺 2 } β€’ How could we do intersection? 19

  20. 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 20

  21. Nondeterminism Driving to a friend’s house Friend forgets to mention a fork in the directions Which way do you go? Why not both? ? 21

  22. Example Non-deterministic Finite Automaton β€’ π‘ˆβ„Žπ‘—π‘ π‘’π‘€π‘π‘‘π‘’1 = { π‘₯ ∈ 0,1 βˆ— the third from last character is a 1} | 0,1 π‘œπ‘“π‘¦π‘’2 start π‘π‘œπ‘“ π‘œπ‘“π‘¦π‘’1 1 0,1 0,1 22

  23. 23

  24. 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 24

  25. Union Using Non-Determinism 0,1 Some 0s 0 New start 0 start 1 1 No 0s 1 0 Even 0 Odd 25 1

  26. Union Using Non-Determinism 0,1 Some 0s 0 𝜁 new 0 start 𝜁 1 1 No 0s 1 0 𝑁 βˆͺ = 𝑅 1 βˆͺ 𝑅 2 βˆͺ π‘œπ‘“π‘₯ , Ξ£, πœ€ βˆͺ , π‘œπ‘“π‘₯, 𝐺 1 βˆͺ 𝐺 2 Even 0 Odd πœ€ βˆͺ (π‘Ÿ, 𝜏) = α‰Š πœ€ 1 π‘Ÿ, 𝜏 if π‘Ÿ ∈ 𝑅 1 {πœ€ 2 π‘Ÿ, 𝜏 } if π‘Ÿ ∈ 𝑅 2 26 πœ€ βˆͺ π‘œπ‘“π‘₯, 𝜁 = {𝑑𝑒𝑏𝑠𝑒, π‘“π‘€π‘“π‘œ} 1

  27. What’s the language? 0, 𝜁 final start 27

  28. NFA Example {π‘₯ ∈ 0,1 βˆ— |π‘₯ contains 0101} 28

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend