Math Review
Math Review
Math review
This book assumes that you understood precalculus when you took it. So you
used to know how to do things like factoring polynomials, solving high school
geometry problems, using trigonometric identities. However, you probably
can’t remember it all cold. Many useful facts can be looked up (e.g. on the
internet) as you need them. This chapter reviews concepts and notation that
will be used a lot in this book, as well as a few concepts that may be new
but are fairly easy.
1
CHAPTER 1. MATH REVIEW 2
• open interval: (a, b) is the set of real numbers from a to b, not including
a and b
CHAPTER 1. MATH REVIEW 3
• half-open intervals: [a, b) and (a, b] include only one of the two end-
points.
• a point in 2D space
• a complex number
Oddly enough, you can also multiply two intervals of the real line. This
carves out a rectangular region of the 2D plane, with sides determined by
the two intervals.
bx by = bx+y
ax bx = (ab)x
(bx )y = bxy
y
b(x ) 6= (bx )y
Suppose that b > 1. Then we can invert the function y = bx , to get the
function x = logb y (“logarithm of y to the base b”). Logarithms appear
in computer science as the running times of particularly fast algorithms.
They are also used to manipulate numbers that have very wide ranges, e.g.
probabilities. Notice that the log function takes only positive numbers as
inputs. In this class, log x with no explicit base always means log2 x because
analysis of computer algorithms makes such heavy use of base-2 numbers and
powers of 2.
CHAPTER 1. MATH REVIEW 5
blogb (x) = x
logb (xy) = logb x + logb y
logb (xy ) = y logb x
logb x = loga x logb a
In the change of base formula, it’s easy to forget whether the last term
should be logb a or loga b. To figure this out on the fly, first decide which of
logb x and loga x is larger. You then know whether the last term should be
larger or smaller than one. One of logb a and loga b is larger than one and
the other is smaller: figure out which is which.
More importantly, notice that the multiplier to change bases is a con-
stant, i.e doesn’t depend on x. So it just shifts the curve up and down
without really changing its shape. That’s an extremely important fact that
you should remember, even if you can’t reconstruct the precise formula. In
many computer science analyses, we don’t care about constant multipliers.
So the fact that base changes simply multiply by a constant means that we
frequently don’t have to care what the base actually is. Thus, authors often
write log x and don’t specify the base.
k! = 1 · 2 · 3 · . . . · (k − 1) · k
n! n
from S. The quantity k!(n−k)!
is frequently abbreviated as k
, pronounced
“n choose k.”
The max function returns the largest of its inputs. For example, suppose
we define f (x) = max(x2 , 7). Then f (3) = 9 but f (2) = 7. The min function
is similar.
The floor and ceiling functions are heavily used in computer science,
though not in many areas other of science and engineering. Both functions
take a real number x as input and return an integer near x. The floor func-
tion returns the largest integer no bigger than x. In other words, it converts
x to an integer, rounding down. This is written ⌊x⌋. If the input to floor
is already an integer, it is returned unchanged. Notice that floor rounds
downward even for negative numbers. So:
⌊3.75⌋ = 3
⌊3⌋ = 3
⌊−3.75⌋ = −4
The ceiling function, written ⌈x⌉, is similar, but rounds upwards. For
example:
⌈3.75⌉ = 4
⌈3⌉ = 3
⌈−3.75⌉ = −3
Most programming languages have these two functions, plus a function
that rounds to the nearest integer and one that “truncates” i.e. rounds
towards zero. Round is often used in statistical programs. Truncate isn’t
used much in theoretical analyses.
1.5 Summations
If ai is some formula that depends on i, then
CHAPTER 1. MATH REVIEW 7
n
X
ai = a1 + a2 + a3 + . . . + an
i=1
For example
n
X 1 1 1 1 1
i
= + + ...+ n
i=1
2 2 4 8 2
n
Y 1 1 1 1 1
= · · · ...·
k=1
k 1 2 3 n
Certain sums can be re-expressed “in closed form” i.e. without the sum-
mation notation. For example:
n
X 1 1
i
=1− n
i=1
2 2
n
X r n+1 − 1
k
r =
k=0
r−1
n
X
For example, 2k = 2n+1 − 1. In Calculus, you may have seen infinite
k=0
versions of geometric series formulas. In this class, we’re always dealing with
finite sums, not infinite ones.
If you modify the start value, the closed form must be adapted to add/subtract
n
X 1
the values of the extra/missing terms. For example, starts with the
i=0
2i
CHAPTER 1. MATH REVIEW 8
n
X 1 1
i = 0 term. So i
= 2 − n . Always be careful to check where your
i=0
2 2
summation starts.
Many reference books have tables of useful formulas for summations that
have simple closed forms. We’ll see them again when we cover mathematical
induction and see how to formally prove that they are correct.
Only a very small number of closed forms need to be memorized. Aside
from the geometric series formula, you should also know this closed form:
n
X n(n + 1)
i=
i=1
2
Here’s one way to convince yourself it’s right. On graph paper, draw a
box n units high and n+1 units wide. Its area is n(n+1). Fill in the leftmost
part of each row to represent one term of the summation: the left box in the
first row, the left two boxes in the second row, and so on. This makes a little
triangular pattern which fills exactly half the box.
1.6 Strings
You’ve probably seen strings in introductory programming, e.g. when pro-
cessing input from the user or a disk file. In computer science, a string is a
finite-length sequence of characters and its length is the number of characters
in it. E.g. pineapple is a string of length 9.
The special symbol ǫ is used for the string containing no characters, which
has length 0. Zero-length strings may seem odd, but they appear frequently
in computer programs that manipulate text data. For example, a program
that reads a line of input from the keyboard will typically receive a zero-
length string if the user types ENTER twice.
We specify concatenation of strings, or concatenation of strings and indi-
vidual characters, by writing them next to each other. For example, suppose
that α = blue and β = cat. Then αβ would be the string bluecat and βs
be the string cats.
CHAPTER 1. MATH REVIEW 9
In standard definitions of the real numbers and in this book, infinity is not
a number. People are sometimes confused because ∞ is sometimes used in
notation where numbers also occur, e.g. in defining limits in calculus. There
are non-standard number systems that include infinite numbers. And points
at infinity are sometimes introduced in discussions of 2D and 3D geometry.
We won’t make use of such extensions.
Regular expressions are quite widely used in both theory and practical
applications. As a result there are many variations on the notation. There are
also other operations that make it easy to specify a wider range of patterns.