CS3102 Theory of Computation 0,1 Some 0s 0 0 start Warm up: 1 1 No 0s This automaton computes infinite AND: π΅ππΈ = π¦ β 0,1 β π¦ has no 0s} Show how to compute infinite NAND: ππ΅ππΈ = {π¦ β 0,1 β |π¦ has a 0}
Infinite NAND Automaton β’ Observation: π΅ππΈ π = ππ΅ππΈ β’ NAND should do the opposite 0,1 Some 0s 0 of NAND 0 start β’ Switch final states and non- final states! 1 1 No 0s 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 3
Logistics β’ Exercise 4 (partially) released β First part is on creating finite automata β The rest released today, due Friday (March 6) β’ Quiz will be released Thursday, due Tuesday 4
Last Time β’ Languages and decision problems β A different way of thinking about functions β’ Introducing Finite State Automata β DFA: Deterministic finite state automaton β Language of a FSA: The set of strings for which that automaton returns 1 5
FSA are strictly more powerful than NAND circuits β’ How can we show this? β Show that there is at least one function we can do with FSA but not NAND-CIRC β’ Done! (infinite XOR) β Show anything we can do with NAND-CIRC can also be done with FSA β’ How? β’ We need to be able to compute any finite function 6
Computing any finite function with NAND-CIRC β’ Summary: β "Manually Precompute" the output for every (finitely- many) possible input β When we receive the actual input, do a "lookup" β’ Our proof before: β Make a variable to represent each possible input, assigning its value to match the correct output β Use LOOKUP to return the proper variable for the given input 7
Straightline Code for f Input Output 000 0 001 0 010 1 011 0 100 1 101 1 110 0 111 0 8
Computing finite functions with FSA β’ Summary: β "Manually Precompute" the output for every (finitely-many) possible input β When we receive the actual input, do a "lookup" β’ Same idea, but with Automata: β Make a state for every possible input, determining whether or not it is final depending on the correct output β Do a "binary tree traversal" with the given input to navigate to its correct output 9
Input Output FSA for π 000 0 001 0 ββ 010 1 1 011 0 0 100 1 0 1 101 1 1 0 1 0 110 0 00 01 10 10 111 0 0 0 1 1 0 0 000 001 010 011 100 101 110 111 0,1 0,1 trash 10 0,1
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 : π , ππ , ππ , πππ , πππ , πππ , πππ , β¦ 11
βPiecesβ of a Regex β’ Empty String: β Matches just the string of length 0 Note: The compents here are the β Notation: π or ββ minimal necessary. In practice, regexes β’ Literal Character have other components as well, those are just βsyntactic sugarβ. β 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 12
13
Regex for UVA computing IDs β’ A UVA computing id is formatted as: β 2-3 letters β A digit β 1-3 letters 14
AND as a Regex β’ π΅ππΈ = π¦ β 0,1 β π¦ has no 0s} 15
NAND as a Regex β’ ππ΅ππΈ = {π¦ β 0,1 β |π¦ has a 0} 16
XOR as a Regex β’ πππ = {π¦ β 0,1 β |π¦ has an odd number of 1s} 17
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? 18
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) 19
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 20
β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 21
FSA for the empty string 22
FSA for a literal character 23
FSA for Alternation/Union ⒠Tricky⦠⒠What does it need to do? 24
Recommend
More recommend