Residue number system
A residue numeral system (RNS) represents a large integer using a set of smaller integers, so that computation may be performed more efficiently. It relies on the Chinese remainder theorem of modular arithmetic for its operation, a mathematical idea from Sunzi Suanjing (Master Sun’s Arithmetic Manual) in the 4th century AD.
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.
Defining a residue numeral system
A residue numeral system is defined by a set of integer constants,
referred to as the moduli. Let be the least common multiple of all the .
Any arbitrary integer smaller than can be represented in the defined residue numeral system as a set of smaller integers
with
representing the residue class of to that modulus, symbol makes sense of performance of modulo operation.
For representational efficiency the moduli should be pairwise coprime; that is, no modulus should have a common factor with any other. is then the product of all the .
For example, RNS(4|2) has non-coprime moduli, with an LCM of 4, and a product of 8, resulting in the same representation for different values smaller than the product:[1]
(3)decimal = (3|1)RNS(4|2) (7)decimal = (3|1)RNS(4|2)
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 ai and bi in an RNS system defined by mi (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 does not have 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 not possible.
Division
Division in residue numeral systems is problematic. A paper describing one possible algorithm is available at [1].[dead link ] On the other hand, if is coprime with (that is ) then
can be easily calculated by
where is multiplicative inverse of modulo , and is multiplicative inverse of modulo .
Integer factorization
The RNS can improve efficiency of trial division, essentially a form of wheel sieving. The RNS using n primes represents a number coprime to their product if and only if it has no 0s. For example, using the primes 2, 3, and 5, the RNS can automatically eliminate all numbers but
or 73% of numbers. Using the 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.
See also
References
- ^ Behrooz Parhami, Computer Arithmetic: Algorithms and Hardware Design. 2nd edition, Oxford University Press, New York, 2010. 641+xxv p. ISBN 978-0-19-532848-6.
Further reading
- Jean-Claude Bajard, Nicolas Meloni and Thomas Plantard, Efficient RNS bases for Cryptography, IMACS'05: World Congress: Scientific Computation Applied Mathematics and Simulation. 2005.
- O. A. Fin'ko, Large Systems of Boolean Functions: Realization by Modular Arithmetic Methods, Automation and Remote Control, 65 (2004), no. 6, 871–892.
- Amos Omondi, Benjamin Premkumar. Residue Number Systems: Theory and Implementation. Imperial College Press. London. 2007. 296 p. ISBN 978-1-86094-866-4.
- Ananda Mohan, P.V. Residue Number Systems, Springer International Publishing. 2016. 351 p. ISBN 978-3-319-41385-3.
- Amir Sabbagh, Molahosseini, Leonel Seabra de Sousa, and Chip-Hong Chang (editors), Embedded Systems Design with Special Arithmetic and Number Systems, Springer International Publishing. 21 March 2017. 389 p. ISBN 978-3-319-49742-6.