I have gotten this program to work so far in GNU prolog
not(X) :- \+ X.
and(X, Y):- X , Y.
or(X, Y):- X ; Y.
implies(X, Y):- \+ X ; Y.
p.
q.
:- initialization(main).
main :-
write('Program start'), nl.
You can type in and(p,q), and get yes, as well as and(p,not(q)) and get no. Now i'd like to do something like this:
I sett p to true, (by initializing it with p.) , and (and(p,q)) to true (but without initializing q), and i want prolog to say: One solution exists: "q" must be true
If i set p and (or(p,q)) to true i want prolog to say: Two solutions exists, "q" can be true or false. Which is the best way to do it?
I suggest that you use variables instead of
p
andq
and wrap it in some term, e.g.Additionally, I would implement two predicates, one for solving true statements, one for solving false statements. Using
\+
is not the right approach since it doesn't allow you to bind variables. Here is a little bit of example code:Your example query would then be:
And maybe you have a better name than
formula_true
resp.formula_false
. :)If you have a Boolean constraint solver, that would of course be more efficient.