37.8% of people surveyed liked cake.
How many people were surveyed?
In general, of course, we can’t know. But we can say something about the smallest number that could possibly have been asked. If 14 out of 37 people liked cake, that would give us 37.8%. No smaller denominator will do.
After , the next simplest fractions that round to 37.8% are and , after which candidates start getting much easier to find, and so less interesting.
It would be fair to say that reasoning in this way is not often useful, at least on its own. Sometimes the minimum is large enough to be interesting. Really, though, I just think we owe it to the overly precise number reporters of this world to learn what we can from their output.
So, without further ado, here’s a little percentage-to-simplest-fraction calculator:
% might be
It shows at least three fractions, then stops when the denominators get within 10% of each other. These criteria aren’t perfect, but it’s surprisingly hard to capture the notion of interestingness rigorously.
Stern–Brocot¶
It turns out to be rather easy to find simple fractions in an interval by searching the Stern–Brocot tree. This tree contains all positive rational numbers somewhere within it, and the path to each is made up of the best rational approximations to it. A binary search that explores an interval looks much like the usual kind, except that once the interval is found it may take both branches.
While searching for a node yields decreasingly simple1 fractions, exploring an interval does not. A priority queue would be a great tool to handle this. Unfortunately JavaScript doesn’t have one and I was too lazy to write one, so I just sort the queue of nodes to visit between iterations.
The tree exploration yields fractions in lowest terms. That is usually more useful, but I think undesirable here. I am rather crudely generating them between rational approximations and… sorting the results.
Perhaps the lesson of this post is that I really wish JS included batteries.
As usual, you’re more than welcome to get in touch if you have questions.