构造一个图灵机来决定 ww^Rw

发布于 2024-12-07 10:49:32 字数 91 浏览 2 评论 0原文

w^R 是 w 的逆,w 是 {0, 1}* 。因此,TM 需要决定一个单词,然后是该单词的反义词,然后是该单词。 我不想要答案,我只想要一个开始并走上正确轨道的线索。

w^R is the reverse of w and w is {0, 1}* . So the TM needs to decide a word followed by the reverse of this word followed by the word.
I don't want the answer, I just want a lead to start and to get on the right track.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

栖迟 2024-12-14 10:49:32

由于一段时间过去了,可能不再需要答案,我想我会提出一个解决方案,以方便未来寻找图灵机如何识别一种语言的示例的学生。

这是我的想法。我们将采用磁带字母表 {0, 1, a, b, c, d} 并制作一个识别 ww^R w 的单磁带单无限磁带图灵机。该机器将分五个阶段工作:

  1. 将前缀 ww^R 中的 0 和 1 替换为 a 和 b。
  2. 看看 ww^R 是否是回文。
  3. 将磁带恢复到原始状态。
  4. 将后缀 w^R w 中的 0 和 1 替换为 c 和 d。
  5. 看看 w^R 是否是回文。

请注意,这只是一种简单的(对我来说是可以理解的)方法来表明存在图灵机来识别这种语言。当然,证明在任何图灵等效计算系统中存在一种算法来解决这个问题也同样好(它证明了存在一个TM)......不过,这概述了一个这样的TM的构造。另请注意,可能有一个更简单、更高效或更直观的 TM 来解决这个问题……再次强调,这只是一种方法。

第 1 步的工作原理如下:

  • 前提条件:磁带以空白开头,包含 (0+1)* 中的任何字符串,后面是无限的空白方块串。
  • 后置条件:如果磁带为空或长度不是 3 的倍数,则停止;否则,磁带以空白开始,后面是 (a+b)^2n (c+d)^n,最后是无限的空白字符串。

    1. 向右移动。
    2. 如果为空,则停止接受。否则,向右扫描,直到找到一个空的胶带方块,然后向左移动。
    3. 如果为 0,则将磁带更改为 c;如果为 1,则将磁带更改为 d。
    4. 向左扫描,直到找到一个空的胶带方块。向右移动。
    5. 如果磁带为 0 或 1,则更改为 a 或 b,然后向右移动。如果磁带是 c 或 d,则停止拒绝。
    6. 如果磁带为 0 或 1,则更改为 a 或 b,然后向右移动。如果磁带是 c 或 d,则停止拒绝。
    7. 如果磁带是 c 或 d,则扫描到磁带开头并转到步骤 2。否则,向右扫描直到 c 或 d,然后向左移动。
    8. 如果为 0,则将磁带更改为 c;如果为 1,则将磁带更改为 d。
    9. 向左扫描,直到找到 a 或 b。向右移动。
    10. 从 4 开始重复。

。步骤 2 的工作原理如下:

  • 前提条件:磁带以空白开始,后面是 (a+b)^2n (c+d)^n,最后是无限的空白字符串。
  • 后置条件:如果前缀 (a+b)^2n 不是回文,则停止;否则,使磁带处于类似 D (c+d)^3n D*

    的状态

    1. 向右移动。
    2. 如果磁带是a(或b),则向右移动。如果磁带是 c 或 d,请转到磁带的开头,然后转到步骤 3。
    3. 如果磁带为 c、d 或空白,则停止拒绝。否则,向右扫描,直到找到 ac、d 或空白。向左移动。
    4. 如果磁带是 ab(或 a),则停止拒绝。否则,将其更改为 ac(或 d),然后向左扫描,直到看到空白、ac 或 d。向右移动。将a(或b)更改为c(或d)。向右移动。
    5. 从第 2 步开始重复。

步骤 3 的工作方式如下

  • 前提条件:磁带为 D (c+d)^3n D*
  • 后置条件:磁带为 D (0+1)^3n D*

    1. 向右移动。
    2. 如果磁带是c,则写入0并向右移动。如果磁带是 d,则写入 1 并向右移动。如果磁带为空白,则移至磁带末尾的第一个空白区域,然后转到步骤 4。
    3. 重复步骤 2。

步骤 4 和 5 的工作方式与步骤 1 和 2 类似,只是向后操作(磁带现在看起来像 D (c +d)^n (a+b)^2n D*,并且您必须检查 (a+b)^2n 部分是否是回文。

通过这两项测试的任何字符串都必须采用 ww^R w 的形式。其中 w位于 (0+1)* 中。

Since some time has passed and the answer probably isn't needed anymore, I guess I'll propose a solution for the benefit of future students looking for an example of how one language can be recognized by a Turing machine.

Here's the idea. We'll take as the tape alphabet {0, 1, a, b, c, d} and make a single-tape singly-infinite tape Turing machine that recognizes w w^R w. The machine will work in five phases:

  1. Replace 0s and 1s in the prefix w w^R with a's and b's.
  2. See whether w w^R is a palindrome.
  3. Restore the tape to its pristine state.
  4. Replace 0s and 1s in the suffix w^R w with c's and d's.
  5. See whether w^R is a palindrome.

Note that this is simply one easy (for me to understand, that is) way to show that there exists a Turing machine to recognize this language. Naturally, showing that there exists an algorithm to solve this in any Turing-equivalent system of computation is just as good (it proves there exists a TM)... still, this outlines the construction of one such TM. Also note that there may be a simpler, more efficient or more intuitive TM to solve this problem... again, this is only one approach.

Step 1 will work as follows:

  • Precondition: The tape begins with a blank, contains any string in (0+1)*, and is followed by an infinite string of blank squares.
  • Postcondition: Halts if tape is empty or if length is not a multiple of 3; else, the tape begins with a blank, is followed by (a+b)^2n (c+d)^n, followed by an infinite string of blanks.

    1. Move to the right.
    2. If empty, halt accept. Otherwise, Scan to the right until you find an empty tape square, then move left.
    3. Change the tape to c if 0 or d if 1.
    4. Scan left until you find an empty tape square. Move right.
    5. If the tape is 0 or 1, change to a or b then move right. If the tape is c or d, halt reject.
    6. If the tape is 0 or 1, change to a or b then move right. If the tape is c or d, halt reject.
    7. If tape is c or d, scan to the beginning of the tape and go to Step 2. Otherwise, scan right until c or d, then move left.
    8. Change the tape to c if 0 or d if 1.
    9. Scan left until you find either a or b. Move right.
    10. Repeat starting at 4.

Step 2 will work as follows:

  • Precondition: The tape begins with a blank, is followed by (a+b)^2n (c+d)^n, followed by an infinite string of blanks.
  • Postcondition: Halts if the prefix (a+b)^2n isn't a palindrome; otherwise, leaves the tape in a state like D (c+d)^3n D*

    1. Move right.
    2. If tape is a (or b), move right. If tape is c or d, go to the beginning of the tape, then go to Step 3.
    3. If the tape is c, d or blank, halt reject. Otherwise, scan right until you find a c, d or blank. Move left.
    4. If the tape is a b (or a), halt reject. Otherwise, change this to a c (or d) and scan back to the left until you see a blank, a c or a d. Move right. Change a (or b) to c (or d). Move right.
    5. Repeat starting at step 2.

Step 3 will work as follows

  • Precondition: Tape is D (c+d)^3n D*
  • Postcondition: Tape is D (0+1)^3n D*

    1. Move right.
    2. If tape is c, write 0 and move right. If tape is d, write 1 and move right. If tape is blank, move to first blank space at the end of tape and go to step 4.
    3. Repeat step 2.

Step 4 and 5 work just like steps 1 and 2, except you work backwards (the tape now looks like D (c+d)^n (a+b)^2n D*, and you must check to see whether the (a+b)^2n part is a palindrome.

Any string passing both these tests must be of the form w w^R w where w is in (0+1)*.

调妓 2024-12-14 10:49:32

作为提示,请注意对于某些 n,wwRw 的长度必须为 3n(因为每个字符恰好出现 3 次)。因此,您可以构建一台图灵机,它通过某种方式计算字符串的长度,使用它来确定三个字符串的边界在哪里,然后检查这三个部分是否都具有适当的组成。如果您无法算出 3 个字符的倍数,您可以立即拒绝。

根据允许的 TM 类型,使用多轨或多磁带图灵机可能是最简单的,这样您就可以用一些额外的信息来标记字母。

希望这有帮助!

As a hint, note that wwRw must have length 3n for some n (since each character appears exactly three times). You might therefore build a Turing machine that works by somehow counting the length of the string, using this to determine where the boundaries of the three strings are, and then checking that the three pieces all have the appropriate composition. If you can't count up a multiple of 3 characters, you could immediately reject.

Depending on what sort of TM is allowed, this might be easiest with a multitrack or multitape Turing machine so that you can mark up the letters with some extra information.

Hope this helps!

皓月长歌 2024-12-14 10:49:32

以下是我使用 2 个磁带和 O(n) 复杂度的方法:

  1. 通过扫描磁带 1 确保长度除以 3,同时在磁带 1 中每 3 步在磁带 2 上向右移动
  2. 如果在下一步时到达磁带 1 的末尾对于磁带 2,向右移动足够数量的字母(可被 3 整除)
  3. 在磁带 2 上标记您到达的字母(这是前三分之一的末尾)
  4. 回滚到两个磁带的开头
  5. 到达第二个三分之一通过翻阅磁带 2 直到标记并返回
  6. 确认 WWR:将两盘磁带移动到磁带 2 的末尾,然后向前移动磁带 1,向后移动磁带 2。如果它们匹配,您会
  7. 在开头和结尾得到 WWR 检查 W:只需继续扫描磁带 1,同时从磁带 2 的开头进行比较

Here's how I did it with 2 tapes and O(n) complexity:

  1. make sure the length divides by 3 by scanning tape 1 while moving right on tape 2 every 3 steps in tape 1
  2. If you reached the end of tape 1 while the next step for tape 2 is to move right you the sufficient number of letters (divisible by 3)
  3. Mark the letter you reached on tape 2 (this is the end of the first thirds)
  4. Roll back to the beginning of both tapes
  5. Get to the second third by going over tape 2 till the mark and back
  6. confirm WWR: move both tapes till the end of tape 2 and then move tape 1 forward and tape 2 backwards. If they match you got WWR
  7. Check W at the beginning and the end: simply continue the scan on tape 1 while comparing to tape 2 from its beginning
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文