Download Lecture 5: Residual Number System.

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CSE20 Lecture 5
4/12/11
CK Cheng
UC San Diego
1
Residual Numbers
(NT-1 and Shaum’s Chapter 11)
•
•
•
•
Introduction
Definition
Operations
Range of numbers
2
Introduction
• Applications: communication, cryptography,
and high performance signal processing
• Goal: Simplify arithmetic operations (+, -, x)
when bit width n is huge, e.g. n= 1000. Note
no division is involved.
• Flow:
Residual number
Mod Operation
(x1, x2, …, xk)
Number x
Moduli (m1, m2, …, mk)
Results
+, -, x operations
for each xi under mi
Chinese Remainder Theorem
3
Definition
Mod (Modular) operation.
– Given integer x and d (d> 0), find q and r such that
x = q*d+r, 0<= r <d,
where q: quotient, d: divisor, and r: remainder.
We define x%d= r.
Conversion to residual system:
Given moduli (m1, m2, …, mk), where all mi are
mutually prime, transform
integer x to (r1, r2, …, rk), where ri=x%mi
4
Definitions
• Mutually Prime: Two integers a & b are
mutually (or relatively) prime if their greatest
common divisor is 1.
• e.g. 3 & 8, 4 & 9, but not 6 & 9
• Residual number: Given (m1, m2,…,mk) where
mis are mutually prime and a positive integer
x <M=m1xm2x…xmk
(0 ≤x <M ) represent x as
( x%m1, x%m2,…, x%mk )
5
Examples (x%mi=ri)
Given (m1, m2, m3) = (3, 5, 7), convert
x: (r1, r2, r3).
• 0: (0, 0, 0);
0%3=0,
0%5=0,
• 2: (2, 2, 2);
2%3=2,
2%5=2,
• 21: (0, 1, 0); 21%3=0 , 21%5=1,
• -2: (1, 3, 5); -2%3=1, -2%5=3,
• -3: (0, 2, 4); -3%3=0, -3%5=2,
• -21: (0, 4, 0); -21%3=0, -21%5= 4,
Hint: 0<= ri < mi
0%7= 0
2%7=2
21%7=0
-2%7=5
-3%7=4
-21%7=0
6
Examples
• k = 3 ( m1, m2, m3 ) = ( 2, 3, 7 )
• M = m1 x m2 x m3 = 2 x 3 x 7 = 42
• Given x=30, ( x%m1, x%m2, x%m3 )
= ( 30%2, 30%3, 30%7 ) = ( 0, 0, 2 )
• Given y=4, ( y%m1, y%m2, y%m3 )
= ( 4%2, 4%3, 4%7 ) = ( 0, 1, 4 )
• Given x+y=34, ((x+y)%m1,(x+y)%m2,(x+y)%m3 )
= ( 34%2, 34%3, 34%7 ) = ( 0, 1, 6 )
7
3. Modular Operations
Theorem: Given three integers x,y,d, we have
(x+y)%d=(x%d+y%d)%d.
Proof:
Let x = qxd + rx, y = qyd + ry
We have (x+y)%d = (qxd + rx + qyd + ry)%d
=(rx+ry)%d
Therefore, (x+y)%d = (x%d+y%d)%d
8
3. Modular Operations
Theorem: Given three integers x,y,d, we have
(x*y)%d=(x%d * y%d)%d.
Proof:
Let x = qxd + rx, y = qyd + ry
We have (x*y)%d = (qxd + rx )*(qyd + ry)%d
=(qxqyd2+ryqxd+rxqyd+rx*ry)%d
= (rx*ry)%d
Therefore, (x*y)%d = (x%d * y%d)%d
9
3. Modular Operations
• What about division?
• Could we state the following equality?
((x%d)/(y%d))%d= (x/y)%d
Answer: No! We have the following problems.
1. y%d can be zero.
2. (x%d)/(y%d) or x/y can be fractional.
10
Range of Numbers
Theorem: Given (m1, m2, …, mk), where all mi are
mutually prime, let M=m1xm2x…xmk.
For 0<= x< M, the residual number
(x1, x2, …, xk) is distinct.
Proof: By contradiction, let 0<= y<x < M.
Suppose (x1, x2, …, xk)=(y1, y2, …, yk) then
x-y : (0,0, …,0). However, for all numbers in the
range of the interval, only 0 : (0,0, …,0)
because the mods mi are mutually prime.
11
Related documents