Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
more asymptotics Course Notes chapter 5 & 6 Danny Heap heap@cs.toronto.edu
http:/www.cdf.toronto.edu/ f heap/165/F10/
CSC 165
slide 1
bounding a sort
def IS(A) : " IS(A) sorts the elements of A in nondecreasing order " 1. i = 1 2. while i < len(A) : 3. t
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
counting costs
want a coarse comparison of algorithms \speed" that ignores hardware, programmer virtuosity
which speed do we care about: best, worst, average? why?
dene idealized \step" that doesn't depend on particular hardware and idealized \time" that
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
Prove:
f P y g
()
A g P
( )
f
slide 2
Prove or disprove:
f P y g
()
A f f P y g g
(
).
slide 4
scratch
slide 7
scratch
slide 7
Prove or disprove:
f P y g
()
A f P y g g
(
)
slide 8
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
rove Pn TP 2F @using l9rpitl9s rule nd limitsA o
n
slide IW
bounded below
xotie tht the denition of igEymeg diers in just one hrter from igEyhX @ A a f X N U3 R0 j W P R+ W P N V P N ! A @ A ! @ Ag
g f c ; B ; n ;n B f n cg n
he rle of isD s with igEyhD t
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
Prove 2n TP n2.
slide 16
scratch
slide 17
the short cut
Do you know anything about the ratio 2n=n2, as n gets very large? How do you evaluate: 2n lim n!1 2
n
If the limit evaluates to I, then that's the same as saying:
n +; Wn0 P N; Vn P N; n ! n0 A 2 Vc
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
Special case?
Was the rst bigOh exercise a special case? What happens to the argument if you add a constant:
Prove 3n2 + 2n + 5 P y(n2)
See what needs to be modied in the proof to accommodate the constant 5.
slide 9
in general, O(g ):
y(
g
) = ff : N U3
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
recall the halting problem
We showed that H is uncomputable by reducing navel_gaze to H.
def H(f, i): 'Return True if f(i) will halt, False otherwise.' # Once you've figured out how to implement this, delete next line return True def navel_gaze(f) : if H(
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
CSC 165
uncomputable problems Danny Heap heap@cs.toronto.edu
http:/www.cdf.toronto.edu/ f heap/165/F10/
slide 1
an algorithm for everything?
Many of us become interested in computers because we want to solve problems in a systematic, repeatable way. We wr
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
scratch
slide 7
less tidy
What about a messier problem. Suppose you have an inexhaustible supply of 4 and 7cent stamps. You can make 4cent postage or 7cent postage exactly. In general, what postage amounts can you make exactly? Make a conjecture, and p
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
induction Course Notes pp. 56cfw_58 Danny Heap heap@cs.toronto.edu
http:/www.cdf.toronto.edu/ f heap/165/F10/
CSC 165
slide 1
implication, over and over
Earlier we saw that implication is transitive. If P (n) is a predicate of the natural numbers, and we
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
getting wrong right
Be careful proving a claim false. Consider the claim, for some suitably dened X; Y and P; Q:
S
:
Vx P X; Vy P Y; P (x; y) A Q(x; y)
To disprove S , should you prove:
Vx P X; Vy P Y; P (x; y) A XQ(x; y)
What about
Vx P X; Vy P Y; X (P (
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
using uniqueness
Suppose you have a predicate of the natural numbers: Is S (3 3) true? How do you prove that? It's useful to check out the remainder theorem from the sheet of mathematical prerequisites.
Vn P N
S (n)
D Wk P N; n = 7k + 3
slide 4
getting wr
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
CSC 165
epsilon/delta Danny Heap heap@cs.toronto.edu
http:/www.cdf.toronto.edu/ f heap/165/F10/
slide 1
a continuous example
The claim below says that the function x2 is continuous at . In proving the claim you can't control the value of " or x, but you c
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
using more of the denition
You may have been disappointed that the last proof used only part of the denition of oor. Here's a symbolic rewriting of the denition of oor:
V PR
x
y
= x D y P Z y
x
(V P Z
z
;z
x
A
z
y
)
The full version of the denition shou
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
innitely many primes
Dene the prime natural numbers as P = fp P N j p has exactly two distinct divisors in Ng. How do you prove: S : Vn P N; jP j > n It would be nice to have some result R that leads to S . If you could show R A S , and that R is true, th
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
proving existence
To prove the a set is nonempty, it's enough to exhibit one element. How do you prove:
W PR
x
;x
3
+ 3x2 4x = 12
slide 2
prove a claim about a sequence
Dene sequence an by: Now prove:
V PN
n
an
= n2
i
W PN V PN
i ; j
; aj
A
j < i
slide 3
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
a real inequality
Prove that for every pair of nonnegative real numbers (x; y ), if x is greather than y , then the p geometric mean, xy is less than the arithmetic mean, (x + y )=2.
slide 10
some directions work better
Prove that for any natural number
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
proof Danny Heap heap@cs.toronto.edu
http:/www.cdf.toronto.edu/ f heap/165/F10/
CSC 165
slide 1
a proof foretold
A proof communicates why and how you believe something to be true. You'll need to master two things:
1. Why do you believe the thing is true?
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
def inner_forall(L, P, y) : for x in L : if not P(x,y) : return False # there's a counterexample else : pass return True # no counterexamples def outer_forall(L1, P, L2, Q) : for x in L1 : if not Q(L2, P, x) : return False # there's a counterexample else
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
mixed quantiers Danny Heap heap@cs.toronto.edu
http:/www.cdf.toronto.edu/ f heap/165/F10/
CSC 165
slide 1
recall: tabulating truth
The standard venn diagram for 3 sets has 23 regions  one region for each possible combination of truth values for its compo
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
products of sums
Work with 1 or 2 other students, and choose one of your group as the recorder. The recorder should keep a written record of his/her group's discussion of the problem below, which they may use as the basis for a contribution to the problem
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
scope
In order to parse a logical expression we need to know which subexpressions to parse rst. Although there's often conventions (just as in your favourite programming language), such as evaluating before A, when in doubt you should use parentheses:
P x
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
conjunction
Combine two statements by claiming they are both true with logical \and": A(x) and B (x) (python keyword and works like this) A(x) B (x) ( is a symbol for \and") As sets: x P A B Notice that a conjunction is false if either part is false. \The
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
vacuous truth
We've already separated implication from quantication, so we can make sense of
P x
( ) A Q(x)
It's true, except when P (x) is true and Q(x) is false. In particular, an implication is always true when the antecedent is false. For example, if
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
rigor without mortis
You need both rigor and intuition to solve problems you haven't seen a template for. In this course I'll present openended problems, and recommend the following steps for getting started on them:
Understand the problem:
Know what's g
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
contrapositive and negation
Another symbol, X, toggles the truth value of a statement. When we toggle and reverse an implication, we get its contrapositive. Compare the meanings of:
V P ( )A ( ) V P X ( )AX (
x E; F x L x x E; L x
F x
)
What information d
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
quantiers Danny Heap heap@cs.toronto.edu
http:/www.cdf.toronto.edu/ f heap/165/F10/
CSC 165
slide 1
quantiers as sets
Think of quantication as set operations. Suppose E is the set of employees, M is the set of male employees, F is the set of female employ
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
set properties
Quantiers connect properties of elements to properties of sets. The statement \Every employee earns less than 70,000" isn't a statement about a single, or even several, employees. It's about the entire set.
Employee Gender Salary
Al Betty C
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
ambiguity
When you use a natural language (English, Chinese) you can make it as precise or ambiguous as you need. For some purposes (jokes, gossip) rich ambiguity is essential. For other purposes (getting instructions on heart surgery) precision is essent
Mathematical Expression and Reasoning for Computer Science
COMPUTER S CSC 165

Fall 2010
CSC 165
introduction Danny Heap heap@cs.toronto.edu
http:/www.cdf.toronto.edu/ f heap/165/F10/
slide 1
what's CSC165?
This is a course about expression (communication):
with and through programs
with developers
knowing what you mean
understanding what