[英]PDA for L = {a^nb^m : m ≥ n, m-n is even}
Design a PDA for the following language为以下语言设计一个 PDA
L = {a^nb^m : m ≥ n, mn is even}. L = {a^nb^m : m ≥ n, mn 是偶数}。
Let's start with a PDA for a^nb^m where m >= n.让我们从 a^nb^m 的 PDA 开始,其中 m >= n。 A PDA can push an a to the stack for every a it sees, pop ab for every b it sees, and if it runs out of b while there are still a on the stack, it rejects.
PDA 可以针对它看到的每个 a 将 a 压入堆栈,针对它看到的每个 b 弹出 a b,如果 b 用完而堆栈中仍有 a,它就会拒绝。
Now, what else do we need to do to exclude the case where m - n is odd?现在,我们还需要做什么来排除 m - n 是奇数的情况? Well, m - n is odd means we have some b left over in the input.
好吧,m - n 是奇数意味着我们在输入中还剩下一些 b。 We can simply modify our accepting state so that on further b, it moves to a new state (encoding odd b) and then back to the accepting state on the next b, encoding the requirement that the residual b must be even.
我们可以简单地修改我们的接受状态,以便在进一步的 b 上,它移动到一个新状态(编码奇数 b),然后在下一个 b 上返回到接受状态,编码残差 b 必须是偶数的要求。
A full PDA might look like this:完整的 PDA 可能如下所示:
q s S q' S'
q0 a Z q0 aZ
q0 a ax q0 aax
q0 b Zx q2 Z
q0 b ax q1 x
q1 b ax q1 x
q1 b Z q2 Z
q2 b Z q1 Z
Check that to see if it works, there might be some bugs.检查它是否有效,可能有一些错误。 The way to read this is:
阅读本文的方法是:
From state q, on input s, with stack configuration S, the PDA can transition to state q' and update the stack configuration to S'.
从状态 q,在输入 s 上,使用堆栈配置 S,PDA 可以转换到状态 q'并将堆栈配置更新为 S'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.