“Your calculator has broken, leaving you with only the buttons for $\sin$, $\cos$, $\tan$ and their inverses, the equals button and the 0 that starts on the screen. Show that you can still produce any positive rational number.”

When this showed up on Reddit, I knew I was in for a) a rough ride and b) a bit of a treat. (The poster mentioned that it was an International Mathematical Olympiad problem, and those are often the worst kind of fun.)

In this post, I want to talk not just about the solution, but the nebulous process that took me there.

Below the line be spoilers.


My eventual solution

I’ll start by presenting my solution, pared down and simplified, stripped away of all of the scaffolding that was used in its construction.

Proposition: all numbers of the form $\frac{\sqrt{a}}{\sqrt{b}}$, with $p$ and $q$ coprime positive integers, can be produced using these six functions.

Observation: $\tan\br{ \arccos \br{ \sin \br{ \arctan \br{x} } } } = \frac{1}{x}$. This can be shown using a right-angled triangle with legs 1 and $x$.

Observation: 1 can be produced (from, e.g., $\cos(0)$.)

Lemma: if $\frac{\min(\sqrt{a},\sqrt{b})}{\sqrt{|b-a|}}$ can be produced, so can $\frac{\sqrt{a}}{\sqrt{b}}$.

Proof: If $a < b$, then $\sin\br{\arctan\br{\frac{\sqrt{a}}{\sqrt{b-a}}}} = \frac{\sqrt{a}}{\sqrt{b}}$.

If $b < a$, then $\sin\br{\arctan\br{\frac{\sqrt{b}}{\sqrt{a-b}}}} = \frac{\sqrt{b}}{\sqrt{a}}$, and $\tan\br{ \arccos \br{ \sin \br{ \arctan \br{\frac{\sqrt{b}}{\sqrt{a}} } } }} = \frac{\sqrt{a}}{\sqrt{b}}$, as previously observed $\blacksquare$

Proof of proposition: Our target number, $\frac{\sqrt{a}}{\sqrt{b}}$, can be reached from $\frac{\min(\sqrt{a},\sqrt{b})}{\sqrt{|b-a|}}$, a number of the form $\frac{\sqrt{p}}{\sqrt{q}}$ with $\max(p,q) < \max(a,b)$ (($p$ and $q$ are positive integers.)) This new number can be reached from a number with a still smaller maximum component, and so on.

Since the maximum component is, in each case, a smaller integer than the one before, while bounded from below by 1, repeatedly applying the process shows that all numbers of the form $\frac{\sqrt{a}}{\sqrt{b}}$ can be reached from 1. All rational numbers are of this form, so the proposition holds $\blacksquare$

Other paths

This was not, of course, how I originally approached it. I started by playing. What numbers could I generate? I quickly stumbled on applying $\sin(\arctan(\cdot))$ repeatedly to 1 to generate all numbers of the form $\frac{1}{\sqrt{n}}$ (for positive integer $n$) and their reciprocals; the whole numbers and their reciprocals are a subset of these numbers.

I couldn’t see how to get from there to any rational number, though. I applied the same functional combination to $2$ to generate all numbers of the form $\frac{2}{\sqrt{4n+1}}$, which includes all rational numbers with a 2 in the numerator, but then I got stuck: doing the same thing with $3$ only generated numbers of the form $\frac{3}{\sqrt{9n+1}}$, missing out many of the rationals with a 3 on top.

(Eventually, after finding the solution above, I realised that applying the function to $\sqrt{2}$ generated all numbers of the form $\frac{\sqrt{2}}{\sqrt{2n+1}}$, while $\sqrt{3}$ and $\frac{\sqrt{3}}{\sqrt{2}}$ generated all numbers of the form $\frac{\sqrt{3}}{\sqrt{3n+1}}$ and $\frac{\sqrt{3}}{\sqrt{3n+2}}$ between them - leading to an induction argument that all numbers of the given form can be reached.)

Thinking in triangles

This is a situation where having a geometric understanding of what’s going on really helps.

If you know the fraction $\frac{\sqrt{a}}{\sqrt{b}}$ can be produced, we can think about a couple of right-angled triangles:

  • one with legs of $\sqrt{a}$ and $\sqrt{b}$ (and a hypotenuse of $\sqrt{a+b}$);
  • one with a hypotenuse of $\max(\sqrt{a}, \sqrt{b})$ and legs of $\min(\sqrt{a},\sqrt{b})$ and $\sqrt{|a-b|}$.

The insight this gave me was that the process was invertible: if a number can be produced from another number, the other number can be produced from the first.

I could then consider a fraction like $\frac{3}{4}$ as a right-angled triangle with hypotenuse $\sqrt{16}$ and one leg of $\sqrt{9}$ - meaning the other leg was $\sqrt{7}$. This meant the sine of one of the angles was $\frac{\sqrt{9}}{\sqrt{16}}$, and its tangent was $\frac{\sqrt{7}}{\sqrt{9}}$. I could then repeat the process with a triangle with a hypotenuse of $\sqrt{9}$ and legs of $\sqrt{7}$ and $\sqrt{2}$ - and so on, each time the numbers reducing.

The Holy Cow moment

While I was trying to straighten out the proof of my solution, I almost jumped out of the bath ((luckily, it was during the cold snap in February and Weymouth was spared the ordeal of me running naked down Abbotsbury Road shouting ‘eureka!’)).

The step outlined in the lemma is exactly analogous to a step in the Euclidean algorithm for finding the highest common factor of two numbers.

And since $p$ and $q$ are coprime by supposition, their highest common factor is 1 - which means they can be reached!


This was a belter of a puzzle. I hope you enjoyed it as much as I did.