Relationship between not found, dif, and \+

Viewed 60

Conceptually what's the relationship between false, dif, and \+.

Given this program:

likes(john, mary).

What is being asked exactly when executing the query:

\+ like(john, A).

And why is the answer not:

dif(A, mary).

The more I think about it, the more I'm convinced that I don't understand the meaning of negation in Prolog.

1 Answers

\+ like(john, A)

(This is an malformed query if variable A behind the \+ is unbound at call time: floundering)

\+ is an operator that is defined procedurally:

  • prove the query on the right of \+
  • If it succeeds then fail.

In other words, "if you can't find evidence for it, assume it's false" aka. "default negation". An attitude taken in relational databases for one. It is basically a replacement for the problem that Prolog doesn't have strongly negated statements, but turns out to be a welcome extension that the philosophers of logic hadn't even come up with earlier.

dif(A, mary).

Is much simpler: "Make sure that A and mary do not unify on this branch of the computation". A constraint is set up that will cause unification of mary and A to fail, either immediately if A is already bound to mary or later. Compare with A \= mary which states that A and mary do not unification at the time this statement is encountered, and so is not really a "logic statement" at all.

I collected some notes on negation as failure and dif/2 which need to be reworked. Still useful.

Related