1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancements. ;;;;;
5 ;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
6 ;;; All rights reserved ;;;;;
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; (c) Copyright 1980 Massachusetts Institute of Technology ;;;
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12 (macsyma-module ufact
)
14 (load-macsyma-macros ratmac rzmac
)
16 ;; Dense Polynomial Representation
22 ((< e
0) (cons n
(nreverse l
)))
23 (cond ((equal e
(car p
))
29 (cond ((zerop (car l
)) (cadr l
))
30 ((do ((l (nreverse (cdr l
)) (cdr l
))
35 (setq ll
(cons n
(cons (car l
) ll
))))))))
37 ;; not currently called
39 ;; (COND ((OR (PCOEFP P) (PCOEFP Q)) 1)
41 ;; (merror "Illegal CALL TO PGCDU"))
42 ;; ((> (CADR P) (CADR Q))
43 ;; (PSIMP (CAR P) (DPDISREP (DPGCD (DPREP (CDR P)) (DPREP (CDR Q))))))
44 ;; ((PSIMP (CAR P) (DPDISREP (DPGCD (DPREP (CDR Q)) (DPREP (CDR P))))))))
46 ;;(DEFUN PMODSQFRU (P)
47 ;; (DO ((DPL (DPSQFR (DPREP (CDR P))) (CDR DPL))
48 ;; (PL NIL (CONS (PSIMP (CAR P) (DPDISREP (CDAR DPL))) (CONS (CAAR DPL) PL))))
52 (if (< (car p
) (car q
)) (rotatef p q
))
53 (do ((p (copy-list p
) q
)
54 (q (copy-list q
) (dpremquo p q nil
)))
56 (if (= (cadr q
) 0) p
'(0 1)))))
59 (cond ((> (car p
) (car q
))
60 (do ((i (car p
) (f1- i
))
62 (l nil
(cons (car pl
) l
)))
63 ((= i
(car q
)) (dpdif1 pl
(cdr q
) l
)) ))
65 (do ((i (car q
) (f1- i
))
67 (l nil
(cons (cminus (car ql
)) l
)))
68 ((= i
(car p
)) (dpdif1 (cdr p
) ql l
))))
69 (t (dpdif1 (cdr p
) (cdr q
) nil
))))
71 (defun dpdif1 (p1 q1 l
)
74 (ll l
(cons (cdifference (car pl
) (car ql
)) ll
)))
75 ((null pl
) (dpsimp (nreverse ll
)))))
77 (defun dpsimp (pl) (setq pl
(ufact-strip-zeroes pl
))
78 (cond ((null pl
) '(0 0))
79 (t (cons (f1- (length pl
)) pl
))))
82 (cond ((= 0 (car p
)) '(0 0))
83 (t (do ((l (cdr p
) (cdr l
))
85 (dp nil
(cons (ctimes i
(car l
)) dp
)))
86 ((= i
0) (cons (f1- (car p
)) (nreverse dp
)))))))
88 (defun dpsqfr (q) ;ASSUMES MOD > DEGREE
89 (do ((c q
(dpmodquo c p
))
90 (d (dpderiv q
) (dpmodquo d p
))
95 (cond (p (setq d
(dpdif d
(dpderiv c
))
98 (setq pl
(cons (cons i p
) pl
))))
99 (t (setq p
(dpgcd c d
))
100 (cond ((= (car p
) 0) (return (ncons (cons 1 c
)))))))))
104 (defun dpmodrem (p q
)
105 (cond ((< (car p
) (car q
)) p
)
106 ((= (car q
) 0) '(0 0))
107 ((dpremquo (copy-list p
) (copy-list q
) nil
))))
109 (defun dpmodquo (p q
)
110 (cond ((< (car p
) (car q
)) '(0 0))
112 (cond ((equal (cadr q
) 1) p
)
114 (mapcar #'(lambda (c) (cquotient c
(cadr q
))) (cdr p
))
116 ((dpremquo (copy-list p
) (copy-list q
) t
))))
118 ;; If FLAG is T, return quotient. Otherwise return remainder.
120 (defun dpremquo (p q flag
)
121 (prog (lp lq l alpha
)
122 (cond ((= (cadr q
) 1)
124 (t (setq alpha
(crecip (cadr q
)))
125 (do ((l (cddr q
) (cdr l
)))
128 (rplaca l
(ctimes (car l
) alpha
)))))
129 a
(and flag
(setq l
(cons (ctimes (cadr p
) alpha
) l
)))
130 (setq lp
(cddr p
) lq
(cddr q
))
131 b
(rplaca lp
(cdifference (car lp
) (ctimes (car lq
) (cadr p
))))
132 (cond ((null (setq lq
(cdr lq
)))
133 (do ((e (f1- (car p
)) (f1- e
))
134 (pp (cddr p
) (cdr pp
)))
135 ((null pp
) (setq p
'(0 0)))
136 (cond ((signp e
(car pp
))
137 (and flag
(not (< e
(car q
)))
138 (setq l
(cons 0 l
))))
139 ((return (setq p
(cons e pp
))))))
140 (cond ((< (car p
) (car q
))
141 (return (cond (flag (dpsimp (nreverse l
)));GET EXP?
144 (t (setq lp
(cdr lp
))
147 (defun ufact-strip-zeroes (l)
149 ((null (pzerop (car l
))) l
)))
152 (prog (res (v 0) a3
) (declare (fixnum v
))
153 (setq a
(dprep a
) b
(dprep b
))
155 again
(setq a3
(dpmodrem a b
))
156 (setq v
(boole boole-xor v
(logand 1 (car a
) (car b
) )))
157 (setq res
(ctimes res
(cexpt (cadr b
)
158 (f- (car a
) (car a3
)))))
159 (cond ((= 0 (car a3
))
160 (setq res
(ctimes res
(cexpt (cadr a3
) (car b
))))
161 (return (cond ((oddp v
) (cminus res
))