简体   繁体   English

图灵机计算2个二进制数之和

[英]Turing machine to calculate sum of 2 binary numbers

How can I build a Turing machine to calculate the sum of 2 binaries numbers given X$Y* for input?如何构建图灵机来计算给定X$Y*输入的 2 个二进制数的总和?

For example, suppose X = 3 and Y = 5 .例如,假设X = 3Y = 5 The input for the machine will be #011$101*# .机器的输入将是#011$101*# The state in the end should be #1000# .最后的状态应该是#1000#

We can assume X and Y have the same length of bits.我们可以假设XY具有相同的位长度。

You need to implement a full adder .您需要实现一个全加器 This question is probably homework, so I will provide a high-level overview.这个问题可能是家庭作业,所以我将提供一个高层次的概述。 The Turing machine M has special states Q(xyc) where x,y ∈ {0,1,U} and c ∈ {0,1} .图灵机M具有特殊状态Q(xyc) ,其中x,y ∈ {0,1,U}c ∈ {0,1} The state Q(xyc) means that the i th bit of X is x , the i th bit of Y is y and the carry is c .状态Q(xyc)表示Xi 位是xYi 位是y并且进位是c The symbol U means that the i th bit of the relevant inputs are unknown.符号U表示相关输入的i 位未知。 The states Q(Uyc) where y ∈ {0,1} are invalid because the i th bit of X is known if the i th bit of Y is known.状态Q(Uyc)其中y ∈ {0,1}是无效的,因为iX如果存在i位是已知的Y是已知的。 The algorithm goes something like this:算法是这样的:

  1. The initial state of M is Q(UU0) . M的初始状态是Q(UU0)
  2. Suppose the i th bits of X and Y are being added and the carry is c .假设XYi 位被添加并且进位是c Then M is in state Q(UUc) .然后M处于状态Q(UUc) If i is greater than the number of bits in X and Y , goto step (6).如果i大于XY的位数,则转到步骤 (6)。 Since the least significant input bits are overwritten in steps (3) and (4), this condition is easy to detect.由于最低有效输入位在步骤 (3) 和 (4) 中被覆盖,因此这种情况很容易检测到。
  3. Find the least significant bit x of X , overwrite x with $ and transition to state Q(xUc) .找到X的最低有效位x ,用$覆盖x并转换到状态Q(xUc)
  4. Find the least significant bit y of Y , overwrite y with * and transition to state Q(xyc) .找到Y的最低有效位y ,用*覆盖y并转换到状态Q(xyc)
  5. Write the appropriate sum at the end of the tape, transition to state Q(UUd) where d is the new carry, and goto step (2).在磁带的末尾写入适当的和,转换到状态Q(UUd) ,其中d是新进位,然后转到步骤 (2)。 These values are given by the truth table in the above link.这些值由上述链接中的真值表给出。
  6. If c = 1 , write c at the end of the tape.如果c = 1 ,写c在带的端部。
  7. Copy the reverse of the computed value to the beginning of the tape.将计算值的反向复制到磁带的开头。 Clear the remaining tape.清除剩余的胶带。

Note that the output is constructed in reverse order, and thus must be reversed in step (7).请注意,输出是以相反的顺序构造的,因此必须在步骤 (7) 中颠倒。 The remaining work consists of writing states and transitions for traversing/manipulating the tape.剩余的工作包括写入状态和用于遍历/操作磁带的转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM