More ENIGMAWhat I want to discuss in this feature is one part of Enigma operation that has been much written about elsewhere, but which still causes some confusion. This is the way in which key presses lead to rotor motion....
Bill Casselman
Introduction
Stated mathematically, you'd like to find a solution to the equation \[ 11x + 21 y= 100 \] where $x$ and $y$ are nonnegative integers. More generally, suppose we are in a country whose currency consists of denominations of $a_1, a_2, \ldots, a_d$ and ask if we can pay a bill of $n$ without needing change. In other words, can we find nonnegative integers $x_1,x_2,\ldots, x_d$ such that \[a_1x_1 + a_2x_2 + \ldots + a_dx_d = n?\] This problem arises in other ways as well. For instance, postage stamps come in a limited number of denominations so we need to solve this equation to mail a package with exact postage. American football allows scores of 2, 3, 6, 7, and 8 points; if we see that a team has scored 31 points, we feel fairly confident they have scored four touchdowns and a field goal. Until recently, McDonald's Chicken McNuggets came in boxes with 6, 9, or 20 McNuggets presenting us with the Chicken McNugget problem. As we'll see, with a mild assumption on the denominations, there are only finitely many values of $n$ for which there are no solutions. Determining the largest such $n$ is sometimes called the Frobenius problem, named after the 19^{th} century mathematician Ferdinand Georg Frobenius, who is said to have originally discussed this problem. This article presents a solution to the Frobenius problem in the simplest case that there are two denominations of currency. Though the problem seems like one from discrete mathematics, we will see an unexpected interplay between the continuous and discrete worlds as we use somewhat elementary techniques from calculus to arrive at a solution.
The case when $d=2$We will begin with the simplest case in which there are only two denominations of currency, which we will denote by $a$ and $b$. Our question is then: given a nonnegative integer $n$, can we find nonnegative integers $x$ and $y$ such that \[ax + by = n.\] If there is a solution, we say that $n$ is representable. When $a$ and $b$ are not relatively prime, we may easily find numbers that are not representable. For instance, if $a$ and $b$ are even, then any odd number is not representable. To prevent this kind of situation, we will therefore require that $a$ and $b$ are relatively prime. Of course, the general case can be reduced to this one by dividing out the greatest common divisor. In the case that $a$ and $b$ are relatively prime, the Euclidean algorithm implies that there are integers $p$ and $q$ such that $ap + bq = 1$. However, it is not possible for both $p$ and $q$ to be nonnegative. For instance, if $a=5$ and $b = 8$, we have $(3)a + 2b = 1$. In other words, if we need to pay a 1unit check, we could pay with two 8unit bills and receive three 5unit bills as change. However, we could not pay with exact change. This problem has a geometric interpretation that is useful to keep in mind. The equation $ax + by = n$ describes a line in the plane; shown below are two such lines when $a=4$ and $b=7$.
The integer $n$ is representable precisely when a point on the integer lattice lies on the line $ax+by=n$. In the case when $a=4$ and $b=7$, we see that $n=10$ is not representable, while $n=19$ is. The following figure considers all possible $n$. Lines corresponding to representable integers $n$ are gray, and those corresponding to nonrepresentable integers are red.
This figure validates an intuitive notion that says larger values of $n$ are more likely to be representable than smaller values. In fact, there are only finitely many $n$ that are not representable. The largest such $n$ is called the Frobenius number and will be denoted $g(a,b)$; in the case that $a=4$ and $b=7$, the figure shows that the Frobenius number $g(4,7)=17$.
We will develop an expression for the Frobenius number in the case that $d=2$.
The restricted partition function and its generating functionIn an effort to find which $n$ are representable, we will take two seemingly ambitious steps. First, let's not just ask if a number $n$ is representable; let's ask how many solutions there are to the equation $ax+by=n$. We define the restricted partition function $\partitionn$ to be the number of nonnegative integral solutions $(x,y)$. The integer $n$ is representatble precisely when $\partitionn > 0$. Second, rather than focusing on $\partitionn$ for a single value of $n$, let's consider them all at once. We will do so by creating the restricted partition function's generating function: \[ \begin{eqnarray*} f(z) &=& \sum_{n=0}^\infty \partitionn z^n \\ & = & \partition{0}+\partition{1} z+\partition{2} z^2 + \ldots + \partitionn z^n + \ldots \\ \end{eqnarray*} \] At this time, let's not worry about the values of $z$ for which this infinite power series converges. It will, however, be useful to remember the geometric series: \[ \frac1{1z^c} = 1 + z^c + z^{2c} + \ldots + z^{ck} +\ldots= \sum_{k\geq0}z^{ck}, \] which holds when $z < 1$. Now remember that $\partitionn$ is the number of nonnegative integral solutions to the equation $ax + by = n$. In other words, $\partitionn$ is the number of nonnegative pairs $(j, k)$ such that $aj + bk = n$. With this observation, we may rewrite the generating function as \[ \begin{eqnarray*} f(z) & = & \sum_{j\geq 0}\sum_{k\geq0} z^{aj+bk} \\ & = & \sum_{j\geq 0}z^{aj} \sum_{k\geq0} z^{bk} \\ & = & \frac{1}{1z^a}\frac{1}{1z^b}. \end{eqnarray*} \] In other words, we have \[ \frac{1}{(1z^a)(1z^b)} = \partition{0}+\partition{1} z+\partition{2} z^2 + \ldots + \partitionn z^n + \ldots. \] By the way, this shows that the infinite series defining $f(z)$ converges when $z<1$ so that we may view $f(z)$ as an analytic function around $z=0$. It looks like we're making progress. Let's now go back and focus on a specific value of $n$, which we will isolate by dividing by $z^n$: \[ \begin{eqnarray*} \frac{1}{(1z^a)(1z^b)z^n} &=& \frac{\partition{0}}{z^n}+ \frac{\partition{1}}{z^{n1}}+ \ldots + \frac{\partition{n1}}{z}+ \\ & & \partitionn + \partition{n+1}z + \ldots. \end{eqnarray*} \] This operation exchanges our infinite power series for a Laurent series, which includes negative powers of $z$. The term we seek, $\partitionn$, is the constant term of this series.
A partial fraction expansionFrom this point, our strategy is to find a partial fraction expansion of the left hand side of expression above. To this end, remember that the roots are $1z^a$ are given by the $a^{th}$ roots of unity, $\zeta_a^j=e^{2\pi i j/a}$ for $j=0,1,2,\ldots,a1$. There is, of course, one special root: when $j=0$, $\zeta_a^0 = 1$. We therefore arrive at the factorization \[ 1z^a=(z^a1) = \prod_{j=0}^{a1}(z\zeta_a^j) =(z1)\prod_{j=1}^{a1}(z\zeta_a^j), \] which, assuming $a$ and $b$ are relatively prime, leads to the partial fraction expansion \[ \begin{eqnarray*} \frac1{(1z^a)(1z^b)z^n} &=& \frac1{z^n(z1)^2\prod_{j=1}^{a1}(z\zeta_a^j)\prod_{k=1}^{b1} (z\zeta_b^k)} \\ & = & \frac{A_1}z + \frac{A_2}{z^2} + \ldots + \frac{A_n}{z^n} \\ & & + \frac{B_1}{z1}+\frac{B_2}{(z1)^2} \\ & & + \sum_{j=1}^{a1} \frac{C_j}{z\zeta_a^j} + \sum_{k=1}^{b1} \frac{D_k}{z\zeta_b^k}. \end{eqnarray*} \] Let's compare this expression to the one we previously found: \[ \begin{eqnarray*} \frac{1}{(1z^a)(1z^b)z^n} &=& \frac{\partition{0}}{z^n}+ \frac{\partition{1}}{z^{n1}}+ \ldots + \frac{\partition{n1}}{z}+ \\ & & \partitionn + \partition{n+1}z + \ldots. \end{eqnarray*} \] The restricted partition function $\partitionn$ appears as the constant term of this Laurent series. We may neglect the negative powers of $z$ to see that: \[ \begin{eqnarray*} \partitionn & = & \left.\left(\frac{B_1}{z1}+\frac{B_2}{(z1)^2} + \sum_{j=1}^{a1} \frac{C_j}{z\zeta_a^j} + \sum_{k=1}^{b1} \frac{D_k}{z\zeta_b^k}\right)\right_{z=0} \\ & = & B_1 + B_2  \sum_{j=1}^{a1} \frac{C_j}{\zeta_a^j}  \sum_{k=1}^{b1} \frac{D_k}{\zeta_b^k} \end{eqnarray*} \] Therefore, to compute the restricted partition function $\partitionn$, we only need to evaluate the coefficients $B_1$, $B_2$, $C_j$ and $D_k$ in the partial fraction expansion: \[ \begin{eqnarray*} \frac1{(1z^a)(1z^b)z^n} &=& \frac1{z^n(z1)^2\prod_{j=1}^{a1}(z\zeta_a^j)\prod_{k=1}^{b1} (z\zeta_b^k)} \\ & = & \frac{A_1}z + \frac{A_2}{z^2} + \ldots + \frac{A_n}{z^n} \\ & & + \frac{B_1}{z1}+\frac{B_2}{(z1)^2} \\ & & + \sum_{j=1}^{a1} \frac{C_j}{z\zeta_a^j} + \sum_{k=1}^{b1} \frac{D_k}{z\zeta_b^k}, \end{eqnarray*} \]
Computing the restricted partition functionWe will begin with $B_2$. Multiply by $(z1)^2$ and let $z\to 1$ to obtain: \[ B_2 = \lim_{z\to1} \frac{(z1)^2}{(1z^a)(1z^b)z^n}. \] Applying l'Hôpital's rule twice shows that $B_2 = \frac1{ab}$. We may find $B_1$ in a similar way. Subtract $B_2/(z1)^2$ from both sides of the equation, multiply by $z1$ and let $z\to 1$. This gives: \[ B_1 = \lim_{z\to 1}\left(\frac{z1}{(1z^a)(1z^b)z^n}  \frac{\frac1{ab}}{(z1)^2}\right). \] Applying l'Hôpital's rule three times shows that \[ B_1 = \frac1{ab}  \frac1{2a}  \frac1{2b} \frac n{ab}. \] Finally, the coefficients $C_j$ may be computed by multiplying by $z\zeta_a^j$ and letting $z\to\zeta_a^j$. A dose of l'Hôpital's rule shows that \[ \begin{eqnarray*} C_j&=&\lim_{z\to\zeta_a^j}\frac{z\zeta_a^j}{(1z^a)(1z^b)z^n} \\ &=&\frac1{a\zeta_a^{j(a1)}(1\zeta_a^{jb})\zeta_a^{jn}} \\ &=&\frac1{a\zeta_a^{j}(1\zeta_a^{jb})\zeta_a^{jn}} \\ &=&\frac1{a(1\zeta_a^{jb})\zeta_a^{j(n1)}}. \end{eqnarray*} \] Similarly, \[ D_k=\frac1{b(1\zeta_b^{ja})\zeta_b^{k(n1)}}. \] Finally, if we remember that \[ \partitionn = B_1 + B_2  \sum_{j=1}^{a1} \frac{C_j}{\zeta_a^j}  \sum_{k=1}^{b1} \frac{D_k}{\zeta_b^k}, \] then we arrive at \[ \partitionn = \frac1{2a} + \frac1{2b} + \frac n{ab} + \frac1a \sum_{j=1}^{a1}\frac1{(1\zeta_a^{jb})\zeta_a^{jn}} + \frac1b \sum_{k=1}^{b1}\frac1{(1\zeta_b^{ja})\zeta_b^{kn}}. \]
Computing the FourierDedekind sumsThe terms of the form \[ \frac1a \sum_{j=1}^{a1}\frac1{(1\zeta_a^{jb})\zeta_a^{jn}} \] appearing in our expression for $\partitionn$ are examples of FourierDedekind sums. Though it is useful to note that these sums may be evaluated as Fourier transforms, we will evaluate them using a simpler observation. Remembering that \[ \partitionn = \frac1{2a} + \frac1{2b} + \frac n{ab} + \frac1a \sum_{j=1}^{a1}\frac1{(1\zeta_a^{jb})\zeta_a^{jn}} + \frac1b \sum_{k=1}^{b1}\frac1{(1\zeta_b^{ja})\zeta_b^{kn}}, \] we consider the case where $b=1$ to find \[ p_{\{a,1\}}(n) = \frac1{2a}+\frac12 + \frac n{a} + \frac1a \sum_{j=1}^{a1}\frac1{(1\zeta_a^{j})\zeta_a^{jn}}. \] However, the restricted partition function $p_{\{a,1\}}(n)$ is easily understood in this case; it is the number of nonnegative solutions $(x,y)$ to $ax + y = n$. There is one solution for each $x$ such that $0\leq x \leq \frac na$. In other words, $p_{\{a,1\}}(n)$ equals the number of integers in the closed interval $[0,\frac na]$. If we use $\lfloor z\rfloor$ to denote the greatest integer less than or equal to $z$, then we have \[p_{\{a,1\}} = \left\lfloor \frac na\right\rfloor + 1,\] and so \[ p_{\{a,1\}}(n) = \left\lfloor \frac na\right\rfloor + 1 = \frac1{2a}+\frac12 + \frac n{a} + \frac1a \sum_{j=1}^{a1}\frac1{(1\zeta_a^{j})\zeta_a^{jn}}. \] This implies that \[ \begin{eqnarray*} \frac1a \sum_{j=1}^{a1}\frac1{(1\zeta_a^{j})\zeta_a^{jn}} & = & \left\lfloor \frac na\right\rfloor +\frac12\frac1{2a}  \frac n{a} \\ & = & \fractional{\frac na} + \frac 12  \frac1{2a}, \end{eqnarray*} \] where $\fractional{z} = z  \lfloor z \rfloor$ is the fractional part of $z$. We may apply this to evaluate the FourierDedekind sum appearing in our general expression for $\partitionn$. Since $a$ and $b$ are relatively prime, we may find $b^{1}$ where $b\cdot b^{1} \equiv 1 \bmod{a}$ and sum over $j'=jb$ to see that \[ \frac1a \sum_{j=1}^{a1}\frac1{(1\zeta_a^{jb})\zeta_a^{jn}} = \frac1a \sum_{j'=1}^{a1}\frac1{(1\zeta_a^{j'})\zeta_a^{j'b^{1}n}} = = \fractional{\frac {b^{1}n}a} + \frac 12  \frac1{2a}. \] After all this, we may rewrite the FourierDedekind sums in our expression for $\partitionn$ to arrive at the following remarkable formula known as
Let's look at an example when $a=4$, $b=7$ and $n=107$. In this case, we have $2a + (1)b = 1$, which means we may take $a^{1} = 2$ and $b^{1} = 1$. Therefore, \[ \begin{eqnarray*} p_{\{4,7\}} &=& \frac{107}{4\cdot7}\fractional{\frac{107}{4}} \fractional{\frac{2\cdot107}{7}} + 1 \\ &=&\frac{107}{28}\frac14\frac47+1 \\ &=&4+\frac{23}{28}\frac14\frac47 \\ &=&4. \end{eqnarray*} \] There are then four ways of representing 107 as a linear combination of 4 and 7: \[ 107=4\cdot4+13\cdot7=11\cdot4+9\cdot7=18\cdot4+5\cdot7=25\cdot4+1\cdot7. \]
The Frobenius numberWe noted earlier that it seems clear that there are only finitely many integers $n$ that are not representable and we called the largest nonrepresentable integer the Frobenius number. Popoviciu's theorem tells us that $\partitionn$ grows in a roughly linear fashion, which, as we'll now see, explains why there are only finitely many nonrepresentable integers. First, observe: if $p$ is an integer, then $\fractional{\frac pa}$ belongs to the set $\{0, \frac 1a,\frac 2a, \ldots, \frac{a1}{a}\}$, which implies that $\fractional{\frac pa} \leq\frac{a1}a.$ Let's now consider \[ \begin{eqnarray*} \partitionn &=&\frac n{ab}  \fractional{\frac{b^{1}n}{a}}  \fractional{\frac{a^{1}n}{b}} + 1 \\ &\geq&\frac{n}{ab}\frac{a1}{a}\frac{b1}{b}+1 \\ &\geq&\frac{n(a1)b(b1)a+ab}{ab} \\ &\geq&\frac{n[abab]}{ab} \end{eqnarray*} \] This shows that if $n> abab$, then $\partitionn>0$ and so $n$ is representable. In other words, we have found an upper bound for the nonrepresentable integers, and the Frobenius number will be less than or equal to $abab$. We can do still more. If you play around with our expression for $\partitionn$, you may begin to notice a symmetry. To see this, first note that $\fractional{x} = 1\fractional{x}$ if $x$ is not an integer. Assuming that $n< ab$ and $n$ is divisible by neither $a$ nor $b$, we have \[ \begin{eqnarray*} p_{(a,b)}(abn)&=&\frac{abn}{ab}\fractional{\frac{b^{1}(abn)}{a}}  \fractional{\frac{a^{1}(abn)}{b}} + 1 \\ &=&2  \frac{n}{ab} \fractional{\frac{b^{1}n}{a}}  \fractional{\frac{a^{1}n}{b}} \\ &=&\frac{n}{ab}+\fractional{\frac{b^{1}n}{a}}+ \fractional{\frac{a^{1}n}{b}} \\ &=&1p_{(a,b)}(n) \\ \end{eqnarray*} \] In other words, we have \[ p_{(a,b)}(n) + p_{(a,b)}(abn) = 1 \] if $n$ is not divisible by either $a$ or $b$. Keeping in mind that the restricted partition function is nonnegative, we conclude that when $n< ab$ and $n$ is not divisible by either $a$ or $b$, then exactly one of the integers $n$ or $abn$ is representable. With this observation in hand, we may determine the Frobenius number by considering $n=a+b = 1\cdot a + 1\cdot b$. Therefore, $n=a+b$ is representable and divisible by neither $a$ nor $b$. This means that $ab(a+b) = abab$ is not representable. Since we previously saw that $n$ is representable whenever $n> abab$, we have found the Frobenius number.
This is consistent with the earlier example in which we saw that the Frobenius number $g(4,7) = 4\cdot747 = 17$.
More than two denominationsSome of what we have done immediately applies when there are more than two denominations of currency. For instance, the restricted partition function is found in precisely the same way; if we have denominations $a$, $b$, and $c$, then \[ p_{\{a,b,c\}}(n) = \hbox{the constant term in} \frac1{(1z^a)(1z^b)(1z^c)z^n}. \] Proceeding as before, we find: \[ \begin{eqnarray*} p_{\{a,b,c\}}(n)&=&\frac{n^2}{2abc} + \frac n2\left(\frac1{ab} + \frac 1{ac} + \frac1{bc}\right) + \frac 1{12}\left(\frac 3a+\frac3b + \frac 3c + \frac a{bc} + \frac b{ac}+\frac c{ab}\right) \\ & & + \frac 1a\sum_{k=1}^{a1}\frac1{(1\zeta_a^{kb})(1\zeta_a^{kc}) \zeta_a^{kn}} + \frac 1b\sum_{k=1}^{b1}\frac1{(1\zeta_b^{kc})(1\zeta_b^{ka}) \zeta_b^{kn}} \\ & & + \frac 1c\sum_{k=1}^{c1}\frac1{(1\zeta_c^{ka})(1\zeta_c^{kb}) \zeta_c^{kn}} \end{eqnarray*} \] Given the success we've had in finding the Frobenius number when $d=2$ with rather elementary methods, it seems natural to think that, with some more work, we can find a general formula for the Frobenius number $g(a, b, c)$ when $d=3$. Unfortunately, this problem seems to be much more difficult: there is no general formula known for the Frobenius number when $d\geq 3$. Worse yet, RamírezAlfonsín has shown that solving the Frobenius problem is NPhard, if we allow a general list of denominations $a_1,a_2,\ldots,a_d$ to be input. However, Kannan showed that there is an algorithm that completes in polynomial time for any fixed value of $d$, which means that the Frobenius number can be efficiently computed if we fix the number of denominations. To give an indication of how such an algorithm works, I will present an idea of Nijenhuis that constructs a weighted graph and then computes the Frobenius number by applying Dijkstra's algorithm to find minimal weight paths. If we have denominations $a_1,a_2,\ldots, a_d$, we form a graph whose vertices are the integers $0,1,2,\ldots,a_11$, which may be thought of as the residue classes of $a_1$. There is a directed edge with weight $a_j$ from vertex $v$ to vertex $w$ if $w\equiv v+a_j\bmod{a_1}$, where $j\geq 2$. For each vertex $v\not\equiv0$, we use Dijkstra's algorithm to find the path from 0 to $v$ having the smallest possible weight, which we denote by $w_v$. It is now relatively straightforward to see that the largest nonrepresentable integer congruent to $v$ is $w_va_1$. Therefore, the Frobenius number $g(a_1,a_2,\ldots, a_d)=\max_{v\not\equiv0} w_va_1$.
SummaryAs mentioned previously, it is remarkable that the solution to a counting problem may be found using techniques from calculus. However, this is not the only place that the continuous and discrete come together. This article is adapted from the first chapter of the book Computing the Continous Discretely, written by Matthias Beck and Sinai Robins, which introduces readers to many beautiful, and sometimes deep, ideas that illustrate this theme.
References
Bill Casselman The AMS encourages your comments, and hopes you will join the discussions. We review comments before they're posted, and those that are offensive, abusive, offtopic or promoting a commercial product, person or website will not be posted. Expressing disagreement is fine, but mutual respect is required.

Welcome to the These web essays are designed for those who have already discovered the joys of mathematics as well as for those who may be uncomfortable with mathematics. Search Feature Column Feature Column at a glance 
Comments: Email Webmaster 
© Copyright
, American Mathematical Society


