Mathematics for Computer Scientists

Similar documents
MODULAR ARITHMETIC I

To Infinity and Beyond

Math 31 Lesson Plan. Day 2: Sets; Binary Operations. Elizabeth Gillaspy. September 23, 2011

MATH 2200 Final Review

128. The integers 1 to 1000 are written in order around a circle. Starting at 1, every fifteenth number is marked (that is, 1, 16, 31, etc.).

Chapter 2 - Relations

Name (please print) Mathematics Final Examination December 14, 2005 I. (4)

Ch1 Algebra and functions. Ch 2 Sine and Cosine rule. Ch 10 Integration. Ch 9. Ch 3 Exponentials and Logarithms. Trigonometric.

STEP Support Programme. Hints and Partial Solutions for Assignment 17

Contribution of Problems

PART ONE. Once upon a time there was a very special baby. who grew up to be very wise. and to tell us how to be kind. His name was Jesus.

1. Prove that the number cannot be represented as a 2 +3b 2 for any integers a and b. (Hint: Consider the remainder mod 3).

Do not turn over until you are told to do so by the Invigilator.

2 Arithmetic. 2.1 Greatest common divisors. This chapter is about properties of the integers Z = {..., 2, 1, 0, 1, 2,...}.

Linear Diophantine Equations

Error Correcting Codes Prof. Dr. P. Vijay Kumar Department of Electrical Communication Engineering Indian Institute of Science, Bangalore

Basic counting techniques. Periklis A. Papakonstantinou Rutgers Business School

Chapter 1 : The language of mathematics.

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

To Infinity and Beyond. To Infinity and Beyond 1/43

CS 124 Math Review Section January 29, 2018

Finite and infinite sets, and cardinality

Mathematics of Cryptography

AS1051: Mathematics. 0. Introduction

We introduce one more operation on sets, perhaps the most important

CIRCLES AND TABLES AND SLEEPING

MATHEMATICAL INDUCTION

Number Theory, Algebra and Analysis. William Yslas Vélez Department of Mathematics University of Arizona

The Chinese Remainder Theorem

MACMILLAN READERS ELEMENTARY LEVEL BRAM STOKER. Tales of Horror. Retold by John Davey MACMILLAN

Discrete Mathematics and Probability Theory Summer 2017 Course Notes Note 6

Math 138: Introduction to solving systems of equations with matrices. The Concept of Balance for Systems of Equations

CHMC: Finite Fields 9/23/17

MATH 115, SUMMER 2012 LECTURE 4 THURSDAY, JUNE 21ST

CSE 20 DISCRETE MATH WINTER

Q: How can quantum computers break ecryption?

21-110: Problem Solving in Recreational Mathematics Homework assignment 3 solutions

Modern Algebra Prof. Manindra Agrawal Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Review Sheet for the Final Exam of MATH Fall 2009

Examples of Finite Sequences (finite terms) Examples of Infinite Sequences (infinite terms)

Number Theory. Modular Arithmetic

My Favorite Problems HAROLD B. REITER. Mu Alpha Theta Annual Convention Denver, Colorado. Visit my website:

Part IA Numbers and Sets

An Introduction to Mathematical Thinking: Algebra and Number Systems. William J. Gilbert and Scott A. Vanstone, Prentice Hall, 2005

Definition For a set F, a polynomial over F with variable x is of the form

One-to-one functions and onto functions

Q 2.0.2: If it s 5:30pm now, what time will it be in 4753 hours? Q 2.0.3: Today is Wednesday. What day of the week will it be in one year from today?

AN ALGEBRA PRIMER WITH A VIEW TOWARD CURVES OVER FINITE FIELDS

MA554 Assessment 1 Cosets and Lagrange s theorem

MA 1125 Lecture 15 - The Standard Normal Distribution. Friday, October 6, Objectives: Introduce the standard normal distribution and table.

Chapter 1 Review of Equations and Inequalities

Continuing discussion of CRC s, especially looking at two-bit errors

Introducing Proof 1. hsn.uk.net. Contents

Part IA Numbers and Sets

AQA Level 2 Further mathematics Further algebra. Section 4: Proof and sequences

6: Polynomials and Polynomial Functions

Math 31 Lesson Plan. Day 5: Intro to Groups. Elizabeth Gillaspy. September 28, 2011

Cosets and Lagrange s theorem

8 Primes and Modular Arithmetic

MAT115A-21 COMPLETE LECTURE NOTES

Day 15. Tuesday June 12, 2012

MAS114: Exercises. October 26, 2018

1 Modular Arithmetic Grade Level/Prerequisites: Time: Materials: Preparation: Objectives: Navajo Nation Math Circle Connection

Egyptian Fractions: Part I

C.T.Chong National University of Singapore

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 3

This is a recursive algorithm. The procedure is guaranteed to terminate, since the second argument decreases each time.

Introduction to Proofs

CONTENTS. 6 Two Promises Miranda and Ferdinand plan to marry. Caliban 36 gets Stephano and Trinculo to promise to kill Prospero.

After that, we will introduce more ideas from Chapter 5: Number Theory. Your quiz in recitation tomorrow will involve writing proofs like those.

Discrete Mathematics for CS Spring 2007 Luca Trevisan Lecture 27

CHAPTER 1. REVIEW: NUMBERS

Discrete Mathematics and Probability Theory Fall 2018 Alistair Sinclair and Yun Song Note 6

Complex Numbers: A Brief Introduction. By: Neal Dempsey. History of Mathematics. Prof. Jennifer McCarthy. July 16, 2010

Discrete Mathematics and Probability Theory Summer 2014 James Cook Note 5

An Introduction to Proof-based Mathematics Harvard/MIT ESP: Summer HSSP Isabel Vogt

Unit 2: Polynomials Guided Notes

PENGUIN READERS. Five Famous Fairy Tales

Error Correcting Codes Prof. Dr. P Vijay Kumar Department of Electrical Communication Engineering Indian Institute of Science, Bangalore

Egyptian Fractions: Part I

Grade 7/8 Math Circles. Mathematical Thinking

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

Clock Arithmetic and Euclid s Algorithm

No Solution Equations Let s look at the following equation: 2 +3=2 +7

(x 1 +x 2 )(x 1 x 2 )+(x 2 +x 3 )(x 2 x 3 )+(x 3 +x 1 )(x 3 x 1 ).

UMASS AMHERST MATH 300 SP 05, F. HAJIR HOMEWORK 8: (EQUIVALENCE) RELATIONS AND PARTITIONS

MINKOWSKIAN SPACE, GRAPHS, EVENTS, WORLD LINES and MEASURING TIME

The PROMYS Math Circle Problem of the Week #3 February 3, 2017

MATH 2200 Final LC Review

Lecture Notes. Advanced Discrete Structures COT S

The solutions to the two examples above are the same.

11 Division Mod n, Linear Integer Equations, Random Numbers, The Fundamental Theorem of Arithmetic

Introduction to Algebra: The First Week

What is proof? Lesson 1

MITOCW ocw f99-lec23_300k

5. Sequences & Recursion

* 8 Groups, with Appendix containing Rings and Fields.

What s the Average? Stu Schwartz

Lecture 4: Constructing the Integers, Rationals and Reals

Discrete Mathematics. W. Ethan Duckworth. Fall 2017, Loyola University Maryland

Transcription:

Mathematics for Computer Scientists Lecture notes for the module G51MCS Venanzio Capretta University of Nottingham School of Computer Science

Chapter 6 Modular Arithmetic 6.1 Pascal s Triangle One easy way to compute the binomial coefficients is by building Pascal s triangle. It is a triangular table containing in row n the values of ( n k) for all possible values of k: n 0 1 1 1 1 2 1 2 1 3 1 3 3 1 4 1 4 6 4 1 5 1 5 10 10 5 1 So for example ( 4 3) is the fourth element for the line for 4 (because the first element is ( 4 0) ), that is, 4. There is an easy recursive way of computing the triangle, based on the following fact. Theorem 17 For every natural number n and every natural number k such that 0 < k < n, we have that: ( ) ( ) ( ) n n 1 n 1 + k k k 1 Proof. We can prove this theorem in two ways: by using the definition of binomial coefficient or by using the formula to compute it with factorials. Let s look at both proofs. Proof 1: Remember that ( n k) is the number of subsets of size k in a set of size n, for example in Z n. Now let s divide these subsets in two groups: those that contain n 1 and those that don t. The ones that don t contain n 1 are subsets of size k of Z n 1 and we know that there are ( ) n 1 k ways of choosing them. The ones that contain n 1 will also have to contain k 1 elements of Z n 1 ; we know that there are ( n 1 k 1) ways of selecting the latter. Putting the 78

two groups together, we know that we have ( ) ( n 1 k + n 1 k 1) ways of selecting our subset, as the formula says. Proof 2: Let s write out both sides of the equality in terms of factorials and verify that they are the same. ( ) n n! k (n k)! k! ( n 1 k ) + ( ) n 1 k 1 (n 1)! ((n 1) k)! k! + (n 1)! ((n 1) (k 1))! (k 1)! (n 1)! (n k 1)! k! + (n 1)! (n k)! (k 1)! (n k) (n 1)!+k (n 1)! (n k)! k! (n k +k) (n 1)! (n k)! k! n! (n k)! k! Since we obtained the same result from both expressions, the equality must be true. The theorem allows us to give a recursive way to compute binomial coefficients; we use as base cases the fact that there is only one subset with zero elements, the empty set, and only one subset with n elements, the whole set. Recursive computation of binomial coefficients: ( ) n 1 0 ( ) n 1 n ( ) ( ) ( ) n n 1 n 1 + if 0 < k < n. k k k 1 Pascal s triangle is constructed using this recursive definition. The sides of the triangle correspond to the base cases and are always 1. The internal values are obtained by adding the two values that are immediately above and to the left and right of the one we want to compute. So, for example, line number 6 is: 1 6 15 20 15 6 1. 6.2 Hilbert s Hotel One of the consequences of the pigeonhole principle was that for a function f : Z n Z n, injectivity is equivalent to surjectivity and, therefore, to bijectivity. 79

This is not true for infinite sets. In fact, a set X is infinite exactly when there is a function f : X X that is injective but not surjective. For example, for the natural numbers N, we can show these two functions: f : N N f(n) n+1 injective but not surjective; g : N N g(n) quot(n, 2) surjective but not injective. The property of infinite sets of allowing injective but not surjective functions to themselves (which can be taken as the definition of infinity) is exploited in a whimsical tale about the Hilbert s Hotel. The hotel happens to have an infinite number of rooms, numbered 0, 1, 2, etc. There s a room for every natural number. At present the hotel is completely booked. In the middle of the night a traveller comes to the reception and asks for accommodation. The hotel owner, Mr. Hilbert, tells him that, although at the moment all rooms are occupied, he can find a place for the new customer. (In reality, David Hilbert was a German mathematician who, around 1900, worked on the foundations of mathematics and the problems of the infinite.) Hilbert asks the tenant of room 0, let s call him Tenant 0, to move to room 1; he asks Tenant 1 to move to room 2; Tenant 2 to move to room 3 and so on. In this way every tenant is moved to a new room and room 0 is left free for the newcomer. You see that what Hilbert did is to apply the function f(x) x+1 to the tenants to determine what room to put them in. Since the function is injective, no two people are sent to the same room; and since it is not surjective, a new room is magically freed. The properties of Hilbert s Hotel are even more astonishing. Some time later an infinite bus stops in front of the hotel. It contains an infinite number of travellers, let s call them Newcomer 0, Newcomer 1, Newcomer 2 and so on. They ask Mr. Hilbert to find them a place to stay. Again, Hilbert is unfazed: now he asks Tenant 1 to move to room 2, Tenant 2 to move to room 4, Tenant 3 to mover to room 6, and so on, Tenant n moves to room 2 n. In this way, an infinite number of rooms becomes available: Newcomer 0 is accommodated in room 1, Newcomer 1 in room 3, Newcomer 2 in room 5 and so on, Newcomer m is accommodated in room 2 m+1. 6.3 Modular Arithmetic The operations of addition and multiplication can be extended to the sets Z n by wrapping the result around, that is, by taking the remainder of the result after division by n. If two natural numbers a and b have the same remainder when they are divided by n then we say that they are equivalent modulo n and we write: a b (mod n). 80

By definition this mean that we can write both a and b as: a q 1 n+r b q 2 n+r with 0 r < n. The remainder r is an element of Z n. If we are in a context in which it is clear that we are talking exclusively about elements of Z n, then we could consider also a and b as different ways of writing r. We are all familiar with this way of seeing numbers: on a clock dial the hours 1 and 13 are represented by the same mark: The clock actually represent the set Z 12. We can perform addition on its elements: if two friends meet at 7 and agree to meet again 10 hours later, we know that the appointment is for 5 o clock. This operation is performed by adding the numbers, 7+10 17, and then taking the remainder of the division by 12, obtaining 5. (To be realistic we should distinguish between AM and PM, or use a clock with 24 hours instead, working in Z 24.) Imagine a planet that rotates around its axis in 26 hours. The inhabitants of that planet may have watches looking a bit like this: The times on the planet are given as elements of Z 26 (at least as long as we are happy with the hours and don t care about minutes and seconds). The number 81

29, for example, is considered just a different way of writing 3. The negative number 2 is a different way of writing 24. We denote by the symbols and the operations of addition and multiplication in Z 26. Remember that they are just the ordinary addition and multiplication, but taking the remainder of the division by 26 at the end. For example: 9 13 22 (in Z 26 ) 14 15 3 (in Z 26 ) 8 18 0 (in Z 26 ) 6 3 18 (in Z 26 ) 6 4 24 (in Z 26 ) 6 5 4 (in Z 26 ) 2 13 0 (in Z 26 ) It is important that we always specify clearly that we are working on a specific set Z n, since the operations will generally have different results for different values of n. For example, if we take n 19 the operations above give: 9 13 3 (in Z 19 ) 14 15 10 (in Z 19 ) 8 18 7 (in Z 19 ) 6 3 18 (in Z 19 ) 6 4 5 (in Z 19 ) 6 5 11 (in Z 19 ) 2 13 7 (in Z 19 ) It is more common to use the normal symbols + and for addition and multiplication in Z n, but always remember to specify that they must be computed modulo n. Modular Arithmetic satisfies most of the same properties as Arithmetic on the natural numbers and integers. But it has some surprising idiosyncrasies. Firsofall, theremay bezero divisors. Thesearenumbersxandy, bothdifferent from zero, but whose product x y give zero. We have seen an example above: 2 13 0 (in Z 26 ). This happens if n is a composite number: in our case it happens because 26 2 13. It never happens if n is a prime number. But in that case something even more interesting occurs: every non-zero number has a multiplicative inverse: Theorem 18 If p is a prime number, then for every element x Z p, if x 0 then there exists an element x 1 Z p such that x x 1 1. For example, in Z 7 we have that 5 1 3 because 5 3 1 (in Z 7 ). You may verify for yourself that the inverses of all non-zero elements of Z 7 are the following: 1 1 1, 2 1 4, 3 1 5, 4 1 2, 5 1 3, 6 1 6. 82

6.4 The Monkey and the Coconuts On the first lecture I proposed the following puzzle: Five men and a monkey were shipwrecked on a desert island, and they spent the first day gathering coconuts for food. They piled them all up together and then went to sleep for the night. But when they were all asleep one man woke up and decided to take his share. He divided the coconuts in five piles. He had one coconut left and he gave it to the monkey. He took his pile and put the rest all back together. Later a second man woke up and acted in exactly the same way: He divided the coconuts into five piles; there was one coconut left that he tossed to the monkey; he took his pile and put the rest all back together. One after the other all five men do the same thing and every time there is one extra coconut that is given to the monkey. The next morning they divided what coconuts were left into five parts. Once again there was one coconut left that was given to the monkey. How many coconuts were there at the beginning? If we call N the total number of coconuts at the beginning, we know that N must give remainder 1 when divided by 5: N 5 A+1 for some natural number A. The first man gives one coconut to the monkey and takes one fifth of the rest for himself. The number of the remaining coconuts is 4 A. When the second man comes, he starts with 4 A coconuts and proceed in the same way, so: 4 A 5 B +1 for some natural number B. He gives one coconut to the monkey and takes one fifth of the rest for himself: the remaining coconuts are 4 B. The same process is repeated by every man, so we have five similar steps: N 5 A+1 for some natural number A 4 A 5 B +1 for some natural number B 4 B 5 C +1 for some natural number C 4 C 5 D +1 for some natural number D 4 D 5 E +1 for some natural number E At the end of the night 4 E coconuts are left. The next morning they still give one coconut to the monkey and then divide the remaining in five equal parts: 4 E 5 F +1 for some natural number F. 83

To solve the puzzle we must find numbers N,A,B,C,D,E,F that satisfy these equation. Using some algebraic manipulation, we can reduce the six equations to a relation between the initial number N and the final share F: 1024 N 15625 F +11529. We must solve it by finding two natural numbers N and F satisfying this equation. It is not easy to find the solution without trying all the possible values. One way to solve the puzzle is, first of all, to notice that there are many, in fact infinite, different solutions. Suppose we have one solution, call it N 0. Since we divided the number of coconuts by 5 six times, it is easy to see that also N 0 + 5 6 must be a solution (try so substitute it for N in the equations, using the fact that N 0 already satisfies them). But if we can obtain one solution by adding 5 6 to one that is already known, then we could also look at negative solutions, as long as they are still larger than 5 6. In particular we may notice that if we take N 0 4 we have that we can solve the first equation by taking A 0 1: 4 5 ( 1)+1. That would give that the number of coconuts left by the first man is 4 ( 1) 4, that is, equal to the initial number. This, of course, doesn t make any sense in the real situation, since talking of negative coconuts is meaningless. But as a solution to the equations it is correct. The second equation can be solved in exactly the same way, since we have the same number 4 on its left. Indeed, by taking N 0 4 all six equations are solved in the same way. So 4 is a solution, but not a realistic one. However, as we said earlier, when we have a solution we can get another one by adding 5 6 to it, therefore the number 4+5 6 4+15625 15621 and this number is the solution we are looking for. 84