CS 454, Section 001 Sonoma State University Spring, 2024
 
Theory of Computation
Instructor: Henry M. Walker

Lecturer, Sonoma State University
Professor Emeritus of Computer Science and Mathematics, Grinnell College

Although much of this course has been well developed in recent semesters, the SSU CS faculty recently have approved an updated course description. Also, the required SSU Signature Project for SSU's Upper Division GE Area B Requirement for CS Majors has been rethought for this course. Currently, the Web site is reasonably stable, but modest refinements are likely. Check these pages regularly for adjustments.


Contract Negotiations Have Yielded a Tentative Agreement

Since May, 2024, the California Faculty Association (CFA) – the labor union of professors, lecturers, librarians, counselors, and coaches across the 23 California State University campuses – has been in negotiations with the management of the California State University System. After a one-day strike on Monday, January 22, the two sides have reached a tentative agreement, and the strike has been called off. Effective Tuesday, January 23, SSU classes (including CS 454) will be held as scheduled.

Assignment on Turing Machines and Algorithms

  1. Shifting a String Right: Consider the problem of shifting a string on a tape right by one character, placing a space or blank at the original first position.

    One solution of this problem, apparently by Bhanu Priya on Tutorials Point, presents a Turing machine to solve this problem over the alphabet Σ = {0,1} by moving to the right end of the string and then moving backward—shifting each character one position to the right.

    1. In reviewing the operation of this Turing machine from Tutorials Point,

      • When the Turing machine first moves right, how does it detect the right end of the string? That is, what state is the Turing machine in, and what symbol is read?
      • In working right to left, how does the Turning machine from Tutorials Point know when to stop shifting elements to the right? That is, how does processing know when the first character is shifted, so the entire shift has been completed?
    2. The given solution works with strings of binary numbers and requires 6 states for the Turing machine. Suppose the problem were expanded to include strings of decimal numbers.

      How would the Tutorials Point Turing machine need to be changed to include decimal integers? That is,

      • What symbols would need to be allowed on the tape (both the input and tape alphabets)?
      • How many states would be needed for the revised Turing machine, and what would each state represent?

      In each case, justify your answer.

      Note In this part you are NOT asked to write out the full, revised Turing machine. Rather, you need to explain what each state represents, and describe how processing would proceed.

    3. The given Turing machine over the alphabet Σ = {0, 1} first moves to the right end of the string and then works backward, moving each character one position at a time. Can this problem be solved (for binary numbers) with a single pass from left to right?

      • If so, write a formal description of the Turing machine, including its transition function.
      • If not, explain why such a Turing machine cannot be created without first moving to the right end of the string.
  1. Adding 1 in binary: This problem considers algorithms implemented on a Turning Macine, that are supposed to add 1 to a non-negative binary integer. More precisely, at the start of processing, a non-negative binary integer is to appear at the start of an input tape, and at the end of processing, the incremented positive binary integer should appear at the start of the tape. At the end of processing, no other non-blank systems should be present on the tape.

    As might be expected, many such algorithms are discussed on the Web.

    Before proceeding, some notes are needed regarding how the tape of a Turing machine works.

    • Turning machines traditionally have an infinite tape that starts at a given cell and continues without limit to the right. No characters can appear before the starting point of the tape (except possibly in one position as noted below).
    • At the start of processing, Turing machines are set to process the first character on the string (that is, the left-most character in the string).
    • During processing, a Turing machine reads a character, does whatever is specified internally, overwrites the input character, and moves the read/write head one character left or right.
    • But what happens if the Turing machine is processing the left-most character, and the internal program indicates the read/write head should move left?
      1. Sipser's book provides a common specification: "If [Turing Machine] M ever tries to move its head to the left of the left-hand end of the tape, the head stays in the same place for the move, even though the transition function indicates L. The computation continues until M enters either the accept or reject states at which point M halts. If neither occurs, M goes on forever." In this case, moving left (beyond the left edge of the tape) does not generate any signal or interrupt regarding the end of the tape; rather, the read/write head stays at the beginning of the tape, and processing can continue—possibly indefinitely.
      2. To address this situation, some Turing machine environments specify that all input strings must start with a special symbol (e.g., $). This symbol cannot be used in another context and, as a marker, the symbol cannot be overwritten. However, in processing, if the Turing machine reads the special symbol, it serves to signal that processing has gone too far to the left; subsequent processing cannot move further to the left, but the Turing machine could take any needed action.
      3. In some other Turing machine environments, trying to read to the left of the tape may cause the next symbol read to be special (e.g., $), even though this symbol is not written explicitly on the tape.

      Now consider three proposed algorithms to solve the problem of adding 1 to a non-negative binary integer.

      1. One algorithm is given by the Turning machine described in Tutorial Point. Does this algorithm provide a correct solution to the problem of adding 1 to a non-negative binary integer, according to any of the approaches given above for processing at the left-end of a tape? Explain—if the solution is correct, write a careful justification that applies in all cases. Alternatively, if there is an issue, explain the difficulty.
      2. A second approach to this problem is given on YouTube. Does this implementation correctly solve the problem? As with Part a, justify your answer.
      3. Restricting your attention to the specification of start-of-tape processing as given in Sipser's text, modified as in approach ii that uses a special symbol ($) to mark the start of the tape. write a complete specification of a Turing machine that adds 1 to a non-negative binary integer. (Of course, your answer should work for all possible non-negative binary integers.) Feel free to draw upon any or all parts a or b, if that seems helpful (but cite whatever pieces you utilize).

Notes on Binary Integers

Within computers, numbers are represented in a binary format—that is, numbers are notated with just two symbols: 0 and 1. For this exercise, only non-negative numbers are considered. For those unfamiliar or uncomfortable with non-negative binary integers, many references are available on the Web, including the following:


  1. Analyze a Given Turing Machine: Consider a Turing machine with an input of non-negative decimal integers. That is, the input alphabet is Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} and uses the following transition function. (In this table, "sp" represent a space or blank character. Also, * is a tape symbol that is not in the input alphabet.)

    Input Character
    Notes state 012 345 6789*sp (for space or blank)
    start q0 q3, *, R q1, *, R q2, *, R q3, *, R q1, *, R q2, *, R q3, *, R q1, *, R q2, *, R q3, *, R q7, 0, R q7, 0, R
    q1 q1, 1, R q2, 2, R q3, 3, R q1, 1, R q2, 2, R q3, 3, R q1, 1, R q2, 2, R q3, 3, R q1, 1, R q7, 1, R q4, sp, L
    q2 q2, 2, R q3, 3, R q1, 1, R q2, 2, R q3, 3, R q1, 1, R q2, 2, R q3, 3, R q1, 1, R q2, 2, R q7, 2, R q5, sp, L
    q3 q3, 3, R q1, 1, R q2, 2, R q3, 3, R q1, 1, R q2, 2, R q3, 3, R q1, 1, R q2, 2, R q3, 3, R q7, 3, R q6, sp, L
    q4 q4, sp, L q4, sp, L q4, sp, L q4, sp, L q4, sp, L q4, sp, L q4, sp, L q4, sp, L q4, sp, L q4, sp, L q7, 1, R q7, sp, R
    q5 q5, sp, L q5, sp, L q5, sp, L q5, sp, L q5, sp, L q5, sp, L q5, sp, L q5, sp, L q5, sp, L q5, sp, L q7, 2, R q7, sp, R
    q6 q6, sp, L q6, sp, L q6, sp, L q6, sp, L q6, sp, L q6, sp, L q6, sp, L q6, sp, L q6, sp, L q6, sp, L q7, 0, R q7, sp, R
    accept q7 accept

    For this Turing machine, assume all inputs are valid non-negative decimal integers (e.g., without embedded spaces and without non-digit characters).

    1. Trace the processing of this Turing machine with inputs 13, 24, and 135. In each case, what output is generated?
    2. State as an English statement what numerical computation this Turing machine computes. (Although you are welcome to approach this problem any way you wish, one approach might be to look at the output for inputs 0, 1, 2, 3, . . . up to some manageable number, and look for a pattern.)
    3. From a design perspective, what is the purpose or function of state q0?
    4. What is the purpose or function of the states q1, q2, and q2?
    5. Are there any states, for which the input * will never be encountered? If so, what states are these, and why do you think these cells are included in the table?
    6. What intermediate result(s) are maintained by states q4, q5, and q6?
    created Fall, 2023
    revised Fall, 2023
    Valid HTML 4.01! Valid CSS!
    For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.