       Re: Cyclical Decimal Expansion

• To: mathgroup at smc.vnet.net
• Subject: [mg114502] Re: Cyclical Decimal Expansion
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Sun, 5 Dec 2010 21:57:38 -0500 (EST)

```Here is a quick implementation of the function described below. It takes a
fraction as an argument and returns a pair: {the number of non-recurring digits in the decimal expansion of the fraction, the number of recurring ones}.

f[x_Rational] :==
Module[{n == Denominator[x], a, b}, a == IntegerExponent[n, 2];
b == IntegerExponent[n, 5]; {Max[a, b],
MultiplicativeOrder[10, n/(2^a*5^b)]}]

For example:

f[17/234]

{1,6}

and indeed:

N[17/234, 12]

0.0726495726496

Andrzej Kozlowski

On 5 Dec 2010, at 18:28, Andrzej Kozlowski wrote:

> The answer is classical and is (or rather used to be) taught in elementary number theory classes. Here is how to compute it with Mathematica:
>
> Consider a fraction of the form p/q in reduced form. Use FactorInteger to factorize it into the form 2^a 5^b Q ,where we have GCD[Q,10]====1. Let m == Max[a,b]. Then in the decimal expansion of p/q will get m non-recurring digits, while the number of recurring ones depends only on Q and is given by the Mathematica function MultiplicativeOrder[10,Q]. For example. in the case 1/7 there are no non-recurring digits and the number of recurring ones is:
>
> In:== MultiplicativeOrder[10, 7]
>
> Out== 6
>
>
> Andrzej Kozlowski
>
>
> On 3 Dec 2010, at 11:21, Harvey P. Dale wrote:
>
>> What's the easiest way to determine the length of the repeating
>> cycle for decimal expansions of fractions?  For example, 1/7 ==
>> 0.14285714285714285714 . . . so the length of its repeating cycle
>> (142857) is 6.  For 1/3 the length of the cycle is obviously 1.  For
>> some fractions, e.g., 1/4, the decimal expansion is not cyclical (in
>> base 10).
>>
>> Thanks.
>>
>> Harvey
>>
>> ______________________________________________________________________
>> This email has been scanned by the MessageLabs Email Security System.