Continued fractions, is an idea that is at once not only simple, but also one which holds within its infinite recursive folds and recesses many secrets and surprises. Perhaps dating back to remote antiquity, yet fully vigorous even today, it stands as a testament to a paradigm that is well known to mathematicians, which is that an idea may be old, but is never ruled out as having fully exhausted its possibilities. A common theme that binds the uncommon stories presented in this article is the omnipresent yet almost reticent continued fraction.
Ramanujan, Mahalanobis and The Strand Magazine
The name Srinivasa Ramanujan often invokes strong emotions in mathematicians, particularly if they happened to have worked in an area that Ramanujan’s short and incredibly romantic life (romantic only in the sense of the intensity of its pathos), touched and impacted. His name, for everybody else, learned and lay, is synonymous with an attribute that can only be called Genius. Timeless Genius.
Such reputations are of course earned. An incident that serves to burnish Ramanujan’s reputation as a man who had free access to spaces and planes of the human mind that are only dreamt of, but never realized, by most of humanity, is vividly narrated (pages 214–215) in the book The Man Who Knew Infinity by Robert Kanigel—the book that inspired the recent Hollywood movie with the same title.
The story goes as follows. The Strand Magazine, a local London publication, used to run a regular column called “Perplexities”. In the December of 1914, this column featured a puzzle titled “Puzzles at a Village Inn”, which an Indian student then in Cambridge, Prasanta Chandra Mahalanobis, brought to the attention of his friend and compatriot, Ramanujan. The puzzle:

“I was talking the other day,” said William Rogers to the other villagers gathered around the inn fire, “to a gentleman about the place called Louvain, what the Germans have burnt down. He said he knowed it well — used to visit a Belgian friend there.
He said the house of his friend was in a long street, numbered on this side one, two, three, and so on, and that all the numbers on one side of him added up exactly the same as all the numbers on the other side of him. Funny thing that! He said he knew there was more than fifty houses on that side of the street, but not so many as five hundred. I made mention of the matter to our parson, and he took a pencil and worked out the number of the house where the Belgian lived. I don’t know how he done it.”
Perhaps the reader may like to discover the number of that house.
Mahalanobis is supposed to have figured this out in a few minutes by a trial and error method. He then posed the puzzle to Ramanujan, who was cooking a meal when he heard this question. Much to his friend’s surprise, who did not have to wait long, Ramanujan asked him to take down the solution. Amazed at the spontaneous answer, Mahalanobis asked him how he did it: Ramanujan says that as soon as he heard the problem, he knew that there should be a continued fraction; and that when he asked himself which one it was, the answer apparently just came to his mind!
So, what is a continued fraction? And what could Ramanujan’s solution have been?
Let us first embark on a brief journey of the continued fractions. One normally learns to express real numbers, both rationals and irrationals, in their decimal expansions, that is, writing katex is not defined as katex is not defined and such. That is why one also tries to express the number katex is not defined, an irrational, as katex is not defined and approximate it to monstrously large decimal places but, alas, there appears to be no discernible pattern in the digits of the expansion. In this article, however, we discuss another way, perhaps a more elegant and fruitful way, of representing real numbers as “generalized” fractions, or what are mathematically known as continued fractions. Here are a few elementary examples:
- Any integer, say katex is not defined, written as a quotient is simply katex is not defined; so we need not do anything to express it as a continued fraction and leave it as katex is not defined
- Consider the rational number katex is not defined, which we could rewrite as \cfrac{22}{7}= 3 + \cfrac{1}{7}\,.
- Now, take another rational number, say, katex is not defined, and write it as
- Let us repeat the above procedure with another rational number, say, katex is not defined:
Looking at the examples above, one may be reminded of Euclid’s algorithm to find the greatest common divisor, or GCD, of any two given numbers, a procedure which involves many ideas similar to the continued fraction representation of a number.
In general, an expression of the form
a_0 + \cfrac{b_1}{a_1 + \cfrac{b_2}{a_2 + \ddots}}
where the katex is not defined and katex is not defined are integers, is called a continued fraction. When the katex is not defined are all equal to katex is not defined and katex is not defined for katex is not defined are all natural numbers, as in the examples above, we call it a simple continued fraction, or SCF.
Now, an obvious question to pose is: Can irrationals also be represented using continued fractions? The answer is yes but with a crucial difference—the continued fraction representations for rationals terminate after finitely many steps, whereas for the irrationals, the process does not end.
Here is a classic example of what we are talking about. What could the number katex is not defined below be?
Since the fractional part continues indefinitely, one can observe that the expression in the denominator of the second term on the right-hand side of the equation is actually the same as katex is not defined itself! Strange indeed, but it is true! Mathematically, this amounts to the fact that katex is not defined satisfies the equation katex is not defined; or equivalently, katex is not defined The positive root of this equation is the ubiquitous golden ratio, usually denoted as katex is not defined, and is equal to katex is not defined.
The term “golden ratio” comes from a special property: It is a ratio of two numbers that equal the ratio of their sum to the larger of the two numbers. That is, if katex is not defined are two numbers such that katex is not defined, then katex is not defined; in other words, katex is not defined satisfies katex is not defined. In the case of the golden ratio, we obtained a quadratic equation in katex is not defined from the continued fraction representation of katex is not defined.
This process can be run in reverse, i.e., one can obtain the continued fraction representation of a number from a quadratic equation. Quadratic equations can also be used to build a continued fraction representation. For example, katex is not defined, one of the earliest irrationals to be discovered, can be thought of as a root of the quadratic equation katex is not defined. This can be rewritten as
katex is not defined
Now, simply replace the katex is not defined on the right-hand side by the expression katex is not defined, which is the same as katex is not defined according to the left-hand side of the above equation. This yields
By continuing this process recursively, we see that
x=1 + \cfrac{1}{2 + \cfrac{1}{2 + \cfrac{1}{2 + \ddots}}}
In other words, we have just obtained a simple continued fraction expansion of katex is not defined. Numbers such as katex is not defined fall into the category of quadratic irrationals, which are irrational numbers that are solutions to the quadratic equation katex is not defined, where katex is not defined are rational numbers with katex is not defined. Simple continued fraction expansions exist not only for quadratic irrationals but for every real number, including katex is not defined and katex is not defined.
Of course, the simple continued fraction expansions of such irrationals contain an infinite number of terms, unlike those of rational numbers, which contain finitely many terms. However, finite could still mean a large number, depending on the rational number in question. Much like how one writes only a few decimal places of a real number, the SCF representation of any real number can be truncated at different stages, which yields rational numbers called convergents. For example, katex is not defined and katex is not defined are the first five convergents of the SCF for the golden ratio katex is not defined described earlier.
Convergents provide good approximations of real numbers. One aspect of approximating irrational numbers by rational fractions involves determining which of the fractions, differing from the given irrational within a specified degree of proximity, has the largest denominator. Such approximations are meaningful even for rational numbers—if a rational number has an extremely large numerator and denominator, one may want to approximate it by another rational number whose numerator and denominator are smaller.
Mathematically, a rational number katex is not defined is a best approximation of a real number katex is not defined if katex is not defined for rationals katex is not defined with katex is not defined and katex is not defined.
With regard to SCF representations of real numbers, it turns out that the later you truncate an SCF, the better the approximation you get. Let us denote the rational number obtained by truncating an SCF at the katex is not defined-th stage as katex is not defined; let this also be the best approximation of a real number katex is not defined. Therefore, the katex is not defined-th convergent katex is not defined in the SCF of katex is not defined is the best possible rational approximation that is closest to katex is not defined among all rational numbers with denominators less than or equal to katex is not defined. (For more on the delightful topic of continued fractions, see [6] and [8].)
Now, back to the Ramanujan–Mahalanobis story: Let us assume that the total number of houses on the particular Louvain street is katex is not defined and that the number of the particular sought-after-house is katex is not defined. The problem in The Strand Magazine, stated in mathematical terms, means that katex is not defined. Working out the two sums (using high school algebra), one gets the relation
katex is not definedor, equivalently,
katex is not definedEven more conveniently expressed, the equation to be solved in integers is katex is not defined, for katex is not defined and katex is not defined, which is a particular case of the so-called Pell’s equation, or what is now called the Brahmagupta–Pell equation. (For more on this, see the article The bhavana in Mathematics)
How does one go about solving such an equation? The answer is that some of the convergents of the continued fraction for katex is not defined provide solutions to the above equation. Let us try to elaborate a bit on this point.
The interesting case of the general Brahmagupta–Pell equation katex is not defined occurs when the integer katex is not defined is a not a square. For, if katex is not defined for some katex is not defined, then the equation katex is not defined can be written as katex is not defined, which is possible if and only if katex is not defined. Therefore, katex is not defined This means that katex is not defined and katex is not defined are the only solutions.
Therefore, non-trivial solutions of the equation katex is not defined exist only when katex is not defined is a non-square positive integer, such as katex is not defined. It turns out that if katex is not defined and katex is not defined are positive solutions of the equation, then katex is not defined is a convergent of the SCF expansion of katex is not defined. Although not all convergents provide solutions, some of the convergents do. We can see this for katex is not defined.
The convergents obtained by truncating the continued fraction for katex is not defined after the first few successive terms are
The pairs katex is not defined alternately satisfy katex is not defined and katex is not defined. In fact, the solution katex is not defined and katex is not defined gives katex is not defined and katex is not defined, which is one of the solutions described in Robert Kanigel’s book.
For The Strand Magazine puzzle, one has to find an integer katex is not defined between katex is not defined and katex is not defined and an integer katex is not defined satisfying katex is not defined. We shall now use the theory of SCF to show that katex is not defined and katex is not defined is the only solution, i.e., the number of the sought-after house is katex is not defined. Working through the successive convergents of the SCF expansion of katex is not defined after katex is not defined, one gets katex is not defined katex is not defined as solutions, alternately, to katex is not defined and katex is not defined. Thus, the solutions to katex is not defined are given by katex is not defined. Now finding katex is not defined such that katex is not defined amounts to looking for katex is not defined such that katex is not defined. Thus, it becomes clear that katex is not defined and katex is not defined is the unique solution to katex is not defined under the constraint that katex is not defined lies between katex is not defined and katex is not defined. Hence katex is not defined (with katex is not defined) is the unique solution to the puzzle.
The particular convergent katex is not defined, corresponding to katex is not defined and katex is not defined, is obtained by truncating the SCF at the eighth step. Note that the previous and the next solutions of katex is not defined are katex is not defined and katex is not defined giving katex is not defined and katex is not defined respectively, which are, of course, outside the specification in the puzzle which stated that there were more than katex is not defined houses on the street but not more than katex is not defined.
Curiously enough, the fraction katex is not defined which solves The Strand Magazine puzzle has another Indian connection, and takes us back to anonymous ancient Indian mathematicians. The mystic seers of the Vedic Age had made many remarkable mathematical discoveries and innovations. Some of their knowledge, especially those results in geometry and arithmetic which are needed for building the vedis or altars, are preserved in later treatises called Śulbasūtras which, though composed much after the Vedas, still belong to a pre-historic period (800 BCE or earlier).
Baudhāyana, Āpastamba and Kātyāyana are the three most prominent authors of the Śulbasūtras, which describe both exact geometric constructions of irrational numbers like katex is not defined, as well as their rational approximations (see [1] (section 5) and [2] for a detailed discussion). One of the rational approximations for katex is not defined that the Śulbasūtra authors record is the following sum of unit fractions:
katex is not definedAnd what is the expression for this number as a single rational number katex is not defined? It is again katex is not defined, the eighth convergent katex is not defined in the SCF expansion for katex is not defined. The very convergent from Ramanujan’s prompt answer, while cooking a meal, to Mahalanobis’s question!
Śulbasūtra authors also give the rational approximations katex is not defined and katex is not defined for katex is not defined, i.e., the third convergent katex is not defined and fourth convergent katex is not defined; indeed, katex is not defined. Thus, each of these (rational) approximations for katex is not defined is really the best possible in a precise sense as elaborated above—they are the best among all fractions with denominators not exceeding the denominator of the chosen rational approximation.
The Archimedes Cattle Problem
Continued fractions and the Brahmagupta–Pell equation also make their appearance in another interesting problem, posed by Archimedes and presented as a challenge to his peers in Alexandria.
It was sent in a letter to Eratosthenes of Cyrene—now at least 2,200 years old—and is scripted in beautiful verse. In the mathematical world, it is called the Archimedes Cattle Problem because it involves a certain definite number of bulls and cows. The bulls are of four different types, as are the cows. The problem posed in verse is a series of constraints that the variables are subjected to.
Assuming that the four “bull” variables are katex is not defined, and katex is not defined, and their “cow” counterparts are katex is not defined and katex is not defined, the equations read as follows:
The problem challenges people to find the size of the herd katex is not defined, and also to find out how many bulls and cows belong to each of the four respective varieties.
Archimedes stated that a person who could “merely” solve this portion of the problem was at best competent. He then suggested two more constraints that had to be satisfied by the solution of these equations [9]:
“… But come, understand also all these conditions regarding the cattle of the Sun. When the white bulls katex is not defined mingled their number with the black katex is not defined, they stood firm, equal in depth and breadth, and the plains of Thrinacia, stretching far in all ways, were filled with their multitude. Again, when the yellow katex is not defined and the dappled bulls katex is not defined were gathered into one herd they stood in such a manner that their number, beginning from one, grew slowly greater till it completed a triangular figure, there being no bulls of other colours in their midst nor none of them lacking…”
In mathematical terms, katex is not defined had to be a square; i.e., katex is not defined for some katex is not defined. Also, katex is not defined had to be a triangular number; i.e., katex is not defined for some katex is not defined. The one who solved this harder version could stake claim to the prize of supreme wisdom [9]:
“If thou art able, O stranger, to find out all these things and gather them together in your mind, giving all the relations, thou shalt depart crowned with glory and knowing that thou hast been adjudged perfect in this species of wisdom.”
One learns in high schools that katex is not defined. One may also have heard the story of Gauss’s childhood exploit where he stumped his school teacher by arriving at the above formula on the spot. The evaluation of the same sum relates to another anecdote (see [5]) that demonstrates the precocious mathematical prowess of a 20th century mathematician.
William Thurston, Jr. (1946–2012) was famous for his unusually fertile imagination, coupled with powerful geometric insights. He went on to make major contributions to the world of geometry, and his work was recognized with a Fields Medal in 1982.
We recall an incident that transpired when Thurston was still a little boy, which led his father, Paul, to discover young Thurston’s innate ability to summon at will original mathematical ideas. His father, a physicist, used to ask young William and his siblings questions from elementary school mathematics. Below is a conversation between Paul Thurston and William:
Paul: “What is katex is not defined?”
Bill said, “katex is not defined.”
Paul said, “Almost right.”
Bill said, “Oh, I filled one square with katex is not defined, two squares for katex is not defined and all the way up to katex is not defined, so that’s half of katex is not defined, but I forgot that the middle squares are cut in two, so that’s katex is not defined!”
Once these additional constraints are imposed, the solutions to the cattle problem grow to monstrously large numbers whose digits take up 47 pages if completely written out. Regarding the size of these solutions, David Fowler, a historian of Greek mathematics said “I don’t know what anybody would do with a solution, once found, except use it as a piece of mathematical wallpaper!” (see [10])
We will briefly sketch the key ideas involved in solving the problem. The continued fractions appear as a means to ensure that the solutions satisfy the triangular number constraint.
We begin midway through the solution process by considering the set
katex is not defined
that involves the variables in the Cattle Problem. It can be shown that the set
helps solve the cattle problem. Since the solutions must be integers, we multiply each number in this set by the LCM of all its members, which is katex is not defined. We then get
as the set that gives the smallest integral solution to the cattle problem, with each member of the set representing katex is not defined respectively. But this solution does not satisfy the two additional constraints—that katex is not defined must be square and katex is not defined must be triangular—imposed by Archimedes. As we will see, the solutions start to grow in size as these two constraints are enforced one by one.
The square constraint on katex is not defined means that
katex is not definedis supposed to be a square. The prime factors of katex is not defined are katex is not defined and katex is not defined. Removing katex is not defined, and retaining the rest of the terms, we require katex is not defined to be a square. Therefore katex is not defined, for some integer katex is not defined, will make katex is not defined a square number. Multiplying each element of the set katex is not defined with katex is not defined constitutes a solution set that satisfies the square constraint:
We will now impose the triangular number constraint on katex is not defined, which requires that
for some katex is not defined. That is, we are looking for an integer solution, for katex is not defined, of the quadratic equation
katex is not definedwhich happens exactly when the discriminant katex is not defined is a square. This implies that the statement above is true only if katex is not defined for some katex is not defined. This is again another case of the Brahmagupta–Pell equation katex is not defined, but with a very large value of katex is not defined.
While it is not clear who in ancient Greece laid claim to the basic prize for solving the Cattle Problem, let alone the one for supreme wisdom, this problem gained traction in modern times. In 1867, C.F. Meyer, a German mathematician, set out looking for the solution using a continued fraction expansion of katex is not defined. He toiled through katex is not defined steps of the continued fraction expansion, and gave up [7].
In 1880, A. Amthor solved the problem, using a different approach from continued fractions, and presented intriguing numbers. The smallest number—there are infinitely many solutions—was katex is not defined cattle.
Note that in the Archimedes cattle problem, it is given that the number of solutions had to be integers—a fractional or even rational number of cattle would clearly not make much sense, except of course, to a butcher!
Ultimately, C.F. Meyer’s attempted use of continued fractions in solving the cattle problem may seem a mere abstract curiosity to many. However, there was one event that occurred centuries ago that still touches our lives, and lends a measure of stability to our sense of the passage of time. It is an event that makes sense, in hindsight, through the lens of continued fractions.
Centurial Years—To Leap or Not to Leap?
In October 1582, Pope Gregory XIII introduced a new calendar that was a refinement of the Julian calendar in use until then. The correction introduced in what became known as the Gregorian calendar was minimal, in the sense that it shortened the mean length of the calendar year from katex is not defined days to katex is not defined days, which is a change of katex is not defined. Thus, for all practical purposes of calculating the length of the year, the change is minimal.
The motivation for the Church to make this change, however, was a more dire one. In the Julian calendar, the number of calendar days between the celebration of Easter and the occurrence of the spring equinox1 seemed to drift, i.e., increase over time. The Church had always identified the two together, and the fact that the equinox and Easter fell on different days didn’t exactly please the Church, intent as it was on the symbolism and significance of long held beliefs. In the Indian context, an analogous situation would have been that of our own Makara Sankranthi coinciding with, say, either Christmas, or our Republic Day.
At the heart of the effected change of katex is not defined in the mean length of the calendar year was the change in leap years. Under the Julian system, centurial years that are divisible by four were leap years. This included every centurial year such as katex is not defined. Under the Gregorian system, however, centurial years such as katex is not defined will not be leap years, but katex is not defined and katex is not defined would qualify. In general, any centurial year that was an integer multiple of katex is not defined was a leap year. But why?
Let us call a block of katex is not defined years in which there are katex is not defined leap years katex is not defined as a cycle. The job of refining the calendar now involves coming out with an easy and efficient way of finding katex is not defined and katex is not defined such that, according to the Gregorian calendar’s predictions, Easter and spring equinox are always on the same day. In every cycle, there will be a total number of katex is not defined days. Therefore, every mean year will be katex is not defined days long. The challenge is to make this quantity, katex is not defined, as close as possible to the day length in excess of katex is not defined, as per the new Gregorian calendar. We know that this number is katex is not defined.
Enter continued fractions. The first few convergents in the SCF expansion of katex is not defined turn out to be katex is not defined. The first fraction corresponds to the Julian system of one leap year every katex is not defined years. But this is precisely the system that caused the problem we wanted to fix in the first place. The next convergents offer cycle lengths of katex is not defined and katex is not defined years, which are not very convenient. But is there a way out?
If katex is not defined was multiplied by katex is not defined, we get katex is not defined whose SCF has katex is not defined and katex is not defined as the first few convergents. Since the denominator is the cycle length, one has to multiply katex is not defined with katex is not defined, giving a katex is not defined-year cycle. This is the key step. Is there a way to match the excess of katex is not defined days with a katex is not defined-year cycle?
The very first convergent has the answer: katex is not defined leap years in katex is not defined years. Can one work with these numbers? Yes, if we mandate that only the centurial year divisible by katex is not defined will be a leap year. Everything dramatically falls into place. katex is not defined will all be leap years, while katex is not defined will not be leap years according to the changed canon. While there is no evidence that continued fractions were the method through which the Gregorian calendar was made, there is a curious twist of history here—Greece, the land of Archimedes and the Cattle Problem, was one of the last European countries to adopt the changed calendar!
For millenia, the repeated appearance of continued fractions in seemingly unconnected stories sampled in this article have enthralled us on issues ranging from counting cattle to something as mundane as a calendar. It is only fitting to say that the ever continuing saga of continued fractions is an ode to the mortal geniuses who created these immortal melodies.
References
- [1]Dani, S.G. Geometry in the Śulvasūtras, Studies in the History of Indian Mathematics (Ed. C.S. Seshadri), chom 5, Hindustan Book Agency, 2010.
- [2] Datta, B. Ancient Hindu Geometry: The Science of the Sulbas, Calcutta Univ. Press, 1932, reprinted Cosmo Pub., New Delhi, 1993.
- [3] Dutka, J. On the Gregorian revision of the Julian calendar, Math. Intelligencer, 10 (1988) no.1, 56–64..
- [4] Frederick, R.V. Mathematics of the Gregorian calendar, Math. Intelligencer, 7 (1985), no. 1, 53–56.
- [5] Gabai, D. and Kerckhoff, S. William P. Thurston: 1946–2012, Notices of the AMS, 62, no. 11 (2015) 1318–1332.
- [6] Khinchine, A.I. Continued Fractions, Mineola, N.Y. : Dover Publications, 1997, (first published in Moscow, 1935)
- [7] Lenstra Jr., H.W. Solving the Pell Equation, Notices of the AMS, 49, no. 2 (2002) 182–192.
- [8]Silverman, J.H. A Friendly Introduction to Number Theory, Fourth Edition, 2012 Pearson Education, Inc.
- [9]Thomas, I. Greek Mathematical Works II, 1941
- [10]Vardi, I. Archimedes’ Cattle Problem, The American Mathematical Monthly, 105, no. 4 (1998) 305–319.