The Residue Number System (RNS) is a number system used for representing and performing arithmetic operations on integers, with the advantage of supporting parallel computations. In RNS, an integer is represented using multiple distinct coprime integers (referred to as the base set). The underlying principle of RNS is based on the Chinese remainder theorem, which states that given a set of pairwise coprime integers, a unique solution exists for a system of simultaneous congruences, allowing the representation of a single integer using multiple coprime integers.

RNS Representation

In RNS, an integer XXX can be represented as a set of kkk integers: where is the base set of the RNS.

For example, in an RNS with the base set {3,5,7}{3, 5, 7}{3,5,7}, the integer 23 is represented as (2,3,2)(2, 3, 2)(2,3,2):

Arithmetic operations

Add

Addition in RNS is performed by simply adding the corresponding residues:

Subtract

Subtraction in RNS is performed by subtracting the corresponding residues:

Multiply

Multiplication in RNS is performed by multiplying the corresponding residues:

Divide

Division in RNS is performed using the modular multiplicative inverse of the divisor. This is calculated as follows:

Comparison

For equality, two numbers are considered equal if all their residues are equal. Direct comparison for greater than or less than is not straightforward in RNS and typically requires reconstructing the full value for the comparison.