7
$\begingroup$

Suppose I have a base two number that repeats itself every five places (a number $x$ such that $0\le x<1$. For example:

$$x=0.101011010110101101011010110101101011010110101...$$

What would be a cool way to start with:

x={1,0,1,0,1}

Then, thinking of this five number list as repeating itself forever, use Mathematica to change it to a base 10 number.

Update: My question came as a result of @Kagaratsch's answer at Using a piecewise defined sequence, find all $x_0$. Thanks to @Xavier's answer, now I can do this:

mytup = Tuples[{0, 1}, 5]
FromDigits[{{#}, 0}, 2] & /@ Most[mytup]
$\endgroup$
  • 3
    $\begingroup$ {1, 0, 1, 0, 1}. (2)^Range[0, 4]/(2^5 - 1) //N $\endgroup$ – Michael E2 Dec 7 '15 at 3:22
  • 3
    $\begingroup$ NSum[{1, 0, 1, 0, 1}. (2)^-Range[n + 1, n + 5], {n, 0, Infinity, 5}] $\endgroup$ – Michael E2 Dec 7 '15 at 3:24
  • $\begingroup$ @MichaelE2 Great answer. Thanks. $\endgroup$ – David Dec 7 '15 at 3:48
  • $\begingroup$ @MichaelE2 better still, your expression with plain Sum produces the exact 21/31 result. $\endgroup$ – george2079 Dec 7 '15 at 18:07
  • $\begingroup$ @george2079 Yeah, I realized that, but I thought the question asked for numerical, decimal result. I suppose RealDigits@Sum[{1, 0, 1, 0, 1}. (2)^-Range[n + 1, n + 5], {n, 0, Infinity, 5}] or {1, 0, 1, 0, 1}. (2)^Range[0, 4]/(2^5 - 1) // RealDigits might be more in line with @David's question. $\endgroup$ – Michael E2 Dec 7 '15 at 21:54
9
$\begingroup$

You can use

FromDigits[{{{1, 0, 1, 0, 1}}, 0}, 2]

where {1, 0, 1, 0, 1} is the infinite repeating part, 0 the length of the integer part, and 2 the base in which the number is given. The output will be given in base ten.

FromDigits[{{{1, 0, 1, 0, 1}}, 0}, 2]
(* 21/31 *)
$\endgroup$
  • $\begingroup$ Wow! Haven't seen this one before. Thanks. $\endgroup$ – David Dec 7 '15 at 3:49
  • $\begingroup$ See my update to my original post. Thanks to you, I found this idea in the documentation. $\endgroup$ – David Dec 7 '15 at 3:57
2
$\begingroup$

It should be clear that if x = 0.101011010110101.... then 2^5 x = 10101.1010110101... so 32 x - x = 10101 = 21, then x = 21/31.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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