base conversion in residue number systems · mixed-radix number system, for the same base vector...

17
BIT 17 11977), 286-302 BASE CONVERSION IN RESIDUE NUMBER SYSTEMS ROBERT TODD GREGORY and DAVID W. MATULA 1o Introduction. We are concerned in this paper with the representation of an integer in a (multiple-modulus) residue number system and, in particular, with an algorithm for changing the base vector of the residue number system. Szab6 and Tanaka [1, p. 47] describe such an algorithm when each modulus of the second base vector is relatively prime to each modulus of the first base vector. However, we show that a much simpler algorithm exists if we allow the moduli of the second base vector to have factors in common with the moduli of the first base vector (even though the moduli of the second base vector are pairwise relatively prime among themselves). Since the algorithm involves the use of "associated" residue and mixed-radix representations for integers, Section 2 contains an elementary survey of the terminology, notation, and theory behind these two types of representation. Section 3 contains the proofs of the basic theorems upon which our algorithm for residue base conversion is based along with a description of the algorithm. It also contains illustrative examples which demonstrate the power of the algorithm. In this paper we lay the foundation for a subsequent paper in which we propose procedures for extending single-precision residue arithmetic to multiple-precision residue arithmetic. 2. Associated Residue and Mixed-radix Number Systems. Complete Systems of Residues. Let R denote the set of real numbers and I the set of integers. For every x ~ R we use I~] to denote the largest integer smaller than or equal to x, and for all a, b ~ I we use (a, b) to denote the greatest common divisor of a and b. It is well.known that each integer is congruent modulo* m to exactly one of the integers in the set {0,1,2 .... ,m-l}, and this fact partitions I into exactly m disjoint subsets s0,s 1 .... ,s,,-1 called the residue classes with respect to the modulus m. These residue classes have the following properties: m--1 (i) I = U sj j=O * We assume m> 1 throughout the paper. Received June 16, 1977.

Upload: lamquynh

Post on 27-Jul-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

BIT 17 11977), 286-302

BASE CONVERSION IN RESIDUE NUMBER SYSTEMS

ROBERT TODD GREGORY and DAVID W. MATULA

1o Introduction.

We are concerned in this paper with the representation of an integer in a (multiple-modulus) residue number system and, in particular, with an algorithm for changing the base vector of the residue number system. Szab6 and Tanaka [1, p. 47] describe such an algorithm when each modulus of the second base vector is relatively prime to each modulus of the first base vector. However, we show that a much simpler algorithm exists if we allow the moduli of the second base vector to have factors in common with the moduli of the first base vector (even though the moduli of the second base vector are pairwise relatively prime among themselves).

Since the algorithm involves the use of "associated" residue and mixed-radix

representations for integers, Section 2 contains an elementary survey of the terminology, notation, and theory behind these two types of representation. Section 3 contains the proofs of the basic theorems upon which our algorithm for residue base conversion is based along with a description of the algorithm. It also contains illustrative examples which demonstrate the power of the algorithm.

In this paper we lay the foundation for a subsequent paper in which we propose procedures for extending single-precision residue arithmetic to multiple-precision residue arithmetic.

2. Associated Residue and Mixed-radix Number Systems.

Complete Systems of Residues.

Let R denote the set of real numbers and I the set of integers. For every x ~ R we use I~] to denote the largest integer smaller than or equal to x, and for all a, b ~ I we use (a, b) to denote the greatest common divisor of a and b.

It is well.known that each integer is congruent modulo* m to exactly one of the integers in the set {0,1,2 . . . . , m - l } , and this fact partitions I into exactly m disjoint subsets s0,s 1 . . . . ,s,,-1 called the residue classes with respect to the modulus m. These residue classes have the following properties:

m--1

(i) I = U sj j=O

* We assume m > 1 throughout the paper. Received June 16, 1977.

BASE CONVERSION IN RESIDUE NUMBER SYSTEMS 287

and

(ii) a e sj and b s sj imply a-= b (mod m) for j = O, 1 , . . . , m - 1 .

By selecting exactly one integer rj f rom each residue class, s~, we have a set of m

different integers {ro, r 1 . . . . . rm-1}, called a complete system of residues modulo m. Each ri "represents" its residue class, and the individual r's are called residues modulo m.

There are infinitely m a n y complete systems of residues for a given modulus m. However , we shall discuss only the two that are most widely used. Suppose r, s e I

and r - s (mod m). If

(2.1) 0 =< r < m ,

then we use the no ta t ion**

(2.2) r = ISlm,

and call lsl,, the residue of s modu lo m in the complete system of residues, {0, 1, 2 . . . . . m - 1 } . We call this system the standard complete system of residues

modulo m.

If, on the other hand, r lies in the range

(2.3) - < r <

then we use the no ta t ion

(2.4) r = Is~m,

and call /s/,, the residue of s modu lo m in the complete system of residues, {r o, r 1 . . . . , r m_ a}, with r~ satisfying (2.3) for all i. When m is odd, these residues are

symmetr ic with respect to the origin, but when m is even, perfect symmet ry is lost. Fo r this reason, we shall restrict our use of (2.3) and (2.4) to the case where m is odd. A complete system of residues, based on the inequality (2.3) with m odd, is called balanced. (Szab6 and T a n a k a [1, p. 113] use the term symmetric but allow m to be both odd and even.)

Fo r the mos t par t we shall discuss s tandard complete systems of residues in this paper. However , ba lanced complete systems of residues are also discussed in the l i terature and so we shall include remarks pertaining to balanced systems as it seems appropr ia te .

Residue Number Systems.

Suppose we have two modul i m 1 and m 2. We call them relatively prime if (m 1, m2) = 1 and redundant if (ml, m2) >2 . Consider the ordered n-tuple

** Our notation will generally follow the notation in [1].

288 ROBERT T O D D GREGORY AND DAVID W. MATULA

(2.5) fl = [ml, m2 , . . , toni ,

whose componen t s are the n (distinct) modul i m 1, m 2 . . . . . ran. Assume tha t the modul i are pairwise relatively prime, that is, that

(2.6) (m~, m j) = 1 i * j .

If fl in (2.5) satisfies (2.6), we call it a base vector for the residue number systems

we are abou t to describe. Let Mp be the p r o d u c t of the modul i in the base vector fl, that is, let

(2.7) Mp -- f i m i . i = 1

For each integer s we call the (unique) n-tuple of residues

(2.8) Lsla = EIs[mi, Isl~,~,..., I s l j

the standard residue representation of s with respect to the base vector ft. The

individual residues, Islml, are the residue digits of s with respect to ft.

(2.9) THEOREM* I-1, p. 13]. Two integers s and t have the same standard residue representation with respect to fl, that is, Isla= Itl~, if and only i f

s - t ( m o d M a ) .

(2.10) COROLLARY*. The integers ISlMa and s have the same standard residue representation with respect to fl, that is, i f

t = [SlMa,

then Itla = Islp.

This means, then, that there is a one- to-one cor respondence between integers in the range

(2.11) 0 N s < Ma

and their s tandard residue representat ions with respect to the base vector ft. The

star~dard residue number system for the base vector fl is the Ma-member set of s tandard residue representat ions

(2.12) Ip = {Isla : s ~ I} .

Obviously, this is a finite number system. In the residue number system Ip every integer s is represented by a unique n-

* The product of the moduli, Mp, should be replaced in this theorem and its corollary, by the least common multiple of the moduli. However, we have assumed that the moduli in ~ are pairwise relatively prime and so Ma is automatically the least common multiple of the moduli.

BASE CONVERSION IN RESIDUE NUMBER SYSTEMS 289

tuple ]sip and the correspondence is one-to-one for those non-negative integers tess than Mp. This set of integers, {0, 1, 2 , . . . , M s - 1}, is called the r a n g e of Ip and is identical to the standard complete system of residues modulo Mp.

REMARK. If fi = [m,, m 2 . . . . . m,] contains only odd moduli, we can use (2.3) and (2.4) to define the b a l a n ced residue number system for fl in a similar manner. In this case we represent s by the b a l a n ced residue representation

(2.13) /s b = [/s/m,,/s/~2 . . . . , / s / j ,

and define the b a l a n ced residue number system to be the set of balanced residue representations

(2.14) Bp = { / s / a : s ~ I} .

In Bp every integer s is represented by a unique n-tuple of the form (2.13) and the correspondence is one-to-one for those integers in the range

(2.15) Mp Mp 2 < s < 2

Since Ip and Bp, along with their ranges (2.11) and (2.15), respectively, are all Mp-member sets we have a one-to-one correspondence between these two residue number systems. Note that for any s e I, conversion from the standard representation ]sip to the balanced representation/s/p is affected by

mi { Ist,,i if 0 < lSlmi<-~-,

(2:16) / s / , , , = ' [ s [ ~ , - m i otherwise,

for i= 1, 2 , . . . , n, and the reverse conversion is similarly evident.

T h e A s s o c i a t e d M i x e d - r a d i x N u m b e r S y s t e m .

We now introduce a m i x e d - r a d i x n u m b e r r e p r e s e n t a t i o n . * Consider the set of positive integers Pl, P2,-- -, P, called radices . Let P--Pl"P2 • • • P, . It is welt known [1, p. 41] that any integer s in the range O < = s < P can be expressed uniquely in the form

(2.17) s = do + d l p l + d 2 p l p 2 + . • . + d n - t p l p 2 . . • P , - 1 ,

where do, d~ . . . . . d , _ ~ are the s t a n d a r d m i x e d - r a d i x d ig i t s satisfying

(2.18) 0 =< di < Pi+l i = 0 , 1 , . . . , n - 1 .

The dig i t s e q u e n c e for s in this mixed-radix representation is denoted by

(2.19) (s)[v,,v ~ ..... p.] = ( d o , d l, . . . , d , _ 1 )[vl,p . . . . . p,] "

• See, for example, [2, pp. 25-27].

290 ROBERT T O D D GREGORY AND DAVID W. MATULA

We define the standard mixed-radix number system for the (ordered) radices Pl, P2 . . . . . p, to be the set of digit sequences for s, in the range 0 =< s < P, of the form (2.19).

A special case occurs if Pl =Pz . . . . . p,, the familiar f ixed-radix number system for which the radix ten provides the traditional example. Another special case occurs if p~= m~, for i= 1, 2 , . . . , n, where the integers ml, m2 . . . . . m, are the (ordered) moduli of the base vector fl in (2.5). In this case we have the standard mixed-radix number system associated with Ia. We call these two number systems

associated number systems with respect to ft.

REMARK. If we happen to be working with Bp (rather than with Ia) we can introduce as its associated mixed-radix system a balanced mixed-radix number system. The only change necessary to accomplish this is to change the range for the mixed-radix digits to

(2.20) mi + 1 < _di < mi+ 1 i =0, 1 , . . n - 1 - - - - - - " 7 "

2 2 '

In this balanced system it is easily shown that there exists a unique representation for each integer s in the range

(2.21) Mp < s < M~ 2 2

Thus, the ranges for the standard mixed-radix number system and the balanced mixed-radix number system, for the same base vector fl, both contain the same number of integers.

By including in the definition of a base vector fl the stipulation that the moduli m 1, m 2 . . . . , m, must be pairwise relatively prime, we guarantee that Mp is the least common multiple of the moduli. This fortunate circumstance causes the ranges of the two residue number systems to be 0 =<s < M~ and - M~/2 < s < Mp/2,

respectively. Consequently, in each case the range of the residue number system and the range of its associated mixed-radix number system coincide. (This would not be the case if M~ were not the least common multiple of the moduli.) This is extremely important when we wish to change from one system to the other.

The Order o f the Moduli.

We have assumed throughout our discussion so far that the moduli m I, m2, . . . ,m, of the base vector fl have been kept rigidly ordered when forming the associated mixed-radix number systems. Suppose, on the other hand, we allow permutations of the moduli. Two obvious choices would be the orderings

(2.22) mj~ < mj~ < . . . < mj,,

BASE CONVERSION IN RESIDUE NUMBER SYSTEMS 291

and

(2.23) ink, > mk 2 > . . . > ink.

In these two examples we use the names ascending associated mixed-radix number system and descending associated mixed-radix number system, respectively. Other permutations are also possible, of course, and each permutation of the moduli in/3 produces its own associated mixed-radix number system. It is important to note that a permutation of the elements of the base vector/~ causes simply the same permutation of the residue digits in ls[p. However, the mixed-radix digits in (s)p can be altered drastically by a permutation of the moduli in/~. This apparent anomaly can be utilized to our advantage for certain computations, as we shall show in the next section.

Mot iva t ion .

One of the motivations for our interest in pairs of associated residue and mixed- radix number systems stems from the fact that addition, subtraction, and multiplication of integers (and even division, under certain circumstances) are extremely simple to perform in a residue number system. On the other hand, the residue representation Isl~ does not lend itself to simple algorithms for

(i) magnitude comparison of s with t (ii) sign detection of s

(iii) recovery of the ordinary decimal (or binary) representation of s from Is[~ (called residue-to-radix conversion).

Simple algorithms are available, however, for these three operations if we have the corresponding mixed-radix representation.

Digit Sets.

Consider the standard mixed-radix number system and its associated stan- dard residue number system for the base vector fl = [m 1, m2 . . . . ,m,]. If

(2.24) s = d o + d i m t + d2mxm 2 + . . . + d ,_ 1mira2 . . . m , _ 1

has the (unique) digit sequence ( s ) ~ = ( d o , d 1 . . . . . d , , _ l ) p in the former, and if s has the representation

(2.25) [sip = [ t s l , . . tslm2 . . . . . t s l , j

in the latter, we see from (2.1) and (2.18) that both the residue digits [sims, and the mixed-radix digits, di- 1, lie in the same closed interval [0, ml - 1], for i = 1, 2 . . . . , n.

Similarly, if

(2.26) s = bo + b x m l + b z m l m z + . . . + b , _ i m l m z . . . m , _ l

292 ROBERT TODD GREGORY AND DAVID W. MATULA

has the (unique) digit sequence (s)p = (bo, bt . . . . , b ._ , ) e in the balanced mixed- radix number system relative to fl (assume all odd moduli) and if

(2.27) /s/~ = [/s/m~,/s/,,v . . . , / s / , , , ]

in the associated balanced residue number system, we see from (2.3) and (2.20) that both IS~m, and bl-1, for i= 1, 2 , . . . , n, lie in the same interval [ - m j2, mj2].

The integers in the intervals [0, m l - 1] for 1 < i_< n are called the digit sets for the standard mixed-radix-number system for ft. Similarly, the integers in [ - m j2 , m j2], t < i < n form the digit sets for the balanced mixed-radix system for ft. It is no coincidence that the complete systems of residues and their digit sets for the associated standard (respectively balanced) systems are identical. These associated systems were specifically chosen for further investigation with this property in mind. There are advantages with these choices (both esthetic and practical) but it should be pointed out that other choices could have been made. From the point of view of computer architecture it should not go unnoticed that the set of residue digits and the set of associated mixed-radix digits require identical storage and register capacity.

Conversion Between Associated Residue and Mixed-radix Number Systems.

Suppose we are given the residue representation [s[~ in I~ and we wish to find (s) e in the associated mixed-radix number system. In other words, suppose we are given the residue digits ]sl,,, and we wish to find the mixed-radix digits d~_ 1 for i=1 ,2 . . . . . n.

To do this we set t 1 =s and observe that

(2.28) ]ta[ml = ]do+ml(dt + d 2 m 2 + . . . +dn_lmzm 3 . . . m,_l)l,,1

= [do+mlt2]ml

d o .

We also observe that [tll,,~ = Ts[,,,. Thus,

(2.29) do = Js],, 1

and so the first mixed-radix digit of s is equal to the first residue digit of s and no computation is necessary.

We continue by writing

(2.30) 1t2l,,2 = [ d l + m 2 ( d i + d a m 3 + . . . + d , - l m 3 m 4 . . . m,-0[m2

= [d I + mztalm2

= d 1 •

In general, then, tl =s, do = Is[,.,, and

BASE CONVERSION IN RESIDUE NUMBER SYSTEMS 293

(2.31)

ti - - d i - 1 t i+ I = -

mi

d~ = {ti+llm,+a

i=1 ,2 . . . . n - 1 .

We should point out that the computations necessary for computing dl in (2.31) can be carried out using residue arithmetic. (See Szab6 and Tanaka [1, p. 44] for details.)

Suppose, on the other hand, we are given (s>a and we wish to determine tsla. I~ this case we note

fls{,,i - d o (2.32)

[ISlm~ [do+dimi + . . . +d~-imlm2 . . . ml-i{m~ i = 2 , 3 , . . . , n

where {slm~is computed from the relations

P2 = [di - 2 q- Pimi- 11,,~ (2.33)

"= [do q_pi_lml{m~

with Islm,= Pi. These computations can also be done using residue arithmetic so that

converting between residue and mixed-radix systems can be done using residue arithmetic in both directions.

3. Residue Base Conversion.

Suppose we are given the base vector fl and, for s in the range 0____ s < Mp, the standard residue representation {sly, and we wish to find the standard residue representation

(3.1) {sip, = []Stml, ISlm~ . . . . , IS[m;]

for some other base vector

(3.2) fi' = [mi, ml, . . . ,m~,] .

We call the process by which this is accomplished residue base conversion. Carrying out residue base conversion involves the determination of the new

residue digits IS[m, ,, for i= 1,2 . . . . . k, from the old residue digits. Since we shall compute the new residue digits one at a time all we need is an efficient algorithm for determining the residue {sl~ for an.arbitrary target modulus # > 2. For the case where # is relatively prime to Mp an efficient algorithm is alreffdy ~known. It

294 ROBERT TODD GREGORY AND DAVID W. MATULA

involves the conversion of lsla to (s)p, followed by the evaluation of

(3.3) Is[, = ]do + d tml + d2mlm2 + • • • + d ,_ lmlm2 . . . m,_ llu .

This algori thm is widely used [I , p. 47] if the new base vector ff = [ m , m 2 , . . . , m , , g ] is merely an extension of the old base vector ft. (In base extension, # must be relatively prime to Ma.) However, our concern in this paper

is not with base extension but with the general problem of residue base conversion and, in particular, with the case where each modulus in /~' is not

relatively prime to Ma even though the moduli in ff are pairwise relatively prime among themselves. It is now shown that this leads to a considerable simplification of the base conversion algori thm mentioned above.

Some Preliminaries.

Given the base vector f l = [ m , , m 2 . . . . . m,] and the target modulus # > 2 , we define a set of [I-reduced moduli gi([I), for i=0 , 1 , . . . , n - 1 , as follows:

# o ( / ~ ) = # (3.4)

#~(fl) = # i = 1, 2 . . . . , n - 1 . (p, mlm2 . . . mi)

Since the moduli m 1, m z . . . . . m, are pairwise relatively prime, #~(fl) can also be

written*

(3.5) #~ =

Thus, we have the relation

(#, m0(#, m2) . • • (#, mi)

(3.6) #~ = (#,mi+.0#i+l i = 0 , 1 . . . . . n - 2 .

The following lemma makes use of the fl-reduced moduli.

(3.7) LEMMA. Le t the base vector f l = [ml, m 2 . . . . . m,], the target modulus #_->2,

and the fl-reduced moduli #o, P l , - . . , Y , - 1 be given. Then, fo r any integer k,

(i) Imi + lklu, = [Imi + ll,.Ikl,~,+ ,l~,, O < i < n - 1 ,

(ii) lmlm2 , . . mikll, = [ Imlm2. . . mil.lkl.,l, t <_i < n ,

(iii) [ m i m e . . . mil, = Ilml[,olm2],l-.. [mi[,,_,[, l < i < n .

PROOF. For part (i) we use (3.6) and recall that labl,,m=alb[,.. Then, for i --0,1 . . . . . n - 2 ,

* W e write y~ ins tead of #~(fl) when the dependence on fl is evident.

BASE CONVERSION IN RESIDUE NUMBER SYSTEMS 295

mi+ I = ( # , m ~ + l ) ~ k

(#,m;+l) ~+ l(~,m,+,)

= ( # , m , + ~ ) - ( ~ k j , , + ~

= (#,mi+l) ~ Ikl.,+, ,ai+l

= (p, .[ mi+x { Ik[.,+l mi+ 1 ) . ~ ,Ui+l ,ai+ l(,u, mi+l)

mi+ 1 {k{"'+1 ,u, = ( , , m ~ + l ) ~

(#, mi+ 1){m+, (~, m~+1)

= { I m ,

Similarly, for part (ii), using #=#i(p , m lmz . . , mi),

Imlm2 mikl, = (# ,mlmz . . . mi) mlm2 "'" mi k "'" (#,mlm2 • mi) ~i(,,mlm2...,,,)

mi) mlm2 "'" mi k ~ = ( # ' m t m 2 " ' " (# ,mx~ 2 ~m,)

= {{m~m~ . . . m L { k { 2 ~ .

For part (iii), note that applying (ii), with k=m~, and i : = i - 1 , yields

I ra ,m2 . . . mi-lmi{u = {Imlm2 . . . mi-liulmilu,_,{u

and applying this result iteratively, for decreasing i, yields

{ m l m 2 . . . mil, = [{mll,olm21,1 • • • Imi-,l,,_2lmilF,,_l[~,. •

The mixed-radix expression

s = do+d~m ~ + d z m l m 2 + . . . + d . _ ~ m l m z . . m , _ t ,

can be simplified in the sense that the results of Lemma (3.7) can be used to reduce the magnitude of both the mixed-radix digits do, d , , . . . , d , _ a , and the radices ml, m 2 , . . , m,_ 1 during the evaluation of }st,.

The Basic Theorem.

(3.8) THEOREM (Target Modulus Reduction Theorem). For the base vector fl and the target modulus It > 2, with fi-reduced moduli Pl, for i = O, 1 . . . . , n - 1, let s have the standard mixed-radix form

296 R O B E R T T O D D G R E G O R Y A N D D A V I D W. M A T U L A

(3.9)

and let

(3.10)

Then

(3.11)

s = d o + d i m 1 + d 2 m l m 2 + . . . + d n _ l m l m 2 . . . mn_ 1 ,

= 0, . . . . , n - d~ Id&

i t 1 r~i+l Im~+d.,

Islu = Ido + dt~l + ~ 2 / ~ 1 f f / 2 + , • . + d n - lmlm2 . . • r h n - l lu •

PROOF. F r o m results (ii) and (iii) of Lemma (3.7),

Idimlm2 . . . mi[u = I l m l m 2 . . . miluldil,,[u

= llmllJmzl , l . . . ImL,_jdLd~

= I/fil/~2 . . . ~idilu • Hence,

Islu = I ldolu + ldl ml I. + Id2mlm2lu + . . . + Id, - lm lm2 . . . m , _ l I , [ , .

= l d o - t - d l / ~ l - i - d 2 f f / l f f / 2 "t- • • • " 1 - ~ n - 1 / ~ 1 / ~ 2 " ' " /~n--11/.¢ "

If we are given the base vector /3 and a target modulus # > 2 along with the/3- reduced moduli ~h from (3.4), we can use (3.10) to introduce the two terms #- reduced vector

(3.12) p = [ r h l , ~ 2 , . . . , t h , ] ,

and #-reduced digit sequence for s

(3.13) ( s )p = (do, d l , . . . , d , _ ~ ) t ~ .

REMARK. It should be noted that ]~ does not necessarily satisfy the definition of a "bhse vector" since r~ i = 0 or n~= 1 might occur for some i. Also, note that the expression

do + dlrhl + a 2 f f / l f f / 2 -t- . . . + d n _ 1 /~1 /~ /2 . . . / n n - 1

is not necessarily a s tandard mixed-radix expression since we cannot guarantee' that d~ < ~ + 1.

In (2.32) and (2.33) we demonst ra ted a recursive procedure for evaluating expressions such as (3.11). However, the following corol lary will enable us to reduce the effort in the evaluation, considerably, by using the fl-reduced moduli instead of/~.

(3.14) COROLLARY. Under the hypotheses o f the Target Modu lus Reduc t ion

Theorem,

(3.15)

where

(3.16)

BASE CONVERSION IN RESIDUE NUMBER SYSTEMS

{ Q ~ = ~ ._~

PROOV. We can write

recursively as

j = 2 , 3 , . . . , n .

s = do+dim i + d z m l m z + . . . +d._amlm 2 . . . mn_ 1

Q1 = d . - 1

Qj d ,_ j+Qj_lm,_ j+ 1 j = 2 , 3 , . . . , n

where s=Q. . Then, from (3.10),

tQd~.-1 = td.-i1.._1

= (~n--I ,

and, for j = 2 , 3 . . . . ,n, using Lemma (3.7) part (i) and (3.10),

[Qjl,,-, = [[d,-jlu._,+lQj-am,-j+,lu._,[~._~

= la. j+l lm.

If we set

(L = IQL. - ,

for t = 1,2 . . . . ,n, then

~j ld.-j+ Qj- lm.-j+ 11.._~

and (3.16) is satisfied. Since s=Q. and # o = p

Isl. = tQ.t.o

and the proof is complete.

j = 2 , 3 , . . . , n

297

The Effect of Permuting the Moduli.

It should be noted that the amount of efficiency achieved by using the smaller fl-reduced moduli p~, rather than/~, in the process of target modulus conversion depends on the ordering of the {m~} in the base vector fl = Ira1, m2, . . . , m,]. Let the

BIT 17--20

298 ROBERT TODD GREGORY AND DAVID W, MATULA

base vector rc be obtained from fl by a permutation of the moduli. Furthermore, let the moduli in

(3.17) rc = [m~l, m i 2 , . . . , m j

= [ P , P2 . . . . , P,]

be so ordered that

(3.18)

Then certainly

(#,P0 ~ (P, Pj) j = 2 , 3 . . . . . n.

# (3.19) /zl = (P, Pl)

is minimized over all such permuted orderings. The effect of permuting the m.oduli in fl to produce ~ is simply to change the

residue representation of an integer s from

IS[/? = [[S[ml, [Stm 2 . . . . . [S]mn'] , (3.20)

for the base vector fl, to

(3.21) Isl= = E l s l p . Islp2 . . . . . Isls.]

for the base vector 7t. In other words, the residue digits in Isle are permuted to produce fs]~ in exactly the same way that the moduli in fl are permuted to produce

Obviously, it is desirable for efficient target modulus conversion first to permute the moduli in the base vector fl (producing the base vector ~z) so that the resulting re-reduced moduli tti(r 0 will be as small as possible. The following theorem shows that a simple ordering procedure for the moduti in a base vector exists which affects a uniformly optimal reduction in the size of #o, #~ . . . . . P,-1.

(3.22) THEOREM. Given the base vector n = [ P l , P 2 , . . . , Phi and the target modulus

# > 2, where rc is so ordered that b

(3.23) (P,P~) > (#,P2) > . - . > (#,P,),

let the base vector ~ = [Ptl, Pt2,. • . , Pt,] have the same moduli as n but permuted in the

order (tl, t 2 , . . . , t,). Then

(3.24) #i(g) < Pj(2;) j = 0 , 1 . . . . . n - 1 .

PROOF. Suppose the target modulus # is redundant (not relatively prime) with exactly k of the moduli pi of n. Since the {p~} are pairwise relatively prime and ordered to satisfy (3.23), then

(P, PO > (#,P2) > . . - > (#,Pk) > 1

BASE CONVERSION IN RESIDUE NUMBER SYSTEMS 299

and

( # , P k + l ) = ( # , P k + 2 ) . . . . . (]l,p'n) = 1 .

Now #o(rC)=#=#o(y ), and for j = 1 , 2 . . . . , n - l , consider the j integers

(#,Ptl), (#,Pt2) . . . . , (#,P0" The largest of these is no greater than (#,Pl), and, in general, the rth largest of these j numbers is no larger than (#, p,) for r = 1, 2 . . . . . j. Hence

(#,PtO(#,Pt2)''' (#'PO <= (# ,P0(# ,Pz ) - . - (# ,P j ) ,

so that

#

#J(~) = (#,PlP2.. .Pj)

#

(#, P l ) ( # , P2) • • ' (# , Pj)

#

(#, pJ(~, pt2) - • . (# , P O

#

(#, PtlPt2 • • • Ptj)

= #j(~) j = l , 2 . . . . . n - 1 . |

For any set of pairwise relatively prime positive integers {ml, m2 . . . . . mn} and # > 2 , a redundancy ordering with # of {ml, m 2 . . . . . ran} is an ordering

(m a, m a . . . . . mi. ) such that

(3.25) (#,rail) > (#,m~2) > . . . > (#,mi,) .

The base vector rr = [Pl, P2 . . . . . p,] is I~-redundancy-ordered if (Pl, P2 . . . . . Pn) is a redundancy ordering with p of the moduli {p~}.

For the purposes of efficient target modulus conversion to modulus # it is evident from Theorem (3.8), Corollary (3.14), and Theorem (3.22) that the base vector of a residue number system should first be #-redundancy-ordered. The following examples illustrate target modulus conversion utilizing both a #- redundancy-ordered base vector rc and the subsequent re-reduced moduli #i(rc) to simplify the computational effort.

Target Modulus Conversion Examples .

Let f l=[39,41,43,77,80] be the base vector of a standard residue number system, where Ma=423 543 120. Also, let # =3 1 5 be the target modulus. We observe that 315 is redundant with 77, 80, and 39 and that

300 ROBERT TODD GREGORY AND DAVID W. MATULA

(315,77) = 7 (3.26) (315,80) = 5

(315, 39) = 3 .

Thus the permuted base vector = = [77,80,39,41,43] is # - redundancy-ordered

(for p = 3 1 5 ) for the residue number system under considerat ion. The n-reduced

modul i p~ are

/~o = 315

315 #1 = - - = 45

7

315 (3.27) /~a = (7)(5) - 9

315 # 3 = - - = 3

(7)(5)(3)

# 4 = 3

and the p-reduced vector* f f = [/31,/32,/~3,/34,/Ss] has componen t s

/51 = 177]315 = 77

/32 -~ [80t4-5 = 35 (3.28) /33 = 13919 = 3

/54 = [4113 = 2

/35 = 14313 = 1.

We recall that our objective, in all of this, is the efficient evaluat ion of [s1315. Fo r

s in the range

(3.29) 0 N s < Mp = M=

the values of #o,/~1,.. . ,/~4 and /3t,/52 . . . . ,/35 are fixed. Therefore, in a practical application, these values can be entered pe rmanen t ly in the compute r hardware , microcode, or software implementa t ion of target modulus conversion. The digit reduct ion procedure indicated in Theo rem (3.8) must be carried out, of course, as a par t icular integer s is being converted.

For example, s = 228 306 863 has the mixed-radix representat ion

(3.30) s = 15+64(77)+12(77)(80)+7(77)(80)(39)+23(77)(80)(39)(41)

in the s tandard mixed-radix number system associated with the s tandard residue

n u m b e r system for 7r= [77, 80, 39, 41,43-1 under considerat ion. Then

(3.31) ( s )~ = (15, 64,12, 7, 23)~

is the digit sequence for s. The ~-reduced digits (for # = 315) are

* See (3.12).

BASE CONVERSION IN RESIDUE NUMBER SYSTEMS 301

(3.32)

do = 1151315 = 15 d, = ]64145 = 19

d 2 = 11219 = 3

da 17~ -- 1 d-4 12313 = 2 .

From Theorem (3.8), it follows that

(3.33) Is]315 = It 5 + 19(77) + 3(77)(35) + 1 (77)(35)(3)+ 2(77)(35)(3)(2)1315

which is a considerable simplification over working wi{h the full mixed-radix form

(3.30). If we use Corollary (3.14), we can evaluate (3.33) as follows:

Qx = 2

Q2 = I1+ (2)(2)[3 = 2

03 = 13+(2)(3)[9 = 0

Q4 = 119+(0)(35)[, 5 = 19

Q5 = t15+ (19)(77)t315 = 218

and so [s1315=218. A still more dramatic reduction is possible if the target modulus # happens to

divide Ma. In the example above if wechange p from 315 to the value 105 (which divides 423 543 120) we obtain the results

Hence,

(3.34)

#o = 105 Pl = 77 d o = 15

#1 = 15 P2 = 5 d l = 4

~2 = 3 P3 = 0 d 2 = 0

P3 = 1 P 4 = 0 d 3 = 0

~4 = 1 P5 = 0 d 4 = 0

IStlo5 = 115+4(77)11o5

= 8 .

REMARK. Although the theory and examples for target modulus conversion have been derived herein for standard residue number systems, the modifications necessary to establish the same results for balanced residue number systems are

straightforward. For reference, the balanced residue system versions of [ ,emma (3.7), Theorem (3.8), and Corollary (3.14) are given without prgof since the proofs follow by simply paralleling the previous proofs in an obvious manner.

(3.35) LEMMA. Let the base vector fi = [ml, m 2 . . . . , re,I, with all odd moduIi, the target modulus !~ >= 2, and the fl-reduced moduli /to, P p . . . , # , -1 be given. Then Jor

302

any integer k,

( i )

(ii)

(iii)

ROBERT T O D D GREGORY AND DAVID W. MATULA

/mi + lk/~,, = / /mi + 1/l,,/k/~,,+,li,,

/ m l m 2 . . . mik/~, , = / / m l m 2 . . . m.]dkl~,] .

/ m l m 2 . . . m J , = / / m l / , o / m 2 / , 1 . . . / m , / , , _ i / ~ ,

0__<i<n-1 ,

l<__i<n,

l < i < n .

(3.36) THEOREM (Target Modulus Reduct ion Theorem). For the base vector fl,

wi th all odd moduli, and the target modulus # > 2 , wi th f l-reduced moduli izi, f o r i

= 0, 1 . . . . . n - 1 , let s have the balanced mixed-rad ix f o r m

s = b o + b l m l + b 2 m l m 2 + . . . + b , _ l m i m 2 . . . m , - 1 ,

and let

Then

(3.37) COROLLARY. Theorem,

bi = /bi/ , i

nSi+l /mi+l/ ,~ i=0 , 1 . . . . , n - 1 .

/ s / , = /bo + b l f f h +b2rhi f f~2+. . . +b,,_lrhin~2 . . . rh,,_i/~,.

Under the hypotheses o f the Target Modu lus Reduct ion

Is~. = 0 . .

{ 0 1 =

Oj = / b . -~+Oj - i r h~ - j+ i / . . -~ j = 2 , 3 . . . . . n .

where

R E F E R E N C E S

1. N. S. S z a b 6 a n d R. I. T a n a k a , Residue Arithmetic'and Its Applications to Computer Technology, N e w

N e w York , M c G r a w - H i l l , 1967.

2. J. A. Howe l l a n d R. T. G r e g o r y , Solving Linear Equations Using Residue Arithmetic-Algorithm II,

BIT 10 (1970), 23-37.

ROBERT TODD GREGORY DEPARTMENT OF COMPUTER SCIENCE THE UNIVERSITY OF TENNESSEE

KNOXVILLE TENESSEE 37916, U.S.A.

AND

DAVID W. MATULA DEPARTMENT OF COMPUTER SCIENCE SOUTHERN METHODIST UNIVERISTY DALLAS TEXAS 75275, U.S.A.