Creating mega-periodic Fractions
by Arnout Jaspers

If you write 1/7 as a decimal number, you get 0.bar(142857).
The bar(..) above the  6 digits means that the group
is repeated indefinitely. We say: the period of 1/7 is 6.

In the article "The period of a decimal number" in the January issue
we stated (without proof):

Take two prime numbers a and b. If their inverses 1/a and 1/b, written
as decimals, have periods p_a and p_b, the product 1/(a*b)
has period lcm(p_a,p_b). Here lcm means the least common multiple.

With the aid of 9-numbers of the previous article the proof is easy. We
show it by example, taking a=7 and b=17. We observed that 1/7 has period 6.
Also 1/17= 0.bar(0588235294117647) has period 16. Then the fraction 1/(7*17)
=1/119, written as decimal, should have period lcm(6,16)=48.

Earlier we showed that each periodic fraction may be written as a fraction
with a 9-number in the denominator:
0.bar(142857) = 142'857/999'999
and
0.bar(0.588235294117647)=588'235'294'117'647/9'999'999'999'999'999.

Observe that the number of 9's in the denominator equals the period of the decimal
number.
In addition we should have
1/7=142857/999'999
and
1/17 = 588'235'294'117'647/9'999'999'999'999'999
and this is true, because 7*1542857 =999'999 and
17*588'235'294'117'647=9'999'999'999'999'999.

In fact the period of a fraction (written as a decimal): 999'999 is
the smallest 9-number with a factor of 7, and the smallest 9-number with
a factor of 17 is 9'999'999'999'999'999.

Writing a periodic fraction as a simple fraction with a 9-number
in the denominator now demands:
(*) For 1/(7*17), the product of 1/7 by 1/17, we need a 9-number in
the denominator with a factor of 7 as well as a factor of 17, so we may
write 1/119 = 1/(7*17)=(some integer number)/(9-number with factor 7 and factor 17).

Now we use two properties of 9-numbers that we already proved:
- a 9-number of P-1 digits has at least one factor P (if P is neither 2 nor 5)
- if the 9-number with N digits is the smallest 9-number with P as factor,
  then all the 9-numbers N, 2N, 3N.. have one or more factors P.

Applied to our example this means we already know that 999'999 must contain
a factor 7 and 9'999'999'999'999'999 a factor 17. How do we construct a 9-number
that has a factor 7 as well as a factor 17? Easy: because of the second property
all 9-numbers with 6, 12, 18... digits contain a factor 7, and all 9-numbers with
16, 32,.. digits contain a factor 17. The smallest 9-numbers that is in both
sequences is the 9-number with lcm(6,16)=48 digits. By the second property these
two sequences are also the *only* 9-number with the factors 7 and 17, and
therefore the 9-number with 48 digits is indeed the smallest possible one.

This means the faction 1/119 is written as (an integer with 48 digits)/(9-number with 48 digits).
In decimal this is a fraction with period 48, i.e.
1/19=0.bar(0084033613....521)

Quadratic base fractions.
-------------------------

If a=b this rule cannot hold, as lcm(a,a)=a.
We return to the requirement stated in (*), but in view of the case a=b,
with a=7 as example:

(*) For 1/(7*7) we need a 9-number in the denominator with two factors 7,
so we can write 1/49=1/(7*7) = (an integer)/(9-number with two factors 7).

We already know that 1/7 has period 6, so the 9-numbers with 6, 12, 18...
digits all have a factor 7. But how does another factor 7 join? In general:
if the smallest 9-number with a factor P with N digits is 10^N-1, what is
the smallest 9-numbers with a factor P^2?

As 10^N-1 has a factor P, it is a multiple V of P, so we can write
10^N-1=V*P
whence
10^N=V*P+1
and
10^(P*N)=(10^N)^P=(V*P+1)^P.
Write this using Newton's binomial expansion, (a+b)^M.
(VP+1)^P=(VP)^P+P*(VP)^(P-1)+...+P(P-1)*(VP)^2+P(VP)+1.
We now have
10^(PN)-1=(VP)^P+P*(VP)^(P-1)+...+P(P-1)*(VP)^2+P*(VP).
All terms on the right hand side have a factor P^2, so 10^(PN)-1 is a 9-number
with P*N digits that is divisible by P^2, precisely what we looked for.

But is 10^(PN)-1 the *smallest* 9-number with factor P^2? Assume that there
is a smaller 9-number with factor P^2. This 9-number then has the form 10^(A*N)-1
(because all these 9-numbers have one or more factors) with A<P. In the same
manner as in the previous article when we had a prime factor P one may prove
that only the 9-numbers 10^(A*N)-1, 10^(2*A*N)-1, 10^(3*A*N)-1 have one or more
factors P^2. In general, each 9-number 10^(Q*A*N)-1, with Q=1,2,3... has a factor P^2.
But we have not shown that in each case 10^(P*N)-1 has a factor P^2, therefore
that must show up in the sequence of 9-numbers. Is this possible?
This may only occur as P*N=Q*A*N, therefore with P=Q*A. But here that states
that P is the product of two integers, where P is a prime number. This cannot
be, therefore there is no smaller 9-number with factor P^2 than 10^(P*N)-1.

Back to the example 1/7. This fraction has period 6, so the denominator is
the 9-number with 6 digit, 10^6-1. We would like to add a factor 7, so P is 7, thus
the first 9-number with two factors 7 is 10^(6*7)-1=10^42-1. The period of 1/(7*7)
should be 42. Indeed
1/49 = 0.(020408...51).

Base fractions with more than two prime factors.
------------------------------------------------

For small prime factors a the period of 1/a is already the maximum, a-1.
So 1/7 has period 6 and 1/17 period 16. That is not always the case: 
1/13 has period 6. For a larger prime G one cannot predict whether the inverse 1/G
has the maximum period length G-1; this becomes more unlikely as G increases.

This happens only when G appears in the (G-1)st 9-numbers as a prime factor.
Look for example at a G of approximately 1 million. Then a prime factor G
has approximately a 1-millionth higher chance to be earlier in the
sequence of 9-numbers. The larger the 9-numbers get, the larger the
probability that the number of prime factors (on the average) increases
as the 9-number increases.

So if you wish to construct a fraction with small numbers in the
denominator, but a period as long as possible, you need to choose a small
prime number P with longest possible period P-1. The fraction 1/P^k
then has a period (P-1)*P^(k-1).

All the previous remarks are also valid for fractions 1/(a*b*c....) with more
than two distinct prime factors. Then you need to find the smallest 9-number
with factors a,b,c.., and this has lcm(p_a,p_b,p_c,...) digits.

So periods may increase rapidly. For example 1/(17*29*47) = 1/23171 is 
a fraction with period lcm(16,28,46) = 2576.
You may check yourself the calculation of the fraction with online calculators
for large numbers, for example https://defuls.ca/big-number-calculator.htm .
This - and other calculators - don't show digits after the dot; so even
a fraction 1/7 is shown as 0. But you may can easily change this: for the fraction
1/(17*29*47) key in:
10^10000/(17*29*47)
and you get the answer
431 573 950 196 366 ...
You may check that the first 2576 digits are indeed the period, by searching
with 'control-F' (Windows) or 'cmd-F' (Mac) for the first digits, then for
'431 573 950' (don't forget the blanks). You find the block again after 2576,
5152 and 7728 digits, but nowhere else.

Product of arbitrary periodic fractions.
----------------------------------------

Finally we look at a more general case: take two arbitrary periodic
fractions, say 0.bar(523) and 0.bar(3054478), and multiply them. What is
the period length of the product? We note

0.bar(523)*0.bar(3054478) = 523/999 * 3054478/9999999
and search for a 9-number such that
523/9999 * 3054.378/9999999 = (an integer)/(a 9-number). (**)
Note: the product of two 9-numbers is not itself a 9-number (Observe:
(10^N-1)(10^M-1) = 10^(N+M)-10^N-10^M+1, which may not be written as 10^R-1
for some R. Otherwise we could have simply calculated 999*9999999, put
this 9-number in the denominator, 523*3054478, and that kills it.

To find the 9-number in the denominator, we decompose both 9-numbers
left of the equal sign as factors:
999=3^3*57 and 9999999=3^2*239*4649.
To write the product as a fraction with a 9-number in the denominator
we need a 9-number with the factors 3^5, 37, 239 and 4649. In the list
of factorization of 9-numbers (see pages 25-26 in the January issue)
we see that 239 and 4649 occur in the 9-numbers ith 7 and 14 digits,
thus also in those with 21, 28...digits. 37 appears in the 9-numbers
with 3, 6,9.. digits. Because lcm(3,7)=21, 239, 4649 and 37 occur in the
9-numbers with 21, 42, 63,...digits.
We do not need to treat the factor 3 differently because it occurs
in both denominators, comparable to what happens if you multiply
two identical reduced fractions. We said that if a 9-number with
N digits has a factor P, the 9-number with N*P digits has factor P^2.
This concludes that a 9-number with N*P^2 digits has a factor P^3,
and so forth.

All 9-numbers are divisible by 9, so they have a factor 3^2. So the
9-numbers with 3, 6,9,... digits have a factor 3^3, the 9-numbers with
9,18,27.. digits have a factor 3^4, and the 9-numbers with 27, 54, 81,... digits
have a factor 3^5. The smallest 9-number with all the factors needed,
3^5, 37, 239 and 4649, therefore has lcm(3,7,27)=189 digits.

Now look again at the expression (**). The denominator, the 9-number
with 189 digits, has the factors 3^5, 37, 239 and 4649 and others, which
we symbolically replace by [others]. The numerator is the
number 523 *3054748 * [others]. Therefore
523/999 * 3054478/9999999 = 523*3054*478*others / (3^5*37*239*4649*others)
[others] carries the minimum of factors that is needed to pump up the
factors 3^5, 37, 239 and 4649 to a 9-number. Conclusion: the product
of a decimal fraction with period 3 and a decimal fraction with period 7
has at most period 189.

Note: We write 'at most' because with an arbitrary fraction with 999
in the denominator we cannot exclude that this may be reducible to
a smaller fraction, and likewise for a fraction with 9999999 in the
denominator. Example: each 9-number is divisible by 9 (therefore
also by 3), so if you can divide the numerator by 9 (or 3), such
a fraction can be reduced. All 9-numbers with an even number of digits
are divisible by 11, so if you can divide the numerator by 11,
the fraction can also be simplified. In that case the 9-number in the
denominator of the product of the two periodic fractions must have a smaller
number of factors, and may be replaced by a smaller 9-number. If you
chose for both numerators prime numbers, this is excluded and you
get a maximum period.

This way you may compute step-by-step the maximum period of fractions
with length 2,3,4.. This is summarized in the table on the bottom of the page.
This table shows that the product of two periodic fractions with the
same period delivers much longer periods than a product of two
periodic fractions with different periods.

This means for example, that if you chose two prime numbers of just 3
digits, say 359 and 617, the product 0.bar(359)*0.bar(167) has period 2997.
For two periodic fractions with period 5 you already arrive at a maximum
period of 499995, close to half a million! Prime numbers with 5 digits
are plentiful; lists of these are on the internet. The computer mentioned
earlier may handle numbers to half a million digits, so you can create
fractions with these enormous periods by yourself.

Finally, the table suggests that the maximum length for two fractions
with period N equals N*(10^N-1). Whether this is true or not we leave as
an open problem to the reader...

  1   2    3     4      5     6    7
----------------------------------
1 9  18   27    36     45    54   63
2   198   54   396     90   594  126
3       2997   108    135  5994  189
4            39996    180  3564  252
5                  499995   270  351