Module 1 Logic
Module 1 Logic
Module #1:
Foundations of Logic
Rosen 6th ed., §§1.1-1.4
~74 slides, ~4-6 lectures
2024/10/9 1
Module #1 - Logic
Module #1: Foundations of Logic
(§§1.1-1.3, ~3 lectures)
Mathematical Logic is a tool for working with
complicated compound statements. It
includes:
A language for expressing them.
A concise notation for writing them.
A methodology for objectively reasoning
about their truth or falsity.
It is the foundation for expressing
formal proofs in all branches of
mathematics.
2024/10/9 2
Module #1 - Logic
2024/10/9 3
Module #1 - Logic Topic #1 – Propositional Logic
2024/10/9 4
Module #1 - Logic Topic #1 – Propositional Logic
Definition of a Proposition
A proposition (p, q, r, …) is simply a
statement (i.e., a declarative sentence)
with a definite meaning, having a truth
value that’s either true (T) or false (F)
(never both, neither, or somewhere in
between).
(However, you might not know the actual
truth value, and it might be situation-
dependent.)
[Later we will study probability theory, in which we
assign degrees of certainty to propositions. But
for now: think True/False only!]
2024/10/9 5
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
Operators / Connectives
An operator or connective combines
one or more operand expressions
into a larger expression. (E.g., “+”
in numeric exprs.)
Unary operators take 1 operand
(e.g., −3); binary operators take 2
operands (eg 3 4).
Propositional or Boolean operators
operate on propositions or truth
values instead of on numbers.
2024/10/9 6
Module #1 - Logic
Some Popular Boolean
Operators
2024/10/9 7
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
A Simple Exercise
Let p=“It rained last night”,
q=“The sprinklers came on last
night,”
r=“The lawn was wet this morning.”
Translate each of the following into
English: “It didn’t rain last night.”
“The lawn was wet this morning, and
¬p =it didn’t rain last night.”
r ¬p = “Either the lawn wasn’t wet this
morning, or it rained last night, or
¬ r p q = the sprinklers came on last night.”
2024/10/9 14
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
2024/10/9 17
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
2024/10/9 18
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
2024/10/9 19
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
2024/10/9 20
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
p q q p pq q p
F F T T T T
F T F T T T
T F T F F F
T T F F T T
2024/10/9 22
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
2024/10/9 23
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
2024/10/9 24
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
2024/10/9 26
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
2024/10/9 27
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
2024/10/9 28
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
Logical Equivalence
Compound proposition p is logically
equivalent to compound proposition
q, written pq, IFF the compound
proposition pq is a tautology.
Compound propositions p and q are
logically equivalent to each other IFF
p and q contain the same truth
values as each other in all rows of
their truth tables.
2024/10/9 29
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
Proving Equivalence
via Truth Tables
Ex. Prove that pq (p q).
2024/10/9 30
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
Equivalence Laws
These are similar to the arithmetic
identities you may have learned in
algebra, but for propositional
equivalences instead.
They provide a pattern or template
that can be used to match all or part
of a much more complicated
proposition and to find an
equivalence for it.
2024/10/9 31
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
2024/10/9 32
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
2024/10/9 33
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
Defining Operators via
Equivalences
Using equivalences, we can define
operators in terms of other operators.
Exclusive or: pq (pq)(pq)
pq
(pq)(qp)
Implies: pq p q
Biconditional: pq (pq) (qp)
pq (pq)
2024/10/9 34
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
An Example Problem
Check using a symbolic derivation whether
(p q) (p r) p q r.
(p q) (p r)
[Expand definition of ] (p q) (p r)
[Defn. of ] (p q) ((p r) (p
r))
[DeMorgan’s Law]
(p q) ((p r) (p
r))
[associative law] cont.
2024/10/9 35
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
Example Continued...
(p q) ((p r) (p r)) [ commutes]
(q p) ((p r) (p r)) [ associative]
q (p ((p r) (p r))) [distrib. over ]
q (((p (p r)) (p (p r)))
[assoc.] q (((p p) r) (p (p r)))
[trivail taut.] q ((T r) (p (p r)))
[domination] q (T (p (p r)))
[identity] q (p (p r)) cont.
2024/10/9 36
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
Other Applications
Predicate logic is the foundation of the
field of mathematical logic, which
culminated in Gödel’s incompleteness
theorem, which revealed the ultimate
limits of mathematical thought:
– Given any finitely describable, consistent
proof procedure, there will still be some
true statements that can never be proven
by that procedure.
I.e.,we can’t discover all
mathematical truths, unless we
sometimes resort to making guesses.
2024/10/9 40
Module #1 - Logic Topic #3 – Predicate Logic
Practical Applications
Basis for clearly expressed formal
specifications for any complex
system.
Basis for automatic theorem provers
and many other Artificial Intelligence
systems.
Supported by some of the more
sophisticated database query engines
and container class libraries
(these are types of programming
tools).
2024/10/9 41
Module #1 - Logic
Deductive Database
example tables
PART_COST ASSEMBLY
BASIC_PART SUPPLIER COST TIME PART SUBPART QTY
top_tube cinelli 20.00 14
top_tube columbus 15.00 6 bike frame 1
down_tube columbus 10.00 6 bike wheel 2
head_tube cinelli 20.00 14 frame top_tube 1
head_tube columbus 15.00 6 frame down_tube 1
seat_mast cinelli 20.00 6 frame head_tube 1
seat_mast cinelli 15.00 14
seat_stay cinelli 15.00 14 frame seat_mast 1
seat_stay columbus 10.00 6 frame seat_stay 2
chain_stay columbus 10.00 6 frame chain_stay 2
fork cinelli 40.00 14 frame fork 1
fork columbus 30.00 6 wheel spoke 36
spoke campagnolo 0.60 15
nipple mavic 0.10 3
wheel nipple 36
hub campagnolo 31.00 5 wheel rim 1
hub suntour 18.00 14 wheel hub 1
rim mavic 50.00 3 wheel tire 1
rim araya 7.00 1
2024/10/9 42
Module #1 - Logic
Example
Try writing a program for the following
query: Find the maximum time required
for basic subparts of the given assembly
(assuming each basic subpart is delivered
by fastest provider)?
2024/10/9 43
Module #1 - Logic
Example
All subparts: a transitive-closure query
all_subparts(Part,Sub)
assembly(Part, Sub, _).
all_subparts(Part, Sub2)
all_subparts(Part, Sub1),
assembly(Sub1, Sub2, _ ).
For each part, basic or otherwise, find its basic subparts. A
basic part is a subpart of itself :
basic_subparts(BasicP, BasicP)
part_cost(BasicP,_ , _, _).
basic_subparts(Prt, BasicP)
assembly(Prt, SubP, _),
basic_subparts(SubP, BasicP).
2024/10/9 44
Module #1 - Logic
Example
For each basic part find the least
time needed for delivery
fastest(Part, Time)
part_cost(Part, Sup1,Cost,Time),
faster(Part, Time).
faster(Part, Time)
part_cost(Part, Sup2, Cost, Time),
part_cost(Part,Sup1,Cost,Time1),
Time1<Time.
2024/10/9 45
Module #1 - Logic
Example
Times required for basic subparts of the given assembly
timeForbasic(AssPart, BasicSub, Time)
basic_subparts(AssPart,BasicSub),
fastest(BasicSub, Time).
The maximum time required for basic subparts of the given
assembly
howsoon(AssPart, Time)
timeForbasic(AssPart, _, Time),
slower(AssPart, Time).
slower(Part, Time)
timeForbasic(Part, _(basic1) , Time),
timeForbasic(Part, _(basic2) , Time1),
Time1 > Time.
Note: to compute howsoon you must first compute larger
completely.
2024/10/9 46
Module #1 - Logic Topic #3 – Predicate Logic
2024/10/9 47
Module #1 - Logic Topic #3 – Predicate Logic
Propositional Functions
Predicate logic generalizes the
grammatical notion of a predicate to
also include propositional functions of
any number of arguments, each of
which may take any grammatical
role that a noun can take.
– E.g. let P(x,y,z) = “x gave y the grade
z”, then if
x=“Mike”, y=“Mary”, z=“A”, then P(x,y,z)
= “Mike gave Mary the grade A.”
2024/10/9 49
Module #1 - Logic Topic #3 – Predicate Logic
Quantifier Expressions
Quantifiers provide a notation that allows us to
quantify (count) how many objects in the univ.
of disc. satisfy a given predicate.
2024/10/9 51
Module #1 - Logic Topic #3 – Predicate Logic
Example of Binding
P(x,y) has 2 free variables, x and y.
x P(x,y) has 1 free variable, and one
bound variable. [Which is which?]
“P(x), where x=3” is another way to bind
x.
An expression with zero free variables is a
bona-fide (actual) proposition.
An expression with one or more free
variables is still only a predicate: x P(x,y)
2024/10/9 55
Module #1 - Logic Topic #3 – Predicate Logic
Nesting of Quantifiers
Example: Let the u.d. of x & y be people.
Let L(x,y)=“x likes y” (a predicate w. 2 f.v.’s)
Then y L(x,y) = “There is someone whom x
likes.” (A predicate w. 1 free variable, x)
Then x (y L(x,y)) =
“Everyone has someone whom they like.”
(A __________ with ___ free variables.)
2024/10/9 56
Module #1 - Logic
Review: Propositional Logic
(§§1.1-1.2)
Atomic propositions: p, q, r, …
Boolean operators:
2024/10/9 57
Module #1 - Logic Topic #3 – Predicate Logic
Quantifier Exercise
If R(x,y)=“x relies upon y,” express
the following in unambiguous English:
x(y R(x,y))= Everyone has someone to rely on.
y(x R(x,y))= There’s a poor overburdened soul whom
x(y R(x,y))= everyone relies upon (including himself)!
There’s some needy person who relies
y(x R(x,y))=upon everybody (including himself).
x(y R(x,y))=Everyone has someone who relies upon them.
Everyone relies upon everybody,
(including themselves)!
2024/10/9 58
Module #1 - Logic Topic #3 – Predicate Logic
2024/10/9 63
Module #1 - Logic Topic #3 – Predicate Logic
Defining New Quantifiers
As per their name, quantifiers can be
used to express that a predicate is true
of any given quantity (number) of
objects.
Define !x P(x) to mean “P(x) is true of
exactly one x in the universe of
discourse.”
!x P(x) x (P(x) y (P(y) y x))
“There is an x such that P(x), where
there is no y such that P(y) and y is
other than x.”
2024/10/9 64
Module #1 - Logic Topic #3 – Predicate Logic
Some Number Theory
Examples
Let u.d. = the natural numbers 0, 1, 2, …
“A number x is even, E(x), if and only if it
is equal to 2 times some other number.”
x (E(x) (y x=2y))
“A number is prime, P(x), iff it’s greater
than 1 and it isn’t the product of two non-
unity numbers.”
x (P(x) (x>1 yz x=yz y1
z1))
2024/10/9 65
Module #1 - Logic
Calculus Example
lim f ( x) L
quantifiers:
x a
0 : 0 : x :
| x a | | f ( x) L |
2024/10/9 67
Module #1 - Logic Topic #3 – Predicate Logic
Deduction Example
Definitions:
s :≡ Socrates (ancient Greek
philosopher);
H(x) :≡ “x is human”;
M(x) :≡ “x is mortal”.
Premises:
H(s) Socrates is
human. x H(x)M(x) All
humans are mortal.
2024/10/9 68
Module #1 - Logic Topic #3 – Predicate Logic
then he is mortal.
H(s) M(s) Socrates is inhuman
or mortal.
H(s) (H(s) M(s))
Socrates is human, and also either inhuman
or mortal.
(H(s) H(s)) (H(s) M(s)) [Apply
distributive law.]
F (H(s) M(s)) [Trivial
contradiction.]
2024/10/9 69
Module #1 - Logic Topic #3 – Predicate Logic
Another Example
Definitions: H(x) :≡ “x is human”;
M(x) :≡ “x is mortal”; G(x) :≡ “x is a
god”
Premises:
– x H(x) M(x) (“Humans are mortal”)
and
– x G(x) M(x) (“Gods are immortal”).
Show that x (H(x) G(x))
(“No human is a god.”)
2024/10/9 70
Module #1 - Logic Topic #3 – Predicate Logic
The Derivation
x H(x)M(x) and x G(x)M(x).
x M(x)H(x) [Contrapositive.]
x [G(x)M(x)] [M(x)H(x)]
2024/10/9 71
Module #1 - Logic
Example from Singapore elementary
school …
Albert and Bernard want to know Cheryl’s birthday. She gives
them 10 possible dates.
– May 15, May 16, May 19
– June 17, June 18
– July 14, July 16
– August 14, August 15, August 17
Cheryl then tells Albert and Bernard separately the month and the
day of her birthday respectively.
Albert: I don’t know when Cheryl’s birthday is, but I know that
Bernard does not know too.
Bernard: At first I don’t know when Cheryl’s birthday is, but I know
now.
Albert: Then I also know when is her birthday.