[英]turing machine design 0 and 1
f1(1^n01^m) = 1^|m−n| f1(1 ^ n01 ^ m)= 1 ^ | mn |
design a turing machine that computes the function (transition diagram) 设计可计算功能的图灵机(转换图)
how to keep track of the 0 in the middle? 如何跟踪中间的0? I have tried to do it but can not figure it out 我已经尝试过但无法解决
I'll assume you want the tape alphabet to consist only of 0, 1 and - (blank). 我假设您希望磁带字母仅包含0、1和-(空白)。 Our strategy here is a fruitful one when working with single-tape Turing machines: we will bounce back and forth around the 0 in the middle, crossing off 1s as we find them. 在使用单带图灵机时,我们的策略是富有成效的策略:我们将在中间的0左右来回弹跳,找到它们就越过1。 We will continue until we run out of 1
s and reach a blank. 我们将继续操作,直到用完1
秒并达到空白。 At that point, all that remains on the tape is 1^|mn| 此时,磁带上剩余的全部为1 ^ | mn |。 as well as n+m+1-|mn| 以及n + m + 1- | mn | zeroes. 零。 Finally, we copy our result to the beginning of the tape (if that's not where it already is, ie, if m > n) and erase the zeroes. 最后,我们将结果复制到磁带的开头(如果尚未到达该位置,即m> n),然后擦除零。
Q s s' D Q'
// read past 1^n
q0 1 1 R q0
// read through zeroes
q0 0 0 R q1
q1 0 0 R q1
// mark out the first 1 remaining in 1^m
q1 1 0 L q2
// read through zeros backwards
q2 0 0 L q2
// mark out the last 1 remaining in 1^n
q2 1 0 R q1
// we were reading through zeroes forward
// and didn't find another 1. n >= m and
// we have deleted the same number from
// the first and last parts so just delete
// zeroes
q1 - - L q3
q3 0 - L q3
q3 1 1 L halt_accept
// we were reading through zeroes backwards
// and didn't find another 1. n < m and we
// accidentally deleted one too many symbols
// from the 1^m part. write it back and start
// copying the 1s from after the 0s back to
// the beginning of the tape. then, clear zeroes.
q2 - - R q4
q4 0 1 R q5
q5 0 0 R q5
q5 1 0 L q6
q6 0 0 L q6
q6 1 1 R q4
q5 - - L q7
q7 0 - L q7
q7 1 1 L halt_accept
Naturally, no TM example would be complete without an example of its execution. 自然,没有TM示例的执行就不会完整。
-111110111- => -111110111- => -111110111-
^ ^ ^
q0 q0 q0
=> -111110111- => -111110111- => -111110111-
^ ^ ^
q0 q0 q0
=> -111110111- => -111110011- => -111110011-
^ ^ ^
q1 q2 q2
=> -111100011- => -111100011- => -111100011-
^ ^ ^
q1 q1 q1
=> -111100001- => -111100001- => -111100001-
^ ^ ^
q2 q2 q2
=> -111100001- => -111000001- => -111000001-
^ ^ ^
q1 q1 q1
=> -111000001- => -111000001- => -111000001-
^ ^ ^
q1 q1 q1
=> -111000000- => -111000000- => -111000000-
^ ^ ^
q2 q2 q2
=> -111000000- => -111000000- => -111000000-
^ ^ ^
q2 q2 q2
=> -110000000- => -110000000- => -110000000-
^ ^ ^
q1 q1 q1
=> -110000000- => -110000000- => -110000000-
^ ^ ^
q1 q1 q1
=> -110000000- => -110000000- => -11000000--
^ ^ ^
q1 q3 q3
=> -1100000--- => -110000---- => -11000-----
^ ^ ^
q1 q3 q3
=> -1100------ => -110------- => -11--------
^ ^ ^
q1 q3 q3
=> -11--------
^
halt_accept
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.