The Beginning

Thomas J. Kennedy

Contents:

1 The Big-3

In C++, when discussing Object Oriented Programming, we cover the Big-3 (or Big-0 or Big-5). These Big-3 eventually become second nature.

This course (i.e., CS 417) has its own Big-3:

  1. It is Just Notation.
  2. Left as an Exercise to the Reader.
  3. Slightly Inconvenienced, Not Overwhelmed.

1.1 It is Just Notation

Math and Computer Science use many mathematical notations. This includes some Calculus:

$$ \int f(x)dx $$ $$ \lim_{x\to\infty} \frac{1}{x}$$ $$ \sum_{i=0}^{\infty} x_i^2 $$ $$ \prod_{i=0}^{10} x_i^2 $$

You will see many notations in this course. Some will be familiar… others will be unfamiliar. Throughout this semester we will strive to demystify these notations.

1.2 Left as an Exercise to the Reader

Many textbook and academic paper authors skip over certain steps in a problem. You have probably come across the phrase left as an exercise to the reader". In such cases, the reader is expected to have the necessary foundation to understand the omitted steps.

At the start of the semester most of my discussions will include sidebars. I will take a step back, work through the oft omitted steps, and explain the “tricks of the trade”.

As you become familiar with the process, I leave working through more of these left as an exercise to the reader steps up to you.

1.3 Slightly Inconvenienced, Not Overwhelmed

Many students look at a math problem, see unfamiliar notation, and psyche themselves out. At the end of this semester you should, at worst, feel slightly inconvenienced, not overwhelmed, by such problems.

2 A Couple Quick Tricks

Through this semester we will work with many formulae. This includes:

  1. The sum of the first n integers.
  2. The Geometric Series formula.

These are usually the first two formulae students put on a cheat sheet. Is it possible to derive them? Yes.

2.1 The First n Integers

Suppose we wanted to sum the first 10 integers (1 to 10) or first 100 (1 to 100) integers. As computer scientists we would probably write a couple lines of Python 3 code:

print(sum(range(1, 11)))
print(sum(range(1, 101)))

Of course, we know the naive way to solve this by hand (i.e., on paper): write down all the numbers and compute a running sum.

Let use $S_n$ to represent the sum of the first $n$ integers. This allows us to write:

$$ S_n = 1 + 2 + 3 + 4 + \dots + (n-2) + (n-1) + n $$

Now that we have defined a notation, we can leverage the associativity of addition to write:

$$\begin{align} S_n &= 1 + 2 + 3 + 4 + \dots + (n-2) + (n-1) + n \\ &= n +(n-1) + (n-2) + \ldots + 4 + 3 + 2 + 1 \\ \end{align} $$

All we did was reverse the ordering. Now we can write:

$$\begin{align} 2S_n &= 1 + 2 + 3 + 4 + \dots + (n-2) + (n-1) + n \\ &+ n +(n-1) + (n-2) + \ldots + 4 + 3 + 2 + 1 \\ \end{align} $$

We can then group each pair of terms:

$$\begin{align} 2S_n &= 1 + 2 + 3 + 4 + \dots + (n-2) + (n-1) + n \\ &+ n +(n-1) + (n-2) + \ldots + 4 + 3 + 2 + 1 \\ \hline 2S_n &= n + 1 + (n-1) + 2 + (n-2) +3 + \ldots + 4 + (n-3) + 3 + (n-2) + 2 + (n-1) + 1 + n \\ &= (n+1) + (n+1) + (n+1) (n+1) + \ldots + (n + 1) + (n + 1) + (n+1) + (n+1) \\ \end{align} $$

If we count up all the $(n+1)$ terms we end up with:

$$ \begin{align} 2S_n &= n(n+1) \\ S_n &= \frac{n(n+1)}{2} \\ \end{align} $$

That is the well known equation for the sum of the first n integers. That allows us to compute:

$$ S_{10} = \frac{10*11}{2} = 55 $$

and

$$ S_{100} = \frac{100*101}{2} = 5050 $$

This approach is well known (i.e., it is akin to Newton’s laws of motion).

3 Geometric Series

We can apply a similar set of tricks to derive the geometric series formula. We will restrict ourselves to $r < 1$ and finite series. Suppose we have the series:

$$ \begin{align} S &= \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{16} + \frac{1}{32} \\ &= 2^{-1} + 2^{-2} + 2^{-3} + 2^{-4} + 2^{-5} \\ \end{align} $$

There are two approaches:

  1. Pull out a common $\frac{1}{2}$ and have the series start at 1.
  2. Use the $0 = 1 - 1$ trick.

We will use the second trick in few examples this semester. Let us try the former approach. That leads us to

$$ \begin{align} S &= \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{16} + \frac{1}{32} \\ S &= 2^{-1} + 2^{-2} + 2^{-3} + 2^{-4} + 2^{-5} \\ S &= \frac{1}{2}(1 + 2^{-1} + 2^{-2} + 2^{-3} + 2^{-4}) \\ \end{align} $$

Let us replace $2^{-1}$ with r:

$$ \begin{align} S &= r(1 + r^{1} + r^{2} + r^{3} + r^{4}) \\ \end{align} $$

and ignore the leading $r$. That leaves us with:

$$ \begin{align} S &= 1 + r^{1} + r^{2} + r^{3} + r^{4} + \ldots + r^{n-1} \\ \end{align} $$

We would like to eliminate a few terms. We will use the $S - rS$ trick:

$$ \begin{align} S &= 1 + r^{1} + r^{2} + r^{3} + r^{4} + \ldots + r^{n-1} \\ -rS &= r^{1} + r^{2} + r^{3} + r^{4} + \ldots + r^{n} \\ \hline S - rS &= 1 - r^n \\ \end{align} $$

That leaves us with a couple algebraic manipulations:

$$ \begin{align} S - rS &= 1 - r^n \\ (1-r)S &= 1 - r^n \\ S &= \frac{1 - r^n}{1-r} \\ \end{align} $$

We can add $a$ as a scaling factor, leaving us with:

$$ \begin{align} aS &= a\frac{1 - r^n}{1-r} \\ \end{align} $$

We can solve the original problem by letting $n=5$ and $a = 2^{-1}$. That leads us to:

$$ \begin{align} 2^{-1}S &= \frac{1}{2}\frac{1 - 2^{-5}}{1-2^{-1}} \\ &= \frac{1}{2}\frac{1 - 2^{-5}}{2^{-1}} \\ &= \frac{1}{2}2(1 - 2^{-5}) \\ &= (1 - 2^{-5}) \\ &= \frac{32}{32} - \frac{1}{32} \\ &= \frac{31}{32} \\ \end{align} $$

This derivation is another “well known” summation trick.