Number theory for self-study students: books and computer languages

Sometimes students will contact me, as my email is visible. This time, an undergraduate in Sri Lanka has no number theory courses available and is self-studying.

My own experience is that it helps to run computer experiments; that is how I learned the topic. I took a course in C++ some twenty years ago, and that has served me well. Steep learning curve, though. It helped a good deal when I found I could use the GMP library for large integers. My impression is that many current computer languages have large integers built in.

What computer languages might one recommend for, say, investigations in number theory?

As far as books, she is currently reading Burton. I have requested that and Burn, A Pathway into Number Theory, from my library. The one thing I would add to early number theory is quadratic forms, maybe just binary, before attempting quadratic fields. I like that Burns does the automorphism group of a binary quadratic form; he may not call it a group, not sure yet.

Recommendations for inquiry based/aided discovery textbooks

• I have said it many times. Just in case I haven't said it to you: I totally enjoyed Joe Robert's Elementary number theory - a problem oriented approach when I was an advanced high schooler. No theorems, just definitions and exercises that cover proofs broken into smaller parts (as well as examples). Of course, one could also do wonders with a suitable CAS and material prepared for that. Roberts book is pre-computer era, so may not be exactly what you need. – Jyrki Lahtonen Feb 27 '17 at 18:17
• @JyrkiLahtonen new one on me, looks good. I was able to download from archive.org/details/ElementaryNumberTheory_841 – Will Jagy Feb 27 '17 at 18:43
• I'm not sure what you're trying to ask. You're unclear what your question is. Are you asking for a recommendation on how to self study number theory? – Timothy Jan 17 '19 at 0:56
• @Timothy I suppose I was at the time. Note that Jyrki, for example, knows me well from MSE and has a pretty good idea what I might be hoping this student would study. – Will Jagy Jan 17 '19 at 1:04

I would recommend Python combined with SageMath, as already recommended by Joseph O'Rourke, or rather SageMath and Python comes naturally.

Python is a modern, and widely used, interpreted language (no compilation needed) it supports big integers via the bignum type. (But using SageMath I think this is tangential, I mention it for completeness mainly.)

SageMath is a free CAS whose user language is essentially Python. SageMath has lots of number theory functionality; its founder William A. Stein is a number theorist.

He also wrote a nice book "Elementary Number Theory: Primes, Congruences, and Secrets" that uses this software; you can check it out on his site.

As you mentioned PARI/gp you might be interested to know that PARI is an integral part of SageMath.

• Yes, I get a good deal of mileage out of pari, although I still do not know how to write multi-line programs in pari. I do know how to do big programs in Magma, but the language developed some strange storage problems at the msri installation and I could no longer run a program for months at a time. Naturally, the people who maintain Magma were unable to duplicate the problem there in Sydney. – Will Jagy Jan 21 '17 at 0:07
• @pjs36 this is the book page wstein.org/ent – Will Jagy Jan 21 '17 at 0:12
• @pjs36 yes, it was an error, I meant to link to the page Will Jagy gives. It's fixed now. – quid Jan 21 '17 at 0:37
• @WillJagy the original idea behind SageMath was to have a substitute for Magma. So if you know Magma lots of things in Sage should be familiar. – quid Jan 21 '17 at 0:41
• +1. While it isn't necessary for large integers, the gmp library is usable in python as gmpy and does provide good functions for next_prime, is_prime, gcd,... – Matthew Towers Jan 23 '17 at 9:03

What computer languages might one recommend for, say, investigations in number theory?

I find Mathematica ideal, e.g.:

But: (a) there is a huge start-up learning curve, and (b) Mathematica is not free. Because of the latter, I recommend Sage / SageMath:

Multi-edge graph: "All pairs of characters in the sentence 'I am a cool multiedge graph with loops.'"

• Hi, Joseph. Is that the same as sage? I have that at home but have never figured out how to write a many-line program. – Will Jagy Jan 20 '17 at 23:50
• Website seem to show an online calculator version; they also show titles of books for beginners. Good start. – Will Jagy Jan 20 '17 at 23:52
• @WillJagy likely yes, except if you are into accounting, and have that Sage. // I second the recommendation for SageMath. In fact I wrote an answer recommending it in parallel. – quid Jan 20 '17 at 23:55
• @WillJagy The version of Sage that runs in a terminal is a bit hard for me to use (I think you save a text file with your long programs and load it, to access the functions you've defined). But they've put a lot of work into creating an online interface (SageMathCloud) and it is very nice to use (in my opinion). – pjs36 Jan 21 '17 at 0:03

For beginning number theory, Art of Problem Solving has an online course. The textbook used with it, Introduction to Number Theory by Matthew Crawford, can be used alone for self-study. (I have not used the course. I have used the textbook.) I tutored a very advanced 9-year-old using this book, and enjoyed it.

I see they also have an intermediate number theory course.

• Thanks. Here is the one number theory question by this student, math.stackexchange.com/questions/2103981/… Otherwise it is mostly complex analysis. I did reply to her email, trying to get her to arrange some project with faculty there. math.stackexchange.com/users/393345/janitha357 – Will Jagy Jan 24 '17 at 19:53
• That's above my head (for now). – Sue VanHattum Jan 24 '17 at 19:55
• I try to show them Pascal's triangle when possible. Lots of these students on MSE try to argue purely formally, never really get their hands dirty. The worst thing is that they don't draw graphs...I put a website where they can download a pdf of graph paper, print that out, actually draw $y = 2 x^2 + x + 3$ or whatever. they never do. – Will Jagy Jan 24 '17 at 19:59

Seconding/complementing other answers: Python (and/or Python as a part of Sage) has a command-line interface (on Linux/Unix and on Mac OS) that does allow defining variables, pre-loading files that set things up, and so on. Python (and, thus, Sage) has built-in large integers that are easier to use than C++ large integers (in my opinion). And freely available.

EDIT: ... and (I forgot to mention) it is quite easy to use the built-in graphing and graphical capabilities of Sage (especially in the "notebook" mode).

• Right. The GMP interface for C++ still requires knowing odd looking constructions rather than simple operator overloading. I have mostly worked out what I need. I did want to offer the student something that she might actually do, but that may be too optimistic. – Will Jagy Jan 24 '17 at 19:57
• @WillJagy, and, in my experience, the weak typing of Python/Sage is less oppressive/confusing to inexperienced students than the typing in C++. Beginners often are unable to use/see the benefits of any typing and/or pre-declaring variables, etc. – paul garrett Jan 24 '17 at 20:41

Benjamin Hutz has a recent book that could be appropriate: An Experimental Introduction to Number Theory.

This book presents material suitable for an undergraduate course in elementary number theory from a computational perspective. It seeks to not only introduce students to the standard topics in elementary number theory, such as prime factorization and modular arithmetic, but also to develop their ability to formulate and test precise conjectures from experimental data. Each topic is motivated by a question to be answered, followed by some experimental data, and, finally, the statement and proof of a theorem. There are numerous opportunities throughout the chapters and exercises for the students to engage in (guided) open-ended exploration. At the end of a course using this book, the students will understand how mathematics is developed from asking questions to gathering data to formulating and proving theorems.

Regarding languages, in the preface he mentions the following:

The book is not tied into any one computer algebra system, and there are several freely available. The systems SageMath and PARI/GP are two excellent freely available systems. Similarly, Mathematica, Maple, or other commercial software could also be used. Because there are many excellent tutorials for each of these systems freely available, they will not be presented in this book.

• That seems quite good. In most of the MSE number theory questions by relative beginners, it is clear the jumble of symbols has little meaning for them. Also, they mostly refuse to do experiments I suggest. This could be a winner. – Will Jagy Sep 11 '20 at 13:26
• Attempting to order a print copy. There is probably a way to tell the ams bookstore page that I am already a member and get it to charge the sale price. Contents look really good, – Will Jagy Sep 11 '20 at 13:34
• @WillJagy: glad it looks useful! Another recent book worth looking into is Weissman's An Illustrated Theory of Numbers. See matheducators.stackexchange.com/a/14131/376. – J W Sep 11 '20 at 13:45
• I have Weissman. I learned Conway's Topograph diagram from his little book, plus answered a dozen questions of type $ax^2 + bxy + cy^2 = target$ when the quadratic form is indefinite. I can't see that any MSE student has ever drawn such a diagram – Will Jagy Sep 11 '20 at 13:47
• @BenjaminDickman: Just a note, but the 2009 article by Benedetto, your good self et al, Computing points of small height for cubic polynomials appears as entry [5] in the Bibliography on p. 299. You may also be interested to know that Hutz's book has a chapter on dynamical systems. – J W Sep 18 '20 at 13:57