One of the tools I use to make figures for papers and books—if I need to make a graph, of course—is Graphviz. Graphviz is flexible, powerful, but also a rather finicky beast that will repeatedly bite your fingers. Today, I’ll share some of my tricks with you.

## The Zero Frequency Problem (Part I)

September 23, 2014In many occasions, we have to estimate a probability distribution from observations because we do not know the probability and we do not have enough *a priori* knowledge to infer it. An example is text analysis. We may want to know the probability distribution of letters conditional to the few preceding letters. Say, what is the probability of having ‘a’ after ‘prob’? To know the probability, we start by estimating frequencies using a large set of observations—say, the whole Project Gutenberg ASCII-coded English corpus. So we scan the corpus, count frequencies, and observe that, despite the size of the corpus, some letter combinations weren’t observed. Should the corresponding probability be zero?

## Jouette’s Attractor

September 16, 2014I have been reading a lot of mathematical recreation books of late. Some in English, some in French, with the double goal of amusing myself and of finding good exercises for my students. In [1], we find the following procedure:

Take any number, digits long, make this number . Make the number made of the sorted (decreasing order) digits of , and , the number made of the sorted (increasing order) digits of . Subtract both to get : . Repeat until you find a cycle (i.e., the computation yields a number that have been seen before).

Jouette states that for 2 digits, the cycle always starts with 9, for 3 digits, it starts with 495, for 4 digits, 6174, and for 5 digits, 82962. For 2, 3, and 4 digits, he’s mostly right, except that the procedure can also reach zero (take 121 for example: 211-112=99, 99-99=0). For 5 digits, however, he’s really wrong.

## Perfect Hashing (part I)

September 9, 2014A few days ago, a friend asked me how to write, if even possible, a hash function that had no collisions. Of course, it’s relatively easy to get a reasonably good hash function that will give the expected amount of collisions (especially when used as usual, modulo the size of the table). But what if we do not want collisions at all? What can we do?

There are some hash functions, known as perfect hash function, that will yield a different hash for every key from a *a priori* known set of keys, say . Are they hard to build? Fortunately, not really. Can we exploit the uniqueness of the hashed value to speed look-ups up? Yes, but it’s a bit more complicated.

## Take That, Fermat!

September 2, 2014You’ve certainly heard of Fermat’s last theorem stating that

has no integer solutions for . Well, guess what:

.

Take that, Fermat!

## Suggested Reading: *The Simpsons and their Mathematical Secrets*

June 8, 2014Simon Singh — *The Simpsons and Their Mathematical Secrets* — Bloomsbury, 2013, 255 pp. ISBN 978-1-62040-277-1

Using, as an excuse, the fact that *The Simpsons* (and their sister series *Futurama*) use mathematics as part of the plot or as a “frame freeze gag” (a gag that is so short that unless you look at the show frame by frame, you might miss it), Singh (which you may remember from books such as *The Code Book* and *Fermat’s Last Theorem*) brings us along a mathematical walk, presenting us the mathematically-inclined writers of the shows. But, as I said, *The Simpsons* are merely a convenient excuse to introduce mathematics and theorems: if you expect to learn a lot about *The Simpsons* themselves, you’d be disappointed. The book is about the mathematics and the writers.

However, it’s an interesting read: prime numbers, , combinatorics, computation and algorithmics. I especially liked the Futurama Theorem that describes how, using a mind-swapping machine that can swap minds between two same individuals once only, we can un-scramble minds and bodies and put every one in their rightful body (not a new plot device, Stargate did it first, in s02e18).

## Suggested Reading: *How Mathematics Happened: The First 50000 Years*

May 19, 2014Peter S. Rudman — *How Mathematics Happened: The First 50000 Years* — Prometheus Books, 2006, 314 pp. ISBN 978-1-59102-477-4

What first got me interested in this book is the “50000 years” part. I was preparing lectures notes for my course on discrete mathematics and I wanted my students to have an idea of what prehistoric maths might have been, say, 20000 years ago. Unfortunately, you wont learn much about this in this book

The book does hint about what mathematics might have been in hunter-gatherer times, and how it might have affected later developments. But that lasts for about a chapter or so, and the remainder is devoted to historical mathematics: Ancient Egyptian, Babylonian, and Classical Greek. All kinds of numerical algorithms are covered, presented in great detail, making the book more technical than historical. Some part are speculative as the historical record is incomplete at best, but it is speculative in the best way possible, with every assumption backed by an actual historical observation.