(lambda a (let ((p (apply (fileVal "Poly/poly") (cdr a)))(* (car (cddddr a)))) (ylppa (cons (car a) (cdr p)) (lambda (inv sub mul sm pp) (let* ((qr (lambda (n d) (if (null? d) "d=0" (let ((ln (length n))(ld (length d))) (if (< ln ld) (cons '() n) (let ((n (reverse n))(d (reverse d))) (let* ((i (inv (car d))) (nd (sm i (cdr d)))) (let ((pr (let Q ((n n)(ln ln)) (if (< ln ld) (cons '() (reverse (let rz ((n n)) (if (null? n) n (if (= 0 (car n)) (rz (cdr n)) n))))) (let* ((qr (Q (sub (cdr n) (sm (car n) nd)) (- ln 1)))(q (car qr))(r (cdr qr))) (cons (cons (car n) q) r)))))) (cons (sm i (reverse (car pr))) (cdr pr)))))))))) (gcd (lambda (A B) (let g ((A A)(B B)) (if (null? B) (sm ((car a) (car (reverse A))) A) (g B (cdr (qr A B)))))))) (lambda (sy) (cdr (assq sy (list (cons 'qr qr) (cons 'ply p)(cons 'gcd gcd)))))))))) ; tests (define f ((fileVal "Poly/qr") / 0 zero? + - * number? 1)) ((f 'qr) '(-8288 7239 -12937 8843 87) '(71 -9 103 1)) ; => ((-118 87) 90) ((f 'gcd) '(-8288 7239 -12937 8843 87) '(71 -9 103 1)) ; => (1) (define g (f 'qr)) (g '(4 4 1) '(2 1)) ; => ((2 1) . ()) (g '(4 4 1) '(4 2)) ; => ((1 1/2) . ()) (g '(5 4 1) '(2 1)) ; => ((2 1) . (1)) (g '(5 4 1) '(4 2)) ; => ((1 1/2) . (1)) (ylppa (f 'ply) (lambda (+ - * sm pp) (let ((t (lambda (a b c) (let* ((n (* a c))(d (* b c)) (p (g n d)) (q (car p))(r (cdr p)) (e (+ (* q d) r))) (list p d c e (- n e)))))) (list (t '(1 2) '(1 3) '(1 1)) (t '(2 4 3) '(1 5) '(4 2 3)) (t '(2 4 3 8 1) '(1 5 2) '(4 1 3)) )))) ; => ((((2/3) 1/3 1/3) (1 4 3) (1 1) (1 3 2) ()) ; (((17/25 3/5) 132/25 66/25 99/25) (4 22 13 15) (4 2 3) (8 20 26 18 9) ()) ; (((-45/8 11/4 1/2) 61/2 1001/8 209/4 705/8) (4 21 16 17 6) (4 1 3) (8 18 22 47 21 25 3) ())) ; should yield a list of lists, each of which end in '(). (ylppa (f 'ply) (lambda (+ - * sm pp) (let* ((g (f 'gcd))(t (lambda (a b c) (let* ((n (* a c))(d (* b c)) (p (g n d))) (list n d c "prop to" p))))) (list (t '(4 1) '(3 1) '(1 1)) (t '(4 1) '(3 1) '(2 1)) (t '(4 1) '(3 1) '(7 11)) (t '(4 -1 1) '(3 4 1) '(1 3 2)) (t '(1 2) '(1 3) '(1 1)) (t '(2 4 3) '(1 5) '(4 2 3)) (t '(2 4 3 8 1) '(1 5 2) '(4 1 3)) )))) ; => (((4 5 1) (3 4 1) (1 1) "prop to" (1 1)) ; ((8 6 1) (6 5 1) (2 1) "prop to" (2 1)) ; ((28 51 11) (21 40 11) (7 11) "prop to" (7/11 1)) ; ((4 11 6 1 2) (3 13 19 11 2) (1 3 2) "prop to" (1/2 3/2 1)) ; ((1 3 2) (1 4 3) (1 1) "prop to" (1 1)) ; ((8 20 26 18 9) (4 22 13 15) (4 2 3) "prop to" (4/3 2/3 1)) ; ((8 18 22 47 21 25 3) (4 21 16 17 6) (4 1 3) "prop to" (4/3 1/3 1)))