Lecture 1 & 2: Integer and Modular Arithmetic

Similar documents
Fast Polynomials Multiplication Using FFT

Fast inverse for big numbers: Picarte s iteration

CPSC 518 Introduction to Computer Algebra Asymptotically Fast Integer Multiplication

Implementation of the DKSS Algorithm for Multiplication of Large Numbers

Algorithms (II) Yu Yu. Shanghai Jiaotong University

MCS 115 Exam 2 Solutions Apr 26, 2018

Module 9: Further Numbers and Equations. Numbers and Indices. The aim of this lesson is to enable you to: work with rational and irrational numbers

Lecture 11: Cantor-Zassenhaus Algorithm

Exploring Lucas s Theorem. Abstract: Lucas s Theorem is used to express the remainder of the binomial coefficient of any two

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

Discrete Mathematics and Probability Theory Summer 2014 James Cook Note 5

Polynomial Degree and Finite Differences

Computing rank-width exactly

Computer Vision, Convolutions, Complexity and Algebraic Geometry

Factoring. there exists some 1 i < j l such that x i x j (mod p). (1) p gcd(x i x j, n).

Implementation of the DKSS Algorithm for Multiplication of Large Numbers

Three Ways to Test Irreducibility

Three Ways to Test Irreducibility

1 Caveats of Parallel Algorithms

arxiv: v3 [cs.sc] 19 Sep 2008

Discrete Mathematics U. Waterloo ECE 103, Spring 2010 Ashwin Nayak May 17, 2010 Recursion

PUTTING FÜRER ALGORITHM INTO PRACTICE WITH THE BPAS LIBRARY. (Thesis format: Monograph) Linxiao Wang. Graduate Program in Computer Science

At first numbers were used only for counting, and 1, 2, 3,... were all that was needed. These are called positive integers.

1Number ONLINE PAGE PROOFS. systems: real and complex. 1.1 Kick off with CAS

Chaos and Dynamical Systems

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 3

Elliptic Curves Spring 2013 Lecture #3 02/12/2013

On the computational complexity of mathematical functions

THE INFLATION-RESTRICTION SEQUENCE : AN INTRODUCTION TO SPECTRAL SEQUENCES

Algebra I Notes Concept 00b: Review Properties of Integer Exponents

Kartsuba s Algorithm and Linear Time Selection

1 Substitution method

SECTION 9.2: ARITHMETIC SEQUENCES and PARTIAL SUMS

Speedy Maths. David McQuillan

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication

Laver Tables A Direct Approach

Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.

Essential Maths 1. Macquarie University MAFC_Essential_Maths Page 1 of These notes were prepared by Anne Cooper and Catriona March.

Lecture 15 and 16: BCH Codes: Error Correction

Fast Integer Multiplication Using Modular Arithmetic

CURRICULUM TIDBITS FOR THE MATHEMATICS CLASSROOM

. Divide common fractions: 12 a. = a b. = a b b. = ac b c. 10. State that x 3 means x x x, . Cancel common factors in a fraction : 2a2 b 3.

All variables a, b, n, etc are integers unless otherwise stated. Each part of a problem is worth 5 points.

6.S897 Algebra and Computation February 27, Lecture 6

Lecture 4: Number theory

Numerical Methods. King Saud University

= 1 2x. x 2 a ) 0 (mod p n ), (x 2 + 2a + a2. x a ) 2

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.

Recurrence Relations

Integer Multiplication

Lecture 6 January 15, 2014

Clock Arithmetic. 1. If it is 9 o clock and you get out of school in 4 hours, when do you get out of school?

Fall 2017 November 10, Written Homework 5

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

3.5 Solving Quadratic Equations by the

Conceptual Explanations: Logarithms

2WF15 - Discrete Mathematics 2 - Part 1. Algorithmic Number Theory

Fast, Parallel Algorithm for Multiplying Polynomials with Integer Coefficients

Fermat's Little Theorem

Modular Arithmetic Instructor: Marizza Bailey Name:

Definition: A sequence is a function from a subset of the integers (usually either the set

CSE 20 DISCRETE MATH. Winter

Algebra I Notes Unit Nine: Exponential Expressions

CPSC 467: Cryptography and Computer Security

Non-Linear Regression Samuel L. Baker

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

III.A. ESTIMATIONS USING THE DERIVATIVE Draft Version 10/13/05 Martin Flashman 2005 III.A.2 NEWTON'S METHOD

1.1 Administrative Stuff

Creating Good Equations for the Classroom: Rational, Logarithmic and Square Root aversion ""Î# 9Î#!"'

Representation theory of SU(2), density operators, purification Michael Walter, University of Amsterdam

Divide-and-Conquer. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n

THE JACOBI SYMBOL AND A METHOD OF EISENSTEIN FOR CALCULATING IT

CHAPTER 3. Congruences. Congruence: definitions and properties

Lecture 6: Finite Fields

Fast Polynomial Multiplication

Integer multiplication and the truncated product problem

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?

Math 109 HW 9 Solutions

SOLUTION OF ALGEBRAIC AND TRANSCENDENTAL EQUATIONS BISECTION METHOD

Definition 6.1 (p.277) A positive integer n is prime when n > 1 and the only positive divisors are 1 and n. Alternatively

Solving Systems of Linear Equations Symbolically

Approximate Binary Search Algorithms for Mean Cuts and Cycles

Efficient Modular Arithmetic in Adapted Modular Number System using Lagrange Representation

Number Theory. Zachary Friggstad. Programming Club Meeting

Upper Bounds for Stern s Diatomic Sequence and Related Sequences

The first property listed above is an incredibly useful tool in divisibility problems. We ll prove that it holds below.

Prime Number Theory and the Riemann Zeta-Function

NUMBER SYSTEMS. Number theory is the study of the integers. We denote the set of integers by Z:

1.1.1 Algebraic Operations

Number Theory. Modular Arithmetic

A Few Primality Testing Algorithms

CMPUT 403: Number Theory

5 + 9(10) + 3(100) + 0(1000) + 2(10000) =

CPSC 518 Introduction to Computer Algebra Schönhage and Strassen s Algorithm for Integer Multiplication

Math 2602 Finite and Linear Math Fall 14. Homework 8: Core solutions

CSE 20 DISCRETE MATH. Fall

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

On the Exponent of the All Pairs Shortest Path Problem

Numerical Analysis Lecture Notes

Transcription:

CS681: Computational Numer Theory and Algera (Fall 009) Lecture 1 & : Integer and Modular Arithmetic July 30, 009 Lecturer: Manindra Agrawal Scrie: Purushottam Kar 1 Integer Arithmetic Efficient recipes for performing integer arithmetic are indispensale as they are widely used in several algorithms in diverse areas such as cryptology, computer graphics and other engineering areas. Hence our first oject of study would e the most asic integer operations - namely addition, sutraction, multiplication and division. We will start off with algorithms that are typically referred to as high-school or peasant algorithms and move on to more efficient ones wherever scope for improvement is found. 1.1 Integer Addition and Sutraction Given two n-it numers a and, the high-school algorithms take O (n) time to perform addition and sutraction. Now this is optimal upto constant factors since the input size itself is Ω(n). Hence these do not pose a challenge to us. Of course for someone designing a processor, these constant factors may decide whether the chip ecomes a market leader or not ut we shall consider the issue of integer addition and sutraction closed from now on having otained optimal algorithms for the same (many thanks to our respective high school Math teachers for this). 1. Integer Multiplication Unfortunately we have less to thank our high school teachers on this matter since the high school algorithm takes O (n ) time to multiply two n-it numers. This is too slow for most scientific calculations. A slight improvement comes due to an oservation of Gauss on multiplication of complex numers. Gauss oserved that the product (a+i)(c+di) can e calculated using just three multiplications and five additions instead of four multiplications and four additions. Let k 1 = ac, k = d, k 3 = (a + )(c + d). Then (a + i)(c + di) = (k 1 k ) + (k 3 k 1 k )i. This was the trick employed y Karatsua and Ofman in [KO6] to arrive at an O ( n log 3) algorithm for integer multiplication. What is done in this algorithm is to express each n-it numer using two n -it numers. Thus a = a 1 n + a 0 and = 1 n + 0. Hence we can use the aove trick to multiply these two numers using three n -it multiplications and some constant numer of O (n) operations which include adding the intermediate results, left shifts etc. So the time complexity of this algorithm is M(n) = 3M ( ) ( ) n + O (n) which gives M(n) = O n log 3. 1

This method of reaking up numers can e generalized to reak numers into more parts and save on some multiplications using similar tricks. This led to a family of multiplication algorithms known as Toom-Cook methods [Too63, Coo66] which give an asymptotic time complexity of O (n log(k 1) log(k) ) for any k > 1 and hence can give a complexity of O (n 1+ɛ ) for any ɛ > 0. This was improved y Schönage and Strassen using Spectral techniques (more specifically Fourier Analysis) to O (n log n log log n) in [SS71]. After this came a long period of waiting efore Fürer and De-Kurur-Saha-Saptharishi in a series of closely spaced papers [F 07, DKSS08] improved the time complexity to O ( n log n log n ) where log denotes the iterated log function. Of course one does not typically use the fastest method on all instances. As it turns out the algorithms y Fürer and De et al outperform the Schönage-Strassen algorithm in practice only on astronomically large numers due to the large constants involved. Thus for really huge numers, one uses the algorithms due to Fürer and De et al at the top level ut as the recursive calls are made to smaller numers, one switches to the Schönage-Strassen algorithm only to switch to the Karatsua algorithm for still smaller numers and finally to the high school algorithm for the ottom level recursive calls. 1.3 Integer Division As it turns out, if asymptotic complexity is all that we are interested in then integer division has the same time complexity as integer multiplication. In fact the operations of multiplication, squaring, division, inversion and square-rooting all have the same time complexity. However in this lecture our aim is only to show that division is no more difficult than multiplication. For this we require the Newton-Raphson method for inversion. This method is used in general to find roots of a real valued function f y starting with a wellinformed guess x 0 for the root and improving it iteratively using the update rule x i+1 = x i f(x i) f (x i ). The method typically has a quadratic convergence ut is also known to go astray at times. But in our case we will show that it approaches its goal in a steadfast manner. We shall of course use a slightly modified version of the algorithm keeping in mind not to keep very high precision numers. Note that all logarithms are taken to ase unless otherwise mentioned. Let us take the two n-it integers to e divided as a and where < a. We want to find integers d and r such that a = d + r and r <. We will always work only with positive integers for simplicity. For now let us assume that has een scaled down to the range ( 1, 1) y dividing y an appropriate power or. For this assume >. The case = is clearly very simple to handle. From now on, till otherwise mentioned, we shall call this scaled down n-it numer as. Our goal here is to find a good approximation of 1. Note that 1 (1, ). Let us choose x 0 = 1 as our first approximation. Clearly x 0 < 1 and 1 x 0 < 1. Truncate 1 x 0 to the first it after the decimal point and call this quantity y 0. Clearly y 0 < 1 as well. Define y i = yi 1 and x i+1 = x i (1 + y i ) for all i > 0. Consider the following results : Lemma 1.1. For any i > 0, we have the following to e true 1. y i < 1 i

. 1 x i < 1 i 3. y i is at most i its long 4. x i is at most i its long Proof. We present the respective proofs elow. All proofs are y induction on i. 1. For i = 0 we have already shown the result. Suppose the result also holds upto some i, then we have y i+1 = y i < 1 i+1.. For i = 0 we have already shown the result. Suppose the result also holds ( upto some ) i, then we have 1 x i+1 = 1 x i (1 + y i ) = 1 x i x i y i < 1 1 + 1 ( ) i i y i < 1 1 1 + 1 = 1. i i i i+1 3. For i = 0 this is true ecause of choice of y 0. Suppose the result also holds upto some i, then we have y i+1 = y i and hence the numer of its in y i+1 can e atmost twice that of y i. Hence the result holds. 4. For i = 0 this is true y choice of x 0. Suppose the result also holds upto some i, then we have x i+1 = x i (1 + y i ). Since y i < 1 and oth x i and y i are at most i its long, the result holds. At this point we fix the issue of scaling to within the range ( 1, 1). Let m > 0 such that = [ 1, 1). Then it is clear that if x is such that 1 x < ɛ then if x = x then 1 x < ɛ m m as well. Now we state a final lemma efore moving on to prove our desired result. Lemma 1.. Fix i = log n + 1. Then if a = d + r then a x i d 1. Proof. Clearly a x i d = d( x i 1) + r x i < d + r d + 1 1 i i and log d n. 1 since r <, log n The preceding lemmata give us an O (M(n)) algorithm for integer division where M(n) is the asymptotic complexity for integer multiplication. This can e shown as follows : at the i-th iteration, all we do is multiply and add i -it numers (this includes the squaring step). This takes M (O ( i )) + O ( i ) time which is O (M ( i )) since M (O (n)) = O (M(n)) and M(n) = Ω(n). Another outcome of M(n) = Ω(n) is that M(a) + M() M(a + ) for all a, 1. In the eginning we calculate 1 x 0 which takes O (M(n)) time. The calculations at the end to find d from x log n+1 also takes O (M(n)) time. Due to some uncertainty in the value of d, we may have to try out a constant numer of values in the vicinity of the d otained. All this will take time O (M(n)). Hence integer division is no more difficult than integer multiplication. 3

Note: There are some minute details of the algorithm that need to e taken care of. It can e seen that the algorithm will fail if y 0 = 0. However this is actually a good thing for us ecause it tells us that our very first approximation is as good as something we hoped to get several iterations down 1 the line. Thus if 1 x l 1 0 > 1, then we can retain log l its of 1 x l 0 and call this the log l -th iteration and proceed. Modular Arithmetic In this section we will deal with how to do the four asic integer operations on n-it numers a and modulo another n-it numer m. It should e clear that modular addition, sutraction and multiplication can e done in O (M(n)) time. As far as division is concerned we first have to define what does it mean for a to e z mod m. Definition.1. For any three integers a, and c, a mod m is said to e defined if there exists an integer z such that z a mod m. In such a situation we say a z mod m. a Lemma.. mod m for integers a and such that (a, ) = 1 is defined iff (m, ) = 1. = rm + z where z Z and r Q such that Proof. ( ) Suppose a mod m is defined and a r Z. Hence a = rm + z. Now suppose (m, ) > 1. This implies from the aove equation that (a, ) > 1 as well which is contradictory to our assumption. Hence (m, ) = 1. ( ) Suppose (m, ) = 1, hence there exist p, q Z such that pm + q = 1. Hence apm + aq = a which implies (aq) a mod m. Hence a mod m is defined. Using the aove lemma we can easily find a mod m in O (n ) time. First using the extended Euclid s algorithm determine if (m, ) = 1. If this is indeed the case then the algorithm will also output the pair (p, q) and clearly q 1 mod m. Hence aq 1 mod m. Since the Euclid s algorithm works in quadratic time and M(n) = o(n ) hence the algorithm takes only O (n ) time. References [Coo66] Stephen A. Cook. On the Minimum Computation Time of Functions. PhD thesis, Department of Mathematics, Harvard University, 1966. [DKSS08] Anindya De, Piyush Kurur, Chandan Saha, and Ramprasad Saptharishi. Fast Integer Multiplication Using Modular Arithmetic. In Fortieth Annual ACM Symposium on Theory of Computing, 008. [F 07] [KO6] Martin Fürer. Faster Integer Multiplication. In Thirty Ninth Annual ACM Symposium on Theory of Computing, 007. A. Karatsua and Yu. Ofman. Multiplication of Many-Digital Numers y Automatic Computers. Proceedings of the USSR Academy of Sciences, 145:93 94, 196. 4

[SS71] A. Schönhage and V. Strassen. Schnelle Multiplikation großer Zahlen. Computing, 7:81 9, 1971. [Too63] Andrei Toom. The Complexity of a Scheme of Functional Elements Realizing the Multiplication of Integers. Soviet Mathematics - Doklady, 3:714 716, 1963. 5