CS3102 Theory of Computation Warm up: Whats the language of this - - PowerPoint PPT Presentation

β–Ά
cs3102 theory of
SMART_READER_LITE
LIVE PREVIEW

CS3102 Theory of Computation Warm up: Whats the language of this - - PowerPoint PPT Presentation

CS3102 Theory of Computation Warm up: Whats the language of this NFA? 0, final start 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


slide-1
SLIDE 1

CS3102 Theory of Computation

Warm up: What’s the language of this NFA?

start

final

0, 𝜁

slide-2
SLIDE 2

Logistics

2

slide-3
SLIDE 3

Last Time

  • Non-determinism

3

slide-4
SLIDE 4

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

slide-5
SLIDE 5

Proof β€œStoryboard”

5

FSA Regex 𝜁, literal, union, concat, * How to build a Regex Computability by FSA closed under

=

Non- determinism Makes that easy

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

Nondeterminism

8

?

Why not both?

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

slide-9
SLIDE 9

Example Non-deterministic Finite Automaton

  • π‘‡π‘“π‘‘π‘π‘œπ‘’π‘€π‘π‘‘π‘’1 =

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

9

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

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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

slide-12
SLIDE 12

Powerset Construction

12

  • ne

0,1 start next 0,1 1

{} start

  • ne

next Start,

  • ne

Start, next One, next Start, One, next

slide-13
SLIDE 13

Powerset Construction

13

  • ne

0,1 start next 0,1 1

{} start

  • ne

next Start,

  • ne

Start, next One, next Start, One, next

1 1 1 1

slide-14
SLIDE 14

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

slide-15
SLIDE 15

Union Using Non-Determinism

15 start

0,1 1

Some 0s No 0s

1 Even 1 1

Odd

new Goal: Return 1 if either machine returns 1 Strategy: Run both machines in parallel (non-deterministically) by transitioning to the start states for both without using input

slide-16
SLIDE 16

Union Using Non-Determinism

16 start

0,1 1

Some 0s No 0s

1 Even 1 1

Odd

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

1 βˆͺ 𝐺 2

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

slide-17
SLIDE 17

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

slide-18
SLIDE 18

Concatenation using NFA

18

𝑁2 e 𝑁1 e

start

0,1 1

Some 0s No 0s

1 Even 1 1

Odd

Goal: Return 1 if the input can be broken into 2 chunks, 𝑁1 returns 1 on the first chunk, 𝑁2 on the second Strategy: Every time we enter a final state in 𝑁1, non-deterministically run the rest of the string on 𝑁2. Return 1 if 𝑁2 does.

slide-19
SLIDE 19

Concatenation using NFA

19

𝑁2 e 𝑁1 e

start

0,1 1

Some 0s No 0s

1 Even 1 1

Odd

𝜁 𝜁 𝑁𝑑 = 𝑅1 βˆͺ 𝑅2, Ξ£, πœ€π‘‘, π‘Ÿ01, 𝐺

2

πœ€π‘‘(π‘Ÿ, 𝜏) = πœ€1 π‘Ÿ, 𝜏 if π‘Ÿ ∈ 𝑅1 βˆ’ 𝐺

1

πœ€1 π‘Ÿ, 𝜏 , π‘Ÿ0,2 if π‘Ÿ ∈ 𝐺

1

{πœ€2 π‘Ÿ, 𝜏 } if π‘Ÿ ∈ 𝑅2

slide-20
SLIDE 20

Kleene Star

  • π‘€βˆ— = 𝑀0 βˆͺ 𝑀1 βˆͺ 𝑀2 βˆͺ β‹―
  • 𝑀0 = {𝜁}
  • 𝑀𝑙 = (𝑀 concatenated 𝑙 times)
  • 00, 11 βˆ— =

{𝜁, 00, 11, 0011, 1100, 0000, 1111, 110011, … }

20

slide-21
SLIDE 21

Kleene Star using NFA

21

𝑁1 e e e

start

0,1 1

Some 0s No 0s

1 Goal: Return 1 if the input can be broken into chunks such that 𝑁1 returns 1 for every chunk Strategy: Every time we enter a final state in 𝑁1, non- deterministically β€œrestart” the machine to run on the rest of the string, make sure we return 1 on 𝜁

slide-22
SLIDE 22

Kleene Star using NFA

22

𝑁1 e e e

start

0,1 1

Some 0s No 0s

1 Goal: Return 1 if the input can be broken into chunks such that 𝑁1 returns 1 for every chunk Strategy: Every time we enter a final state in 𝑁1, non- deterministically β€œrestart” the machine to run on the rest of the string, make sure we return 1 on 𝜁

empty

𝜁 𝜁 𝜁

slide-23
SLIDE 23

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

slide-24
SLIDE 24

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

slide-25
SLIDE 25

Majority with FSA?

  • Consider an inputs with lots of 0s
  • Recall: we read 1 bit at a time, no going back!
  • To count to 50,000, we'll need 50,000 states!

25

000...0000 111...1111 000...0000 111...1111 Γ—50,000 Γ—50,000 Γ—50,000 Γ—50,001 000...0000 111...1111 Γ—49,999 Γ—50,000