嗨我有一个gprolog文件,我收到错误。我知道存在错误是什么,但无法找到解决方案。在相关文件的部分我正在尝试设置证明树。 :-
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):-(P1<=ProofTree1),(P2<=ProofTree2).
is_true(P1 or P2, ProofTree1):-(P1 or P2<=ProofTree1).
is_true(P1 or P2, ProofTree2):-(P1 or P2<=ProofTree2).
感谢您的帮助
答案 0 :(得分:0)
正如@false所指出的,你有语法错误:
Quetzalcoatl$ cat <<.. > pl.pl
> 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):-(P1<=ProofTree1),(P2<=ProofTree2).
> is_true(P1 or P2, ProofTree1):-(P1 or P2<=ProofTree1).
> is_true(P1 or P2, ProofTree2):-(P1 or P2<=ProofTree2).
> ..
Quetzalcoatl$ gprolog --init-goal "['pl.pl']"
compiling pl.pl for byte code...
pl.pl:1:20: syntax error: . or operator expected after expression
pl.pl:2:12: syntax error: , or ) expected
pl.pl:3:12: syntax error: , or ) expected
pl.pl:4:12: syntax error: , or ) expected
pl.pl:5:12: syntax error: , or ) expected
5 error(s)
compilation failed
warning: command-line goal '[''pl.pl'']' failed
GNU Prolog 1.4.4 (64 bits)
Compiled Apr 23 2013, 17:26:17 with /opt/local/bin/gcc-apple-4.2
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz
| ?-
Prolog是 - 声明式编程......尝试这样思考。
这是一个带有gnu-prolog语法(gprolog manual)的版本。我不明白你的逻辑,所以你应该验证。
Quetzalcoatl$ cat pl.pl
%you should be aware of the signatures of your rules, e.g. is_true(+fact,?fact), is_true(?fact,?fact)
:-op(800,xfy, and).
:-op(801,xfy, or).
is_true(P,P):-nonvar(P),P. %P should be bounded to a fact (e.g. fact/1) existing in your knowledge base of facts
is_true(C,ProofTreeA):- A , C@=<ProofTreeA, is_true(A,ProofTreeA). %A is ubounded ?
%'if A then C' ---> 'A,C' %assuming A is a fact in the knowledge base
is_true(and(P1, P2), and(ProofTree1 , ProofTree2)):-(P1@=<ProofTree1),(P2@=<ProofTree2).
is_true(or(P1 , P2), ProofTree1):-P1 @=< ProofTree1 ; P2 @=< ProofTree1.
%s_true(or(P1 , P2), ProofTree2):-(P1 or P2<=ProofTree2). this rule is the same than the above one
Quetzalcoatl$ gprolog --init-goal "['pl.pl']"
compiling pl.pl for byte code...
pl.pl compiled, 9 lines read - 1708 bytes written, 4 ms
GNU Prolog 1.4.4 (64 bits)
Compiled Apr 23 2013, 17:26:17 with /opt/local/bin/gcc-apple-4.2
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz
| ?-