Notes Cse Basics File21
Notes Cse Basics File21
S, tefan Ciobâcă
Andrei Arusoaie
Rodica Condurache
Cristian Masalagiu
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
1 Introduction 7
3
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
6 Logical Connectives 45
6.1 Several Propositional Logics . . . . . . . . . . . . . . . . . . . . 45
6.2 The relation between implications and semantical consequence 46
6.3 Translating propositions from English into PL . . . . . . . . . . 47
6.4 Application 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
6.5 Exercise sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
7 Natural Deduction 51
7.1 Sequents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.2 Inference Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.3 Proof system . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
7.4 Formal Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
7.5 Natural Deduction . . . . . . . . . . . . . . . . . . . . . . . . . 55
7.5.1 The Rules for Conjunction . . . . . . . . . . . . . . . . 55
7.5.2 The Rules for Implications . . . . . . . . . . . . . . . . 56
7.5.3 Rules for Disjunctions . . . . . . . . . . . . . . . . . . . 58
7.5.4 The Rules for Negations . . . . . . . . . . . . . . . . . . 60
7.5.5 Alte reguli . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7.6 Natural Deduction . . . . . . . . . . . . . . . . . . . . . . . . . 63
7.7 Derived Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
7.8 Soundness and Completeness for Natural Deduction . . . . . . 64
7.9 Exercise Sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8 Normal Forms 67
8.1 Notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
8.2 Replacement Theorem . . . . . . . . . . . . . . . . . . . . . . . 69
8.3 Literal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
8.4 Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
8.5 Conjunctive Normal Form . . . . . . . . . . . . . . . . . . . . . 70
8.6 Bringing a Formula into CNF . . . . . . . . . . . . . . . . . . . 71
Introduction
If Arithmetic is the science that studies numbers and operations with num-
bers, then Logic is the science that studies propositions and operations with
propositions.
For example, if in Arithmetic we notice that the sum of two even numbers
is an even number, then in Logic we could notice that the disjunction of two
true sentences is also true.
Logic sits at the intersection of philosophy, mathematics and computer
science and has experienced its greatest development starting with the 1950s,
because of its numerous applications in Computer Science.
In this course, we will study at an introductory level propositional logic
and first-order logic.
Propositional logic is extremely simple, but the concepts that we study, the
methods that we learn and the issues that we face in propositional logic gener-
alize to other more complex logics. Moreover, propositional logic corresponds
intimately to the internal organization of computers at an abstract level, in
the sense that electronic circuits can be modeled as formulae in propositional
logic. Propositional logic has a rich and mathematically interesting theory
(examples: compactness theorem, Craig’s interpolation theorem). The sat-
isfiability problem for propositional logic has many applications in computer
science. It is especially important both from a theoretical viewpoint (being
the canonical NP-complete problem) and from a practical viewpoint as well
(with applications in program verification, circuit verification, combinatorial
optimization, and others).
First-order logic is an extension of propositional logic and also has numer-
ous application in computer science, but also in mathematics. For example,
all of the math that you have studied in highschool is based on a so-called first-
order logic theory called ZFC (the Zermelo–Fraenkel set theory, together with
the Axiom of Choice). In Computer Science, applications of first-order logic
7
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
Informal Propositional
Logic
2.1 Propositions
A proposition is a statement that is either true or false. Propositions are
sometimes called sentences. Here are examples of propositions:
9
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
2. π (not a statement);
3. Is it raining? (question, not a statement);
4. Go fish! (imperative);
5. x is greater than 7 (we have here a predicate of x; once we set a value
for x, the predicate becomes a proposition);
6. This sentence is false. (although a statement, it is not a proposition,
since it is not either true or false: if it were true, it would need to be
false and vice-versa).
2.3 Conjunctions
Others however seem to be composed of smaller parts. For example, the
proposition I play games often and I study very well is composed of two
smaller propositions: I play games often and I study very well, joined together
by and. When two propositions ϕ and ψ are joined by an and, the resulting
proposition ϕ and ψ is called a conjunction (the conjunction of ϕ and ψ).
The propositions ϕ and ψ are called the conjuncts of the proposition ϕ and
ψ.
A conjunction is true if both of its conjuncts are true. For example, the
proposition I play games often and I study very well. is true if both I play
games often and I study very well are true. In particular, as I do not play
games often, this proposition is false (when I say it).
Note that a conjunction need not use explicitly the word and. For ex-
ample, the proposition It is raining outside, but I have an umbrella is also a
conjunction, and it conjuncts are It is raining outside and I have an umbrella.
This particular conjunction uses the adversative conjunction but.
Exercise 1. Find the conjuncts of I play at home and I study at school..
Exercise 2. Give an example of a conjunction that is false and an example
of a conjunction that is true.
2.4 Disjunctions
Disjunctions are propositions linked together by or. For example, I can install
the software on my smartphone or on my tablet is a disjunction between I can
install the software on my smartphone and I can install the software on my
tablet. The two parts of the disjunction are called the disjuncts.
In the example above, note that the English grammar allows us to omit
I can install the software . . . in the second disjunct, as it is implicit in our
understanding of the language. However, when we find the disjuncts, is helps
to state them explicitly.
Exercise 3. Find the disjuncts of I will buy a laptop or a tablet. Pay
attention! The two disjuncts must be propositions (some words in them could
be implicit and not appear in the text).
A disjunction is true if at least one of the disjuncts is true. For example,
I am Darth Vader or I teach is true because I teach is true (I do not have to
worry about being Darth Vader). I teach or I program is also true (it happens
that both disjuncts are true).
This meaning of disjunctions is called the inclusive or. It is standard in
mathematics. Sometimes people use or in natural language to mean exclusive
or. For example Either white wins or black wins in a game of go is an example
where the or is exclusive. The meaning of the sentence is that white wins or
black wins, but not both. Here is an example of a false proposition that uses
exclusive or : Either I program or I teach (hint: false because I do both).
When you see either in a sentence, it is a sign that you are dealing with an
exclusive or.
In the following, by disjunction we will understand inclusive or (the stan-
dard interpretation in mathematics).
Exercise 4. Give an example of a false disjunction and an example of a true
disjunction.
Exercise 5. When is a disjunction ϕ or ψ false (depending on the truth value
of ϕ and ψ)?
2.5 Implications
Implications are propositions of the form if ϕ then ψ. The proposition ϕ
is called the antecedent and the proposition ψ is called the conclusion (or
consequent) of the implication.
An example of an implication is If I get a passing grade in Logic, I will
buy everyone beer. The antecedent is I get a passing grade in Logic. and the
conclusion is I will buy everyone beer. When is an implication true? Actually,
it is easier to say when it is false. An implication is false if and only if the
antecedent is true, but the conclusion is false. Assume that I got a passing
grade in Logic. Therefore, the proposition I get a passing grade in Logic is
true. However, I will not buy beer for everyone (just a few select friends).
Therefore the proposition I will buy everyone beer is false. Therefore the
implication If I get a passing grade in Logic, I will buy everyone beer as a
whole is false (antecedent is true, but conclusion is false).
The meaning of implications is worth a more detailed discussion as it is
somewhat controversial. This is mostly because implication as we understand
it in mathematics can sometimes be subtly different from implication as we
understand it in everyday life. In everyday life, when we say If I pass Logic,
I buy beer, we understand that there is a cause-and-effect relation between
passing Logic and buying beer. This subtle cause-and-effect relation is evident
in a number of if-then statements that we use in real life: If I have money, I
will buy a car, If you help me, I will help you, etc. We would never connect
two unrelated sentences with an implication: the proposition If the Earth is
round, then 2+2=4 would not be very helpful, even though it is true (both
the antecedent and the conclusion are true).
This implication that we use in mathematics is called material implication
or truth functional implication, because the truth value of the implication as a
whole depends only on the truth values of the antecedent and the conclusion,
not on the antecedent and the conclusion itself. This meaning of implication
sometimes does not correspond to the meaning of natural language implica-
tions, but it turns out that it is the only sensible interpretation of implications
in mathematics (and computer science).
In particular, we will take both the propositions If the Earth is flat, then
2 + 2 = 5 and If the Earth is flat, then 2 + 2 = 4 to be true, because the
antecedent is false. Implications that are true because the antecedent is false
are called vacuously true.
Exercise 6. What are the truth values of If 2 + 2 = 4, then the Earth is flat
and If 2 + 2 = 5, then the Earth is flat?
The truth value of an implication if ϕ then ψ, depending on the truth
values of its antecedent ϕ and its conclusion ψ, is summarized in the truth-
table below:
ϕ ψ if ϕ then ψ
false false true
false true true
true false false
true true true
The following example aims at convincing you that the truth table above
is the only reasonable one. You must agree that every natural number is
also an integer. Otherwise put, the proposition for any number x, if x is a
natural, then x is an integer is true. In particular, you will agree that the
proposition above holds for x = −10, x = 10 and x = 1.2. In particular, the
propositions If −10 is a natural, then −10 is an integer, If 10 is a natural,
then 10 is an integer and If 1.2 is a natural, then 1.2 is an integer must all
be true. This accounts for the first, second and fourth lines of the truth table
above (typically, the second line is controversial). As for the third line, false
is the only reasonable truth value for an implication if ϕ then ψ where ϕ is
true but ψ is false. Otherwise, we would have to accept propositions such as
If 2 + 2 = 4, then 2 + 2 = 5 (antecedent 2 + 2 = 4 true, conclusion 2 + 2 = 5
false) as being true.
Implications are sometimes subtle to spot and identify correctly. For ex-
ample, in the proposition I will pass Logic only if I study hard (emphasis on
only if ), the antecedent is I will pass Logic and the conclusion is I study hard.
In particular, the above proposition does not have the same meaning as If I
study hard, then I will pass Logic.
Implications can sometimes not make use of if. For example, take the
proposition I will pass Logic or I will drop school (apparently a disjunction).
This most likely meaning of this proposition is If I do not pass Logic, then I
will drop school. Thankfully, both of these propositions are equivalent, in a
sense that we shall study in the following lectures.
2.6 Negations
A proposition of the form it is not the case that ϕ (or simply not ψ) is the
negation of ϕ. For example, It is not raining is the negation of It is raining.
The negation of a proposition takes the opposite truth value. For example,
as I am writing this text, the proposition It is raining is false, and therefore
the proposition It is not raining is true.
Exercise 7. Give an example of a false proposition that uses both a negation
and a conjunction.
2.7 Equivalences
A proposition of the form ϕ if and only if ψ is called an equivalence or double
implication. Such a proposition, as a whole, is true if ϕ and ψ have the same
truth value (both false or both true).
For example, when I am writing this text, It is raining if and only if it is
snowing is true. Why? Because both of the propositions It is raining and It
is snowing are false.
Exercise 8. What is the truth value of the proposition The number 7 is odd
if and only if 7 is a prime.?
Equivalences are, semantically speaking, conjunctions of two implications:
ϕ if and only if ψ gives the same information as
ϕ if ψ and ϕ only if ψ .
| {z } | {z }
the reverse implication the direct implication
The proposition ϕ if ψ is the same as if ψ, then ϕ (but it has a different
topic). The proposition ϕ only if ψ has the same meaning as if ϕ, then ψ, as
we dicussed in the previous section on implications.
1. John and Mary are married (meaning 1: John and Mary are married to
each other; meaning 2: John and Mary are married, but not necessarily
to each other).
2. It is not true that John is tall and Jane is short (meaning 1: John is
not tall and Jane is short; meaning 2: the conjunction John is tall and
Jane is short is false).
In the study of the laws of logic, such ambiguities can get in the way, just
like a wrong computation could impact the resistance of buildings or bridges
in civil engineering.
The state of the art in Logic for over 2.000 years, from Aristotle up to the
development of Symbolic Logic in the 19th century, has been to use natural
language. Symbolic logic (formal logic) has changed the game by introducing
languages so precise that there is no risk of misunderstandings.
Such ambiguities impede the study of propositional logic. Therefore we
will design a formal language, the language of propositional logic, where no
ambiguity can occur. The first such language that we study will be the lan-
guage of propositional logic.
Normally, when people say formal, they mean it in a bad way, such as
having to dress or act formally to go to dinner.
However, in computer science (and in mathematics), formal is a good
thing: it means making things so precise that there is no possibility of mis-
understanding.
Exercise 10. For all propositions that you identified, establish whether they
are atomic or not. If not, establish if they are conjunctions, disjunctions,
implications, negations, etc.).
Exercise 11. Determine whether the sentences below are atomic or not. If
they are not atomic, identify their types (conjunctions, disjunctions, implica-
tions, negations, equivalences). For each such sentence, discuss their truth
values based on the truth values of their components.
17
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
1. ))p ∨ ∧;
2. ∨ ∨ ¬(p);
3. p;
4. ppp;
5. ¬(p ∨ q).
p q ¬p ¬q ¬p0 ¬¬p1 (p ∨ q) (p ∧ q)
pp q¬q q ∧ ¬p p+q
p q
(p ∨ q)
¬(p ∨ q)
It is easy to see that a word belongs to PL iff there is a construction tree
for it.
If the word is not over the right alphabet, such as the three-symbol word
p + q, which uses a foreign symbol +, then we can easily dismiss it as PL
only contains words over L.
However, if the word is over the right alphabet and we want to show that
it is not part of PL, we must make use of the minimality condition. Here is
an example showing that (p¬q) 6∈ PL:
Let’s assume (by contradiction) that (p¬q) ∈ PL. Then, by the minimal-
ity condition, it follows that (p¬q) ∈ PL must be explained by one of the
rules Base Case, Inductive Case i – iii.
But we cannot apply the Base Case to show that (p¬q) 6∈ PL, since
(p¬q) 6∈ A.
But we cannot apply the Inductive Case i either, because there is no
formula ϕ such that (p¬q) = ¬ϕ (no matter how we would choose ϕ ∈ PL,
the first symbol of the word on the lhs would be (, while the first symbol of
the word on the rhs would be ¬).
But we cannot apply the Inductive Case ii either, because there are no
formulae ϕ1 , ϕ2 ∈ PL such that (p¬q) = (ϕ1 ∨ ϕ2 ) (no matter how we would
choose ϕ1 , ϕ2 ∈ PL, the word on the lhs would not contain the symbol ¬,
while while the the word on the rhs would contain it).
By similar reasons, we cannot apply Inductive Case iii either.
But this contradicts our assumption and therefore it must be the case that
(p¬q) 6∈ PL.
..
.
The only difference would be that we do not place parantheses around
disjunctions. With this alternative, fictive, definition of PL, we have that
the word ¬p ∨ q ∈ PL. However, this word has two different construction
trees:
p q p
p∨q ¬p q
¬p ∨ q ¬p ∨ q
Such an ambiguity would be very troubling, because we would not know
if ¬p ∨ q is a disjunction (if we would use the construction tree on the right)
or a negation (the construction tree on the left). In fact, avoiding such
syntactic ambiguities was the main reason why we left natural language
and began studying formal logic.
End of Wrong Definition of PL.
I hope that you can now see that the Unique Readability Theorem is non-
trivial (as an exercise to the more mathematically inclined students, I suggest
that you try to prove it) and that it is a very important property of our
definition of formulae, since it essential says that any propositional formula
can be read unambiguously.
Note that the sentences that are the object of our study (I do not go to
school and I go to school) are propositions, but so is the entire statement The
proposition I do not go to school is false if the proposition I go to school is
true. In this way, it seems that we are performing a circular reasoning, in
which we study our own method of study.
This apparent difficulty does not occur in the case of arithmetic, for ex-
ample. In arithmetic, we study numbers and operations over numbers, and
we reason about numbers using propositions.
The difficulty can be solved by strictly separating the object language from
the meta-language. The object language is the language that we study (PL),
and the meta-language is the language that we use to perform the study
(English).
In this course, to more easily differentiate between the two, we make the
following convention: all elements in the object language are written in sans-
serif blue font (for example, (p ∧ q)), and the statement in the meta-language
are written using a regular black font (for example, any atomic formulae is a
formula).
1. ¬q;
2. (p1 ∧ q);
3. ¬(p ∨ q);
4. (¬p ∨ ¬q);
5. ¬(¬p ∨ (q ∧ ¬q)).
Exercise 17. Show that the following words over the alphabet L are not
elements of PL(hint: show that none of the four construction rules applies):
1. ((¬)q);
2. q ∧ ¬;
3. pq;
4. p ∧ q;
5. (p¬q);
6. (p) ∧ (q).
Exercise 18. Which of the following are formulae (in PL) and which are
not:
1. p1 ;
2. p1 ∨ q1 ;
3. (p1 ∨ q1 );
4. (¬p1 ∨ q1 );
5. ¬(p1 ∨ q1 );
6. ((¬p1 ) ∨ q1 );
7. (¬p)?
Functions Defined
Recursively on PL
25
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
Here is how we can compute subf ϕ when ϕ = ¬(p ∨ q):
subf ¬(p ∨ q) = {¬(p ∨ q)} ∪ subf (p ∨ q)
= {¬(p ∨ q)} ∪ {(p ∨ q)} ∪ subf p ∪ subf q
= {¬(p ∨ q)} ∪ {(p ∨ q)} ∪ {p} ∪ {q}
= {¬(p ∨ q), (p ∨ q), p, q}.
It is an error to write subf p ∨ q instead of subf (p ∨ q) , as
the word p ∨ q 6∈ PL is not a formula.
The function subf is the first in a long line of functions defined recursively
on the structure of a formula ϕ ∈ PL. These functions are called structurally
recursive. It is very important to understand how such functions operate in
order to understand the remainder of this course. In the following sections
we provide more examples of such functions.
ϕ , if ϕ ∈ A;
¬
if ϕ = ¬ϕ0 and ϕ0 ∈ PL;
,
0
ast ϕ
∧
ast ϕ = ,
ast ϕ1 ast ϕ2
if ϕ = (ϕ1 ∧ ϕ2 ) and ϕ1 , ϕ2 ∈ PL;
∨
,
ast ϕ ast ϕ2
1
if ϕ = (ϕ1 ∨ ϕ2 ) and ϕ1 , ϕ2 ∈ PL.
Here is the computation of the abstract syntax tree of the formula ((p ∧ ¬q) ∧ r).
∧
ast ((p ∧ ¬q) ∧ r) =
ast (p ∧ ¬q) ast r
= ∧ r
ast p ast ¬q
∧ r
=
p ¬
ast q
∧ r .
=
p ¬
The next function, size : PL → N, computes the size of the abstract syn-
tax tree of a formula (i.e., the number of nodes):
1, if ϕ ∈ A;
1 + size ϕ0 , if ϕ = ¬ϕ0 and ϕ0 ∈ PL;
size ϕ = 1 + size ϕ1 + size ϕ2 ,
if ϕ = (ϕ1 ∧ ϕ2 ) and ϕ1 , ϕ2 ∈ PL;
1 + size ϕ1 + size ϕ2 ,
if ϕ = (ϕ1 ∨ ϕ2 ) and ϕ1 , ϕ2 ∈ PL.
Make sure that you are proficient at understanding, defining and comput-
ing with functions such as those given above.
Proof: We proceed
bystructural induction (the property P (ϕ) is simply
that height ϕ ≤ size ϕ ). It is sufficient to show that:
1. (Base Case) height ϕ0 ≤ size ϕ0 for any propositional variable ϕ0 ∈
A.
But by definition, height ϕ0 = 1 and size ϕ0 = 1 when ϕ0 ∈ A. And
1 ≤ 1, which is what we had to show.
2. (Inductive Case i) Assuming that height ϕ0 ≤ size ϕ0 , we show that
height ¬ϕ0 ≤ size ¬ϕ0 .
But by definition, height ¬ϕ0 = 1 + height ϕ0 and size ¬ϕ0 =
1 + size ϕ0 . And 1 + height ϕ0 ≤ 1 + size ϕ0 (what we had to
show), as we already know height ϕ0 ≤ size ϕ0 .
3. (Inductive Case ii) Assuming that height ϕ1 ≤ size ϕ1 and height ϕ2 ≤
size ϕ2 , we show height (ϕ1 ∨ ϕ2 ) ≤ size (ϕ1 ∨ ϕ2 ) .
But, by definition, height (ϕ1 ∨ ϕ2 ) = 1+max height ϕ1 , height ϕ2
max(a, b) ≤ a + b (forany naturals a, b∈ N), we have
and, as that
height (ϕ1 ∨ ϕ2 ) ≤ 1 + height ϕ1 + height ϕ2 . But height ϕi ≤
size ϕi (1 ≤ i ≤ 2) by our hypothesis, and therefore height (ϕ1 ∨ ϕ2 ) ≤
1 + size ϕ1 + size ϕ2 . But, by definition, size (ϕ1 ∨ ϕ2 ) = 1 +
size ϕ1 +size ϕ2 , and therefore height (ϕ1 ∨ ϕ2 ) ≤ size (ϕ1 ∨ ϕ2 ) ,
what we had to prove.
4. (Inductive Case iii) Similar to Inductive Case ii.
q.e.d.
Exercise 26. Show by structural induction that height(ϕ) < size(ϕ) + 1 for
any formula ϕ ∈ PL.
Semantics of Propositional
Logic
5.2 Assignments
A truth assignment (or simply assignment from hereon) is any function τ :
A → B. In other words, an assignment is a function that associates to any
propositional variable a truth value.
1. τ1 (p) = 1;
2. τ1 (q) = 0;
3. τ1 (r) = 1;
33
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
1. τ2 (p) = 0;
2. τ2 (q) = 0;
3. τ2 (r) = 1;
4. τ2 (a) = 1 for all a ∈ A \ {p, q, r}.
τ̂1 (p ∨ q) = τ̂1 p + τ̂1 q = τ1 (p) + τ1 (q) = 1 + 0 = 1.
We conclude that the truth value of (p ∨ q) in τ̂1 is 1.
Here is another example, where we compute the truth value of the formula
¬(p ∧ q) in the truth assignment τ1 :
τ̂1 ¬(p ∧ q) = τ̂1 (p ∧ q) = τ̂1 p · τ̂1 q = τ1 (p) · τ1 (q) = 1 · 0 = 0 = 1.
We conclude that the truth value of the formula ¬(p ∧ q) in τ1 is 1.
Here is yet another example, where we compute the truth value of the
formula ¬¬q in the truth assignment τ2 :
τ̂2 ¬¬q = τ̂2 ¬q = τ̂2 q = τ2 (q) = 0 = 1 = 0. So the truth value of
¬¬q in τ2 is 0.
Remark. It does not make sense to say “the truth value of a formula”. It
makes sense to say “the truth value of a formula in an assignment”.
Also, it does not make sense to say “the formula is true” or “the formula
is false”. Instead, it makes sense to say “this formula is true/false in this
assignment”.
This is because a formula could be true in an assignment but false in
another. For example, the formula ¬¬p is true in τ1 , but false in τ2 .
Definition 30 (Satisfaction). An assignment τ satisfies ϕ if τ̂ ϕ = 1.
1. τ is a model of ϕ;
2. τ is true of ϕ;
3. ϕ holds in/at τ ;
4. τ makes ϕ true;
Example 31. The assignment τ1 defined above is a model for ¬(p ∧ q). The
assignment τ1 is not a model of the formula (¬p ∧ q).
We write τ |=
ϕ (and we read: τ is a model of the formula ϕ; or: τ satisfies
ϕ, etc.) iff τ̂ ϕ = 1. We write τ 6|= ϕ (and we read: τ is not a model of the
formula ϕ; or: τ does not satisfy ϕ) iff τ̂ ϕ = 0.
Definition 32 (The satisfaction relation (written |=)). The relation |=, be-
tween assignments and formulae, is called the satisfaction relation. It is de-
fined as follows: τ |= ϕ iff τ̂ ϕ = 1.
The satisfaction relation |= is defined as: τ |= ϕ iff τ̂ ϕ = 1.
5.4 Satisfiability
Definition 33. A formula ϕ is satisfiable if, by definition, there exists at
least an assignment τ such that τ |= ϕ (i.e., if there exists at least a model of
ϕ).
Example 34. The formula (p ∨ q) is satisfiable, since it has a model (for
example τ1 above).
Example 35. The formula ¬p is also satisfiable: for example, the assignment
τ3 above makes the formula true.
Example 36. The formula (p ∧ ¬p) is not satisfiable, since it is false in any
assignment.
Example 42. The formula p is not valid (because there is an assignment (for
example τ3 ) that makes it false).
1. (p ∧ ¬p) is a contradiction.
2. p is contingent.
3. (p ∨ ¬p) is a tautology.
5.7 Equivalence
Definition 45. We say that two formulae ϕ1 , ϕ2 ∈ PL are
equivalent
and
we write ϕ1 ≡ ϕ2 if, for any assignment τ : A → B, τ̂ ϕ1 = τ̂ ϕ2 .
Intuitively, formulae that are equivalent have the same meaning (express
the same thing).
Example 46. At the start of the course, someone asked whether p and ¬¬p
are equal. Of course not, I said, since one has 1 symbol and the other 3
symbols from the alphabet.
However, we are now ready to understand the relation between them: p ≡
¬¬p. In other words, even if they are not equal, they are equivalent: they
express the same thing.
To prove p 𠪪p, we have to show they have the same truth value in
any assignment. Let τ be an arbitrary assignment. We have that τ̂ ¬¬p =
τ (p) = τ (p) = τ̂ p . In summary, τ̂ ¬¬p = τ̂ p . As τ was chosen
arbitrarily, it follows that τ̂ ¬¬p = τ̂ p for any assignment τ and therefore
p is equivalent to ¬¬p.
ϕ1 , . . . , ϕn |= ϕ
instead of
{ϕ1 , . . . , ϕn } |= ϕ.
Remark. When n = 0, the notation above allows us to we write |= ϕ instead
of {} |= ϕ. This is consistent will the notation for validity, since a formula
which is a logical consequence of the empty set is valid (and vice-versa).
(((ϕ1 ∧ ϕ2 ) ∧ . . .) ∧ ϕn )
is satisfiable.
Lemma 54 (The link between inconsistent sets and the logical connector ∧).
A set of formulae {ϕ1 , ϕ2 , . . . , ϕn } is inconsistent if and only if the formula
(((ϕ1 ∧ ϕ2 ) ∧ . . .) ∧ ϕn )
is not satisfiable.
{ϕ1 , ϕ2 , . . . , ϕn } |= (p ∧ ¬p),
5.10 Application 1
John writes the following code:
Is Jill right? It is difficult to tell just by looking at the code, but we can
use our logic-fu to model the problem above and to determine whether the
two programs behave in the same manner.
First of all, we will “translate” the conditions in the if-else statements into
propositional logic. Supposed the value of y is fixed. We identify the “atomic
propositions” and we replace them with propositional variables as follows:
Taking into account the translation key above, we can see that John’s
condition is, in propositional logic speak, ((p ∧ ¬q) ∨ r).
Jill’s formula is, in propositional logic speak,((¬p ∨ q) ∧ ¬r).
Also notice that the branches in the two programs are reversed (the if
branch of John’s program is the else branch of Jill’s program and vice-versa).
In order for the two programs to have the same behaviour, it is sufficient for
By applying De Morgan’s laws, we can see that the equivalence does hold
and therefore the two programs have the same behaviour. So Jill’s changes
do not break the program – they are correct.
1. (p ∧ q);
2. (q ∧ p);
3. ¬q;
4. (¬q ∧ r);
5. ((¬q ∧ r) ∨ ¬p).
Exercise 58. Find an assignment τ that is a model for the following formulae
(one assignment for each formula):
1. (p ∧ q);
2. (p ∧ ¬q);
3. ((p ∧ ¬q) ∨ q).
1. (p ∨ q);
2. (q ∧ (p ∨ ¬q));
3. ((p ∧ ¬q) ∨ q).
1. (p ∧ ¬p);
2. (p ∨ ¬p);
3. ((p ∨ ¬p) ∧ ¬q);
4. ((p ∨ ¬p) ∧ (¬p ∧ q));
5. ((p ∨ ¬q) ∧ (¬p ∨ r)).
1. (p ∧ ¬p);
2. (p ∨ ¬p);
3. p;
4. ((p ∨ ¬p) ∧ ¬q);
5. (p → ¬p);
6. ((p ∧ q) ∨ (¬p ∧ r)).
Exercise 65. Can you prove that, for any formulae ϕ1 , ϕ2 ∈ PL, (ϕ1 ∨ ϕ2 ) ≡
ϕ1 if and only if ϕ1 ∈ PL is a tautology?
Exercise 66. Can you prove that, for any formulae ϕ1 , ϕ2 ∈ PL, (ϕ1 ∧ ϕ2 ) ≡
ϕ2 if and only if ϕ1 ∈ PL is a tautology?
Exercise 67. Can you prove that, for any formulae ϕ1 , ϕ2 ∈ PL, (ϕ1 ∧ ϕ2 ) ≡
ϕ1 if and only if ϕ1 ∈ PL is a contradiction?
Exercise 68. Can you prove that, for any formulae ϕ1 , ϕ2 ∈ PL, (ϕ1 ∨ ϕ2 ) ≡
ϕ2 if and only if ϕ1 ∈ PL is a contradiction?
Logical Connectives
There are two more important connectives in propositional logic: the condi-
tional (implication) and the equivalence (double implication).
We use the syntax (ϕ1 → ϕ2 ) for an implication and (ϕ1 ↔ ϕ2 ) for a
double implication.
The semantics of an implication (ϕ1 → ϕ2 ) is given by
τ̂ (ϕ1 → ϕ2 ) = τ̂ ϕ1 + τ̂ ϕ2 ,
45
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
2. PL⊥,→ is the propositional logic in which that only connectives are ⊥ (an
arity 0 connective) and →. The formula ⊥ (read as: bottom) is false in any
truth assignment.
3. PL∨,∧ is a logic in which the only connectives are ∨ and ∧.
Exercise 74. Write the definition of the formal syntax for each of the logics
above.
What do PL, PL¬,∨ , PL⊥,→ have in common? They are equiexpressive
(equally expressive). This means that for any formula ϕ ∈ PL there is a
formula ϕ0 ∈ PL¬,∨ so that ϕ ≡ ϕ0 (and vice-versa, for any formula ϕ0 ∈
PL¬,∨ there is an equivalent formula in PL).
How can we show that PL and PL¬,∨ are equally expressive? For one of
the directions, it is sufficient to translate all conjunctions in PL as follows:
(ϕ ∧ ϕ0 ) ≡ ¬(¬ϕ ∨ ¬ϕ0 ).
At the end we will obtain an equivalent formula that does not contain
conjunctions (and is therefore in PL¬,∨ ). Vice-versa, any formula in PL¬,∨
is already a formula in PL.
How can we show that PL¬,∨ and PL⊥,→ are equally expressive?
We translate all disjunctions and negations using the following equiva-
lences:
1. (ϕ ∨ ϕ0 ) ≡ (¬ϕ → ϕ0 );
2. ¬ϕ ≡ (ϕ → ⊥).
The translation operation stops after a finite number of steps and the re-
sult is a formula equivalent to the starter formula, but which uses only the
connectives ⊥ and →.
The logic PL∨,∧ is strictly less expressive. For example, in this logic there
are no unsatisfiable formulae.
Exercise 75. Explain why in PL∨,∧ all formulae are satisfiable.
Remark. By propositional logic we understand any logic that is as expressive
as PL. For example, PL¬,∧ , PL¬,∨ , PL¬,→ are all propositional logics, but
PL¬ and PL∧,∨ are not propositional logics (they are less expressive).
For example, let us translate the proposition I want to learn Logic and
pass the examination if the subject is interesting into propositional logic.
The first step is to identify the atomic propositions. In our case, we find
three atomic propositions:
2. I want to pass the examination; (note that the words I want do not
appear explicitly in the proposition, but they are implied )
The next step is to identify the logical connectives. In the example above,
there are two logical connectives:
1. the connective and in the context [...] Logic and pass [...], which indi-
cates a conjunction;
2. the connective if-then (even if the word then does not appear explicitly)
in the context [...] the examination if the subject [...], which indicates
an implication.
What is the order of the two connectives? In other words, it the entire
proposition a conjunction or an implication? What is the main connective?
Our English-language intuition tells us that it is more likely an implication
(for example, because the verb want is implied (not explicit) in the proposition
I want to pass the examination). The translation is therefore
(r → (p ∧ q)),
Exercise 79. Translate the following proposition into propositional logic: Ei-
ther I pass Logic, or I don’t.
Pay attention to the words that do not explictly appear in the atomic propo-
sitions. Pay attention to the meaning of the connective either-or (hint: it
is not among the connectives that we discussed so far, but it can be emu-
lated/ simulated).
6.4 Application 2
The following puzzle is from the book Peter Smith. An Introduction to Formal
Logic. Either the butler or the cook committed the murder. The victim died
from poison if the cook did the murder. The butler did the murder only if the
victim was stabbed. The victim didn’t die from poison.
Does it follow that the victim was stabbed?
We associate to every atomic proposition a propositional variable as fol-
lows:
1. For the proposition “the butler commited the murder” the propositional
variable p;
2. For the proposition “the cook commited the murder” the propositional
variable q;
3. For the proposition “the victim died of posion” the propositional vari-
able r1 ;
4. For the proposition “the victim was stabbed” the propositional variable
r2 .
4. ¬r1 .
3. Thing go well in the country if the leaders of the country are not thiefs
and if the economy is healthy. People go abroad if and only if things
do not go well in the country. The economy is healthy, but people leave
abroad.
Natural Deduction
In the previous lecture we have discussed some important notions about the
semantics of propositional logic.
We have seen that in order to establish that two formulae are equivalent,
a semantical reasoning process is necessary (meaning an argument that uses
semantical notions such as truth values, assignments etc).
One of the main purposes of logic in computer science is to design mechan-
ical models (meaning models that are suitable to computer implementation)
for reasoning instead of semantical-based reasoning.
In this lecture, we will study a method for mechanizing the notion of se-
mantical consequence. By mechnization, we understand a method for proving
consequeneces with the following properties:
51
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
7.1 Sequents
Definition 81 (Sequent). A sequent is a pair consisting of a set of formulae
{ϕ1 , . . . , ϕn } and a formula ϕ, pair denoted by
{ϕ1 , . . . , ϕn } ` ϕ.
The word sequent does not really exist in English. It is borrowed from the
German word Sequentz.
Sometimes we read {ϕ1 , . . . , ϕn } ` ϕ as ϕ is a syntactical consequence of
{ϕ1 , . . . , ϕn }. We will often use Γ to denote the set of premisses {ϕ1 , . . . , ϕn }
of the sequent and in this case we will write Γ ` ϕ. Also, the usual notion
in the literature permits the writing ϕ1 , . . . , ϕn ` ϕ (without curly braces)
instead of {ϕ1 , . . . , ϕn } ` ϕ, but we have to keep in mind that to the left
hand side of the ` symbol we always have a set of formulae.
Example 82. Here are some examples of sequents:
1. {p, q} ` (p ∧ q);
2. {p, (q ∧ ¬r)} ` (p ∨ q);
3. {(p ∧ q), (p ∨ q)} ` (p ∧ r).
Later on, we shall see that the first two sequents are valid, and the last
sequent is not.
S1 ... Sn
name condition.
S
Remark. It is possible for a sequent to have n = 0 hypotheses. Such inference
rules, having 0 hypotheses, are called axioms.
Γ`ϕ Γ ` ϕ0 Γ ` (ϕ ∧ ϕ0 )
∧i ∧e1
Γ ` (ϕ ∧ ϕ0 ), Γ ` ϕ,
Γ ` (ϕ ∧ ϕ0 )
∧e2
Γ ` ϕ0 .
All three rules above are sound, in a sense that we will define later. None
of the three rules above has a condition. Here is an example of a rule with
n = 0 hypotheses, but having a condition:
Premiss ϕ ∈ Γ.
Γ`ϕ
Here is an example of an unsound inference rule (we will see later in what
sense it is unsound):
Γ ` ϕ0
unsound rule
Γ ` (ϕ ∧ ϕ0 ).
Remark. To be precise, the hypotheses of the inference rule, as well as the
conclusion, are really sequent schemes and not sequents. This means that
an inference rules might have several instances, obtained by replacing the
mathematical variables ϕ, ϕ0 , Γ with actual formulae. For example, here are
two instances of the rule ∧i above:
{p, q} ` p {p, q} ` q
∧i
{p, q} ` (p ∧ p).
Example 88. Consider the proof system D1 , containing the following infer-
ence rules:
Γ`ϕ Γ ` ϕ0 Γ ` (ϕ ∧ ϕ0 )
Premiss ϕ∈Γ ∧i ∧e1
Γ ` ϕ, Γ ` (ϕ ∧ ϕ0 ), Γ ` ϕ,
Γ ` (ϕ ∧ ϕ0 )
∧e2
Γ ` ϕ0 .
1. S1 ;
2. S2 ;
...
n. Sn
1. {p, q} ` p; ( Premiss)
2. {p, q} ` q; ( Premiss)
Note that each line is annotated by the name of the inference rule that was
applied, plus the lines where the hypotheses of the rule are found.
Definition 91 (Valid Sequent). A sequent Γ ` ϕ is valid in a proof system
D if there exists a formal proof S1 , . . . , Sn in D such that Sn = Γ ` ϕ.
Example 92. The sequent {p, q} ` (p ∧ q) is valid in the proof system D1
above, because it is the last sequent in the following formal proof:
1. {p, q} ` p; ( Premiss)
2. {p, q} ` q; ( Premiss)
3. {p, q} ` (p ∧ q). ( ∧i, 1, 2)
Remark. Do not mistake the notion of sequent valid in a proof system for
the notion of valid formula.
Γ`ϕ Γ ` ϕ0 Γ ` (ϕ ∧ ϕ0 ) Γ ` (ϕ ∧ ϕ0 )
∧i ∧e1 ∧e2
Γ ` (ϕ ∧ ϕ0 ), Γ ` ϕ, Γ ` ϕ0 .
The proof system is called natural deduction because it mimics the human
reasoning process:
• The rule for introducing and indicates that we can prove a conjunction
(ϕ ∧ ϕ0 ) from the antecedents Γ if we know that each conjunct, ϕ and ϕ0
respectively, is a consequence of Γ.
In other words, to show that a conjunction follows from Γ, it is enough to
show individually that each conjunct follows from Γ.
• There are two elimination rules for and. The first elimination rule indicates
that if we have already established that a conjunction (ϕ ∧ ϕ0 ) follows from
Γ, then the left-hand side conjunct, ϕ, also follows from Γ.
The second elimination rule is symmetrical.
Here is an example of a formal proof that uses the inference rules for and :
Γ ` (ϕ → ϕ0 ) Γ`ϕ
→e
Γ ` ϕ0 .
The rule tells us that, assuming that we already know that ϕ → ϕ0 follows
from Γ and that ϕ follows from Γ, then we also have that ϕ0 follows from Γ.
Here is an example of formal proof that uses the modus ponens rule:
This formal proof shows that the sequent {(p → r), (p ∧ q)} ` r is valid,
meaning that the formula r is a consequence of the formulae (p → r) and
(p ∧ q). Note the order of the line numbers 3 and 2 in the annotation for line
4 (they follow the order in the inference rule).
1. {((p ∧ q) → r), p, q} ` r;
Γ, ϕ ` ϕ0 Γ ∪ {ϕ} ` ϕ0
→i →i
Γ ` (ϕ → ϕ0 ), Γ ` (ϕ → ϕ0 ).
What is important to note and understand for the rule for introducing
implication is that the premisses of the sequent in the hypotheses are different
from the premisses of the sequent in the conclusion. Whereas in the conclusion
we have that the formula (ϕ → ϕ0 ) follows from Γ, in the hypothesis we have
to show that ϕ0 follows from Γ ∪ {ϕ}. In other words, intuitively speaking, to
prove an implication (ϕ → ϕ0 ), we assume the antecedent ϕ and we show the
consequent ϕ0 .
Example 95. Let us show that the sequent {} ` (p → p) is valid:
1. {p} ` p; ( Premiss)
2. {} ` (p → p). ( → i, 1)
Example 96. Let us show that the sequent {(p → q)} ` (p → q) is valid.
A simple proof is:
Example 97. Let us show that the sequent {(p → q), (q → r)} ` (p → r)
is valid:
1. {((p ∧ q) → r), p, q} ` r;
Γ ` ϕ1 Γ ` ϕ2
∨i1 ∨i2
Γ ` (ϕ1 ∨ ϕ2 ), Γ ` (ϕ1 ∨ ϕ2 ).
The first rule indicates that if we already know ϕ1 follows from Γ, then
(ϕ1 ∨ ϕ2 ) must also follow from Γ, what ϕ2 is. In other words, intuitively
speaking, if we know ϕ1 , then we also know (ϕ1 ∨ whatever else). The second
introduction rule for disjunction is symmetrical.
Example 99. Let us show that the sequent {(p ∧ q)} ` (p ∨ q) is valid:
Γ ` (ϕ1 ∨ ϕ2 ) Γ, ϕ1 ` ϕ0 Γ, ϕ2 ` ϕ0
∨e
Γ ` ϕ0
Example 101. Let us show that the sequent {(p ∨ q)} ` (q ∨ p) is valid:
Note that way in which the set of premisses varies from one sequent to
another along the formal proof, obbeying the inference rules.
Exercise 102. Show that the sequent {(p ∨ q), (p → r), (q → r)} ` r is
valid.
Exercise 103. Show that the sequent {(p → r), (q → r)} ` ((p ∨ q) → r)
is valid.
Γ, ϕ ` ⊥ Γ`ϕ Γ ` ¬ϕ Γ`⊥
¬i ¬e ⊥e
Γ ` ¬ϕ, Γ ` ⊥, Γ ` ϕ.
Recall that ⊥ is a nullary logical connective (it has arity 0), meaning that
⊥ connects 0 formulae among themselves. In other words, the connective ⊥
is by itself a formula. The semantics of ⊥ is that it is false in any assignment.
In other words, ⊥ is a contradiction.
The first rule above is that for introducing negations. It is easy to explain
intuitively: how can we show that a formula of the form¬ϕ follows from Γ?
We assume ϕ in addition to Γ and we show that from Γ and ϕ follows a
contradiction (Γ, ϕ ` ⊥). In this way, we have that ¬ϕ follows from Γ.
The second rule, for eliminating negations, indicates that if both a formula,
ϕ, and its negation, ¬ϕ, follow from the same set of premisses Γ, then from
Γ follows a contradiction, ⊥. A set Γ from which a contradiction follows is
called inconsistent.
The third rule indicates that, if Γ is an inconsistent set, then any formula
ϕ follows from Γ.
There is no rule for introducing ⊥ (or, equivallently, the rule for eliminat-
ing negation can be considered as the rule for introducing ⊥).
Example 104. Let us show that the sequent {p} ` ¬¬p is valid:
Example 105. Let us show that the sequent {p, ¬p} ` r is valid:
Γ`ϕ
Extend
Γ, ϕ0 ` ϕ
Example 107. Let us show that the sequent {p, ¬q, r, (q1 ∧ q2 )} ` ¬¬p is
valid:
The rules above are natural deduction for a logic that is called intuitionistic
propositional logic. In this lecture, we study classical propositional logic. The
two logics have the same syntax, but their semantics are different. Intuitionist
logic is important in computer science, because formal proofs in this logic are
in a 1-to-1 correspondence with computer programs. Meaning that to each
intuitionistic proof we can associate a program, and to each program, an
Γ ` ¬¬ϕ
¬¬e
Γ ` ϕ.
Example 108. Let us show that the sequent {(¬p → q), ¬q} ` p is valid:
1. {(¬p → q), ¬q, ¬p} ` ¬p; ( Premiss)
2. {(¬p → q), ¬q, ¬p} ` (¬p → q); ( Premiss)
3. {(¬p → q), ¬q, ¬p} ` q; ( → e, 2, 1)
4. {(¬p → q), ¬q, ¬p} ` ¬q; ( Premiss)
5. {(¬p → q), ¬q, ¬p} ` ⊥; ( ¬i, 4, 3)
6. {(¬p → q), ¬q} ` ¬¬p; ( ¬i, 5)
7. {(¬p → q), ¬q} ` p. ( ¬¬e, 6)
Example 109. Let us show that the sequent {} ` (p ∨ ¬p) is valid:
1. {¬(p ∨ ¬p), p} ` ¬(p ∨ ¬p); ( Premiss)
2. {¬(p ∨ ¬p), p} ` p; ( Premiss)
3. {¬(p ∨ ¬p), p} ` (p ∨ ¬p); ( ∨i1 , 2)
4. {¬(p ∨ ¬p), p} ` ⊥; ( ¬e, 1, 3)
5. {¬(p ∨ ¬p)} ` ¬p; ( ¬i, 4)
6. {¬(p ∨ ¬p)} ` (p ∨ ¬p); ( ∨i2 , 5)
7. {¬(p ∨ ¬p)} ` ¬(p ∨ ¬p); ( Premiss)
8. {¬(p ∨ ¬p)} ` ⊥; ( ¬e, 7, 6)
9. {} ` ¬¬(p ∨ ¬p); ( ¬i, 8)
10. {} ` (p ∨ ¬p). ( ¬¬e, 9)
Exercise 110. Show that the following sequents are valid:
1. {¬(p ∧ q)} ` (¬p ∨ ¬q);
2. {¬(¬p ∨ ¬q)} ` (p ∧ q);
3. {¬(¬p ∧ ¬q)} ` (p ∨ q).
Γ`ϕ Γ ` ϕ0 Γ ` (ϕ ∧ ϕ0 )
∧i ∧e1
Γ ` (ϕ ∧ ϕ0 ), Γ ` ϕ,
Γ ` (ϕ ∧ ϕ0 ) Γ ` (ϕ → ϕ0 ) Γ`ϕ Γ, ϕ ` ϕ0
∧e2 →e →i
Γ ` ϕ0 , Γ ` ϕ0 , Γ ` (ϕ → ϕ0 ),
Γ ` ϕ1 Γ ` ϕ2
∨i1 ∨i2
Γ ` (ϕ1 ∨ ϕ2 ), Γ ` (ϕ1 ∨ ϕ2 ),
Γ ` (ϕ1 ∨ ϕ2 ) Γ, ϕ1 ` ϕ0 Γ, ϕ2 ` ϕ0
∨e
Γ ` ϕ0 ,
Γ`ϕ Γ ` ¬ϕ Γ, ϕ ` ⊥ Γ`⊥
¬e ¬i ⊥e
Γ ` ⊥, Γ ` ¬ϕ, Γ ` ϕ,
Γ`ϕ Γ ` ¬¬ϕ
Premiss ϕ ∈ Γ, Extend ¬¬e
Γ`ϕ Γ, ϕ0 ` ϕ, Γ ` ϕ.
Γ`ϕ
¬¬i
Γ ` ¬¬ϕ.
Here is a formal proof for the rule for introducing double negation. We
start with the hypotheses of the rule, and the last sequent in the proof must
be the conclusion of the rule.
4. Γ, ¬ϕ ` ⊥; (¬e, 2, 3)
5. Γ ` ¬¬ϕ. (¬i, 4)
After having been shown derived (as above), such a proof rule can be used
to shorten other proofs, similarly to how we shorten code by writing subpro-
grams (functions) in certain programming languages. Here is an example of
a formal proof that uses the derived rule ¬¬i:
4. {(¬¬p → q), p} ` q. (→ e, 3, 2)
In the absence of the derived rule, our proof would have been longer:
7. {(¬¬p → q), p} ` q. (→ e, 6, 5)
Note that the lines 1–5 in the longer proof are an instance of the formal
proof for the derived rule.
Lem
2. LEM (law of excluded middle): Γ ` (ϕ ∨ ¬ϕ);
Γ, ¬ϕ ` ⊥
Pbc
3. PBC (proof by contradiction): Γ ` ϕ;
Γ ` (ϕ → ϕ0 ) Γ ` ¬ϕ0
MT
4. MT (modus tollens): Γ ` ¬ϕ.
Exercise 118. Prove the soundness theorem for natural deduction (by induc-
tion on the number of sequents in the formal proof ).
Exercise 119. Show that the rule ¬¬e is derivable using the LEM (i.e., you
may use LEM in the derivation, but not ¬¬e).
Exercise 120. Prove, using the soundness and completeness theorems, that
ϕ1 a` ϕ2 if and only if ϕ1 ≡ ϕ2 .
Normal Forms
So far, we have discussed the syntax and the semantics of propositional logic,
and in the last chapter, we introduced a first method for mechanizing formal
proofs, namely natural deduction.
An essential concern in Logic is automated proof, which means automatic
search for formal proofs by a computer for a specific conjecture/theorem.
Natural deduction is a deductive system with certain features (for instance,
formal proofs can be theoretically verified and easily understood). However,
the performance of automated provers using natural deduction is lacking in
practice.
For this reason, we will study another deductive system called resolution,
which allows for practical and efficient implementations, even though resolu-
tion proofs may not be as elegant as natural deduction proofs.
Unlike natural deduction, which works with arbitrary formulae, resolution
is limited to formulae in a specific form, known as clausal normal form. The
goal of this chapter is to study clausal normal forms.
8.1 Notations
In practice, when we write formulae in PL, we only use parentheses when
strictly necessary.
Just as when we write 5 × −3 + 2, we understand it as (5 × (−3)) + 2,
similarly, instead of p ∧ ¬q ∨ r, we will understand ((p ∧ ¬q) ∨ r). In this
sense, the negation ¬ has the highest priority, followed by ∧ and then ∨. We
can remember this convention by associating:
67
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
3. ∨ with addition.
⊥, ¬, ∧, ∨, →, ↔.
For example, by
¬¬p ∨ ⊥ ∧ p → ¬p ∧ q ↔ q
p ∧ q ∧ r ∨ ¬p ∧ ¬q ∧ ¬r
p1 ∧ p2 ∧ p3 ∧ p4
for the
(((p1 ∧ p2 ) ∧ p3 ) ∧ p4 ).
p1 ∨ p2 ∨ p3 ∨ p4
8.3 Literal
Definition 126 (Literal). A formula ϕ is called a literal if there exists a
propositional variable a ∈ A such that
ϕ=a or ϕ = ¬a.
Example 127. The formulae p, q, ¬p, ¬p0 , q1 are literals, but the formulae
(p ∨ q), ¬¬p, ¬¬¬q1 , (¬p ∧ q) are not literals.
8.4 Clauses
Definition 128. A formula ϕ is called a clause if there exist n literals
ϕ1 , . . . , ϕn such that
ϕ = ϕ1 ∨ϕ2 ∨ . . . ∨ϕn .
1. p ∨ q ∨ r;
2. p ∨ ¬q ∨ ¬r;
3. ¬p ∨ ¬q ∨ ¬r;
4. ¬p1 ∨ p1 ∨ p2 ∨ ¬q ∨ ¬r;
5. ¬p1 ∨ p1 ;
6. ¬p1 (n = 1).
7. p (n = 1).
The first two equivalences ensure the fact that all double implications and
all implications disappear from the formula.
The third and the fourth equivalence ensure that in the tree of the formula,
all disjunctions “go under” the conjunctions.
Equivalences 5 and 6 ensure the associativity of the chains of disjunctions
and conjunctions, respectively (it allows us to write ϕ1 ∨ ϕ2 ∨ ϕ3 ∨ . . . ∨ ϕn
instead of ((((ϕ1 ∨ ϕ2 ) ∨ ϕ3 ) ∨ . . .) ∨ ϕn ).
Equivalences 7 and 8 ensure that the negations end up “under” the con-
junctions and disjunctions in the tree of the formula.
The last equivalence ensures that there are no double negations “one under
the other” in the abstract syntax tree.
Applying the equivalences above eventually stops (they cannot be applied
ad infinitum – why?).
The result will be a formula in which all conjunctions are “above” all
disjunctions, which are “above” all possible negations, meaning a formula in
CNF. q.e.d.
Example 133. Let us bring the formula ((¬p → ¬q) ↔ (q → p)) into CNF
2. ¬p ∨ (r ∧ ¬p ∧ r0 ) ∨ ¬r;
3. ¬p ∨ r ∨ ¬r;
4. ¬p;
5. p.
ϕ2 c is in CNF.
1. ((p ∧ q) ∨ r);
2. ((p ∨ q) ∧ r);
3. ¬((p ∨ q) ∧ r);
4. ¬((p ∧ q) ∨ r);
9. (p ↔ (q →(¬p ∧ ¬q)));
10. ((p → q) ↔ (¬q → ¬p));
11. (p1 ∧ q1 ) ∨ (p2 ∧ q2 ) ∨ . . . ∨ (pn ∧ qn ) (first solve the cases n = 2 and
n = 3, then generalize);
Exercise 146. Bring into CNF the formula p ∨ q → p ∧ ¬r (mind the pri-
ority of the logical connectives).
Resolution in Propositional
Logic
ϕ1 , ϕ2 , . . . , ϕn ` ϕ,
75
Logic for Computer Science 2023-2024 Alexandru Ioan Cuza University
{ϕ1 , . . . , ϕn }
ϕ1 ∧ . . . ∧ϕn .
9.3 Resolution
Resolution is a proof system with only one inference rule. The hypotheses and
the conclusion of the inference rule are all clauses (unlike natural deduction,
where the hypotheses and the conclusion were sequents).
Here is the resolution rule:
C ∪ {a} D ∪ {¬a}
Binary Resolution
C ∪D
variable, it follows that C ∪ {a} is also a clause. In fact C ∪ {a} is the first
hypothesis of the inference rule.
The second hypothesis is the clause D ∪{¬a}. The conclusion is the clause
C ∪ D.
Here is an example of applying the resolution rule:
1. {p, q}; (premiss)
2. {¬p, ¬r}; (premiss)
3. {q, ¬r}. (by Resolution, lines 1, 2, a = p)
Definition 153. The clause C ∪D resulting from applying resolution is called
the resolvent of C ∪ {a} and D ∪ {¬a}.
Note that the resolvent of two clauses is not unique. For example, the
clauses {p, q} and {¬p, ¬q, r} have two resolvents: {p, ¬p, r} and respectively
{q, ¬q, r}. We may distinguish among the various resolvents by stating on
which propositional variable a we have performed the resolution:
Definition 154. The clause C ∪D resulting from applying resolution is called
the resolvent of C ∪ {a} and D ∪ {¬a} on a.
For example, {p, ¬p, r} is the resolvent on q of the clauses {p, q} and
{¬p, ¬q, r}, while {q, ¬q, r} is their resolvent on p.
Remark. Note that when we apply inference rules, we must follow them to
the letter. For example, a common mistake in applying resolution is:
1. {p, q, r}; (premiss)
2. {¬p, ¬q}; (premiss)
3. {r}. (wrong application of resolution)
On line 3, we may conclude either the resolvent on p or on q, but it makes
no sense to mix the two in order to have a single resolvent on both p and q.
Make sure you understand this point very well.
Here is the first correct variant:
1. {p, q, r}; (premiss)
2. {¬p, ¬q}; (premiss)
3. {q, r, ¬q}; (resolvent of 1, 2 on a = p)
and the second one:
1. {p, q, r}; (premiss)
2. {¬p, ¬q}; (premiss)
3. {p, r, ¬p}. (resolvent of 1, 2 on a = q)
• either ψi ∈ {ϕ1 , . . . , ϕn },
• or ψi is obtained by resolution from some clauses ψj , ψk that appear
earlier in the formal proof: 1 ≤ j, k < i.
9.5 Soundness
Like natural deduction, resolution is sound. This section shows that this is
indeed the case.
ϕ1 , . . . ϕn |= ϕ.
ϕ1 , . . . , ϕn |= ψi .
ϕ1 , . . . , ϕn |= ψi
ϕ1 , . . . , ϕn |= C ∪ {a}
and that
ϕ1 , . . . , ϕn |= D ∪ {¬a}.
We prove that
ϕ1 , . . . , ϕn |= C ∪ D.
Let τ be a model of ϕ1 , . . ., and ϕn . We have that τ is a model of
C ∪ {a} and of D ∪ {¬a} by the semantical consequences above. By
Lemma 162, it follows that τ is a model of C ∪ D. But ψi = C ∪ D and
therefore τ is a model ψi . As τ was any model of all of ϕ1 , . . ., and ϕn ,
it follows that
ϕ1 , . . . , ϕn |= ψi ,
which is what we had to prove.
ϕ1 , . . . , ϕn |= ψi
ϕ1 , . . . , ϕn |= ϕ,
9.6 Completeness
A proof system must be sound in order to be of any use (otherwise, we could
use it to prove something false).
However, it is also nice when a proof system is complete, in the sense of
allowing to prove any true statement.
Unfortunately, resolution is not complete, as shown by the following ex-
ample:
Theorem 165 (Incompleteness of Resolution). There exist clauses ϕ1 , . . . , ϕn , ϕ
such that
ϕ1 , . . . , ϕn |= ϕ,
but there is no resolution proof of ϕ from ϕ1 , . . . , ϕn .
We have reached a CNF. Starting with the clauses that make up the CNF,
we can derive :
1. ((p ∧ q) → (p ∨ q));
2. (p → (q → p));
1. p |= (p ∨ q);
2. (p ∧ q) |= (p ∨ q);
3. ((p ∧ q) → r) |= (p → (q → r));
4. (p → p0 ), (q → q0 ) |= ((p ∧ q) → (p0 ∨ q0 )).