4

I am working on a project for school in which I would need to sum up hundreds of rational values to over one trillion sig figs (done in code) however it is not practical to store each term in the sequence as the file will become to large, however because all of the numbers are rational they are either finite, which is better, or they are infinite, but still rational so they have to repeat, so my question is: is there a mathematical way to tell the length of the pattern, for example 1/14 is 0.0[714285][714285] with the [714285] bit repeating infinite times.

any help would be much appreciated Thank you in advance!!

  • 2
    This is hard to follow. Of course we can compute the length of a period for any rational number, given the numerator and denominator. See this question for example. – lulu Aug 19 '22 at 00:47
  • Related: https://math.stackexchange.com/q/140583/96384, , https://math.stackexchange.com/q/1449660/96384, https://math.stackexchange.com/q/726969/96384 – Torsten Schoeneberg Aug 19 '22 at 00:48
  • The length of the repeating part is always less than the denominator of the fraction. – Dan Aug 19 '22 at 00:51
  • 1
    For a prime denominator $p$ the period is $\leq p-1$. It is a deep open conjecture, if equality holds infinitely often. It is connected to hard problems in algebraic number theory: Artin conjecture. – Thomas Preu Aug 19 '22 at 01:01

1 Answers1

6

To find the length of the periodic part of the decimal expansion for $\frac ab$ (where $a$ and $b$ have no common factors): first remove all the factors of $2$ and $5$ from $b$ (that is, evenly divide $b$ by $2$ and by $5$ as often as possible); then, if $b'$ is the result of removing the $2$s and $5$s, then calculate the smallest positive integer $n$ such that $10^n-1$ is divisible by $b'$ (this is the "multiplicative order" of $10$ modulo $b'$). Then $n$ is the length of the periodic part of $\frac ab$. The largest it can ever be is $b'-1$.

Greg Martin
  • 78,820
  • Are there cases where the predicted period $n$ you mention is in fact longer just by coincidence? Like predicted period $n=6$ and actual repeating part $129129$ ? – coffeemath Aug 19 '22 at 01:08
  • 1
    No—this is an exact formula! – Greg Martin Aug 19 '22 at 02:22
  • Perhaps I am misreading the comments, but I believe $128128/999999$ has period $3$ but $n=6.$ (the same trick should work for $129129/999999,$ but then the fraction is not reduced and it's more work) – Artimis Fowl Aug 19 '22 at 09:18
  • $\dfrac{128128}{999999} = \dfrac{128\cdot1001}{999\cdot1001} = \dfrac{128}{999}$ – Greg Martin Aug 19 '22 at 16:54