Some useful formulae
This page will be updated from time to time
Geometric series
For any number r,
1 + r + r2 + ... + rn = SUM(k=0...n) rk =
(1 - rn+1) /(1 - r), and
r + r2 + r3 + ... + rn = SUM(k=1...n) rk =
(r - rn+1)/(1 - r).
Thus, if |r| < 1 then taking the limit n -> infinity,
1 + r + r2 + r3 + . . . = SUM(k=0... infinity) rk
= 1/(1-r), and
r + r2 + r3 + . . . = SUM(k=1...infinity) rk = r/(1-r).
Combining the above formulae, we obtain,
rm + rm+1 + ... + rm+k = rm(1 + r + r2 +
. . . + rk) = (rm - rm+k+1) / (1 - r ), for any r, and
rm + rm+1 + rm+2 + . . . = SUM(k=m... infinity) rk =
rm(1 + r + r2 + . . . ) = rm /(1 - r) for |r| < 1.
Decimal, binary, and ternary expansions
Let x be any number in [0,1], and [x]a denote the expansion of x (or the
representation of x) in base a (a can be any positive integer).
Decimal expansion (a=10):
[x]10=.d1d2d3. . . , where di= 0, 1, 2,
... or 9.
Then x = d1/10 + d2/102 + d3/103. . .
Binary expansion (a = 2):
[x]2=.b1b2b3. . . , where bi= 0 or 1.
Then x = b1/2 + b2/22 + b3/23. . .
Ternary expansion (a = 3):
[x]3=.c1c2c3. . . , where ci= 0, 1 or 2.
Then x = c1/3 + c2/32 + c3/33. . .
For numbers greater than 1, there would be digits to the left of the point for the positive powers of a.
Note that some numbers may have two expansions. For example, [1/10]10 = .1 and
.099(99). Also, [3/4]2=.11 and also .1011(11). Another, [7/9]3=.021 and
also .02022(22) (this can be seen by adding up the infinite series using the geometric formula above).
(Here, (ab) denotes the repeating pattern abababab..... )
Here's the algorithm for computing the ternary expansion of a number x between 0 and 1
(there's a similar algorithm for other bases and if the number is greater than 1). Here we want to determine
c1, c2, c3, . . . where each ci is either 0, 1, or 2 such that
x = c1/3 + c2/32 + c3/33 + ... .
Determine c1;
- if 0 < x < 1/3, then c1 = 0
- if 1/3 < = x < 2/3, then c1 = 1
- if 2/3 < = x < 1, then c1 = 2
- let x1 = x - c1/3 (note that x1 < 1/3 )
Determine c2;
- if 0 < x1 < 1/32, then c2 = 0
- if 1/32 < = x < 2/32, then c2 = 1
- if 2/32 < = x < 1/3, then c2 = 2
- let x2 = x1 - c2/32 (note that x2
< 1/32)
Determine c3;
- if 0 < x2 < 1/33, then c3 = 0
- if 1/33 < = x2 < 2/33, then c3 = 1
- if 2/33 < = x2 < 1/32, then c3 = 2
- let x3 = x2 - c3/33 (note that
x3 < 1/33)
etc.
The computer code that calculates the expansion of a number x in base b,
[x]b=.b1b2b3..., is
b1 = floor(b*x); (since b*x = b1+b2/b+b3/b2...
and b2/b+b3/b2... is less than 1)
b2 = floor(b2*x - b*b1); (since b2*x =
b*b1 + b2 + b3/b + b4/b2+ ... and
b3/b + b4/b2+ ... is less than 1)
b3 = floor(b3*x - b2*b1 - b*b2);
b4 = floor(b4*x - b3*b1 - b2*b2
- b*b3);
...
...
where floor(y) is the largest integer less than or
equal to y (eg., floor(2.412) = 2, floor(3) = 3, floor(-1.23) = -2).
Some facts:
Suppose x and y are two numbers between 0 and 1. Let b be a positive
integer, and suppose the expansions of x and y in the base b agree to
the kth place, i.e.,
x = .a1a2...akak+1ak+2...
y = .a1a2...akek+1ek+2...
Then
x = a1/b + a2/b2 + . . . + ak/bk + rx
y = a1/b + a2/b2 + . . . + ak/bk + ry
So x-y = rx-ry. Now note that both rx and
ry are between (or equal to) 0 and 1/bk
(since (b-1)/bk+1 + (b-1)/bk+2 + ... = 1/bk ; use
the formula for a geometric sum), so the largest
|rx - ry| can be is 1/bk.
To summarize:
If x and y are two numbers betweeen 0 and 1 whose expansions in
base b agree up to (and including) the kth place, then |x-y| is less than or
equal to 1/bk. Conversely, if .a1a2a3...
and .e1e2e3... are two expansions in base b that
agree up to the kth place (so a1 = e1,
a2 = e2, . . . , ak = ek), then the
two numbers x = a1/b +
a2/b2 + a3/b3... and
y = e1/b + e2/b2 + e3/b3... are
within (or equal to) a distance 1/bk of one another.