tags:

views:

59

answers:

2
not(A()) and not(D()) and not(B()) and not(A()).

What's the right way?

+1  A: 

The concept of logical negation is already included in Prolog in means of failure. If your implementation doesn't supply it (it can happens) you can think not as

not(P) :- call(P), !, fail.

or

not(P) :- (call(P) -> fail ; true)

Then look at the formula, it can be simplified to have not applied just to single predicates:

~(A & ~D) & ~B & ~A = (~A | D) & ~B & ~A = ~A & ~B

It's just a De Morgan law and a consideration about the fact that D isn't useful to satisfability of the predicate.

then you can combine them:

final_predicate :- not(B), not(A).

EDIT: remember , is AND and ; is OR.

Jack
+1  A: 

If simply trying to evaluate a propositional logic statement using PROLOG, you could try the following. Start with an encoding of the values of your 'propositions' a, b and d, such as:

a :- true. % this means that a is true.

b :- fail. % this means that b is false

...etc. For example, assuming your statements were:

a :- fail.
b :- fail.
d :- fail.

Then, executing your statement:

?- not(a), not(b), not(d), not(a).
true.

n.b.: The 'propositions' encoded here are 'simulated' - they're actually zero arity first-order predicates as far as PROLOG is concerned.

ps. a :- true. can be simplified to a..

pps. If I'm way off the mark and you're after a way of symbolically manipulating the statement into some other form, such as a normalization, then you need to write what is called a meta-interpreter in PROLOG. Refer to Clocksin and Mellish's Programming in Prolog, Appendix B, 'Clausal Form Program Listings', which might help you.

sharky