【发布时间】:2015-04-21 18:42:14
【问题描述】:
以下是针对大学的(不是作业,而是辅导作业)。目前我无法从我的导师那里得到帮助(学期中休),所以我想找你们这些好人看看我哪里出错了。该计划是创建一个非常基本的反向链接推理引擎。我这样做了(按照提供的说明),但现在我们也必须制作一个证明树。以下是我的代码:
%operator rules
:- op(800, fx, if).
:- op(700, xfx, then).
:- op(300, xfy, or).
:- op(200, xfy, and).
:- op(800, fx, fact).
:- op(800, fxf, <=).
% BACKWARD CHAINING INFERENCE ENGINE with proof tree
is_true(P, P) :-
fact P.
is_true(C, C <= ProofTreeA) :-
if A then C, is_true(A, ProofTreeA).
is_true(P1 and P2, ProofTree1 and ProofTree2) :-
is_true(P1), is_true(P2), ProofTree1, ProofTree2.
is_true(P1 or P2, ProofTree1) :- is_true(P1), ProofTree1.
is_true(P1 or P2, ProofTree2) :- is_true(P2), ProofTree2.
% production rules
if covering_scales then family_fish.
if covering_skin then family_mammal.
if family_mammal and size_large then species_whale.
if family_mammal and size_small then species_seal.
if family_fish and size_large then species_tuna.
if family_fish and size_small then species_sardine.
现在,在我查阅文件后,我要断言以下内容:
asserta(fact covering_scales).
asserta(fact size_large).
然后我将输入以下查询:
is_true(species_tuna, P).
但我得到的只是以下错误消息:
uncaught exception: error(existence_error(procedure,is_true/2),top_level/0
我的猜测是我遗漏了一些明显的东西,但我不知道是什么。
【问题讨论】:
-
当我尝试将您的代码加载到 GNU Prolog 中时,我遇到了一些错误。例如,
is_true(C, C <= ProofTreeA)有语法错误。您还在谓词中调用is_true,在某些地方,只有一个参数。 -
另外,
:- op(800, fxf, <=).很有趣 -
谢谢。我的两个错误就像 CapelliC 和 @lurker 所说的那样。需要有 xfx (不是 fxf 错字),我只用一个参数调用 is_true 。现在可以正常工作了,非常感谢
标签: prolog