I've read quite a bit about Prolog's Negation by Failure where Prolog in order to prove that \+Goal
holds tries to prove that Goal
fails.
This is highly connected with CWA (close world assumption) where for example if we query \+P(a)
(where P
is a predicate of arity 1) and we have no clues that lead to prove P(a)
Prolog assumes (due to CWA) that not P(a)
holds so \+P(a)
succeeds.
From what I've searched this is a way to solve classical logic weakness where if we had no clue about P(a)
then we could not answer whether \+P(a)
holds.
What described above was the way of introducing non-monotonic reasoning in Prolog. Moreover the interesting part is that Clark proved that Negation by Failure is compatible/similar with classical negation only for ground clauses. I understand that for example:
X=1, \+X==1.
: should return false in Prolog (and in classical Logic).
\+X==1, X=1.
: should return false in classical logic but it succeeds in Prolog since the time that NF is examined X
is not bound, this differs from classic-Pure Logic.
\+X==1.
: should not give any answer in classical logic until X
is bound, but in Prolog it returns false (possibly to break weakness of classical logic) and this is not same/compatible with pure Logic.
My attempt was to simulate classic negation, thanks to @false's suggestions in comments, current implementation is:
\\+(Goal) :- when(ground(Goal), \+Goal).
Some testing:
?- \\+(X==1).
when(ground(X), \+X==1).
?- X=1, \\+(X==1).
false.
?- \\+(X==1), X=1.
false.
My question:
Is the above a correct interpretation of classical negation?
(Are there any obvious corner cases that it misses?? also I'm concerned about Logic Purity when using when/2
, is it safe to assume that the above is pure??).
In SWI-Prolog, it is possible to implement the rules of inference for classical logic in Constraint Handling Rules, including de Morgan's laws and the law of noncontradiction:
Then, you can use the solver like this:
This program prints
animal(cat,tom)
.But this formula could be solved more efficiently using a different algorithm, such as DPLL.