[英]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 = 3
和Y = 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.我们可以假设
X
和Y
具有相同的位长度。
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)
表示X
第i 位是x
, Y
第i 位是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}
是无效的,因为第i个位X
如果存在第i个位是已知的Y
是已知的。 The algorithm goes something like this:算法是这样的:
M
is Q(UU0)
. M
的初始状态是Q(UU0)
。X
and Y
are being added and the carry is c
.X
和Y
第i 位被添加并且进位是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
大于X
和Y
的位数,则转到步骤 (6)。 Since the least significant input bits are overwritten in steps (3) and (4), this condition is easy to detect.x
of X
, overwrite x
with $
and transition to state Q(xUc)
.X
的最低有效位x
,用$
覆盖x
并转换到状态Q(xUc)
。y
of Y
, overwrite y
with *
and transition to state Q(xyc)
.Y
的最低有效位y
,用*
覆盖y
并转换到状态Q(xyc)
。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.c = 1
, write c
at the end of the tape.c = 1
,写c
在带的端部。 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.