-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter2.html
2705 lines (1316 loc) · 96.1 KB
/
chapter2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="This book discusses methods to implement intelligent reasoning by means of Prolog programs. The book is written from the shared viewpoints of Computational Logic, which aims at automating various kinds of reasoning, and Artificial Intelligence, which seeks to implement aspects of intelligent behaviour on a computer.">
<!-- SWISH -->
<link href="/web/css/lpn.css" rel="stylesheet">
<link href="/web/css/jquery-ui.min.css" rel="stylesheet">
<script src="/web/js/jquery.min.js"></script>
<script src="/web/js/jquery-ui.min.js"></script>
<script src="/web/js/lpn.js"></script>
<!-- custom stylesheet -->
<!--<link href="/web/css/custom.css" rel="stylesheet">-->
<!--Reveal.js-->
<link href="/web/css/reveal.css" rel="stylesheet">
<link href="/web/css/theme/simple.css" rel="stylesheet">
<meta name=Title content="Simply Logical">
<meta name=author content="Peter Flach">
<title>Simply Logical</title>
</head>
<body>
<!--navibar-->
<div class="reveal" style="margin-top: -50px; padding-top: 50px;">
<div style="position: absolute; bottom: 1em; width: 100%; font-size: 0.4em; text-align: center;">
Peter Flach | http://www.cs.bris.ac.uk/~flach/SimplyLogical.html
</div>
<div class="slides">
<section>
<h3>Interactive lab examples</h3>
<h4>Simply Logical</h4>
</section>
<section>
<section>
<h2>Chapter 2: Clausal logic and resolution:<br>theoretical backgrounds</h2>
</section>
<section>
<h3>Syntax, semantics, and proof theory</h3>
<p>In this chapter we develop a more formal view of Logic Programming by means of a rigorous treatment of clausal logic and resolution theorem proving. Any such treatment has three parts: syntax, semantics, and proof theory. </p>
<ul>
<li><em>Syntax</em> defines the logical language we are using, i.e. the alphabet, different kinds of ‘words’, and the allowed ‘sentences’.
</section>
<section>
<h3>Syntax, semantics, and proof theory (ctd.)</h3>
</li>
<li><em>Semantics</em> defines, in some formal way, the meaning of words and sentences in the language. As with most logics, semantics for clausal logic is <em>truth-functional</em>, i.e. the meaning of a sentence is defined by specifying the conditions under which it is assigned certain <em>truth values</em> (in our case: <strong>true</strong> or <strong>false</strong>). </li>
<li>Finally, <em>proof theory</em> specifies how we can obtain new sentences (theorems) from assumed ones (axioms) by means of pure symbol manipulation (inference rules).</li>
</ul>
</section>
<section>
<h3>Soundness and completeness</h3>
<p>Of these three, proof theory is most closely related to Logic Programming, because answering queries is in fact no different from proving theorems. In addition to proof theory, we need semantics for deciding whether the things we prove actually make sense. For instance, we need to be sure that the truth of the theorems is assured by the truth of the axioms. If our inference rules guarantee this, they are said to be <em>sound</em>.
</section>
<section>
<h3>Soundness and completeness (ctd.)</h3>
But this will not be enough, because sound inference rules can be actually very weak, and unable to prove anything of interest. We also need to be sure that the inference rules are powerful enough to eventually prove any possible theorem: they should be <em>complete</em>.</p>
</section>
<section>
<h3>Meta-theory</h3>
<p>Concepts like soundness and completeness are called <em>meta-theoretical</em>, since they are not expressed <strong>in</strong> the logic under discussion, but rather belong to a theory <strong>about</strong> that logic (‘meta’ means above). Their significance is not merely theoretical, but extends to logic programming languages like Prolog. For example, if a logic programming language is unsound, it will give wrong answers to some queries; if it is incomplete, it will give no answer to some other queries.
</section>
<section>
<h3>Meta-theory (ctd.)</h3>
Ideally, a logic programming language should be sound and complete; in practice, this will not be the case. For instance, in the next chapter we will see that Prolog is both unsound and incomplete. This has been a deliberate design choice: a sound and complete Prolog would be much less efficient. Nevertheless, any Prolog programmer should know exactly the circumstances under which Prolog is unsound or incomplete, and avoid these circumstances in her programs.</p>
</section>
<section>
<h3>What this chapter is about</h3>
<p>The structure of this chapter is as follows. We start with a very simple (propositional) logical language, and enrich this language in two steps to full clausal logic. For each of these three languages, we discuss syntax, semantics, proof theory, and meta-theory. We then discuss definite clause logic, which is the subset of clausal logic used in Prolog. Finally, we relate clausal logic to Predicate Logic, and show that they are essentially equal in expressive power.</p>
</section>
</section>
<section>
<section>
<h3>2.1 Propositional clausal logic</h3>
</section>
<section>
<h3>Propositions</h3>
<p>Informally, a <em>proposition</em> is any statement which is either true or false, such as ‘2 + 2 = 4’ or ‘the moon is made of green cheese’. These are the building blocks of propositional logic, the weakest form of logic.</p>
</section>
</section>
<section>
<section>
<h4>Propositional Syntax</h4>
</section>
<section>
<h3>Atoms and clauses</h3>
<p>Propositions are abstractly denoted by <em>atoms</em>, which are single words starting with a lowercase character. For instance, <code>married</code> is an atom denoting the proposition ‘he/she is married’; similarly, <code>man</code> denotes the proposition ‘he is a man’. Using the special symbols ‘ <code>:-</code> ’ (<strong>if</strong>), ‘ <code>;</code> ’ (<strong>or</strong>) and ‘ <code>,</code> ’ (<strong>and</strong>), we can combine atoms to form <em>clauses</em>.
</section>
<section>
<h3>Atoms and clauses (ctd.)</h3>
For instance,</p>
<pre><code class="Prolog">married;bachelor:-man,adult
</code></pre>
<p>is a clause, with intended meaning: ‘somebody is married <strong>or</strong> a bachelor <strong>if</strong> he is a man <strong>and</strong> an adult’<span class="CustomFootnote">
<a href="#_ftn2" name="_ftnref2" title="">
<span class="MsoFootnoteReference">
<span class="AutoStyle13">
<span class="AutoStyle14">
[2]
</span>
</span>
</span>
</a>
</span>. The part to the left of the if-symbol ‘ <code>:-</code> ’ is called the <em>head</em> of the clause, and the right part is called the <em>body</em> of the clause. The head of a clause is always a disjunction (<strong>or</strong>) of atoms, and the body of a clause is always a conjunction (<strong>and</strong>).</p>
</section>
<section>
<h3>Atoms and clauses (ctd.)</h3>
<div class="extract exercise" id="2.1">
<div class="AutoStyle06">
<p class="exercise AutoStyle07">
<i>Exercise 2.1.</i> <p>Translate the following statements into clauses, using the atoms <code>person</code>, <code>sad</code> and <code>happy</code>:<br></p>
<ol>
<li>persons are happy or sad;</li>
<li>no person is both happy and sad;</li>
<li>sad persons are not happy;</li>
<li>non-happy persons are sad.</li>
</ol>
</p>
</div>
</div>
</section>
<section>
<h3>Programs</h3>
<p>A <em>program</em> is a set of clauses, each of them terminated by a period. The clauses are to be read conjunctively; for example, the program</p>
<pre><code class="Prolog">woman;man:-human.
human:-woman.
human:-man.
</code></pre>
<p>has the intended meaning ‘(<strong>if</strong> someone is human <strong>then</strong> she/he is a woman <strong>or</strong> a man) <strong>and</strong> (<strong>if</strong> someone is a woman <strong>then</strong> she is human) <strong>and</strong> (<strong>if</strong> someone is a man <strong>then</strong> he is human)’, or, in other words, ‘someone is human <strong>if and only if</strong> she/he is a woman <strong>or</strong> a man’.</p>
</section>
</section>
<section>
<section>
<h4>Propositional Semantics</h4>
</section>
<section>
<h3>Herbrand base and interpretation</h3>
<p>The <em>Herbrand base</em> of a program <em>P</em> is the set of atoms occurring in <em>P</em>. For the above program, the Herbrand base is { <code>woman</code>, <code>man</code>, <code>human</code> }. A <em>Herbrand interpretation</em> (or interpretation for short) for <em>P</em> is a mapping from the Herbrand base of <em>P</em> into the set of truth values { <strong>true</strong>, <strong>false</strong> }. For example, the mapping { <code>woman</code> → <strong>true</strong>, <code>man</code> → <strong>false</strong>, <code>human</code> → <strong>true</strong> } is a Herbrand interpretation for the above program. A Herbrand interpretation can be viewed as describing a possible state of affairs in the Universe of Discourse (in this case: ‘she is a woman, she is not a man, she is human’).
</section>
<section>
<h3>Herbrand base and interpretation (ctd.)</h3>
Since there are only two possible truth values in the semantics we are considering, we could abbreviate such mappings by listing only the atoms that are assigned the truth value <strong>true</strong>; by definition, the remaining ones are assigned the truth value <strong>false</strong>. Under this convention, which we will adopt in this book, a Herbrand interpretation is simply a subset of the Herbrand base. Thus, the previous Herbrand interpretation would be represented as { <code>woman</code>, <code>human</code> }.</p>
</section>
<section>
<h3>Truth conditions</h3>
<p>Since a Herbrand interpretation assigns truth values to every atom in a clause, it also assigns a truth value to the clause as a whole. The rules for determining the truth value of a clause from the truth values of its atoms are not so complicated, if you keep in mind that the body of a clause is a conjunction of atoms, and the head is a disjunction. Consequently, the body of a clause is <strong>true</strong> if every atom in it is <strong>true</strong>, and the head of a clause is <strong>true</strong> if at least one atom in it is <strong>true</strong>.
</section>
<section>
<h3>Truth conditions (ctd.)</h3>
In turn, the truth value of the clause is determined by the truth values of head and body. There are four possibilities:</p>
<ol>
<li>the body is <strong>true</strong>, and the head is <strong>true</strong>;</li>
<li>the body is <strong>true</strong>, and the head is <strong>false</strong>;</li>
<li>the body is <strong>false</strong>, and the head is <strong>true</strong>;</li>
<li>the body is <strong>false</strong>, and the head is <strong>false</strong>.</li>
</ol>
<p>The intended meaning of the clause is ‘ <strong>if</strong> body <strong>then</strong> head’, which is obviously <strong>true</strong> in the first case, and <strong>false</strong> in the second case.</p>
</section>
<section>
<h3>Positive and negative literals</h3>
<p>What about the remaining two cases? They cover statements like ‘ <strong>if</strong> the moon is made of green cheese <strong>then</strong> 2 + 2 = 4’, in which there is no connection at all between body and head. One would like to say that such statements are neither <strong>true</strong> nor <strong>false</strong>. However, our semantics is not sophisticated enough to deal with this: it simply insists that clauses should be assigned a truth value in every possible interpretation. Therefore, we consider the clause to be <strong>true</strong> whenever its body is <strong>false</strong>.
</section>
<section>
<h3>Positive and negative literals (ctd.)</h3>
It is not difficult to see that under these truth conditions a clause is equivalent with the statement ‘head <strong>or not</strong> body’. For example, the clause <code>married;bachelor:-man,adult</code> can also be read as ‘someone is married <strong>or</strong> a bachelor <strong>or not</strong> a man <strong>or not</strong> an adult’. Thus, a clause is a disjunction of atoms, which are negated if they occur in the body of the clause. Therefore, the atoms in the body of the clause are often called <em>negative literals</em>, while those in the head of the clause are called <em>positive literals</em>.</p>
</section>
<section>
<h3>Summary so far</h3>
<p>To summarise: a clause is assigned the truth value <strong>true</strong> in an interpretation, if and only if at least one of the following conditions is true: (<em>a</em>) at least one atom in the body of the clause is <strong>false</strong> in the interpretation (cases (3) and (4)), or (<em>b</em>) at least one atom in the head of the clause is <strong>true</strong> in the interpretation (cases (1) and (3)). If a clause is <strong>true</strong> in an interpretation, we say that the interpretation is a <em>model</em> for the clause.
</section>
<section>
<h3>Summary so far (ctd.)</h3>
An interpretation is a model for a program if it is a model for each clause in the program. For example, the above program has the following models: ∅ (the empty model, assigning <strong>false</strong> to every atom), { <code>woman</code>, <code>human</code> }, { <code>man</code>, <code>human</code> }, and { <code>woman</code>, <code>man</code>, <code>human</code> }. Since there are eight possible interpretations for a Herbrand base with three atoms, this means that the program contains enough information to rule out half of these.</p>
</section>
<section>
<h3>Logical consequence</h3>
<p>Adding more clauses to the program means restricting its set of models. For instance, if we add the clause <code>woman</code> (a clause with an empty body) to the program, we rule out the first and third model, which leaves us with the models { <code>woman</code>, <code>human</code> }, and { <code>woman</code>, <code>man</code>, <code>human</code> }. Note that in both of these models, <code>human</code> is <strong>true</strong>. We say that <code>human</code> is a logical consequence of the set of clauses. In general, a clause <em>C</em> is a <em>logical consequence</em> of a program <em>P</em> if every model of the program is also a model of the clause; we write <em>P</em> ⊨ <em>C</em>.</p>
</section>
<section>
<h3>Logical consequence (ctd.)</h3>
<div class="extract exercise" id="2.2">
<div class="AutoStyle06">
<p class="exercise AutoStyle07">
<i>Exercise 2.2.</i> <p>Given the program<br></p>
<p><code>married;bachelor:-man,adult.
man.
:-bachelor.</code>
determine which of the following clauses are logical consequences of this program:<br>
1. <code>married:-adult</code>;
2. <code>married:-bachelor</code>;
3. <code>bachelor:-man</code>;
4. <code>bachelor:-bachelor</code>.</p>
</p>
</div>
</div>
</section>
<section>
<h3>Intended model</h3>
<p>Of the two remaining models, obviously { <code>woman</code>, <code>human</code> } is the intended one; but the program does not yet contain enough information to distinguish it from the non-intended model { <code>woman</code>, <code>man</code>, <code>human</code> }. We can add yet another clause, to make sure that the atom <code>man</code> is mapped to <strong>false</strong>. For instance, we could add</p>
<pre><code class="Prolog">:-man
</code></pre>
<p>(it is not a man) or</p>
<pre><code class="Prolog">:-man,woman
</code></pre>
<p>(nobody is both a man and a woman).
</section>
<section>
<h3>Intended model (ctd.)</h3>
However, explicitly stating everything that is false in the intended model is not always feasible. Consider, for example, an airline database consulted by travel agencies: we simply want to say that if a particular flight (i.e., a combination of plane, origin, destination, date and time) is not listed in the database, then it does not exist, instead of listing all the dates that a particular plane does <strong>not</strong> fly from Amsterdam to London.</p>
</section>
<section>
<h3>Minimal model</h3>
<p>So, instead of adding clauses until a single model remains, we want to add a rule to our semantics which tells us which of the several models is the intended one. The airline example shows us that, in general, we only want to accept something as <strong>true</strong> if we are really forced to, i.e. if it is <strong>true</strong> in every possible model. This means that we should take the intersection of every model of a program in order to construct the intended model. In the example, this is { <code>woman</code>, <code>human</code> }. Note that this model is <em>minimal</em> in the sense that no subset of it is also a model. Therefore, this semantics is called a <em>minimal model semantics</em>.</p>
</section>
<section>
<h3>Indefinite clauses</h3>
<p>Unfortunately, this approach is only applicable to a restricted class of programs. Consider the following program:</p>
<pre><code class="Prolog">woman;man:-human.
human.
</code></pre>
<p>This program has three models: { <code>woman</code>, <code>human</code> }, { <code>man</code>, <code>human</code> }, and { <code>woman</code>, <code>man</code>, <code>human</code> }. The intersection of these models is { <code>human</code> }, but this interpretation is not a model of the first clause! The program has in fact not one, but <strong>two</strong> minimal models, which is caused by the fact that the first clause has a disjunctive head. Such a clause is called <em>indefinite</em>, because it does not permit definite conclusions to be drawn.</p>
</section>
<section>
<h3>Definite clauses</h3>
<p>On the other hand, if we would only allow <em>definite</em> clauses, i.e. clauses with a single positive literal, minimal models are guaranteed to be unique. We will deal with definite clauses in section 2.4, because Prolog is based on definite clause logic. In principle, this means that clauses like <code>woman;man:-human</code> are not expressible in Prolog. However, such a clause can be transformed into a ‘pseudo-definite’ clause by moving one of the literals in the head to the body, extended with an extra negation.
</section>
<section>
<h3>Definite clauses (ctd.)</h3>
This gives the following two possibilities:</p>
<pre><code class="Prolog">woman:-human,not(man).
man:-human,not(woman).
</code></pre>
<p>In Prolog, we have to choose between these two clauses, which means that we have only an approximation of the original indefinite clause. Negation in Prolog is an important subject with many aspects. In Chapter 3, we will show how Prolog handles negation in the body of clauses. In Chapter 8, we will discuss particular applications of this kind of negation.</p>
</section>
</section>
<section>
<section>
<h4>Propositional Proof theory</h4>
</section>
<section>
<h3>Computing logical consequence</h3>
<p>Recall that a clause <em>C</em> is a logical consequence of a program <em>P</em> (<em>P</em> ⊨ <em>C</em>) if every model of <em>P</em> is a model of <em>C</em>. Checking this condition is, in general, unfeasible. Therefore, we need a more efficient way of computing logical consequences, by means of inference rules. If <em>C</em> can be derived from <em>P</em> by means of a number of applications of such inference rules, we say that <em>C</em> can be <em>proved</em> from <em>P</em>. Such inference rules are purely syntactic, and do not refer to any underlying semantics.</p>
</section>
<section>
<h3>Resolution</h3>
<p>The proof theory for clausal logic consists of a single inference rule called <em>resolution</em>. Resolution is a very powerful inference rule. Consider the following program:</p>
<pre><code class="Prolog">married;bachelor:-man,adult.
has_wife:-man,married.
</code></pre>
<p>This simple program has no less than 26 models, each of which needs to be considered if we want to check whether a clause is a logical consequence of it.</p>
</section>
<section>
<h3>Resolution (ctd.)</h3>
<div class="extract exercise" id="2.3">
<div class="AutoStyle06">
<p class="exercise AutoStyle07">
<i>Exercise 2.3.</i> <p>Write down the six Herbrand interpretations that are not models of the program.</p>
</p>
</div>
</div>
</section>
<section>
<h3>Resolving upon a literal</h3>
<p>The following clause is a logical consequence of this program:</p>
<pre><code class="Prolog">has_wife;bachelor:-man,adult
</code></pre>
<p>By means of resolution, it can be produced in a single step. This step represents the following line of reasoning: ‘if someone is a man and an adult, then he is a bachelor or married; but if he is married, he has a wife; therefore, if someone is a man and an adult, then he is a bachelor or he has a wife’.
</section>
<section>
<h3>Resolving upon a literal (ctd.)</h3>
In this argument, the two clauses in the program are related to each other by means of the atom <code>married</code>, which occurs in the head of the first clause (a positive literal) and in the body of the second (a negative literal). The derived clause, which is called the <em>resolvent</em>, consists of all the literals of the two input clauses, except <code>married</code> (the literal <em>resolved upon</em>). The negative literal <code>man</code>, which occurs in both input clauses, appears only once in the derived clause. This process is depicted in fig. 2.1.</p>
</section>
<section>
<h3>Resolving upon a literal (ctd.)</h3>
<div id="2.1">
<img src="img/figure/image016.svg" height="60%"/>
<p>
<b>Figure 2.1.</b> <p>A resolution step.</p>
</p>
</div>
</section>
<section>
<h3>Unfolding</h3>
<p>Resolution is most easily understood when applied to definite clauses. Consider the following program:</p>
<pre><code class="Prolog">square:-rectangle,equal_sides.
rectangle:-parallelogram,right_angles.
</code></pre>
<p>Applying resolution yields the clause</p>
<pre><code class="Prolog">square:-parallelogram,right_angles,equal_sides
</code></pre>
</section>
<section>
<h3>Unfolding (ctd.)</h3>
<p>That is, the atom <code>rectangle</code> in the body of the first clause is replaced by the body of the second clause (which has <code>rectangle</code> as its head). This process is also referred to as <em>unfolding</em> the second clause into the first one (fig. 2.2).</p>
<div id="2.2">
<img src="img/figure/image018.svg" height="60%"/>
<p>
<b>Figure 2.2.</b> <p>Resolution with definite clauses.</p>
</p>
</div>
</section>
<section>
<h3>Derivation</h3>
<p>A resolvent resulting from one resolution step can be used as input for the next. A <em>proof</em> or <em>derivation</em> of a clause <em>C</em> from a program <em>P</em> is a sequence of clauses such that each clause is either in the program, or the resolvent of two previous clauses, and the last clause is <em>C</em>. If there is a proof of <em>C</em> from <em>P</em>, we write <em>P</em> ⊢ <em>C</em>.</p>
</section>
<section>
<h3>Derivation (ctd.)</h3>
<div class="extract exercise" id="2.4">
<div class="AutoStyle06">
<p class="exercise AutoStyle07">
<i>Exercise 2.4.</i> <p>Give a derivation of <code>friendly</code> from the following program:<br></p>
<p><code>happy;friendly:-teacher.
friendly:-teacher,happy.
teacher;wise.
teacher:-wise.</code></p>
</p>
</div>
</div>
</section>
</section>
<section>
<section>
<h4>Propositional Meta-theory</h4>
</section>
<section>
<h3>Soundness of propositional resolution</h3>
<p>It is easy to show that propositional resolution is <strong>sound</strong>: you have to establish that every model for the two input clauses is a model for the resolvent. In our earlier example, every model of <code>married;bachelor:-man,adult</code> and <code>has_wife:-man,married</code> must be a model of <code>has_wife;bachelor:-man,adult</code>.
</section>
<section>
<h3>Soundness of propositional resolution (ctd.)</h3>
Now, the literal resolved upon (in this case <code>married</code>) is either assigned the truth value <strong>true</strong> or <strong>false</strong>. In the first case, every model of <code>has_wife:-man,married</code> is also a model of <code>has_wife:-man</code>; in the second case, every model of <code>married;bachelor:-man,adult</code> is also a model of <code>bachelor:-man,adult</code>. In both cases, these models are models of a subclause of the resolvent, which means that they are also models of the resolvent itself.</p>
</section>
<section>
<h3>Incompleteness of propositional resolution</h3>
<p>In general, proving <strong>completeness</strong> is more complicated than proving soundness. Still worse, proving completeness of resolution is impossible, because resolution is not complete at all!
</section>
<section>
<h3>Incompleteness of propositional resolution (ctd.)</h3>
For instance, consider the clause <code>a:-a</code>. This clause is a so-called <em>tautology</em>: it is true under any interpretation. Therefore, any model of an arbitrary program <em>P</em> is a model for it, and thus <em>P</em> = <code>a:-a</code> for any program <em>P</em>. If resolution were complete, it would be possible to derive the clause <code>a:-a</code> from some program <em>P</em> in which the literal <code>a</code> doesn’t even occur! It is clear that resolution is unable to do this.</p>
</section>
<section>
<h3>A form of completeness</h3>
<p>However, this is not necessarily bad, because although tautologies follow from any set of clauses, they are not very interesting. Resolution makes it possible to guide the inference process, by implementing the question ‘is <em>C</em> a logical consequence of <em>P</em>?’ rather than ‘what are the logical consequences of <em>P</em>?’.
</section>
<section>
<h3>A form of completeness (ctd.)</h3>
We will see that, although resolution is unable to generate every logical consequence of a set of clauses, it is complete in the sense that resolution can always determine whether a specific clause is a logical consequence of a set of clauses.</p>
</section>
<section>
<h3>Reduction to the absurd</h3>
<p>The idea is analogous to a proof technique in mathematics called ‘reduction to the absurd’. Suppose for the moment that <em>C</em> consists of a single positive literal <code>a</code>; we want to know whether <em>P</em> ⊨ <code>a</code>, i.e. whether every model of <em>P</em> is also a model of <code>a</code>. It is easily checked that an interpretation is a model of <code>a</code> if, and only if, it is <strong>not</strong> a model of <code>:-a</code>.
</section>
<section>
<h3>Reduction to the absurd (ctd.)</h3>
Therefore, every model of <em>P</em> is a model of <code>a</code> if, and only if, there is no interpretation which is a model of both <code>:-a</code> and <em>P</em>. In other words, <code>a</code> is a logical consequence of <em>P</em> if, and only if, <code>:-a</code> and <em>P</em> are mutually <em>inconsistent</em> (don’t have a common model). So, checking whether <em>P</em> ⊨ <code>a</code> is equivalent to checking whether <em>P</em> ∪ { <code>:-a</code> } is inconsistent.</p>
</section>
<section>
<h3>Proof by refutation</h3>
<p>Resolution provides a way to check this condition. Note that, since an inconsistent set of clauses doesn’t have a model, it trivially satisfies the condition that any model of it is a model of any other clause; therefore, an inconsistent set of clauses has every possible clause as its logical consequence. In particular, the absurd or <em>empty</em> clause, denoted by □<span class="CustomFootnote">
<a href="#_ftn3" name="_ftnref3" title="">
<span class="MsoFootnoteReference">
<span class="AutoStyle13">
<span class="AutoStyle14">
[3]
</span>
</span>
</span>
</a>
</span>, is a logical consequence of an inconsistent set of clauses. Conversely, if □ is a logical consequence of a set of clauses, we know it must be inconsistent.
</section>
<section>
<h3>Proof by refutation (ctd.)</h3>
Now, resolution is complete in the sense that <em>if P set of clauses is inconsistent, it is always possible to derive □ by resolution</em>. Since resolution is sound, we already know that if we can derive □ then the input clauses must be inconsistent. So we conclude: <code>a</code> is a logical consequence of <em>P</em> if, and only if, the empty clause can be deduced by resolution from <em>P</em> augmented with <code>:-a</code>. This process is called <em>proof by refutation</em>, and resolution is called <em>refutation complete</em>.</p>
</section>
<section>
<h3>Proving a clause by refutation</h3>
<p>This proof method can be generalised to the case where <em>B</em> is not a single atom. For instance, let us check by resolution that <code>a:-a</code> is a tautology, i.e. a logical consequence of any set of clauses. Logically speaking, this clause is equivalent to ‘ <code>a</code> <strong>or not</strong> <code>a</code> ’, the negation of which is ‘ <strong>not</strong> <code>a</code> <strong>and</strong> <code>a</code> ’, which is represented by two separate clauses <code>:-a</code> and <code>a</code>. Since we can derive the empty clause from these two clauses in a single resolution step without using any other clauses, we have in fact proved that <code>a:-a</code> is a logical consequence of an empty set of clauses, hence a tautology.</p>
</section>
<section>
<h3>Proving a clause by refutation (ctd.)</h3>
<div class="extract exercise" id="2.5">
<div class="AutoStyle06">
<p class="exercise AutoStyle07">
<i>Exercise 2.5.</i> <p>Prove by refutation that <code>friendly:-has_friends</code> is a logical consequence of the following clauses:<br></p>
<p><code>happy:-has_friends.
friendly:-happy.</code></p>
</p>
</div>
</div>
</section>
<section>
<h3>Proving consistency is harder</h3>
<p>Finally, we mention that although resolution can always be used to prove inconsistency of a set of clauses it is not always fit to prove the opposite, i.e. consistency of a set of clauses. For instance, <code>a</code> is not a logical consequence of <code>a:-a</code>; yet, if we try to prove the inconsistency of <code>:-a</code> and <code>a:-a</code> (which should fail) we can go on applying resolution forever!
</section>
<section>
<h3>Proving consistency is harder (ctd.)</h3>
The reason, of course, is that there is a loop in the system: applying resolution to <code>:-a</code> and <code>a:-a</code> again yields <code>:-a</code>. In this simple case it is easy to check for loops: just maintain a list of previously derived clauses, and do not proceed with clauses that have been derived previously.</p>
</section>
<section>
<h3>Decidability</h3>
<p>However, as we will see, this is not possible in the general case of full clausal logic, which is <em>semi-decidable</em> with respect to the question ‘is <em>B</em> a logical consequence of <em>A</em> ’: there is an algorithm which derives, in finite time, a proof if one exists, but there is no algorithm which, for any <em>A</em> and <em>B</em>, halts and returns ‘no’ if no proof exists. The reason for this is that interpretations for full clausal logic are in general infinite. As a consequence, some Prolog programs may loop forever (just like some Pascal programs).
</section>
<section>
<h3>Decidability (ctd.)</h3>
One might suggest that it should be possible to check, just by examining the source code, whether a program is going to loop or not, but, as Alan Turing showed, this is, in general, impossible (the Halting Problem). That is, you can write programs for checking termination of programs, but for any such termination checking program you can write a program on which it will not terminate itself!</p>
</section>
</section>
<section>
<section>
<h3>2.2 Relational clausal logic</h3>
</section>
<section>
<h3>Why we need variables</h3>
<p>Propositional clausal logic is rather coarse-grained, because it takes propositions (i.e. anything that can be assigned a truth value) as its basic building blocks. For example, it is not possible to formulate the following argument in propositional logic:</p>
<blockquote>
<p>Peter likes all his students<br />
Maria is one of Peter’s students<br />
Therefore, Peter likes Maria</p>
</blockquote>
</section>
<section>
<h3>Why we need variables (ctd.)</h3>
<p>In order to formalise this type of reasoning, we need to talk about individuals like Peter and Maria, sets of individuals like Peter’s students, and relations between individuals, such as ‘likes’. This refinement of propositional clausal logic leads us into relational clausal logic.</p>
</section>
</section>
<section>
<section>
<h4>Relational Syntax</h4>
</section>
<section>
<h3>Constants, variables, and terms</h3>
<p>Individual names are called <em>constants</em>; we follow the Prolog convention of writing them as single words starting with a lowercase character (or as arbitrary strings enclosed in single quotes, like <code>'this is a constant'</code>). Arbitrary individuals are denoted by <em>variables</em>, which are single words starting with an uppercase character. Jointly, constants and variables are denoted as <em>terms</em>. A <em>ground</em> term is a term without variables<span class="CustomFootnote">
<a href="#_ftn4" name="_ftnref4" title="">
<span class="MsoFootnoteReference">
<span class="AutoStyle13">
<span class="AutoStyle14">
[4]
</span>
</span>
</span>
</a>
</span>.</p>
</section>
<section>
<h3>Predicates</h3>
<p>Relations between individuals are abstractly denoted by <em>predicates</em> (which follow the same notational conventions as constants). An <em>atom</em> is a predicate followed by a number of terms, enclosed in brackets and separated by commas, e.g. <code>likes(peter,maria)</code>. The terms between brackets are called the <em>arguments</em> of the predicate, and the number of arguments is the predicate’s <em>arity</em>. The arity of a predicate is assumed to be fixed, and predicates with the same name but different arity are assumed to be different. A <em>ground</em> atom is an atom without variables.</p>
</section>
<section>
<h3>Clauses and programs</h3>
<p>All the remaining definitions pertaining to the syntax of propositional clausal logic, in particular those of literal, clause and program, stay the same. So, the following clauses are meant to represent the above statements:</p>
<div class="extract swish" id="2.2.1">
<pre class="source swish temp AutoStyle03" data-variant-id="group-1" id="swish.2.2.1" query-text="?-likes(peter,S). ?-likes(T,maria). ?-likes(T,S).">
likes(peter,S):-student_of(S,peter).
student_of(maria,peter).
</pre>
</div>
</section>
<section>
<h3>Clauses and programs (ctd.)</h3>
<p>The intended meaning of these clauses are, respectively, ‘ <strong>if</strong> <em>S</em> is a student of Peter <strong>then</strong> Peter likes <em>S</em> ’, ‘Maria is a student of Peter’, and ‘Peter likes Maria’. Clearly, we want our logic to be such that the third clause follows logically from the first two, and we want to be able to prove this by resolution. Therefore, we must extend the semantics and proof theory in order to deal with variables.</p>
</section>