π Lecture 45 β Theory of Automata
π Overview: This lecture introduces the Turing machine (TM), a more powerful computational model capable of accepting non-context-free languages like (a^n b^n a^n) alongside regular languages. It also covers practical TM subprograms for inserting and deleting characters on the tape, which are essential for manipulating string data in computations.
ποΈ Topics Covered
This lecture covers the definition and components of a Turing machine, including its infinite tape, tape head, alphabet, states, and program rules. It provides examples of TMs for regular languages like EVEN-EVEN and non-CFLs like (a^n b^n a^n). The lecture then details the INSERT subprogram for adding a character at the tape headβs location, shifting the rest right, and the DELETE subprogram for removing a character and shifting the rest left.
π Lecture Summary
Turing machine
The mathematical models (FAs, TGs, PDAs) that have been discussed so far can decide whether a string is accepted or not by them i.e. these models are language identifiers. However, there are still some languages which canβt be accepted by them e.g. there does not exist any FA or TG or PDA accepting any non-CFLs. Alan Mathison Turing developed the machines called Turing machines, which accept some non-CFLs as well, in addition to CFLs.
π Definition β Turing machine (TM): consists of the following: An alphabet Ξ£ of input letters. An input TAPE partitioned into cells, having infinite many locations in one direction. The input string is placed on the TAPE starting its first letter on the cell i, the rest of the TAPE is initially filled with blanks (Ξβs). A tape Head can read the contents of cell on the TAPE in one step. It can replace the character at any cell and can reposition itself to the next cell to the right or to the left of that it has just read. Initially the TAPE Head is at the cell i. The TAPE Head canβt move to the left of cell i. An alphabet Ξ of characters that can be printed on the TAPE by the TAPE Head. Ξ may include the letters of Ξ£. Even the TAPE Head can print blank Ξ, which means to erase some character from the TAPE. Finite set of states containing exactly one START state and some (maybe none) HALT states that cause execution to terminate when the HALT states are entered. A program which is the set of rules, which show that which state is to be entered when a letter is read from the TAPE and what character is to be printed. This program is shown by the states connected by directed edges labeled by triplet (letter, letter, direction). The first letter is the character the TAPE Head reads from the cell to which it is pointing. The second letter is what the TAPE Head prints the cell before it leaves. The direction tells the TAPE Head whether to move one cell to the right, R, or one cell to the left, L.
Note: There may not be any outgoing edge at certain state for certain letter to be read from the TAPE, which creates nondeterminism in Turing machines. The machine crashes if there is not path for a letter to be read from the TAPE and the corresponding string is supposed to be rejected. To terminate execution of certain input string successfully, a HALT state must be entered and the corresponding string is supposed to be accepted by the TM. The machine also crashes when the TAPE Head is instructed to move one cell to the left of cell i.
π Definition β acceptance by TM: The string is accepted if the TM enters a HALT state during its execution.
π Formula β TM transition: (read, print, direction) β meaning: if the tape head reads a specific character, print another character, then move one cell R (right) or L (left).
π Example: Consider the following Turing machine program. START state 1 has edges: (a,a,R) β state 2, (b,b,R) β state 3. State 2 has: (a,a,R) β state 2, (b,b,R) β state 3, (Ξ,Ξ,R) β HALT state 4. State 3 has: (a,a,R) β state 3, (b,b,R) β state 2. Let the input string aba be run over this TM. Starting from START state, reading 'a' β print 'a', move right β state 2. At state 2, reading 'b' β print 'b', move right β state 3. At state 3, reading 'a' β print 'a', stay in state 3. Then reading blank 'Ξ' β print 'Ξ', move right β HALT state. This shows that the string aba is accepted by this machine. The machine accepts the language expressed by (a+b)b(a+b)*.
Theorem
Every regular language is accepted by some TM.
π Example: Consider the EVEN-EVEN language. A TM accepting the EVEN-EVEN language is given, and its diagram is similar to that of FA corresponding to EVEN-EVEN language. Following is another example. Consider the following TM: START state 1 has (a,a,R) β state 2, (b,b,R) β state 3. State 2 has (a,a,R) β state 2, (b,b,R) β state 3, (Ξ,Ξ,R) β state 4. State 3 has (a,a,R) β state 3, (b,b,R) β state 2, (Ξ,Ξ,R) β state 4. State 4 has (a,a,R) β state 4, (b,b,R) β state 4, (Ξ,Ξ,R) β HALT state 5. The string aaabbbaaa can be observed to be accepted by the above TM. It can also be observed that the above TM accepts the non-CFL (a^n b^n a^n).
INSERT subprogram
Sometimes, a character is required to be inserted on the TAPE exactly at the spot where the TAPE Head is pointing, so that the character occupies the required cell and the other characters on the TAPE are moved one cell right. The characters to the left of the pointed cell are also required to remain as such. The subprogram of insertion is independent and can be incorporated at any time with any TM program specifying what character to be inserted at what location.
π Example: If the letter b is to be inserted at the cell where the TAPE Head is pointing as shown: Tape: b X a b b X Ξ Ξ. The tape head is at the cell containing 'a'. After insertion of b, the tape becomes: b X b a b b X Ξ Ξ. The function of subprogram INSERT b uses a marker Q placed temporarily. The algorithm: 1) At state 1, read the character at insertion point (e.g., 'a' or 'b' or 'X'). 2) Replace it with Q and move right, entering a state that remembers the displaced character (e.g., state 2 for 'a'). 3) Continue shifting each subsequent character one step right, remembering the displaced character from the previous cell, until a blank Ξ is reached. 4) Replace the blank with the last displaced character. 5) Then move left, replacing 'Q' with the original inserted character ('b'), and move right one step.
π Definition β INSERT subprogram: A TM subroutine that places a new character at the tape head's current cell, shifting all characters to the right by one cell.
DELETE subprogram
Sometimes, a character is required to be DELETED on the TAPE exactly at the spot where the TAPE Head is pointing, so that the other characters on the right of the TAPE Head are moved one cell left. The characters to the left of the pointed cell are also required to remain as such. The subprogram of deletion is independent and can be incorporated at any time with any TM program specifying what character to be deleted at what location.
π Example: If the letter a is to be deleted from the string bcabbc, shown below: Tape: b c a b b c Ξ Ξ. The tape head is at the cell containing 'a'. After deletion, the tape becomes: b c b b c Ξ Ξ. The function of subprogram DELETE uses a marker X placed temporarily. The algorithm: 1) At state 1, read the character to be deleted (e.g., 'a') β replace it with Ξ (blank) and move right. 2) Enter state 2 and continue moving right, shifting each character one step left (replacing the current cell's content with the next cell's content) until a blank Ξ is reached. 3) When blank is read, move left to the cell before the blank. 4) Then, in state 3, continue moving left, replacing the blank in the final cell (the duplicate) with the appropriate character from the preceding cell, until the start of the deletion area is reached. 5) At the final step, replace 'X' (the marker) with the character that was shifted into its position.
π Definition β DELETE subprogram: A TM subroutine that removes the character at the tape head's current cell, shifting all characters to the right by one cell to the left.
π‘ Why this matters: The INSERT and DELETE subprograms demonstrate a fundamental capability of Turing machines: in-place string editing. This is analogous to how computers manipulate text or data structures, illustrating that TMs are a model for general computation, not just language recognition.
β Key Takeaways
The Turing machine is a more powerful computational model than FAs or PDAs because it can accept non-context-free languages like (a^n b^n a^n), in addition to all regular languages. Understanding the TM's structureβan infinite tape, a read/write head, and a set of transition rulesβis crucial, along with the concepts of acceptance via HALT states and rejection via crashes. The INSERT and DELETE subprograms are essential techniques for manipulating tape contents, allowing the TM to perform arbitrary data processing tasks. These subprograms are independent modules that can be reused in larger TM programs for string editing operations.
π§ Quick Revision Questions
- What are the key components of a Turing machine?
- How does a Turing machine accept or reject an input string?
- Can you draw the TM for the language (a^n b^n a^n)?
- Describe the step-by-step process of the INSERT subprogram when a character is to be inserted into a non-empty tape.
- Explain what happens to the tape contents when the DELETE subprogram is executed to remove a character.