AN codes

From HandWiki

AN codes[1] are error-correcting code that are used in arithmetic applications. Arithmetic codes were commonly used in computer processors to ensure the accuracy of its arithmetic operations when electronics were more unreliable. Arithmetic codes help the processor to detect when an error is made and correct it. Without these codes, processors would be unreliable since any errors would go undetected. AN codes are arithmetic codes that are named for the integers [math]\displaystyle{ A }[/math] and [math]\displaystyle{ N }[/math] that are used to encode and decode the codewords.

These codes differ from most other codes in that they use arithmetic weight to maximize the arithmetic distance between codewords as opposed to the hamming weight and hamming distance. The arithmetic distance between two words is a measure of the number of errors made while computing an arithmetic operation. Using the arithmetic distance is necessary since one error in an arithmetic operation can cause a large hamming distance between the received answer and the correct answer.

Arithmetic Weight and Distance

The arithmetic weight of an integer [math]\displaystyle{ x }[/math] in base [math]\displaystyle{ r }[/math] is defined by

[math]\displaystyle{ w(x) = \min \{t | x=\sum_{i=1}^t a_i r^{n(i)}\} }[/math][citation needed]

where [math]\displaystyle{ |{a_i}| }[/math]< [math]\displaystyle{ r }[/math], [math]\displaystyle{ n(i) \geq 0 }[/math], and [math]\displaystyle{ r, n(i) \in \mathbb{Z} }[/math]. The arithmetic distance of a word is upper bounded by its hamming weight since any integer can be represented by its standard polynomial form of [math]\displaystyle{ x=\sum_{i=1}^n b_i r^i }[/math] where the [math]\displaystyle{ b_i }[/math] are the digits in the integer. Removing all the terms where [math]\displaystyle{ b_i = 0 }[/math] will simulate a [math]\displaystyle{ t }[/math] equal to its hamming weight. The arithmetic weight will usually be less than the hamming weight since the [math]\displaystyle{ a_i }[/math] are allowed to be negative. For example, the integer [math]\displaystyle{ x = 29 }[/math] which is [math]\displaystyle{ 11101 }[/math] in binary has a hamming weight of [math]\displaystyle{ 4 }[/math]. This is a quick upper bound on the arithmetic weight since [math]\displaystyle{ x = 2^0 + 2^2 + 2^3 + 2^4 }[/math]. However, since the [math]\displaystyle{ a_i }[/math] can be negative, we can write [math]\displaystyle{ x = 2^5 - 2^1 - 2^0 }[/math] which makes the arithmetic weight equal to [math]\displaystyle{ 3 }[/math].

The arithmetic distance between two integers is defined by

[math]\displaystyle{ d(x,y) = w(x-y) }[/math][citation needed]

This is one of the primary metrics used when analyzing arithmetic codes.[citation needed]

AN Codes

AN codes are defined by integers [math]\displaystyle{ A }[/math] and [math]\displaystyle{ B }[/math] and are used to encode integers from [math]\displaystyle{ 0 }[/math] to [math]\displaystyle{ B-1 }[/math] such that

[math]\displaystyle{ C = \{ AN|N\in \mathbb{Z}, 0 \leq N }[/math]<[math]\displaystyle{ B \} }[/math]

Each choice of [math]\displaystyle{ A }[/math] will result in a different code, while [math]\displaystyle{ B }[/math] serves as a limiting factor to ensure useful properties in the distance of the code. If [math]\displaystyle{ B }[/math] is too large, it could let a codeword with a very small arithmetic weight into the code which will degrade the distance of the entire code. To utilize these codes, before an arithmetic operation is performed on two integers, each integer is multiplied by [math]\displaystyle{ A }[/math]. Let the result of the operation on the codewords be [math]\displaystyle{ R }[/math]. Note that [math]\displaystyle{ R }[/math] must also be between [math]\displaystyle{ 0 }[/math] to [math]\displaystyle{ B-1 }[/math] for proper decoding. To decode, simply divide [math]\displaystyle{ R/A }[/math]. If [math]\displaystyle{ A }[/math] is not a factor of [math]\displaystyle{ R }[/math], then at least one error has occurred and the most likely solution will be the codeword with the least arithmetic distance from [math]\displaystyle{ R }[/math]. As with codes using hamming distance, AN codes can correct up to [math]\displaystyle{ \lfloor \frac{d-1}{2} \rfloor }[/math] errors where [math]\displaystyle{ d }[/math] is the distance of the code.

For example, an AN code with [math]\displaystyle{ A = 3 }[/math], the operation of adding [math]\displaystyle{ 15 }[/math] and [math]\displaystyle{ 16 }[/math] will start by encoding both operands. This results in the operation [math]\displaystyle{ R = 45 + 48 = 93 }[/math]. Then, to find the solution we divide [math]\displaystyle{ 93/3 = 31 }[/math]. As long as [math]\displaystyle{ B }[/math]>[math]\displaystyle{ 31 }[/math], this will be a possible operation under the code. Suppose an error occurs in each of the binary representation of the operands such that [math]\displaystyle{ 45 = 101101 \rightarrow 101111 }[/math] and [math]\displaystyle{ 48 = 110000 \rightarrow 110001 }[/math], then [math]\displaystyle{ R = 101111 + 110001 = 1100000 }[/math]. Notice that since [math]\displaystyle{ 93 = 1011101 }[/math], the hamming weight between the received word and the correct solution is [math]\displaystyle{ 5 }[/math] after just [math]\displaystyle{ 2 }[/math] errors. To compute the arithmetic weight, we take [math]\displaystyle{ 1100000 - 1011101 = 11 }[/math] which can be represented as [math]\displaystyle{ 11 = 2^0 + 2^1 }[/math] or [math]\displaystyle{ 11 = 2^2 - 2^0 }[/math]. In either case, the arithmetic distance is [math]\displaystyle{ 2 }[/math] as expected since this is the number of errors that were made. To correct this error, an algorithm would be used to compute the nearest codeword to the received word in terms of arithmetic distance. We will not describe the algorithms in detail.

To ensure that the distance of the code will not be too small, we will define modular AN codes. A modular AN code [math]\displaystyle{ C }[/math] is a subgroup of [math]\displaystyle{ \mathbb{Z}/m \mathbb{Z} }[/math], where [math]\displaystyle{ m = AB }[/math]. The codes are measured in terms of modular distance which is defined in terms of a graph with vertices being the elements of [math]\displaystyle{ \mathbb{Z}/m \mathbb{Z} }[/math]. Two vertices [math]\displaystyle{ x \pmod{m} }[/math] and [math]\displaystyle{ x' \pmod{m} }[/math] are connected iff

[math]\displaystyle{ x - x' \equiv \pm c \cdot r^j \pmod{m} }[/math]

where [math]\displaystyle{ c,j \in \mathbb{Z} }[/math] and [math]\displaystyle{ 0 }[/math]<[math]\displaystyle{ c }[/math]<[math]\displaystyle{ r }[/math], [math]\displaystyle{ j \geq 0 }[/math]. Then the modular distance between two words is the length of the shortest path between their nodes in the graph. The modular weight of a word is its distance from [math]\displaystyle{ 0 }[/math] which is equal to

[math]\displaystyle{ w_m(x) = min\{w(y)|y \in \mathbb{Z}, y \equiv x \pmod{m} \} }[/math]

In practice, the value of [math]\displaystyle{ m }[/math] is typically chosen such that [math]\displaystyle{ m=r^n -1 }[/math] since most computer arithmetic is computed [math]\displaystyle{ \mod 2^n-1 }[/math] so there is no additional loss of data due to the code going out of bounds since the computer will also be out of bounds. Choosing [math]\displaystyle{ m=r^n-1 }[/math] also tends to result in codes with larger distances than other codes.

By using modular weight with [math]\displaystyle{ m=r^n-1 }[/math], the AN codes will be cyclic code.

definition: A cyclic AN code is a code [math]\displaystyle{ C }[/math] that is a subgroup of [math]\displaystyle{ [r^n-1] }[/math], where [math]\displaystyle{ [r^n-1] = \{0,1,2,\dots,r^n-1\} }[/math].

A cyclic AN code is a principal ideal of the ring [math]\displaystyle{ [r^n-1] }[/math]. There are integers [math]\displaystyle{ A }[/math] and [math]\displaystyle{ B }[/math] where [math]\displaystyle{ AB = r^n-1 }[/math] and [math]\displaystyle{ A,B }[/math] satisfy the definition of an AN code. Cyclic AN codes are a subset of cyclic codes and have the same properties.

Mandelbaum-Barrows Codes

The Mandelbaum-Barrows Codes are a type of cyclic AN codes introduced by D. Mandelbaum and J. T. Barrows.[2][3] These codes are created by choosing [math]\displaystyle{ B }[/math] to be a prime number that does not divide [math]\displaystyle{ r }[/math] such that [math]\displaystyle{ \mathbb{Z}/B\mathbb{Z} }[/math] is generated by [math]\displaystyle{ r }[/math] and [math]\displaystyle{ -1 }[/math], and [math]\displaystyle{ m=r^n-1 }[/math]. Let [math]\displaystyle{ n }[/math] be a positive integer where [math]\displaystyle{ r^n \equiv 1 \pmod{B} }[/math] and [math]\displaystyle{ A = (r^n -1)/B }[/math]. For example, choosing [math]\displaystyle{ r=2, B=5, n=4 }[/math], and [math]\displaystyle{ A= (r^n-1)/B = 3 }[/math] the result will be a Mandelbaum-Barrows Code such that [math]\displaystyle{ C = \{ 3N|N\in \mathbb{Z}, 0 \leq N }[/math]<[math]\displaystyle{ 5 \} }[/math] in base [math]\displaystyle{ 2 }[/math].

To analyze the distance of the Mandelbaum-Barrows Codes, we will need the following theorem.

theorem: Let [math]\displaystyle{ C \subset [r^n - 1] }[/math] be a cyclic AN code with generator [math]\displaystyle{ A }[/math], and

[math]\displaystyle{ B = |C| = (r^n - 1)/A }[/math]

Then,

[math]\displaystyle{ \sum_{x \in C} w_m(x) = n(\lfloor\frac{rB}{r+1}\rfloor - \lfloor\frac{B}{r+1}\rfloor) }[/math]

proof: Assume that each [math]\displaystyle{ x \in C }[/math] has a unique cyclic NAF[4] representation which is

[math]\displaystyle{ x \equiv \sum_{i=0}^{n-1} c_{i,x}r^i \pmod{r^n -1} }[/math]

We define an [math]\displaystyle{ n \times B }[/math] matrix with elements [math]\displaystyle{ c_{i,x} }[/math] where [math]\displaystyle{ 0 \leq i \leq n-1 }[/math] and [math]\displaystyle{ x \in C }[/math]. This matrix is essentially a list of all the codewords in [math]\displaystyle{ C }[/math] where each column is a codeword. Since [math]\displaystyle{ C }[/math] is cyclic, each column of the matrix has the same number of zeros. We must now calculate [math]\displaystyle{ n|\{ x \in C | c_{n-1,x} \neq 0\}| }[/math], which is [math]\displaystyle{ n }[/math] times the number of codewords that don't end with a [math]\displaystyle{ 0 }[/math]. As a property of being in cyclic NAF, [math]\displaystyle{ c_{n-1,x} \neq 0 }[/math] iff there is a [math]\displaystyle{ y \in \mathbb{Z} }[/math] with [math]\displaystyle{ y \equiv x \pmod{ r^n -1}, \frac{m}{r+1} }[/math]<[math]\displaystyle{ y \leq \frac{mr}{r+1} }[/math]. Since [math]\displaystyle{ x = AN \pmod{r^n-1} }[/math] with [math]\displaystyle{ 0 \leq N }[/math]<[math]\displaystyle{ B }[/math], then [math]\displaystyle{ \frac{B}{r+1} }[/math]<[math]\displaystyle{ N \leq \frac{Br}{r+1} }[/math]. Then the number of integers that have a zero as their last bit are [math]\displaystyle{ \lfloor\frac{rB}{r+1}\rfloor - \lfloor\frac{B}{r+1}\rfloor }[/math]. Multiplying this by the [math]\displaystyle{ n }[/math] characters in the codewords gives us a sum of the weights of the codewords of [math]\displaystyle{ n(\lfloor\frac{rB}{r+1}\rfloor - \lfloor\frac{B}{r+1}\rfloor) }[/math] as desired.

We will now use the previous theorem to show that the Mandelbaum-Barrows Codes are equidistant (which means that every pair of codewords have the same distance), with a distance of

[math]\displaystyle{ \frac{n}{B-1}(\lfloor\frac{rB}{r+1}\rfloor - \lfloor\frac{B}{r+1}\rfloor) }[/math]

proof: Let [math]\displaystyle{ x \in C, x \neq 0 }[/math], then [math]\displaystyle{ x = AN \pmod{r^n-1} }[/math] and [math]\displaystyle{ N }[/math] is not divisible by [math]\displaystyle{ B }[/math]. This implies there [math]\displaystyle{ \exists j (N \equiv \pm r^j \pmod{B}) }[/math]. Then [math]\displaystyle{ w_m(x) = w_m(\pm r^j A) = w_m(A) }[/math]. This proves that [math]\displaystyle{ C }[/math] is equidistant since all codewords have the same weight as [math]\displaystyle{ A }[/math]. Since all codewords have the same weight, and by the previous theorem we know the total weight of all codewords, the distance of the code is found by dividing the total weight by the number of codewords (excluding 0).

See also

References

  1. Peterson, W. W. and Weldon, E. J.: Error-correcting Codes. Cambridge, Mass.: MIT Press, 1972
  2. Massey, J. L. and Garcia, O. N.: Error-correcting codes in computer arithmetic. In: Advances in Information Systems Science, Vol. 4, Ch. 5. (Edited by J. T. Ton). New York: Plenum Press, 1972
  3. J.H. Van Lint (1982). Introduction to Coding Theory. GTM. 86. New York: Springer-Verlag.
  4. Clark, W. E. and Liang, J. J.: On modular weight and cyclic nonadjacent forms for arithmetic codes. IEEE Trans. Info. Theory, 20 pp. 767-770(1974)