1

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 ?

false
  • 10,264
  • 13
  • 101
  • 209
Sudo
  • 991
  • 9
  • 24

1 Answers1

2

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))).
Sudo
  • 991
  • 9
  • 24