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

Slides:



Advertisements
Similar presentations
Introduction to Computability Theory
Advertisements

Lecture 16 Deterministic Turing Machine (DTM) Finite Control tape head.
Variants of Turing machines
THE CHURCH-TURING T H E S I S “ TURING MACHINES” Pages COMPUTABILITY THEORY.
Decidable A problem P is decidable if it can be solved by a Turing machine T that always halt. (We say that P has an effective algorithm.) Note that the.
Fall 2004COMP 3351 Turing Machines. Fall 2004COMP 3352 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Courtesy Costas Busch - RPI1 Turing Machines. Courtesy Costas Busch - RPI2 The Language Hierarchy Regular Languages Context-Free Languages ? ?

Key to Homework #2 1. What is the language of L-system G = ({a, b, c}, h, acb ), where the rewriting rule h is defined as follows: h (a) = aa h (b) = cb.
Costas Busch - RPI1 Turing Machines. Costas Busch - RPI2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Turing Machines CS 105: Introduction to Computer Science.
Chapter 9 Turing Machine (TMs).
Binary Conversion In today’s lesson we will link together the binary and algorithm topics by looking at how to get the computer to: convert binary to decimal.
Section 11.4 Language Classes Based On Randomization
1 Homework Turn in HW2 tonight HW3 is on-line already Questions?
CSCI 2670 Introduction to Theory of Computing September 28, 2005.
Lecture Pushdown Automata. stack stack head finite control tape head tape.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Turing.
THE CHURCH-TURING T H E S I S “ TURING MACHINES” Part 1 – Pages COMPUTABILITY THEORY.
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
Turing Machine. Turing machine The mathematical models (FAs, TGs, PDAs) that have been discussed so far can decide whether a string is accepted or not.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Undecidable.
1 Turing machines Chapter 4, Smith and Kimber. A Turing machine is an abstraction of a human “computer”. Consists of - control, in the form of states -
CS 3240: Languages and Computation
1 Section 13.1 Turing Machines A Turing machine (TM) is a simple computer that has an infinite amount of storage in the form of cells on an infinite tape.
1 Turing Machines and Equivalent Models Section 13.1 Turing Machines.
CSCI 3130: Formal languages and automata theory Tutorial 7 Chin.
1 Introduction to Turing Machines
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 12 Mälardalen University 2007.
1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Turing Machines. The next level of Machine… PDAs improved on FSAs by adding memory. We make the memory more flexible to do more complicated tasks.
Turing Machines – Examples Lecture 24 Section 3.1 Wed, Oct 17, 2007.
Turing Theory. Turing Machine A Turing Machine denoted by TM, is a collection of six things. –An alphabet  of input letters –A TAPE divided into a sequence.
1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
CSCI 2670 Introduction to Theory of Computing September 29, 2005.
Theory of Computation Automata Theory Dr. Ayman Srour.
TM Macro Language MA/CSSE 474 Theory of Computation.
Finite Automata.
Lecture # 21.
Computer Number Systems
Complexity & the O-Notation
Time complexity Here we will consider elements of computational complexity theory – an investigation of the time (or other resources) required for solving.
Busch Complexity Lectures: Turing Machines
Finite Automata.
Pushdown Automata.
Deterministic Finite Automata
Undecidable problems for CFGs
Undecidable problems for CFGs
Cpt S 317: Spring 2009 Reading: Chapter 8
COSC 3340: Introduction to Theory of Computation
Turing Machines 2nd 2017 Lecture 9.
Chapter 9 TURING MACHINES.
Turing Machines Sipser pages
COSC 3340: Introduction to Theory of Computation
Deterministic Finite Automata
Theory of Computation Turing Machines.
Computing Functions with Turing Machines
MA/CSSE 474 Theory of Computation
Recall last lecture and Nondeterministic TMs
Recap lecture 44 Decidability, whether a CFG generates certain string (emptiness), examples, whether a nonterminal is used in the derivation of some word.
The Church-Turing Thesis
CS 461 – Nov. 14 Section 5.2 – Undecidable problems starting from ATM:
Teori Bahasa dan Automata Lecture 10: Push Down Automata
Variants of Turing machines
DSPACE Slides By: Alexander Eskin, Ilya Berdichevsky
Factors, Prime Numbers & Composite Numbers, Prime Factorization
Languages Fall 2018.
Presentation transcript:

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

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

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.

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.

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 1..1. If so, accept the string; otherwise, reject it. string counter

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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