Documentation for the Approximation Generator.
What is it?
A normal calculator takes a series of values and operations, and gives you a numeric answer. But there has always been a problem with this: how do you know what symbols to put in, to get the answer you want?
Now we proudly present to you the solution to this age-old problem. You simply put in a numeric answer, and it gives you several possible routes you could have taken to arrive there. Couldn’t be simpler!
It accepts numbers in many common forms, ignoring spaces and commas, and allowing exponential notation, including “1e+2”, “1*10^2”, “1×10 2”, and outputs the numbers in a nice, rendered form, as well as a Unicode based text form, and allowing (through the MathJax menu) access to the LaTeX form of the equation.
The source code for this project (to as great an extent as possible), the system to generate the lookup data, and a Java implementation of the search system, is all available on GitHub.
Is this a new idea?
Sadly not. The excellent RIES is one such system, which generally does a better job, producing cleaner expressions, though it needs to be downloaded and run locally, and takes longer to get accurate results. There is also the inverse symbolic calculator, although that has a wider range of functions, so tends to produce less readable results.
How do you use it?
To get some results, simply type a number into the box. The results will appear below the box.
The small arrow to the left of the expression shows and hides the calculated value, displayed to the same number of significant figures as the target value, for easy comparison.
The text below the expression states the number of significant figures the approximation is accurate to (rounded down aggressively). And the down arrow next to that shows more detail.
The extra detail includes the precision of the approximation, the actual calculated value of the approximation, to full calculated precision, a Unicode version of the approximation, and an ‘uncleaned’ version, which will still be right even if the expression cleaning system fails.
It internally uses 20s.f. numbers, so precisions around 18s.f. and above are due to rounding error, rather than actual differences.
The calculations used are quite complex, so there may be a significant delay on the “Try Harder” button, particularly on mobile devices, hence the reduced precision compared to the Java variant.
The drop down menu below the input box, allows you to choose the dataset to work from, such as restricting the system to only using rational numbers. If the ‘No integers’ option is selected, integers can still appear, either as a result of the simplification of expressions, or as part of an inversion, as inversion is still allowed.
What other systems does it use?
The JavaScript generator is effectively a direct port of the Java version (which is the same, but local, and more precise), using MathJax for the rendering, and Decimal.js for the number handling. The fonts used to provide the more unusual characters are Ubuntu and Noto Sans TC, both from Google Fonts, and chosen for their support of the more strange characters (like the down arrow and 1/5th).
How does it work?
Each expression is displayed using the MathJax system, interpreting generated LaTeX. Along with a the number of significant figures of accuracy the approximation is accurate to. The calculated value, displayed by the down arrow, and the given target, are both displayed to the number of significant figures (s.f.) given in the target, limited to 20 s.f. due to size constraints.
The more information section holds the accuracy, a Unicode rendering of the expression, and an ‘uncleaned’ version of the expression. The Unicode rendering uses lots of unusual characters, so may contain significant numbers of ‘tofu’ characters (little boxes). To get a LaTeX version, the MathJax menu can be used (right click on the expression).
The internals of the system first do a simple lookup, using a rest API on the server side (running a Spring Boot Java application), to fetch a set of expressions from the file specified by the search space selection menu. It then runs a cleaner on the expressions. This attempts to resolve any formatting issues with the expressions, and should result in a more easily read, yet entirely equivalent expression. While should be the case, in rare cases it can have bugs. This is why the uncleaned version of the expression is given, this can also explain how some numbers were reached.
The Try Harder button attempts to correct the expression in 3 ways:
- By multiplying the expression by a value.
- By replacing some parts of the expression with other expressions.
- By adding something to the expression.
The normal results are still shown, meaning that the first few approximations are the previously given results. Then there will be a series of expressions based on the replacement and multiplications. Finally, there will be a series of expressions, based on the others, with some offset added (or subtracted).
The additive expressions will generally be least beautiful, but most accurate, often reaching 1 part in 1015.