http://dx.doi.org/10.1090/stml/045

This page intentionally left blank Higher Arithmeti c An Algorithmic Introduction to Theory STUDENT MATHEMATICAL LIBRARY Volume 45

Higher Arithmetic An Algorithmic Introduction to Number Theory

Harold M . Edwards

ilAMS AMERICAN MATHEMATICA L SOCIET Y Providence, Rhode Islan d Editorial Boar d Gerald B . Follan d Bra d G . Osgoo d (Chair ) Robin Forma n Michae l Starbir d

2000 Mathematics Subject Classification. Primar y 11-01 .

For additiona l informatio n an d update s o n thi s book , visi t www.ams.org/bookpages/stml-45

Library o f Congres s Cataloging-in-Publicatio n Dat a Edwards, Harol d M . Higher arithmetic : an algorithmic introduction t o number theory / Harol d M . Edwards. p. cm . — (Studen t mathematica l library , ISS N 1520-912 1 ; v. 45 ) Includes bibliographica l reference s an d index . ISBN 978-0-8218-4439- 7 (alk . paper ) 1. Number theory . I . Title .

QA241 .E39 200 8 512.7—dc22 200706057 8

Copying an d reprinting . Individua l reader s o f thi s publication , an d nonprofi t libraries actin g fo r them , ar e permitte d t o mak e fai r us e o f th e material , suc h a s t o copy a chapte r fo r us e i n teachin g o r research . Permissio n i s grante d t o quot e brie f passages fro m thi s publicatio n i n reviews , provide d th e customar y acknowledgmen t o f the sourc e i s given . Republication, systemati c copying , o r multiple reproduction o f any materia l i n this publication i s permitted onl y unde r licens e fro m th e America n Mathematica l Society . Requests fo r suc h permissio n shoul d b e addresse d t o th e Acquisition s Department , American Mathematica l Society , 20 1 Charles Street , Providence , Rhod e Islan d 02904 - 2294, USA . Request s ca n als o b e mad e b y e-mail t o [email protected] .

© 200 8 by the America n Mathematica l Society . Al l rights reserved . The America n Mathematica l Societ y retain s al l right s except thos e grante d t o th e Unite d State s Government . Printed i n the Unite d State s o f America . @ Th e pape r use d i n this boo k i s acid-free an d fall s withi n th e guideline s established t o ensur e permanenc e an d durability . Visit th e AM S hom e pag e a t http://www.ams.org / 10 9 8 7 6 5 4 3 2 1 1 3 1 2 1 1 1 0 09 0 8 Contents

Preface i x

Chapter 1 . Number s 1

Chapter 2 . Th e Proble m AD + B = • 7

Chapter 3 . Congruence s 1 1

Chapter 4 . Doubl e Congruences and the Euclidean Algorithm 1 7

Chapter 5 . Th e Augmente d Euclidea n Algorith m 2 3

Chapter 6 . Simultaneou s Congruence s 2 9

Chapter 7 . Th e Fundamental Theore m o f Arithmetic 3 3

Chapter 8 . Exponentiatio n an d Order s 3 7

Chapter 9 . Euler' s -Functio n 4 3

Chapter 10 . Findin g the Orde r o f a mod c 4 5

Chapter 11 . Primalit y Testin g 5 1 VI Higher Arithmeti c

Chapter 12 . The RS A Ciphe r Syste m 57

Chapter 13 . Primitive Root s mo d p 61

Chapter 14 . Polynomials 67

Chapter 15 . Tables o f Indices mo d p 71

Chapter 16 . Brahmagupta's Formul a an d Hypernumber s 77

Chapter 17 . Modules o f Hypernumber s 81

Chapter 18 . A Canonical Form fo r Modules o f Hypernumbers 87

Chapter 19 . Solution o f AD + B = • 93

Chapter 20 . Proof o f the Theore m o f Chapter 1 9 99

Chapter 21. Euler's Remarkabl e Discover y 113

Chapter 22 . Stable Module s 119

Chapter 23 . Equivalence o f Module s 123

Chapter 24 . Signatures o f Equivalence Classe s 129

Chapter 25 . The Mai n Theore m 135

Chapter 26 . Modules That Becom e Principal Whe n Square d 137

Chapter 27 . The Possibl e Signature s fo r Certai n Value s o f A 143

Chapter 28 . The La w o f Quadratic Reciprocit y 149

Chapter 29 . Proof o f the Mai n Theore m 153

Chapter 30 . The Theor y o f Binary Quadrati c Form s 155

Chapter 31. Composition o f Binary Quadrati c Form s 163 Contents vn

Appendix. Cycle s o f Stable Module s 16 9

Answers to Exercise s 17 9

Bibliography 20 7

Index 20 9 This page intentionally left blank Preface

It i s widel y agree d tha t Car l Friedric h Gauss' s 180 1 book Disquisi- tiones Arithmeticae [G ] was the beginning o f modern number theory , the firs t wor k o n th e subjec t tha t wa s systemati c an d comprehen - sive rather than a collection o f special problems an d techniques . Th e name "numbe r theory " b y whic h the subjec t i s known toda y wa s i n use at th e time—Gauss himsel f use d i t (theoria numerorum) i n Arti- cle 5 6 o f the book—bu t h e chos e t o cal l i t "arithmetic " i n hi s title . He explaine d i n th e first paragrap h o f hi s Prefac e tha t h e di d no t mean arithmeti c i n th e sens e o f everyda y computation s wit h whol e bu t a "highe r arithmetic " tha t comprise d "genera l studie s of specifi c relation s amon g whole numbers. " I too prefer "arithmetic " to "numbe r theory." T o me, number the- ory sounds passive, theoretical, and disconnected fro m reality . Highe r arithmetic sound s active , challenging, an d relate d to everyday realit y while aspirin g to transcend it . Although Gauss's explanation o f what h e means by "highe r arith - metic" i n his Preface i s unclear, a strong indication o f what h e had i n mind come s at th e end o f his Preface whe n h e mentions the materia l in hi s Sectio n 7 on th e constructio n o f regula r polygons . (I n mod - ern terms , Sectio n 7 i s th e Galoi s theor y o f th e algebrai c equatio n xn — 1 = 0. ) H e admit s tha t thi s materia l doe s no t trul y belon g t o arithmetic bu t tha t "it s principle s mus t b e draw n fro m arithmetic. "

IX X Higher Arithmeti c

What h e mean s b y arithmetic , I believe , i s exact computation, clos e to what Leopol d Kronecke r late r calle d "genera l arithmetic." 1 In 21s t centur y terms , Gauss' s subjec t i s "algorithmi c mathe - matics," mathematic s i n whic h th e emphasi s i s o n algorithm s an d computations. Instea d o f set-theoretic abstraction s an d unrealizabl e constructions, suc h mathematic s deal s wit h specifi c operation s tha t arrive a t concret e answers . Regardles s o f wha t Gaus s migh t hav e meant b y hi s titl e Disquisitiones Arithmeticae, wha t I mea n b y m y title Higher Arithmetic i s a n algorithmi c approac h t o th e number - theoretic topic s i n the book , mos t o f whic h ar e draw n fro m Gauss' s great work . Mathematics i s abou t reasoning , bot h inductiv e an d deductive . Computations ar e simpl y ver y articulat e deductiv e arguments . Th e best theoretica l mathematic s i s a n inductiv e proces s b y whic h suc h arguments ar e found , organized , motivated , an d explained . Tha t i s why I think ample computational experience is indispensable to math- ematical education . In teachin g th e numbe r theor y cours e a t Ne w Yor k Universit y several time s i n recen t years , I hav e foun d tha t student s enjo y an d feel the y profi t fro m doin g computationa l assignments . M y ow n ex - perience i n readin g Gaus s ha s usuall y bee n tha t I don't understan d what h e i s doin g unti l h e give s a n example , s o I tr y t o ski p t o th e example righ t away . Moreover , o n anothe r level , i n writing thi s an d previous books , I have ofte n foun d tha t creatin g exercise s lead s to a clearer understandin g o f the materia l an d a muc h improve d versio n of th e tex t tha t th e exercise s ha d bee n mean t t o illustrate . (Ver y often, th e greates t enlightenmen t cam e whe n writin g answers t o th e exercises. Fo r thi s reason , amon g others , answer s ar e give n fo r mos t of the exercises , beginning o n page 179. ) Fortunately, numbe r theor y i s an idea l subject fro m th e point o f view o f providin g illustrativ e example s o f al l order s o f difficulty . I n this ag e o f computers , student s ca n tackl e problem s wit h rea l com - putational substanc e withou t havin g t o d o a lo t o f tediou s work . I

xSee Essa y 1. 1 o f m y boo k [E3] . Fo r th e relatio n o f genera l arithmeti c t o Galois theory, se e Essa y 2.1. Preface XI have trie d t o provid e a t th e en d o f eac h chapte r enoug h example s and experiment s fo r student s t o try , bu t I' m sur e tha t enterprisin g students an d teacher s wil l be abl e to inven t man y more . What bega n a s a n experimen t i n th e NY U cours e turne d int o a substantial revisio n o f the course . Th e experimen t wa s to see ho w much o f number theory could be formulated i n terms o f "numbers " i n the mos t primitiv e sense—th e number s 0 , 1 , 2, ... use d i n counting . To m y surprise , I foun d tha t no t onl y coul d I avoid negativ e num - bers bu t tha t I didn't miss them . Th e simpl e reaso n fo r thi s i s tha t the basi c question s o f number theor y ca n b e stated i n terms o f con - gruences, an d subtractio n i s alway s possibl e i n congruence s withou t any need fo r negativ e numbers. Negativ e numbers hav e always led to metaphysical conundrums—wh y shoul d a negativ e time s a negativ e be a positive?—which caus e confusing distraction s right at the outse t when the meanin g o f "number " i s being mad e precise . I n this book , the meaning o f "number " derive s simply from the activity o f counting and arithmeti c ca n begi n immediately . Kronecker' s famou s dictum , "God created the whole numbers; al l the rest i s human work," ca n be amended t o say , "nonnegativ e whol e numbers, " whic h i s ver y likel y what Kronecke r mean t anyway . A central theme o f the book i s the problem I denote by the equa - tion AD + B = •, th e proble m o f finding, fo r tw o give n number s A and B, al l number s x fo r whic h Ax 2 + B i s a square . A s Chapte r 2 explains, version s o f thi s proble m ar e a t leas t a s ol d a s Pythago - ras, although tw o millennia later the Disquisitiones Arithmeticae stil l dealt wit h it . A simple algorith m fo r th e complet e solutio n i s give n in Chapter 19 . Work o n problems o f the for m A\D + B = • le d Leonhard Eule r to the discover y o f what I call "Euler' s law, " th e statemen t tha t th e answer t o the questio n "I s A a square mo d p?" fo r a prime numbe r p depends onl y o n the valu e o f p mod 4A. Thi s statement , o f whic h the la w o f quadratic reciprocit y i s a byproduct, i s completely prove d in Chapter 29 . When Ernst Eduard Kummer first introduced his theory o f "idea l complex numbers " i n 1846 , 4 5 years afte r th e publicatio n o f Disqui- sitiones Arithmeticae, Gaus s sai d that h e had worke d ou t somethin g Xll Higher Arithmeti c resembling Rummer' s theor y fo r hi s "privat e use " whe n h e was writ - ing abou t th e compositio n o f binary quadrati c form s i n Sectio n 5 of Disquisitiones Arithmeticae, bu t tha t h e lef t i t ou t o f th e boo k be - cause h e had no t bee n abl e to put i t o n firm ground. 2 Althoug h th e proof o f quadrati c reciprocit y give n i n thi s boo k wa s originall y in - spired b y Gauss' s proo f usin g th e compositio n o f forms , i t i s state d in terms close r to Rummer's idea l numbers. Specifically : If, i n additio n t o usin g ordinar y number s 0 , 1 , 2 , ... , one com - putes wit h a symbol \J~A whos e squar e i s a fixed number A , on e ha s an arithmetic— I hav e dubbe d i t th e arithmeti c o f "hypernumbers " for tha t A —in whic h th e natura l generalizatio n o f doin g computa - tions mo d n fo r som e number n i s to d o computations mo d [a , b] for some pair o f hypernumber s a an d b. (Wit h ordinar y numbers , th e Euclidean algorith m serve s to reduce the number o f numbers i n a set that describe s a modulus to just one, but with hypernumbers two may be needed , a s i s show n i n Chapte r 18. ) Wit h natura l definition s o f multiplication an d equivalenc e o f suc h "module s o f hypernumbers, " the computations needed to solve AD + B = • an d to prove quadratic reciprocity ca n b e explaine d ver y simply . I n thi s way , Gauss' s diffi - cult compositio n o f forms i s avoided but th e essenc e o f his method i s preserved. The las t tw o chapters relat e the methods o f the boo k t o Gauss' s binary quadrati c form s s o student s intereste d i n readin g furthe r i n the Disquisitiones Arithmeticae —or student s interested in binary qua- dratic forms—wil l b e abl e to make the transition . Finally, a n appendix give s a table o f the cycle s o f stable module s of hypernumbers fo r al l numbers A < 11 1 that ar e not squares , whic h will be useful fo r students, a s they wer e fo r me , in understanding th e general theory an d i n working out examples .

2 See [E4]. This page intentionally left blank Bibliography

[D] L. E. Dickson , History of the Theory of Numbers, Carnegi e Insti - tute, Washington , 1920 , Chelsea reprint, 1971 .

[El] H. M. Edwards, Riemann's Zeta , Academi c Press, Ne w York, 1974 , Dover reprint, 2001.

[E2] H . M . Edwards , FermaVs Last Theorem, Springer-Verlag , Ne w York, 1974 .

[E3] H. M . Edwards, Essays in Constructive Mathematics, Springer - Verlag, Ne w York, 2005.

[E4] H. M. Edwards, Composition of Binary Quadratic Forms and the Foundations of Mathematics, articl e in The Shaping of Arithmetic, C . Goldstein e t al. , eds., Springer-Verlag, Berlin , Heidelberg, Ne w York, 2007.

[G] C . F . Gauss , Disquisitiones Arithmeticae, Braunschweig , 1801 . (Reprinted a s vol. 1 of Gauss's Collected Works (Gesammelte Werke) and availabl e i n man y edition s i n whic h i t i s translate d int o man y languages.)

[J] C . G . J . Jacobi , Canon Arithmeticus, Berlin , Typi s Academicis , 1839.

207 This page intentionally left blank Index

Acharya, Bhaskara , 93 , 19 7 content o f a module, 10 2 algebraic , 10 9 counting, 1- 5 algebraic numbe r theory , 10 9 cube roo t mo d p, 7 3 algorithm augmented Euclidean , 24-2 6 Dirichlet, G . Lejeune , 11 5 comparison, 9 3 discriminant o f a form , 15 6 division wit h remainder , 4 , 5 Disquisitiones Arithmeticae , ix-xii , Euclidean, 19 , 18 2 11, 62 , 16 3 exponentiation, 3 7 division, 4 factorization, 53 , 5 4 division b y a mod 6 , 2 7 Miller's test , 53 , 18 9 division wit h remainder , 4 , 6 8 multiplication, 2 , 3 double congruence , 1 8 reduction, 10 4 Archimedes, 8 , 9 equality o f modules, 8 1 augmented Euclidea n algorithm , equivalence o f forms , 15 7 23-26, 59 , 6 4 equivalence o f modules, 123 , 12 4 Euclidean algorithm , 18 , 24 , 8 2 binary quadrati c form , xii , 155-16 0 Euler's criterion , 11 4 Brahmagupta, 77 , 93, 9 7 Euler's generalizatio n o f Fermat' s Brahmagupta's formula , 77-79 , 16 3 theorem, 4 8 Euler's law , 116 , 129 , 136 , 15 4 canonical form , 87-9 1 Euler, Leonhard , xi , 43 , 114-11 6 Chinese remainde r theorem , 3 0 exponentiation, 37-3 9 class group, 12 7 comparison algorithm , 9 3 Farey series , 2 7 composite number , 3 3 Fermat's theorem , 48 , 51, 63 composition o f forms , 163-16 7 form, see binar y quadrati c for m congruence, 11-1 3 fundamental theore m o f arithmetic , congruence o f hypernumbers, 81-8 3 33, 3 4 conjugate o f a module, 10 2 fundamental unit , 108 , 10 9

209 210 Index

Gauss, Car l Friedrich , ix-xii , 11 , pivotal module , 139-14 2 62, 116 , 154 , 156 , 157 , 163-16 7 pivotal o f type 1 , 13 9 greatest commo n divisor , 19 , 2 0 pivotal o f type 2 , 13 9 Plato, 8 hyperinteger, 16 1 polynomial, 6 7 hypernumber, xii , 7 9 prime number , 3 3 indeterminates, 6 7 primitive module , 102 , 12 6 index o f a numbe r mo d p, 71 , 72 primitive roo t mo d p , 6 1 invertible module , 12 6 primitive solution , 9 4 principal cycle , 12 6 Jacobi, C . G . J. , 71-7 4 principal module , 123 , 16 2 Pythagoras, 7 Kronecker, Leopold , x , x i Kummer, Erns t Eduard , xi , xi i quadratic characte r o f A mo d p (CP(A)), 113 , 11 4 Law o f Quadratic Reciprocity , see quadratic numbe r field, 10 9 quadratic reciprocity , la w o f quadratic reciprocity , la w of , 116 , 117, 149 , 150 , 154 , 20 1 Main Theorem , 135 , 136 , 153 , 15 4 matrix computations , 9 7 reciprocal o f a mod b, 2 7 Mersenne primes , 4 9 reduction algorithm , 10 4 Miller's test , 53-5 5 relatively prime , 2 0 module, 8 1 RSA system , 57-6 0 modulus, 1 2 monic polynomial , 6 8 signature o f a module , 130-133 , multiplication o f modules, 83 , 84, 143-145 163 signature relativ e t o A o f a number, 13 5 Nicomachus, 3 1 simultaneous congruences , 29-3 1 norm o f a module, 102 , 110 , 12 6 square roo t mo d p, 7 3 number, 1 squarefree number , 12 9 stable module , 119-121 , 169-17 7 one-to-one, 14 4 successor o f a module , 11 9 onto, 14 4 sum o f two squares, 16 2 orbit, 46 , 4 7 Supplementary La w o f Quadrati c order o f a mod c , 3 9 Reciprocity, 15 0 -function, 4 3 table o f indices , 7 3 Pell's equation , 98 , 111 , 11 2 permutation, 45-4 7 Titles i n Thi s Serie s

45 Harol d M . Edwards , Highe r arithmetic : A n algorithmi c introductio n t o number theory , 200 8 44 Yitzha k Katznelso n an d Yonata n R . Katznelson , A (terse ) introduction t o linea r algebra , 200 8 43 Ilk a Agricol a an d Thoma s Friedrich , Elementar y geometry , 200 8 42 C . E . Silva , Invitatio n t o ergodi c theory, 200 7 41 Gar y L . Mulle n an d Car l Mummert , Finit e fields an d applications , 2007 40 Deguan g Han , Ker i Kornelson , Davi d Larson , an d Eri c Weber , Frames fo r undergraduates , 200 7 39 Ale x losevich , A vie w fro m th e top : Analysis, combinatorics an d numbe r theory, 200 7 38 B . Fristedt , N . Jain , an d N . Krylov , Filterin g an d prediction : A primer, 200 7 37 Svetlan a Katok , p-adi c analysi s compare d wit h real , 200 7 36 Mar a D . Neusel , Invarian t theory , 200 7 35 Jor g Bewersdorff , Galoi s theory fo r beginners : A historical perspective , 2006 34 Bruc e C . Berndt , Numbe r theor y i n the spiri t o f Ramanujan, 200 6 33 Rekh a R . Thomas , Lecture s i n geometri c combinatorics , 200 6 32 Sheldo n Katz , Enumerativ e geometr y an d strin g theory, 200 6 31 Joh n McCleary , A firs t cours e i n topology : Continuit y an d dimension , 2006 30 Serg e Tabachnikov , Geometr y an d billiards , 200 5 29 Kristophe r Tapp , Matri x group s fo r undergraduates , 200 5 28 Emmanue l Lesigne , Head s o r tails: An introductio n t o limi t theorem s i n probability, 200 5 27 Reinhar d Illner , C . Sea n Bohun , Samanth a McCollum , an d The a van Roode , Mathematica l modelling : A cas e studie s approach , 200 5 26 Rober t Hardt , Editor , Si x themes o n variation , 200 4 25 S . V . Duzhi n an d B . D . Chebotarevsky , Transformatio n group s fo r beginners, 200 4 24 Bruc e M . Landma n an d Aaro n Robertson , Ramse y theor y o n th e , 200 4 23 S . K . Lando , Lecture s o n generating functions , 200 3 22 Andrea s Arvanitoyeorgos , A n introductio n t o Li e groups an d th e geometry o f homogeneous spaces , 200 3 21 W . J . Kaczo r an d M . T . Nowak , Problem s i n mathematical analysi s III: Integration , 200 3 20 Klau s Hulek , Elementar y algebrai c geometry , 200 3 19 A . She n an d N . K . Vereshchagin , Computabl e functions , 200 3

18 V . V . Yaschenko , Editor , Cryptography : A n introduction , 200 2 TITLES I N THI S SERIE S

17 A . She n an d N . K . Vereshchagin , Basi c se t theory , 200 2 16 Wolfgan g Kiihnel , Differentia l geometry : curve s - surface s - manifolds , second edition , 200 6 15 Ger d Fischer , Plan e algebrai c curves , 200 1 14 V . A . Vassiliev , Introductio n t o topology , 200 1 13 Frederic k J . Almgren , Jr. , Plateau' s problem : A n invitatio n t o varifol d geometry, 200 1 12 W . J . Kaczo r an d M . T . Nowak , Problem s i n mathematical analysi s II: Continuit y an d differentiation , 200 1 11 Michae l Mesterton-Gibbons , A n introductio n t o game-theoreti c modelling, 200 0 ® 10 Joh n Oprea , Th e mathematic s o f soap films : Exploration s wit h Mapl e , 2000 9 Davi d E . Blair , Inversio n theor y an d conforma l mapping , 200 0 8 Edwar d B . Burger , Explorin g th e numbe r jungle : A journey int o diophantine analysis , 200 0 7 Jud y L . Walker , Code s an d curves , 200 0 6 Geral d Tenenbau m an d Miche l Mende s France , Th e prim e number s and thei r distribution , 200 0 5 Alexande r Mehlmann , Th e game' s afoot ! Gam e theor y i n myth an d paradox, 200 0 4 W . J . Kaczo r an d M . T . Nowak , Problem s i n mathematical analysi s I: Real numbers , s an d series , 200 0 3 Roge r Knobel , A n introductio n t o the mathematica l theor y o f waves, 2000 2 Gregor y F . Lawle r an d Leste r N . Coyle , Lecture s o n contemporar y probability, 199 9 1 Charle s Radin , Mile s o f tiles, 199 9