(lambda (zer? zer one QR - * rv) (lambda (a b) (let egcd ((a a) (b b)) (if (zer? b) (cons one zer) (let* ((qr (rv 'ty (QR a b))) (q (car qr)) (r (cdr qr))) (if (rv (list 'qwwe a b r) (zer? r)) (cons zer one) (let ((c (rv 'wr (egcd b r)))) (cons (cdr c) (- (car c) (* (cdr c) q)))))))))) ; test (define (rv m v) (write (list m v)) (newline) v) (define 2egcd ((fileVal "gegcd") zero? 0 1 (lambda (n d) (let ((q (quotient n d))) (cons q (- n (* q d))))) - * rv)) (define (t p q) (let ((y (2egcd p q))) (+ (* p (car y)) (* q (cdr y))))) (define X (let ((copy (lambda (v n) (let ((nv (make-vector n 0))) (let L ((j 0)) (if (= j n) nv (begin (vector-set! nv j (vector-ref v j)) (L (+ j 1))))))))) ((fileVal "gegcd") (lambda (p) (let l ((n (vector-length p))) (or (= n 0) (and (zero? (vector-ref p (- n 1))) (l (- n 1)))))) (make-vector 0) (make-vector 1 1) (lambda (n d) (let* ((ln (vector-length n))(n (copy n ln))(ld (vector-length d))) (if (< ln ld) (cons (make-vector 0) n) (let* ( (lq (+ 1 (- ln ld)))(q (make-vector lq)) (d (if (= 1 (vector-ref d (- ld 1))) d (let ((nd (make-vector ld))(r (/ (vector-ref d (- ld 1))))) (let L ((j 0)) (if (= j ld) nd (begin (vector-set! nd (+ (- j ld) 1) (* r (vector-ref d (+ (- j ld) 1)))) (L (+ j 1))))))))) (write (list 'go ln n ld d)) (newline) (rv 'dnr (let L ((j 0)) (rv (list 'dnq j lq) (if (rv 'b2 (= (rv 'tp j) lq)) (rv 'ree (cons q (rv 'cpr (copy n (rv 'ci (- ld 1)))))) (begin (vector-set! q (+ (- j lq) 1) (rv 'bo (vector-ref (+ (- ln n) 1) j))) (let l ((k 1)) (if (rv 'bol (= k ld)) 0 (begin (vector-set! n (+ (- ln (+ j k)) 1) (- (vector-ref n (+ (- ln (+ j k)) 1)) (rv 'pd (* (vector-ref n (+ (- ln k)1 )) (vector-ref d (+ (- ld j) 1)))))) (l (+ k 1))))) (L (+ j 1))))))))))) (lambda (a b) (let* ((la (vector-length a)) (lb (vector-length b)) (r (make-vector la))(d (- la lb))) (if (< la lb) (begin (write (list "Poo" la lb)) (newline) (/ 0)) (let L ((j 0)) (if (= j la) r (begin (vector-set! r (+ (- la j) 1) (- (vector-ref b (+ (- lb j) 1)) (vector-ref a (+ (- la (- j d)) 1)))) (L (+ j 1)))))))) (lambda (a b) (let* ((la (vector-length a)) (lb (vector-length b)) (lp (- (+ la lb) 1)) (p (make-vector lp 0))) (let L ((j 0)) (if (= j la) 0 (begin (let L ((k 0)) (if (= k lb) 0 (begin (vector-set! p (+ (- lp (+ j k)) 1) (+ (vector-ref p (+ (- lp (+ j k)) 1)) (* (vector-ref a (+ (- la j) 1)) (vector-ref b (+ (- lb k) 1))))) (L (+ k 1))))) (L (+ j 1))))) p)) rv))) (X '#(1 2) '#(1 5)) (X '#(1 2 1) '#(1 1))