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

β–Ά
cs3102 theory of computation
SMART_READER_LITE
LIVE PREVIEW

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: =


slide-1
SLIDE 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 π‘Œπ‘ƒπ‘†)

slide-2
SLIDE 2

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

2 start

No 0s

0,1 1

Some 0s

1

slide-3
SLIDE 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

slide-4
SLIDE 4

Last Time

  • Regular Expressions

– Equivalent to FSAs (but we haven’t shown that yet)

4

slide-5
SLIDE 5

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 : 𝑑, 𝑏𝑑, 𝑐𝑑, 𝑏𝑏𝑑, 𝑏𝑐𝑑, 𝑐𝑏𝑑, 𝑐𝑐𝑑, …

5

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-6
SLIDE 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

slide-7
SLIDE 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

slide-8
SLIDE 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

slide-9
SLIDE 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

slide-10
SLIDE 10

FSA for the empty string

10

slide-11
SLIDE 11

FSA for a literal character

11

slide-12
SLIDE 12

FSA for Alternation/Union

  • Tricky…
  • What does it need to do?

12

slide-13
SLIDE 13

Recall: 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

13 start

No 0s

0,1 1

Some 0s

1

slide-14
SLIDE 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

slide-15
SLIDE 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

slide-16
SLIDE 16

Example

  • 𝐡𝑂𝐸 βˆͺ π‘Œπ‘ƒπ‘†

– What is the resulting language?

16 start

0,1 1

Some 0s No 0s

1 𝑁

𝐡𝑂𝐸

Even 1 1

Odd

π‘π‘Œπ‘ƒπ‘†

slide-17
SLIDE 17

Cross-Product Construction

  • 2 machines at once!

17 start

0,1 1

Some 0s

No 0s

1 𝑁

𝐡𝑂𝐸

Even

1 1

Odd

π‘π‘Œπ‘ƒπ‘†

Start Even Some0s Even No0s Even Start Odd Some0s Odd No0s Odd

slide-18
SLIDE 18

Cross-Product Construction

  • 2 machines at once!

18 start

0,1 1

Some 0s

No 0s

1 𝑁

𝐡𝑂𝐸

Even

1 1

Odd

π‘π‘Œπ‘ƒπ‘†

Start Even Some0s Even No0s Even Some0s Odd No0s Odd

1 1 1 1 1

Start Odd

slide-19
SLIDE 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

slide-20
SLIDE 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

slide-21
SLIDE 21

Nondeterminism

21

?

Why not both?

Driving to a friend’s house Friend forgets to mention a fork in the directions Which way do you go?

slide-22
SLIDE 22

Example Non-deterministic Finite Automaton

  • π‘ˆβ„Žπ‘—π‘ π‘’π‘€π‘π‘‘π‘’1 = {

| π‘₯ ∈ 0,1 βˆ— the third from last character is a 1}

22

π‘π‘œπ‘“ 0,1 start π‘œπ‘“π‘¦π‘’1 π‘œπ‘“π‘¦π‘’2 0,1 0,1 1

slide-23
SLIDE 23

23

slide-24
SLIDE 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

slide-25
SLIDE 25

Union Using Non-Determinism

25 start

0,1 1

Some 0s No 0s

1 Even 1 1

Odd

New start

slide-26
SLIDE 26

Union Using Non-Determinism

26 start

0,1 1

Some 0s No 0s

1 Even 1 1

Odd

new 𝜁 𝜁 𝑁βˆͺ = 𝑅1 βˆͺ 𝑅2 βˆͺ π‘œπ‘“π‘₯ , Ξ£, πœ€βˆͺ, π‘œπ‘“π‘₯, 𝐺

1 βˆͺ 𝐺 2

πœ€βˆͺ(π‘Ÿ, 𝜏) = α‰Š πœ€1 π‘Ÿ, 𝜏 if π‘Ÿ ∈ 𝑅1 {πœ€2 π‘Ÿ, 𝜏 } if π‘Ÿ ∈ 𝑅2 πœ€βˆͺ π‘œπ‘“π‘₯, 𝜁 = {𝑑𝑒𝑏𝑠𝑒, π‘“π‘€π‘“π‘œ}

slide-27
SLIDE 27

What’s the language?

27

start

final

0, 𝜁

slide-28
SLIDE 28

NFA Example

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

28