Modification of Euclidian Algorithm
Modification of Euclidian Algorithm
initialization
while (rr rs = 0) do
if (rr < rs) then
{ q :=
r
1
r
2
;
rr := r1qr2;
r1 := r2; r2 := rr;
Modication of Euclidian Algorithm for Solving Modular Equations 43
x := x1qx2;
x1 := x2; x2 := x; }
else
{ q :=
r
1
r
2
;
rs := r1qr2;
r1 := r2; r2 := rs;
x := qx2x1;
x1 := x2; x2 := x; }
GCD := r1; X0 := x1;
For the sake of illustration of running Algorithm 1 and 2, we will take the following
equation
233x 7( mod144) (2)
Table 1 outlines execution steps when Algorithm 1 and Algorithm 2 are used.
Table 1.
Algorithm 1 Algorithm 2
step q r
1
r
2
r x
1
x
2
x q r
1
r
2
r x
1
x
2
x
1 1 233 144 89 1 0 1 2 233 144 55 1 0 -1
2 1 144 89 55 0 1 -1 3 144 55 21 0 -1 -3
3 1 89 55 34 1 -1 2 3 55 21 8 -1 -3 -8
4 1 55 34 21 -1 2 -3 3 21 8 3 -3 -8 -21
5 1 34 21 13 2 -3 5 3 8 3 1 -8 -21 -55
6 1 21 13 8 -3 5 -8 3 3 1 0 -21 -55 -309
7 1 13 8 5 5 -8 13 1 -55 89
8 1 8 5 3 -8 13 -21 GDC(233, 144) = 1 X
0
= 55
9 1 5 3 2 13 -21 34
10 1 3 2 1 -21 34 -55
11 2 2 1 0 34 -55 149
12 1 0 -55 89
GDC(233, 144) = 1 X
0
= 55
As can be seen from Table 1, Algorithm 1 requires 12 computational steps, while
Algorithm 2 requires 7 steps. Algorithm 2 uses one additional testing at the beginning of
the loop. All other computational steps in the loop body of both algorithms are of identical
complexity. This obviously justies the usage of the involved modication.
In the sequel we will show how Algorithm 2 can be used for solving the system of
modular equations in one variable based on Chinese remainder theorem.
Consider the following system of modular equations
x c
1
( modb
1
)
x c
2
( modb
2
) (3)
44 I.
Z. Milovanovi c,
C. B. Doli canin, M. K. Stoj cev, E. I. Milovanovi c
.
.
.
x c
k
( modb
k
)
where b
i
and c
i
are integers, and b
i
, i =1, 2, . . . , n are pairwise relatively prime. If we denote
by x
j
, j = 1, 2, . . . , n, solutions of the corresponding modular equations in system (3), i.e.
a
j
x
j
c
j
( modb
j
), a
j
=
b
1
b
2
. . . b
k
b
j
=
b
b
j
, (4)
then a particular solution of system (3) is given by
x
(
k
j=1
a
j
x
j
)
mod b. (5)
If minimal positive solution of system (3) is required, then in (5) instead of mod a
function Mod dened in [7] should be used.
Finally, let us note that computations dened by (4) have high degree of data parallelism
and can be performed in parallel since the computations of x
j
, j =1, 2, . . . , n are completely
independent from each other (see for example [8, 9].
References
[1] J. M. ANDERSON, Discrete mathematics with combinatorics, Prentice Hall, New Jersey,
2004.
[2] D. KNUTH, The art of computer programming, Vol. 2, Semi-numerical algorithms, Reading
MA: Addison-Wesley, 1981.
[3] A. G. AKRITAS, Elements of computer algebra with applications, John Wiley and Sons,
Inc., New York, 1989.
[4] S. M. KUO, B. H. LEE, W. TIAN, Real-time digital signal processing: Implementations
and applications, John Wiley and Sons, Inc. 2006.
[5] R. P. BRENT, H. T. KUNG, Systolic VLSI arrays for polynomial GCD computation, Report
CMU-CS-82-118, Carnegie-Mellon University, 1982.
[6] R. P. BRENT, H. T. KUNG, F. T. LUK, Some linear-time algorithms for systolic arrays,
arXiv: 1004.3716V1,[CS.DS], 21. Apr. 2010.
[7] M. K. STOJ CEV, E. I. MILOVANOVI C, I.
Z. MILOVANOVI C, A unied approach in ma-
nipulation with modular arithmetic, Proc.: 28 International Conference on Microelectronics,
(MIEL12), Ni s, Serbia, 2012, 387-392.
[8] S. G. AKL, The design and analysis of parallel algorithms, Prentice-Hall Inc. 1989.
[9] A. BORODIN, J. GATHEN, J. HOPCROFT, Fast parallel matrix and GCD computations,
Proc. : 23rd Annual Symposium on Foundations of Computer Science, IEEE, New York,
1982, 65-71.