- Residue number system
A residue number system (RNS) represents a large integer using a set of smaller integers, so that
computation may be performed more efficiently. It relies on theChinese remainder theorem ofmodular arithmetic for its operation, a mathematical idea from Sun Tsu Suan-Ching (Master Sun’s Arithmetic Manual) in the 4th century AD.Defining a residue number system
A residue number system is defined by a set of "N" integer constants,
:{"m"1, "m"2, "m"3, ... , "m""N" },
referred to as the "moduli". Let "M" be the
least common multiple of all the "m""i".Any arbitrary integer "X" smaller than "M" can be represented in the defined residue number system as a set of "N" smaller integers
:{"x"1, "x"2, "x"3, ... , "x""N"}
with
:"x""i" = "X" "modulo" "m""i"
representing the residue class of "X" to that modulus.
Note that for maximum representational efficiency it is imperative that all the moduli are
coprime ; that is, no modulus may have a common factor with any other. "M" is then the product of all the "m"i.Operations on RNS numbers
Once represented in RNS, many arithmetic operations can be efficiently performed on the encoded integer. For the following operations, consider two integers, "A" and "B", represented by "a""i" and "b""i" in an RNS system defined by "m""i" (for "i" from 0 ≤ "i" ≤ "N").
Addition and subtraction
Addition (or subtraction) can be accomplished by simply adding (or subtracting) the small integer values, modulo their specific moduli. That is,:can be calculated in RNS as:
One has to check for overflow in these operations.
Multiplication
Multiplication can be accomplished in a manner similar to addition and subtraction. To calculate :we can calculate::Again overflows are possible.
Division
Division in residue number systems is problematic. A paper describing one possible algorithm is available at [http://www.cs.rpi.edu/research/ps/93-9.ps] . On other hand, if "B" is coprime with "M" (that is ) then:can be easily calculated by:where is
multiplicative inverse of "B" modulo "M", and is multiplicative inverse of modulo .Practical applications
RNS have applications in the field of
digital computer arithmetic . By decomposing in this a large integer into a set of smaller integers, a large calculation can be performed as a series of smaller calculations that can be performed independently and in parallel. Because of this, it's particularly popular in hardware implementations.Integer factorization
The RNS can improve efficiency of
trial division . Let asemiprime . Let represent first "N" primes. Assume that , . Then , where . The method of trial division is the method of exhaustion, and the RNS automatically eliminates all "Y" and "Z" such that or , that is we only need to check:numbers below "M". For example, "N" = 3, the RNS can automatically eliminate all numbers but:1,7,11,13,17,19,23,29 mod 30
or 73% of numbers. For "N" = 25 when are all prime numbers below 100, the RNS eliminates about 88% of numbers. One can see from the above formula the diminishing returns from the larger sets of moduli.
Associated mixed radix system
A number given by in the RNS can be naturally represented in the "associated
mixed radix system" (AMRS):where: for and
Wikimedia Foundation. 2010.