Fundamental Mathematics from an Advanced Standpoint

Math 4303

Helmut Knaust, Department of Mathematical Sciences, UTEP, El Paso TX 79968
hknaust@utep.edu

Last Edits: 9/5/09

Periodic Decimals

The following module prints out the "periodic" form of a rational number.  The command will not work for integers or irrational numbers.

RepeatingDecimal[nr_Rational]:=
Module[{p,s,e,n,fd},
fd=FactorInteger[Denominator[nr]]; 
p=1;
s=Select[FactorInteger[Denominator[nr]],(#[[1]]==2||#[[1]]==5&)];If[s=={},e=0,e=Max[Table[s[[i,2]],{i,1,Length[s]}]]];
n=10^e nr;
While[Not[IntegerQ[FractionalPart[n] (10^p-1)]],p=p+1];
If[FractionalPart[n](10^p-1)==0,p="-",];
Print["\n",nr," = ",PaddedForm[N[IntegerPart[n]/10^e],{Length[IntegerDigits[IntegerPart[n]]],e},NumberPadding->{"","0"}],If[FractionalPart[n](10^p-1)==0,"",OverBar[StringInsert[ToString[FractionalPart[n](10^p-1)],"0",Table[1,{i,1,p-Length[IntegerDigits[FractionalPart[n](10^p-1)]]}]]]],"\n\nPeriod: ",p,"\tPrime factorization of the denominator: ", Denominator[nr]," = ", If [Length[fd]>1,CenterDot@@(Superscript@@@fd),(Superscript@@fd[[1]])]]
]

Here are some simple-periodic examples:

RepeatingDecimal[1/7]

RepeatingDecimal[1552500/17]

RepeatingDecimal[1552502/117]

The examples below are delayed-periodic:

RepeatingDecimal[15525/14200000]

RepeatingDecimal[1/1310]

Finally, some examples of  terminating decimal expansions:

RepeatingDecimal[6/250000]

RepeatingDecimal[171/8]

The command will not work for integers or irrational numbers:

RepeatingDecimal[18/6]

RepeatingDecimal[ArcTan[1]/3]