Questions tagged [negation-as-failure]

For questions regarding the concept of negation as failure in logic programming. Please include all relevant tags on your question; e.g., [prolog], [answer-set-programming], etc.

Negation as failure (NAF) is a non-monotonic inference rule in logic programming, used to derive not p from failure to derive p. The adoption of this kind of negation is strictly related to the closed-world assumption.

For instance, let us consider the following Prolog program:

grandpa(X,Z) :- father(X,Y), parent(Y,Z).
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
father(a,b).
mother(b,c).

For answering to the question ?- not grandpa(a,b)., the program will expand the tree having as root grandpa(a,b), from which it follows father(a,X), parent(X,b) and, non-deterministically, father(X,b) and mother(X,b). Both the branches indeed will fail: the first one because it does not exist any X satisfying father(a,X) and father(X,b) at the same time; the second one because mother(X,b) doesn't unify with any fact in the extensional database.

If follows that grandpa(a,b) will be considered false and the answer to

?- not grandpa(a,b).

will be

yes.
10 questions
6
votes
3 answers

How to understand negation as failure in ASP?

Suppose we have the following program: human(socrates). day(tomorrow). die(X) :- human(X). may_go_to_school(Y) :- day(Y), not holiday(Y). If we run clingo to aquire the answer set of the program, we get Answer:…
BobHU
  • 402
  • 5
  • 18
5
votes
3 answers

Why is Prolog's failure by negation not considered logical negation?

In many Prolog guides the following code is used to illustrate "negation by failure" in Prolog. not(Goal) :- call(Goal), !, fail. not(Goal). However, those same tutorials and texts warn that this is not "logical negation". Question: What is the…
Penelope
  • 291
  • 6
5
votes
2 answers

Prolog negation and logical negation

Assume we have the following program: a(tom). v(pat). and the query (which returns false): \+ a(X), v(X). When tracing, I can see that X becomes instantiated to tom, the predicate a(tom) succeeds, therefore \+ a(tom) fails. I have read in some…
Gurkan E.
  • 205
  • 1
  • 2
  • 7
3
votes
1 answer

Seeking a pure Prolog implementation of (\=)/2

Negation as failure is usually considered impure. The Prolog interpreter needed for negation as failure must realize SLDNF which is an extension of SLD. The predicate (\=)/2 is for example used in the library(reif). It can be bootstrapped via…
user502187
3
votes
2 answers

Confusion in output of double negation as failure

I am trying to learn prolog and i came across the following problem: Given - try(X):-not(not((member(X,[a,b,c])))),write(X). I would expect the query ?- try(X)., for the following query to be something like X=a a; X=b b; X=c c. But in fact, the…
Alex Goft
  • 1,114
  • 1
  • 11
  • 23
2
votes
1 answer

Clojure core.logic : nafc and ground

I'm representing a simple data-base in Clojure's core.logic. There are two predicates : page(p) and link(p,q). page(p) represents the existence of pages in a wiki called p link(p,q) represents that page p contains a link to page q. I'm now trying…
interstar
  • 26,048
  • 36
  • 112
  • 180
2
votes
1 answer

Negation as failure in Prolog and default negation in Answer Set Programming

I'm having an extremely hard time understanding the concept of negation as failure in Prolog compared to default negation in Answer Set Programming. Could someone please explain to me what the difference is?
1
vote
1 answer

Why throw an exception in Prolog instead a simple fail?

I'm programming in Prolog and sometimes I want to get a fail but instead I get an exception, which I can't understand why should be a difference between them. If something couldn't execute that's mean that the predicate didn't succed, so it's a…
titusfx
  • 1,896
  • 27
  • 36
1
vote
3 answers

Negation as failure in Prolog is a procedural behavior?

I have a little question about the negation as failure in Prolog language: This is a question more theoretical than practical because I have clear how this example work. so I have the following Prolog program: /* Fatti che specificano quali esseri…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
1
vote
2 answers

How does negation-as-failure works in Prolog?

I want to know how Prolog solves this program: test(X, Y). test(X, X):-!, fail. I googled "negation as failure" but I am confused!
Milad Khajavi
  • 2,769
  • 9
  • 41
  • 66