Inference engine prolog

1.4k views Asked by At

I am trying to build an inference engine in prolog.

For example, here are some rules

R1 : A and B -> C
R2 : E and F -> D
R3 : G and T -> H

I wanted to do it like this

c :- a,b
d :- e,f
h :- g,t

but I have to use a predicate "rule/1" defined as follows

rule(Ri) :- "if conditions then conclusions".

For example :

rule(r1) :- "if a and b then c".

How can I do ?

1

There are 1 answers

0
Sudo On BEST ANSWER

I have found a solution :

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

and then use the predicate clause/2 to iterate over the rules, like this :

clause(rule(R),(if(X),then(Y))).