Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to display a rational number in Mathematica in periodic style. PeriodicForm isn't working anymore. It worked in Mathematica 5 and now I'm using Mathematica 9.

I want to display the number $3.13678989898989898989\ldots$, where the repeating $89$ part should be displayed as $3.1367\overline{89}$

share|improve this question
2  
See this is RealDigits the replacement for what you want? –  bobthechemist Oct 29 '13 at 13:54
    
i want to display the following number 3.13678989898989898989 and the 8989 part should be displayed as periodic –  user2147674 Oct 29 '13 at 13:58
    
Your question implies that there is/used to be some kind of solution or function (PeriodicForm?) which does not work anymore, which is a bit puzzling. –  Yves Klett Oct 29 '13 at 14:03
    
books.google.at/… –  user2147674 Oct 29 '13 at 14:04
1  
@YvesKlett Apparently it was a function in the NumberTheory package that was in versions 6 and earlier. –  bobthechemist Oct 29 '13 at 14:05
show 2 more comments

4 Answers

You can always write your own version of PeriodicForm:

ClearAll@PeriodicForm
PeriodicForm[n_] := RealDigits[n] /. {{d___Integer, {i__Integer} ...}, l_Integer} :> 
    PeriodicForm[n, l, {d}, {i}]

Format[PeriodicForm[n_, l_, d_, i_]] ^:= Interpretation[Row[{
    FromDigits[d ~Take~ l] /. {} -> 0,
     ".", 
    Sequence @@ d ~Drop~ l, 
    OverBar[FromDigits@i]
}] /. OverBar[0] :> Sequence[], n]

enter image description here

share|improve this answer
    
Nice - I started down this route, then realized I was just procrastinating from all the grading I have to do. –  bobthechemist Oct 29 '13 at 16:12
add comment

To get PeriodicForm working in Mathematica 9 (and probably other versions after 6) you need to first download the obsolete package from the Wolfram Library Archive. Run the package, ignore the errors and have fun:

Get["http://library.wolfram.com/infocenter/MathSource/6773/\
   ContinuedFractions.m?file_id=6182"]
PeriodicForm[RealDigits[19/7]]

Mathematica graphics

share|improve this answer
2  
You could use URLSave to install package. URLSave["library.wolfram.com/infocenter/MathSource/6773/…;, FileNameJoin[{$UserBaseDirectory, "Applications", "ContinuedFractions.m"}]] and << ContinuedFractions` –  halmir Oct 29 '13 at 15:03
    
I wonder why this package is not integrated into the kernel. I suspect there are some subtleties that it cannot yet handle. Btw, you may want to show the FullForm of your example. –  David Carraher Oct 29 '13 at 15:48
add comment

Or, without the package, you can use

RealDigits[19/7]
{{2, {7, 1, 4, 2, 8, 5}}, 1}

which shows the repeated decimal portion in the second (list) element of the answer. This tells you that the answer is 2 followed by repeating 714285. The final 1 is the exponent and allows the same representation to handle much larger or smaller numbers.

share|improve this answer
    
Yes, RealDigits is the place to start. –  David Carraher Oct 29 '13 at 15:22
add comment

Here you will find a discussion of issues related to the production of repeated decimals.

The code is reproduced below for convenience.

repeatingDecimal[n_Integer | n_Real] := n

Format[repeatingDecimal[q_Rational]] := 
Row@Flatten[{IntegerPart@q, ".", RealDigits@FractionalPart@q} /. {{nr___Integer, r_List: {}}, 
  pt_} :> {Table[0, {-pt}], nr, OverBar /@ r}]

repeatingDecimal[q_] + x_ ^:= q + x
repeatingDecimal[q_]*x_ ^:= q*x
repeatingDecimal[q_]^x_ ^:= q^x

Examples

n1 = 1; n2 = 15; ClearAll[i, k, r];
TableForm[Table[repeatingDecimal[i/j], {i, n1, n2}, {j, n1, n2}], 
TableHeadings -> {None, Table[("r")/k, {k, n1, n2}]}]

table


Simple arithmetic operations such as addition can be carried out on the repeating decimals.

a = repeatingDecimal[7/31];
b = repeatingDecimal[24/31];
Print["a = ", a]
Print["b = ", b]
Print["a + b = ", a, " + ", b, " = ", a + b]

notation

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.