4
$\begingroup$

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?

$\endgroup$
4
  • 4
    $\begingroup$ See math.stackexchange.com/questions/219991. $\endgroup$
    – joriki
    Commented Apr 19, 2016 at 8:51
  • 1
    $\begingroup$ 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? $\endgroup$ Commented Apr 19, 2016 at 9:11
  • $\begingroup$ 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. $\endgroup$
    – DukeZhou
    Commented May 25, 2018 at 16:15
  • $\begingroup$ If have a small collection of percents you know are rounded rational fractions that share a denominator (e.g. some one gave you a pie chart with percents, but no n), then you can look for an approximate LCD between the decimals, and the denominator will be it's approximate inverse. $\endgroup$ Commented Dec 4, 2020 at 21:19

2 Answers 2

3
$\begingroup$

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).

$\endgroup$
3
  • $\begingroup$ cool, thank you, I'll take a look. Are you the author of the mpmath library @JohanC? $\endgroup$ Commented May 16, 2018 at 14:21
  • $\begingroup$ @Reblochon Masque. No, at the moment I'm not involved with mathmp, but it is an intriguing topic . $\endgroup$
    – JohanC
    Commented May 16, 2018 at 15:44
  • $\begingroup$ Thank you - It is the similarity between your name ( @JohanC ) & that of the of the repo maintainer (Johansson), that made me ask. I'll review the lib shortly, and if it answers my request, I'll accept your answer. $\endgroup$ Commented May 16, 2018 at 16:05
1
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .