Midys Theorem

Author

Eric W. Weisstein
April 14, 2004

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Arithmetic/MidysTheorem.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/MidysTheorem.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Code

Midy::notprime="Denominator is not a prime number.";
Midy::odd="Repeating decimal has an odd number of digits.";
Midy::norep="Decimal terminates.";

Midy[f_Rational]:=Message[Midy::notprime]/;!PrimeQ[Denominator[f]]

Midy[f_Rational]:=Module[{r=RealDigits[f][[1,-1]],n},
n=Length[r];
Switch[n,
0,Message[Midy::norep],
_?EvenQ,{OverBar[FromDigits[r]],Plus@@Partition[r,n/2]},
_,Message[Midy::odd]
]
]/;PrimeQ[Denominator[f]]

Examples

Midy[1/2]

Midy[1/3]

Midy[1/4]

Midy[1/5]

Midy[#/7]&/@Range[6]//ColumnForm

Midy[#/11]&/@Range[10]//ColumnForm

Midy[#/13]&/@Range[12]//ColumnForm

Midy[#/17]&/@Range[16]//ColumnForm

Midy[#/19]&/@Range[18]//ColumnForm

Midy[1/131]

Midy[2/131]