【发布时间】:2016-12-10 09:45:57
【问题描述】:
为了在 prolog 中表示 M finite automata,我使用了以下谓词:
states /*states(Q) <=> Q is the list of automata's states*/
symbols /*symbols(Sigma) <=> Sigma is the list of automata's input symbols*/
transition /*transition(X, A, Y) <=> δ(X, A)=Y*/
startState /*startState(S) <=> S is the start state of automata*/
finalStates /*finalStates(F) <=> F is the list of automata's final states */
对于这个示例自动机:
表示是:
states([q0, q1, q2]).
symbols([a, b]).
transition(q0, a, q1).
transition(q0, b, q2).
transition(q1, a, q2).
transition(q1, b, q0).
transition(q2, a, q1).
transition(q2, b, q2).
startState(q0).
finalStates([q2]).
假设第五个 w 单词被 M 自动机 accepted(W) 识别(接受)(W 是单词的表示列表)
accepted(W):-startState(Q0), accepted1(Q0, W)
其中accepted1 w 属于由自动机的 Q 状态识别的语言。
accepted1(Q, []):- finalStates(F), !, member(Q, F).
accepted1(Q, [A|W]):- transition(Q, A, Q1), accepted1(Q1, W),!.
这里的问题是:如何找到给定M有限自动机接受的所有正K长度词?
【问题讨论】: