Arithmetic and Algebra

Similar documents
Mathematics of Cryptography

Intermediate Math Circles February 29, 2012 Linear Diophantine Equations I

Intermediate Math Circles February 26, 2014 Diophantine Equations I

Discrete Structures Lecture Solving Congruences. mathematician of the eighteenth century). Also, the equation gggggg(aa, bb) =

COMP239: Mathematics for Computer Science II. Prof. Chadi Assi EV7.635

C-N Math 207 Discrete Math

C-N Math 207 Discrete Math

Math Circle Beginners Group February 28, 2016 Euclid and Prime Numbers Solutions

Math From Scratch Lesson 20: The Chinese Remainder Theorem

The Chinese Remainder Theorem

Lecture Notes. Advanced Discrete Structures COT S

The Euclidean Algorithm and Multiplicative Inverses

CPSC 467b: Cryptography and Computer Security

Math Circle Beginners Group February 28, 2016 Euclid and Prime Numbers

Math 131 notes. Jason Riedy. 6 October, Linear Diophantine equations : Likely delayed 6

Number Theory Proof Portfolio

MTH 346: The Chinese Remainder Theorem

Basic elements of number theory

Basic elements of number theory

8 Primes and Modular Arithmetic

Elementary Algebra Chinese Remainder Theorem Euclidean Algorithm

Algebra. Modular arithmetic can be handled mathematically by introducing a congruence relation on the integers described in the above example.

CHAPTER 3. Congruences. Congruence: definitions and properties

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?

Discrete Mathematics and Probability Theory Fall 2014 Anant Sahai Homework 5. This homework is due October 6, 2014, at 12:00 noon.

Math Circles - Lesson 2 Linear Diophantine Equations cont.

Chapter 4 Finite Fields

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

Arithmetic Algorithms, Part 1

Direct Proof MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Direct Proof Fall / 24

MATH 2112/CSCI 2112, Discrete Structures I Winter 2007 Toby Kenney Homework Sheet 5 Hints & Model Solutions

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?

4 Powers of an Element; Cyclic Groups

4 Number Theory and Cryptography

Lecture 7: Number Theory Steven Skiena. skiena

3 The fundamentals: Algorithms, the integers, and matrices

Chapter 2. Divisibility. 2.1 Common Divisors

Number Theory Notes Spring 2011

a the relation arb is defined if and only if = 2 k, k

Applied Cryptography and Computer Security CSE 664 Spring 2017

Lecture 2. The Euclidean Algorithm and Numbers in Other Bases

Primes and Modular Arithmetic! CSCI 2824, Fall 2014!!

MATH 433 Applied Algebra Lecture 4: Modular arithmetic (continued). Linear congruences.

Discrete Mathematics GCD, LCM, RSA Algorithm

Remainders. We learned how to multiply and divide in elementary

Deepening Mathematics Instruction for Secondary Teachers: Algebraic Structures

Elementary Number Theory Review. Franz Luef

Modular Arithmetic Instructor: Marizza Bailey Name:

Number Theory and Group Theoryfor Public-Key Cryptography

Integers and Division

cse 311: foundations of computing Spring 2015 Lecture 12: Primes, GCD, applications

Clock Arithmetic and Euclid s Algorithm

Preliminaries and Complexity Theory

Algorithms (II) Yu Yu. Shanghai Jiaotong University

Notes on Systems of Linear Congruences

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

2.3 In modular arithmetic, all arithmetic operations are performed modulo some integer.

INTEGERS. In this section we aim to show the following: Goal. Every natural number can be written uniquely as a product of primes.

EUCLID S ALGORITHM AND THE FUNDAMENTAL THEOREM OF ARITHMETIC after N. Vasiliev and V. Gutenmacher (Kvant, 1972)

CS 5319 Advanced Discrete Structure. Lecture 9: Introduction to Number Theory II

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

Rings and modular arithmetic

5: The Integers (An introduction to Number Theory)

Finite Fields. Mike Reiter

Algorithms CMSC Basic algorithms in Number Theory: Euclid s algorithm and multiplicative inverse

Math 312/ AMS 351 (Fall 17) Sample Questions for Final

MATH 145 Algebra, Solutions to Assignment 4

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?

Practical assessment week 5 and 6

CSE 311: Foundations of Computing. Lecture 12: Two s Complement, Primes, GCD

1 Overview and revision

CMPUT 403: Number Theory

cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications

Number Theory Basics Z = {..., 2, 1, 0, 1, 2,...} For, b Z, we say that divides b if z = b for some. Notation: b Fact: for all, b, c Z:

8. Given a rational number r, prove that there exist coprime integers p and q, with q 0, so that r = p q. . For all n N, f n = an b n 2

A STUDY ON THE CONCEPT OF DIOPHANTINE EQUATIONS

Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry. Spring 2006

Exercises Exercises. 2. Determine whether each of these integers is prime. a) 21. b) 29. c) 71. d) 97. e) 111. f) 143. a) 19. b) 27. c) 93.

Know the Well-ordering principle: Any set of positive integers which has at least one element contains a smallest element.

Airo International Research Journal September, 2016 Volume VII, ISSN:

4.4 Solving Congruences using Inverses

1. Given the public RSA encryption key (e, n) = (5, 35), find the corresponding decryption key (d, n).

Proofs. Methods of Proof Divisibility Floor and Ceiling Contradiction & Contrapositive Euclidean Algorithm. Reading (Epp s textbook)

Lecture 7 Number Theory Euiseong Seo

Lecture 4: Number theory

CPSC 467: Cryptography and Computer Security

Chapter 1. Greatest common divisor. 1.1 The division theorem. In the beginning, there are the natural numbers 0, 1, 2, 3, 4,...,

Elementary Number Theory II

Numbers. Çetin Kaya Koç Winter / 18

Simultaneous Linear, and Non-linear Congruences

ALGEBRA+NUMBER THEORY +COMBINATORICS

ECEN 5022 Cryptography

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

Divisibility. Chapter Divisors and Residues

MATH 361: NUMBER THEORY FOURTH LECTURE

MATH 3240Q Introduction to Number Theory Homework 4

Homework #2 solutions Due: June 15, 2012

The next sequence of lectures in on the topic of Arithmetic Algorithms. We shall build up to an understanding of the RSA public-key cryptosystem.

Elementary Number Theory MARUCO. Summer, 2018

Math 110 FOUNDATIONS OF THE REAL NUMBER SYSTEM FOR ELEMENTARY AND MIDDLE SCHOOL TEACHERS

Transcription:

Arithmetic and Algebra Daniel Butnaru daniel.butnaru@uni-konstanz.de 15. Dezember 2006 Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 1/39

Outline 1 Introduction 2 Big Number Arithmetic 3 Modular Arithmetic 4 Linear Diophantine Equations 5 Gaussian Elimination Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 2/39

Outline 1 Introduction 2 Big Number Arithmetic 3 Modular Arithmetic 4 Linear Diophantine Equations 5 Gaussian Elimination Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 3/39

Definitions Arithmetic The mathematics of integers, rational numbers, real numbers, or complex numbers under addition, subtraction, multiplication, and division. Algebra A branch of mathematics in which symbols, usually letters of the alphabet, represent numbers or members of a specified set and are used to represent quantities and to express general relationships that hold for all members of the set. Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 4/39

Outline 1 Introduction 2 Big Number Arithmetic 3 Modular Arithmetic 4 Linear Diophantine Equations 5 Gaussian Elimination Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 5/39

Working with big numbers in computers Can be done by stringing digits together: Arrays of Digits the initial element of the array represents the least significant digit a counter with the length of the number in digits can aid efficiency Linked Lists of Digits necessary if we are really going to do arbitrary precision arithmetic Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 6/39

Example #define MAXDIGITS 100 #define PLUS 1 #define MINUS -1 typedef struct { char digits[maxdigits]; int signbit; int lastdigit; } bignum; Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 7/39

Example add_bignum(bignum *a, bignum *b, bignum *c) { int cr; int i; initialize_bignum(c); c->lastdigit = max(a->lastdigit,b->lastdigit)+1; cr = 0; for (i=0; i<=(c->lastdigit); i++) { c->digits[i] = (char) (cr + a->digits[i] + b->digits[i]) % 10; cr = (cr + a->digits[i] + b->digits[i]) / 10; } Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 8/39

Outline 1 Introduction 2 Big Number Arithmetic 3 Modular Arithmetic 4 Linear Diophantine Equations 5 Gaussian Elimination Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 9/39

Basics(1) a divides b when the equation b = k a with k Z is satisfied A number k which is divided only by 1 and itself is a prime number. Examples : 2, 3,5,7, 11... For a number a and some other number b there is exactly one q and one r with 0 r < n so that a = q b + r Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 10/39

Basics(2) A number k is called a common divisor for a and b if k a and k b. Among all the common divisors the biggest is called the greatest common divisor (GCD). Two numbers are relative prime if their greatest common divisor is 1. Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 11/39

Finding the GCD Euclid s Algorithm calculate gcd(a, b) after the division theorem we know a = q b + r 0 based on observing that gcd(a, b) = gcd(b, r 0 ) continue to apply the algorithm on (r k, r k+1 ) stop when the last remainder is 0 the gcd is the last non-zero remainder 1 a = q b + r 0 with 0 r 0 < b 2 b = q r 0 + r 1 with 0 r 1 < r 0 3 r 0 = q r 1 + r 2 with 0 r 2 < r 1 Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 12/39

GCD(12, 5) Example 1 12 = 2 5 + 2 with 0 2 < 5 2 5 = 2 2 + 1 with 0 1 < 2 3 2 = 2 1 + 0 with 0 0 < 1 Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 13/39

Euclid s Algorithm Recursive gcd(a, b) if b = 0 return a else return gcd(b, a mod b) Iterative gcd(a, b) while b!= 0 c := b b := a mod b a := c return a Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 14/39

Side Effects Bezout s Lemma Find k and l so that gcd(a, b) = a k + b l r 0 = a q 0 b r 1 = b q 1 r 0 r 2 = r 0 q 2 r 1 r 1 = b q 1 (a q 0 b) = k 1 a + l 1 b r 2 = (a q 0 b) q 2 (k 1 a + l 1 b) = k 2 a + l 2 b r 3 = (k 1 a + l 1 b) q 2 (k 2 a + l 2 b) = k 3 a + l 3 b Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 15/39

Bezut s Lemma Example 1 9 = 1 6 + 3 3 = 1 9 1 6 2 6 = 2 3 + 0 0 = 6 2 3 therefore, gcd(9, 6) = 9 1 6 1 Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 16/39

Chinese Remainder Theorem We have a number n. Repeatedly divided by 3, the remainder is 2; by 5 the remainder is 3; and by 7 the remainder is 2. What number is n? Sun Tsu Suan-Ching (4th century AD) Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 17/39

Chinese Remainder Theorem Formal Given a set of congruences: x a i m i for i = 1,....r and for which the m i are pairwise relatively prime, the solution of the set of congruences is: x = a 1 b 1 M m 1 + + a r b r M m r Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 18/39

Chinese Remainder Theorem Formal Where, M = m 1 m 2 m r and the b i s can be obtained from solving the linear congruence equations: b i M m i 1 m i Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 19/39

Problem An old woman goes to market and a horse steps on her basket and crashes the eggs. The rider offers to pay for the damages and asks her how many eggs she had brought to sell. She does not remember the exact number, but when she had taken them out two at a time or 3 at a time, there was one egg left but when she took seven at a time they came out even. What is the smallest number of eggs she could have had? 1 x = 1 mod 2 2 x = 1 mod 3 3 x = 0 mod 7 Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 20/39

Solution M = 2 3 7 = 42. Using the extended Euclid algorithm we can find solutions for the linear congruence equations: b 1 21 = 1 2 b 2 14 = 1 3 b 3 6 = 1 7 The/Some b i s that satisfy the above conditions are 1, 2 and -1. x = 1 1 21 + 1 2 14 + 0 1 21 = 49(eggs) Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 21/39

Outline 1 Introduction 2 Big Number Arithmetic 3 Modular Arithmetic 4 Linear Diophantine Equations 5 Gaussian Elimination Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 22/39

Linear Diophantine Equations Diophantus of Alexandria Hellenistic mathematician of the 3rd century AD, was one of the first mathematicians to introduce symbolism into algebra A Diophantine equation is an indeterminate polynomial equation that only allows the variables to be integers. with a i Z, b Z. a 1 x 1 + a 2 x 2 + + a n x n = b Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 23/39

Solving the Equations Condition A diophantine equation has a solution only when the greatest common divisor of all the a i s a divisor of b is and not all the a i are 0. Solution gcd(a 1, a 2,..., a n ) b with a i Z, b Z and (a 1, a 2,..., a n ) (0, 0,..., 0). Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 24/39

n = 2 Example Solve 114 x + 315 y = 6 with gcd(a 1, a 2 ) = 3 6 (solvable). 1 Divide the equation by 3. We get: 38 x + 105 y = 2 2 Use the extended Euclid algorithm to get the linear representation of 1 as a combination of 38 and 105: 47 38 17 105 = 1 3 The special solution is (47 2, 17 2) = (94, -34) 4 Set of all the solutions: {(94 + t 105, 34 t 38) t Z} Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 25/39

Solution for n = 2 Start from a 1 x 1 + a 2 x 2 = b with gcd(a 1, a 2 ) b and (a 1, a 2 ) (0, 0) 1 Divide the equation by gcd(a 1, a 2 ). We get a 1 x 1 + a 2 x 2 = b with gcd(a 1, a 2) = 1 2 Use the extended Euclid algorithm to get the linear representation of 1 as a combination of a 1 and a 2 : c 1 a 1 + c 2 a 2 = 1 3 a special solution for the diophantine equation is now (c 1 b, c 2 b) 4 The set of all the solutions can be obtained starting from our special solution: {(c 1 + t a 2, c 2 t a 1) t Z} Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 26/39

Solution for n > 2 Start from a 1 x 1 + a 2 x 2 + + a n x n = b with a i Z, b Z, (a 1, a 2,..., a n ) (0, 0,..., 0), gcd(a 1, a 2,..., a n ) = 1. 1 Rewrite the equation as follows: a 1 x 1 + a 2 x 2 + + a n 1 x n 1 = b a n x n 2 Consider x n constant. We have a diophantine equation with n 1 variables now. This has a solution only if: gcd(a 1, a 2,..., a n 1 ) (b a n x n ) 3 This is true only when there are c and c n so that: gcd(a 1, a 2,..., a n 1 ) c + a n c n = b 4 We solve this diophantine equation with two variables and we are down to n 1 variables in the initial equation. Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 27/39

n > 2 Example Solve 2 x + 4 y + 3 z = 3 with gcd(2, 3, 4) = 1 3 (solvable) 1 Rewrite the equation as follows: 2 x + 4 y = 3 3 z 2 This new diophantine equation with two variables is solvable only if gcd(2, 4) (3 3 z). By solving it we get the solution set: {( 3 + t 3, 3 t 2) t Z} 3 This gives us z = 3 t 2. After inserting this in the initial equation we are down to solving: 2 x + 4 y = 3 3 (3 2 t) x + 2 y = 3 + 3 t Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 28/39

n > 2 Example Solve x + 2 y = 3 + 3 t with gcd(1, 2) = 1 ( 3 + 3 t) (solvable) 1 The extended Euclid algorithm gives us ( 1) 1 + 1 2 = 1 and so: (3 3 t) 1 + ( 3 + 3t) 2 = 3 + 3 t 2 The solution set to this equation is: {((3 3 t) + s 2, ( 3 + 3t) s 1) s Z} 3 The final solution set: {((3 3 t) + s 2, ( 3 + 3t) s 1, 3 t 2) s, t Z} Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 29/39

Outline 1 Introduction 2 Big Number Arithmetic 3 Modular Arithmetic 4 Linear Diophantine Equations 5 Gaussian Elimination Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 30/39

Process Description Calculates solutions for linear equation systems Uses a matrix representation of the system Four elementary operations on the matrix a 11 x 1 + a 12 x 2 + + a 1n x n = b 1 a 21 x 1 + a 12 x 2 + + a 2n x n = b 2... a n1 x 1 + a n2 x 2 + + a nn x n = b n Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 31/39

Process Matrix Representation a 11 a 12... a 1n x 1 b 1 a 11 a 12... a 1n x 2...... = b 2... a 11 a 12... a 1n x n b n Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 32/39

Process Description Four elementary operations are applied on such equation systems without changing the solution: 1 switch equations rows in the matrix representation (also the solution vector) 2 rename variables equivalent to switching columns in the matrix 3 multiply a row with a constant ( 0) multiply a row in the matrix and solution vector with the same constant 4 add an equation to another equation add a row to another row in the matrix and solution vector. Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 33/39

Forward and Backward Elimination Aim Use the four operations on the matrix to bring it into the upper triangular form. r 11 r 12 r 13... r 1n x 1 c 1 0 r 21 r 23... r 2n x 2 c 2 0 0 r 33... r 3n 0 0...... 0 0...... r nn x 3... x n = As we use only equivalent transformations Rx = c will have the same solution as Ax = b : x i = 1 r ii (c i n k=i+1 r ik x k )(i = n 1, n 2,..., 1; x n = cn r nn ) c 3... c n Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 34/39

Process From A to R The first transformation, from A to A 1 : a 11 a 12... a 1n a11 1 a12 1... a1n 1 a 21 a 22... a 2n A = a 31 a 32... a 3n... A 0 a22 1... a 1 2n 1 = 0 a32 1... a 1 3n... a n1 a n2... a nn 0 an2 1... ann 1 1 find a pivot a r1 0 2 switch the 1 st and the r th rows 3 subtract from the rows i = 2,..., n the first row multiplied with a value l ij. a (1) ik = a ik l i1 a 1k, where l i1 = a i1 a 11, b (1) i = b i l i1 Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 35/39

Gaussian Elimination Example 9 3 4 7 4 3 4 8 1 1 1 3 1 1 1 3 4 3 4 8 9 3 4 7 1 1 1 3 4 3 4 8 0-6 -5-20 1 1 1 3 0-1 0-4 0-6 -5-20 1 1 1 3 0-1 0-4 0 0-5 4 1 x 1 = 1/5 2 x 2 = 4 3 x 3 = 4/5 Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 36/39

Summary Working with really big numbers use array/list representation and operations on these structures Chinese Remainder Theorem gives us solutions to equations of type: x x i mod n i Diophantine Equations integer solutions to equations of type: a 1 x 1 + a 2 x 2 + + a n x n = b Gaussian Elimination solves linear equations systems Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 37/39

Resources Steven S. Skiena and Miguel A. Revilla Programming challenges: the programming contest training manual Uwe Schöning Algorithmik Math World http://mathworld.wolfram.com Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 38/39

Questions? Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 39/39