Given a CNF logic formula
[[a, b, c], [b, d], [not(d), a]]
that is equal to ((a or b or c) and (b or d) and (not d or a))
, how do I calculate its models (possible values for its atoms that makes the formula true
), using prolog? This is what i've got so far:
A valuation to the formula is a list of terms in the form os val(X,B)
, where X
is an atom, and B
is its value (0 or 1).
The relation value(X, Vs, B)
is given by
value(X, [val(X, B)|_], B) :− !.
value(X, [_|Ps], B) :− value(X, Ps, B).
and its true whenever B
is the value for the atom X
in the valuation Vs
.
The relation sp(F, Ss)
, given by
sp([],[]).
sp([F|Fs], Ss) :- setof(A, member(A,F), R), sp(Fs, N), append(R,N,M), setof(B,member(B,M),Ss).
and its true whenever Ss
is the list of atoms in logic formula F.
The relation valuation(As, Vs)
, given by
valuation([],[]).
valuation([A|As], [V|Vs]) :- (V = val(A,0); V = val(A,1)), valuation(As,Vs).
that is true whenever Vs
is a possible valuation for the list of atoms As
.
What I need:
The relation ext(F, Vs, B)
that is true whenever F
is a formula, Vs
is a possible valuation for that formula, and B
is the value of the formula applying Vs
valuation. For example, the consult
ext([[a], [not(b), c]] , [val(a, 1), val(b, 0), val(c , 1)], B).
should return the value B = 1.
The relation model(F,Vs)
that is true whenever the valuation Vs
is a model for the formula F
.
The relation models(F, Ms)
that is true whenever Ms
is a list which elements are models for the formula F. I guess we need to use prolog’s setof
here.
And, at last, I don't know whats the best implementation of val(X,B)
to make it work. I dont know if I should specify val(_,1)
and val(_,0)
to be true or only val(_,1)
, what is better knowing the other relations to be implemented?