Number Bases part 5: Positive real number bases

Positive real number bases allow you to convert a number from one base to another without the restriction of using whole numbers and integer bases. So instead of just having to use just base 3 or base 4, you can use base 3.2657. This also allows you to handle fractional numbers as well. In other words, it’s going to get esoteric. Hopefully this explanation will make it less so. But if not, ummm…. You can look at the references.

First off, Positive real number bases are also known as beta expansions. It was first defined in 1957 by A. Rényi who was discussing a representation of a recursive function he called ‘f- expansion’. Then later on in his paper he discussed a class of this f-expansion that he named beta expansion. So it’s just the name the guy picked.

The real base system is defined to work for any base greater than one. So a base 1 can’t be used but base 1.0001 can. You can get as close to one as you’d like, but it can’t be one. Though the closer to one you get the larger the number you get. For example, the value 2 (in base 10) is the following value in base 1.001: 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.

Note that base 1.001 used two different characters. While an integer base will use the number of characters its value is (base 10 uses ten characters, base 11 uses eleven characters), a real base uses the number of characters when you round the base up to the next whole number. So rounding base 1.001 up is two, and that’s how many characters it uses. Base 2.995 will use three characters; base 3.00023 will use four characters. Rounding up this way is also called taking the ceiling of a number and comes with these fancy brackets: \left \lceil\;\right\rceil. Likewise rounding down (2.995 rounded down becomes 2) is called the floor and has these brackets: \left \lfloor \; \right \rfloor.

So to convert from a number in base ten to any base B greater than 1 requires a transformation function that is helpfully named TB(x). This is defined to be Bx-\left \lfloor Bx \right \rfloor. In actual words this function returns the fractional part of a number (the 0.141592 from 3.141592) when that number is multiplied by the base B. So for example, if x was 34.5 and B was 2.7, this function would return 0.15. This function is also called recursively. But to avoid RuntimeError: maximum recursion depth exceeded, it can be put into a while loop. So to convert a number N in base 10 to base B, it’s defined as the following:

N = \sum_{i=1}^{\infty }\frac{a_{i}}{B^{i}} \;\; \textup{with} \;\; a_{i}=\left \lfloor T_{B}^{i-1}(N) \right \rfloor

Where the confusing T_{B}^{i-1}(N) notation means to recursively call the TB(x) function. The ai’s are the values that you store which correspond to their characters which you use to represent the number in the new base.

But wait! This is only defined for any number N that’s between zero and one! That’s not helpful! I want to be able to convert any number, not just numbers between zero and one!

Luckily though there is a number (that I’m totally calling M) that is between zero and one which is equal to N/BP where P is some integer that cuts N down to size. This is usually the ceiling of the logarithm of N with respect to B. So instead of starting at 1 and summing up to infinity (that takes some time), We can start at P and sum down to negative infinity (also takes some time, but we can stop when it gets too small to matter for practical purposes). Thus it’s now the following:

Confusing_Beta_Expansion

(though I think I just made that more confusing)

In this case we are starting from the top of the summation sign and head to the bottom, subtracting 1 from i and adding 1 to j for each iteration. We go through the sum, store the ai’s and from there we have our number in base B. This only works for positive numbers though. But that’s easy to take care of. If the number N is negative, we just make note of it, make it positive, convert it to the new base, and then make it negative again. Code wise (Python) it looks like this:

def toBaseB(N,B):
    'Converts a number N in base 10 to base B (>1). Returns a list of digits'
    if N==0:return[0]
    from math import log,ceil,floor

    D=[]#digit list
    prec=-10#how many decimal places to go

    if N<0:D=['-'];N*=-1#negative number, note its negative in the digit list D, make n positive

    P=ceil(log(abs(N),B))#get log power, take the ceiling of it.
    M=N/pow(B,P)

    if P<0:#starting with a fractional value
        D.extend([0,'.'])
        D.extend(([0]*-int(P)))

    def T(x):return B*x-floor(B*x)#the transformation function

    while P>prec:
        a=int(M*B)#get digit
        M=T(M)#call transformation function
        if P==0 and'.'not in D:D.append('.')#don't add this if its already there!
        D.append(a)#store the digit
        P-=1
    return D

A note about the confusing notation of T_{B}^{j}(M) :when j=0, the function is equal to M, when j=1, the function is TB(M), when j=2, its TB(TB(M)), when j=3, its TB(TB(TB(M))) and so on.

References:
1.’Representations for real numbers and their ergodic properties’ A. Rényi, Acta Mathematica Academic Sci. Hungar. Vol. 8, pg. 477, 1957
2. http://arxiv.org/abs/0912.4597v3

Posted in Number Bases

Leave a comment

In Archive
Design a site like this with WordPress.com
Get started