What's the difference between "false" and "no" in Prolog
Asked Answered
P

2

7

I started to learn Prolog following the book Programming in Prolog: Using the ISO Standard. At page 7 of the intro to the language they made the assertion : "In Prolog the answer no is used to mean nothing unifies with the question. It is important to remember that no is not the same as false". So why SWI-Prolog uses the falseand truestatement instead of yesor no?

Perfusion answered 1/7, 2015 at 14:23 Comment(0)
D
11

To begin with, the ISO standard (ISO/IEC 13211-1:1995) does not define a toplevel loop. In 1 Scope it reads:

NOTE — This part of ISO/IEC 13211 does not specify:

...

f) the user environment (top level loop, debugger, library
system, editor, compiler etc.) of a Prolog processor.

Traditionally, the answer of a query has been answered with yes or no. In case of yes, answer substitutions were shown, if present.

Today, with more and more constraints present in answers, the traditional toplevel loop becomes a bit cumbersome to use. What is the correct answer to ?- dif(X,a).? It cannot be a yes, it might be a maybe,which was used first by Jaffar et al.s CLP(R). But very frequently one wants to reuse the answer.

?- dif(X,a).
   dif(X,a).
?- dif(b,a).
   true.
?- true.
   true.

Following Prolog IV's pioneering toplevel, the idea in SWI is to produce text as an answer such that you can paste it back to get the very same result. In this manner the syntax of answers is specified to some degree - it has to be valid Prolog text.

So if there is no longer yes, why should there be no? For this reason SWI gives false. as an answer. Prior to SWI, Prolog IV did respond false. Note for example the following fixpoint in SWI:

?- true ; false.
   true
;  false.

So even this tiny detail is retained in answers. Whereas in Prolog IV this is collapsed into true because Prolog IV shows all answers in one fell swoop.

?- true ; false.

   true.

For more on answers, see this.

Degreeday answered 1/7, 2015 at 14:35 Comment(5)
This answer was good until I looked at your username, then it became amazing.Albanian
@false, thanks for your reply but still I cannot get the point. For simple assertions like human(socrates). human(aristotle). and athenian(socrates). I would expect a yes and no answer instead of a true-flase to the question ?- athenian(socrates). and ?-athenian(aristotle).Perfusion
@EnricoPirani: Why not answer true? or false? Many humans answer like this too: Socrates is human? True! Prolog is human? False! Or 3 > 2 ? true!Degreeday
But Clocksin & Mellish wrote that : no is not the same as false (and I suppose the same for yes and true).Perfusion
That's a misunderstanding. true/0 and false/0 are built-in predicates. By showing you true/0 Prolog says: The answer to your query is exactly the same as the answer to true/false. What C&M wants to stress is that the facts in a program are an incomplete description of reality.Degreeday
C
2

I came across this question recently and took a look at an old (third) edition of Clocksin and Mellish which discusses the difference between yes, no and true, false. From my reading of the text this is what I understand:

  1. yes and no are returned after Edinburgh Prolog evaluates a query using its 'database' of facts and rules. yes means the result is provable from the facts and rules in the database; no means it's not provable from those rules and facts.
  2. true and false refer to the real world. It's possible for Prolog to return no to the query isAmerican(obama) simply because this fact is not in the database; whereas in fact (in the real world) Obama is an American and so this fact is true in reality.

Edinburgh Prolog returns yes and no to queries, however later implementations, like SWI Prolog, return true and false. Clearly later implementors didn't consider this distinction very important, but in fact it is a crucial distinction. When Edinburgh Prolog returns a no then it means "not provable from the database"; and when SWI Prolog returns false it also means "not provable from the database". They mean the same thing (semantically) but they look different (syntactically) because SWI Prolog doesn't conform entirely to Edinburgh Prolog conventions.

Chas answered 18/2, 2019 at 21:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.