简体   繁体   English

如何正式描述用于图灵机的算法?

[英]how to formally described this algorithm for turing machine?

Waring : This task was given by my professor who is 80 y/o and nobody understands what he sometimes wants, I do not expect more less standard approach to this problem, not just because the problem is difficult, but because my professor is old-school ex-ussr crazy guy ;) (he likes to make easy things complicated, just to explain why this is posted here) 警告 :这项任务是由我的教授完成的,他是80岁,而没人理解他有时想要的东西,我不希望对这个问题有更多的标准方法,不仅是因为这个问题很困难,而且因为我的教授很老,学校前苏联疯狂的家伙;)(他喜欢使简单的事情变得复杂,只是为了解释为什么将其发布在这里)

This task is pure theory one, but I do not know how to formalize it with words Problem: 该任务是纯粹的理论任务,但我不知道如何用单词“问题”来形式化它:

9 bits binary code is given on input, we have to print "0" in output if amount of bits with value "1" are two times less than amount of bits with value "0", if this condition is false that we have to print "1" in output. 输入上给出了9位二进制代码,如果值为“ 1”的位数比值为“ 0”的位数少两倍,则必须在输出中打印“ 0”,如果此条件为假,则必须在输出中打印“ 1”。

What I proposed in my description is to introduce a counter, and then count bits that have value 1, then make an output based on this counter, but I was claimed to be an idiot and I was told that there's the way without the counter and I choose the hardest way. 我在描述中建议的是先引入一个计数器,然后对具有值1的位进行计数,然后根据该计数器进行输出,但是我被称为白痴,并且被告知没有计数器和我选择最困难的方式。 Does someone know the better way to determine what to output? 有人知道确定输出什么的更好方法吗?

Thanks in advance, and sorry if description looks messy 在此先感谢您,如果描述看起来很混乱,请多谢

As the TM reads the input bits, the state number must capture the number of bits seen, from 0 through to 9, so that we can recognize when we get to the end, and the number of 1 bits seen, with the relevant cases being 0, 1, 2, 3, and >=4. 当TM读取输入位时,状态号必须捕获从0到9的可见位数,以便我们可以识别到结束的时间以及看到的1位数,相关情况是0、1、2、3和> = 4。

There are less than 10*5=50 states required to encode all the relevant possibilities. 编码所有相关可能性所需的状态少于10 * 5 = 50。 When the machine enters one of the states indicating that 9 input bits have been seen, it writes a 0 if it indicates that 3 1s have been seen, or 1 otherwise, then stops. 当机器进入指示已经看到9个输入位的状态之一时,如果它指示已经看到3个1,则写入0,否则,写入1。

Note that we didn't need to use the tape for storage -- the input language is regular so it can be decided with a finite state machine and unbounded storage is unnecessary. 请注意,我们不需要使用磁带进行存储-输入语言是常规的,因此可以使用有限状态机确定它,并且无限制存储是不必要的。

While Matt is correct, you can generalize this problem to arbitrary input sizes using storage. 尽管Matt是正确的,但您可以使用存储将这个问题推广到任意输入大小。

  1. Go to the beginning of the tape 转到磁带的开头
  2. Move forward looking for an unmarked 1 . 前进寻找没有标记的1 Mark it. 标记它。
    • If you can't find an unmarked 1 , go to step 7. 如果找不到未标记的1 ,请转到步骤7。
  3. Go back to the beginning of the tape 回到磁带的开头
  4. Look for an unmarked 0 . 寻找未标记的0 Mark it. 标记它。
    • If you can't find an unmarked 0 , go to step 9. 如果找不到未标记的0 ,请转到步骤9。
  5. Look for another unmarked 0 . 寻找另一个未标记的0 Mark it. 标记它。
    • If you can't find an unmarked 0 , go to step 9. 如果找不到未标记的0 ,请转到步骤9。
  6. Go to step 1 转到步骤1
  7. Go to the beginning of your input. 转到输入的开头。
  8. Look for an unmarked 0 . 寻找未标记的0
    • If you don't find one, output 0 . 如果找不到,则输出0 Halt. 停。
  9. Output 1 . 输出1 Halt. 停。

This will work for any input size. 这适用于任何输入大小。 Intuitively, we're looking for 2 0 s for every 1 in the input, making sure there are twice as many 0 bits as 1 bits. 直观地,我们正在寻找输入中每1 2 0 s,请确保0位是1位的两倍。

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

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