Computing and Data Science

Number

Humans are very good at recognizing patterns. We are often too good at it, finding patterns where there aren't any, but more on that later.

Calculus

Imagine living twenty-eight thousand years ago. Among your hobbies, you enjoy rock collecting. It isn't long before you start to notice patterns in various arrangements of your rocks.

You don't yet have a number system to talk about these patterns, but you have a sense of quantity. You notice that only certain quantities of rocks can form this nice pattern:

Pattern 1

\(\dots\)

\(\dots\)


\(\dots\)



and only certain quantities of rocks can form this other nice pattern:

Pattern 2

\(\dots\)

\(\dots\)


\(\dots\)



Moreover, you notice that you can combine adjacent arangements from Pattern 1 to get arrangements from Pattern 2. Pretty neat! Good thing cell phones don't exist...

Then your friend Chelsea, also from twenty-eight thousand years ago, notices another connection: sometimes she can combine two arrangements from Pattern 2 to get a bigger arrangement also in Pattern 2, but it doesn't always work. She finds this one:



   with    



   makes    





Pretty soon your whole village is obsessed with these amazing patterns. They find some nice rocks that stack into towers and begin to make arrangements of towers in patterns like this one:

Pattern 3

\(\dots\) \(\dots\)

Chelsea, who is rightly proud of her discovery about combinations in Pattern 2, searches for similar combinations in Pattern 3. She wants to find two piles in Pattern 3 that can combine together to get another pile in Pattern 3, but this last format is challenging and it will be quite a wiles before someone figures it out.

Factors

In modern times, rocks still exist. You can even find your own in nature. Let's build some numbers with rows of rocks:

One


Two
     


Three
     


Four
     
     


Five
     


Six
     
     
     

These are all the ways that you can construct the numbers one through six with regular rows (rows of the same size so they line up). In each construction, a row represents a factor or divisor of the number. Four example, \(4\) is a factor of \(12\) because we can construct 12 with rows of size \(4\). Another way to think about this is that \(12\) can be dividied into rows of size \(4\).

Definition

A factor or divisor is a number that divides a larger number into whole parts. We write \[d \mid n \] and say "\(d\) divides \(n\)" to mean that \(d\) is a divisor of \(n\).

Since \(4\) "goes into" \(12\), we may write \(4 \mid 12\). We can also write \(5 \nmid 12\) to say that \(5\) does not divide \(12\).

We haven't yet talked about negative rocks, which could be viewed as factors, but when we say "\(d\) divides \(n\)", we mean for positive integer values of \(d\).

Exercise

For \(n=1\) to \(15\), how many "rock constructions" can we make for \(n\)? How does this relate to the number of divisors of \(n\)?

Algorithm

Once we have stacks of rocks, we begin to move those stacks around. Like Chelsea, we start to find patterns not only in the arrangements, but also in relationships between arrangements. An algorithm is a sequence of steps to perform a calculation or solve a problem. The algorithms we will work with will take some inputs and return some output.

As we play with rock constructions, a question arrises:

Given two piles of rocks, what is the largest row that could be used in either of their constructions?
This is equivalent to asking: what is the greatast common divisor of two numbers?

Definition

If \(a\) and \(b\) are positive integers, the greatest common divisor of \(a\) and \(b\) is denoted gcd(\(a\),\(b\)) and is defined to be the positive integer \(d\) such that \(d \mid a\) and \(d \mid b\).

The algorithm below can be used to find the greatest common divisor of Left and Right piles of rocks.

Algorithm — Greatest Common Divisor

Given Left and Right piles of rocks, find the gcd of the two piles.


gcd(Left, Right):

  1. If the piles are the same size, that is the GCD and we are done.
  2. Remove a small-pile-amount from the larger pile, go back to 1.

In this algorithm, we start with two piles and repeatedly take the smaller amount away from the bigger amount until the piles are equal. Let's run through it with an example of \(55\) and \(25\).

Algorithm StepsState of Piles
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(55\)\(25\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(30\)\(25\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(30\)\(25\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(5\)\(25\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(5\)\(25\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(5\)\(20\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(5\)\(20\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(5\)\(15\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(5\)\(15\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(5\)\(10\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(5\)\(10\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(5\)\(5\)
(1) If the piles are the same size, that is the GCD and we are done
(2) Remove a small-pile-amount from the larger pile, go back to (1)
LeftRight
\(5\)\(5\)

We are done, and we find that \(\gcd(55,25) = 5\).

Exercise

Why does the \(\gcd\) algorithm work?

Decimal

Our standard number system is base-10, which uses ten symbols: \[0, 1, 2, 3, 4, 5, 6, 7, 8, 9\] Every place value is a power of 10. The number \[4703\] is 4 thousands (\(10^{3}\)), 7 hundreds (\(10^{2}\)), 0 tens (\(10^{1}\)), and 3 ones (\(10^{0}\)). We could make a table like this: \[ \begin{array}{c|c|c|c|c} \text{Place-Value} & 10^3 & 10^2 & 10^1 & 10^0 \\ \hline \text{Digit} & 4 & 7 & 0 & 3 \\ \end{array} \] or represent it like this:



Notice the ways that ten shows up all over the place in these representations.

Counting

Given a set of symbols like \(0,1,2,3,4,5,6,7,8,9\), we start counting with the symbol \(0\) reprsenting zero, then move to the next symbol to represent the next number, and so on: \[ \begin{array}{c|c} \textbf{Number} & \textbf{Decimal} \\ \hline \text{zero} & 0 \\ \text{one}& 1 \\ \text{two}& 2 \\ \text{three} & 3 \\ \text{four} & 4 \\ \text{five} & 5 \\ \text{six}& 6 \\ \text{seven} & 7 \\ \text{eight} & 8 \\ \text{nine} & 9 \\ \end{array} \] At this point, we have run out of symbols! With every number system:

When you run out of symbols, start over, and add one to the left.

To move from \(9\) to the next number, we reset the ones place from \(9\) back to \(0\) and increment the tens place to get \[10\] Then we can go through all of the symbols again until we get to \(19\) and repeat the process to get \(20\).

In each place, we start with our first symbol, \(0\), and count up to our last symbol \(9\). Every time we run out of symbols, we start over at \(0\) and add one to the left.

Place Value

Each place we write a decimial has a value associated with it. That value is a power of \(10\), increasing from right to left.

\(10^{4}\)\(10^{3}\)\(10^{2}\)\(10^{1}\)\(10^{0}\)
00000\(=\)0

If this is the only number system you know, then it might be suprising to learn that we don't have to represent numbers this way.

Binary

Binary is a base-2 number system that uses the symbols \(0\) and \(1\). When we start counting in binary, we run out of symbols quickly: \[0\] \[1\] We reset the one's place and add \(1\) to the left of it: \[10\] That looks like a ten, but it is a two written in binary. Here are several numbers written in binary: \[ \begin{array}{c|r} \textbf{Number} & \textbf{Binary} \\ \hline \text{zero} & 0 \\ \text{one} & 1 \\ \text{two} & 10 \\ \text{three} & 11 \\ \text{four} & 100 \\ \text{five} & 101 \\ \text{six} & 110 \\ \text{seven} & 111 \\ \text{eight} & 1000 \\ \text{nine} & 1001 \\ \end{array} \] Some very nice patterns emerge. In fact, once we notice patterns counting in base-2, we might go back and look for similar patterns in base-10 that were there all along.

Place Value

In binary, we have numbers that look like: \[10111\] which has place-values in base-2: \[ \begin{array}{c|c|c|c|c|c} \text{Place Value} &2^4 & 2^3 & 2^2 & 2^1 & 2^0 \\ \hline \text{Bit} & 1 & 0 & 1 & 1 & 1 \\ \end{array} \] We can convert \(10111\) to decimal by calculting: \[ 1(2^4) + 0 (2^3) + 1 (2^2) + 1 (2^1) + 1(2^0) \] \[ = 16 + 0 + 4 + 2 + 1 \] \[ = 23 \]

Try creating some binary numbers by clicking on the cells below:

6432168421
0000000\(=\)0

Decimal to Binary

Let's convert \(57\) to binary. We look at the place values and fill in the largest possible place until we have a value that sums to our target of \(57\).

\[ \begin{array}{c|c|c|c|c|c|c|c r } \text{Place Value} & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^0 & \quad \quad \text{Target: }57 \\ \hline \text{Bit} & & & & & & & & \quad \quad \text{Sum: } 0 \\ \end{array} \] \[ \begin{array}{c|c|c|c|c|c|c|c r } \text{Place Value} & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^0 & \quad \quad \text{Target: }25 \\ \hline \text{Bit} & & 1 & & & & & & \quad \quad \text{Sum: } 32 \\ \end{array} \] \[ \begin{array}{c|c|c|c|c|c|c|c r } \text{Place Value} & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^0 & \quad \quad \text{Target: }9 \\ \hline \text{Bit} & & 1 & 1 & & & & & \quad \quad \text{Sum: 48 } \\ \end{array} \] \[ \begin{array}{c|c|c|c|c|c|c|c r } \text{Place Value} & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^0 & \quad \quad \text{Target: } 1 \\ \hline \text{Bit} & & 1 & 1 & 1 & & & & \quad \quad \text{Sum: 56 } \\ \end{array} \] \[ \begin{array}{c|c|c|c|c|c|c|c r } \text{Place Value} & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^0 & \quad \quad \text{Target: } 0 \\ \hline \text{Bit} & & 1 & 1 & 1 & 0 & 0 & 1 & \quad \quad \text{Sum: 57 } \\ \end{array} \] We find that \(57\) in binary is \(111001\).

Exercise

Convert the binary \(101010\) to decimal.

Convert the decimal number 76 to binary.

Recommended Resources