Numbers
Now, suppose you have a younger sibling who has eaten the top-left square of your chessboard. Can you completely cover without overlap this chessboard with dominoes?
What if they also ate the bottom-right square? Does this change your answer?
Now, we know that this isn’t right, and that is actually . Sometimes, however, even a formula that is wrong in general might be right in a specific situation! Think of the old adage “a stopped clock is right twice a day”.
Does this ever happen with this mistake? In other words: are there any values such that ? Or is this false for literally every value of and ?
Integers
We start our coursebook by studying the integers! In case you have not seen the word “integer” before, we define it here:
In this course and in mathematics in general, we will define lots of useful concepts. When we do so, we’ll label these things by writing ”Definition” in bold, and then give you a carefully-written and precise definition of that word.
When studying for this class, it is a good idea to make sure that you know all of the definitions in this coursebook, as well as some examples and nonexamples for each definition where appropriate.
The symbol comes from the German word “Zahl”, which means “number”, in case you were curious.
Example 1.1. The numbers are integers, but things like and are not.
In some form or another, integers have been used by humans for almost as long as humans have existed theirselves. The Lebombo bone, one of the oldest human artifacts, is a device on which people used tally marks to count the number of days in the lunar cycle. The base-10 system and idea of numerals took a bit longer for us to discover, but we can trace these concepts back to at least the Egyptians and Sumerians around 4,000-3,000 BC. Finally, negative numbers and zero have been with us for at least two millenia: historical documents tracking back to at least 1000 BC describe how Chinese mathematicians used negative numbers solve concrete problems on bounding areas of fields, exchanging commodities, and debt.
In short, integers are quite handy! To this day, we use them to model all sorts of problems. To give a pair of examples, let’s solve the first two exercises from this chapter:
Answer to Exercise 1.1. By just trying things out by hand, it’s relatively straightforward to find a tiling of a board with no squares missing; one solution is drawn below.
When you remove a square, however, things get a bit more interesting! Try it for a while; no matter how you do this, you’ll always have at least one square left over uncovered.
However, saying “I tried it a lot and it didn’t work” is not a very persuasive argument. Suppose that you had a boss that said that Chad from Marketing said this was totally possible, and to have a working version on their desk by 5pm or you’ll be fired. What do you do?
Well, maybe you start revising your resumé and looking for other work. Before that, though, you may want to try to make a logical argument to your boss that shows that it’s impossible to come up with such a tiling - a set of reasons so airtight that no matter what they think or would respond with, they’d have to agree that you’re right. In mathematics and computer science, we call such logical arguments proofs!
In this class, we’re going to write these kinds of arguments for almost all of the claims that we make. We’re going to leave the rules for what constitutes a “proof” a little vague at first; in our first few chapters, we’re going to just try to write a solid argument that tells us why something is true, and anything that does that we’ll count as a proof. (Later in this course, we’ll approach proofs a bit more formally: feel free to read ahead if you can’t wait!)
For this problem, let’s prove that an chessboard without a single square cannot be covered with dominoes as follows:
Proof.
First, notice that each time we place a domino on a board, it covers two squares worth of area. Because dominoes cannot overlap, this means that if we have placed dominoes on our board, there are squares of our board covered by dominoes.
If we have an chessboard that’s missing a square, that board has squares on it in total. Therefore, if we’ve completely covered our chessboard with dominoes, the number of dominoes we used must satisfy the equation .
In other words, we have ; i.e. we’ve used half of a domino! This means that the other half of that domino is sticking off of our board or overlaps another domino, which means we’ve broken the rules of our tiling problem. So this is impossible!
To denote the end of our arguments, we draw a square box symbol, like . This means that we’ve reached the end of our argument. In physics or other fields, people often use QED in place of this. Feel free to use either in your own working!
Notice how in the argument above, the only things we used were factual observations (i.e. the number of squares in our grid minus a square, the amount of area taken up by each domino) and logical combinations of those observations. This is how you write a solid argument!
To get a bit more practice with this sort of thing, let’s try the last part of our exercise. In this problem, we had a chessboard with its top-left and bottom-right squares removed, and wanted to try to cover this with dominoes.
On one hand, the argument above no longer tells us that this is impossible. A board minus two squares contains 62 squares in total; therefore, it might be possible to do this with 31 dominoes! However, if you try this for a while, you’ll find yourself quite stuck again. So: why are we stuck? What is a compelling argument we could write that would persuade someone that this is truly impossible, and not just that we’re bad at tiling?
After some thought and clever observations, you might come up with the following:
Proof.
- Notice that each time we place a domino on our grid, it’s not just true that it covers two units of area: it also covers exactly one unit of white area and one unit of black area! This is because our chessboard has alternating white and black squares.
Because dominoes cannot overlap, this means that if we have placed dominoes on our board, there are white squares and black squares covered by our dominoes. In particular, this means that we always have as much black area covered as white area!
- However, if we count the black and white area in our board with the top-left and bottom-right squares removed, we can see that there are 32 black squares and 30 white squares. These numbers are different! Therefore, it is impossible to cover this board with dominoes as well.
Notice that when we wrote this argument, we used observations from our earlier work, and modified them to suit this new problem! This is a good problem-solving technique in general: always see if you can modify a pre-existing solution before trying to come up with something entirely new.
In our working above, the fact that we could not write 63 as an integer multiple of 2 was a very useful observation! We can generalize this into the concepts of even and odd integers:
Even and Odd Integers
Example 1.2. 2 is even, because we can write , and is an integer. Similarly, is an even number, because we can write and is an integer.
As well, and are all even, because we can write , and , where are all integers.
3 is odd, because we can write and 2 is even (as shown above.) Similarly, because and , we have that 5 and 7 are also odd. As well, are all odd, as and .
To get some practice writing logical arguments, let’s look at a few properties of even and odd numbers that you already know:
Claim 1.1. The sum of any two odd numbers is even.
Before getting into a “good” solution for this claim, let’s first study an argument that doesn’t work.
“Bad” solution: Well, is even, is even, is even, and is even. Certainly seems to be true!
A defense of the “bad” solution: This might seem like a silly argument, but suppose we’d listed a thousand examples, or a billion examples, or set a computer program to work overnight and had it check all of the pairs of numbers below . In many other fields of study, that would be enough to “show” a claim is true! (Think about science labs: there, we prove claims via experimentation, and any theory you could test a billion times and get the same result would certainly seem very true!)
Why this argument is not acceptable in mathematics and computer science: When we make a claim about “any” number, or say that something is true for “all” values, we want to really mean it. If we have not literally shown that the claim holds for every possible case, we don’t believe that this is sufficient!
This is not just because computer scientists are fussy. In the world of numbers, there are tons of “eventual” counterexamples out there:
- Consider the following claim: “The sequence of numbers ” ” are all not prime.”
Skip ahead a bit to Definition 1.4. if you haven’t encountered prime numbers before!
If you were to just go through and check things by hand, you’d probably be persuaded by the first few entries:
However, when you get to , that one’s prime! This is well beyond the range of any reasonable human’s ability to calculate things, and yet something that could come up in the context of computer programming and information security (where we make heavy use of 500+ digit primes all the time.)
Here’s a fun exercise one of the writers of this coursebook saw in the wild on Facebook, shared by one of our troll-ier friends:
On its surface, this looks simple, right? Just solve it.
And yet: suppose you set a computer program to work at this problem, by just bashing out all possible triples of numbers. To be fair, let’s give you access to the world’s fastest supercomputer. By the end of a week, you wouldn’t have found an answer. By the end of a year, you wouldn’t have found an answer! Indeed: by the time we reached the heat death of the universe, you’d still have found nothing. You’d be tempted to say that no answer exists, right?
Roughly years, or seconds, or about floating-point operations on the world’s fastest supercomputer as of early 2019.
And yet, an answer exists! The math required to find this goes way beyond the scope of this course, but if you’re curious: the smallest known answer is to do the following:
In general, mathematics and computer science is full of things like this! Huge numbers that are prime or that satisfy equations similar to the ones above can be incredibly useful in information security (as you’ll see in later papers in Compsci/Maths!)
Examples alone, then, are not enough for a good argument. What would a good solution look like here? Here is one of many possible answers:
Proof.
Take any two odd numbers. Let’s give them names, for ease of reference: let’s call them and . By definition, because and are odd, we can write and , for two integers .
Therefore, . In particular, this means that is an even number, as we’ve written it as a multiple of 2!
The argument above might look a little awkwardly-written to you at a first glance! This is because mathematics is something of a language in its own right: there are certain phrases and constructions with very specific meanings in mathematics, that we use when making arguments to ensure that they’re completely rigorous. Let’s talk about some of those phrases and concepts that came up in the argument above:
-
We worked in general! That is, we didn’t just look at a few examples, but instead considered arbitrary values! This is what writing a phrase like “Take any two odd numbers” does for us: it doesn’t lock us into specific odd numbers, but instead tells the reader that we’re going to show that this works for anything that could ever come up.
-
We defined our variables! That is, we didn’t just try to use pronouns to refer to our odd numbers the whole way through: instead, we gave them variable names, by calling them and . This makes writing our arguments much cleaner, as it’s much easier to refer to something if it has a name!
Note also that we defined these variables only after saying what kind of object they were! This is like when you’re writing code: you typically have to declare the type of variable you’re working with, i.e. you’d write something like int numA
instead of just saying numA
.
- We used words to describe what we were doing and why it worked! Mathematics, surprisingly, has a lot of words and sentences in it. You should find that the number of sentences in most solutions you make in this class exceeds the number of equations!
To get a bit more practice with this, let’s try out a few more claims:
Proof.
As before, let’s start by taking any two odd numbers. Let’s give them names, and call them and respectively.
Also as before, let’s consult our definitions! By definition, because are both odd, we can again write and , for two integers .
Therefore, . Expanding this product gives you , which you can regroup as . Factoring a 2 out of the left-hand part gives you .
Because are integers, the expression inside the parentheses is an integer as well, as any product or sum of integers is still an integer. Therefore, we’ve written in the form ; i.e. we’ve shown that satisfies the definition of being an odd integer!
Proof.
As before, let’s start by working in general. Take any integer .
Phrases like “Take any integer ” or “take any number ” are useful; they start by both saying that we’re going to work in general with any number, and also assign a variable to that number so that we can refer to it.
As a thought experiment, let’s think about what it would mean for to be both odd and even at the same time.
If was even, then by definition we could write for some integer ; as well, if is also odd, then by definition we should be able to write for some integer .
Note that we had to pick different letters when we applied the even and odd definitions! If we had used the same letter for both, that would imply that the same integer is being used in both definitions, and this might not be true.
As a result, we have and . Combining gives us , which we can rearrange into ; i.e. .
But this is clearly not possible! and are both integers, and so their difference must an integer as well; it cannot be !
As a result, we’ve shown that it is impossible for an integer to be equal to and at the same time if are both integers; that is, it is impossible for to be both odd and even!
(S1 2019 Test Q5) Which of the following statements about integers is FALSE?
0 is both an even integer and an odd integer.
See Claim 1.3: No integer can be both odd and even at the same time.
There are infinitely many distinct integers.
This is a TRUE statement. To prove it, ask yourself what happens if the statement were FALSE.
The integer 56,784,910 is even.
The sum of any two odd numbers must be even.
This statement is TRUE. See Claim 1.1.
Follows from definition of even numbers. 56,784,910 can be written as .
(SS 2020 Test Q1) Which of the following statements is FALSE?
Follows from the Definition 1.2.
The sum of an odd number and an even number is always an odd number.
The square of an odd number must be even.
This is not straightforward. You need to work a bit. See the next exercise on how to prove this.
is an even number.
Let be ab odd number and let be an even number. Then, by definition of even and odd integers, we have and where and are some integers. Now, . Thus, is an odd integer.
Let be an odd number. Then . From Claim 1.2, we know the product of any two odd numbers is odd. Hence, the statement is FALSE.
For every choice of positive integers and , the number is even.
By definition, you can think of our even/odd split above as classifying every number as either “a multiple by 2” or “not a multiple of 2.” We expand on this idea in the following section, where we study divisibility and prime numbers.
Divisibility and Primes
There are many synonyms for “divides”: each of the phrases
- ” is a divisor of “,
- ” is a factor of “,
- ” is a multiple of “,
- ” can be divided by ,” and
all mean the same thing as ” divides .”
Here’s a string of examples, to make this clearer:
Example 1.3.
- divides ; this is because we can multiply 4 by 3 to get 12.
- can be divided by ; this is because we can multiply by to get 72.
- does not divide ; this is because for any integer , is an even number, and so is in particular never equal to an odd integer like 15.
- is a multiple of for any integer ; this is because we can always multiply 1 by to get .
- is a factor of for any integer ; this is because we can always multiply by 0 to get 0.
Example 1.4. Note that the phrases “divides” and “can be divided by,” while quite similar-sounding in English, have almost the opposite meaning in mathematics! For instance, 3 divides 9 and 9 can be divided by 3 are the same claims.
To get some practice with making abstract arguments about divisibility, let’s study a simple claim about factors and divisibility:
Again, we need to work in abstract! That is: we cannot just check this for a few values and say that “well, when this all works out.” Instead, we must consider any three integers , and work in general without knowing what are.
In theoretical computer science / mathematics, the words “any” and “every” are often used interchangeably. That is, if someone says to you “For any integer , ,” this means the same thing as “For every integer , .”
By definition, if divides , we can write for some integer . Similarly, if divides , then we can write for some integer .
Now, take the equation , and use this to substitute in for in our second equation . This gives us , i.e. . Because are both integers, their product is an integer; as a result, we’ve written . In other words, by definition we have shown that is a factor of , as desired.
A particularly useful concept related to divisibility is the concept of a prime number:
Example 1.5. The first few prime numbers are
Proof.
This is because 1’s only factor is 1, and so 1 does not have two distinct positive integer factors.
Proof.
This is because every other positive even number by definition has the form , and so has at least as its set of factors (and thus has more than 2 distinct positive factors.)
Example 1.6. , , and are all composite.
(S1 2019 Test Q6) Which of the following is a prime number?
17
Factors of 17 are 1 and 17.
3,784,972
This number has more than two factors as 1, 2, and 3,784,972 are all factors. Hence, cannot be prime by definition.
1
330
This number has more than two factors as 1, 2, and 330 are factors. Hence, cannot be prime by definition.
See Observation 1.1. 1 is neither prime nor composite.
(SS 2020 Test Q2) Which of the following statements is FALSE?
1 is a prime number
123212424242444333333332 is not a prime number.
This is true as 123212424242444333333332 has more than two distinct factors.
This is FALSE. See Observation 1.1.
If is a positive integer then cannot be prime.
This is a true statement. If , then , which is not prime. If , then conatins and as factors, and hence not prime.
If and are both positive even numbers then cannot be prime
This is a true statement. Since and are even, and where and are integers. Now, . If , then , which is not prime. If , then has atleast 1, 4 and as factors and hence cannot be prime.
Example 1.7. Here are a few prime factorizations:
- ,
- ,
(S2 2019 Test Q1) What is the prime factorisation of 20?
Prime factorisation is way of factoring an integer into product of prime numbers. By obervation 1.1, 1 is not prime and hence the product is not a prime factorisation of 20.
Prime factorisation is way of factoring an integer into product of prime numbers. 4 is not a prime number and hence this is incorrect.
Prime factorisation is way of factoring an integer into product of prime numbers. Here, 20 is expressed as a sum of two integers and hence incorrect.
We can write .
Here are a pair of useful observations about prime numbers:
Theorem 1.1. Every positive integer can be factorized into a product of prime numbers in exactly one way, up to the ordering of those prime factors.
To see a proof of Theorem 1.1., take Compsci 225!
You might object to Theorem 1.1. by saying that 1 cannot be factored into a product of prime numbers. If so, good thinking! For now, regard 1 as a special case.
Later on, though, we’ll consider the idea of an “empty product” when we get to the factorial and exponential functions. At that time, we’ll argue that the “empty product” or “product of no numbers” should be considered to be 1, because 1 is the multiplicative identity. If you believe this, then 1 can indeed be written as the product of prime numbers; it specifically can be written as the product of no prime numbers!
In other words, this theorem is saying the following:
-
Every positive integer can be factored into primes, as illustrated above. So, for example, we can take 60 and write it as .
-
No number can be factored into primes in two different ways, up to the ordering. That is: while you could write as or , you’re never going to write a prime factorization of 60 that has a 7 as one of its prime factors, or doesn’t have a 5.
is a factor of .
is a prime number.
is a composite number.
None of are factors of .
We can find a counter-example: and is composite.
We can find a counter-example: and is prime.
cannot be a factor of because by definition and the largest possible factor of any number is the number itself.
Let’s assume is a factor of , then this means that has to divide both and , but by definition, so it is not possible. Therefore, we reached a contradiction and cannot be a factor of . Same logic works for and .
Take three prime numbers . Let .
Which of the following statements must be true about ?
Proving this theorem is a bit beyond our skill set at the moment. Instead, let’s mention a second useful fact about primes:
Theorem 1.2. There are infinitely many primes.
This proof is also a bit beyond us for now. However, if you skip ahead to the proof by contradiction section of our notes / wait a few weeks, you’ll see a proof of this in our course!
Prime numbers (as you’ll see in Compsci 110) are incredibly useful for communicating securely. Using processes like the RSA cryptosystem, one of the first public-key cryptosystems to be developed, you can use prime numbers to communicate secretly over public channels.
Prime numbers are also quite baffling objects, in that despite having studied them since at least 300 BC there are still so many things we do not know about them! Here are a few particularly outstanding problems, the solutions for which would earn you an instant Ph.D/professorship basically anywhere you like in the world:
In general, working with prime numbers can get tricky very fast; even simple problems can get out of hand! With that said, there are some claims that are approachable. We study two such statements here:
Proof.
As noted before, examples alone aren’t enough for a solution. However, if you’re stuck (as many of us would be on first seeing a problem like this) they can be useful for helping us find a place to start!
prime factorization of | ||
---|---|---|
So: let’s create a bunch of two-digit numbers and factor them (say, via WolframAlpha.) If our claim is wrong, then maybe we’ll stumble across a number whose only factors are 1 and itself. Conversely, if our claim is right, maybe we’ll see a pattern we can generalize! We do this at right.
As we do this, a pattern quickly emerges: it looks like all of these numbers are multiples of 101! This isn’t a solution yet: we just checked six numbers out of quite a few possibilities. It does, however, tell us how to write a proper argument here:
Notice that for any two-digit number , . Therefore, any number of the form is a multiple of 101 and also a multiple of , by definition. Because is a two-digit number by definition, this means that has at least two factors other than 1. This means that cannot be a prime number, as claimed!
Proof.
We use the “suppose we’re wrong” technique from Claim 1.3. That is: take any number with the “no factors in the set ” property listed above. There are two possibilities:
-
is prime. This is what we want: if this case holds, we’re done!
-
is not prime. We want to show that this case cannot hold; if we can do this, then we are left with only the case above, and have thus proven our claim!
To do this: note that if is not prime, then, it must have more than 2 factors. Let be one of those positive factors that is not or ; by the definition of factor, then, we can write for some positive integer , and thus have that is also another factor of .
We know that because that . We also know that because both are factors of , that by our “suppose we’re wrong” assumption that . Therefore, by combining these results, both ; that is, both are greater than .
But this means that . But this is impossible, as .
Therefore the only possibility left is that is prime, as desired.
This last claim is particularly useful! We know that by definition, a positive integer is prime if it has exactly two positive integer factors: 1 and itself. Naively, then, to check if a number is a prime, you might think that you would have to check all of the numbers each individually, and see if any of them divide .
However, Claim 1.6. tells us that we don’t actually have to check all the numbers up to ; we only have to go up to . This can save us a lot of time: as you’ll see later in this coursebook in our runtime-analysis section / in papers like Compsci 130 and 220, a “runtime” of checking cases is considerably better than a “runtime” of checking cases!
For instance, to see if is prime, Claim 1.6. tells us that because 101 is not a multiple of 2,3,4,5,6,7,8,9 or 10, then 101 is itself a prime. (Much faster than checking all of the numbers up to 100.)
We leave a few more exercises along these lines for the end of this chapter. For now, we turn to an extension of the ideas behind divisibility: modular arithmetic!
Modular Arithmetic
Modular arithmetic is something you’ve been working with since you were a child! Specifically, think about how you tell and measure time:
-
Suppose that it is currently 6am and 3 hours pass. Because , we know that the answer is 9am.
Now, suppose that it is 11am and 18 hours pass. What is the time now?
Unlike the process above, you would not find the answer here by adding 18 to 11 and getting “29 o’clock.” Instead, you’d find , and then subtract off 24 to get the right answer, .
In general, when you’re adding hours together to tell time, you do so on a circle (as drawn at right,) where measurements “wrap around” every 12 hours. That is: if it is 7 o’clock now and 38 hours pass, then the hour hand on a clock would point to a 9; this is because , and .
-
In the above example, we saw that hours wrapped around in units of 12. Similarly, we know that days of the week repeat in groups of 7. That is: let Monday = 0, Tuesday = 1, and so on/so forth until we get to Sunday = 6. Then, suppose that it is Thursday and we want to know what day of the week it is in 10 days. We can see that because “Thursday ” and , the day must be Sunday.
-
Similarly, seconds wrap around in groups of 60. That is: if you type in “99” on your microwave and walk away, the same amount of time passes as if you had entered “1:39”, because and thus 99 seconds is a minute and 39 seconds.
Using “99” on your microwave: one of the less-useful “life pro tips.”
All of these calculations involved arithmetic where our numbers “wrapped around” once they got past a certain point. This idea is the basis for modular arithmetic, which is arguably the most useful mathematical concept you’ll encounter in computer science.
To make this rigorous, let’s make a definition:
An algorithm is a step-by-step process for solving a problem or performing a calculation! We will study algorithms in more depth later in this class; you’ll also see them everywhere in Compsci 110 / 130 / 220 / 225 / essentially, every paper you’ll see in your Compsci degree!
- If , repeatedly subtract from until . The result of this process is .
- If , repeatedly add to until . The result of this process is .
Note: if , we can use the same process as above to calculate . The only change is that we replace with in our steps, to compensate for the fact that is negative.
- If neither of these cases apply, then by definition . In this case, is simply (that is, we don’t have to do anything!)
We call the modulus operator. Most programming languages implement it as described here, though (as always) you should read the documentation for details.
To get a handle on this, we calculate a number of examples:
Example 1.8.
-
. To see why, simply run the process above. Because , we just subtract copies of 2 from 4 until we get something less than 2: .
-
. To see why, simply run the process above. Because , we just add copies of 2 from 4 until we get something nonnegative: .
-
In general, if is any even number, then . This is because if we start with any even number , the process above will reduce to 0 after subtracting/adding times in a row.
-
Similarly, if is any odd number, then . These two observations come in handy when working with binary arithmetic: as you’ll see in Compsci 110, these facts tell you that you can tell if a number is even or odd by looking at its last digit in binary!
-
. This is an easy one to calculate: because , we don’t have to do anything here!
We also study a quick argument-based problem, to make sure that we’re comfortable with a more “abstract” way of working with the modulus operator :
Proof.
As always, because this is a claim about any two integers, we need to work in general. That is: we cannot pick examples for and , and instead need to consider every possible pair of values for with .
Our algorithm had three different cases: one for when , one for when , and one for when . As such, our argument will likely want three cases as well:
-
. In this case, our algorithm repeatedly subtracted copies of from until it got to something less than .
This process clearly only runs for finitely many steps, as starts off as greater than and decreases by a fixed nonzero amount at each step. In particular, it must eventually be less than , as that was the condition we gave for this process to stop.
As well, if , then ; as a result, when this process ends, it cannot end at a negative number.
Therefore, at the end of our process we’ve reduced so that it’s nonnegative and less than , as desired.
-
. In this case, our algorithm repeatedly added copies of from until it got to something positive.
As before, this process clearly only runs for finitely many steps; this is because starts off as a negative number and increases by a fixed amount at each step. In particular, it must eventually be nonnegative, as that was the condition we gave for this process to stop.
As well, if , then ; as a result, when this process ends, it cannot end at a value equal to or greater than .
Therefore, at the end of our process we’ve reduced so that it’s nonnegative and less than , again as desired.
-
. In this case our algorithm just outputs , which again has the desired properties.
Because every integer falls into one of these three cases, we’ve proven our claim for all values of and all , as desired.
This sort of argument (that a given algorithm “works”) is one that we will make repeatedly in this class! More generally, these are the most common sorts of arguments you’ll want to make in computer science: when working with any problems that require nontrivial algorithms or thought, you’ll often want to be able to write proofs that the process should be bug-free in theory.
Some useful notation for rounding: given any number , we say that is ” rounded down,” is ” rounded up,” and is ” rounded to the nearest integer, with .5 rounding up.”
For example, , , , and .
Modular arithmetic comes up often in computer science and mathematics:
-
Remainders. Take any two positive integers . We say that the quotient of on division by is just ” rounded down:” that is, we say that the quotient of is 4, as rounds down to 4.
Based on this, we say that the remainder of is the difference of and the quotient of on division by times ; that is, the remainder of is everything “left over” after we try to divide through by .
Notice that by definition, is the remainder of ! So, for example, we have the following:
-
Because , we have that the remainder of is 2.
-
Because , we have that the remainder of is 0.
-
-
Binary arithmetic. Computers are built off of the binary number system: i.e. instead of storing numbers in decimal notation where we use the digits 0,1,2,\ldots 9, computers store everything with just 0’s and 1’s (i.e. on and off, which computers are much better at storing than something as imprecise as a decimal digit!) To work with numbers in binary, we often work modulo 2, as you’ll see in classes like Compsci 110.
-
Overflow errors. In many programming languages, you have to tell the computer the “type” of any variable that you want to work with. That is, you can’t just tell the computer that
x = 3
;” instead, you have to first tell the computer that is an integer by writing something like ”int x
;” and then say ”x = 3
.”However, when you declare that is an integer, your computer does not automatically assume that can literally be any integer! This is because when a computer declares a variable, it typically has to set aside a block of space to store the information corresponding to that variable. As a result, the computer has to make an assumption about a reasonable range of values that your integer will fall between (a common range is to , i.e. you use 32 bits to describe your integer in binary, with one of those used to record .)
Suppose you did this, though, and later on tried to increase the value stored in past its maximum value: i.e. you had , and you tried to add one to . The result (if you ignore warnings / errors produced by your compiler) won’t be , because this value is too large to store! Instead, it will often “overflow” and wrap around to become instead. That is: computers technically do a lot of their arithmetic “mod ,” and this can trip you up if you’re not being careful about the sizes of your variables! Check out Wikipedia’s integer overflow page for a bunch of examples and discussion around how to handle this situation.
-
Checksums. On almost every ID number or tag (i.e. barcodes, bank account numbers, library book numbers, etc) the last digit or two is a “checksum” digit, found by adding up the previous numbers and applying the operator to the result (with usually being 10, but sometimes something stranger like 97 in the case of bank account numbers.)
The use of these checksum digits is that they let a computer program spot typos: if someone makes a mistake when entering a number, they’ll usually do so in a way that changes the modulus of the sum! As a result, we can spot this error by rechecking the modulus, and alert the user that they’ve made a mistake.
-
Cryptography. Calculating remainders modulo has been key to the entire field of cryptography, from its inception in ancient Rome to its present-day uses. There is almost no way to keep information secret in the modern world that does not use modular arithmetic in some way.
As an example, let’s look at how modular arithmetic is used in one of the first forms of cryptography: the Caesar cipher, otherwise known as a shift cipher!
- To set this up, take the alphabet and label each letter with the numbers , as shown at right. Also choose a secret key from the set of numbers ; for this problem, let’s pick our secret key to be .
-
Now, take the message you want to send: for example, let’s send the phrase .
-
Swap the letters for numbers, to get .
-
Take each number in your code and add our secret code to it: this gives us .
-
Now replace each number in our code with its value modulo 26; this gives us .
-
Translate this back to letters, to get the encrypted message . To an outsider, this would look like gibberish! In ancient Roman times, most people who would intercept such a message would assume that it was written in a foreign language and not be able to translate it.
-
But, if you knew the secret key, you could just translate this message back to numbers and subtract 15 from each letter modulo 26. This would give you the original message, as desired.
This specific cipher is easy to crack: a simple brute-force approach of trying all 26 keys one-by-one on the encrypted text would lead you to the right answer pretty quickly. (Try it out by hand or by writing a program; it’s not too bad.)
There are better ways to keep information secure, though! See courses like Compsci 110 and Maths 328 for some more modern approaches (that still use modular arithmetic at their core!)
% and Arithmetic
Question 1. What is ?
If you tried to use a computer to directly expand this problem, the size of the resulting number (approximately ) would take up terabytes, i.e. several orders of magnitude in excess of the current total storage capacity of humanity.
As of 2019, according to a variety of articles + some back-of-the-envelope estimation by the coursebook’s authors. By way of comparison, the total data storage of humanity was about terabytes in 2008. To put that figure in modern perspective: YouTube broadcasted more than this much data in the past six months.
And yet, if you pop over to WolframAlpha and ask it this question, you’ll get the following answer in about three seconds:
So: how is WolframAlpha able to calculate this so quickly, if the precise result is so staggeringly huge?
Partly, this is because the “powers-of-ten” approximation can be made by replacing the values here with just large powers of 10: i.e. things like can make approximating things a bit easier. However, WolframAlpha also seems to know the last few digits of this number, which seems a little bit spooky: how can you calculate this without understanding the entire number?
The trick here is the modulus operation, which we can use to perform certain arithmetic tasks very quickly. To show how this is possible, we introduce the closely related idea of congruency modulo :
The phrase ” is equivalent to modulo ” is also frequently used for this concept.
To get an idea for how this works, we calculate a number of examples here:
Example 1.9.
- ; this is because is a multiple of 8.
- ; this is because is a multiple of 8. Notice that it’s possible for a number to be congruent to many other possible values: i.e. 21 was congruent to both 5 and 13 modulo 8!
- ; this is because is a multiple of 2.
- ; this is because is not a multiple of 5.
- For any two integers , ; this is because is always a multiple of 1 (as any integer is a multiple of 1!)
- For any two integers , we have if and only if are both even or are both odd. This is because holds if and only if is a multiple of 2, i.e. is even, and this only happens when are the same parity: i.e. when they’re both even or both odd.
Congruency and our modulus operator are very closely linked:
- .
- is a multiple of ; i.e. .
In English/mathematics, we say that two statements are equivalent if they hold in precisely the same situations: i.e. whenever one is true, the other is true, and vice-versa. For example, the two statements ” is an even prime number” and ” ” are equivalent, as they both describe the same thing!
We reserve proving this claim for your practice problems at the end of this chapter (see exercise 7). Instead, let’s talk about how we can use this:
Then we have the following properties:
This claim is basically just saying that we can do “arithmetic modulo !” That is: for numbers , you know that if then and , by just combining these equalities with the addition and multiplication operations. This claim is saying that if your values are “equal modulo ,” the same tricks work!
We prove this claim here:
Proof.
We need to prove our claim in general here, as we’re making a claim about any possible set of values, not a specific set of values! To do so, we let be any set of integers such that and .
If we now use Claim 1.8, we get the following: is a multiple of , and is a multiple of . By definition, this means that we can write and for some pair of integers .
By adding these equations together, we get ; that is, that is a multiple of . This means that, by Definition 1.8, ! Applying Claim 1.8 gives us , as claimed.
If we take and multiply both sides by , we get ; similarly, if we take and multiply by we get . Adding these equations together gives us ; i.e. is a multiple of . This means that ! Again, applying Claim 1.8 then tells us that , as desired.
A quick corollary to Claim 1.9 is the following:
More English/mathematics word definitions! A corollary is a claim that follows quickly from the claim that just came before. That is, a corollary is a “consequence” of the earlier claim, or something that you get “for free” once you’ve proven some earlier result.
Corollary 1.1. If , then for any positive integer , we have .
(S1 2019 Test Q1) Suppose that is an integer such that . Which of the following facts must be true?
This is True. We have . By Claim 1.9 , we have . This tells us that when divided by 24 leaves a remainder of 14. Thus,
This is False. By Claim 1.7, the value of lies between and . That is, the output of must be an integer between and .
This is False. By Claim 1.7, the value of lies between and . That is, the output of must be an integer between and .
This is False. By Claim 1.7, the value of lies between and . That is, the output of must be an integer between and .
We leave proving this for Exercise 9; try proving this by using the multiplication property in Claim 1.9!
Instead of spending more time with this sort of abstract stuff, let’s do something practical: let’s talk about how we could solve our WolframAlpha problem! Specifically, let’s solve the following problem:
The last digit of is .
Proof.
The clever thing here is not that we can calculate this (again, if we just wanted an answer, we could plug this into WolframAlpha), but rather that we can calculate this easily! That is: we can use modular arithmetic to find this number without needing a calculator, with relatively little work overall.
To do so, just make the following observations:
-
First, , and in general any positive number is congruent to its last digit modulo 10. This is by definition: if you take any number greater than 10, subtracting 10 from it does not change its last digit! Therefore, the process we defined to calculate will never change the last digit of , and thus its output at the end is precisely ’s last digit.
-
Therefore, we have that , by using our “exponentiation” result from earlier.
-
Now, notice that , and thus that .
As a result, we have that for any ,
-
Therefore, because , and any multiple of 100 is a multiple of 4, we have that .
In other words, our number’s last digit is !
It’s worth noting that this trick isn’t just useful for humans, but for computers as well: you can use tricks like this to massively speed up calculations in which you only care about the number’s last few digits, and/or other pieces of partial information.
We can use this trick to basically calculate any number to any other number’s last digit! For example, the task of finding the last digit of
is now something we can do very quickly:
- Like before, we only care about the last digit of the thing we’re exponentiating: i.e. we can reduce this problem to just finding ’s last digit.
- ; therefore, for any even number , we have .
- Therefore, for any odd number , we have .
- So, because the last digit of our base is 9 and the exponent is odd, the last digit of our entire number is !
Generalizations of this process (i.e. working modulo 100 to find the last two digits, etc) can be used to quickly find the last few digits of any number. This can be quite useful when writing computer algorithms: most of the time when working with large numbers, you only need the first few and last digits for an approximation of its size, not the entire exact value!
Other Number Systems
In the past five sections, we’ve focused on studying the integers; i.e. whole numbers. However, there are lots of problems in real life whose answers cannot be given with just integers alone. Even going back to primary school, you’ve seen and solved problems like the following:
- Suppose that three hedgehogs come across two sausages while wandering through a backyard barbie, and want to share them equally. How many sausages should each hedgehog get?
- If you have one and a half pavlovas left over from the barbeque, and you eat a third of one for breakfast, how much pav do you have left?
Note: pavlovas are likely not part of a balanced breakfast.
- How many dollars are there in ten cents?
The answers to each of these are all relatively easy to calculate, and are tasks you’ve seen in school for years now! However, their solutions are not things that we can express as integers.
To work with them, we need some new sets of numbers! We start with one such set that you’re already familiar with:
Example 1.10 The numbers , and are all rational numbers. The numerator of is 3, and the denominator is 6; similarly, the numerator of is 0, and the denominator is 7.
Notice that every integer can be written as a rational number, because .
There are several operations we know how to perform on rational numbers:
Fact 1.1. If are a pair of rational numbers, then we can add and multiply them! Specifically, we say that
Notice that these are both still rational numbers, as their numerator and denominators are still integers, and the denominator is nonzero because .
With these operations in mind, we can answer our second exercise:
Answer to Exercise 1.2. In this problem, we’re asking if it is ever possible for to be equal to .
If you’re ever given a problem like this (i.e. someone hands you an equation and asks you “are there any solutions,”) the first thing you should try to do is solve the equation! That is: try to rearrange the equation for one of your variables in terms of the other and/or some constants, and hope that this tells you something.
In this situation, we know that and must be nonzero if the fractions are defined. Therefore, the numbers are rationals, and so their sum is just as noted above.
If , then because and are all nonzero, we can multiply both sides by the denominators (i.e. multiply both sides by .) Doing so will get rid of our fractions, as
|
This is a simpler equation! In particular, if we think of as our variable and as a constant, we have a quadratic equation. In general, a quadratic equation of the form has the two solutions when is nonnegative, and has no real-valued solutions if is negative.
In this situation, the quadratic formula above tells us that , and thus that our solutions (if they exist) would be . However, we know that is always a negative number; this is because is negative, while is a nonzero number squared (and thus is positive.) Therefore we have no solutions!
There are other number systems that you’ve likely seen before in high school as well:
- ,
- ,
- , and
So, for example, the real number contain all of the rational numbers, because you can do things like write
- ,
- , and
- .
However, there are also real numbers that are not rationals: i.e. there are quantities out there in the world that we cannot express as a ratio of integers! We call such numbers irrational.
It’s a bit beyond the skills we have at the moment, but numbers like
and
are both irrational numbers. Later on in this class, we’ll prove that is also an irrational number (check out the proof by contradiction section of this book if you cannot wait!)
With that said, though, it would be a bit of a shame to not show you at least one irrational number. So, let’s close this chapter by doing this!
Proof.
We prove this claim by using the “suppose we’re wrong” structure we’ve successfully used in Claims 1.6 and 1.3. That is: what would happen if was rational?
Well: we could write , for two integers . Note that because is positive (it’s greater than ), we can have .
Exponentiating both sides of this equation by 2 gives us . By definition, and cancel each other out, so this simplifies to .
Now, raising both sides to the -th power gives us . By using our known rules for exponentiation, this simplifies to .
On the left-hand-side, we have an odd number: it’s just copies of multiplied together! On the right-hand-side, however, we have an even number: it’s copies of 2 multiplied together.
These two values cannot be equal! In other words, our initial assumption that we could write must have been flawed, as this assumption would imply that a number can be even and odd at the same time. Therefore is irrational, as desired.
(SS 2020 Test Q3) Which of the following statements is FALSE?
The sum of two irrational numbers is always an irration number.
This is a true statement. Use definitions of rational numbers to prove the claim.
This is False. Take and . They are both irrational numbers but adding them you get 0, which is rational.
If and are rational numbers then is also a rational number.
There exists irrational numbers and such that is a rational number.
This is True. Take and . They are both irrational numbers but , which is rational.
There exists two irrational numbers and such that is a rational number.
This is True. Take and . They are both irrational numbers but , which is a rational number
We close this chapter with some exercises for you to try out. Give these an attempt, and post your answers / attempts on Piazza!
Practice Problems
- (-) Let be even. Show that is also even.
- Show that if and are both odd, then is also odd.
- (+) Show that if is an even number and is a positive integer, then is even.
- In Claim 1.3, we showed that no number is both even and odd at the same time. Prove the converse of this claim: that is, prove that every integer is either even or odd (i.e. you can’t have an integer that is both not even and not odd.)
- (-) Write down all of the numbers between 1 and 100 that are congruent to 2 modulo 12.
- How many numbers between 1 and 1000 are congruent to 0 modulo 3? How many are congruent to 0 modulo 4? Can you make a formula to count how many numbers between 1 and 1000 are congruent to 0 modulo , that works for any positive integer ?
- (+) Prove Claim 1.11.
- Take any three-digit number (where is the ones digit, is the tens digit, and is the hundreds digit.) Show that is never a prime number.
- Prove Corollary 1.1.
- (+) Suppose that are all prime numbers. Must the number be prime? Either explain why, or find a set of prime numbers such that the value defined above is not prime.
- (-) Show that is always even, for any integer .
- Show that if is an odd number, then is a multiple of 8.
- Find the last digit of without using a computer or calculator.
- (+) Find the last digit of without using a computer or calculator.
- (+) What is the longest English word that can be shift-ciphered into another English word?
- (++) Take an integer . If it’s odd, replace it with ; if it’s even, replace it with . Repeat this until the number is equal to 1. Will this process always eventually stop?
(from https://xkcd.com/710/)
- Consider the following claim: “Let be a pair of rational numbers. Suppose that . Then we have .” Is this claim true? If it is, explain why. If it is not, find a pair of fractions that demonstrate that this claim is false.
- If is rational and is irrational, must be irrational? Either explain why or find a counterexample (i.e. find a pair of numbers such that is rational, is irrational, and is rational.)
- If and are both irrational numbers, must be irrational? Either explain why or find a counterexample (i.e. find a pair of numbers such that are irrational, but is rational.)
- (+) Show that if are all odd integers, then there is no rational number such that the equation holds.
- (++) Is irrational?