[Math] Design a Turing machine which computes the sum of two numbers in base $2$

automataturing-machines

Question:

Design a Turing machine which computes the sum of two numbers in base $2$. For example, If the input is $110×1$, The machine should return $000×111$ (which means: $6+1=7$)


My try:

At each iteration, decrease the first number by $1$, and increase the second one by $1$. Repeat this until the first number becomes $0$. (I know how to increase and decrease a number in base $2$ using a Turing machine)


Problem:

(I) I don't know what to do if the input is like $111×001$. My algorithm is not general enough to solve this one too.
(II) It seems like the numbers should have the same number of digits. But I'm not sure of that. Can we design the machine without presuming this condition?

Best Answer

assuming input a#(1)b convert to a#(1)b#(2)c#(3)BLANK

Blank will be filled with sum. Make 2 cases for LSB of 'a'. Further divide 2 cases for LSB of 'b'. 'c' is the carry bit that is initially 0. Make seperate 2 cases for each of the four cases and update the carry bit on the way. Path is chosen based on if 'c' was 0 or 1.

Picture shows a rough sketch.

enter image description here

Final result will be reversed value of original sum. You reverse this again. Take the pic with a grain of salt. It is just a rough sketch. Nomenclature is not followed.

Related Question