## Secret Santa (Now with Fewer Hats!)

As we approach the holiday season, some of you may soon participate in—or perhaps even organize—a “Secret Santa” exchange. Specifically, some number of people enter the exchange, and each is assigned one person (their Santee) to give a gift to (or multiple gifts… or other craziness…), in such a way that each person also receives from one person (their Santa). As organizers of such an exchange, how should we choose a permutation of the participants, i.e., an assignment of each person to his/her Santee? Here’s one method: put all names in a hat, and let each player extract a name at random. What could go wrong?

For starters, someone might pick their own name! Shopping for yourself might make the task easier, but this seems to contradict the (Christmas) spirit of the exchange. If we pick randomly as above, and if there are $$n$$ people in the exchange, what is the probability that no one picks him/herself? For large $$n$$, this answer tends toward $$1/e = .3679\ldots$$, where $$e = 2.718\ldots$$ is Euler’s number. So, with more than a 63 percent chance, someone is left out. (See below for a proof of this fact.)

What else might go wrong? Perhaps we also want to avoid two people being assigned each other, so that this pair doesn’t feel excluded. What is the chance of a randomly chosen permutation having no excluded person or pair? This can be computed to tend toward $$1/e^{3/2} = .2231\ldots$$, so there is some left out person or pair with almost 80% probability. And if we wish to make sure there are no excluded groups of size at most 6, say, then the chance of failure limits to $$1-e^{-1-\frac{1}{2}-\frac{1}{3}-\frac{1}{4}-\frac{1}{5}-\frac{1}{6}} = .9137$$ for large $$n$$.

So, while Santa hats may be fluffy and festive, Secret Santa hats are a bad idea. What should we do to organize our exchange? Here’s one option: just make a big cycle. Specifically, write all names in some random order and chain them up, e.g., $$2\to 6\to 7\to 3\to 1\to 4\to 5\to 2$$ (if the “names” are just 1, 2, …, 7).

### Where do these numbers come from?

How can we compute the probabilities mentioned above? One common method to prove the $$1/e$$ probability uses the principle of Inclusion-Exclusion, but here is a sketch of an argument that doesn’t rely on this technique. Let $$A_n$$ be the number of permutations of $$n$$ people with no person assigned to him/herself. Such a permutation is called a Derangement, and a direct counting argument can be used to show that $$A_n = (n-1)(A_{n-1} + A_{n-2})$$ (see the Wikipedia page for derangements, for example). As there are $$n!$$ total permutations of the players, the desired probability is $$P_n = A_n/n!$$, so the above formula can be manipulated to $$P_n-P_{n-1} = -\frac{1}{n}(P_{n-1}-P_{n-2})$$. This produces $$P_n-P_{n-1} = \frac{(-1)^n}{n!}$$ by induction, so we obtain $$P_n = 1-\frac{1}{1!}+\frac{1}{2!}-\frac{1}{3!}+\cdots+\frac{(-1)^n}{n!}.$$ As $$n$$ gets big this value tends toward the infinite sum $$\sum_{i=0}^\infty \frac{(-1)^i}{i!} = 1/e$$.

The other probabilities mentioned take more work. A well-suited tool is that of (Exponential) Generating Functions, which in this case help organize a more complicated Inclusion-Exclusion argument. Using these, it can be shown that the probability that a random permutation of $$n$$ players has no groups of size 6 or less is equal to the coefficient of $$x^n$$ in the power series expansion of $$\frac{1}{1-x}\cdot e^{-\left(x+\frac{x^2}{2} + \cdots + \frac{x^6}{6}\right)}.$$

## Some Strange Sums

If someone told you to compute the value of the infinite sum $$Z = 1+2+3+4+\cdots$$, you would tell them that it simply does not converge. But what if they insisted that you assign a finite value to this sum? Which value would you give? Is there any way to make sense of this question? Yes, and the answer is $$-1/12$$.

Before tackling this sum, let’s try a slightly easier one, known as Grandi’s Series: $$G = 1-1+1-1+\cdots$$. How can we compute its value? Let’s write \begin{align*}G &= 1-1+1-1+1-\cdots \text{ and}\\ G &= 0+1-1+1-1+\ldots,\end{align*} and adding these term by term gives $$2G = 1+0+0+0+0+\cdots = 1$$, i.e., $$G = 1/2$$. So we got a value! The same “trick” lets us sum $$H = 1-2+3-4+\cdots$$ like this: \begin{align*}2H &= 1 + (-2+1) + (3-2) + (-4+3) + \cdots\\ &= 1-1+1-1+\cdots\\ &= G = 1/2,\end{align*} so $$H = 1/4$$.

What’s really going on here? A good way to understand it is to look at the functions $$g(x) = 1-x+x^2-x^3+\cdots$$ and $$h(x) = 1-2x+3x^2-4x^3+\cdots$$, and to realize that we’re asking for $$g(1)$$ and $$h(1)$$, respectively. The sum defining $$g(x)$$ converges for $$-1 < x < 1$$, and since $$g(x) + x \cdot g(x) = 1$$ (this is just the "trick" from above!), we find $$g(x) = 1/(1+x)$$. So, even though the sum defining $$g(1) = 1-1+1-\cdots$$ does not converge, the limit as $$x$$ approaches 1 from below is well defined and equals $$1/(1+1) = 1/2$$. Likewise, we find that $$h(x) = 1/(1+x)^2$$ for $$-1 < x < 1$$, and the limit as $$x$$ goes to 1 is 1/4. This method of putting the terms as the coefficients of a power series and extrapolating with limits is called Abel Regularization. Notice, however, that this method does not work for the sum $$Z$$, because $$1 + 2x + 3x^2 + 4x^3 + \cdots = 1/(1-x)^2$$, and the limit as $$x$$ approaches 1 is still infinite.

A different method of summing divergent series is called Zeta Function Regularization: to compute $$a_1 + a_2 + a_3 + \cdots$$, define the function $$a_1^{-s} + a_2^{-s} + a_3^{-s} + \cdots$$ (which hopefully converges for large enough s), and try to “extend” this to a function we can evaluate at $$s=-1$$. For example, for $$H = 1-2+3-\cdots$$, the corresponding function $$1/1^2-1/2^s+1/3^s-\cdots$$ is called the Dirichlet Eta Function, $$\eta(s)$$. Analysis based on our “trick” from above (iterated infinitely many times! [producing the so-called Euler Transform]) can be used to show that $$\eta(s)$$ can be defined for all values $$s$$ (even complex values!) and that $$\eta(-1) = 1/4$$, which agrees with our computation of $$1-2+3-4+\cdots$$ above. The corresponding function for the sum $$Z$$ is called the Riemann Zeta Function, $$\zeta(s)$$, and we can compute (for all $$s$$ where this makes sense): $$\begin{gather*} \zeta(s) = \frac{1}{1^s} + \frac{1}{2^s} + \frac{1}{3^s} + \frac{1}{4^s} + \cdots,\\ 2^{-s} \zeta(s) = \frac{1}{2^s} + \frac{1}{4^s} + \frac{1}{6^s} + \frac{1}{8^s} + \cdots, \text{ and so}\\ \zeta(s)-2\cdot 2^{-s} \zeta(s) = \frac{1}{1^s}-\frac{1}{2^s}+\frac{1}{3^s}-\frac{1}{4^s}+\cdots = \eta(s).\end{gather*}$$ So $$(1-2^{1-s}) \zeta(s)$$ equals $$\eta(s)$$ everywhere (by general complex analysis facts). At $$s = -1$$, this says $$\zeta(-1) = \eta(-1)/(-3) = -1/12$$, as claimed.

## A “Frac”ing Prime Generator

Last week we saw a few ways to (try to) generate prime numbers with simple formulas. I will now describe a much more puzzling (and recreational) method. The following numbers specify everything you need: $$\left(\frac{17}{91}, \frac{78}{85}, \frac{19}{51}, \frac{23}{38}, \frac{29}{33}, \frac{77}{29}, \frac{95}{23}, \frac{77}{19}, \frac{1}{17}, \frac{11}{13}, \frac{13}{11}, \frac{15}{14}, \frac{15}{2}, \frac{55}{1} \right).$$ To run this “game,” the rules are as follows: Start with value $$v = 2$$. At each step, find the first fraction $$f$$ in the list so that $$v \cdot f$$ is an integer, and replace the value $$v$$ by this integer. Repeat indefinitely (or until no such $$f$$ can be found). The beginning of the computation looks like this:

1. Start with value $$v = 2$$.
2. The first fraction $$f$$ in the list such that $$2\cdot f$$ is an integer is $$f=15/2$$, so the new value $$v$$ is $$2 \cdot 15/2 = 15$$.
3. The first $$f$$ in the list with $$15 \cdot f$$ an integer is $$f=55/1$$, so the new $$v$$ is $$15 \cdot 55/1 = 825$$.
4. The first $$f$$ with $$825 \cdot f$$ an integer is $$29/33$$, so set $$v = 825 \cdot 29/33 = 725$$.

And so on.

Continuing as above, the list of values looks like 2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132, 116, 308, 364, 68, 4, 30, 225, 12375, … .

But what does this have to do with primes? The list of fractions was carefully constructed so that many powers of 2 will appear, in exactly the following order: $$2^1, 2^2, 2^3, 2^5, 2^7, 2^{11}, 2^{13}, 2^{17}, \ldots .$$ Indeed, except for $$2^1$$ (the starting value), any power of two obtained by this process will have a prime exponent, and all primes will appear in this way (in order)! This is a very special property of the chosen list of fractions, and different lists give rise to vastly different output sequences.

In fact, you can think of this procedure as a programming language, where the list of fractions and the starting value constitute your “program.” This language is called FRACTRAN, and both the language and the above prime-enumerating program were designed by John Conway. What else is this language capable of computing? Lots! FRACTRAN can compute anything that modern computers could—but much less efficiently. (In Theoretical Computer Science terminology, FRACTRAN is turing complete.) See the Wikipedia page for more information, as well as an explanation of why the above program works.

## Generating Primes with Formulas

Prime numbers—namely, positive integers with no divisors other than 1 and themselves—have long fascinated mathematicians. As a result, there have been many attempts at formulas to generate prime numbers. For example, the polynomial $$x^2-x+41$$ spits out a prime number for $$x = 0, 1, 2, …, 40$$. But for $$x = 41$$, the value is $$41^2$$, which is not prime. Can we find some nonconstant polynomial $$f(x)$$ with integer coefficients that only spits out prime values? (The constant polynomial $$f(x) = 2$$ always returns a prime, but this is not very interesting.) In a word: No. There is no such polynomial. To prove this, assume $$f$$ is such a polynomial. Then $$f(0) = p$$ for some prime $$p$$, and all of the numbers $$\{f(p), f(2p), f(3p), \ldots \}$$ are divisible by $$p$$. This sequence grows toward infinity, so one of them is greater than $$p$$. Since this number has a factor of $$p$$, it is not prime.

What if we switch from polynomials to exponents? Maybe the function $$2^m + 1$$ will give us lots of primes. It can be shown that if $$2^m + 1$$ is prime then $$m$$ itself has to be a power of 2. (Indeed, if a prime $$p > 2$$ divides $$m$$, check that $$2^{m/p} + 1$$ divides $$2^m + 1$$.) So the only possibilities are the numbers $$F_n = 2^{2^n} + 1$$, which are called Fermat numbers. The first few are \begin{align*} F_0 &= 3,\\ F_1 &= 5,\\ F_2 &= 17,\\ F_3 &= 257,\\ F_4 &= 65537. \end{align*} It was long believed that all Fermat numbers were prime (Fermat himself conjectured this!), but in fact the very next one, $$F_5 = 4294967297 = 641 \cdot 6700417$$, is composite. (In Fermat’s defense, this is a large number to factor by hand!) Are there at least infinitely many Fermat primes? We currently don’t know. In fact, the Fermat primes shown above are the only known Fermat primes!

Similarly, numbers of the form $$2^n-1$$ are called Mersenne numbers. In order for this to be prime, it is necessary for $$n$$ itself to be prime. (Indeed, if $$a$$ divides $$n$$ then $$2^a-1$$ divides $$2^n-1$$.) So is $$2^p-1$$ prime for every prime $$p$$? Unfortunately, no: $$2^{11}-1$$ is not prime. But there seem to be many Mersenne primes. Thanks to the “Great Internet Mersenne Prime Search,” a.k.a. GIMPS, there are 47 Mersenne primes known, the largest of which is $$2^{43112609}-1$$, which has 12978189 digits (in base 10).

OK, so the above “prime-generating” functions don’t work very well. Here’s one that does work. It can be shown that there is some polynomial $$Z(a, b, c, d, e, f, g, h, i, j)$$ with 10 variables and integer coefficients such that any positive output from $$Z$$ (when given integer inputs) is prime, and furthermore, every prime is obtained in this way. (Note: $$Z$$ spits out many non-positive values as well.) Unfortunately, this polynomial $$Z$$ is not very practical. For one thing, its degree is about $$38!$$. (Yes, I mean 38 factorial.)

If we consider digits instead of letters or words, then numbers such as 676, 100020001, and 12345678987654321 are palindromes. These are in fact quite special palindromes, as they are all squares of integers: $$26^2 = 676$$, $$111111111^2 = 12345678987654321$$, and $$10001^2 = 100020001$$. Are there infinitely many palindromic squares? Yes: the last example above hints that $$10\ldots01^2 = 10\ldots020\ldots01$$ for however many 0s you put in the middle. By contrast, if we ask for $$n^5$$ to be palindromic (or any higher power), then no solutions are currently known!
You might ask for other types of palindromic numbers, such as palindromic primes. A few examples include 7 (this is a palindrome!), 101, 19391, and 1000000008000000001. Are there infinitely many? We don’t know. But the largest palindromic prime currently known is $$10^{200000} + 47960506974 \cdot 10^{99995} + 1$$, according to Wikipedia.