2014-04-13 17 views
0

您好我有一个gprolog文件,我得到一个错误。我知道存在错误是什么,但无法找到解决方案。在有问题的部分文件中,我试图设置证明树。什么是错的,在过去3线:-GNUProlog文件'存在错误'遇到问题

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). 

感谢您的帮助

+1

语法看起来很不寻常。 “事实”,“<=”,“如果”,“然后”,“和”,“或”必须定义为运营商。您可能会定义一些额外的运算符。 – false

+0

正如@false指出的那样,您已经有了自定义的操作符,但您没有提到过。而你的*有些错误*有点含糊。发布问题时最好显示错误消息等。 '<='是你定义的一个操作符?如果不是的话,那么如果你使用它来比较术语,你的'<='应该在Prolog中是@ = <'。 '<='不是Prolog中的内置运算符。 – lurker

回答

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是-kind OF-声明式编程......试着像那样思考。

这是一个使用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 , [email protected]=<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)):-([email protected]=<ProofTree1),([email protected]=<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 
| ?-