Tutorial Letter 101/0/2022: Formal Logic
Tutorial Letter 101/0/2022: Formal Logic
Tutorial Letter 101/0/2022: Formal Logic
Formal Logic
COS4807
Year module
CONTENTS
General module information and assignments
university
Define Tomorrow. of south africa
CONTENTS
Page
1 INTRODUCTION .........................................................................................4
2 ABOUT THIS MODULE ...............................................................................4
2.1 Purpose .......................................................................................................................... 4
2.2 Syllabus.......................................................................................................................... 4
2.3 Outcomes ....................................................................................................................... 4
3 CONTACT DETAILS ....................................................................................5
3.1 Lecturer ......................................................................................................................... 5
3.2 Department and School ................................................................................................... 5
3.3 University ....................................................................................................................... 5
4 MODULE-RELATED RESOURCES ...............................................................5
4.1 Tutorial letters ................................................................................................................ 6
4.2 Prescribed book .............................................................................................................. 6
4.3 Software for practical work .............................................................................................. 6
4.4 Recommended books ....................................................................................................... 7
5 STUDENT SUPPORT SERVICES .................................................................7
5.1 First-year experience programme ..................................................................................... 7
5.2 myUnisa ......................................................................................................................... 7
5.3 myLife ........................................................................................................................... 7
6 CURRICULUM TRANSFORMATION ..........................................................8
7 STUDY PLAN ..............................................................................................8
8 ASSESSMENT ..............................................................................................8
8.1 Assignment numbers and due dates .................................................................................. 8
8.2 Submission of assignments ............................................................................................... 9
8.3 Year mark, exam mark and final mark ............................................................................. 9
8.4 Examination admission.................................................................................................... 9
8.5 Examination information ................................................................................................. 9
9 ASSIGNMENTS .......................................................................................... 10
Assignment 1 .............................................................................................................................10
Assignment 2 .............................................................................................................................11
2
COS4807/101/0/2022
Assignment 3 .............................................................................................................................13
Assignment 4 .............................................................................................................................14
3
1 INTRODUCTION
Welcome to COS4807. This module provides an introduction to formal logic. For this field of study,
you need a background in discrete mathematics, covered by a course like our undergraduate module
COS1501. In particular, we assume that you are familiar with set theory and mathematical proof
techniques. The study of formal logic requires a high level of mathematical rigour, so if you coped well
with mathematics at school or at undergraduate level, then you should have an aptitude for formal
logic too. If you have never encountered formal logic before, you should find the prescribed book for
our second-year logic module, COS2661, helpful. (See the book by Barwise and Etchemendy, listed
as additional reading in Section 4.4 below.)
2.2 Syllabus
The following aspects of propositional and first-order logic are covered in COS4807:
2.3 Outcomes
To cover the abovementioned syllabus, the following techniques of formal logic need to be mastered:
Propositional logic:
Use truth tables to show the validity or satisfiability of formulas.
Give semantic arguments to prove the validity or unsatisfiability of formulas.
4
COS4807/101/0/2022
3 CONTACT DETAILS
3.1 Lecturer
The lecturer responsible for this module this year will be specified on the COS4807 website on myUnisa.
See Section 5.2 below for information about accessing this website.
Feel free to direct queries about the content of this module to your lecturer. However, queries of
a purely administrative nature should be addressed to the relevant departments of Unisa. See Section
3.3 below.
3.3 University
If you need to contact Unisa about matters not related to the content of this module, please consult
the Study@Unisa brochure. This brochure is available from the myUnisa website, in particular on
the Student Support & Regions link. This brochure contains information on how to contact Unisa (e.g.
who to write to for different queries, important telephone and fax numbers, addresses and details of
the times certain facilities are open).
4 MODULE-RELATED RESOURCES
COS4807 is presented online. This means that you will not receive study material for this module in
printed form. It will all be available in electronic format on myUnisa (see Section 5.2 below).
5
4.1 Tutorial letters
For COS4807, communication about teaching, learning and assessment is in the form of tutorial
letters which will be made available on myUnisa during the year. Tutorial Letter 101 is available in
the Official Study Material folder for COS4807, and all the other tutorial letters will be made available
in Additional Resources (see Section 5.2).
Tutorial Letter 101 (this tutorial letter) contains important information about the syllabus,
the prescribed book and other resources for this module. This tutorial letter also specifies the
assignments as well as instructions for their submission.
Tutorial Letter 102 contains additional notes on the prescribed book, indicating which parts are
important and which parts are for interest only. It also contains a number of worked examples
similar to those you can expect in the assignments and the exams.
Tutorial Letter 103 contains instructions for installing and using the SWI-Prolog and LearnSAT
software required for Assignment 2.
Tutorial Letter 104 will probably contain examination information, and will be available later
in the year.
Tutorial Letters 201, 202, 203 and 204 contain solutions to assignments, and will be made
available about two weeks after the due dates of the corresponding assignments.
Ben-Ari, M. Mathematical Logic for Computer Science, 3rd edition. Springer-Verlag, 2012.
You need your own copy of this book, and you should make it a priority to get hold of it as soon
as possible. Prescribed books can be obtained from Unisa’s official booksellers. Consult the list of
official booksellers and their addresses listed in the brochure Study@Unisa. If you have difficulty in
locating this book at these booksellers, please contact the Prescribed Book Section at Tel: 012 429
4152 or email: vospresc@unisa.ac.za
The following chapters of the prescribed book cover the syllabus (specified in Section 2.2 above):
Propositional logic: Chapters 1, 2, 3, 4 and 6. You can omit Sections 3.3 to 3.9 and 6.6.
First-order logic: Chapters 7, 8, 9, 10 and 11. You can omit Sections 8.2 to 8.5 and 11.4.
Please note that the chapter and section numbers of the prescribed book used in this (and subsequent)
tutorial letters refer to the 3rd edition, and differ from previous editions.
6
COS4807/101/0/2022
Barwise, J & Etchemendy, J. The Language of First-Order Logic, 3rd ed. CSLI, 1992.
Burke, E & Foxley, E. Logic and its Applications. Prentice Hall, 1996.
Fitting, M. First-Order Logic and Automated Theorem Proving. Springer-Verlag, 1996.
Ginsberg, M. Essentials of Artificial Intelligence. Morgan Kaufmann, 1993.
Nerode, A & Shore, RA. Logic for Applications. Springer-Verlag, 1997.
Russell, S & Norvig, P. Artificial Intelligence: A Modern Approach, 3rd ed. Prentice Hall,
2010.
Shinghal, R. Formal Concepts in Artificial Intelligence. Chapman & Hall, 1992.
5.2 myUnisa
The myUnisa learning management system is Unisa’s online campus. It is intended to help you to
communicate with your lecturers, with other students and with the administrative departments of
Unisa by means of the internet. In particular, you can download study material and submit your
assignments on myUnisa. The web address for myUnisa is http://my.unisa.ac.za/.
Each module at Unisa has a website on myUnisa. You will be given access to the websites of
the modules you are registered for for the year.
Please consult Study@Unisa for more information on myUnisa.
Amongst other tools, a discussion forum is provided for COS4807 on the myUnisa website. We
encourage you to make use of this discussion forum, as it provides an excellent means of discussing
the work with your fellow students.
5.3 myLife
As explained in Study@Unisa, every student at Unisa is given a myLife email account. We encourage
you to make use of your myLife account, or at least to forward your myLife email to your personal
email address (as explained in Study@Unisa). From time to time, we send emails to the myLife
accounts of all students registered for CO4807. Also, whenever COS4807 tutorial matter is uploaded
7
to myUnisa, an email is automatically sent to all students. If you are not monitoring your myLife
email, you could miss some important announcements.
6 CURRICULUM TRANSFORMATION
Unisa has implemented a transformation charter, and curriculum transformation has consequently
been placed high on the teaching and learning agenda. Curriculum transformation includes student-
centred scholarship, the pedagogical renewal of teaching and assessment practices, the scholarship of
teaching and learning, and the infusion of African epistemologies and philosophies. These pillars and
their principles will be integrated at both programme and module levels in a phased-in approach. You
may therefore notice a change in the teaching and learning strategy implemented by Unisa, together
with how the content is conceptualised in your modules. We encourage you to embrace these changes
during your studies at Unisa in a responsive way within the framework of transformation.
7 STUDY PLAN
The learning outcomes of COS4807 (specified in Section 2.3 above) are covered by four assignments.
We recommend that you work through the material for each assignment (in the relevant chapters
of the prescribed book and the corresponding sections of Tutorial Letter 102) at least two weeks before
the due date of each assignment, to give you enough time to complete and submit the assignment.
(See Table 1 below for the assignment due dates.)
After submitting the last assignment, you should spend time revising your work in preparation
for the exam. A special tutorial letter about preparation for the exam will be made available at this
time.
8 ASSESSMENT
Assessment for COS4807 is on the basis of four assignments and an examination. The assignments
count towards a year mark, which together with the exam mark contribute to a final mark. (Section
9 below contains the assignment questions.)
Every assignment has a number, namely 1, 2, 3 or 4. Please submit each assignment with the correct
number, even if it is not the first, second, third or fourth assignment that you submit.
8
COS4807/101/0/2022
Table 1 also gives the due dates of the assignments. For COS4807 there is an automatic extension
of two weeks for every assignment. Please note that we can give no guarantee that assignments received
after this extension will be marked or contribute to your year mark. (See Section 8.3 below.)
You must submit at least one assignment by its due date to be admitted to the exam. (See
Section 8.4 below.)
The year mark contributes 20% and the exam mark 80% to the final mark. In other words, your final
mark for the module as a whole will be calculated according to the following formula:
1
Please check this date on the academic calendar.
9
9 ASSIGNMENTS
ASSIGNMENT 1
Due Date: 29 April 2022
Question 1 (20)
Use truth tables to prove that the following propositional formulas have the corresponding properties.
In each case, also explain why the truth table proves that the formula has the relevant property.
(i) (p ∧ q) ↔ ¬(p → ¬q) is valid.
(ii) (p → q) ∧ (p → (q → r)) ∧ ¬(p → r) is unsatisfiable.
(iii) p → (q ∨ (p ∧ r)) is satisfiable and is falsifiable.
Question 2 (20)
Prove that the formulas given in Question 1 (i) and (ii) above have the corresponding properties, by
means of semantic arguments (in terms of the truth values of formulas, and the definitions of validity
and satisfiability).
Question 3 (20)
Prove Theorems 2.53 and 2.54 in the prescribed book.
Question 4 (30)
Prove that the propositional formulas given in Question 1 (i), (ii) and (iii) above have the corresponding
properties, by means of semantic tableaux.
Question 5 (10)
Prove that the formula given in Question 1 (i) above is a theorem of the Gentzen system G . Annotate
each step with the rule used, and the step numbers it was applied to.
10
COS4807/101/0/2022
ASSIGNMENT 2
Due Date: 15 June 2022
Question 1 (10)
Convert the formula p → (q ↔ (p ∧ r)) to CNF. Show your working.
Write this in clausal form and remove trivial clauses. Finally, write your answer in (abbreviated)
clausal form.
Question 2 (10)
Prove by resolution refutation that the set of clauses {p̄qs, pr̄, pqr, q̄r̄s̄} is satisfiable.
Question 3 (15)
Show that the goal p ∧ q ∧ r is a logical consequence of the set of formulas {p → r, (p → q) → r, ¬(q →
r)} by means of resolution refutation.
Hint: Convert each of the formulas in the set as well as the negation of the goal to clausal form.
Then perform resolution refutation on all these clauses.
Question 4 (25)
Consider the graph-colouring problem described in Exercise 6.4 of the prescribed book. Use the DPLL
algorithm by hand to show that the graph K4 is 4-colourable. K4 is the complete graph with 4 vertices.
This is what it looks like:
3 4
Hint: Use the notation pij for a propositional atom to represent whether vertex i is coloured by colour
j. You need to encode the following constraints as a set of clauses:
(a) Every vertex must be coloured by some colour (1, 2, 3 or 4).
(b) No vertex may be coloured by more than one colour.
(c) No adjacent vertices may be coloured by the same colour.
Show your working by specifying the set of clauses after each series of propagation.
What solution is generated by your application of the DPLL algorithm?
Question 5 (20)
(i) Specify the constraints of the graph colouring problem in Question 4 above as a predicate in a
Prolog program, similar to the pigeon-hole example distributed with the LearnSAT code. But
use atoms of the format pij to represent whether vertex i is coloured by colour j. Call the
predicate tetra4.
11
(ii) Use the LearnSAT system to show that the graph is 4-colourable. Save the trace of the execution
to a text file.
(iii) Add another predicate to the Prolog program you wrote, called tetra3. It should encode the
problem for testing whether the same graph is 3-colourable. (Hint: Copy and edit tetra4 for
this purpose.)
(iv) Use the LearnSAT system to show that the graph is not 3-colourable. Save the trace of the
execution to a text file.
Submit the contents of the files as part of your answer. Also explain the output of the execution of
the two predicates.
Question 6 (15)
There are a number of example SAT problems provided with the LearnSAT distribution. One of the
files is called mcgregor.pro. Change the filename to mcgregor.pl and use LearnSAT to evaluate it.
This file contains an encoding of a simplified version of the McGregor graph, where the colours
1, 2, 3 or 4 are used to colour the graph. The file learnsat-tutorial.pdf (also provided with the
LearnSAT distribution) contains a discussion of the McGregor problem, and gives a map representation
of the simplified McGregor graph.
(ii) Submit the output (i.e. trace) of the execution of the mcgregor4 predicate.
What solution is generated by the execution of this code?
(iii) Execute the mcgregor3 predicate and comment on the differences between mcgregor3 and
mcgregor4 in terms of their encoding and their output.
12
COS4807/101/0/2022
ASSIGNMENT 3
Due Date: 15 August 2022
Question 1 (20)
Provide semantic arguments (in terms of the truth values of formulas, and the definitions of validity
and satisfiability) to prove that the following first-order formulas have the corresponding properties:
(i) ∀x(p(x) ↔ q(x)) ∧ ∃x(p(x) ∧ ¬q(x)) is unsatisfiable.
(ii) ∀x(p(x) ∨ q(x)) → ∃x(p(x) ∨ ∀xq(x)) is valid.
Question 2 (10)
Show that the formula ∃x(p(x) ∨ ∀xq(x)) → ∀x(p(x) ∨ q(x)), is satisfiable and falsifiable by giving
appropriate interpretations using the natural numbers N as domain.
Explain why your interpretations satisfy and falsify the formula, respectively.
Question 3 (15)
(i) Prove the following (simplification of the second part of Theorem 7.22):
Let A(x) be a non-closed formula and let IA be an interpretation. Then:
vσIA (A(x)) = T for some assignment σIA iff vIA (∃xA(x)) = T .
(ii) Provide an argument why the following corollary of the above statement holds:
Let A(x) be a non-closed formula and let IA be an interpretation. Then:
vσIA (A(x)) = F for all assignments σIA iff vIA (∃xA(x)) = F .
Question 4 (25)
Prove that the formulas given in Question 1 (i) and (ii) above have the corresponding properties by
means of semantic tableaux.
The tableau for part (ii) is quite complex. If you struggle to work it out, for half the marks, try
to prove that the alternative formula ∀x(p(x)∨q(x)) → (∃xp(x)∨∀xq(x)) is valid. This is considerably
simpler.
Question 5 (15)
Prove that the formula ∃x(p(x) ∨ ∀xq(x)) → ∀x(p(x) ∨ q(x)) is (i) satisfiable and (ii) falsifiable by
means of semantic tableaux.
Question 6 (15)
Prove that the formula given in Question 1 (ii) above is a theorem in the Gentzen system G . Annotate
the steps of your proof with the rule used and the steps it was applied to.
13
ASSIGNMENT 4
Due Date: 30 September 2022
Question 1 (30)
Convert the following first-order formulas to clausal form:
(i) ∃x(p(x) ∨ q(x, x)) → ∃x(p(x) ∧ ∃yq(x, y))
(ii) ∀x(∃yp(y) ↔ ¬p(x))
(iii) ∀x(∃y∃z(p(x, y) ∧ p(z, x)) ↔ q(x))
If it makes a difference, use the commutativity of ∧ and ∨ (just before extracting quantifiers) to move
existential quantifiers as far forwards as possible, so as to minimise the number and arity of skolem
functions in the final clausal form.
Question 2 (18)
Give the Herbrand universe, the Herbrand base and two Herbrand models for the answers to Question
1 (i), (ii) and (iii) above.
Question 3 (12)
Give substitutions that will unify the following pairs of atoms, or explain why they are not unifiable:
(i) p(a, x, f (x)) p(y, y, f (a))
(ii) p(x, f (x), f (f (x))) p(g(a), y, f (z))
(iii) p(f (a), g(x, x), f (x)) p(f (y), z, y)
(iv) p(f (a), b, f (x)) p(f (y), y, g(y))
Question 4 (15)
Prove by resolution refutation that the following set of clauses is unsatisfiable:
{{p(f (x), b), ¬p(x, f (y))}, {p(x, y), p(y, f (x))}, {¬p(f (x), y), p(y, a)}, {¬p(x, a)}}
Annotate each resolvent with the substitution used and the numbers of parent clauses.
Remember to standardize apart as necessary.
Question 5 (20)
Consider the following logic program intended to express the addition operation of number theory:
1. sum(0, x, x)
2. sum(x, inc(y), inc(z)) ← sum(x, y, z)
3. sum(inc(x), y, inc(z)) ← sum(x, y, z)
Note: In this program, sum is a predicate, inc is a function and 0 is a constant.
Draw an SLD-tree for each attempt at SLD-refutation resulting from the following queries:
(i) ← sum(inc(0), inc(0), x)
(ii) ← sum(inc(inc(0)), inc(0), inc(inc(inc(0))))
Use the selection rule which resolves on the leftmost literal, and label the edges with the numbers of
the program clauses.
14
COS4807/101/0/2022
Submit the Prolog file, as well as traces of the queries. Explain the traces.
© Unisa 2022
15