Representation of complex numbers in redundant numeration systems | Basics

Positional numeration systems

A positional numeration system is the most common way of representing numbers. It consists of a number Ξ², the base, and a set of numbers π’Ÿ, the digits. Usually the base and digits are positive integers, but the definition can be generalized to any abelian group, with multiplication by a base being replaced with a group endomorphism [optimality-width-w]. However, for the purposes of this project, it will suffice to generalize the notion to complex numbers.

Definition 1.1. A positional numeration system is an ordered pair (Ξ²,π’Ÿ), where Ξ²βˆˆβ„‚ and π’ŸβŠ‚β„‚ is a finite set.
Definition 1.2. Let (Ξ²,π’Ÿ) be a positional numeration system and (xn,…,x0) a finite sequence where each xkβˆˆπ’Ÿ. Then the number represented by the sequence (xn,…,x0) in base Ξ² is x=(xnβ‹―x0)Ξ²β‰”βˆ‘k=0nxkΞ²k. The sequence (xn,…,x0) is called a (Ξ²,π’Ÿ)-representation of x, x0 is its least significant digit and xn is its most significant digit.
Example. Let Ξ²=4,π’Ÿ={0,1,2,3}. Then (133220)4=1β‹…45+3β‹…44+3β‹…43+2β‹…42+2β‹…41+0β‹…40=2024.
Example. Let Ξ²=Ο†=1+52,π’Ÿ={Β±1}. Then ((βˆ’1)11)Ο†=βˆ’1β‹…Ο†2+1β‹…Ο†1+1β‹…Ο†0=0.
Example. Let Ξ²=i,π’Ÿ={0,1}. Then (11001100110011001100)i=βˆ‘k=04(i4k+2+i4k+3)=βˆ’5βˆ’5i.
Note. A positional representation of a number is not necessarily unique. For example, with Ξ²=2,π’Ÿ={0,1,2}, (1000)2=(200)2=(120)2=(112)2=8.
Definition 1.3. A positional representation (xn,…,x0) is called reduced if xnβ‰ 0. As a special case, the empty representation (representing the number 0) is reduced.

Since adding leading zeros to a representation does not change its value, we will usually consider representations that differ only in leading zeros to be the same, with the reduced representation being their canonical form. In some cases, it is more useful to consider all representations as implicitly having an infinite sequence of zeros to their left.

It is a well-known fact that if Ξ² is an integer greater than 1 and π’Ÿ={0,…,Ξ²βˆ’1}, as in our usual decimal systems, then every non-negative integer has a unique reduced representation. However, the basic concept of the proof is going to be useful later for proving similar facts about more unusual systems.

Definition 1.4. Let Ξ²βˆˆβ„€,Ξ²β‰₯2,π’Ÿ={0,…,Ξ²βˆ’1}. Then (Ξ²,π’Ÿ) is the standard positional numeration system with base Ξ².
Theorem 1.5. Let (Ξ²,π’Ÿ) be a standard positional numeration system. Then every xβˆˆβ„•0 has exactly one reduced (Ξ²,π’Ÿ)-representation (xn,…,x0).
Proof. It follows immediately from Definition 1.2 that if x=(xnβ‹―x0)Ξ², then x≑x0(modΞ²). Since every digit from π’Ÿ belongs to a different congruence class modulo Ξ² and all classes are covered, this uniquely determines x0. Since (xnβ‹―x0)Ξ²=x0+Ξ²β‹…(xnβ‹―x1)Ξ² (which also follows from the definition), (xn,…,x1) has to be a (Ξ²,π’Ÿ)-representation of xβˆ’x0Ξ² (which is obviously a non-negative integer). Therefore, the same argument can be used to uniquely find the value of x1. Since xβˆ’x0Ξ²<x for all xβ‰ 0, repeating this process will eventually result in trying to find a representation of 0. Since 0 obviously has exactly one represention that does not start with 0 β€” the empty string, this gives an algorithm for finding the (Ξ²,π’Ÿ)-representation of x along with a proof of its uniqueness.
Example. Let us find the base-17 representation of 2024 (with digits {0,1,…,16}). We start by dividing 2024 by 17 with remainder: 2024=119β‹…17+1 From this, we know that the representation ends in 1, which is preceded by the representation of 119. We perform another division: 119=7β‹…17+0 This tells us that the representation of 119 ends in 0, preceded by the representation of 7. Since 7<17, its representation is just the single digit 7; if we were to continue dividing, we would get an infinite sequence of leading zeros. Therefore, the standard base-17 representation of 2024 is (701)17.

NAF binary representations

Consider the positional numeration system with Ξ²=2 and π’Ÿ={0,Β±1}. For the sake of compactness, we will write βˆ’1 as 1β€Ύ when used as a digit (this notation is not to be confused with the notation for complex conjugation). This system can represent any xβˆˆβ„€, including negative integers: simply take the standard binary representation of |x| and multiply all digits by sgn⁑x. In this system, many integers have multiple representations, for example (101)2=(111β€Ύ)2=(101β€Ύ1β€Ύ)2=(11β€Ύ01)2=5. However, it turns out that if we add a simple restriction to which representations are eligible, reduced representations will once again be unique. [binary-arithmetic]

Definition 1.6. A positional representation (xn,…,x0) is in non-adjacent form (NAF) if there are no two non-zero digits next to each other, that is, βˆ€kβˆˆβ„•:xk=0∨xk+1=0, using the convention of representations having infinitely many leading zeros.
Note. If all non-zero digits have an absolute value of 1 (as is the case with π’Ÿ={0,Β±1}), Definition 1.6 can be equivalently written in a more compact, but also more obfuscated way: βˆ€kβˆˆβ„•:|xk|+|xk+1|≀1.
Example. Out of the aforementioned representations of 5: (101)2,(111β€Ύ)2,(101β€Ύ1β€Ύ)2,(11β€Ύ01)2, precisely one is in non-adjacent form, namely (101)2. It turns out that this is the case for all integers, as shown in the following theorem.
Theorem 1.7. Let π’Ÿ={0,Β±1}. Then every xβˆˆβ„€ has exactly one reduced (2,π’Ÿ)-representation (xn,…,x0) with the NAF property.
Proof. Analogously as in the proof of Theorem 1.5, we need to have x0≑x(mod2). If x is even, this uniquely determines x0 to be 0; we can then recursively find a represention of x2. If x is odd, we have two options: either choose x0=1 and find a representation of xβˆ’12, or choose x0=βˆ’1 and find a representation of x+12. Either way, x0 will be a non-zero digit, so in order to fulfill the NAF constraint, we need x1=0, which means that (xnβ‹―x1)2 has to be even. Since exactly one of xΒ±12 is even, we have precisely one choice. Repeating this process, we will eventually reach 0, since for all non-zero x we have |xβˆ’x02|<|x|.
Example. Let us find the NAF binary representation of 119. Since 119 is odd, its representation has to end in either 1 or 1β€Ύ. If we were to choose 1, we would have to find a representation of 119βˆ’12=59 and then append the 1 to it. However, since 69 is also odd, the resulting representation would end in two non-zero digits, making it not NAF. So instead, we need to use 1β€Ύ as the last digit and prepend the representation of 119+12=60. 60 is even, so its representation ends in a zero, exactly as we need. After dividing by 2, we get the even number 30, giving us another zero. After that, we have to find a representation of 15. Again, it is necessary to choose 1β€Ύ because choosing 1 would violate the NAF condition. After a few more divisions by 2, we get to 1, which must be represented as 1 because any other of its infinitely many representations is not NAF: 1=(1)2=(11β€Ύ)2=(11β€Ύ1β€Ύ)2=(11β€Ύ1β€Ύ1β€Ύ)2=β‹―. Putting all this together, we obtain the desired NAF representation 119=(10001β€Ύ001β€Ύ)2.

The system with Ξ²=2,π’Ÿ={0,Β±1} also has the useful property that it is possible to tell the sign of a number just from the first non-zero digit of its representation, no matter whether the representation is NAF. We will need this property later, so here is a simple proof.

Theorem 1.8. Let π’Ÿ={0,Β±1} and (xn,…,x0) be a reduced (2,π’Ÿ) representation of a non-zero integer x. Then sgn⁑x=sgn⁑xn.
Proof. We shall prove the case xn=1, the proof for xn=βˆ’1 is analogous. From Definition 1.2: x=βˆ‘k=0nxk2k=2n+βˆ‘k=0nβˆ’1xk2kβ‰₯2n+βˆ‘k=0nβˆ’1βˆ’2k=2nβˆ’2nβˆ’12βˆ’1=1

NAF binary representations have the interesting property that they contain the fewest non-zero digits out of all (2,π’Ÿ)-representations of the same number. As mentioned in the introduction, this has positive implications for parallel multiplication algorithms. In order to prove this fact, we first need some definitions and a lemma.

Definition 1.9. The Hamming weight of a (Ξ²,π’Ÿ)-representation (xn,…,x0) is its count of non-zero digits: W(xn,…,x0)≔|{k∈{0,…,n}|xkβ‰ 0}|.
Note. If all non-zero digits in π’Ÿ have an absolute value of 1, then Definition 1.9 can be equivalently expressed as W(xn,…,x0)β‰”βˆ‘k=0n|xk|.
Definition 1.10. A (Ξ²,π’Ÿ)-representation is optimal if its Hamming weight is minimal among all (Ξ²,π’Ÿ)-representations of the same number.
Lemma 1.11. Let π’Ÿ={0,Β±1}. Then any (2,π’Ÿ)-representation (xn,…,x0) can be converted to a NAF (2,π’Ÿ)-representation of the same number by repeatedly applying the following substitutions:
Proof. It is obvious from Definition 1.2 that the substitutions preserve the value of the representation. Also, if this procedure terminates, then the resulting representation has to be NAF, because if there was a pair of non-zero digits next to each other, one of the substitutions could be applied to the first such pair. Therefore, we only need to prove that this procedure terminates. Suppose that xn=1; the proof is analogous for xn=βˆ’1. Clearly, the only way the representation can increase in length is by applying the third substitution at the beginning: 11ynβˆ’2β‹―y0β†’101β€Ύynβˆ’2β‹―y0 In order for the representation to increase in length again, a series of substitutions would have to change 01β€Ύynβˆ’2β‹―y0 into 1znβˆ’1znβˆ’2β‹―z0. However, by Theorem 1.8, the former represents a negative number, whereas the latter represents a positive number. Since the substitutions preserve the value, this is impossible. Therefore, the length of the initial representation can increase at most once. In other words, the length of all intermediate representations is at most n+2. For a given intermediate representation (yn+1,…,y0), we define s(yn+1,…,y0)β‰”βˆ‘k=0n+1(n+2βˆ’k)|yk|. It can be easily verified that every substitution strictly decreases s. Since s is a non-negative integer, the procedure always terminates.
Example. Consider the number 119 with its standard binary representation (1110111)2. By applying these substitutions from right to left, we obtain 119=0(1110111)2=0(111101β€Ύ1)2=0(1111001β€Ύ)2=(101β€Ύ11001β€Ύ)2=(1001β€Ύ1001β€Ύ)2=(10001β€Ύ001β€Ύ)2 This gave us the same result as the modular algorithm, which was to be expected because binary NAF representations are unique according to Theorem 1.7. Notice that several of the substitutions decreased the Hamming weight of the representation, whereas none of them increased it. This is the key to proving that binary NAF representations are optimal, as formalized by the following theorem.
Theorem 1.12. Binary NAF representations are optimal: Let π’Ÿ={0,Β±1}. Let (xn,…,x0) and (ym,…,y0) be two (2,π’Ÿ)-representations of the same integer, with (xn,…,x0) also being NAF. Then W(xn,…,x0)≀W(yn,…,y0).
Proof. By Lemma 1.11, we can convert (ym,…,y0) into a NAF representation (zl,…,z0) of the same number. None of the possible substitutions increase the Hamming weight, therefore W(zl,…,z0)≀W(ym,…,y0). According to Theorem 1.7, binary NAF representations of the same number are equal, so W(zl,…,z0)=W(xn,…,x0), which concludes the proof.

Not only are binary NAF representations optimal, they have asymptotically fewer non-zero digits on average than standard binary representations. To be specific: If we list all possible standard binary representations of some fixed length (not necessarily reduced), obviously exactly half of the digits will be 0 and the other half will be 1. However, if we do the same with NAF representations in signed binary, the total proportion of non-zero digits will only be approximately 13, as shown in the following theorem.

Theorem 1.13. Let π’Ÿ={0,Β±1}. Let an be the number of all (not necessarily reduced) NAF (2,π’Ÿ)-representations of length n and bn the sum of the Hamming weights of these representations. Then limnβ†’βˆžβ‘bnnan=13. That is, for an average sufficiently long NAF (2,π’Ÿ)-representation, about 13 of its digits are non-zeros.
Proof. [Proof (taken and modified from [algebraicke-metody]).] Let us find an explicit formula for an and bn. We can think of NAF (2,π’Ÿ)-representations as consisting of three kinds of β€œblocks”: 0,01Β andΒ 01β€Ύ. Note that these blocks can only be used to construct representations starting with a zero, so we are actually expressing anβˆ’1 and bnβˆ’1, but this does not matter when nβ†’βˆž. Take one representation with n digits and let k be its Hamming weight, which corresponds to the number of 01 and 01β€Ύ blocks. These blocks take up 2k digits, so the number of 0 blocks is nβˆ’2k, for a total of nβˆ’k blocks. There are (nβˆ’kk) ways to choose which of these blocks contain a non-zero digit and 2k ways to choose whether the digit will be 1 or 1β€Ύ. Therefore, the total number of these representations is an=βˆ‘k=0∞2k(nβˆ’kk) and the sum of Hamming weights is bn=βˆ‘k=0∞k2k(nβˆ’kk), where we define (nk)≔0 for k>n so that we do not have to worry about the upper limit. If we also define (nk)≔0 for k<0, the formula (nk)=(nβˆ’1k)+(nβˆ’1kβˆ’1) will work for all k, which we can use in finding a recursive expression for an: an=βˆ‘k=0∞2k(nβˆ’kk)=βˆ‘k=0∞2k(nβˆ’kβˆ’1k)+βˆ‘k=0∞2k(nβˆ’kβˆ’1kβˆ’1)=βˆ‘k=0∞2k(nβˆ’kβˆ’1k)+βˆ‘k=βˆ’1∞2k+1(nβˆ’kβˆ’2k)=βˆ‘k=0∞2k(nβˆ’kβˆ’1k)+2βˆ‘k=0∞2k(nβˆ’kβˆ’2k)=anβˆ’1+2anβˆ’2. Solving this recurrence using its characteristic polynomial Ξ»2βˆ’Ξ»βˆ’2=(Ξ»βˆ’2)(Ξ»+1), we get an=Ξ±2n+Ξ²(βˆ’1)n for some Ξ±,Ξ²βˆˆβ„. Clearly Ξ±β‰ 0, otherwise some terms would be negative. For bn, we analogously have bn=βˆ‘k=0∞k2k(nβˆ’kk)=βˆ‘k=0∞k2k(nβˆ’kβˆ’1k)+βˆ‘k=0∞k2k(nβˆ’kβˆ’1kβˆ’1)=βˆ‘k=0∞k2k(nβˆ’kβˆ’1k)+βˆ‘k=βˆ’1∞(k+1)2k+1(nβˆ’kβˆ’2k)=βˆ‘k=0∞k2k(nβˆ’kβˆ’1k)+2βˆ‘k=0∞k2k(nβˆ’kβˆ’2k)+2βˆ‘k=0∞2k(nβˆ’kβˆ’2k)=bnβˆ’1+2bnβˆ’2+2anβˆ’2=bnβˆ’1+2bnβˆ’2+2Ξ±2nβˆ’2+2Ξ²(βˆ’1)nβˆ’2. This is a non-homogenous linear recurrence. The homogenous solution is the same as for an, except with possibly different coefficients Ξ±~,Ξ²~βˆˆβ„: bnhom=Ξ±~2n+Ξ²~(βˆ’1)n The particular solution is of the form bnpar=ΞΌn2n+Ξ½n(βˆ’1)n for some ΞΌ,Ξ½βˆˆβ„. We can find those by substituting in the recurrence: ΞΌn2n+Ξ½n(βˆ’1)nβˆ’ΞΌ(nβˆ’1)2nβˆ’1βˆ’Ξ½(nβˆ’1)(βˆ’1)nβˆ’1βˆ’2ΞΌ(nβˆ’2)2nβˆ’2βˆ’2Ξ½(nβˆ’2)(βˆ’1)nβˆ’2=2Ξ±2nβˆ’2+2Ξ²(βˆ’1)nβˆ’2 Collecting terms with 2n and cancelling, we obtain ΞΌ(nβˆ’nβˆ’12βˆ’nβˆ’22)=Ξ±2 ΞΌ=Ξ±3β‰ 0 This suffices to evaluate the desired limit, since only the fastest-growing terms matter: limnβ†’βˆžβ‘bnnan=limnβ†’βˆžβ‘Ξ±~2n+Ξ²~(βˆ’1)n+Ξ±3n2n+Ξ½n(βˆ’1)nΞ±n2n+Ξ²n(βˆ’1)n=13

In Theorem 1.13, we have shown that NAF binary representations of a fixed length have an asymptotically smaller Hamming weight than standard binary representations. However, one might object that if, on average, the NAF representation of a given number is significantly longer than the standard binary representation, this might not result in such an improvement for fixed numbers. However, as shown in the following theorem, a NAF binary representation of a given integer is at most one digit longer than its standard binary representation. This is in fact already apparent from the proof of Lemma 1.11, but can easily be proven separately.

Theorem 1.14. Let π’Ÿ={0,Β±1}. Let x be a non-zero integer. Then the reduced NAF (2,π’Ÿ)-representation of x has at most ⌊log2⁑|x|βŒ‹+2 digits.
Proof. Let hn be the smallest positive integer whose binary NAF representation consists of exactly n digits. From Theorem 1.8, we know that the representation starts with 1. To minimize the value while respecting the NAF condition, it is easy to see that this 1 is followed by alternating 0 and 1β€Ύ, so for all mβˆˆβ„•0, h2m+1=(1(01β€Ύ)m)2,h2m+2=(1(01β€Ύ)m0)2. Consider first the odd case n=2m+1. By Definition 1.2, hn=h2m+1=22mβˆ’βˆ‘k=0mβˆ’122k=22mβˆ’βˆ‘k=0mβˆ’14k=22mβˆ’4mβˆ’13=2n+13, n=log2⁑(3hnβˆ’1)<log2⁑(4hn)=log2⁑hn+2. Since hn has the minimal absolute value out of all integers with an n-digit NAF (2,π’Ÿ)-representation, this concludes the proof for odd n. For even n, hn=2hnβˆ’1, so by the already proven odd case, n=(nβˆ’1)+1<log2⁑hnβˆ’1+2+1=log2⁑hn+2.

Complex integers

There are two different natural ways to extend the concept of an integer to complex numbers: either using a square lattice, or using a triangular lattice. These generalizations are called Gaussian integers and Eisenstein integers respectively.

Definition 1.15. The Gaussian integers are the numbers β„€[i]≔{a+bi|a,bβˆˆβ„€}.
Definition 1.16. Let ω≔exp⁑(23Ο€i)=βˆ’12+32i. The Eisenstein integers are the numbers β„€[Ο‰]≔{a+bΟ‰|a,bβˆˆβ„€}.

It is obvious how to naturally extend the notion of divisibility and modular arithmetic to integers. A more interesting question is how to extend the notion of parity. We could, just like in the ordinary integers, define a complex integer to be even if it is divisible by 2. However, this way we would lose the useful property that if x is even, then xΒ±1 is odd and vice-versa. Instead, we will use the following definition for the case of Gaussian integers, which preserves this property (additionally ensuring that xΒ±i also has the opposite parity from x):

Definition 1.17. Let xβˆˆβ„€[i]. If x≑0(modiβˆ’1), then x is even, otherwise x is odd. (Note that divisibility by iβˆ’1 is the same as divisibility by i+1, we are choosing the former for reasons that will be apparent soon.)

However, it is not possible to do this with Eisenstein integers, the reason being that the triangular grid is not a bipartite graph. Note that if there were names for different congruence classes modulo 3, they could be generalized to Eisenstein integers by considering congruence classes modulo Ο‰βˆ’1.

The most obvious way to represent complex integers using a positional numeration system is to simply choose a system for representing regular integers and apply it component-wise. However, with the right choice of base and digits, we can naturally represent both kinds of complex integers directly. [binary-system-complex-numbers]

Theorem 1.18. Let Ξ²=iβˆ’1,π’Ÿ={0,1}. Then every Gaussian integer x has a unique reduced (Ξ²,π’Ÿ)-representation (xn,…,x0).
Proof. Analogously as in the proof of Theorem 1.5, if x is even (by Definition 1.17), then x0=0, otherwise x0=1. We then recursively find a representation of xβˆ’x0iβˆ’1. It remains to show that this procedure terminates. We can estimate |xβˆ’x0iβˆ’1|=|xβˆ’x0|2≀|x|+|x0|2≀|x|+12. This implies that if |x|>2+1, then |xβˆ’x0iβˆ’1|<|x|. Since |x| is always the square root of an integer, after finitely many steps we will reach an x such that |x|≀2+1. Therefore, we just have to manually check that every such x has a representation. There are 21 such numbers: 0=()iβˆ’1,1=(1)iβˆ’1,i=(11)iβˆ’1,βˆ’1=(11101)iβˆ’1,βˆ’i=(111)iβˆ’1,1+i=(1110)iβˆ’1,βˆ’1+i=(10)iβˆ’1,βˆ’1βˆ’i=(110)iβˆ’1,1βˆ’i=(111010)iβˆ’1,2=(1100)iβˆ’1,2i=(1110100)iβˆ’1,βˆ’2=(11100)iβˆ’1,βˆ’2i=(100)iβˆ’1,2+i=(1111)iβˆ’1,βˆ’1+2i=(11001)iβˆ’1,βˆ’2βˆ’i=(11101011)iβˆ’1,1βˆ’2i=(101)iβˆ’1,1+2i=(1110101)iβˆ’1,βˆ’2+i=(11111)iβˆ’1,βˆ’1βˆ’2i=(11101001)iβˆ’1,2βˆ’i=(111011)iβˆ’1.
Note. This system is known as the Penney numeration system due to Walter F. Penney being one of the first mathematicians to work with it.
Note. It is apparent from the proofs of Theorem 1.5 and Theorem 1.18 that they could be generalized to a much larger class of positional numeration systems, with the only two requirements being that the digits uniquely cover all congruence classes modulo Ξ² and that all numbers with an absolute value within some bound have a representation. The general statement is outside the scope of this project, but can be found in [kvaterniony].
Note. It is not possible to represent every Gaussian integer with Ξ²=i+1 and π’Ÿ={0,1}. If we tried to find such a representation for some numbers, such as βˆ’1, using the modular algorithm, we would get into an infinite loop. This shows that verifying the representability of certain small numbers is an important part of the proof of Theorem 1.18 that cannot be left out.
Theorem 1.19. Let Ξ²=Ο‰βˆ’1,π’Ÿ={0,1,Ο‰+1}. Then every Eisenstein integer x has a unique reduced (Ξ²,π’Ÿ)-representation (xn,…,x0).
Proof. Analogous to the proof of Theorem 1.18. The proof is left as an exercise for the reader or it can be found in [kvaterniony].

Exercises

Exercise 1.20. Let Ξ²βˆˆβ„€,Ξ²β‰₯2. Theorem 1.5 shows the modular algorithm for finding the standard base-Ξ² representation of a non-negative integer x. There also exists a greedy algorithm for doing the same, with the difference that it produces digits starting from the most significant one. The basic idea is that we find the maximal n such that Ξ²n≀x, then set xnβ‰”βŒŠxΞ²nβŒ‹ and fill in the remaining digits by finding the representation of xβˆ’xnΞ²n. Prove that this algorithm works and use it to find the standard base-17 representation of 2024.
Exercise 1.21. Let Ξ²βˆˆβ„€,Ξ²β‰₯1,π’Ÿ={1,…,Ξ²}. The system (Ξ²,π’Ÿ) is called the bijective positional numeration system with base Ξ². Prove that every non-negative integer has a unique representation in this system (hence the name β€œbijective”). What do these representations look like when Ξ²=1?
Exercise 1.22. Prove Theorem 1.19.