1.1-1.4 Logic
1.1-1.4 Logic
Module #1:
The Fundamentals of Logic
1
Module #1 - Logic
Chrysippus of Soli
05/02/25 (c)2001-2004, Michael P. Frank (ca. 281 B.C. – 205 B.C.)4
Module #1 - Logic Topic #1 – Propositional Logic
Definition of a Proposition
Definition: A proposition (denoted p, q, r, …) is simply:
• a statement (i.e., a declarative sentence)
– with some definite meaning, (not vague or ambiguous)
• having a truth value that’s either true (T) or false (F)
– it is never both, neither, or somewhere “in between!”
• However, you might not know the actual truth value,
• and, the truth value might depend on the situation or context.
• Later, we will study probability theory, in which we assign
degrees of certainty (“between” T and F) to propositions.
– But for now: think True/False only!
Examples of Propositions
• “It is raining.” (In a given situation.)
• “Beijing is the capital of China.” • “1 + 2 = 3”
But, the following are NOT propositions:
• “Who’s there?” (interrogative, question)
• “La la la la la.” (meaningless interjection)
• “Just do it!” (imperative, command)
• “Yeah, I sorta dunno, whatever...” (vague)
• “1 + 2” (expression with a non-true/false value)
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 their truth values)
instead of on numbers.
05/02/25 (c)2001-2004, Michael P. Frank 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:
¬p = “It didn’t rain last night.”
r ¬p = “The lawn was wet this morning, and
it didn’t rain last night.”
¬rpq= “Either the lawn wasn’t wet this
morning, or it rained last night, or
the sprinklers came on last night.”
05/02/25 (c)2001-2004, Michael P. Frank 15
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators
Examples of Implications
• “If this lecture ever ends, then the sun will
rise tomorrow.” True or False?
• “If Tuesday is a day of the week, then I am
a penguin.” True or False?
• “If 1+1=6, then Bush is president.”
True or False?
• “If the moon is made of green cheese, then I
am richer than Bill Gates.” True or False?
05/02/25 (c)2001-2004, Michael P. Frank 21
Module #1 - Logic
N
a
me: no
ta
ndo
rxo
rimp
l
ies i
ff
P
r
oposi
ti
onall
ogic
:
B
ool
eanalg
ebra
: ppq+
C
/C++/
Java(wor
dw i
se)
:! &&|
| !
= ==
C
/C++/
Java(b
it
w i
se)
: ~&|^
L
og
i
c g
at
es:
Bit Strings
• A Bit string of length n is an ordered sequence
(series, tuple) of n0 bits.
– More on sequences in §3.2.
• By convention, bit strings are (sometimes) written
left to right:
– e.g. the “first” bit of the bit string “1001101010” is 1.
– Watch out! Another common convention is that the
rightmost bit is bit #0, the 2nd-rightmost is bit #1, etc.
• When a bit string represents a base-2 number, by
convention, the first (leftmost) bit is the most
significant bit. Ex. 11012=8+4+1=13.
Counting in Binary
• Did you know that you can count
to 1,023 just using two hands?
– How? Count in binary!
• Each finger (up/down) represents 1 bit.
• To increment: Flip the rightmost (low-order) bit.
– If it changes 1→0, then also flip the next bit to the left,
• If that bit changes 1→0, then flip the next one, etc.
• 0000000000, 0000000001, 0000000010, …
…, 1111111101, 1111111110, 1111111111
Bitwise Operations
• Boolean operations can be extended to
operate on bit strings as well as single bits.
• E.g.:
01 1011 0110
11 0001 1101
11 1011 1111 Bit-wise OR
01 0001 0100 Bit-wise AND
10 1010 1011 Bit-wise XOR
05/02/25 (c)2001-2004, Michael P. Frank 34
Module #1 - Logic
End of §1.1
You have learned about: • Atomic vs. compound
• Propositions: What propositions.
they are. • Alternative notations.
• Propositional logic • Bits and bit-strings.
operators’ • Next section: §1.2
– Symbolic notations. – Propositional
– English equivalents. equivalences.
– Logical meaning. – How to prove them.
– Truth tables.
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.
05/02/25 (c)2001-2004, Michael P. Frank 38
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences
Proving Equivalence
via Truth Tables
Ex. Prove that pq (p q).
p q p q p q p q ( p q)
F F F T T T F
F T T T F F T
T F T F T F T
T T T F F F T
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.
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) [Expand defn. of ]
(p q) ((p r) (p r))
[DeMorgan’s
Law]
(p q) ((p r) (p r))
cont.
05/02/25 (c)2001-2004, Michael P. Frank 44
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.
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: Kurt Gödel
– Given any finitely describable, consistent 1906-1978
proof procedure, there will always remain some
true statements that will never be proven
by that procedure.
• I.e., we can’t discover all mathematical truths,
unless we sometimes resort to making guesses.
05/02/25 (c)2001-2004, Michael P. Frank 50
Module #1 - Logic Topic #3 – Predicate Logic
Practical Applications
of Predicate Logic
• It is the basis for clearly expressed formal
specifications for any complex system.
• It is basis for automatic theorem provers and
many other Artificial Intelligence systems.
– E.g. automatic program verification systems.
• Predicate-logic like statements are supported by
some of the more sophisticated database query
engines and container class libraries
– these are types of programming tools.
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.”
Quantifier Expressions
• Quantifiers provide a notation that allows
us to quantify (count) how many objects in
the univ. of disc. satisfy a given predicate.
• “” is the FORLL or universal quantifier.
x P(x) means for all x in the u.d., P holds.
• “” is the XISTS or existential quantifier.
x P(x) means there exists an x in the u.d.
(that is, 1 or more) such that P(x) is true.
05/02/25 (c)2001-2004, Michael P. Frank 56
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: e.g. let Q(y) = x P(x,y)
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.)
Quantifier Exercise
If R(x,y)=“x relies upon y,” express the
following in unambiguous English:
Everyone has someone to rely on.
x(y R(x,y))=
There’s a poor overburdened soul whom
y(x R(x,y))= everyone relies upon (including himself)!
x(y R(x,y))= There’s some needy person who relies
upon everybody (including himself).
y(x R(x,y))=Everyone has someone who relies upon them.
x(y R(x,y))= Everyone relies upon everybody,
(including themselves)!
05/02/25 (c)2001-2004, Michael P. Frank 63
Module #1 - Logic Topic #3 – Predicate Logic
B(so-and-so,such-and-such) case?
Calculus Example
• One way of precisely defining the calculus
concept of a limit, using quantifiers:
lim f ( x) L
x a
0 : 0 : x :
| x a | | f ( x) L |
05/02/25 (c)2001-2004, Michael P. Frank 76
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.
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.”)
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)]
x G(x)H(x) [Transitivity of .]
x G(x) H(x) [Definition of .]
x (G(x) H(x)) [DeMorgan’s law.]
x G(x) H(x) [An equivalence law.]
05/02/25 (c)2001-2004, Michael P. Frank 80
Module #1 - Logic
Facts in Prolog
• A fact in Prolog represents a simple, non-
compound proposition in predicate logic.
– e.g., “John likes Mary”
• can be written Likes(John,Mary) in predicate logic.
• can be written likes(john,mary). in Prolog!
– Lowercase symbols must be used for all constants and
predicates, uppercase is reserved for variable names.
Rules in Prolog
• A rule in Prolog represents a universally
quanitifed proposition of the general form
x: [y P(x,y)]→Q(x),
where x and y might be compound variables
x=(z,w) and P,Q compound propositions.
• In Prolog, this is written as the rule:
q(X) :- p(X,Y). ← Variables must be capitalized
i.e., the , quantifiers are implicit.
• Example: likable(X) :- likes(Y,X).
Deduction in Prolog
• When a query is input to the Prolog
interpreter,
– it searches its database to determine if the query
can be proven true from the available facts.
– if so, it returns “yes”, if not, “no”.
– If the query contains any variables, all values
that make the query true are printed.