Today I received a very nice package from the AMS — a complete color printout of a draft of the book!  This means it’s time to proofread, and think of all the things I should have done along the way.

So here is a retrospective look at what I should have done.

1.  Created a stylesheet as I was writing.  For example, when abbreviating circa (as in Euclid lived c.300 BCE), is there a space as in “c. 300” or not as in “c.300”.  I’ll look it up… but my life would have been easier if I had kept a running list of style details for consistency throughout the manuscript.  Credit goes to Ellen Muehlberger for this advice — when I told my wife about this problem, she said that her advisor (E.M.) told her to maintain such a stylesheet throughout her dissertation.  Great advice!
2. Used a version control system throughout.  I just took the Udacity course on Git and GitHub yesterday (better late than never).  It’s an excellent quick class, and I’ll be using GitHub for producing a webpage for the book, sharing teaching materials, etc..  Unfortunately my current book files are organized like my camping gear… randomly stashed in large not-quite-clean tubs.
3. Considered CMYK color issues from the outset.  I had read and heard about color issues before, but didn’t do anything about it.  So now I have a large book, and of course the colors look great on a monitor (in RGB) and varying stages of terrible in print (in CMYK).  Fortunately, I have been using xcolor throughout, which gives me precise control over colors in the CMYK (or any other) colorspace.  I was a bit surprised at how different things ended up in print.  For example, a standard red  corresponds to 0% Cyan, 100% Magenta, 100% Yellow, 0% Black in CMYK space.  I wanted to desaturate the red when filling large areas; the xcolor setting red!50 yields the result 0% Cyan, 50% Magenta, 50% Yellow, 0% Black, which makes sense.  But on paper, this looks distinctly orange, in a sort of carrot-left-in-the-freezer-too-long way.  Similarly blue turns pale purple as blue!50.  The solution is fun, if a bit time-consuming.  I printed a CMYK color chart which I found via stackexchange, asking the local print shop to use their nicest inkjet and book-quality paper.  I’m using this printed color chart to choose my colors now.  So, instead of using a command like blue!50, I’ll define my own color (blueB perhaps) as 60% Cyan, 10% Magenta, 0% Yellow, 7% Black, and use this wherever I used blue!50 before.  I’ll probably give the local print shop some business with color experiments over the next month.  There’s really no way for me to match what the eventual offset printer will do, but I’m hoping to get as close as possible.

## Prime distribution, before and after

In the Illustrated Theory of Numbers, the pictures serve different purposes.  Some lend geometric insight to proofs.  Others display logical flow.  Others render an abstract concept.  This post is about those which are data visualizations.

Using the term “data visualization” automatically increases web traffic, but I’m not just doing it for the hits.  Instead, I think it’s time that the best data visualization practices are directed towards the most interesting data in number theory:  the prime numbers being the prime example.  While the data visualization community typically studies people and places and money and the natural world, the Illustrated Theory of Numbers gets its data from numbers themselves.  It is one of the fascinating things about number theory that the data is entirely deterministic while at the same time obeying heuristics for random variables.

In this spirit, I’ve provided two drafts of a data visualization below, displaying the distribution of prime numbers up to 5 million.  I’ll explain the editing process that led me from left to right.

My goal in this image is to provide the reader with a sense of the microscopic irregularity and the macroscopic regularity of the prime numbers.  In the left column, the prime numbers are thick bars (10 points, I think).  Each column displays a range of prime numbers:  the first displays primes up to 50, the second the primes up to 500, etc..  The rightmost column displays the primes up to 5 million.  In some ways, this is the simplest kind of data set — a one-dimensional distribution.

From the beginning, I decided on this basic layout of columns, so that by the rightmost column the image would appear smooth, and gradually getting lighter towards the top as the primes spread out.  The numbers which represent primes on the far left are replaced by densities on the far right.  A number near 5 million has about a 6.5% chance of being prime.

I made a lot of changes to this image, starting with the draft on the left (from a few years ago) and ending at the draft on the right (a few weeks ago).  First, I pushed the prime number labels onto the bars.  There might be some printing/clarity risks with white text on black bars, but it gets across the idea that the bars are the prime numbers and it reduces the chance of confusion that the same “ticks” apply to all columns.

In that spirit, I narrowed and separated the columns.  This, I think, lightens the whole page, saves ink, and increases clarity.  The red lines now indicate how each column is effectively contained in a tenth of the column to its right.  I’ll admit there’s a bit of influence from the cover of Tufte’s Visual Display of Quantitative Information, though the subject matter is completely different.  I hope the red lines also break the tendency to scan directly left-to-right, and indicate how data is squeezed into shorter intervals.

Also lightening the page, I changed the shading in columns 3-6.  In the first two columns, solid black bars are used to represent prime numbers.  But in columns 3-6, a shade of gray is used according to the density of primes in each bin.  Among the numbers between 4000 and 4499, there are 60 prime numbers.  Since 60/500 = 12%, I used a line segment at 12% black in the later draft.  (With TikZ, this is accomplished by setting the color to black!12).

At first I was concerned that this would be too light, and I’ll see how it all looks when it’s printed professionally.  But on the Ricoh printers here, the result looks good — even at 6.5% black (the density around 5 million), the gray is easily distinguishable from the white paper.  And this fits with the principle of “smallest effective difference” described in Tufte’s Visual Explanations.  It’s a bit hard (though not impossible) to see the primes spread out, as their density goes from 8.5% to 6.5% in the rightmost column.  But that’s also part of the honest representation — it would be dishonest to the data to exaggerate the image to make the primes appear to spread out more quickly.  The table of densities at the far right exhibits the gradual spreading unambiguously with numbers.

A note to the reader — the images tend to render with horizontal stripes on a computer monitor!  Another reminder to print on a regular basis.

There’s probably a bit more tuning to do before publication.  The primes deserve the effort.

## Determinants and Pick’s theorem, in color.

Like most blogs, the Illustrated Theory of Numbers blog went on a long hiatus.  Unlike most blogs, this one has returned!  Really, there has not been too much to show over the past few months, but I’ve gotten back to work on Part II of the book, covering binary quadratic forms (including all discriminants, Pell-like equations, a bit on SQUFOF factorization perhaps, the class number and the “Siegel bound”).  This might strike the experts as a bit out of order — where is modular arithmetic already? — but I’m sticking with “global” number theory until Part III of the book.  Of course, some readers might skip Part II and go directly to Part III, but I hope they will return to Part II to learn Conway’s beautiful “topographic” approach to binary quadratic forms.

I was heavily influenced by Conway’s visual approach to binary quadratic forms, found in Chapter 1 of “The (sensual) Quadratic Form.”  It’s amazing how far you can go with his topographs.  I think I can go through reduction theory, symmetries (a.k.a. orthogonal groups), and finiteness of the class number, without ever needing to multiply two matrices.  As recent work of Savin and Bestvina illustrates, along with recent work of my PhD student Chris Shelley, Conway’s approach generalizes in interesting ways to binary Hermitian forms and beyond.

One thing I use often in Part II is the determinant.  Fortunately, for two-by-two determinants, the geometry is relatively simple.  Below is a two-page spread introducing the geometric interpretation of the determinant.  A helpful bonus, presented in parallel, is the discrete version: Pick’s theorem for lattice parallelograms.

From mathematical and design perspectives, I like the idea of presenting parallel proofs in visual parallel on opposite pages.  The left displays a theorem in continuous Cartesian geometry; the right displays a theorem in discrete geometry.  The idea of dissection is the same, but the discrete version requires a bit more care.

I’m not exactly sure what to call the theorem on the right side of the page.  It certainly falls under the purview of Pick’s Theorem but really, someone must have proved it before Pick, at least for parallelograms!  I wouldn’t be surprised to see it in the work of Gauss or Eisenstein, if not earlier. Unfortunately, my German is not so good (nicht so gut?), though I can recognize the frequency of “Gitterpunkt” (grid-point) and “Gitterpolygon” (polygon with vertices on grid-points) in 19th century sources.  Any reader who can find an earlier reference for Pick’s theorem, even for parallelograms (rectangles don’t count on their own!) gets an acknowledgment in the book!

The utility of Pick’s Theorem is the following — it gives a cute geometric proof of the following fact well-known to algebraists:  A pair $(a,b)$ and $(c,d)$ of integer vectors forms an integer basis of $Z^2$ if and only if $ad - bc = \pm 1$.  Indeed, a grid-parallelogram of area one cannot cover any grid-points except its corners, by Pick’s Theorem.  This avoids any mention of matrix inversion, for example.

From a design perspective, this two-page spread was a lot of fun (and a bit of work).  A combination of \foreach and scoped \clip commands in TikZ allowed for the easy creation of dot-textures on the right page.  Perhaps the toughest decision (and one that isn’t final) was the choice of four colors; they are called “pinkish,” “blueish”, “greenish”, and “orangeish” in my source file.  Following some technical color-theory advice, I worked with a color tetrad — literally a rectangular arrangement in the HSV color wheel, converted for LaTeX via the xcolor package.  Analogous regions, such as the triangles, are in the nearby colors blue and green.  Less saturated colors are on the left page, where there are large regions of solid color.  Fully saturated colors are on the right page, where the colors are in small dots.  The real test of color will come when I print this out, along with another half-dozen copies with other rectangular tetrads of color, and see what looks the best.