Lecture 1
Lecture 1
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Writing our First Proof
Theorem: If n is an even integer,
then n2 is even.
s
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
10 2·5
8 2·4
0 2·0
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Let’s Draw Some Pictures!
k k
n = 2k n2 = 2(2k2)
n = 2k
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Our First Proof!
Theorem: If n is an even integer, then n2 is even.
Proof: Assume n is an even integer. We want to
show that n² is even.
Since n is even, there is some integer k such
that n = 2k. This means that
n2 = (2k)2
= 4k2
= 2(2k2).
From this, we see that there is an integer m
(namely, 2k2) where n2 = 2m. Therefore, n2
is even, which is what we wanted to show. ■
Our First Proof!
Theorem: If n is an even integer, then n2 is even.
Proof: Assume n is an even integer. We want to
show that n² is even.
Since n is even, there is some integer k such
that n = 2k. This means that
This symbol
n = (2k)
2 2
means “end of
= 4k2
proof”
= 2(2k2).
From this, we see that there is an integer m
(namely, 2k2) where n2 = 2m. Therefore, n2
is even, which is what we wanted to show. ■
Our First Proof!
Theorem: If n is an even integer, then n2 is even.
Proof: Assume n is an even integer. We want to
show that n² is even.
Since n is even, there is some integer k such
that n = 2k. This means that
n2 =To prove
(2k)2 a statement of the
= 4k2 form
= 2(2k2).
“If P is true, then Q is true,”
From this, we see that there is an integer m
(namely, 2k2) wherestart
n2 =by2m. Therefore,
asking the reader n2 to
is even, which is what assume
we wanted
that Ptois show.
true. ■
Our First Proof!
Theorem: If n is an even integer, then n2 is even.
Proof: Assume n is an even integer. We want to
show that n² is even.
Since n is even, there is some integer k such
that n = 2k. This means that
To 2 prove a 2 statement of the form
n = (2k)
= 4k2
“If P is true, then Q is true,”
= 2(2k ).2
we see
From this, we assume
thatP there
is true,
is then need tomshow
an integer
(namely, 2k2)that
whereQ isntrue.
2
= 2m. Therefore,
Here, n2 the
we’re telling
is even, which is what
readerwe wanted
where we’re to show. ■
headed.
Our First Proof!
Theorem: If n is an even integer, then n2 is even.
Proof: Assume n is an even integer. We want to
show that n² is even.
Since n is even, there is some integer k such
that n = 2k. This means that
n2 = (2k)2
This is the definition of an even
= 4k 2
integer. We need
= 2(2k2). to use this definition
to make this proof rigorous.
From this, we see that there is an integer m
(namely, 2k2) where n2 = 2m. Therefore, n2
is even, which is what we wanted to show. ■
Our First Proof!
Theorem: If n Notice
is an even integer,
how we use thethen
valuen2ofiskeven.
that
we obtained above. Giving names to
Proof: Assume n is an even integer. We want to
show that n²quantities,
is even. allows us to manipulate them.
This is similar to variables in programs.
Since n is even, there is some integer k such
that n = 2k. This means that
n2 = (2k)2
= 4k2
= 2(2k2).
From this, we see that there is an integer m
(namely, 2k2) where n2 = 2m. Therefore, n2
is even, which is what we wanted to show. ■
Our First Proof!
Theorem: If n is an even integer, then n2 is even.
Proof: Assume n is an even integer. We want to
show that n² is even.
Our ultimate goal is to prove that n2 is
Since n is even, there is some integer k such
even. This means that we need to find
that n = 2k. This means that
some m where
n2 = 2m. nHere,
= (2k)
2 2
we're explicitly showing
= 4k 2
how we can do that.
= 2(2k2).
From this, we see that there is an integer m
(namely, 2k2) where n2 = 2m. Therefore, n2
is even, which is what we wanted to show. ■
Our First Proof!
Theorem: If n is an even integer, then n2 is even.
Proof: Assume n is an even integer. We want to
show that n² is even.
Since n is even, there is some integer k such
that n = 2k. This means that
Hey, that's what we
n = (2k)
2 2
said we were going to
= 4k2
do! We’re done.
= 2(2k2).
From this, we see that there is an integer m
(namely, 2k2) where n2 = 2m. Therefore, n2
is even, which is what we wanted to show. ■
Our Next Proof
Theorem: For any integers m and n,
if m and n are odd, then m + n is even.
s
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
11 2·5+1
7 2·3+1
1 2·0+1
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Let’s Do Some Math!
k 1 r
2k+1 2r+1
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Theorem: For any integers m and n, if m and n are odd, then
m + n is even.
Proof: Consider any arbitrary integers m and n where m and n are
odd. We need to show that m + n is even.
Since m is odd, we know that there is an integer k where
m = 2k + 1. (1)
Similarly, because n is odd there must be some integer r such that
n = 2r + 1. (2)
By adding equations (1) and (2) we learn that
m + n = 2k + 1 + 2r + 1
= 2k + 2r + 2
= 2(k + r + 1). (3)
Equation (3) tells us that there is an integer s (namely, k + r + 1)
such that m + n = 2s. Therefore, we see that m + n is even, as
required. ■
Theorem: For any integers m and n, if m and n are odd, then
m + n is even.
Proof: Consider any arbitrary integers m and n where m and n are
odd. We need to show that m + n is even.
Since m is odd, we We
know
askthat
thethere is an
reader tointeger k where
make an arbitrary
m =
choice. 2k + than
Rather 1. specifying (1)
what m and
Similarly, because n isare,
odd we’re
there signaling to the
must be some reader
integer thatthat
r such
they could,
n = 2rin+ principle,
1. supply(2)
any choices
of (2)
By adding equations (1) and m and n that
we learn thatthey’d like.
m By
+ nletting
= 2k +the
1 +reader
2r + 1 pick m and n
= 2k
arbitrarily, + 2r + we
anything 2 prove about m and
= 2(k + rto
n will generalize + 1).
all possible(3)
choices for
Equation (3) tells us that there is an integer
those s (namely, k + r + 1)
values.
such that m + n = 2s. Therefore, we see that m + n is even, as
required. ■
Theorem: For any integers m and n, if m and n are odd, then
m + n is even.
Proof: Consider any arbitrary integers m and n where m and n are
odd. We need to show that m + n is even.
Since m is odd,To
we know
provethat there is an integer
a statement of thek form
where
m = 2k + 1. (1)
Similarly, because n“If P is there
is odd true,must
thenbe
Qsome
is true,”
integer r such that
n = 2r + 1. (2)
start by asking the reader to assume
By adding equations (1) and (2) we learn that
that P is true.
m + n = 2k + 1 + 2r + 1
= 2k + 2r + 2
= 2(k + r + 1). (3)
Equation (3) tells us that there is an integer s (namely, k + r + 1)
such that m + n = 2s. Therefore, we see that m + n is even, as
required. ■
Theorem: For any integers m and n, if m and n are odd, then
m + n is even.
Proof: Consider any arbitrary integers m and n where m and n are
odd. We need to show that m + n is even.
Since m is odd, we know that there is an integer k where
To prove a statement of the form
m = 2k + 1. (1)
Similarly, because“If
n is
P odd therethen
is true, must Q
beis
some integer r such that
true,”
n = 2r + 1. (2)
after assuming
By adding equations P we
(1) and (2) is true, you need to
learn that
show
m+ n =that
2k + Q
1 +is2rtrue.
+1
= 2k + 2r + 2
= 2(k + r + 1). (3)
Equation (3) tells us that there is an integer s (namely, k + r + 1)
such that m + n = 2s. Therefore, we see that m + n is even, as
required. ■
Theorem: For any integers m and n, if m and n are odd, then
m + n is even.
Numbering these equalities lets us refer
Proof: Consider any arbitrary integers m and n where m and n are
back to them later on, making the flow of
odd. We need to show that m + n is even.
the proof a bit easier to understand.
Since m is odd, we know that there is an integer k where
m = 2k + 1. (1)
Similarly, because n is odd there must be some integer r such that
n = 2r + 1. (2)
By adding equations (1) and (2) we learn that
m + n = 2k + 1 + 2r + 1
= 2k + 2r + 2
= 2(k + r + 1). (3)
Equation (3) tells us that there is an integer s (namely, k + r + 1)
such that m + n = 2s. Therefore, we see that m + n is even, as
required. ■
Theorem: For any integers m and n, if m and n are odd, then
m + n is even.
Proof: Consider any arbitrary integers m and n where m and n are
odd. We need to show that m + n is even.
Since m is odd, we know that there is an integer k where
m = 2k + 1. (1)
Similarly, because n is odd there must be some integer r such that
This is a complete sentence! nProofs
= 2r + 1.
are (2)
By adding
expected toequations
be written(1)
in and (2) we learn that
complete
sentences, so you’llmoften
+ n =use
2k + 1 + 2r + 1
punctuation at the end of formulas.
= 2k + 2r + 2
We recommend using the “mugga mugga”
= 2(k + r + 1). (3)
test – if you(3)
Equation read a us
tells proof
thatand replace
there is an integer s (namely, k + r + 1)
all the
suchmathematical
that m + n notation with “mugga
= 2s. Therefore, we see that m + n is even, as
required.
mugga,” ■ comes back should be a
what
valid sentence.
Some Little Exercises
●
Here’s a list of other theorems that are true about odd
and even numbers:
●
Theorem: The sum and difference of any two even numbers is
even.
●
Theorem: The sum and difference of an odd number and an
even number is odd.
●
Theorem: The product of any integer and an even number is
even.
●
Theorem: The product of any two odd numbers is odd.
●
Going forward, we’ll just take these results for granted.
Feel free to use them in the problem sets.
●
If you’d like to practice the techniques from today, try
your hand at proving these results!
Universal and Existential Statements
Theorem: For any odd integer n,
there exist integers r and s where r2 – s2 = n.
s
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Universal vs. Existential Statements
●
A universally-quantified statement is a
statement of the form
For all x, [some-property] holds for x.
●
We've seen how to prove these statements.
●
An existentially-quantified statement is
a statement of the form
There is some x where [some-property] holds for x.
●
How do you prove an existentially-
quantified statement?
Proving an Existential Statement
●
Over the course of the quarter, we will
see several different ways to prove an
existentially-quantified statement of the
form
There is an x where [some-property] holds for x.
●
Simplest approach: Search far and
wide, find an x that has the right
property, then show why your choice is
correct.
s
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Let’s Try Some Examples!
1 = 2·0+1 = 1 2
– 0 2
3 = 2·1+1 = 2 2
– 1 2
5 = 2·2+1 = 3 2
– 2 2
7 = 2·3+1 = 4 2
– 3 2
9 = 2·4+1 = 5 2
– 4 2
k +1
k
(k+1)2 – k2 = 2k+1
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Theorem: For any odd integer n, there exist integers
r and s where r2 – s2 = n.
Proof: Let n be an arbitrary odd integer. We will show
that there exist integers r and s where r2 – s2 = n.
Since n is odd, we know there is an integer k where
n = 2k + 1. Now, let r = k+1 and s = k. Then we see
that
r2 – s2 = (k+1)2 – k2
= k2 + 2k + 1 – k2
= 2k + 1
= n.
This means that r2 – s2 = n, which is what we needed
to show. ■
Theorem: For any odd integer n, there exist integers
r and s where r2 – s2 = n.
Proof: Let n be an arbitrary odd integer. We will show
that there exist integers r and s where r2 – s2 = n.
Since n isWe
odd,
ask we
the know
readerthere is an
to make an integer
arbitraryk where
n = 2k + choice.
1. Now,Rather
let r than
= k+1 and s =
specifying k. Then
what n is, we see
that we’re signaling to the reader that they
r2 in
could, – sprinciple,
2
= (k+1)supply – k2 choice n that
2 any
they’d like.
= k + 2k + 1 – k2
2
= 2k + 1
= n.
This means that r2 – s2 = n, which is what we needed
to show. ■
Theorem: For any odd integer n, there exist integers
r and s where r2 – s2 = n.
Proof: Let n be an arbitrary odd integer. We will show
that there exist integers r and s where r2 – s2 = n.
Since n is odd, we know there is an integer k where
As always, it’s helpful to
n = 2k + 1. Now, let r = k+1write
andouts =what
k. Then we
we need
see
that
to demonstrate with the
r2 – s2 = (k+1)2 –rest
k2 of the proof.
= k2 + 2k + 1 – k2
= 2k + 1
= n.
This means that r2 – s2 = n, which is what we needed
to show. ■
Theorem: For any odd integer n, there exist integers
r and s where r2 – s2 = n.
Proof: Let n be an arbitrary odd integer. We will show
that there exist integers r and s where r2 – s2 = n.
Since n is odd, we know there is an integer k where
n = 2k + 1. Now, let r = k+1 and s = k. Then we see
that
We’re trying to prove
r –s
2 2
= (k+1) – k2
2
an existential
= k2 + 2k statement.
+ 1 – k2 The easiest
= 2k + 1 way to do that is to
just give concrete
= n.
choices of the objects
This means that r2 – s2 = n, which is what we needed
being sought out.
to show. ■
Check the appendix to this
slide deck for more about
who gets to choose values.
Time-Out for Announcements!
Working in Pairs
●
Starting with Problem Set One, you are
allowed to work either individually or in pairs.
●
Each pair should make a single joint submission.
●
We have advice about how to work effectively
in pairs up on the course website – check the
“Guide to Partners.”
●
Want to work in a pair, but don’t know who to
work with? Fill out this Google form and
we’ll connect you with a partner on Friday.
Problem Set 0
●
Problem Set 0 is due this Friday at
1:00PM.
●
(It needs to be completed individually.)
●
Need help getting Qt Creator installed?
There’s a Qt Creator help session
running tonight, 6PM – 8PM, in Durand
353.
CS103 ACE
●
Reminder: There’s an optional companion course,
CS103 ACE, that runs in parallel with CS103.
●
CS103 ACE meets Tuesdays 3:00 – 4:50PM and
provides additional practice with the course
material in a small group setting.
●
The first course meeting is next Tuesday.
●
Interested? Apply online using this link.
●
The CS103 ACE materials are available to
everyone. You can pull them up here.
Preview: Lecture Participation
●
5% of your course grade is allocated to lecture
participation, which starts next Wednesday.
●
We’ll use PollEV to ask questions in lecture to help
solidify understanding.
●
You’ll get participation credit for the day if you answer
those questions, regardless of whether your answers
are right.
●
You get three free missed lectures without penalty.
●
If you aren’t able to make it to lecture, or would prefer
to watch asynchronously, you can opt to count your final
exam score in place of your participation grade. (We’ll
send out a form in Week 4 you can use to opt out.)
Outdoor Activities
●
You’re less than fifty miles from grassy mountains,
redwood forests, Pacific coastline, beautiful wetlands,
and more.
●
Want to explore the area to see what it has to offer?
Check out our (unofficial) Outdoor Activities Guide.
https://cs103.stanford.edu/outdoor_activities
●
A sampler of what to check out:
●
Drive to the observatory in the mountains near San Jose and
take in the views.
●
Visit a beach with an enormous colony of elephant seals.
●
Walk in redwood forests and pick your own bay leaves.
●
Grab cheap, high-quality food from unassuming strip malls.
Back to CS103!
Theorem: If n is an integer,
then ⌈ⁿ/₂⌉ + ⌊ⁿ/₂⌋ = n.
s
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Floors and Ceilings
●
The notation ⌈x⌉ represents the ceiling of x,
the smallest integer greater than or equal to x.
●
What is ⌈1⌉? What’s ⌈1.2⌉? What’s ⌈-1.2⌉?
●
Intuition: Start at x on the number line, then move
to the right until you hit a tick mark.
●
The notation ⌊x⌋ represents is the floor of x,
the largest integer less than or equal to x.
●
What is ⌊1⌋? What’s ⌊1.2⌋? What’s ⌊-1.2⌋?
●
Intuition: Start at x on the number line, then move
to the left until you hit a tick mark.
s
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Let’s Draw Some Pictures!
⌈ⁿ/₂⌉
ⁿ/₂
k ⌊ⁿ/₂⌋
ⁿ/₂
k
n = 2k
k+1
⌈ⁿ/₂⌉ ⌊ⁿ/₂⌋
k
n = 2k + 1
In
What terms are What does this
on
used in this proof? theorem mean?
tu
iti
What do they Why, intuitively,
iti
formally mean? should it be true?
fin
on
De
s
Conventions
What is the standard
format for writing a proof?
What are the techniques
for doing so?
Theorem: If n is an integer, then ⌊ⁿ/₂⌋ + ⌈ⁿ/₂⌉ = n.
Proof: Let n be an integer. We will show that ⌊ⁿ/₂⌋ + ⌈ⁿ/₂⌉ = n. To do so,
we consider two cases:
Case 1: n is even. This means there is an integer k such that n = 2k.
Some algebra then tells us that
This is called a proof by cases (or
⌈⌉⌊⌋ ⌈ ⌉⌊ ⌋
n
2
+
n
2
2k
2
2k
=proof +by exhaustion). We split
2
apart into one or more cases and
=confirm
⌈k⌉ +⌊ k⌋that the result is indeed
= 2 k true in each of them.
= n.
Case 2: n is odd. Then there’s(Think of itk like
an integer an n
where if/else
= 2k + or1,switch
and
⌈⌉⌊⌋ ⌈ ⌉⌊ ⌋
statement.)
n n 2 k +1 2 k +1
+ = +
2 2 2 2
⌈ ⌉⌊ ⌋
= k+
1
2
+ k+
1
2
= (k + 1)+ k
= 2 k+1
= n.
In either case, we see that ⌊ⁿ/₂⌋ + ⌈ⁿ/₂⌉ = n, as required. ■
Theorem: If n is an integer, then ⌊ⁿ/₂⌋ + ⌈ⁿ/₂⌉ = n.
Proof: Let n be an integer. We will show that ⌊ⁿ/₂⌋ + ⌈ⁿ/₂⌉ = n. To do so,
we consider two cases:
Case 1: n is even. This means there is an integer k such that n = 2k.
Some algebra then tells us that
⌈⌉⌊⌋ ⌈ ⌉⌊ ⌋
n
2
+
n
2
=
2k
2
+
2k
2
= ⌈k⌉ +⌊ k⌋
= 2k
= n.
Case 2: n is odd. Then there’s an integer k where n = 2k + 1, and
⌈⌉⌊⌋ ⌈ ⌉⌊ ⌋
n
2
+
n
2
=
2 k +1
2
+
2 k +1
2
⌈ ⌉⌊ ⌋
At the end of a split into cases, it’s
1 1
= k + + k +
a nice 2courtesy
2 to explain to the
reader what it was that you
= (k + 1)+ k
established in each case.
= 2 k+1
= n.
In either case, we see that ⌊ⁿ/₂⌋ + ⌈ⁿ/₂⌉ = n, as required. ■
Theorem: If n is an integer, then ⌊ⁿ/₂⌋ + ⌈ⁿ/₂⌉ = n.
Proof: Let n be an integer. We will show that ⌊ⁿ/₂⌋ + ⌈ⁿ/₂⌉ = n. To do so,
we consider two cases:
Case 1: n is even. This means there is an integer k such that n = 2k.
Some algebra then tells us that
⌈⌉⌊⌋ ⌈ ⌉⌊ ⌋
n
2
+
n
2
=
2k
2
+
2k
2
= ⌈k⌉ +⌊ k⌋
= 2k
= n.
Case 2: n is odd. Then there’s an integer k where n = 2k + 1, and
⌈⌉⌊⌋ ⌈ ⌉⌊ ⌋
n
2
+
n
2
=
2 k +1
2
+
2 k +1
2
⌈ ⌉⌊ ⌋
= k+
1
2
+ k+
1
2
= (k + 1)+ k
= 2 k+1
= n.
In either case, we see that ⌊ⁿ/₂⌋ + ⌈ⁿ/₂⌉ = n, as required. ■
To Recap
s
In
on
tu
iti
iti
fin
on
De
s
Conventions
ry S o m e E xa m p le s !
Let’s T
n = 137
Reader Picks
k = 68
Neither Picks
z = 34
Writer Picks
Proof Writer (You) Proof Reader
Proofs as
Each of these a Dialog
variables has a
distinct, assigned value.
Each
Let n bevariable was either
an arbitrary picked by
odd integer.
the reader, picked by the writer, or
Since nhas
is an odd integer,
a value that canthere is an integer
be determined
k such
fromthat n =variables.
other 2k + 1.
Now, let z = k – 34.
n = 137
Reader Picks
k = 68
Neither Picks
z = 34
Writer Picks
Proof Writer (You) Proof Reader
Who Owns What?
●
The reader chooses and owns a value if you use wording
like this:
●
Pick a natural number n.
●
Consider some n ∈ ℕ.
●
Fix a natural number n.
●
Let n be a natural number.
●
The writer (you) chooses and owns a value if you use
wording like this:
●
Let r = n + 1.
●
Pick s = n.
●
Neither of you chooses a value if you use wording like this:
●
Since n is even, we know there is some k ∈ ℤ where n = 2k.
●
Because n is odd, there must be some integer k where n = 2k + 1.
Proofs as a Dialog
x = 242
Reader Picks
x = 242
Reader Picks
What does
”for any even 242”
mean?
Proof Writer (You) Proof Reader
Proofs as a Dialog
x = 242
Reader Picks
x = 242
Reader Picks
Let x be an integer.
Consider an arbitrary x ∈ ℤ.
Pick any x.
m = 103
Reader Picks
n = 166
Reader Picks
m = 103
Reader Picks
Let n = 1.
⚠ ⚠
Pick any integer m where m+1 is odd.
Let n = 1.
⚠ ⚠
Pick any integer m where m+1 is odd.
m = 166
Reader Picks
n=1
Writer Picks
m = 166
Reader Picks
n=1
Writer Picks
m = 166
Reader Picks