<<

Finite AutomataHuman-aware Robocs

• 2017/08/22 • Chapter 1.1 in Sipser

1 Last time Human-aware Robocs

• Theory of computation § Finite automata o Automata Theory § Pushdown automata o Computability Theory § Turing machines o Complexity Theory

2 Outline forHuman-aware Robocs today

• Finite automata o Definition of FA o Computation of FA o Regular language o Design an FA

3 DefinitionHuman-aware Robocs of FA

• ( Q, ⌃, ,q0,F)

4 DefinitionHuman-aware Robocs of FA

• ( Q, ⌃, ,q0,F)

o Q == q0q,q01,q,q12,q3 {{ } } o ⌃ = a, b { } o = Q ⌃ Q ⇥ ! o q 0 o F = q1 { }

5 DefinitionHuman-aware Robocs of FA

• ( Q, ⌃, ,q0,F)

• Notes about FA o Can F be {} or ? ; o Can we have two initial states? Two accept states? o Can the initial state also be an accept state? o Can we have two arrows out of a state on the same symbol?

6 Outline forHuman-aware Robocs today

• Finite automata o Definition of FA o Computation of FA o Regular language o Design an FA

7 ComputationHuman-aware Robocs of FA

• ( Q, ⌃, ,q0,F)

• Computation o Input string: a finite length string over the alphabet ⌃

input

8 ComputationHuman-aware Robocs of FA

• ( Q, ⌃, ,q0,F)

• Computation

input

9 ComputationHuman-aware Robocs of FA

• ( Q, ⌃, ,q0,F)

• Computation

input

10 ComputationHuman-aware Robocs of FA

• ( Q, ⌃, ,q0,F)

• Computation

input input ends: reject

11 ComputationHuman-aware Robocs of FA

• ( Q, ⌃, ,q0,F)

• Computation o The computation stops in an non-accept state: reject o The computation stops in an accept state: accept o

12 Outline forHuman-aware Robocs today

• Finite automata o Definition of FA o Computation of FA o Regular language o Design an FA

13 Regular languageHuman-aware Robocs

• ( Q, ⌃, ,q0,F) • A language is a of strings • Let A be the set of strings that a machine M accepts: A is the language of machine M, or equivalently M recognizes A, and write L(M) = A o What is A in the above example?

14 Regular languageHuman-aware Robocs

• How to describe the language of a machine M?

15 LexicographicHuman-aware Robocs order of strings

v Review: • Alphabet: any nonempty of symbols (also known as symbols of an alphabet) o ⌃ = a, b, c, d 1 { } o ⌃ = 0, 1 2 { } • String (over an alphabet): a finite of symbols, w o length of a string, |w | o zero length string or empty string, " o Q: is {} the same as {" }?

• ⌃ ⇤ : all the strings over the alphabet ⌃

o Q: does ⌃ ⇤ include " ?

16 LexicographicHuman-aware Robocs order of strings

• Lexicographic order: similar to order o An ordering relation < on the symbols of an alphabet: < ⌃ ⌃ ✓ ⇥ o In English, ( a, b ) <, ( b, c ) <, ( a, c ) < , or simplified as, a < b, b < c, a < c 2 2 2 • More formally, x, y over 2 ⌃⇤ ⌃ o we write x y iff  1) y = xu for some u , OR 2⌃⇤ 2) x = uav, y = ua’w and a a’ for some u, v, w ⌃ and a, a’ ⌃  2 ⇤ 2 • What is the lexicographic order for {0, 1}* ?

17 LexicographicHuman-aware Robocs order of strings

• Lexicographic order: similar to dictionary order o An ordering relation < on the symbols of an alphabet: < ⌃ ⌃ ✓ ⇥ o In English, ( a, b ) <, ( b, c ) <, ( a, c ) < , or simplified as, a < b, b < c, a < c 2 2 2 • More formally, x, y over 2 ⌃⇤ ⌃ o we write x y iff  1) y = xu for some u , OR 2⌃⇤ 2) x = uav, y = ua’w and a a’ for some u, v, w ⌃ and a, a’ ⌃  2 ⇤ 2 • What is the lexicographic order for {0, 1}* ? o Identify the ordering relation on the symbols, let’s say 0 < 1 o ( " , 0, 00, 000, 0000, …, 00000..001, 00000..010, 00000..011, …)

18 LexicographicHuman-aware Robocs order of strings

• Shortlex order: similar to lexicographic order, except that shorter strings precede longer strings o ( " , 0, 00, 000, 0000, …, 00000..001, 00000..010, 00000..011, …) o ( " , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …) • Consider the following strings: ab, aa, a, aba, acbab, abaaaa o Lexicographic order o Shortlex order

19 LexicographicHuman-aware Robocs order of strings

• Shortlex order: similar to lexicographic order, except that shorter strings precede longer strings o ( " , 0, 00, 000, 0000, …, 00000..001, 00000..010, 00000..011, …) o ( " , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …) • Consider the following strings: ab, aa, a, aba, acbab, abaaaa o Lexicographic order: {a, aa, ab, aba, abaaaa, acbab} o Shortlex order: {a, aa, ab, aba, acbab, abaaaa}

20 Regular languageHuman-aware Robocs

• How to describe the language of a machine M?

o List all the strings ⌃ ⇤ in shortlex order o Compare patterns for accept and reject strings

21 Regular languageHuman-aware Robocs

• How to describe the language of a machine M?

o List all the strings ⌃ ⇤ in shortlex order o Compare patterns for accept and reject strings

o ⌃ ⇤ = { " , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …}

22 Regular languageHuman-aware Robocs

• How to describe the language of a machine M?

o List all the strings ⌃ ⇤ in shortlex order o Compare patterns for accept and reject strings

o ⌃ ⇤ = { " , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …}

23 Regular languageHuman-aware Robocs

• How to describe the language of a machine M?

o List all the strings ⌃ ⇤ in shortlex order o Compare patterns for accept and reject strings

o ⌃ ⇤ = { " , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …} o A = {w |w contains at least one 1 and an even number of 0s following the last 1}

24 Regular languageHuman-aware Robocs

• How to describe the language of a machine M?

o List all the strings ⌃ ⇤ in shortlex order o Compare patterns for accept and reject strings

o ⌃ ⇤ = { " , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …}

25 Regular languageHuman-aware Robocs

• How to describe the language of a machine M?

o List all the strings ⌃ ⇤ in shortlex order o Compare patterns for accept and reject strings

o ⌃ ⇤ = { " , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …}

26 Regular languageHuman-aware Robocs

• How to describe the language of a machine M?

o List all the strings ⌃ ⇤ in shortlex order o Compare patterns for accept and reject strings

o ⌃ ⇤ = { " , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …}

27 Regular languageHuman-aware Robocs

• How to describe the language of a machine M?

o List all the strings ⌃ ⇤ in shortlex order o Compare patterns for accept and reject strings

o ⌃ ⇤ = { " , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …} o A = {w |w is the empty string " or ends in a 0}

28 Regular languageHuman-aware Robocs

• ⌃ ⇤ = {" , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …} o L(M) = { " , 0, 00, 10, 000, 010, …} o L ( M ) = {1, 01, 11, 001, 011, …} or complement of L(M)

29 Regular languageHuman-aware Robocs

• Notes about a regular langauge o a regular language (recgonized by a FA) may contain an infinite number of strings o an FA recognizes a unique language. Why?

30 Outline forHuman-aware Robocs today

• Finite automata o Definition of FA o Computation of FA o Regular language o Design an FA • Reading assignment for the next class: o Sipser Sec. 0.3, 0.4, http://jflap.org/tutorial/ ->Finite Automata- >Construct and Run->Building Your First Finite Automaton (UP TO Running the Finite Automaton on Multiple Strings) – Quiz link will be sent out; due date is before the beginning of the next class

31 Finite AutomataHuman-aware Robocs (Cont.)

• 2017/08/24 • Chapter 1.1 in Sipser Ø Announcement: q Office hours moved to 5:30 to 6:30PM T/Th q Answers to quiz questions will be posted soon after the due date; answers to your questions are immediately available after the due date q HW1 will be announced later today; due in a week

32 Last time Human-aware Robocs

• Finite automata o Definition of FA o Computation of FA o Regular language o Regular language and FA o Regular operations o Design an FA

33 LexicographicHuman-aware Robocs order of strings (review)

• Lexicographic order: similar to dictionary order o An ordering relation < on the symbols of an alphabet: < ⌃ ⌃ ✓ ⇥ o In English, ( a, b ) <, ( b, c ) <, ( a, c ) < , or simplified as, a < b, b < c, a < c 2 2 2 • More formally, x, y over 2 ⌃⇤ ⌃ o we write x y iff  1) y = xu for some u , OR 2⌃⇤ 2) x = uav, y = ua’w and a < a’ for some u, v, w and a, a’ ⌃ 2⌃⇤ 2 • What is the lexicographic order for {0, 1}* ? o Identify the ordering relation on the symbols, let’s say 0 < 1 o ( " , 0, 00, 000, 0000, …, 00000..001, 00000..010, 00000..011, …)

34 LexicographicHuman-aware Robocs order of strings (review)

• Shortlex order: similar to lexicographic order, except that shorter strings precede longer strings o ( " , 0, 00, 000, 0000, …, 00000..001, 00000..010, 00000..011, …) o ( " , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …) • Consider the following strings: ab, aa, a, aba, acbab, abaaaa o Lexicographic order: {a, aa, ab, aba, abaaaa, acbab} o Shortlex order: {a, aa, ab, aba, acbab, abaaaa}

35 Outline forHuman-aware Robocs today

• Finite automata o Definition of FA o Computation of FA o Regular language o Regular language and FA o Regular operations o Design an FA

36 Regular operationHuman-aware Robocs

• Notes about regular operations o Unary and binary operations

* o Similaries and differences between A and ⌃⇤

37 Regular operationHuman-aware Robocs

38 Closed collectionHuman-aware Robocs

• Definition - A collection (or set) is closed under an operation if applying this operation to members of the collection returns a member in the collection o Are the set of integers, Z, closed under addition? multiplication? division? o What about rational numbers, Q? o What if we add in the square root operation?

39 Closed underHuman-aware Robocs operation

• Definition - A collection (or set) is closed under an operation if applying this operation to members of the collection returns a member in the collection o Are the set of integers, Z, closed under addition? multiplication? division? o What about rational numbers, Q? o What if we add in the square root operation?

40 Closed underHuman-aware Robocs union

v Review: • Proof by construction • Proof by contradiction • Proof by induction

41 Closed underHuman-aware Robocs union

v Review: • Proof by construction

• Proof by contradiction • Proof by induction

42 Closed underHuman-aware Robocs union

1. Given any RLs A1 and A2 1. Prove that A1 A2 is also a RL [

43 Closed underHuman-aware Robocs union

1. Given any RLs A1 and A2 1. Prove that A1 A2 is also a RL [ 2. Based on the definition, we can 2. Construct a machine M to simulate both M1 and construct M1 for A1 and M2 for A2 M2 at the same time and accept if either one

M1 =(Q1, ⌃, 1,q0,F1) accepts M2 =(Q2, ⌃, 2,s0,F2) o Keep a copy of both M1 and M2; for every step in M, run a step from M1 and then a step in M2; M accepts if either M1 or M2 accepts; otherwise, reject o First run M1, if M1 accpets, M accepts; otherwise, run M2 with the same input, if M2 accepts, M accepts; otherwise, reject

44 Closed underHuman-aware Robocs union

1. Given any RLs A1 and A2 1. Prove that A1 A2 is also a RL [ 2. Based on the definition, we can 2. Construct a machine M to simulate both M1 and construct M1 for A1 and M2 for A2 M2 at the same time and accept if either one

M1 =(Q1, ⌃, 1,q0,F1) accepts M2 =(Q2, ⌃, 2,s0,F2) o Keep a copy of both M1 and M2; for every step in M, run a step from M1 and then a step in M2; M accepts if either M1 or M2 accepts; otherwise, reject o First run M1, if M1 accpets, M accepts; otherwise, run M2 with the same input, if M2 accepts, M accepts; otherwise, reject

45 Closed underHuman-aware Robocs union

1. Given any RLs A1 and A2 1. Prove that A1 A2 is also a RL [ 2. Based on the definition, we can 2. Construct a machine M to simulate both M1 and construct M1 for A1 and M2 for A2 M2 at the same time and accept if either one

M1 =(Q1, ⌃, 1,q0,F1) accepts M2 =(Q2, ⌃, 2,s0,F2) o Keep a copy of both M1 and M2; for every step in M, run a step from M1 and then a step in M2; M accepts if either M1 or M2 accepts; otherwise, reject o First run M1, if M1 accpets, M accepts; otherwise, run M2 with the same input, if M2 accepts, M accepts; otherwise, reject

46 Closed underHuman-aware Robocs union

1. Given any RLs A1 and A2 1. Prove that A1 A2 is also a RL [ 2. Based on the definition, we can 2. Construct a machine M to simulate both M1 and construct M1 for A1 and M2 for A2 M2 at the same time and accept if either one

M1 =(Q1, ⌃, 1,q0,F1) accepts M2 =(Q2, ⌃, 2,s0,F2) o Keep a copy of both M1 and M2; for every step in M, run a step from M1 and then a step in M2; M accepts if either M1 or M2 accepts; otherwise, reject o First run M1, if M1 accpets, M accepts; otherwise, run M2 with the same input, if M2 accepts, M accepts; otherwise, reject

47 Closed underHuman-aware Robocs union

1. Given any RLs A1 and A2 1. Prove that A1 A2 is also a RL [ 2. Based on the definition, we can 2. Construct a machine M to simulate both M1 and construct M1 for A1 and M2 for A2 M2 at the same time and accept if either one

M1 =(Q1, ⌃, 1,q0,F1) accepts M2 =(Q2, ⌃, 2,s0,F2) o Keep a copy of both M1 and M2; for every step in M, run a step from M1 and then a step in M2; M accepts if either M1 or M2 accepts; otherwise, reject o First run M1, if M1 accpets, M accepts; otherwise, run M2 with the same input, if M2 accepts, M accepts; otherwise, reject

48 Closed underHuman-aware Robocs union

1. Given any RLs A1 and A2 1. Prove that A1 A2 is also a RL [ 2. Based on the definition, we can 2. Construct a machine M to simulate both M1 and construct M1 for A1 and M2 for A2 M2 at the same time and accept if either one

M1 =(Q1, ⌃, 1,q0,F1) accepts M2 =(Q2, ⌃, 2,s0,F2) o Keep a copy of both M1 and M2; for every step in M, run a step from M1 and then a step in M2; M accepts if either M1 or M2 accepts; otherwise, reject o First run M1, if M1 accpets, M accepts; otherwise, run M2 with the same input, if M2 accepts, M accepts; otherwise, reject

49 Closed underHuman-aware Robocs union

1. Given any RLs A1 and A2 1. Prove that A1 A2 is also a RL [ 2. Based on the definition, we can 2. Construct a machine M to simulate both M1 and construct M1 for A1 and M2 for A2 M2 at the same time and accept if either one

M1 =(Q1, ⌃, 1,q0,F1) accepts M2 =(Q2, ⌃, 2,s0,F2) o Keep a copy of both M1 and M2; for every step in M, run a step from M1 and then a step in M2; M accepts if either M1 or M2 accepts; otherwise, reject o First run M1, if M1 accpets, M accepts; otherwise, run M2 with the same input, if M2 accepts, M accepts; otherwise, reject Q = Q1 Q2 F = F ⇥Q F Q 1 ⇥ 2 [ 2 ⇥ 1

M =(Q, ⌃, ,q s ,F) 50 0 ⇥ 0 Closed underHuman-aware Robocs union

1. Given any RLs A1 and A2 1. Prove that A1 A2 is also a RL [ 2. Based on the definition, we can 2. Construct a machine M to simulate both M1 and construct M1 for A1 and M2 for A2 M2 at the same time and accept if either one

M1 =(Q1, ⌃, 1,q0,F1) accepts M2 =(Q2, ⌃, 2,s0,F2) o Keep a copy of both M1 and M2; for every step in M, run a step from M1 and then a step in M2; M accepts if either M1 or M2 accepts; otherwise, reject o First run M1, if M1 accpets, M accepts; otherwise, run M2 with the same input, if M2 accepts, M accepts; otherwise, reject Q = Q1 Q2 F = F ⇥Q F Q 1 ⇥ 2 [ 2 ⇥ 1 q What if F = F F ? 1 ⇥ 2 q Note: what if we want to find the complement of M =(Q, ⌃, ,q s ,F) a language? 51 0 ⇥ 0 Outline forHuman-aware Robocs today

• Finite automata o Definition of FA o Computation of FA o Regular language o Regular language and FA o Regular operations o Design an FA

52 Design anHuman-aware Robocs FA

• Download JFLAP

o BB Content Software Libraries ! !

53 Design anHuman-aware Robocs FA

• Book exampe: L(M) = {w | w {0, 1}* and 001 is a substring of w } 2 o Pretend that you are the machine reading the string o Identify how much memory you need or what are the states you need to remember? • What are the states

54 Design anHuman-aware Robocs FA

• Book exampe: L(M) = {w | w {0, 1}* and 001 is a substring of w } 2 o Pretend that you are the machine reading the string o Identify how much memory you need or what are the states you need to remember? • What are the states o haven’t just seen any symbols of the pattern o have just seen a 0 o have just seen 00 o have been the entire pattern 001

55 Design anHuman-aware Robocs FA

• Exampe: L(M) = { w | w {0, 1}* and 001 is a suffix of w } 2 o Pretend that you are the machine reading the string o Identify how much memory you need or what are the states you need to remember? • What are the states

• Is this correct?

56 Design anHuman-aware Robocs FA

• Exampe: L(M) = { w | w {0, 1}* and 001 is a suffix of w } 2 o Pretend that you are the machine reading the string o Identify how much memory you need or what are the states you need to remember?

• What are the states let us revisit our previous example where 001 is a substring o haven’t just seen any symbols of the pattern o have just seen a 0 o have just seen 00 o have been the entire pattern 001

57

Design anHuman-aware Robocs FA

• Exampe: L(M) = { w | w {0, 1}* and 001 is a suffix of w } 2 o Pretend that you are the machine reading the string o Identify how much memory you need or what are the states you need to remember? • What are the states o haven’t just seen any symbols of the pattern o have just seen a 0 o have just seen 00 o have been the entire pattern 001

58 Design anHuman-aware Robocs FA

• Exampe: o Assume that we have an elevator serving 3 floors o Build a finite automaton M that satisifes § If no requests, stays idle § First in first serve unless the elevator unless the new requests are on the way; otherwise, the request will be dropped until the current request is served § Alphabet {1, 2, 3, 1up, 2up, 2dn, 3dn, at1, at2, at3} or design your own; no simultaneous actions and sensor outputs § Accept only when idle o States?

59 Design anHuman-aware Robocs FA

• One possible FA:

60 Design anHuman-aware Robocs FA

• Exampe: o Assume that we have an elevator serving 3 floors o Build a finite automaton M that satisifes § If no requests, stays idle § First in first serve unless the elevator unless the new requests are on the way; otherwise, the request will be dropped until the current request is served § Alphabet {1, 2, 3, 1up, 2up, 2dn, 3dn, at1, at2, at3} or design your own; no simultaneous actions and sensor outputs § Accept only when idle Ø State abstraction is the key here!

61 Outline forHuman-aware Robocs today

• Finite automata o Definition of FA o Computation of FA o Regular language o Regular language and FA o Regular operations o Design an FA • Reading assignment for the next class: o Sipser Sec. 1.1 (up to page 58, closure under the regular operations) – Quiz link will be sent out; due date is before the beginning of the next class

62