Presentation is loading. Please wait.

Presentation is loading. Please wait.

TMs for {a2n | n  0} {a2n | n  0}

Similar presentations


Presentation on theme: "TMs for {a2n | n  0} {a2n | n  0}"— Presentation transcript:

1 TMs for {a2n | n  0} {a2n | n  0}
How to design a TM for the language containing the strings of a’s whose length is a power of 2? {a2n | n  0} Basic idea: Step 1: count the number of a’s, say m Step 2: check whether m is a power of 2 In this class, we will study two different TMs for this language: TM 1: Use a unary number to represent m TM 2: Use a binary number to represent m

2 Review of unary and binary numbers
Unary numbers Use a single symbol, such as  Number m is represented by m symbols Examples: 1:  2:  3:  4:  Binary numbers Use two symbols, such as 0 and 1 1: 1 2: 10 3: 11 4: 100

3 TM 1 for {a2n | n  0}: Basic Idea
Step 1: use a unary number m to count the number of a’s Step 2: check whether m is a power of 2 How to count the number of a’s with a unary number? We do not need an additional counter. The input string itself can be treated as a unary number with symbol a. Example: String aaaa is a unary number and its decimal value is 4. String aa is a unary number and its decimal value is 2.

4 TM 1 for {a2n | n  0}: Basic Idea
Step 1: use a unary number m to count the number of a’s Step 2: check whether m is a power of 2 How to check whether a decimal number is a power of 2? Keep dividing m by 2, until we get an odd number. If the odd number is 1, the original m is a power of 2; otherwise, not a power of 2. Example: Originally, m=4 After dividing it by 2, m=2 After dividing it by 2, m=1 Therefore, the original m is a power 2.

5 TM 1 for {a2n | n  0}: Basic Idea
Step 1: use a unary number m to count the number of a’s Step 2: check whether m is a power of 2 How to check whether a unary number is a power of 2? The same method, but the problem is how to divide a unary number by 2? Relatively easy way: Remove every other a (i.e., replacing it with a special symbol, say x) Example: Originally, a a a a After dividing it by 2, a x a x After dividing it by 2, a x x x Therefore, the original number is a power 2.

6 TM 1 for {a2n | n  0}: State Diagram
Put everything together Step 1: treat the input string as a unary number m Step 2: keep dividing m by 2 by removing every other a, until we get an odd number. If the odd number is 1, we accept the string; otherwise, reject it. aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

7 TM 1 for {a2n | n0}: State 0 State 0 replaces the first a with A to indicate the left-most cell of the tape. aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

8 TM 1 for {a2n | n0}: State 1 State 1 checks whether m=1 or not.
If so, go to the accept state. aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

9 TM 1 for {a2n | n0}: State 2 State 2 checks whether m is even
If so, go to state 4. State 3 checks whether m is odd If so, go to the reject state. aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

10 TM 1 for {a2n | n0}: States 2 and 3
Also states 2 and 3 together divide m by 2 (i.e. replacing every other symbol a with symbol x). aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

11 TM 1 for {a2n | n0}: State 4 State 4 moves the tape head back to the left-most cell to start a new round. aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

12 Input String: aaaa a a a a 4 1 2 3 aa,L xx,L accept reject  ,R
1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

13 Round 1 Step 0 : a a a a Round 1 state 0 replaces the first a by A to indicate the left-most cell of the tape 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

14 Round 1 A a a a 4 1 2 3 Step 1 : state 1 checks whether m=1 or not.
there are more than one a’s (i.e., m>1), so go to state 2, and at the same time divide m by 2 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

15 Round 1 A x a a 4 1 2 3 Step 2 : state 2 checks whether m is even.
there is one more a, so go to state 3 to check whether m is odd 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

16 Round 1 A x a a 4 1 2 3 Step 3 : state 3 checks whether m is odd
there is one more a, so go to state 2 to check whether m is even, and at the same time divide m by 2. 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

17 Round 1 A x a x 4 1 2 3 Step 4 : state 2 checks whether m is even.
there is no more a’s (i.e. m is even), so go to state 4 to start the next round 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

18 Round 1 A x a x 4 1 2 3 Step 5 : moving back to the left end aa,L
1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

19 Round 1 A x a x 4 1 2 3 Step 6 : moving back to the left end aa,L
1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

20 Round 1 A x a x 4 1 2 3 Step 7 : moving back to the left end aa,L
1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

21 Round 1 Step 8 : A x a x we have reached the left end (letter A) 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

22 Round 2 Step 9 : A x a x Round 2 state 1 checks whether m=1 or not in this round skip all x’s 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

23 Round 2 Step 10 : A x a x state 1 checks whether m=1 or not in this round there are more than one a’s (i.e., m>1) in this round, so go to state 2, and at the same time divide m by 2 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

24 Round 2 Step 11 : A x x x state 2 checks whether m is even in this round. skip the x 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

25 Round 2 Step 12 : A x x x state 2 checks whether m is even in this round. there is no more a’s (i.e., m is even) in this round, so go to state 4 to start the next round 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

26 Round 2 A x x x 4 1 2 3 Step 13 : moving back to the left end aa,L
1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

27 Round 2 A x x x 4 1 2 3 Step 14 : moving back to the left end aa,L
1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

28 Round 2 A x x x 4 1 2 3 Step 15 : moving back to the left end aa,L
1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

29 Round 2 Step 16 : A x x x We have reached the left end (letter A) 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

30 Round 3 Step 17 : A x x x Round 3 state 1 checks whether m=1 or not in this round skip all x’s 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

31 Round 3 Step 18 : A x x x state 1 checks whether m=1 or not in this round skip all x’s 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

32 Round 3 Step 19 : A x x x state 1 checks whether m=1 or not in this round skip all x’s 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

33 Round 3 Step 20 : A x x x state 1 checks whether m=1 or not in this round there is no more a’s (i.e., m=1) in this round, so the original m is a power of 2, and then go to the accept state 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

34 String aaaa is accepted
Step 21 : A x x x Accept 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

35 Another Input String: aaa
1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

36 Round 1 Step 0 : a a a Round 1 state 0 replaces the first a by A to indicate the left-most cell of the tape 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

37 Round 1 A a a 4 1 2 3 Step 1 : state 1 checks whether m=1 or not.
there are more than one a’s (i.e., m>1), so go to state 2, and at the same time divide m by 2 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

38 Round 1 A x a 4 1 2 3 Step 2 : state 2 checks whether m is even.
there is one more a, so go to state 3 to check whether m is odd 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

39 Round 1 A x a 4 1 2 3 Step 3 : state 3 checks whether m is odd
there is no more a. That is, m is an odd number and m is not 1. Therefore, go to the reject state 1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

40 String aaa is rejected A x a 4 1 2 3 Step 4 : reject aa,L xx,L
1 reject 2 accept 3 4 aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

41 TM 1 for {a2n | n  0}: Summary
Basic Idea Step 1: treat the input string as a unary number m Step 2: keep dividing m by 2 by removing every other a, until we get an odd number. If the odd number is 1, we accept the string; otherwise, reject it. aa,L xx,L accept 4 reject  ,R AA,R  ,L  ,R ax,R 1 2 3 aA,R aa,R ax,R xx,R xx,R xx,R

42 TM 2 for {a2n | n  0}: Basic Idea
Step 1: use a binary counter m to count the number of a’s. Specifically, we write the binary counter after the string on the tape. Initially, it is zero. At each round, we remove one a from the string, and then increase the counter by one. Step 2: check whether the counter m is a power of 2 How to increase a binary counter by 1? Example: At some point, After one round, After the next round, Difficulty: we need to shift the counter one bit to the right, if there is a carry from the most significant bit. string counter x a 1 x a 1 x a 1

43 TM 2 for {a2n | n  0}: Basic Idea
Step 1: use a binary counter m to count the number of a’s. Specifically, we write the binary counter after the string on the tape. Initially, it is zero. At each round, we remove one a from the string, and then increase the counter by one. Step 2: check whether the counter m is a power of 2 How to increase a binary counter by 1? Relatively easy way: Write the counter in the reverse order. At some point, After one round, After the next round, If there is a carry from the most significant bit, we just write it to the next blank cell. string counter x a 1 x a 1 x a 1

44 TM 2 for {a2n | n  0}: Basic Idea
Step 1: use a binary counter m to count the number of a’s. Specifically, we write the binary counter after the string on the tape. Initially, it is zero. At each round, we remove one a from the string, and then increase the counter by one. Step 2: check whether the counter m is a power of 2 How to check whether binary m is a power of 2? Check whether m looks like 0..01 Example Relatively easy way: count m-1 (do not increase the counter for the last a), and check whether it looks like 1..1 string counter x 1 x 1

45 TM 2 for {a2n | n  0}: Put everything together
Step 1: write a binary counter in the reverse order on the tape. Initially, it is zero. At each round, we remove one a from the string, and then increase the counter by one except for the last a. Step 2: check whether m-1 looks like If so, accept the string; otherwise, reject it. string counter

46 TM 2 for {a2n | n  0}: State Diagram
3 10,R 01,L 1,L 10,R aa,L 00,L 11,L 4 2 aa,R 01,L 1,L reject 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

47 TM 2 for {a2n | n0}: State 0 State 0 removes one a from
an input string 3 10,R 01,L 1,L 10,R aa,L 00,L 11,L 4 2 aa,R 01,L 1,L reject 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

48 TM 2 for {a2n | n0}: State 1 State 1 checks whether the removed a is the last one or not. If not, increase the counter by 1 If so, check whether counter=1…1 If 1…1, accept; otherwise, reject. 3 10,R 01,L 1,L 10,R aa,L 00,L 11,L 4 2 aa,R 01,L 1,L reject 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

49 TM 2 for {a2n | n0}: State 5 State 5 continues to check
whether the counter = 1…1 3 10,R 01,L 1,L 10,R aa,L 00,L 11,L 4 2 aa,R 01,L 1,L reject 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

50 TM 2 for {a2n | n0}: States 2 and 3
States 2 and 3 together move the tape head to the counter, and increase the counter by one. 3 10,R 01,L 1,L 10,R aa,L 00,L 11,L 4 2 aa,R 01,L 1,L reject 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

51 TM 2 for {a2n | n0}: State 4 State 4 moves the tape head
back to find the next a to be removed. 3 10,R 01,L 1,L 10,R aa,L 00,L 11,L 4 2 aa,R 01,L 1,L reject 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

52 Input String: aaaa a a a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

53 Input String: aaaa a a a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 0 Counter = 0 Remove one a 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

54 Input String: aaaa x a a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 1 The removed a is not the last one, so we go to the end of the string to increase the counter 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

55 Input String: aaaa x a a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 2 move the tape head to the end of the input string 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

56 Input String: aaaa x a a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 3 move the tape head to the end of the input string 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

57 Input String: aaaa x a a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 4 we have reached the end of the string. Increase the counter by 1, 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

58 Input String: aaaa x a a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 5 Move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

59 Input String: aaaa x a a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 6 Move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

60 Input String: aaaa x a a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 7 Move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

61 Input String: aaaa x a a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 8 Have found the next a to be removed (i.e. the a right after x’s) 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

62 Input String: aaaa x a a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 9 Remove one a 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

63 Input String: aaaa x x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 10 The removed a is not the last one, so we go to the end of the string to increase the counter. 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

64 Input String: aaaa x x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 11 Move the tape head to the counter 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

65 Input String: aaaa x x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 12 Increasing the counter by 1… 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

66 Input String: aaaa x x a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 13 Increasing the counter by 1, and counter = 01 (i.e. reverse order of binary number of 2) 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

67 Input String: aaaa x x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 14 Move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

68 Input String: aaaa x x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 15 Move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

69 Input String: aaaa x x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 16 Move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

70 Input String: aaaa x x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 17 Have found the next a to be removed (i.e. the a right after x’s) 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

71 Input String: aaaa x x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 18 Remove one a 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

72 Input String: aaaa x x x a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 19 The removed a is not the last one, so go to the end of the string to increase the counter 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

73 Input String: aaaa x x x a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 20 Increase the counter by 1, and counter = 11 (i.e. the reverse order of binary number of 3) 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

74 Input String: aaaa x x x a 1 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 21 move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

75 Input String: aaaa x x x a 1 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 22 Have found the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

76 Input String: aaaa x x x a 1 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 23 Remove one a 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

77 Input String: aaaa x x x x 1 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 24 The removed a is the last one, so we check whether every bit of the counter is 1 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

78 Input String: aaaa x x x x 1 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 25 Continue checking whether every bit of the counter is 1 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

79 Input String: aaaa x x x x 1 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 26 Yes, every bit of the counter is 1, so go to the accept state 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

80 String aaaa is accepted
x x x x 1 1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 27 Accept 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

81 Another Input String: aaa
3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

82 Input String: aaa a a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 0 Counter = 0 Remove one a 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

83 Input String: aaa x a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 1 The removed a is not the last one, so we go to the end of the string to increase the counter 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

84 Input String: aaa x a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 2 move the tape head to the end of the input string 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

85 Input String: aaa x a a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 3 we have reached the end of the string. Increase the counter by 1, 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

86 Input String: aaa x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 4 Move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

87 Input String: aaa x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 5 Move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

88 Input String: aaa x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 6 Have found the next a to be removed (i.e. the a right after x’s) 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

89 Input String: aaa x a a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 7 Remove one a 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

90 Input String: aaa x x a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 8 The removed a is not the last one, so we go to the end of the string to increase the counter. 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

91 Input String: aaa x x a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 9 Increasing the counter by 1… 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

92 Input String: aaa x x a 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 10 Increasing the counter by 1, and counter = 01 (i.e. reverse order of binary number of 2) 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

93 Input String: aaa x x a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 11 Move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

94 Input String: aaa x x a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 12 Move the tape head back to find the next a to be removed 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

95 Input String: aaa x x a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 13 Have found the next a to be removed (i.e. the a right after x’s) 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

96 Input String: aaa x x a 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 14 Remove one a 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

97 Input String: aaa x x x 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L 00,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 15 The removed a is the last one, so we check whether every bit of the counter is 1. But, there is a 0. 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

98 String aaa is rejected x x x 1 3 4 2 1 5 10,R 01,L 1,L 10,R aa,L
1 3 10,R 01,L 1,L reject 1 10,R aa,L 00,L 11,L accept 2 4 2 aa,R 5 3 01,L 1,L 4 reject Step 16 Reject 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept

99 TM 2 for {a2n | n  0}: Summary
Basic Idea Step 1: use a binary counter to counter m-1. Step 2: check whether m-1 looks like 1..1. 3 10,R 01,L 1,L 10,R aa,L 00,L 11,L 4 2 aa,R 01,L 1,L reject 00,R xx,R aa,R 00,R 1 11,R 5 11,R ax,R  ,R  ,R accept


Download ppt "TMs for {a2n | n  0} {a2n | n  0}"

Similar presentations


Ads by Google