A non-integer representation uses non-integer numbers as the radix, or base, of a positional numeral system. For a non-integer radix β > 1, the value of
is
The numbers di are non-negative integers less than β. This is also known as a β-expansion, a notion introduced by and first studied in detail by . Every real number has at least one (possibly infinite) β-expansion. The set of all β-expansions that have a finite representation is a subset of the ring Z[β, β−1].
There are applications of β-expansions in coding theory and models of quasicrystals (; ).
Construction
β-expansions are a generalization of decimal expansions. While infinite decimal expansions are not unique (for example, 1.000... = 0.999...), all finite decimal expansions are unique. However, even finite β-expansions are not necessarily unique, for example φ + 1 = φ2 for β = φ, the golden ratio. A canonical choice for the β-expansion of a given real number can be determined by the following greedy algorithm, essentially due to and formulated as given here by .
Let be the base and x a non-negative real number. Denote by the floor function of x (that is, the greatest integer less than or equal to x) and let be the fractional part of x. There exists an integer k such that . Set
and
For , put
In other words, the canonical β-expansion of x is defined by choosing the largest dk such that , then choosing the largest dk−1 such that , and so on. Thus it chooses the lexicographically largest string representing x.
With an integer base, this defines the usual radix expansion for the number x. This construction extends the usual algorithm to possibly non-integer values of β.
Conversion
Following the steps above, we can create a β-expansion for a real number (the steps are identical for an , although must first be multiplied by to make it positive, then the result must be multiplied by to make it negative again).
First, we must define our value (the exponent of the nearest power of greater than , as well as the amount of digits in , where is written in base ). The value for and can be written as:
After a value is found, can be written as , where
for . The first values of appear to the left of the decimal place.
This can also be written in the following pseudocode: function toBase(n, b) { k = floor(log(b, n)) + 1 precision = 8 result = ""
for (i = k - 1, i > -precision-1, i--) {
if (result.length == k) result += "."
digit = floor((n / b^i) mod b) n -= digit * b^i result += digit }
return result
}
Note that the above code is only valid for and , as it does not convert each digits to their correct symbols or correct negative numbers. For example, if a digit's value is , it will be represented as instead of .
Example implementation code
To base
JavaScript:function toBasePI(num, precision = 8) {
let k = Math.floor(Math.log(num)/Math.log(Math.PI)) + 1; if (k < 0) k = 0;
let digits = [];
for (let i = k-1; i > (-1*precision)-1; i--) {
let digit = Math.floor((num / Math.pow(Math.PI, i)) % Math.PI); num -= digit * Math.pow(Math.PI, i); digits.push(digit);
if (num <= 0) break; }
if (digits.length > k) digits.splice(k, 0, ".");
return digits.join(""); }
From base
JavaScript:function fromBasePI(num) {
let numberSplit = num.split(/\./g); let numberLength = numberSplit[0].length;
let output = 0; let digits = numberSplit.join("");
for (let i = 0; i < digits.length; i++) {
output += digits[i] * Math.pow(Math.PI, numberLength-i-1); }
return output; }
Examples
Base
Base behaves in a very similar way to base 2 as all one has to do to convert a number from binary into base is put a zero digit in between every binary digit; for example, 191110 = 111011101112 becomes 101010001010100010101 and 511810 = 10011111111102 becomes 1000001010101010101010100. This means that every integer can be expressed in base without the need of a decimal point. The base can also be used to show the relationship between the side of a square to its diagonal as a square with a side length of 1 will have a diagonal of 10 and a square with a side length of 10 will have a diagonal of 100. Another use of the base is to show the silver ratio as its representation in base is simply 11. In addition, the area of a regular octagon with side length 1 is 1100, the area of a regular octagon with side length 10 is 110000, the area of a regular octagon with side length 100 is 11000000, etc…