Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's an attempt. Mr.Wizard did much of the heavy lifting, especially in the base-preserving arithmetic.</p> <pre><code>rd[n_] := rd[n, 10] rd[rd[n_, _], b_] := rd[n, b] Format[rd[n_Integer | n_Real, base_]] := BaseForm[n, base] Format[rd[q_Rational, base_]] := Subscript[Row @ Flatten[{ IntegerString[IntegerPart@q, base], ".", RealDigits[FractionalPart@q, base] /. {{nr___, r_List:{}}, pt_} :&gt; {0~Table~{-pt}, nr, OverBar /@ r} }], base /. 10 -&gt; ""] </code></pre> <p>Base-preserving arithmetic can be implemented using this:</p> <pre><code>Scan[ (#[rd[q1_, b1_], rd[q2_, b2_] | tail___] ^:= rd[ #[q1, q2, tail], If[b1 === b2, b1, 10] ]) &amp;, {Plus, Times, Power} ] </code></pre> <p>Checking to see that conversions to repeating decimals in several bases work. Also checking routines for adding, multiplying, and dividing:</p> <pre><code>Grid[{{"n", "value", "decimal", "rd[n,10]", "rd[n,2]", "rd[n,3]", "rd[n,7]"}, {"a", a = 14/3, N[a], rd[a, 10], rd[a, 2], rd[a, 3], rd[a, 7]}, {"b", b = 2/5, N[b], rd[b, 10], rd[b, 2], rd[b, 3], rd[b, 7]}, {"c", c = 1/2, N[c], rd[c, 10], rd[c, 2], rd[c, 3], rd[c, 7]}, {"a + b", a + b, N[a + b], rd[a, 10] + rd[b, 10], rd[a, 2] + rd[b, 2], rd[a, 3] + rd[b, 3], rd[a, 7] + rd[b, 7]}, {"a + b + c", a + b + c, N[a + b + c], rd[a, 10] + rd[b, 10] + rd[c, 10], rd[a, 2] + rd[b, 2] + rd[c, 2], rd[a, 3] + rd[b, 3] + rd[c, 3], rd[a, 7] + rd[b, 7] + rd[c, 7]}, {"a \[Times] b ", a*b, N[a*b], rd[a, 10]*rd[b, 10], rd[a, 2]*rd[b, 2], rd[a, 3]*rd[b, 3], rd[a, 7]*rd[b, 7]}, {"a \[Times] b \[Times] c ", a*b*c, N[a*b*c], rd[a, 10]*rd[b, 10]*rd[c, 10], rd[a, 2]*rd[b, 2]*rd[c, 2], rd[a, 3]*rd[b, 3]*rd[c, 3], rd[a, 7]*rd[b, 7]*rd[c, 7]}, {"a / b", a/b, N[a/b], rd[a, 10]/rd[b, 10], rd[a, 2]/rd[b, 2], rd[a, 3]/rd[b, 3], rd[a, 7]/rd[b, 7]}}, Dividers -&gt; All] </code></pre> <p><img src="https://i.stack.imgur.com/Pq7wT.png" alt="summary table"></p> <hr> <p><strong>Edit</strong></p> <p>The latest refinements (credit, once again, to Mr.Wizard) support nesting:</p> <pre><code>ClearAll[f, x, y] f := (x/(x + 3 + 2 y) + y)/7 x; f f // FullForm x = 14/3; y = 1/3; f BaseForm[N[f], 10] x = rd[14/3, 10]; y = rd[1/3, 10]; f x = rd[14/3, 2]; y = rd[1/3, 2]; f x = rd[14/3, 5]; y = rd[1/3, 5]; f </code></pre> <p><img src="https://i.stack.imgur.com/xH3Hb.png" alt="nesting"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload