CS3102 Theory of Computation 0,1 Some 0s 0 0 start Warm up: 1 - - PowerPoint PPT Presentation

β–Ά
cs3102 theory of computation
SMART_READER_LITE
LIVE PREVIEW

CS3102 Theory of Computation 0,1 Some 0s 0 0 start Warm up: 1 - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

CS3102 Theory of Computation

Warm up: This automaton computes infinite AND: 𝐡𝑂𝐸 = 𝑦 ∈ 0,1 βˆ— 𝑦 has no 0s} Show how to compute infinite NAND: 𝑂𝐡𝑂𝐸 = {𝑦 ∈ 0,1 βˆ—|𝑦 has a 0}

start

0,1 1

Some 0s No 0s

1

slide-2
SLIDE 2

Infinite NAND Automaton

  • Observation: 𝐡𝑂𝐸𝑑 = 𝑂𝐡𝑂𝐸
  • NAND should do the opposite
  • f NAND
  • Switch final states and non-

final states!

2 start

No 0s

0,1 1

Some 0s

1

slide-3
SLIDE 3

AND to NAND

  • AND:

– 𝑅 = 𝑑𝑒𝑏𝑠𝑒, 𝑂𝑝0𝑑, 𝑇𝑝𝑛𝑓0𝑑 – π‘Ÿ0 = 𝑑𝑒𝑏𝑠𝑒 – 𝐺 = {𝑑𝑒𝑏𝑠𝑒, 𝑂𝑝0𝑑} – πœ€ defined as the arrows

  • NAND:

– 𝑅, π‘Ÿ0, πœ€ don’t change – 𝐺 = 𝑅 βˆ’ 𝐺

  • In general, If we can compute a language 𝑀

with a FSA, we can compute 𝑀𝑑 as well

3 start

No 0s

0,1 1

Some 0s

1

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

Straightline Code for f

8

Input Output 000 001 010 1 011 100 1 101 1 110 111

slide-9
SLIDE 9

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

  • r 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

slide-10
SLIDE 10

FSA for 𝑔

10

Input Output 000 001 010 1 011 100 1 101 1 110 111 β€œβ€ 000 1 00 001 010 011 101 100 110 111 01 10 10 1 1 1 1 1 trash 0,1 0,1 0,1

slide-11
SLIDE 11

Regular Expressions

  • 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

Name Decision Problem Function Language Regex Does this string match this pattern? 𝑔 𝑐 = α‰Š0 the string matches 1 the string doesnβ€²t 𝑐 ∈ Ξ£βˆ— 𝑐 matches the pattern}

slide-12
SLIDE 12

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

12

Note: The compents here are the minimal necessary. In practice, regexes have other components as well, those are just β€œsyntactic sugar”.

slide-13
SLIDE 13

13

slide-14
SLIDE 14

Regex for UVA computing IDs

  • A UVA computing id is formatted as:

– 2-3 letters – A digit – 1-3 letters

14

slide-15
SLIDE 15

AND as a Regex

  • 𝐡𝑂𝐸 = 𝑦 ∈ 0,1 βˆ— 𝑦 has no 0s}

15

slide-16
SLIDE 16

NAND as a Regex

  • 𝑂𝐡𝑂𝐸 = {𝑦 ∈ 0,1 βˆ—|𝑦 has a 0}

16

slide-17
SLIDE 17

XOR as a Regex

  • π‘Œπ‘ƒπ‘† = {𝑦 ∈ 0,1 βˆ—|𝑦 has an odd number of 1s}

17

slide-18
SLIDE 18

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

slide-19
SLIDE 19

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

slide-20
SLIDE 20

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

slide-21
SLIDE 21

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

slide-22
SLIDE 22

FSA for the empty string

22

slide-23
SLIDE 23

FSA for a literal character

23

slide-24
SLIDE 24

FSA for Alternation/Union

  • Tricky…
  • What does it need to do?

24