我通常将其理解为使用 prolog。 Prolog 允许您定义谓词和真值。然后序言解释器可以使用标准逻辑规则得出进一步的“真相”。例如,以下每一行在第一个和第二个参数之间建立了father_child 和mother_children 关系(提到的人来自辛普森一家)。
member(X, [X|_]).
member(X, [_|T]) :- member(X,T).
mother_children(marge, [bart, lisa, maggie]).
mother_children(mona, [homer, jay]).
mother_child(X, Y) :- mother_children(X, C), member(Y, C).
father_child(homer, bart).
father_child(homer, lisa).
father_child(homer, maggie).
father_child(abe, homer).
father_child(abe, herb).
father_child(abe, abbie).
sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).
parent_child(X, Y) :- father_child(X, Y).
parent_child(X, Y) :- mother_child(X, Y).
如果您将该程序启动到 prolog 解释器中,然后询问它sibling(X,Y),它将返回给您所有存在的兄弟姐妹对。有趣的是,我们从来没有明确说过,巴特是丽莎的兄弟姐妹。我们只是定义了父亲和母亲的关系,但是通过定义进一步的规则,prolog 使用正常的规则来推导出满足sibling 规则的名称。
Prolog 在 80 年代更流行,在各种 AI 系统等中。这些天它有点过时了(不是你在大学里知道的那样,它仍然很热)。