Logic
Logic
1 Propositions
Definition
A proposition, or statement, is a declarative sentence that is either true or false.
Notes:
• Note that we may not know if a proposition is true of false. We do know, however, that it is
either true, or false, but not both.
• When a sentence can be both true and false, we say that it is a paradox. A famous example
is the liar’s paradox. I refer the reader to the excellent article in the Stanford encyclopedia
of philosophy on this paradox( see https://plato.stanford.edu/entries/liar-paradox/)
and especially their first paragraph:
‘The first sentence in this essay is a lie. There is something odd about saying so, as has
been known since ancient times. To see why, remember that all lies are untrue. Is the first
sentence true? If it is, then it is a lie, and so it is not true. Conversely, suppose that it is
not true. We (viz., the authors) have said it, and normally things are said with the intention
of being believed. Saying something that way when it is untrue is a lie. But then, given what
the sentence says, it is true after all!”
Examples:
Sentence Is it a proposition? Truth value
1+2=4 Yes F
2×3=6 Yes T
It depends! It is a proposi-
tion that is true on Friday,
Today is Friday Yes
and false the other days of
the week
It will rain on July 4th 2022 Yes We will know in 6 months
x+1=2 No (we do not know what x is)
I am lying now No (liar’s paradox)
Notation:
p: “Today is Monday”
1
2 Compound propositions
Definition
A compound proposition is a proposition that involves the assembly of possibly multiple propo-
sitions, where the assembly is performed using logic operators.
Notes:
• The truth value of a compound proposition depends on the truth values of the propositions
that define it. To analyze this dependence, we usually use a truth table that lists exhaustively
all options. A compound proposition that depends on N proposition will be represented with
a truth table with 2N possibilities.
Definition
Let p be a proposition. The sentence “It is not the case that p” is another proposition, called
the negation of p, denoted ¬p, sometimes ∼ p.
p ¬p
T F
F T
Examples:
Truth Truth
Proposition p Negation ¬p
value value
2+2=4 T 2 + 2 6= 4 F
1=0 F 1 6= 0 T
There is at least one politician
All politicians are crooks
that is not a crook
All students in this class will There is at least one student in
get an A in ECS17 this class that will not get an A
2
2.2 Conjunction (AND) (binary)
Definition
The conjunction of two propositions p and q is the compound proposition that we write p ∧ q
and read “p and q”, which is only true if both p and q are true.
Truth table:
p q p∧q
T T T
T F F
F T F
F F F
Examples:
Proposition Value
p∧q John likes pizza and Bill likes milk
¬p ∧ q John does not like pizza and Bill likes milk
p ∧ ¬q John likes pizza and Bill does not like milk
¬p ∧ ¬q John does not like pizza and Bill does not like milk
Definition
The disjunction of two propositions p and q is the compound proposition that we write p ∨ q
and read “p or q”, which is true if p is true, q is true, or both p and q are true.
Truth table:
p q p∨q
T T T
T F T
F T T
F F F
Examples:
3
p: “The butler did it”
q: “The cook did it”
p ∨ q: “Either the butler or the cook did it”
Notes:
p ¬p p ∧ ¬p p ¬p p ∨ ¬p
T F F T F T
F T F F T T
Definition
The exclusive or of two propositions p and q is the compound proposition that we write p ⊕ q,
which is true if and only if p is true, or q is true, but not when both p and q are true.
Truth table:
p q p⊕q
T T F
T F T
F T T
F F F
Examples:
Notes:
p p p⊕p p ¬p p ⊕ ¬p
T T F T F T
F F F F T T
4
2.5 (Material) implication (binary)
Definition
The compound proposition p → q that reads “p implies q” is true unless p is true and q is false.
Truth table:
p q p→q
T T T
T F F
F T T
F F T
Note: when p is false, p → q is true, no matter what the truth value of q is.
Example:
Consider the statement “If you earn an A in this class, then I will buy you a car”. This is a
compound proposition made of the two propositions
that reads “p → q. This statement can be seen as a “contract” between you and me. If you do
satisfy your part of the contract, namely you earn an A, and I buy you a car, then the contract
is satisfied; we call it true. However, if you do satisfy your part of the contract, but I do not buy
you a car, then the contract is broken; we call it false. Interestingly, if you do not satisfy your part
of the contract, then it does not matter what I do, the contract does not apply, or at least is not
broken; it is then true.
Definitions
Definition
The biconditional compound proposition p ↔ q is defined as the compound proposition (p →
q) ∧ (q → p), for any proposition p and q.
5
Truth table:
p q p↔q
T T T
T F F
F T F
F F T
Phrasing:
• “p is equivalent to q”
6
3 Comparing Propositions
3.1 Logical equivalence - Tautology - Contradiction
Definitions
i) Two propositions p and q are logically equivalent if they always have the same truth values.
We write p ⇔ q.
Notes:
• Do note the difference between p ↔ q and p ⇔ q: in the former, ↔ refers to the logical
operator “biconditional”, while in the latter, ⇔ refers to the comparison of p and q, signaling
that they always have the same truth value.
• From the definition of the biconditional, we note that to show that two propositions p and q
are logically equivalent, it is enough to show that the proposition p ↔ q is a tautology. In
practice, however, we check directly the truth values of both propositions to see if they are
equal.
• One way to prove that two propositions are logically equivalent is to build the truth table
associated with those two propositions, and check the corresponding columns. Please note,
however, that there are other possibilities. We will see some of them later.
7
The two propositions (p ∨ q) ∧ ¬(p ∧ q) and p ⊕ q (columns 6 and 7 in the truth table) always have
the same truth values; they are therefore equivalent.
a) ¬(p ∧ q) ⇔ ¬p ∨ ¬q.
b) ¬(p ∨ q) ⇔ ¬p ∧ ¬q.
p q p∧q ¬(p ∧ q) ¬p ¬q ¬p ∨ ¬q
T T T F F F F
T F F T F T T
F T F T T F T
F F F T T T T
The two propositions ¬(p ∧ q) and ¬p ∨ ¬q (columns 4 and 7 in the truth table) always have
the same truth values; they are therefore equivalent.
p q p∨q ¬(p ∨ q) ¬p ¬q ¬p ∧ ¬q
T T T F F F F
T F T F F T F
F T T F T F F
F F F T T T T
The two propositions ¬(p ∨ q) and ¬p ∧ ¬q (columns 4 and 7 in the truth table) always have
the same truth values; they are therefore equivalent.
Example of application:
Let p and q be two propositions. Show that,
8
p q p∨q ¬p ¬q ¬p ∧ ¬q (p ∨ q) ∨ (¬p ∧ ¬q)
T T T F F F T
T F T F T F T
F T T T F F T
F F F T T T T
¬p ∧ ¬q ⇔ ¬(p ∨ q)
Therefore,
A ⇔ (p ∨ q) ∨ ¬(p ∨ q)
Defining B = p ∨ q, we get,
A ⇔ (p ∨ q) ∨ ¬(p ∨ q)
A ⇔ B ∨ ¬B
A ⇔ T
a) p → q ⇔ (¬p) ∨ q.
9
p q p→q ¬p q ¬p ∨ q
T T T F T T
T F F F F F
F T T T T T
F F T T F T
The two propositions p → q and ¬p ∨ q (columns 3 and 6 in the truth table) always have the
same truth values; they are therefore equivalent.
p q p→q ¬q ¬p ¬q → ¬p
T T T F F T
T F F T F F
F T T F T T
F F T T T T
The two propositions p → q and ¬q → ¬p (columns 3 and 6 in the truth table) always have
the same truth values; they are therefore equivalent.
10
3.4 List of important logical equivalences
p∨p⇔p Idempotent 1
p∧p⇔p Idempotent 2
p ∨ (q ∨ r) ⇔ (p ∨ q) ∨ r Associativity 1
p ∧ (q ∧ r) ⇔ (p ∧ q) ∧ r Associativity 2
p ∨ (q ∧ r) ⇔ (p ∨ q) ∧ (p ∨ r) Distributivity 1
p ∧ (q ∨ r) ⇔ (p ∧ q) ∨ (p ∧ r) Distributivity 2
¬T ⇔ F Complement law 1
¬F ⇔ T Complement law 2
p ∨ ¬p ⇔ T Complement law 3
p ∧ ¬p ⇔ F Complement law 4
(p ↔ q) ⇔ (p → q) ∧ (q → p) Equivalence law
11
4 Predicates and quantifiers
4.1 Definitions
We have seen that the expression “x + 3 = 1” is not a proposition as we cannot assess of its truth
value. We can denote this expression as P (x), where x is the variable defined in a “universe” D and
P is the predicate. A predicate can become a proposition through quantification.
• Universal quantification:
P (x) is true for all x in the universe D of discourse
Notation: ∀x ∈ D, P (x)
Example: ∀n ∈ N, n2 ≥ 0.
• Universal quantification:
There exists a value x in the universe D if discourse such at P (x) is true.
Notation: ∃x ∈ D, P (x)
Example: ∃n ∈ N, n is prime.
12
5 Some Applications
5.1 Boolean searches
Boolean operators form the basis of database logic. They connect your search words together to
either narrow or broaden your set of results. Given two search terms, the three basic boolean
operators are:
• AND: match records that contains both terms
• To connect various pieces of information to find exactly what you’re looking for.
ii) For each assignment (row of the table), evaluate the truth values of the statements of the
inhabitants.
iii) Finally, check for each row of the table, check if the truth values assigned in ii) are compatible
with the corresponding types of the inhabitant
The solution is then the row that is found compatible in step iii). Note that some problems my be
ill-posed, in which case multiple solutions, or no solutions are possible.
Examples
a) Let John and Bill be two inhabitants of the island. John says, ”the two of use are both
knights,” but Bill says, ”John is a knave.? Can you find out what types John and Bill are?
We define:
13
If John is a If Bill is a PJ PB Validity
Knight Knight T F No: Bill would be a knight that lies
Knight Knave F F No: John would be a knight that lies
Yes, John is a Knave that lies and Bill is a
Knave Knight F T
Knight that tells the truth
Knave Knave F T No: Bill would be a knave that tells the truth
b) Let John and Bill be two inhabitants of the island. John says, ”We are both knaves,” but Bill
says nothing. Can you find out what types John and Bill are?
We define:
14