Unformatted text preview: Foundations of Logic 1 Foundations of Logic
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.
2 Foundations of Logic: Overview
• Propositional logic (1.11.2):
– Basic definitions. (1.1)
– Equivalence rules & derivations. (1.2) • Predicate logic (1.31.4)
– Predicates.
– Quantified predicate expressions.
– Equivalences & derivations.
3 Propositional Logic (1.1)
Propositional Logic is the logic of compound
statements built from simpler statements
using socalled Boolean connectives.
Some applications in computer science:
• Design of digital electronic circuits.
• Expressing conditions in programs.
• Queries to databases & search engines. 4 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 situationdependent.)
[Later we will study probability theory, in which we assign
degrees of certainty to propositions. But for now: think
True/False only!]
5 Examples of Propositions
• “It is raining.” (In a given situation.)
• “Toronto is the capital of Canada.” • “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 nontrue/false value)
6 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.
7 Some Popular Boolean Operators
Formal Name Nickname Arity Negation operator
Conjunction operator NOT
AND Disjunction operator
OR
ExclusiveOR operator XOR
Implication operator
IMPLIES
Biconditional operator IFF Unary
Binary
Binary
Binary
Binary
Binary Symbol
¬ ↔
8 The Negation Operator
The unary negation operator “¬” (NOT)
transforms a prop. into its logical negation.
E.g. If p = “I have brown hair.”
then ¬p = “I do not have brown hair.”
Truth table for NOT:
p p
T F
T :≡ True; F :≡ False
“:≡” means “is defined as”
F T
Operand
column Result
column 9 The Conjunction Operator
The binary conjunction operator “” (AND)
combines two propositions to form their
ND
logical conjunction.
E.g. If p=“I will have rice for lunch.” and
q=“I will have noodles for dinner.”, then
pq=“I will have rice for lunch and
I will have noodles for dinner.”
Remember: “” points up like an “A”, and it means “ND” 10 Conjunction Truth Table
Operand columns • Note that a
p q
p q
conjunction
F F
F
p 1 p 2 … pn
F T
F
of n propositions
T F
F
will have 2n rows
in its truth table.
T T
T
• Also: ¬ and operations together are sufficient to express any Boolean truth table!
11 The Disjunction Operator
The binary disjunction operator “” (OR)
combines two propositions to form their
logical disjunction.
p=“My car has a bad engine.” q=“ My car has a bad carburetor.”
pq=“Either my car has a bad engine, or
the downwardmy car has a bad carburetor.” After
pointing “axe” of “”
Meaning is like “and/or” in English. splits the wood, you
can take 1 piece OR the
other, or both. 12 Disjunction Truth Table
• Note that pq means
p q p q
that p is true, or q is
F
F
F
true, or both are true!
Note
F T T difference
• So, this operation is
T F T from AND
also called inclusive or,
T
T
T
because it includes the
possibility that both p and q are true.
• “¬” and “” together are also universal.
13 Nested Propositional Expressions
• Use parentheses to group subexpressions:
“I just saw my old friend, and either he’s
grown or I’ve shrunk.” = f (g s)
– (f g) s would mean something different
– f g s would be ambiguous • By convention, “¬” takes precedence over
both “” and “”.
– ¬s f means (¬s) f , not ¬ (s f)
14 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.”
“The lawn was wet this morning, and
r ¬p
= 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.” 15 The Exclusive Or Operator
The binary exclusiveor operator “” (XOR)
combines two propositions to form their
logical “exclusive or” (exjunction?).
p = “I will earn an A in this course,”
q = “I will drop this course,”
p q = “I will either earn an A for this
course, or I will drop it (but not both!)”
16 ExclusiveOr Truth Table
• Note that pq means
p q pq
that p is true, or q is
F
F
F
true, but not both!
F T T
• This operation is
T F T
called exclusive or,
T
T
F
because it excludes the
possibility that both p and q are true.
• “¬” and “” together are not universal. Note
difference
from OR. 17 The Implication Operator
antecedent consequent The implication p q states that p implies q.
I.e., If p is true, then q is true; but if p is not
true, then q could be either true or false.
E.g., let p = “You study hard.”
q = “You will get a good grade.”
p q = “If you study hard, then you will get
a good grade.” (else, it could go either way)
18 Implication Truth Table
• p q is false only when
p is true but q is not true.
• p q does not say
that p causes q!
• p q does not require
that p or q are ever true!
• E.g. “(1=0) pigs can fly” is TRUE! The
only
False
case! 19 Examples of Implications
• “If this lecture 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?
20 Why does this seem wrong?
• Consider a sentence like,
– “If I wear a red shirt tomorrow, then the U.S. will attack
Iraq the same day.” • In logic, we consider the sentence True so long as
either I don’t wear a red shirt, or the US attacks.
• But in normal English conversation, if I were to
make this claim, you would think I was lying.
– Why this discrepancy between logic & language? 21 Resolving the Discrepancy
• In English, a sentence “if p then q” usually really
implicitly means something like,
– “In all possible situations, if p then q.” • That is, “For p to be true and q false is impossible.”
• Or, “I guarantee that no matter what, if p, then q.” • This can be expressed in predicate logic as: – “For all situations s, if p is true in situation s, then q is also
true in situation s”
– Formally, we could write: s, P(s) → Q(s) • This sentence is logically False in our example,
because for me to wear a red shirt and the U.S. not to
attack Iraq is a possible (even if not actual) situation.
– Natural language and logic then agree with each other. 22 English Phrases Meaning p q
•
•
•
•
•
•
•
• “p implies q”
“if p, then q”
“if p, q”
“when p, q”
“whenever p, q”
“q if p”
“q when p”
“q whenever p” •
•
•
•
• “p only if q”
“p is sufficient for q”
“q is necessary for p”
“q follows from p”
“q is implied by p” We will see some equivalent
logic expressions later. 23 Converse, Inverse, Contrapositive
Some terminology, for an implication p q:
• Its converse is:
q p.
• Its inverse is:
¬p ¬q.
• Its contrapositive: ¬q ¬ p.
• One of these three has the same meaning
(same truth table) as p q. Can you figure
out which?
24 How do we know for sure?
Proving the equivalence of p q and its
contrapositive using truth tables: p
F
F
T
T q
F
T
F
T q
T
F
T
F p
T
T
F
F p q q p
T
T
T
T
F
F
T
T
25 The biconditional operator
The biconditional p q states that p is true if and
only if (IFF) q is true.
p = “You can take the flight.”
q = “You buy a ticket.”
p q = “You can take the flight if and only if you
buy a ticket.” 26 Biconditional Truth Table
• p q means that p and q
have the same truth value.
• Note this truth table is the
exact opposite of ’s!
– p q means ¬(p q) p
F
F
T
T q pq
F T
T F
F F
T T • p q does not imply
p and q are true, or cause each other. 27 Boolean Operations Summary
• We have seen 1 unary operator (out of the 4
possible) and 5 binary operators (out of the
16 possible). Their truth tables are below. p
F
F
T
T q
F
T
F
T p p q p q pq p q pq
T F
F
F
T
T
T F
T
T
T
F
F F
T
T
F
F
F T
T
F
T
T
28 Some Alternative Notations
N
a
m
e
: n
o
ta
n
do
rx
o
ri
m
p
l
i
e
s i
f
f
P
r
o
p
o
s
i
t
i
o
n
a
ll
o
g
i
c
: B
o
o
l
e
a
n
a
l
g
e
b
r
a
:
pp
q+
C
/
C
+
+
/
J
a
v
a
(
w
o
r
d
w
i
s
e
)
:!
&
&


!
=
=
=
C
/
C
+
+
/
J
a
v
a
(
b
i
t
w
i
s
e
)
: ~&^
L
o
g
i
c
g
a
t
e
s
: 29 Bits and Bit Operations
•
•
• John Tukey
A bit is a binary (base 2) digit: 0 or 1.
(19152000)
Bits may be used to represent truth values.
By convention:
0 represents “false”; 1 represents “true”.
• Boolean algebra is like ordinary algebra
except that variables stand for bits, + means
“or”, and multiplication means “and”. – See chapter 10 for more details.
30 Bit Strings
• A Bit string of length n is an ordered series
or sequence of n0 bits.
– More on sequences in 3.2. • By convention, bit strings are written left to
right: e.g. the first bit of “1001101010” is 1.
• When a bit string represents a base2
number, by convention the first bit is the
most significant bit. Ex. 11012=8+4+1=13.
31 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 Bitwise OR
01 0001 0100 Bitwise AND
10 1010 1011 Bitwise XOR
32 End of 1.1
You have learned about:
• Propositions: What
they are.
• Propositional logic
operators’
–
–
–
– Symbolic notations.
English equivalents.
Logical meaning.
Truth tables. • Atomic vs. compound
propositions.
• Alternative notations.
• Bits and bitstrings.
• Next section: 1.2
– Propositional
equivalences.
– How to prove them. 33 Propositional Equivalence (1.2)
Two syntactically (i.e., textually) different
compound propositions may be the
semantically identical (i.e., have the same
meaning). We call them equivalent. Learn:
• Various equivalence rules or laws.
• How to prove equivalences using symbolic
derivations.
34 Tautologies and Contradictions
A tautology is a compound proposition that is
true no matter what the truth values of its
atomic propositions are!
Ex. p p [What is its truth table?]
A contradiction is a compound proposition
that is false no matter what! Ex. p p
[Truth table?]
Other compound props. are contingencies.
35 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.
36 Proving Equivalence
via Truth Tables
Ex. Prove that pq (p q).
p
F
F
T
T q
F
T
F
T p q
F
T
T
T p
T
T
F
F q p q ( p q)
T
T
F
F
F
T
T
F
T
F
F
T 37 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.
38 Equivalence Laws  Examples
•
•
•
•
•
• Identity:
pT p
p F p
Domination:
pT T pF F
Idempotent:
p p p
p p p
Double negation:
p p
Commutative: pq qp pq qp
Associative:
(pq)r p(qr)
(pq)r p(qr)
39 More Equivalence Laws
• Distributive: p(qr) (pq)(pr)
p(qr) (pq)(pr) • De Morgan’s:
(pq) p q
(pq) p q
• Trivial tautology/contradiction:
p p T
p p F Augustus
De Morgan
(18061871) 40 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)
41 Review: Propositional Logic
(1.11.2)
•
•
•
•
• Atomic propositions: p, q, r, …
Boolean operators: Compound propositions: s : (p q) r
Equivalences: pq (p q)
Proving equivalences using:
– Truth tables.
– Symbolic derivations. p q r …
42 Predicate Logic (1.3)
• Predicate logic is an extension of
propositional logic that permits concisely
reasoning about whole classes of entities.
• Propositional logic (recall) treats simple
propositions (sentences) as atomic entities.
• In contrast, predicate logic distinguishes the
subject of a sentence from its predicate.
– Remember these English grammar terms?
43 Applications of Predicate Logic
It is the formal notation for writing perfectly
clear, concise, and unambiguous
mathematical definitions, axioms, and
theorems (more on these in chapter 3) for
any branch of mathematics.
Predicate logic with function symbols, the “=” operator, and a
few proofbuilding rules is sufficient for defining any
conceivable mathematical system, and for proving
anything that can be proved within that system!
44 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. Kurt Gödel
19061978 • I.e., we can’t discover all mathematical truths,
unless we sometimes resort to making guesses.
45 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).
46 Subjects and Predicates
• In the sentence “The dog is sleeping”:
– The phrase “the dog” denotes the subject the object or entity that the sentence is about.
– The phrase “is sleeping” denotes the predicatea property that is true of the subject. • In predicate logic, a predicate is modeled as
a function P(·) from objects to propositions.
– P(x) = “x is sleeping” (where x is any object).
47 More About Predicates
• Convention: Lowercase variables x, y, z... denote
objects/entities; uppercase variables P, Q, R…
denote propositional functions (predicates).
• Keep in mind that the result of applying a
predicate P to an object x is the proposition P(x).
But the predicate P itself (e.g. P=“is sleeping”) is
not a proposition (not a complete sentence).
– E.g. if P(x) = “x is a prime number”,
P(3) is the proposition “3 is a prime number.”
48 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.”
49 Universes of Discourse (U.D.s)
• The power of distinguishing objects from
predicates is that it lets you state things
about many objects at once.
• E.g., let P(x)=“x+1>x”. We can then say,
“For any number x, P(x) is true” instead of
(0+1>0) (1+1>1) (2+1>2) ...
• The collection of values that a variable x
can take is called x’s universe of discourse.
50 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.
51 The Universal Quantifier • Example:
Let the u.d. of x be parking spaces at UCSI.
Let P(x) be the predicate “x is full.”
Then the universal quantification of P(x),
x P(x), is the proposition:
– “All parking spaces at UCSI are full.”
– i.e., “Every parking space at UCSI is full.”
– i.e., “For each parking space at UCSI, that space is full.” 52 The Existential Quantifier • Example:
Let the u.d. of x be parking spaces at UCSI.
Let P(x) be the predicate “x is full.”
Then the existential quantification of P(x),
x P(x), is the proposition:
–
–
– “Some parking space at UCSI is full.”
“There is a parking space at UCSI that is full.”
“At least one parking space at UCSI is full.”
53 Free and Bound Variables
• An expression like P(x) is said to have a
free variable x (meaning, x is undefined).
• A quantifier (either or ) operates on an
expression having one or more free
variables, and binds one or more of those
variables, to produce an expression having
one or more bound variables.
54 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 bonafide (actual) proposition.
• An expression with one or more free variables is
still only a predicate: x P(x,y)
55 Nesting of Quantifiers (1.4)
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.)
56 Review: Propositional Logic
(1.11.2)
•
•
•
•
• Atomic propositions: p, q, r, …
Boolean operators: Compound propositions: s (p q) r
Equivalences: pq (p q)
Proving equivalences using:
– Truth tables.
– Symbolic derivations. p q r …
57 Review: Predicate Logic (1.3)
• Objects x, y, z, …
• Predicates P, Q, R, … are functions
mapping objects x to propositions P(x).
• Multiargument predicates P(x, y).
• Quantifiers: [x P(x)] :≡ “For all x’s, P(x).”
[x P(x)] :≡ “There is an x such that P(x).”
• Universes of discourse, bound & free vars.
58 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)!
59 Natural language is ambiguous!
• “Everybody likes somebody.”
– For everybody, there is somebody they like, x y Likes(x,y) [Probably more likely.] – or, there is somebody (a popular person) whom
everyone likes? y x Likes(x,y) • “Somebody likes everybody.”
– Same problem: Depends on context, emphasis.
60 Still More Conventions
• Sometimes the universe of discourse is
restricted within the quantification, e.g., x>0 P(x) is shorthand for
“For all x that are greater than zero, P(x).”
=x (x>0 P(x)) x>0 P(x) is shorthand for
“There is an x greater than zero such that P(x).”
=x (x>0 P(x))
61 Review: Predicate Logic (1.3)
• Objects x, y, z, …
• Predicates P, Q, R, … are functions
mapping objects x to propositions P(x).
• Multiargument predicates P(x, y).
• Quantifiers: (x P(x)) =“For all x’s, P(x).”
(x P(x))=“There is an x such that P(x).” 62 Deduction Example
• Definitions:
g :≡ Gandhi;
H(x) :≡ “x is human”;
M(x) :≡ “x is mortal”.
• Premises:
H(g)
Gandhi is human.
x H(x)M(x)
All humans are mortal.
63 Deduction Example Continued
Some valid conclusions you can draw:
H(g)M(g) [Instantiate universal.] If Gandhi is human
then he is mortal.
H(g) M(g)
Gandhi is inhuman or mortal.
H(g) (H(g) M(g))
Gandhi is human, and also either inhuman or mortal.
(H(g) H(g)) (H(g) M(g))
[Apply distributive law.]
F (H(g) M(g))
[Trivial contradiction.]
H(g) M(g)
[Use identity law.]
M(g)
Gandhi ...
View
Full Document
 Summer '16
 Ms.Preethi Subramaniam
 Logic, Predicate logic