0% found this document useful (0 votes)
2 views

comp106_1_logic

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

comp106_1_logic

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 93

1.

The Foundations (Logic)

Motivation: Basis of all mathematical


reasoning and numerous applications in
computer science

 artificial intelligence
 computer programming and
algorithm development
 design of computer circuits
 etc
By the end of these lectures, you will be able

 to verify your reasoning and conclusions


“If you are older than 18 years, then you can have a driving license.” → ??
“If you can have a driving license, then you are older than 18 years,” or
“If you cannot have a driving license, then you are not older than 18 years.”

 to translate daily language into precise logical expressions


“You cannot ride the roller coaster if you are less than 1.70m tall
unless you are older than 18 years.”
“Everyone has exactly one best friend.”
1.1, 1.2 Propositional Logic

Proposition: A statement that is either true or false, but not both.

e.g.
 Snow is white
 Rain is wet
Propositions
 1+1=2
 2+3=7

 What time is it?


 Consider reading the material. Not Propositions
 x+1=2
 x+y=z

 Use letters to denote propositions:


p, q, r, s, …

Truth values: true T, false F


Compound Propositions
Many mathematical statements are constructed by combining propositions.
Compound propositions are formed by using logical operators such as:
 negation (NOT) ¬
 conjunction (AND) 
 disjunction (OR)  A cat will purr if it is not alone and is getting petted,
or if it is curled up in a sunbeam.
 exclusive or (XOR) 
 implication (IF) → You are required to take either comp106 or
 biconditional (IFF) ↔ indr201, but not both, iff you are a computer
engineering student at KU.

Truth tables:
p q ¬p pq pq pq p→q p↔q
T T F T T F T T
T F F F T T F F
F T T F T T T F
F F T F F F T T
The Connective Or in English

In English “or” has two distinct meanings.


• “Inclusive Or” - In the sentence “Students who have taken Comp100 or Math120
can take this class,” we assume that students need to have taken one of the
prerequisites, but may have taken both. This is the meaning of disjunction.
For p ∨ q to be true, either one or both of p and q must be true.
• “Exclusive Or” - When reading the sentence “Soup or salad comes with this
entrée,” we do not expect to be able to get both soup and salad. This is the
meaning of Exclusive Or (Xor).
For p ⊕ q to be true, one of p and q must be true, but not both.

p q pq pq
T T T F
T F T T
F T T T
F F F F
Implication (IF)

p q p→q
T T T
T F F
F T T
F F T

e.g. “If today is Saturday, then 2 + 2 = 4” (True any day)


“If today is Saturday, then 2 + 2 = 10” (True any day except Saturday)
“If today is Saturday, then we have a quiz” (?)
“If I am elected, then I will lower taxes.”

p→q
p: premise (hypothesis)
q: conclusion (consequence)
Understanding Implication

In p → q, there does not need to be any semantical connection between the premise
and the conclusion. The “truthness” of p → q depends only on the truth values of p
and q.

These implications are perfectly fine, but would not be used in ordinary English.

• “If the moon is made of green cheese, then I have more money than Bill Gates.”

• “If the moon is made of green cheese then I’m on welfare.”

• “If 1 + 1 = 3, then your grandma wears combat boots.”


Understanding Implication

One way to understand the logical implication is to think of it as stating a sufficient


condition:

“If you get 100% in the final, then you get an A” (p → q)

• If this statement is T, it means that to get 100% in the final is sufficient to get an
A, but not necessary.
• So even if you don’t get 100% in the final, you may still get an A.

• Suppose that you get 100% in the final and do not get an A.
• This corresponds to the case where p is true and q is false
• Hence, you understand that p → q was false (so you can object to your letter grade)

Hence, we should consider all possible truth value assignments to analyze the “meaning”
of a compound statement such as an implication.
Understanding Implication

Recall the given statement:

“If you are older than 18 years, then you have a driving license” (p → q)

• This statement does not tell anything about what happens when you are not older
than 18 years.

• So if you are not older than 18 years, you may or may not have a driving license
(we do not know).

• Hence, one cannot infer from the given statement the following: “if you have a
driving license, then you are older than 18 years”.
Common ways of expressing implication:

• if p then q
• q if p
• p implies q
• p only if q
• p is sufficient for q
• q whenever p
• q is necessary for p
• q follows from p
• q unless ¬p
p→q
Converse: q → p
Contrapositive: ¬q → ¬p

“If you are older than 18 years, then you can have a driving license”

Converse: “If you can have a driving license, then you are older than 18 years”

Contrapositive: “If you cannot have a driving license, then you are not older
than 18 years”
“If today is Thursday, then we have a quiz”
Converse: “If we have a quiz, then today is Thursday”
Contrapositive: “If we do not have a quiz today, then today is not Thursday”
Inverse: “If today is not Thursday, then we do not have a quiz”

 Contrapositive is true whenever the statement is true.


(This is NOT the case for converse and inverse)
Biconditional (IFF)

P q p↔q p ↔ q is T if both p → q is T and q → p is T.


T T T
T F F “p if and only if q”
F T F “p is necessary and sufficient for q”
F F T “if p then q, and conversely”

p ↔ q is logically equivalent to say that p → q  q → p.


Translation from English to logical expressions

Example:
“You cannot ride the roller coaster if you are less than 1.70m
tall unless you are older than 18 years.”

q: “You can ride the roller coaster”


r: “You are less than 1.70m tall”
s: “You are older than 18 years”

(r  ¬s ) → ¬q

Here “unless” is like “not if”.


e.g.*
p: “It is below freezing” q: “It is snowing”

 “It is below freezing but not snowing.”

p  ¬q

 “It’s below freezing or it’s snowing; but it’s not snowing if it’s below
freezing.”
(p  q)  (p → ¬q)

and ≈ but

* exempli gratia
Logic and bit operations:

A bit has two possible values, 0 or 1.


Binary digit  bit (John Tukey, 1946)

Bit operations  Logical operations


T → 1, F → 0

Bitwise OR, AND, XOR


1010 1110
1100 0101
1110 1111 bitwise OR
1000 0100 bitwise AND
0110 1011 bitwise XOR

In most programming languages, you can define Boolean variables with


values either T or F, or equivalently 0 or 1.
1.3 Propositional Equivalences

Logical equivalence
The propositions r and s are logically equivalent if r and s have the same truth values.

Notation: r  s

e.g.
Show that ¬(p  q)  ¬p ¬q (De Morgan’s law)

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
Tautology: A compound proposition that is always true

Contradiction: A compound proposition that is always false

Contingency: Neither tautology nor contradiction

e.g. p  ¬p p  ¬p
tautology contradiction
Logical Equivalences
pTp
pFp Identity laws

pTT
pFF Domination laws

ppp
ppp Idempotent laws

¬(¬p)  p Double Negation law

pqqp
pqqp Commutative laws
(p  q)  r  p  (q  r)
(p  q)  r  p  (q  r) Associate laws

p  (q  r)  (p  q)  (p  r)
p  (q  r)  (p  q)  (p  r) Distributive laws

¬(p  q)  ¬p  ¬q
¬(p  q)  ¬p  ¬q De Morgan’s laws
Some additional useful logical equivalences:

p  ¬p  T
p  ¬p  F
(p → q)  (¬p  q)
(p ↔ q)  (p → q)  (q → p)
(p → q)  (¬q → ¬p)

You can show all these logical equivalences using truth tables.
e.g.
Show that ¬(p → q)  p  ¬q

e.g.
Show that ¬(p ↔ q)  (p q)  (¬p  ¬q)

You can show these logical equivalences using truth tables or using
known equivalences.
Recall:

“If you are older than 18 years, then you can have a driving license” p → q

? “If you can have a driving license, then you are older than 18 years” q→p

or

✔ “If you cannot have a driving license, then you are not older than 18 years” ¬q → ¬p

since (p → q)  (¬q → ¬p)
Recall:

“If you are older than 18 years, then you can have a driving license” p → q

? “If you can have a driving license, then you are older than 18 years” q→p

- Note that p → q is not logically equivalent to q → p.

- But this doesn’t necessarily mean that q → p can not be concluded from p → q.

- We should rather ask the question: (p → q) → (q → p) ?

- Or equivalently: Is (p → q) → (q → p) a tautology?
e.g.
Is (p → q) → (q → p) a tautology?

Construct the truth-table and check whether it’s always true.


As a shortcut, observe that when p is F and q is T, the statement is F;
So it is not a tautology.

Hence, we cannot conclude q → p from p → q.

We’ll see more on this while studying "rules of inference" (next lectures).
e.g.
Show that (p  q) → (p  q) is a tautology.

(p  q) → (p  q)  ¬(p  q)  (p  q)
 (¬p  ¬q)  (p  q) De Morgan
 (¬p  p)  (¬q  q) Assoc & Comm
TT
T
Consistency of Propositions

Consider the following propositions for some software system specifications:

“Whenever the system software is being upgraded, users cannot access the file system.”
“If users can access the file system, then they can save new files.”
“If users cannot save new files, then the system software is not being upgraded.”

Are they consistent?


p q r p → ¬q q→r ¬r → ¬p
T T T F T T
The best way is to construct a truth
T T F F F F
table with
F T T T T T
p → ¬q, q → r, ¬r → ¬p
F T F T F T
(what are p, q, r ?)
T F T T T T
T F F T T F
If we can find a truth value
F F T T T T
assignment such that all propositions
F F F T T T
are T, then they are consistent,
otherwise inconsistent.
EXTRA FUN:

Everyday use: Web search on Google, Bing, Ask, Youtube, etc.

Logic puzzle 1 (Smullyan):


An island has two kinds of inhabitants: knights and knaves. Knights always tell the truth, knaves always
lie.
You encounter two people A an B. A says “B is a knight”, B says “The two of us are of opposite types”.
What are the types of A and B ?

Logic puzzle 2: A father has two children, a boy and a girl. While playing, they both get mud on their
foreheads. The father says “at least one of you have mud on your forehead”. And then asks a yes/no
question: “Do you know if you have a muddy forehead?”. The father asks the question twice. The children
are honest, there is no mirror (they cannot see their own forehead) but they see each other’s forehead, and
they answer simultaneously.
What will the boy and girl’s answers to the question the first time?
What will the boy and girl’s answers to the question the second time?
1.4 Predicates and Quantifiers

“If you are older than 18 years, then you can have a driving license”

Who is this “you” exactly?

: Universal quantifier x (P(x) →Q(x))


where
P(x): “x is older than 18 years” P(x) and Q(x): propositional functions

Q(x): “x can have a driving license”

Universe of discourse can be defined as the set of all people in Turkey.


1.4 Predicates and Quantifiers

Subject Predicate

"x is greater than 3"

This is a propositional function.

We can express it as:


P(x): x > 3

Then what are the truth values of P(4) and P(2) ?


Universal Quantification of P(x)
is the proposition “P(x) is T for all values of x in the universe of discourse (domain).”

Notation: x P(x)
“for all x P(x)”
“for every x P(x)”

: Universal quantifier
e.g.
“Every student in this class has studied calculus.”

Express this as a universal quantification.

Let P(x) denote “x has studied calculus”

Then x P(x), where universe of discourse is all the students in the class.
Domain (universe of discourse) must always be specified!

xR P(x)
“for all x in the domain of Real Numbers P(x)”
OR
x (S(x) →P(x))
where
S(x) denotes “x is in the class”
Universe of discourse is the set of all students.

Note that the mathematical expression of the same statement has


changed when the universe of discourse has changed.
e.g.
What is the truth value of x P(x),where
P(x): “x2 < 10 ”
Universe of discourse: x  {1,2,3,4}

x P(x)  P(1)  P(2)  P(3)  P(4)


F

e.g.
What is the truth value of x P(x), where
P(x): “x2 > 0 ”

General assumption: Domain = R when not specified

What about
x≠0 P(x)

DOMAIN IS CRUCIAL!!
Existential Quantification of P(x)
is the proposition “there exists an element x in the universe of discourse (domain)
such that P(x) is true”.

Notation:
x P(x)
“there exists an x s.t. P(x)”
“there is at least one x s.t. P(x)”

: Existential quantifier
e.g.
P(x): x2 > 10, x  {1, 2, 3, 4}

x P(x)  P(1)  P(2)  P(3)  P(4)


T
e.g.
P(x): x>3 x  {…, –1, 0, 1,…} (Z : Integers)
x P(x)  T

e.g.
P(x): x = x +1, x  R
x P(x)  F

e.g.
P(x):x2 ≥ x
x P(x) if x  Z ?
x P(x) if x  R ?
Precedence of Quantifiers

The quantifiers  and  have higher precedence than all the logical operators.

e.g. x P(x)  Q(x) means (x P(x))  Q(x)

x (P(x)  Q(x)) means something different.

Unfortunately, often people may write x P(x)  Q(x) when they mean x (P(x)  Q(x)).

DO NOT DO THIS !
Negation of Quantified Statements

¬(x P(x))  x ¬P(x) equivalent to say x (P(x) is F)

¬(x P(x))  x ¬P(x) equivalent to say x (P(x) is F)


You can show the equivalences ¬(x P(x))  x ¬P(x) and ¬(x P(x))  x ¬P(x)
by using De Morgan’s rule.

e.g.
P(x): x2 > 10, x  {1, 2, 3, 4}

Negation of x P(x) ?

¬x P(x)  ¬(P(1)  P(2)  P(3)  P(4))


 ¬P(1)  ¬P(2)  ¬P(3)  ¬P(4) by De Morgan’s rule
 x ¬P(x)

Note that above, we only demonstrate this equivalence on an example.

This is not a proof by any means, yet it can easily be generalized to


show that the equivalence is true in the general case.
1.5 Nested Quantifiers

Translating Sentences into Logical Expressions

e.g.
“Everyone has at least one best friend.”

Let B(x,y): “y is the best friend of x”


Universe of discourse for both x and y is the set of all students in this class.

x y B(x, y)
The Order of Quantifiers

The order of quantifiers is important! unless all quantifiers are universal or


existential.

e.g.
x y P(x,y) is not equivalent to yx P(x,y).

Let P(x,y) be the statement “ x + y = 0 ”

x y P(x,y) : “ For every real number x there is a real number y such that x+y=0”

yx P(x,y) : “ There is a real number y such that for every real number x, x+y=0”

Note that above, we provide a counter-example, which is sufficient to


prove that the equivalence is not true in general.

Hence, counter examples are sufficient to disprove a given statement;


but not to prove it.
e.g. Negate “Some student in this class has solved every exercise in the book.”

“Some student in this class has not solved every exercise in the book.” ?

Not correct! (since it does not exclude the case where a student has solved every exercise)

Let S(x,y) be “student x has solved exercise y”, where the universe of discourse for x is the
set of students in this class, and for y, the set of exercises in the book.

¬xy S(x,y)  xy ¬S(x,y)

“For every student x in this class, there is an exercise y that student x has not solved.”
Equivalently “No student in this class has solved every exercise in the book.”
e.g. Negate “Some student in this class has solved every exercise in the book.”

What if the universe of discourse for x is the set of all students, and for y, the set of
exercises in the book?

S(x,y): “Student x has solved exercise y”


Q(x):“Student x is in this class”

¬xy (Q(x)  S(x,y))  xy (¬Q(x)  ¬S(x,y))


 xy (Q(x) → ¬S(x,y)) this is a better form

“For every student x, if x is in this class, then there is an exercise y that x has not solved.”

Equivalently “For every student x in this class, there is an exercise y that x has not solved.”

Equivalently “No student in this class has solved every exercise in the book.”
Replacing quantifiers

e.g.
Consider Universe of discourse for x is the set
P(x,y): “Student x has solved question y” of students in this class; for y the set
Q(x): “Student x passes the exam” of questions in the exam

“If a student in this class passes the exam, then that student has solved every question”

x (Q(x) → y P(x,y) )
 x y ( Q(x) → P(x,y) )

Note that this is equivalent to say:


since Q(x) → y P(x,y)  y ( Q(x) → P(x,y))
“Every student in this class, who
passes the exam, has solved all the
questions”.
Be careful when replacing quantifiers!

Example: We cannot write


x ((yP(x,y)) → Q(x))  x y ( P(x,y) → Q(x) ) (this is wrong!)

since
y ( P(x,y) → Q(x) ) is not logically equivalent to (yP(x,y) ) → Q(x)

This is equivalent to say that a student x passes the exam How about this?
if x solves any of the questions.
Be careful when replacing quantifiers!

e.g.
Consider
P(x,y): “Student x has solved question y”
Q(x): “Student x passes the exam”

y ( P(x,y) →Q(x) ): “For every question y, if student x has solved y, x passes the exam.”

( y P(x,y) ) → Q(x): “If student x has solved every question y, x passes the exam.”

In the first case, a student x passes the exam if that student has solved any question;
In the second case, a student passes the exam if that student has solved all the questions.
So, they are not logically equivalent.
e.g. Negate x (yP(x,y) → Q(x) )

Consider
P(x,y): “Student x has solved question y”
Q(x): “Student x passes the exam”
“For every student x in this class, if x has solved every question y in the exam, x passes
the exam.”

¬ x (y P(x,y) → Q(x))  x ¬ (yP(x,y) → Q(x))  x ¬ (¬yP(x,y)  Q(x))

 x (yP(x,y)  ¬Q(x))

“There exists a student in this class, who has solved every question but does not pass the
exam.”
Recall the example:

e.g.
“Everyone has at least one best friend.”

Let B(x,y): “y is the best friend of x”


Universe of discourse for both x and y is the set of all students in this class.

x y B(x, y)
How about “Everyone has exactly one best friend”?

Universe of discourse is all the students in this class.


Let B(x,y): “y is the best friend of x”

“For every person x, there is a person y such that y is the best friend of x and
(and ??)
for every z, if z is a person other than y, then z is not the best friend of x.”

x y ( B(x, y)  z ( (z  y) → ¬B(x, z)) )

 x y z ( B(x, y)  ( (z  y) → ¬B(x, z) ) ) This works out this time; but be careful while
replacing quantifiers in general.
e.g. Negate “Everyone has exactly one best friend.”
Universe of discourse is the set of all students in the class (for both x and y).
Let B(x,y): “y is the best friend of x”
x yz ( B(x, y)  ((z  y) → ¬B(x, z)))

Negation: “Everyone does not have exactly one best friend.” ?


Not very informative! (and not very clear)

¬ xyz (B(x, y)  ((z  y) → ¬B(x, z) ))


 x ¬yz (B(x, y)  ((z  y) → ¬B(x, z) ))
 xy ¬z (B(x, y)  ((z  y) → ¬B(x, z) ))
 xyz ¬ (B(x, y)  ((z  y) → ¬B(x, z) ))
 xyz (¬B(x, y)  ¬((z  y) → ¬B(x, z) ))
 xyz (¬B(x, y)  ((z  y)  B(x, z) ))
“There is a person x such that, for every person y,
y is not the best friend of x,
OR there exists a person z other than y such that z is the best friend of x”.
An alternative way of expressing the above negation (easier to interpret):

x y z (¬B(x, y)  ((z  y)  B(x, z) ))) 


x y z (B(x, y) → ((z  y)  B(x, z) )))

“There is a person x such that, for every person y,


if y is the best friend of x,
then there exists a person z other than y such that z is the best friend of x”.

We could rephrase the same statement as:


“There is a person x such that, x has no best friend or x has more than one best friend.”
or “There is a person who has no best friend or has more than one best friend.”

Note that, for a given x, this statement is T when B(x, y) is F for all y, hence when x has no
best friend.
1.6/1.7 Mathematical Reasoning
We will learn:

 Rules of reasoning

• tell us how to reason correctly

• used to draw conclusions from other assertions and tie the steps of a proof.

Argument: a sequence of statements with a conclusion


Valid: the conclusion follows from the truth of statements (premises)

Valid does NOT mean TRUE. Valid argument means that if the premises are true, then the
conclusion is true. A valid argument may contain premises that are false:
e.g.,
“If we live on the Moon, then I am a carpenter. We live on the Moon. Therefore I am a
carpenter”
This is a valid argument, as long as we assume “We live on the Moon” is a true statement.
But the conclusion is not necessarily true since we know that one of the premises is false.
Example (Reasoning)

We have two premises:

• “All men are mortal.”

• “Socrates is a man.”

And the conclusion:

• “Socrates is mortal.”

How do we get the conclusion from the premises?


Basic rule of inference: (Modus ponens)

(p  (p → q)) → q

e.g.
“If it is sunny today, then we’ll play soccer. (given)
It is sunny today. (given)

So we’ll play soccer”.

Another notation:

p
p→q
q
Basic rule of inference: (Modus ponens)

(p  (p → q)) → q : Tautology

e.g.

“If it is sunny today, then we’ll play soccer. It is sunny today. So we’ll play soccer”.

p q p→q (p  (p → q)) → q
T T T T
T F F T
F T T T
F F T T
e.g.
It is sunny now. Therefore, it’s sunny or snowy now. Tautology
p Addition Rule
pq

e.g.
It is windy and raining now. Therefore, it is windy now. Tautology
pq Simplification Rule
p
Rule of
Inference Tautology Name
p p → (p  q) Addition
pq
pq (p  q ) → p Simplification
p
p ((p)  (q)) → (p  q) Conjunction
q
pq
p [p  (p → q)] → q Modus Ponens
p→q
q
¬q [¬q  (p → q)] → ¬p Modus Tollens
p→q
 ¬p
p→q [(p → q)  (q → r)] → (p → r) Hypothetical
q→r Syllogism
p→r
pq [(p  q )  ¬p] → q Disjunctive
¬p Syllogism
q
Fallacies: Types of incorrect reasoning:

Fallacy of affirming the conclusion:

e.g.
“If you are older than 18 years, then you can have a driving license. You can have a
driving license. Therefore, you are older than 18 years.”

[(p → q)  q] → p NOT a tautology


F when p is F and q is T

Fallacy of denying the hypothesis:

“If you are older than 18 years, then you can have a driving license. You are not older
than 18 years, so you can’t have a driving license.”

[(p → q)  ¬p] → ¬q NOT a tautology


F when p is F and q is T

Begging the question fallacy: When one or more steps of a proof are based on the truth
of the statement being proved (circular reasoning)
e.g. Show that the premises

“If you help me, then I will finish writing the program,” “If you do not help me, then I will go to
sleep early,” and “If I go to sleep early, then I will wake up feeling refreshed”

lead to the conclusion:


“If I do not finish writing the program, then I’ll wake up feeling refreshed.”

Let
p: “you help me”
q: “I’ll finish writing the program”
r: “I’ll go to sleep early”
s: “I’ll wake up feeling refreshed”

Step Reason
1. p → q premise
2. ¬q → ¬p contrapositive of step 1
3. ¬p → r premise
4. ¬q → r hypothetical syllogism using steps 2, 3
5. r → s premise
6. ¬q → s hypothesis syllogism using steps 4, 5
Rules of Inference for Quantified Statements

Universal instantiation: x P(x) U: universe of discourse


 P(c) if c  U

Existential instantiation:

If x P(x) is true then x P(x)


we know one c exists  P(c) for some element c  U
s.t. P(c) is true.

Existential generalization:

If we know one c in U P(c) for some element c  U


s.t. P(c) is true then  x P(x)
x P(x) is true
e.g.
i) “All lions are fierce”
ii) “Some lions do not drink coffee”
Do i) and ii) imply that “some fierce creatures do not drink coffee” ?

P(x): “x is a lion”
Q(x): “x is fierce”
R(x): “x drinks coffee”
Universe of discourse is the set of all creatures.

i) x (P(x) → Q(x))
ii) x (P(x)  ¬R(x))
i)  ii) ? x (Q(x)  ¬R(x))

(ii) implies that there is some x1 such that P(x1)  ¬R(x1) by Existential Instantiation.
Hence by (i), Q(x1) is true (using Simplification and Modus Ponens rules).
¬R(x1) is also true by using again Simplification rule.
Then Q(x1)  ¬R(x1) which implies that x (Q(x)  ¬R(x)) by Existential Generalization.
1.8 Methods of Proof

Theorem: A statement that can be shown to be true.

Proof: Arguments which show that a theorem is true.

Axioms: Underlying assumptions about a mathematical structure.


(Many theorems are later shown to be false by showing cases that the assumption
does not hold !! BE VERY CAREFUL WITH THE ASSUMPTIONS)

Definitions: Rules of the game!

To prove a theorem, you usually start from premises (hypothesis), and using known
theorems, axioms and definitions, you construct a sequence of steps that leads to the
conclusion (forward reasoning).
Direct proof: (forward reasoning)
Example:
nZ, if n is odd, then n2 is odd.
Many theorems are implications: n (P(n) → Q(n))

To prove this, we need to show that P(n) → Q(n) is T for all n.

While doing so, we need to consider only the cases where P(n) is T
since otherwise, the implication will already be T due to the definition
of implication.

(So we don’t care about the cases where P(n) is F.)

e.g. P(n) Q(n)


Prove that, nZ, if n is odd, then n2 is odd.

Let n be an arbitrary integer. This is another way of writing n


n is odd  kZ such that n = 2k + 1
 n2 = 4k2 + 4k + 1 = 2(2k2 + 2k) +1
Here  is used to tie the steps of a proof (actually
 n2 is odd. serves like implication).
Indirect proof: (backward reasoning)

Recall:
n (P(n) → Q(n))  n (¬Q(n) → ¬P(n)) p → q  ¬q → ¬p (contrapositive)

Hence, instead of showing P(n) → Q(n) is T for all n,


we show ¬Q(n) → ¬P(n) is T for all n.

e.g.
Prove that, nZ, if 3n + 2 is odd, then n is odd.

Let n be an even integer.


Then k Z s.t. n = 2k
 3n + 2 = 6k + 2 = 2(3k + 1)

 3n + 2 is even too.
Formally, this needs to be written as
e.g. (iff) n (P(n) ↔ Q(n)); so parantheses are
taken granted.
Prove that, nZ, n is odd if and only if n2 is odd.
P(n): n is odd, Q(n): n2 is odd  Prove n P(n) ↔ Q(n)

We have to show two things:

i) n P(n) → Q(n) : we’ve already showed it.


ii) n Q(n) → P(n) : use indirect proof s.t. ¬ P(n) → ¬ Q(n)

Let n be even (not odd).


Then k Z s.t. n = 2k  n2 = 4k2 = 2(2k2) which is even.
Proof by contradiction:

e.g. Prove that 2 is irrational.


Suppose that 2 is not irrational (hence that the negation of the original statement is T).

That is, suppose 2 = a/b, where a and b have no common factors.


 2 = a2/ b2  2b2 = a2
 a2 is even  a is even  cZ s.t. a = 2c
 2b2 = 4c2  b2 = 2c2

 b2 is even  b is even
 2 | a  2 | b  a and b have common factors
 contradiction!
 2 is irrational.

General strategy: Suppose we want to prove p is true. We start assuming p is false


and then proceed. If we end up with a contradiction, then we conclude that the
assumption “p is false” is false, i.e., p is true.

WHAT ABOUT 3
http://www.grc.nasa.gov/WWW/k-12/Numbers/Math/Mathematical_Thinking/irrationality_of_3.htm
Proof by cases:

e.g.

Prove that, nZ, if n is not divisible by 3, then n2  1 (mod 3).

nZ (P(n) → Q(n))

We can prove this specific theorem by using “proof by cases”.


Prove that, nZ, if n is not divisible by 3, then n2  1 (mod 3).

Q(n): n2  1 (mod 3) n (P(n) → Q(n)) ?


P(n): n is not divisible by 3

There are only two cases to consider:


Case 1: P1(n): n  1 (mod 3)
Case 2: P2(n) : n  2 (mod 3)
 P(n)  P1(n)  P2(n)
n
If P1(n) is T,
k Z s.t. n = 3k + 1  n2 = 9k2 + 6k + 1 = 3 (3k2 + 2k) + 1
 n2  1 (mod 3)
If P2(n) is T,
k Z s.t. n = 3k + 2  n2 = 9k2 + 12k + 4 = 3(3k2 + 4k + 1) + 1
 n2  1 (mod3)

 n (P1(n) → Q(n))  (P2(n) → Q(n)) is T


 n (P(n) → Q(n))
Proof by cases (in general):

To prove p → q, where p  (p1  p2  … pn),

we can use the following logical equivalence:

[ (p1 p2 …  pn) → q ]  [(p1→q)  (p2→q)  …  (pn→q)]


Theorems and Quantifiers:

Constructive Existence proof:

Prove x P(x): Find an a s.t. P(a) is true

Non-constructive existence proof:

x P(x) ? Prove or disprove the existence of an a s.t. P(a) is true, without explicitly
finding it.

e.g., Show that there exists irrational numbers x and y such that xy is rational.
Consider x = 2 and y = 2 . Both are irrational.

xy = 2 2
Case 1: 2 2 is rational. DONE.
Case 2: 2 2 is irrational. Then let x = 2 2 and y = 2 . Thus xy = ( 2 2 ) 2 = 2
which is rational. DONE.

Non-constructive becase we didn’t find an example x and y exactly (we do not know which
case is true, but one of them must be).
Theorems and Quantifiers:

Counter-example:
x P(x)?

Find a for which P(a) is false; which Hence you can use counter-examples to
disprove a given universal quantification.
means (x P(x)) isfalse.
e.g.
Show that ‘all primes are odd’ is false.
x = 2 even and prime
 it is false.

Uniqueness proof:
x (P(x)  y (y≠x → ¬P(y)) )

e.g., “If a and b are real numbers and a≠0, then there exists a unique real number r such that
ar+b=0”

Part 1 – Existence: Let r=-b/a. Then ar+b = a(-b/a)+b = -b+b = 0. DONE.

Part 2 – Uniqueness: Ley y be such that ay+b=0 but y≠r. We know ar+b = 0 = ay+b. Subtracting b
from both sides we get ar=ay. We know a≠0 hence dividing both sides by a we get r=y,
contradicting our assumption that y≠r. Therefore no such y can exist.
2.1 Sets
Set: A fundamental discrete structure upon which all other discrete structures are built.
Sets group objects together.

Definition: Set.
The objects (elements, members) are in a set. A set is said to contain its elements.

e.g. E = {2, 4, 6, 8}
E = {x | x is a positive even integer less than 10}
E = {x | x > 0, x < 10, x=2k, k  Z}

Definition: Two sets are equal if and only if they have the same elements.

Definition: Null set, empty set, :


The set that has no element
Definition: Subset.
A is a subset of B if and only if every element of A is also an element of B.
A B
 x (xA → xB)

 The null set is a subset of every set


S
also S  S

PROOF ?? (see Theorem 1 in Chapter 2.1)

Definition: A is a proper subset of B if A is a subset of B but A ≠ B.


AB
x (xA → xB)  x (xB  xA)

General Notation: Q: Rational numbers, R: Real numbers, Z: Integers,


N: Natural numbers (non-negative integers) NZ
Definition: Power Set.
Given a set S, the power set of S is the set of all subsets of the set S.
Denoted as P(S) (or sometimes as 2S since it has 2|S| elements all of which are sets)
e.g.
A = {a, b}
P(A) = {x | x is a subset of {a, b}} = {, {a}, {b}, {a, b}}

Definition:
Let S be a set.
If there are exactly n distinct elements in S where n is a nonnegative integer, we say S is a finite set
and n is the cardinality of S.
 |S| = n
e.g.
Let S be the set of students in this class.
|S| = ?
e.g.
|| = ?
Definition:
A set is said to be infinite if it is not finite.

Definition: Cartesian Product.


Let A, B be two sets.
The Cartesian product of A and B, denoted A × B, is the set of all ordered pairs (a, b) where a  A
and b  B.
 A × B = {(a, b) | a  A  b  B}

e.g.
Let A={1, 2}, B={a, b}
A × B = {(1, a), (1, b), (2, a), (2, b)}

Note: A×B≠B×A
unless A=  B= so that A × B is equal to B × A = 
or unless A = B
Remember example:
Let A={1, 2}, B={a, b}
A × B = {(1, a), (1, b), (2, a), (2, b)}

Equality of tuples:
(a,b) = (c,d) ↔ a = c  b = d

Definition:
The Cartesian product of the sets A1, A2, …, An
denoted by A1 × A2 × … × An, is the set of ordered n-tuples (a1, a2, … , an), where ai belongs to Ai
for i = 1,2,… , n.

A1 × A2 × … × An = {(a1, a2, … , an) | aiAi for i = 1,2,… , n }

Equality of n-tuples:
(a1, a2, … , an) = (b1, b2, … , bn) ↔ i, 1 ≤ i ≤ n, ai = bi
2.2 Set Operations
Definition: Union
Let A and B sets.
A  B is the set that contains those elements that are either in A or in B, or in both.

A  B = {x | xA  xB}

Definition: Intersection
Let A and B be sets.
A  B is the set containing those elements that are both in A and B.

A  B = {x | x  A  x  B}

Definition: Disjoint sets


Let A, B be sets.
A and B are called disjoint iff A  B = .
Cardinality of the union of sets.
|A  B| = |A| + |B| – |A  B|

VENN DIAGRAMS (an easy way to reason about sets)

A
B

Definition: Difference set


The difference of A and B, A – B, is the set containing elements that are in A but not in B.
A – B = {x | x  A  x  B}

Definition: Complement
Let U be the universal set (domain from which x is coming).
The complement of the set A, denoted by Ā, is the complement of A with respect to U.
Ā = U – A = {x | x  A}
Set Identities:
A=A
AU=A identity laws

AU=U
A= domination

AA=A
AA=A idempotent

( A) = A complementation

AB=BA
AB=BA commutative
A  (B  C) = (A  B)  C
A  (B  C) = (A  B)  C associative

A  (B  C) = (A  B)  (A  C)
A  (B  C) = (A  B)  (A  C) distributive property

(AB) = A  B
(AB) = A  B De Morgan’s rule

e.g. AB = { x | x  AB }


= { x | ¬(x  AB)}
= { x | ¬(x  A  x  B)}
= { x | x  A  x  B}
={x|xAxB}
= { x | x  AB}
=AB
Definition:
The union of a collection of sets is the set that contains those elements that are members of at
least one set in the collection.

n
A1  A2  …  An =  Ai
i 1

Definition:
The intersection of a collection of sets is the set that contains those elements that are members
of all sets in the collection.
n
A1  A2  …  An =  Ai
i 1
2.3 Functions :

Definition: Function
Let A and B be sets.
A function from A to B is an assignment of each element of A to exactly one element of B.
ƒ: A → B; ƒ(a) = b

Definition:
Let ƒ be a function from A to B.
A: domain
B: codomain

Let ƒ(a) = b
b is image of a
a is a pre-image of b
ƒ
a b
A B

Range: All images of elements of A.


{y | xA y = f(x)}

Definition:
A function ƒ is said to be one-to-one (or injective) iff x, yA (ƒ(x)=ƒ(y) → x=y).

e.g.
ƒ(x) = x2 ƒ(x) = x3 ƒ(x) = x + 2
not 1-to-1 1-to-1 1-to-1
Definition:
ƒ : A→ B A  R, B  R R: set of real numbers

x, y  A,
ƒ is strictly increasing iff ƒ(x) < ƒ(y) for x < y
ƒ is strictly decreasing iff ƒ(x) > ƒ(y) for x < y

Definition:

ƒ : A→ B is onto (or surjective) iff


bB aA s.t. ƒ(a) = b
 range and codomain are equal
Definition:
ƒ is a one-to-one correspondence (bijection) iff it is both 1-to-1 and onto.

1-to-1 not 1-to-1


onto not onto onto not a function
a 1 1 1 a 1
b 2 2 2 b 2
c 3 3 c 3

Definition:
Let ƒ : A → B is a 1-to-1 correspondence.
-1
Inverse function ƒ : B → A such that
ƒ-1 (b) = a where ƒ(a) = b.
ƒ is invertible if and only if it is 1-to-1 and onto.

e.g.
ƒ : R→ R
ƒ(x) = x + 1 Is ƒ(x) invertible?
y = x +1
x=y–1
ƒ-1(y) = x – 1

 ƒ(x) is invertible.
Definition: Composition of functions.
Let g be a function from the set A to the set B and let ƒ be a function from the set B to the set C.
 composition ƒ○g is defined by
(ƒ○g)(a) = ƒ(g(a))

Identity function: ƒ-1 ○ ƒ or ƒ ○ ƒ-1


 (ƒ-1)-1 = ƒ

e.g. f(x) = x+1 g(x) = x2


(ƒ○g)(5) = ??
26
(g○f)(5) = ??
36
Functions to know:
x floor function: the largest integer that is less than or equal to x
x ceiling function: the smallest integer that is greater than or equal to x
1/2 = 0, 1/2 = 1, 9.1 = 10, –9.1 = –9, 6 = 6

x x

Properties:
x–1 < x  x  x < x + 1
–x = – x
–x = – x
x + m = x + m where m is integer
x + m = x + m where m is integer
2.5 Carfinality :
Definition:
The sets A and B have the same cardinality if and only if there is 1-to-1 correspondence from
A to B.

Definition:
Countable set: either has finite cardinality or has the same cardinality as the set of natural
numbers.
e.g. The set of real numbers is not countable (uncountable).
e.g. The set of rational numbers is countable.
2.6 Matrices:

A very quick review:

• A matrix is a rectangular array of numbers.


• An mn (“m by n”) matrix has exactly m horizontal rows, and n vertical columns.
• An nn matrix is called a square matrix whose order is n.

 a1,1 a1, 2  a1,n 


2 3  a
5  1  a2 , 2  a2,n 
A  [ai , j ] 
2 ,1
  a 32      
7 0  matrix  
am,1 am, 2  am , n 

• Two matrices A and B are equal iff they have the same number of rows, the same number
of columns, and all corresponding elements are equal.

 3 2  3 2 0
  1 6     1 6 0
   
• A+B = [ai,j+bi,j]

2 6   9 3  11 9
0  8   11 3   11  5
     

• For an mk matrix A and a kn matrix B, the product AB is an mn matrix. Note that the
dimensions must match!
• Note: Matrix multiplication is not commutative! AB is not necessarily equal to BA (even
if both are defined)

k 
AB  C  [ci , j ]   ai ,b, j 
  1 

0  1 1 0
0 1  1   1 0  5  1
2 0 3   2 0  2 0  3  2 11 3 
  1 0   
 3 1 
More things to know about matrix multiplication:
- It is costly: O(n3) In many computer vision problems we use 1000x1000 images!
- AB are BA both defined only when A and B are of size nm and mn for some n,m.
- It is associative: ABC = (AB)C = A(BC)
- Order matters in terms of number of steps: If A:nm, B:mk, C:kt then (AB)C requires
nmk + nkt steps whereas A(BC) requires mkt + nmt steps!

Identity matrix (of size nn)


1 0  0
1 if i  j  0 1  0
I n   
0 if i  j      
 
0 0  1
• For some (but not all) square matrices A, there exists a unique multiplicative inverse A-1
of A, a matrix such that A-1A = In.
• If the inverse exists, it is unique, and A-1A = AA-1 = In
• Powers of a square matrix: Ap  AAA···A p times (A0  In)
• If A=[aij] is an mn matrix, the transpose of A (often written At or AT) is the nm matrix
given by At = B = [bij] = [aji] (1in,1jm)

2 0 
t
2 1 3  

0  1  2  1  1 
   3  2
 
• A square matrix A is symmetric iff A=At. i.e., i,jn: aij = aji .

You might also like