A Mec hanical Pro of of the Chinese Remainder Theorem Da - - PDF document

a mec hanical pro of of the chinese remainder theorem da
SMART_READER_LITE
LIVE PREVIEW

A Mec hanical Pro of of the Chinese Remainder Theorem Da - - PDF document

A Mec hanical Pro of of the Chinese Remainder Theorem Da vid M. Russino Adv anced Micro Devices, Inc. david.russinoff@a md. co m http://www.onr.c om /us er /ru ss /da vid Informal Statemen t L et m ; : : :


slide-1
SLIDE 1 A Mec hanical Pro
  • f
  • f
the Chinese Remainder Theorem Da vid M. Russino Adv anced Micro Devices, Inc. david.russinoff@a md. co m http://www.onr.c
  • m
/us er /ru ss /da vid
slide-2
SLIDE 2 Informal Statemen t Theorem L et m 1 ; : : : ; m k 2 N b e p airwise r elatively prime mo duli and let a 1 ; : : : ; a k 2 N . Ther e exists x 2 N such that x
  • a
1 (mo d m 1 ) x
  • a
2 (mo d m 2 ) . . . x
  • a
k (mo d m k ): If x satises the same c
  • ngruenc
es, then x
  • x
(mo d m 1 m 2
  • m
k ): 1
slide-3
SLIDE 3 A CL2 F
  • rmalization
(defun g-c-d (x y) (declare (xargs :measure (nfix (+ x y)))) (if (zp x) y (if (zp y) x (if (<= x y) (g-c-d x (- y x)) (g-c-d (- x y) y))))) (defun rel-prime (x y) (= (g-c-d x y) 1)) (defun congruent (x y m) (= (rem x m) (rem y m))) (defun congruent-all (x a m) (if (endp m) t (and (congruent x (car a) (car m)) (congruent-al l x (cdr a) (cdr m))))) (defthm chinese-remain de r-t he
  • r
em (implies (and (natp-all a) (rel-prime-modu li m) (= (len a) (len m))) (and (natp (crt-witness a m)) (congruent-all (crt-witness a m) a m)))) 2
slide-4
SLIDE 4 Informal Pro
  • f
Lemma 1 If x; y 2 N ar e r elatively prime, then ther e exists s 2 Z such that sy
  • 1
(mo d x). Lemma 2 If x; y ; z 2 N and x is r elatively prime to b
  • th
y and z , then x is r elatively prime to y z . Pro
  • f
  • f
CR T: Let M = m 1 m 2
  • m
k . F
  • r
i = 1; : : : ; k , let M i = M =m i and nd s i suc h that s i M i
  • 1
(mo d m i ). Let x = a 1 s 1 M 1 + a 2 s 2 M 2 +
  • +
a k s k M k : Then x
  • a
i s i M i
  • a
i (mo d m i ): 3
slide-5
SLIDE 5
slide-6
SLIDE 6 Example Supp
  • se
w e ha v e 10000
  • N
  • 50000
and N
  • 6
(mo d 25) N
  • 13
(mo d 36) N
  • 28
(mo d 49) Then w e ma y solv e for N as follo ws: M = 25
  • 36
  • 49
= 44100 M 1 = 36
  • 49
= 1764 M 2 = 25
  • 49
= 1225 M 3 = 25
  • 36
= 900 1764s 1
  • 1
(mo d 25) , 14s 1
  • 1
(mo d 25) , s 1
  • 9
(mo d 25) 1225s 2
  • 1
(mo d 36) , s 2
  • 1
(mo d 36) 900s 3
  • 1
(mo d 49) , 18s 3
  • 1
(mo d 49) , s 3
  • 30
(mo d 49) a 1 = 6, a 2 = 13, a 3 = 28 x = a 1 M 1 s 1 + a 2 M 2 s 2 + a 3 M 3 s 3 = 6
  • 1764
  • 9
+ 13
  • 1225
  • 1
+ 28
  • 900
  • 30
= 867281
  • 29281
(mo d 44100) N = 29281 5
slide-7
SLIDE 7 Pro
  • f
  • f
Lemma 1 Lemma 1 If x; y 2 N ar e r elatively prime, then ther e exists s 2 Z such that sy
  • 1
(mo d x). This is a sp ecial case
  • f
the follo wing: F
  • r
al l x; y 2 N , ther e exist r ; s 2 Z such that r x + sy = g cd(x; y ). The pro
  • f
is b y induction
  • n
x + y : (1) If x = 0, then r = and s = 1. (2) If y = 0, then r = 1 and s = 0. (3) If < x
  • y
, then nd r and s suc h that r x + s (y
  • x)
= g cd(x; y
  • x)
= g cd(x; y ) and let r = r
  • s
and s = s . Then r x + sy = (r
  • s
)x + s y = r x + s (y
  • x)
= g cd(x; y ): (4) If < y < x, then nd r and s suc h that r (x
  • y
) + s y = g cd(x
  • y
; y ) = g cd(x; y ) and let r = r and s = s
  • r
. 6
slide-8
SLIDE 8 F
  • rmal
Pro
  • f
(mutual-recurs io n (defun r (x y) (declare (xargs :measure (nfix (+ x y)))) (if (zp x) (if (zp y) 1 (if (<= x y) (- (r x (- y x)) (s x (- y x))) (r (- x y) y))))) (defun s (x y) (declare (xargs :measure (nfix (+ x y)))) (if (zp x) 1 (if (zp y) (if (<= x y) (s x (- y x)) (- (s (- x y) y) (r (- x y) y)))))) ) (defthm r-s-lemma (implies (and (natp x) (natp y)) (= (+ (* (r x y) x) (* (s x y) y)) (g-c-d x y)))) 7
slide-9
SLIDE 9 Pro
  • f
  • f
Lemma 2 Lemma 2 If x; y ; z 2 N and x is r elatively prime to b
  • th
y and z , then x is r elatively prime to y z . This is a consequence
  • f
the follo wing basic prop erties
  • f
g cd and primes: (1) g cd(x; y ) divides b
  • th
x and y . (2) If d divides b
  • th
x and y , then d divides g cd(x; y ). (3) If x > 1, then some prime divides x. (4) If a prime p divides ab, then p divides either a
  • r
b. It w
  • uld
tak e some w
  • rk
to pro v e these in A CL2. F
  • rtunately
, there is a more direct route to CR T. 8
slide-10
SLIDE 10 Alternate Approac h Lemma 3 L et x; y 1 ; y 2 ; : : : ; y k 2 N and p = y 1
  • y
k . If x is r elatively prime to e ach y i , then ther e exist c; d 2 Z such that cx + dp = 1. Pro
  • f:
Let p = y 1
  • y
k 1 . Assume that r x + sy k = 1 and, b y induction, that c x + d p = 1: Then (sd )p = (sy k )(d p ) = (1
  • r
x)(1
  • c
x) = 1
  • (r
+ c
  • r
c x)x: Th us, if c = r + c
  • r
c x and d = sd , then cx + dp = 1: 9
slide-11
SLIDE 11 F
  • rmal
Pro
  • f
(defun c (x l) (if (endp l) (- (+ (r x (car l)) (c x (cdr l))) (* (r x (car l)) (c x (cdr l)) x)))) (defun d (x l) (if (endp l) 1 (* (s x (car l)) (d x (cdr l))))) (defthm c-d-lemma (implies (and (natp x) (natp-all l) (rel-prime-all x l)) (= (+ (* (c x l) x) (* (d x l) (prod l))) 1))) 10
slide-12
SLIDE 12 Denition
  • f
crt-witness (defun
  • ne-mod
(x l) (* (d x l) (prod l) (d x l) (prod l))) (defthm rem-one-mod-1 (implies (and (natp x) (> x 1) (natp-all l) (rel-prime-all x l)) (= (rem (one-mod x l) x) 1))) (defthm rem-one-mod-0 (implies (and (natp x) (> x 1) (rel-prime-modu li l) (rel-prime-all x l) (member y l)) (= (rem (one-mod x l) y) 0))) (defun crt1 (a m l) (if (endp a) (+ (* (car a) (one-mod (car m) (remove (car m) l))) (crt1 (cdr a) (cdr m) l)))) (defun crt-witness (a m) (crt1 a m m)) 11
slide-13
SLIDE 13 The Main Lemma W e pro v e the follo wing generalization
  • f
CR T: (defthm crt1-lemma (implies (and (natp-all a) (rel-prime-modu li l) (sublistp m l) (= (len a) (len m))) (congruent-all (crt1 a m l) a m))) The pro
  • f
is b y induction, as suggested b y the denition: (defun crt1 (a m l) (if (endp a) (+ (* (car a) (one-mod (car m) (remove (car m) l))) (crt1 (cdr a) (cdr m) l)))) In the inductiv e case, the conclusion
  • f
the lemma expands as follo ws: (and (congruent (+ (* (car a) (one-mod (car m) (remove (car m) l))) (crt1 (cdr a) (cdr m) l)) (car a) (car m)) (congruent-al l (+ (* (car a) (one-mod (car m) (remove (car m) l))) (crt1 (cdr a) (cdr m) l)) (cdr a) (cdr m))). 12
slide-14
SLIDE 14 The Final Result CR T is deriv ed as an instance
  • f
crt1-lemma: (defthm crt1-lemma (implies (and (natp-all a) (rel-prime-modu li l) (sublistp m l) (= (len a) (len m))) (congruent-all (crt1 a m l) a m))) (defthm chinese-remain de r-t he
  • r
em (implies (and (natp-all a) (rel-prime-modu li m) (= (len a) (len m))) (and (natp (crt-witness a m)) (congruent-all (crt a m) a m)))) 13