the relation
![]() |
(96) |
![]() |
(97) |
where addition and multiplication are defined by
![]() |
(98) |
with
.
We consider the ideal
is often denoted by
and the class of
in
by
.
For
the relation
means
that
is a multiple of
and
be the quotient-remainder
pairs of ![]() |
(99) |
we have in fact
![]() |
(100) |
for a field
and let
.
For every
there exists
such that
![]() |
(101) |
we have
![]() |
(102) |
be in
iff
.
In this case the Extended Euclidean Algorithm can be used
to compute the inverse of
![]() |
(103) |
then
such that
![]() |
(104) |
such that
.
If
).
Hence
.
ResidueClassRing(R:EuclideanDomain, p:R): Ring with {
class: R -> %;
sample: % -> R;
} == R add {
Rep == R;
import from R;
1: % == per(1);
0: % == per(0);
zero?(x:%): Boolean == zero?(rep(x));
(x:%) = (y:%) : Boolean == zero?(x-y);
one?(x:%): Boolean == x = 1;
class(a:R):% == {
(q,r) := divide(a,p);
per(r);
}
sample(x:%): R == rep(x);
(x:%) + (y:%) : % == class(rep(x) + rep(y));
-(x:%) : % == class(-rep(x));
(x:%) * (y:%) : % == class(rep(x) * rep(y));
(n:Integer) * (x:%): % == class(n * rep(x));
(x:%) ^ (n:NonNegativeInteger) : % == class(rep(x) ^ n);
recip(x:%): Partial(%) == {
import from Partial(%);
(u,v,g) := extendedEuclidean(rep(x),p);
h?: Partial(R) := recip(g);
failed? h? => failed();
h: R := retract(h?);
[class(h * u)];
}
}
with degree
.
One arithmetic operation in the residue class ring
,
that is, addition, multiplication or division by
an invertible element can be done using
arithmetic operations in
![]() |
(105) |
.
The Euler's totient function
counts the number of elements of
.
By convention
.
Then if
.
If ![]() |
(106) |
is a prime and
then we have
![]() |
(107) |
.
which we do by induction on
we have
![]() |
(108) |
and
such that
and such that
can be computed by
![]() |
(109) |
word operations.
Is this better than the modular inversion
via Euclide's algorithm?
Marc Moreno Maza