4

I'm learning prolog, and I'm confused by the claim that prolog uses proof by contradiction:

The resolution proof process makes use of a technique that is known as reduction to the absurd: suppose that the formula to be proved is false, and show that this leads to a contradiction, thereby demonstrating that the formula to be proved is in fact true.

They show the following proof diagram (based on rules and facts established one section earlier):

Proof diagram

But if I read these steps backwards it's a straightforward direct proof:

/* axiom: tottenham_court_road is connected to leicester_square by northern road */
connected(tottenham_court_road, leicester_square, northern)

/* therefore it's connected to something on some road */
connected(tottenham_court_road, W, L)

/* being connected to something also means it's nearby */
nearby(X,Y):-connected(X,Y,L)

/* Therefore tottenham_court_road is near something */
nearby(tottenham_court_road, W)

How is this a proof by contradiction? Why would that be a more useful framework than chaining reasoning from axioms?

false
  • 10,264
  • 13
  • 101
  • 209
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
  • 1
    I think the book is (confusingly) referring to something other than the workings of Prolog's inference engine, at that point. – brebs Jan 29 '23 at 16:33
  • see [wikipedia](https://en.wikipedia.org/wiki/Resolution_(logic)) – CapelliC Jan 29 '23 at 18:31

2 Answers2

5

Horn clauses

A Horn clause is a disjunction with at most one positive literal, where all variables are implicitly universally quantified over the whole formula. For example,

¬father(X,Y) ∨ ¬father(Y,Z) ∨ grandfather(X,Z)

is a Horn clause. Since ¬α ∨ ¬β is equivalent to ¬(αβ), and ¬αβ is equivalent to αβ, that Horn clause can be written as:

  ¬father(X,Y) ∨ ¬father(Y,Z) ∨ grandfather(X,Z)
≡ ¬(father(X,Y) ∧ father(Y,Z)) ∨ grandfather(X,Z)
≡ father(X,Y) ∧ father(Y,Z) → grandfather(X,Z)

Or, equivalently, as:

grandfather(X,Z) ← father(X,Y) ∧ father(Y,Z)
  • A Horn clause composed by a single positive literal is called a fact. For example, father(adam,cain) ∨ ⊥, which can be written as father(adam,cain) ← ⊤, is a fact.

  • A Horn clause without positive literal is called a goal (a.k.a. query). For example, ⊥ ∨ ¬father(adam,cain), which can be written as ⊥ ← father(adam,cain), is a goal.

  • A Horn clause of the form ⊥ ← ⊤ is called a contradiction. For example, the resolution of the goal ⊥ ← father(adam,cain) with the fact father(adam,cain) ← ⊤ produces the resolvent ⊥ ← ⊤. The literal at the LHS of ← is positive, and a literal at the RHS is negative. Therefore, two unifiable literals in opposite sides of ← can be cancelled by resolution.

  • A Horn clause that is not a goal clause is called a definite clause.

  • A set of definite clauses is called a logic program.

In logic programming, the constant literals ⊥ and ⊤ are often omitted. Usually, a fact is written as α ←, a goal is written as ← α, and a contradiction is written as ←.

Horn clauses express a subset of FOL with very useful properties (e.g., unique minimal models and relatively low computational complexity). In fact, Logic programming and Prolog are built on top of Horn clauses.

Proof by contradiction

Consider the following logic program (with numbered clauses):

(1) father(adam,abel) ←
(2) father(adam,cain) ←
(3) father(adam,seth) ←
(4) father(seth,enos) ←
(5) grandfather(X,Z) ← father(X,Y) ∧ father(Y,Z)

The question Who is Enos' grandfather? (that is, there is someone who is Enos' grandfather and we want to know who this person is) can be expressed by the formula ∃W.grandfather(W,enos). Clearly, that formula is not a Horn clause. However, in order to proof that formula by contradiction, we must consider its negation:

  ¬∃W.grandfather(W,enos)
≡ ∀W.¬grandfather(W,enos)
≡ ∀W.[⊥ ∨ ¬grandfather(W,enos)]
≡ ⊥ ← grandfather(W,enos)
≡ ← grandfather(W,enos)

which is, indeed, a Horn clause (or, more precisely, a goal clause).

So, if the logic program (1)-(5) is consistent and ∃W.grandfather(W,enos) is true w.r.t. that program, then the goal ← grandfather(W,enos) must lead to a contradiction (and the constant bound to the universal variable W must be the desired answer for the question):

← grandfather(W,enos)   (5) grandfather(X,Z) ← father(X,Y) ∧ father(Y,Z)
  |                         |
  +-------------------------+ {X=W, Z=enos}                 
  |
← father(W,Y) ∧ father(Y,enos)   (3) father(adam,seth) ←
  |                                  |
  +----------------------------------+ {W=adam, Y=seth} 
  |
← father(seth,enos)   (4) father(seth,enos) ←
  |                       |
  +-----------------------+ {}
  |
← [contradiction]

Horn clauses are useful in various applications due to their very nice properties: the resolvent of two Horn clauses is a new Horn clause, and the resolvent of a goal clause and a definite clause is a new goal clause.

Horn clauses and Prolog

In Prolog, the connective is replaced by , and the connective is replaced by :- (except in facts, where that connective is omitted, and in goals, where the top-level prompt ?- implicitly stands for ).

"In logic, this is achieved by writing the statement as a rule with an empty conclusion, i.e. a rule for which the truth of its premises would lead to falsity"

A clause with an empty conclusion is nothing more than a goal of the form ← α, which is equivalent to ⊥ ← α. So, if the premise α is true:

  ⊥ ← α
≡ ⊥ ← ⊤
≡ ⊥ ∨ ¬⊤
≡ ⊥      [falsity]

Thus, the symbols "?-" and ":-" are in fact equivalent. A contradiction is found if resolution leads to the empty rule, of which the premises are always true (since there are none), but the conclusion is always false.

Since both symbols ?- and :- are used in place of , clearly, they are equivalent. Particularly, the symbol ?- is only implicitly used (when a query is typed in the top-level prompt). In some implementations of Prolog, a goal clause in the program source-code is automatically executed when that program is loaded. For example, when the following program is loaded in SWI-Prolog, the text Hi Alfred! is written to the current output:

user('Alfred').                             % user('Alfred') ←
:- user(Name), format('Hi ~w!~n', [Name]).  % ← user(Name), format('Hi ~w!~n', [Name]).

Empty rule is just another name for contradiction (i.e., ⊥ ← ⊤, often written simply as ). Of course, the premise of an empty rule is always true (⊤) and its conclusion is always false (⊥).

slago
  • 5,025
  • 2
  • 10
  • 23
  • 4
    Thank you for writing what looks like a proper answer. will go ahead and read it now. Thank you again. – Will Ness Feb 02 '23 at 23:04
  • 2
    Questions: 1. What is a "literal"? 2. "all variables are implicitly universally quantified"... over the whole clause, correct? – Will Ness Feb 02 '23 at 23:13
  • 1
    @WillNess Answer 1. In mathematical logic, a literal is an atomic formula (i.e., a formula without connectives) or its negation. Answer 2. Yes, that's correct (a.k.a. prenex normal form). – slago Feb 02 '23 at 23:32
  • Thank you for the attempt at an answer. I still do not understand where the border between "logic programming" and "Prolog programming" is, both in the textbook and in your answer. It would be _tremendously_ helpful if you delineated those even more forcefully. – TA_intern Feb 05 '23 at 18:31
  • Very nice answer. s(X). – tas Feb 08 '23 at 23:52
1

You should probably ask the textbook authors what exactly they are talking about. They for example say "In logic, this is achieved by writing the statement as a rule with an empty conclusion, i.e. a rule for which the truth of its premises would lead to falsity" but do they mean that this is strictly in the world of logic but not in the world of Prolog programming? The example they show:

:- nearby(tottenham_court_road, W)

Doesn't exactly make sense in Prolog, ie, you can write it and it might even do something but it doesn't seem to be the thing that they are talking about "in logic". This sentence specifically gets more unclear the more times I read it:

Thus, the symbols "?-" and ":-" are in fact equivalent. A contradiction is found if resolution leads to the empty rule, of which the premises are always true (since there are none), but the conclusion is always false.

Maybe it made sense in their head when they wrote it but they failed miserably at the exercise of writing a textbook.

TA_intern
  • 2,222
  • 4
  • 12