automata - 如何构造 L={a^nb^m where n<=m<=2n} 的下推自动机?

标签 automata computation-theory pushdown-automaton automata-theory

它应该在不使用 2 个堆栈的情况下构建。我尝试过,但没有 2 个堆栈就做不到。

最佳答案

策略如下:我们可以轻松制作一台接受 a^n b^n 的 PDA,并且可以轻松制作一台接受 a^n b^2n 的 PDA。我们的语言是这些语言的超集,它也接受任何数字 b 在 n 到 2n 之间的语言。我们可以利用非确定性来实现这一点,如下所示:对于放入堆栈的每个 a,我们可以在弹出 a 之前不确定地决定是消耗一个还是两个 b。如果我们的 NPDA 选择每次消耗一个,我们会得到 a^n b^n。如果它选择每次消耗两个,我们得到a^n b^2n。如果它选择两者中的一些,我们就会得到这些极端值之间的数字 b。仅当我们用空堆栈耗尽输入时我们才接受。

Q    s    S    Q'    S'    Comment

q0   e    e    qA    e     Allow empty string to be accepted

q0   a    x    q0    ax    Count a and push onto stack
q0   e    x    q1    x     Transition to counting b

q1   b    ax   q1    x     Mark off a single b for each a
q1   b    ax   q2    x     Mark off the first of two b for this a
q1   e    e    qA    e     Allow string in language to be accepted

q2   b    x    q1    x     Mark off the second of two b for this a

在此 PDA 中,我们将 q0 作为初始状态,将 qA 作为接受状态。 aabbb 上的处理:

   q0, aabbb, e 
-> q0, abbb, a 
-> q0, bbb, aa
-> q1, bbb, aa
-> q1, bb, a
-> q2, b, e
-> q1, e, e
-> qA, e, e

当然,有许多解析不会导致 qA,但在 NPDA 中,如果至少有一个,我们就接受。

关于automata - 如何构造 L={a^nb^m where n<=m<=2n} 的下推自动机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58822772/

相关文章:

finite-automata - DFA 可以有 epsilon/lambda 转换吗?

algorithm - 如何将 CYK 算法应用于此 CFG?

scheme - 可以简化此功能(制作更多 "fast")吗?

pushdown-automaton - 具有不等变量的下推自动机

haskell - 如何在 Haskell/Idris 中拥有受约束的有限状态机?

regex - 查找其他描述的语言的正则表达式

algorithm - 图灵机元素唯一性问题

computer-science - NFA 到 DFA 的问题

time-complexity - 算法的复杂性和问题的复杂性。有什么区别?

automata - PDA 接受包含 a 多于 b 的字符串语言