Gaussian integers
We shall start by adding the digit to the Penney system; that is, we use . The natural question is whether every Gaussian integer has a NAF representation in this system. It is not hard to find that the answer is negative. For example, the number is odd, so its representation would have to end in either or , but after subtracting either digit and dividing by , we are left with another odd number, forcing us to add another non-zero digit.
However, we can add two more digits without violating the useful property that the set of digits is closed under multiplication: and . As with , we will denote as when used as a digit. The resulting system is the main subject of this project, so we shall give it a name.
Definition 2.1. The extended Penney system is the positional numeration system with and .
Obviously, most Gaussian integers can be represented in multiple ways in this system. However, they can even have multiple NAF representations, for example . This suggests that we could restrict the possible representations even further in order to possibly obtain even better results in terms of average weight. It turns out that a simple generalization of the NAF condition is sufficient.
Definition 2.2. Let . A positional representation is in -non-adjacent form (-NAF) if every contiguous subsequence of length at most contains at most one non-zero digit, that is,
Note. If all non-zero digits have an absolute value of
,
Definition 2.2 can be equivalently written in a more compact, but also more obfuscated way:
Note. Trivially, every representation is -NAF and the -NAF condition is equivalent to the original NAF condition.
Lemma 2.3. Let be an odd Gaussian integer. Then there exists exactly one such that .
Proof. Notice that
. Let
. Consider the possible congruence classes of
modulo
, which cannot have the same parity since
is odd:
- ,
- ,
- ,
- ,
- ,
- ,
- ,
- .
This shows that
exists. It is also unique because none of
are congruent modulo
.
Theorem 2.4. Every has exactly one reduced -NAF representation in the extended Penney system.
Proof. Once again, we will use a modular algorithm to find the representation. If
is even, then the last digit has to be
. If
is odd, we have a choice between four digits:
and
, but in order to fulfill the
-NAF constraint, we need the following two digits to be zeros, meaning that
has to be divisible by
.
Lemma 2.3 ensures that there is precisely one choice. Either way, we continue by finding the representation of
. It remains to be proven that this procedure terminates. This can be done using the exact same argument as in the proof of
Theorem [t-penney-uniq], except with different representations for small numbers:
Example. Let us find the -NAF representation of in the extended Penney system.
Because the number is even, we start by writing a and dividing by :
This number is odd, so we have to find an such that . We choose because is divisible by . Now, we could divide by and continue. However, we know that the next two digits will be zeros, so we might as well write them immediately and divide by directly:
We see that this is an even number, so we write another and divide by , yielding . This number is odd, so we need to find a digit which, when subtracted, gives a number divisible by . Such a digit is , giving . Again, we can write two zeros and directly divide by , getting . This is just a single digit, so we write it down and terminate, getting the result
Now that we have proven that the -NAF extended Penney system is usable for uniquely (up to leading zeros) representing Gaussian integers, the next step is to find out how it performs in terms of the Hamming weight. Like in Lemma [t-naf-subst], it can be proven that every possible extended-Penney representation can be converted into an equivalent -NAF representation using a set of substitutions that never increase the Hamming weight. However, this set consists of a total of substitutions and requires temporarily switching to a larger set of digits. Therefore, we are going to avoid this method of proving the optimality of the representations and leave it for the next chapter, which is going to introduce a transducer for converting any representation to -NAF. What we can prove right now, however, is a result analogous to Theorem [t-naf-ratio]: the asymptotic behavior of the ratio of non-zero digits to all digits.
Theorem 2.5. Let be the number of all (not necessarily reduced) -NAF extended Penney system representations of length and the sum of the Hamming weights of these representations. Then . That is, for an average sufficiently long -NAF extended Penney system representation, about of its digits are non-zeros.
Proof. Let us find an explicit formula for and . We can think of -NAF extended Penney system representations as consisting of five kinds of βblocksβ: . Note that these blocks can only be used to construct representations starting with two zeros, so we are actually expressing and , but this does not matter when . Analougously as in the proof of Theorem [t-naf-ratio], we derive
and find a recurrence relation for :
Solving this recurrence using its characteristic polynomial where , we get
for some . Finding a recurrence for :
Homogenous solution:
Particular solution:
It is evident from the proof of Theorem [t-naf-ratio] that we only need to find the value of , since . Therefore, when substituting in the recurrence, we only consider terms with :
Substituting into the limit:
Notice that this is more efficient in terms of the non-zero digits ratio than if we were to represent Gaussian integers by representing the real and imaginary parts separately using the binary NAF system, which would yield a ratio of as shown in Theorem [t-naf-ratio].