asked 132k views
1 vote
Construct a deterministic Turing machine M that, given as input a binary string w, computes the remainder of w modulo 4. M starts with the initial configuration and halts with the configuration. It is assumed that the input, w, is a valid nonnegative number in base 2, that is, w ∈ {0} ∪ 1{0, 1} Here are some examples of M's behaviour: (s, 00) FM (h,00); (s, 01011) FM (h, 011); (s, 0101) FM (h, 01). Describe M using the macro language

asked
User Esse
by
8.3k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

To compute the remainder of w modulo 4, we need to keep track of the value of w modulo 4 as we scan through the binary digits from left to right. We can do this using a state machine with four states, one for each possible remainder value: state 0 for remainder 0, state 1 for remainder 1, state 2 for remainder 2, and state 3 for remainder 3. We also need to shift the binary digits of w to the right as we scan them, so we use a special symbol "#" to represent the least significant bit of w, which is discarded when we shift the digits to the right.

Here is a description of the deterministic Turing machine M that computes the remainder of w modulo 4 using the macro language:

Define the alphabet

Alph = {0, 1, #}

Define the states

States = {s0, s1, s2, s3, h}

Define the transitions

Transitions = {

(s0, 0) -> (s0, 0, R), # Remainder is still 0

(s0, 1) -> (s1, 1, R), # Remainder becomes 1

(s1, 0) -> (s2, 0, R), # Remainder becomes 2

(s1, 1) -> (s0, 1, R), # Remainder becomes 0

(s2, 0) -> (s1, 0, R), # Remainder becomes 1

(s2, 1) -> (s3, 1, R), # Remainder becomes 3

(s3, 0) -> (s0, 0, R), # Remainder becomes 0

(s3, 1) -> (s2, 1, R), # Remainder becomes 2

(s0, #) -> (h, #, N) # Halt and output the remainder

}

Define the initial configuration

Init = (s0, #) # Start in state s0 with "#" as the first digit

Define the final configurations

Final = {(h, 0), (h, 1), (h, 2), (h, 3)} # Halt when remainder is found

Define the machine

M = (Alph, States, Transitions, Init, Final)

In this machine, the symbols 0, 1, and # represent the binary digits 0, 1, and the least significant bit of w, respectively. The machine starts in state s0 with "#" as the first symbol of the input. It then transitions through the states according to the rules in the Transitions set, updating the remainder value as it goes. When it reaches the end of the input, it halts in state h and outputs the current remainder value.

answered
User Nima K
by
7.7k points