SUBTRACTION OF INTEGERS IN
MIXED RADIX SYSTEM
H. B. KEKRE
Senior Professor, Department of Computer Science Mukesh Patel School of Technology Management & Engineering
Mumbai, India hb.kekre@nmims.edu
V. R. LAKSHMI GORTY
Associate Professor Department of Computer Science
Mukesh Patel School of Technology Management & Engineering Mumbai, India
vr.lakshmigorty@nmims.edu
Abstract:
In this paper, two integers with two radices are considered and represented the subtraction of the two integers with the mixed radix system. In the second part of the paper, more than two radices are taken and obtained the difference of the integers. Also a MATLAB code is generated to obtain the mixed radix form of the number. The extension of the same procedure is done for n-radices. The application of the mixed radix system is used in signal, image processing for data compression and many other computer applications.
Keywords: Mixed radix system, subtraction of integers, radices. 1. Introduction
Let N be any integer consisting of radix r, then 1 4 3 2
1 ... 4 3 2 1 0
n n
N mr m r m r m r m rm . In case of mixed radix form general representation is:
1 1...3 2 1 ... 4 3 2 1 4 3 2 1 3 2 1 2 1 1 0 n n
Nmr r r r r r r r m r r r m r r m r m m , where r r r1, , ,...,2 3 rn1 are different radices and when r1 r2 r3 ... rn1 r, then mixed radix reduces to fixed radix system. Thus mixed radix is general and fixed radix is a special case of mixed radix system. In case of a fixed radix N can be decomposed by dividing N by r successively to get coefficients m m m0, 1, 2,...,mn1 as remainders. In case of mixed radix N can be decomposed by dividing N by r1 to obtain m0 as a remainder and quotient can then be divided by r2 to obtain m1 as remainder. The process can be continued till mn1 obtained. Thus n-tuplemn1,...,m m m2, 1, 0 is obtained representing numberN. In the paper [1], Kekre and Lakshmi Gorty have given the addition of numbers in Mixed Radix system. They have also generated a MATLAB code for the possible outcomes on addition of integers by mixed radix system. The Author in [2] describes the magnitude comparison, sign detection and overflow detection for the residue number system was facilitated by converting the residue representations into the associated Mixed-Radix number system. In [3] applications have been shown for security using Mixed Radix design flow. In [4] the author explains modulo mi addition time is independent of the word length of operands. In [5] of his Doctoral Dissertation, presented a generic sign detection algorithm based on Mixed Radix Conversion algorithm MRC-II and an optimum algorithm for sign detection based on a special moduli set. The Author also presented a scaling algorithm based on Mixed Radix Conversion.
2. Mixed Radix System in subtraction
Considering N1 and N2 as any integers consisting of radices r r1, ,2 then general representation of any integer is given below as:
1 2 1 2 1 1 0 N r r m r m m
(1)
2 2 1 2 1 1 0 N r r n r n n
(2)
1 2 2.1 2 2 1 1 1 0 0
N N r r m n r m n m n (3)
1 2 0 0 2 1 2 2 1 1 1
1 2 0 0 1 2 2 2 1 1
1 2 0 0
2 2 2 1 1
1
1 2 0 0
1 1 2 2 2
1
1 2 0 0 1 1
2 2
1 2 2
1 2 0 0 1 1
2 2
1 2 2
. .
.
.
0
N N m n r r m n r m n
N N m n r r m n m n
N N m n
r m n m n
r
N N m n
m n r m n
r
N N m n m n
m n
r r r
N N m n m n
m n
r r r
In Mixed Radix the combination can be
1 2 1 2
1 2 1 2
1 2 1 2
2; 3 then 0,1; 0,1, 2 2; 5 then 0,1, 2; 0,1, 2,3 2; 7 then 0,1, 2, 3; 0,1, 2,3, 4
r r m m
r r m m
r r m m
and so on.
1
2
2, 3, 5, 7,11,13,...
3, 5, 7,11,13,...
r r 1 2
1 0 1 0
2 0 2 0
even or odd
even or odd
If even; then value of 0 and if odd; then value of 1.
If even; then value of 0 and if odd; then value of 1.
N N
N m N m
N n N n
Thus m0n0 will take either 0, 1 depending on even or odd number. There can be four cases for the integers in the mixed radix form represented:
Case 1: If N1 even ;N2 even.
1 0 2 0
If N even; then value of m 0,N even; then value of n 0. (i) If m0n0 0. If m1n1 0.m2n2 will be equal to
1 2
1 2
N N
r r
, which is quite obvious case.
(ii) If m0n0 0;m0 0,n0 0. 1 1
m n take values 1, 2,3,...,
r11
r11
2
r11
;2 2
m n takes 1 2
1 2 2
1
N N
r r r
.
2 2
m n can take values 0,1, 2, 3,...,
r r1 21
r r1 21
2
r r1 2 1
.For N1 even ;N2 even,the output of results with all possible values of m m n n1, 2, ,1 2are considered under the criteria of Mixed Radix applicability with the help of a code generated in MATLAB and obtained the possible values of N1and N2, along with N1N2.
syms r1 r2 m1 m2 n1 n2 m0 n0 N1 N2; x=1;
for m1=0:1:(r1-1) for n1=0:1:(r1-1) for m2=0:1:(r2-1) for n2=0:1:(r2-1) n0=0;
m0=0;
N1=r1.*r2.*m2+r1.*m1+m0; N2=r1.*r2.*n2+r1.*n1+n0;
fprintf('\n m2 m1 m0 n2 n1 n0 N1 N2 N1-N2\n')
fprintf('\n %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f\n',m2,m1,m0,n2,n1, n0, N1, N2, abs(N1-N2))
x=x+1; end end end end
Case 2: If N1 even ;N2 odd.
1 0 2 0
If N even; then value of m 0,N odd; then value of n 1. (i) If n0m0 1. Substituting in
1 2 0 0 1 1
2 2
1 2 2
0
N N m n m n
m n
r r r
,
with m1n10.m2n2 will be equal to
1 2
1 2
1
N N
r r
, which is quite obvious case.
(ii) If n0 m0 1. 1 1
m n can take values 1, 2,3,...,
r11
r11
2
r11
. 2 2m n can take values 0,1, 2, 3,...,
r r1 21
r r1 21
2
r r1 21
.For N1 even ;N2 odd, the output of results with all possible values of m m n n1, 2, ,1 2are considered under the criteria of Mixed Radix applicability with the help of a code generated in MATLAB and obtained the possible values of N1and N2, along with N1N2.
% N1 is even and N2 is odd (subtraction) syms r1 r2 m1 m2 n1 n2 m0 n0 N1 N2; x=1;
for m1=0:1:(r1-1) for n1=0:1:(r1-1) for m2=0:1:(r2-1) for n2=0:1:(r2-1) n0=1;
m0=0;
N1=r1.*r2.*m2+r1.*m1+m0; N2=r1.*r2.*n2+r1.*n1+n0;
fprintf('\n m2 m1 m0 n2 n1 n0 N1 N2 N1-N2\n')
fprintf('\n %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f\n',m2,m1,m0,n2,n1, n0, N1, N2, abs(N1-N2))
end end end end
Case 3: If N1 odd ;N2 even.Choose .N1 N2
1 0 2 0
If odd; then N value of 1,m N even; then value of 0.n (i) If m0n0 1. Substituting in
1 2 0 0 1 1
2 2
1 2 2
0
N N m n m n
m n
r r r
,
with m1n10.m2n2 will be equal to
1 2
1 2
1
N N
r r
, which is quite obvious case.
(ii) If m0n0 1;m0 1 andn0 0.
m1n1 can take values 1, 2,3,...,
r11
r11
2
r11
.m2n2 can take values 0,1, 2, 3,...,
r r1 2 1
r r1 21
2
r r1 21
.For N1 odd ;N2 even, the output of results with all possible values of m m n n1, 2, ,1 2are considered under the criteria of Mixed Radix applicability with the help of a code generated in MATLAB and obtained the possible values of N1and N2, along with N1N2.
% N1 is odd and N2 is even (subtraction) syms r1 r2 m1 m2 n1 n2 m0 n0 N1 N2; x=1;
for m1=0:1:(r1-1) for n1=0:1:(r1-1) for m2=0:1:(r2-1) for n2=0:1:(r2-1) n0=0;
m0=1;
N1=r1.*r2.*m2+r1.*m1+m0; N2=r1.*r2.*n2+r1.*n1+n0;
fprintf('\n m2 m1 m0 n2 n1 n0 N1 N2 N1-N2\n')
fprintf('\n %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f\n',m2,m1,m0,n2,n1, n0, N1, N2, abs(N1-N2))
x=x+1; end end end end
Case 4: If N1 odd ;N2 odd.Choose .N1 N2
1 0 2 0
If odd; then N value of 1,m N odd; then value ofn 1. (i) If m0n0 0. Substituting in
1 2 0 0 1 1
2 2
1 2 2
0
N N m n m n
m n
r r r
,
with m1n10.m2n2 will be equal to
1 2
1 2
N N
r r
, which is quite obvious case.
(ii) If m0n0 0; m0 1;n0 1.
m1n1 can take values 1, 2,3,...,
r11
r11
2
r11
.For N1odd ;N2 odd, the output of results with all possible values of m m n n1, 2, ,1 2are considered under the criteria of Mixed Radix applicability with the help of a code generated in MATLAB and obtained the possible values of N1and N2, along with N1N2.
% N1 is odd and N2 is odd (subtraction) syms r1 r2 m1 m2 n1 n2 m0 n0 N1 N2; x=1;
for m1=0:1:(r1-1) for n1=0:1:(r1-1) for m2=0:1:(r2-1) for n2=0:1:(r2-1) n0=1;
m0=1;
N1=r1.*r2.*m2+r1.*m1+m0; N2=r1.*r2.*n2+r1.*n1+n0;
fprintf('\n m2 m1 m0 n2 n1 n0 N1 N2 N1-N2\n')
fprintf('\n %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f\n',m2,m1,m0,n2,n1, n0, N1, N2, abs(N1-N2))
x=x+1; end end end end
A code is generated in the similar manner and all values for the initial radices and values of the sum of the possible integers are obtained in the similar manner.
Now considering the numbers in more than three radices:
1 4 3 2 1 4 3 2 1 3 2 1 2 1 1 0
2 4 3 2 1 4 3 2 1 3 2 1 2 1 1 0 N r r r r m r r r m r r m r m m N r r r r n r r r n r r n r n n
1 2 4 3 2 1 4 4 3 2 1 3 3 2.1 2 2 1 1 1 0 0
N N r r r r m n r r r m n r r m n r m n m n
1 2 0 0 4 3 2 1 4 4 3 2 1 3 3 2 1 2 2 1 1 1
1 2 0 0 1 4 3 2 4 4 3 2 3 3 2 2 2 1 1
1 2 0 0
4 3 2 4 4 3 2 3 3 2 2 2 1 1
1
1 2 0 0
1 1 4 3 2 4 4 3 2 3 3 2 2
1
.
N N m n r r r r m n r r r m n r r m n r m n
N N m n r r r r m n r r m n r m n m n
N N m n
r r r m n r r m n r m n m n
r
N N m n
m n r r r m n r r m n r m
r
n2
1 2 0 0 1 1
4 3 4 4 3 3 3 2 2
1 2 2
N N m n m n
r r m n r m n m n
r r r
1 2 0 0 1 1
2 2 4 3 4 4 3 3 3
1 2 2
1 2 0 0 1 1 2 2 3 3
4 4
1 2 3 4 4 3 2 4 3 4
1 2 0 0 1 1 2 2 3 3
4 4
1 2 3 4 4 3 2 4 3 4
0
N N m n m n
m n r r m n r m n
r r r
N N m n m n m n m n
m n
r r r r r r r r r r
N N m n m n m n m n
m n
r r r r r r r r r r
All other possible ways in which the mixed radix subtraction can be in the following manners: % N1 is even , N2 is even;
r1=2;r2=3;r3=5;r4=7; for m1=0:1:(r1-1) for n1=0:1:(r1-1) for m2=0:1:(r2-1) for n2=0:1:(r2-1) for m3=0:1:(r3-1) for n3=0:1:(r3-1) for m4=0:1:(r4-1) for n4=0:1:(r4-1) n0=0;
m0=0;
N1=r1.*r2.*r3.*r4.*m4+r1.*r2.*r3.*m3+r1.*r2.*m2+r1.*m1+m0; N2=r1.*r2.*r3.*r4.*n4+r1.*r2.*r3.*n3+r1.*r2.*n2+r1.*n1+n0;
fprintf('\n m4 m3 m2 m1 m0 n4 n3 n2 n1 n0 N1 N2 N1-N2\n')
fprintf('\n %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f\n',m4,m3,m2,m1,m0,n4,n3,n2,n1, n0, N1, N2, abs(N1-N2))
x=x+1; end end end end end end end end
% N1 is even , N2 is even;
syms r1 r2 m1 m2 n1 n2 m0 n0 N1 N2; x=1;
r1=2;r2=3;r3=5;r4=7;r5=11;r6=13; for m1=0:1:(r1-1)
for n1=0:1:(r1-1) for m2=0:1:(r2-1) for n2=0:1:(r2-1) for m3=0:1:(r3-1) for n3=0:1:(r3-1) for m4=0:1:(r4-1) for n4=0:1:(r4-1) for m5=0:1:(r5-1) for n5=0:1:(r5-1) for m6=0:1:(r6-1) for n6=0:1:(r6-1) n0=0;
m0=0;
N1=r1.*r2.*r3.*r4.*r5.*r6.*m6+r1.*r2.*r3.*r4.*r5.*m5+r1.*r2.*r3.*r4.*m4+r1.*r2.*r3.*m3+r1.*r2.*m2+r1.*m 1+m0;
fprintf('\n m4 m3 m2 m1 m0 n4 n3 n2 n1 n0 N1 N2 N1-N2\n')
fprintf('\n %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f %3.4f\n',m4,m3,m2,m1,m0,n4,n3,n2,n1, n0, N1, N2, abs(N1-N2))
x=x+1; end end end end end end end end end end end end
Thus in general the numbers by mixed radix method for a given set of radices are calculated. General representation is:
1 1...3 2 1 ... 4 3 2 1 4 3 2 1 3 2 1 2 1 1 0 n n
Nmr r r r r r r r m r r r m r r m r m m , where r r r1, , ,...,2 3 rn1 are different radices. 3. Application
This method is very much useful in computer applications, in reading or sorting a particular number N from the multidimensional array or sequence of numbers from its specified location. And subtracting two numbers from the specified array, the distance can be found between the array elements.
4. Conclusion
In this paper, a simple to understand and easily applied mixed radix system for subtraction of integers with known radices is developed. Initially a code is developed for two numbers and later developed not only for more than two numbers but also more than two radices. Here integers with more than two radices can be subtracted and all the possible results of the subtraction of integers are represented as a result of mixed radix system. Due to developed MATLAB code also the process becomes simpler and readily available to use.
5. References
[1] Kekre, H. B. and Lakshmi Gorty, V. R., June (2013): Addition of integers in Mixed Radix System, International Journal of Computer Applications, Vol. 72, No. 3, 40-44.
[2] Israel K., (1993): Computer Arithmetic Algorithms, Prentice Hall PTR.
[3] Rafiev A., September (2011): Mixed Radix Design Flow for Security. Applications, Technical Report Series.
[4] Shugang W., September 4–7, (2005): Number Conversions between RNS and Mixed Radix Number System Based on Modulo (2p− 1)
Signed Digit Arithmetic, SBCCI’05.
[5] Mohammed Zakaria Akkal, (2008): Non-modular-operation algorithms in residue number system based on mixed radix conversion. Doctoral Dissertation.
[6] Imad Bako M., (2010): Using Mixed-Radix Method for Representing and Processing Numbers in Parallel Manner, IASJ, 52-62. [7] Elisardo Antelo, Javier D. Bruguera, and Emilio L. Zapata, September (1996): Unified Mixed Radix 2-4 Redundant CORDIC
Processor, IEEE transactions on Computers, vol. 45, no. 9, 1068-1073. [8] Wai Kai Chen, (2004): The Electrical Engineering Handbook.
[9] Pemmaraju V. Ananda Mohan, September (2007): RNS-To-Binary Converter for a New Three-Moduli set