I could only make out that the logic must have included the logic of multiplication and division in Turing machines . But actually I cannot make out the exact solution.
Asked
Active
Viewed 5,850 times
1 Answers
2
Well, if just any old TM will do, this one is easy to understand.
- input tape is #(n)#
- use a TM to write this to the tape: #(n):(2):(n)#
- use a TM to subtract whatever is in between the : from the thing after both : over and over until either (1) you have too few symbols to remove (not divisible) or (2) there are exactly zero symbols left (evenly divisible). In case of (1) continue, otherwise - in case of (2) - halt-reject as not prime.
- use a TM to write this to the tape: #(n):(m+1):(n)#
- use a TM to check wither the thing before the first : is greater than the thing in between the two :. If so, continue with step 3. Otherwise, halt-accept (since the original input cannot be divisible by a number greater than itself)
Take all the TMs described and construct a single TM that incorporates all that behavior in various states. This is a TM for the language of prime numbers.
Assuming a unary encoding (that is, the natural number n is represented by the string 11...1 where 1 is repeated n times), here's some more pointers on making the individual TMs:
- original input
- go to the first blank after the input and write a :. Then, go to the right and write 1. Then, go to the right and write another 1. Then go to the right and write another :. Then, bounce back and forth from the beginning to the first blank at the end, copying the input natural number's unary digits. To do this, update the input digits to some other symbol, like A, so you remember ones you already copied. Stop this process when there is an A immediately to the left of the first :. Then, set all the A back to 1.
- bouncing back and forth, remove a 1 from the rightmost section for each 1 in the innermost section, updating the innermost section to use A to mark them. Once everything in the innermost section is marked, set them back to 1, and repeat the process until you run out of 1s in the rightmost section .
- erase the second : and everything after it; then write a 1 at the end, then a :, and do what the TM described in 2 does.
- bounce back and forth between the leftmost and innermost sections, marking in each one as you go. If you run out of symbols in the innermost section first, the number is less than the input number; if you run out at the same time, the numbers are the same, meaning that the input number is first divisible by itself, so it's prime.

Patrick87
- 27,682
- 3
- 38
- 73