cse20 lecture 5 4/12/11

11
1 CSE20 Lecture 5 4/12/11 CK Cheng UC San Diego

Upload: sibyl

Post on 06-Jan-2016

24 views

Category:

Documents


3 download

DESCRIPTION

CSE20 Lecture 5 4/12/11. CK Cheng UC San Diego. Residual Numbers (NT-1 and Shaum’s Chapter 11). Introduction Definition Operations Range of numbers. Introduction. Applications: communication, cryptography, and high performance signal processing - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSE20 Lecture 5 4/12/11

1

CSE20 Lecture 54/12/11

CK ChengUC San Diego

Page 2: CSE20 Lecture 5 4/12/11

Residual Numbers(NT-1 and Shaum’s Chapter 11)

• Introduction• Definition• Operations• Range of numbers

2

Page 3: CSE20 Lecture 5 4/12/11

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:

3

Number xResidual number(x1, x2, …, xk)+, -, x operationsfor each xi under mi

Chinese Remainder Theorem

Mod Operation

Moduli (m1, m2, …, mk)

Results

Page 4: CSE20 Lecture 5 4/12/11

DefinitionMod (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

Page 5: CSE20 Lecture 5 4/12/11

Definitions• Mutually Prime: Two integers a & b aremutually (or relatively) prime if their greatestcommon 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

Page 6: CSE20 Lecture 5 4/12/11

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, 0%7= 0• 2: (2, 2, 2); 2%3=2, 2%5=2, 2%7=2• 21: (0, 1, 0); 21%3=0 , 21%5=1, 21%7=0• -2: (1, 3, 5); -2%3=1, -2%5=3, -2%7=5• -3: (0, 2, 4); -3%3=0, -3%5=2, -3%7=4• -21: (0, 4, 0); -21%3=0, -21%5= 4, -21%7=0Hint: 0<= ri < mi

6

Page 7: CSE20 Lecture 5 4/12/11

Examples

7

• 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 )

Page 8: CSE20 Lecture 5 4/12/11

8

3. Modular OperationsTheorem: 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

Page 9: CSE20 Lecture 5 4/12/11

9

3. Modular OperationsTheorem: 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

Page 10: CSE20 Lecture 5 4/12/11

3. Modular Operations• What about division?• Could we state the following equality?

((x%d)/(y%d))%d= (x/y)%dAnswer: No! We have the following problems.1.y%d can be zero.2.(x%d)/(y%d) or x/y can be fractional.

10

Page 11: CSE20 Lecture 5 4/12/11

Range of NumbersTheorem: 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