Next: Real algebraic numbers. Up: How to encode the elements Previous: Rational numbers.

### Modular Integers.

There are many ways to implement the rings /m and even more for the fields /p (where p is a prime). Let us restrict to the fields /p. Here are some examples.
• For p in the range [2, 2N - 1] we can use single integers. Multiplication and addition can be made in (1) word operations. N.B. multiplication requires a two single integers buffer unless p in the range [2, 2N-1 - 1]. Exponentiation and computation of inverses require a bit more of works but are still in (1) word operations. For instance here's an ALDOR code for the division of two integers modulo a third one
       mod_/(i: %, j: %, n: %): % == {
local c0, d0, c1, d1: %;
(c0, d0) := (j, n);
(c1, d1) := (1, 0);
while not zero? d0 repeat {
q := c0 quo d0;
(c0, d0) := (d0, c0 - q*d0);
(c1, d1) := (d1, c1 - q*d1)
}
if c0 ~= 1 then error "inverse does not exist";
if c1 < 0  then c1 := c1 + n;
mod_*(i, c1, n);

• The set of the nonzero elements of /p is a cyclic group. In other words, there exists a generator g /p such that every nonzero x /p is a power of g called the discrete logarithm of x. Hence we can use discrete logarithms to represent nonzero elements of /p. Then exponentiation and computation of inverses become much more easy (for inverses we use Little Fermat Theorem) than with the previous encoding. However addition requires the use of tables of logarithms and exponentiations, for efficiency. Again all arithmetic operations are in (1) word operations.

Next: Real algebraic numbers. Up: How to encode the elements Previous: Rational numbers.
Marc Moreno Maza
2003-06-06
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}