我正试图在prolog中构建一个推理机。
例如,下面是一些规则
R1 : A and B -> C
R2 : E and F -> D
R3 : G and T -> H
我想这样做
c :- a,b
d :- e,f
h :- g,t
但我必须使用谓词“规则/1”,定义如下
rule(Ri) :- "if conditions then conclusions".
例如:
rule(r1) :- "if a and b then c".
我该怎么做?
发布于 2014-12-24 13:16:08
我找到了一个解决办法:
:- dynamic if/1, then/1.
rule(r1) :- if([a,b]),then([c]).
rule(r2) :- if([e,f]),then([d]).
rule(r3) :- if([g,t]),then([h]).
然后使用谓词clause/2
对规则进行迭代,如下所示:
clause(rule(R),(if(X),then(Y))).
https://stackoverflow.com/questions/27593306
复制相似问题