Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 599
Enrico Pirani Avatar asked Jul 01 '15 14:07

Enrico Pirani


2 Answers

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.

like image 129
false Avatar answered Oct 21 '22 11:10

false


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.

like image 1
Boson Avatar answered Oct 21 '22 13:10

Boson