# Reverse engineer numerical results to fractions of remarkable numbers?

Numerical methods output decimal numbers that oftentimes result from the division of two (or more) numbers:

• $1.5708... = \frac{\pi}{2}$
• $0.3679... = \frac{1}{e}$
• $0.7071... = \frac{\sqrt2}{2}$
• $0.7501315 ... = \frac{{e}^{\frac{\pi}{12}}}{\sqrt{3}}$ (maybe this one is pushing it a little)

What is a good way to "reverse engineer" a decimal point number to the fraction it might have originated from?

Of course, maintaining a lookup table of values for most commonly encountered decimal numbers and their fractions of "remarkable numbers" is feasible to some extent, but is there a better way?

Side question: what is the proper jargon to succinctly describe this problem?

• – joriki Apr 19 '16 at 8:51
• Thanks for the link, it is useful: (the inverter) uses a combination of lookup tables and integer relation algorithms in order to associate a closed form representation with a user-defined, truncated decimal expansion (written as a floating point expression) ... Are there other "better" ways? – Reblochon Masque Apr 19 '16 at 9:11
• Thanks for asking this question! It's an applied problem for me, but I need a formula or shorthand referencing an algorithmic function. Let's say I want to make a rectangular Sudoku gameboard in 5 dimensions, and I want it to be (9x7x8x6x5) I need a function that identifies the fraction that produces .97865, or any other fraction. – DukeZhou May 25 '18 at 16:15

If you're happy with just a Python library, take a look at the identify() function of mpmath and its documentation. Its source is available at mpath's identification.py and refers to Ferguson's PSLQ Integer Relation Algorithm (the paper is available online).
It's too hard to give a method of reverse engineering decimal notations of all sorts of definable numbers so I will give just a method on how to do so for all rational numbers, with your brain alone not using Python. Given any rational number expressed in decimal notation ending with a line over a string of digits to indicate that that string of digits starts repeating for ever from then on, let's call $$m$$ the number of digits in the written notation after the decimal point and before the overline and $$n$$ the number of digits with an overline in the notation. To determine its mixed fraction notation, first you have to recognize that the number is a multiple of $$\frac{1}{10^m \times (10^n - 1)}$$. Let $$p$$ be the number the string of digits after the decimal point but before the overline represents and $$q$$ be the number the string of digits with the overline represents. Then the real part of the given number is $$\frac{(p \times (10^n - 1)) + q}{10^m \times (10^n - 1)}$$. There's an easy way to compute the greatest common factor of the numerator and denominator of that expression then divide the numerator and denominator by the greatest common factor to reduce it to lowest terms.