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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13 (macsyma-module algfac
)
15 ;; this is the alg factor package
17 ;;; Toplevel functions are: CPBGZASS CPTOM
19 (load-macsyma-macros ratmac
)
21 (declare-top (special tra
* trl
* *xn var intbs
* plim many
* split
* alc ind p l
))
24 (let ((modulus nil
) (*alpha
* nil
) (minpoly* nil
) (algfac* nil
)
25 (gauss nil
) (tellratlist nil
) (many* nil
)
28 (null (cddr(pfactor p
)))))
33 (setq p
(pctimes intbs
* p
))
35 (return (car (ratreduce p intbs
*)))))
39 (setq mainvar
(car p
))
40 (setq p
(redresult p
(pderivative p mainvar
)))
43 loop
(when (null p
) (return mainvar
))
44 (setq mainvar
(* mainvar
(expt (car p
) (quotient (cadr p
) 2))))
49 (defun cpbgzass (qlist v m
)
50 (prog (f y vj factors u w lc j p2 fnj fnq oldfac
)
54 (return (let ((var (list var
1 1)))
60 qlist
(cdr (nreverse qlist
)))
61 (setq oldfac
(list nil f
))
62 nextq
(setq v
(car qlist
))
63 (setq qlist
(cdr qlist
))
64 (setq j
(findses v f
))
65 (setq oldfac
(nconc oldfac fnq
))
67 incrj
(setq factors
(nconc oldfac fnj
))
69 (setq vj
(pplus v
(car j
))
71 tag2
(setq u
(cadr factors
))
73 (when (or (numberp w
) (and *alpha
* (alg w
))(= (cadr u
) (cadr w
)))
75 (setq y
(car (pmodquo u w
)))
76 (setq fnq
(cons w fnq
))
77 (setq fnj
(cons y fnj
))
79 (rplacd factors
(cddr factors
))
84 (setq factors
(cdr factors
))
85 tag1
(cond ((cdr factors
)
89 out
(setq fnq
(nconc fnq fnj
(cdr oldfac
)))
90 (return (cons (ptimes lc
(car fnq
)) (cdr fnq
)))))
93 ;; The function PMONZ used to be defined here. It is also defined in
94 ;; RAT;RAT3A and BMT claims the definitions are equivalent.
98 (setq g
(zassg (cdr g
) (cdr f
) (car g
)))
99 (setq var
(list (car f
) 1 1))
101 (return (mapcar #'(lambda (a) (car (last a
))) f
))))
103 (defun coefvec (p n vec
)
105 loop
(when (zerop n
) (return vec
))
107 (push (ptterm p n
) vec
)
110 (defun zassg (g f var
)
111 (prog (i mat gn ans n
)
115 mat
(list (coefvec '(0 1) n
(list 1))))
118 (setq gn
(pgcd1 (ptimes1 gn g
) f
))
119 on
(setq ans
(lindep mat
(coefvec gn n
(list (list var i
1)))))
120 (cond (ans (return ans
)))
124 (mapcar #'(lambda (l) (car (pmodquo l a
))) j
))
126 ;; (DEFUN PADDROWS (A B) (MAPCAR (FUNCTION PPLUS) A B))
128 (defun pdifrows (a b
)
129 (mapcar #'pdifference a b
))
131 (defun ptimesrow (var row
)
132 (mapcar #'(lambda (a) (ptimes var a
)) row
))
141 (return (divl j a
))))
143 (defun lindep (mat vec
)
144 (prog (e d m row rowd vecd
)
146 (cond ((equal 0.
(car vec
)) (setq vec
(cdr vec
)))
147 (t (setq vec
(pdifrows (cdr vec
) (ptimesrow (car vec
) (cdar mat
))))))
148 loop
(cond ((null (cdr m
))
149 (cond ((zerolp (cdr (reverse vec
)))
150 (return (car (last vec
))))
151 (t (rplacd m
(cons (ddiv vec
) (cdr m
)))
154 (setq rowd row vecd vec
)
155 loop1
(setq d
(car rowd
))
159 (setq vecd
(cdr vecd
) rowd
(cdr rowd
))
161 (t (setq vec
(cdr vec
)) (setq m
(cdr m
)) (go loop
))))
164 (cons (divl vec e
) (mapcar (function cdr
) (cdr m
))))
166 (setq vec
(pdifrows (cdr vec
) (ptimesrow e
(cdr row
))))
171 (prog (tr fl
(n 0) ans tra
* (i 0) nfl
)
172 (setq fl
(list f
) n
(cadr f
))
173 loop
(cond ((null fl
)
175 (cond ((= n
(length ans
))
178 (t (merror (intl:gettext
"GFSPLIT: unknown error.")))))
186 (merror (intl:gettext
"GFSPLIT: unknown error."))))
187 (setq tr
(tracemod0 f i
))
188 (cond ((or (pcoefp tr
) (and algfac
* (alg tr
)))
189 (setq nfl
(cons f nfl
))
191 (setq f
(cpbg0 tr f
))
192 (setq ans
(nconc ans
(car f
)))
193 (when (null (cdr f
)) (go loop
))
194 (setq nfl
(nconc nfl
(cdr f
)))
198 (prog (m f1 f2 g alc trm
)
200 (cond ((and (not (numberp (caddr tr
))) (alg (caddr tr
)))
201 (setq alc
(painvmod (caddr tr
)) tr
(ptimes alc tr
)))
204 (return (cond ((and (null f1
) (null f2
))
205 ;; NOTE TO TRANSLATORS: MEANING OF NEXT MESSAGE IS OBSCURE
206 (merror (intl:gettext
"CPBG0: wrong trace.")))
210 (return (cons (cons f f1
) f2
)))
212 (return (cons f1
(cons f f2
)))))
213 (setq trm
(pdifference tr
(ptimes m alc
)))
214 (setq g
(pgcdu trm f
))
215 (cond ((or (numberp g
) (and *alpha
* (alg g
)))
218 (setq f
(car (pmodquo f g
)))
219 (cond ((equal (cadr g
) 1) (setq f1
(cons g f1
)))
220 (t (setq f2
(cons g f2
))))
223 (defun cpol2p (p var
)
225 (setq p
(nreverse p
))
226 loop
(cond ((null p
) (return (cons var ans
)))
227 ((equal 0 (car p
)) nil
)
228 (t (setq ans
(cons i
(cons (car p
) ans
)))))
234 (prog (ans tr qlarge term
)
238 (cond ((and (atom (caar tr
)) (not (numberp (caar tr
))))
240 loop
(when (null tr
) (return ans
))
241 (setq term
(if qlarge
245 (setq ans
(pplus ans term
))
246 (setq trl
* (cons term trl
*))
249 (defun otracemod (term q m prime
)
254 loop
(when (equal i m
) (return ans
))
255 (setq ans
(pplus ans
(setq term
(pexptmod term prime q
))))
256 (setq trl
* (cons term trl
*))
260 (defun tracemod0 (q i
)
262 (cond ((= i
0) (return (if trl
*
264 (otracemod var q mm
* modulus
))))
266 trl
* (mapcar #'(lambda(x)
267 (cons (car x
) (pgcd1 (cdr x
) (cdr q
)))) trl
*))))
268 (cond (tra* (go tag
))
269 (t (setq l
(cdr trl
*)
272 loop
(when (null l
) (go tag
))
278 (setq ans
(tracemod1 i tra
* trl
*))
279 (when dl
(setq trl
* dl
))
282 (defun tracemod1 (n a l
)
285 loop
(when (null l
) (return ans
))
286 (setq ans
(pplus ans
(ptimes (pexpt (car a
) n
) (car l
))))
291 ;; The way arrays are manipulated has been changed to make this code reentrant.
292 ;; Previously, arrays were kept on the array properties of symbols. Now, the
293 ;; symbols are bound to the arrays, so they can be rebound on re-entry.
294 ;; The ANOTYPE, INVC, and FCTC arrays are set up in RAT;FACTOR.
296 (declare-top (special anotype invc fctc
))
298 (defmacro a
(row col
)
299 `(aref anotype
,row
,col
))
307 (defun cptomexp (p m u n
)
308 (prog (b1 b2 j n-1 i l
)
309 (setq b1
(x**q1
(list (car u
) 1 1) u m p
))
310 (cond ((equal (cdr b1
) '(1 1))
313 (setq b2 b1 j
1 n-1
(1- n
))
316 (when (= j n
) (return nil
))
317 (setq b1
(pmodrem(ptimes b1 b2
) u
))
318 tag1
(setq l
(p2cpol b1 n-1
) i n-1
)
319 sharp2
(when (null l
) (go on
))
320 (setf (a j i
) (car l
))
324 on
(setf (a j j
) (pdifference (a j j
) 1))
329 (defun cptom (p m u n
)
330 (prog (( q
(expt p m
)) l s
*xn
(j 0) (i 0) ind n-1
)
331 (declare (special q i j
))
333 (when (> q thr
*) (return (cptomexp p m u n
)))
335 (cond ((= j n
) (return nil
))
338 (setq *xn
(mapcar #'pminus
(p2cpol (cddr u
) n-1
))
339 s
(x**q
(p2cpol(list var
1 1) n-1
) p m
)
343 st
(cond ((and (= j
1)
344 (equal '(1 0) (last s
2))
345 (= 1 (length (delete 0 (copy-tree s
) :test
#'equal
))))
346 (return (setq split
* t
))))
349 sharp2
(when (null l
) (go on
))
350 (setf (a j i
) (car l
))
354 on
(setf (a j j
) (pdifference (a j j
) 1))
357 (defun cptimesxa (p i
)
359 ag
(when (= i
0) (return p
))
364 (rplaca q
(pplus (cadr q
) (ptimes lc
(car xn
))))
365 (setq q
(cdr q
) xn
(cdr xn
)))
366 (t (rplaca q
(ptimes lc
(car xn
)))
372 (prog ((i 1) (pp 1) (d 0))
373 (setq i
1 trl
* (list x
) pp
1)
374 loop
(when (= i m
) (return (cptimesxa x
(- (* pp p
) pp
))))
376 (cptimesxa x
(- (setq pp
(* pp p
)) d
))
377 (setq trl
* (cons (copy-tree x
) trl
*))
382 (prog (nullsp (sub1n (1- n
)) mone
(k 1) (j 0) (s 0) nullv
(i 0) vj m aks
)
383 (setq mone
(cmod -
1))
384 sharp
(when (> i sub1n
) (go on
))
389 on
(setq k
1 nullsp
(list 1))
390 n2
(when (> k sub1n
) (return nullsp
))
392 n3a
(cond ((> j sub1n
) (go null
))
393 ((or (equal (a k j
) 0) (> (fctc j
) -
1))
399 (setq m
(ptimes mone
(painvmod m
)))
401 sharp1
(when (> s sub1n
) (go on1
))
402 (setf (a s j
) (ptimes m
(a s j
)))
407 sharp2
(when (> s sub1n
) (go nextk
))
412 sharp3
(when (> i sub1n
) (return nil
))
413 (setf (a i s
) (pplus (a i s
) (ptimes (a i j
) aks
)))
418 null
(setq nullv nil
)
420 sharp4
(cond ((> s sub1n
) (go on4
))
421 ((= s k
) (setq nullv
(cons s
(cons 1 nullv
))))
423 (setq vj
(a k
(invc s
)))
424 (cond ((equal vj
0) nil
)
425 (t (setq nullv
(cons s
(cons vj nullv
)))))))
428 on4
(cond ((equal (car nullv
) 0) (setq nullv
(cadr nullv
)))
429 ((setq nullv
(cons var nullv
))))
430 (setq nullsp
(cons nullv nullsp
))