(defun vadd ( x y ) ( cond ( ( null x ) y ) ( ( null y ) x ) ( t ( cons (+ (car x) (car y) ) (vadd (cdr x) (cdr y)) )) ) ) (defun sprod ( n v ) ( cond ( ( null v ) nil ) ( t ( cons (* n (car v)) (sprod n (cdr v)) )) ) ) (defun vprod ( x y ) ( cond ( ( or ( null x ) ( null y ) ) 0 ) ( t ( + (* (car x) (car y) ) (vprod (cdr x) (cdr y)) )) ) ) (defun madd ( x y ) ( cond ( ( null x ) y ) ( ( null y ) x ) ( t ( cons (vadd (car x) (car y) ) (madd (cdr x) (cdr y)) )) ) ) (defun mvprod ( m v ) ( cond ( ( null m ) nil ) ( t ( cons (vprod (car m) v) (mvprod (cdr m) v) )) ) ) (defun carlist ( m ) ( cond ( ( null m ) nil ) ( ( null ( car m ) ) nil ) ( t ( cons ( car ( car m ) ) ( carlist ( cdr m ) ) )) ) ) (defun cdrlist ( m ) ( cond ( ( null m ) nil ) ( ( null ( car m ) ) nil ) ( t ( cons ( cdr ( car m ) ) ( cdrlist ( cdr m ) ) )) ) ) (defun trans ( m ) ( cond ( ( null ( car m ) ) nil ) ( t ( cons (carlist m) (trans (cdrlist m)) )) ) ) (defun mprodsub ( h v ) ( cond ( ( null v ) nil ) ( t ( cons ( mvprod h (car v) ) ( mprodsub h (cdr v) ) )) ) ) (defun mprod ( x y ) ( trans ( mprodsub x ( trans y ) ) ) ) (defun nraw ( a n ) ( cond ( (= n 1) (car a) ) ( t (nraw (cdr a) (- n 1)) ) ) ) (defun nmelm ( a n m ) (nraw (nraw a n) m) ) (defun nreplace ( a n v ) ( cond ( (= n 1) (cons v (cdr a)) ) ( t (cons (car a) ( nreplace (cdr a) (- n 1) v ) )) ) ) (defun ncprod (a n c) ( nreplace a n (sprod c (nraw a n) ) ) ) (defun nmcsub (a n m c) ( nreplace a n (vadd (nraw a n) (sprod (- c) (nraw a m) ) ) ) ) (defun nmchange (a m n) ( nreplace (nreplace a m (nraw a n)) n (nraw a m) ) ) (defun makepair (a b) (cons a (cons b nil))) (defun pair1 (p) (car p)) (defun pair2 (p) (car (cdr p))) (defun gbcnm ( n m p ) ( gbcnmsub n m (+ m 1) p ) ) (defun gbcnmsub ( n m i p ) (cond ( (< n i) p ) ( t (gbcnmsub n m (+ i 1) (makepair (nmcsub (pair1 p) m i (nmelm (pair1 p) m i )) (nmcsub (pair2 p) m i (nmelm (pair1 p) m i )) ))))) (defun gbc ( n p ) ( gbcsub n (- n 1) p ) ) (defun gbcsub ( n i p ) (cond ( (< i 1) p ) ( t (gbcsub n (- i 1) (gbcnm n i p)) ) )) (defun nunit ( n ) (nunitsub n 1) ) (defun nunitsub ( n i ) (cond ( (< n i) nil ) ( t (cons (nunitv n i) (nunitsub n (+ i 1))) ) )) (defun nunitv (n i) (nunitvsub n i 1) ) (defun nunitvsub ( n i j ) (cond ( (< n j) nil ) ( t (cons (cond ( (= i j) 1 ) ( t 0 ) ) ( nunitvsub n i (+ j 1) ) )) )) (defun gfcnm ( n m p ) ( gfcnmsub n m 1 p ) ) (defun gfcnmsub ( n m i p ) (cond ( (<= m i) p ) ( t (gfcnmsub n m (+ i 1) (makepair (nmcsub (pair1 p) m i (nmelm (pair1 p) m i )) (nmcsub (pair2 p) m i (nmelm (pair1 p) m i )) ))))) (defun gfcnormal ( n i p ) (cond ( (zerop (nmelm (pair1 p) i i)) (gfcnormalsub n i (gfcfind n i p)) ) ( t (gfcnormalsub n i p) ) ) ) (defun gfcnormalsub ( n i p ) (cond ( (null p) nil) ( t (makepair (ncprod (pair1 p) i (/ 1 (nmelm (pair1 p) i i))) (ncprod (pair2 p) i (/ 1 (nmelm (pair1 p) i i))) ) ) ) ) (defun gfcfind (n i p) (gfcfindsub n i (+ i 1) p) ) (defun gfcfindsub (n i j p) (cond ( (< n j) nil ) ( (zerop (nmelm (pair1 p) j i ) ) (gfcfindsub n i (+ j 1) p) ) ( t (makepair (nmchange (pair1 p) i j) (nmchange (pair2 p) i j) ) ) )) (defun gfc ( n p ) ( gfcsub n 2 (gfcnormal n 1 p) ) ) (defun gfcsub ( n i p ) (cond ( (null p) nil ) ( (< n i) p ) ( t (gfcsub n (+ i 1) (gfcnormal n i (gfcnm n i p) ) ) ) )) (defun mrev ( n m ) (mrevsub n (makepair m (nunit n))) ) (defun mrevsub ( n p ) (mrevsub2 n (gfc n p) ) ) (defun mrevsub2 ( n p ) (cond ( (null p) nil ) ( t (pair2 (gbc n p)) ) ) )