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 sprdet
)
15 ;; THIS IS THE NEW DETERMINANT PACKAGE
17 (declare-top (special ;;x
18 *ptr
* *ptc
* *blk
* ml
* *detsign
* rzl
*))
22 (setq ax
(get-array-pointer ax
))
23 (prog ((j 0) rodr codr bl det
(dm 0) (r 0) (i 0))
24 (declare (fixnum i j dm r
))
26 (setq *ptr
* (make-array (1+ n
)))
27 (setq *ptc
* (make-array (1+ n
)))
28 (setq bl
(tmlattice ax
'*ptr
* '*ptc
* n
)) ;tmlattice isn't defined anywhere -- are_muc
29 (when (null bl
) (return 0))
30 (setq rodr
(apply #'append bl
))
31 (setq codr
(mapcar #'cadr rodr
))
32 (setq rodr
(mapcar #'car rodr
))
33 (setq det
(* (prmusign rodr
) (prmusign codr
)))
34 (setq bl
(mapcar #'length bl
))
35 loop1
(when (null bl
) (return det
))
38 (setq *blk
* (make-array (list (1+ dm
) (1+ dm
))))
40 (setq det
(gptimes det
(car (aref ax
(aref *ptr
* (1+ r
)) (aref *ptc
* (1+ r
))))))
43 (setq det
(gptimes det
45 (gptimes (car (aref ax
(aref *ptr
* (1+ r
)) (aref *ptc
* (1+ r
))))
46 (car (aref ax
(aref *ptr
* (+ 2 r
)) (aref *ptc
* (+ 2 r
)))))
47 (gptimes (car (aref ax
(aref *ptr
* (1+ r
)) (aref *ptc
* (+ 2 r
))))
48 (car (aref ax
(aref *ptr
* (+ 2 r
)) (aref *ptc
* (1+ r
))))))))
50 loop2
(when (= i
0) (go cmp
))
52 loop3
(when (= j
0) (decf i
) (go loop2
))
53 (setf (aref *blk
* i j
) (car (aref ax
(aref *ptr
* (+ r i
)) (aref *ptc
*(+ r j
)))))
56 (setq det
(gptimes det
(tdbu '*blk
* dm
)))
62 (defun minorl (x n l nz
)
64 (prog (ans s rzl
* (col 1) (n2 (truncate n
2)) d dl z a elm rule
)
65 (declare (fixnum n2 col
))
67 (setq dl l l nil nz
(cons nil nz
))
68 l1
(when (null nz
) (return ans
))
70 (cond ((null l
) (if dl
(push dl ans
) (return nil
))
71 (setq nz
(cdr nz
) col
(1+ col
) l dl dl nil
)
75 (cond (rule (rplaca (car l
) (list a rule
))
76 (setq rule nil
) (setq l
(cdr l
)))
78 (rplaca (car l
) (list a
0))
80 (t (rplaca l
(cadr l
))
83 (setq elm
(car z
) z
(cdr z
))
84 (setq s
(signnp elm a
))
85 (cond (s (setq d
(delete elm
(copy-list a
) :test
#'equal
))
86 (cond ((membercar d dl
)
89 (when (or (< col n2
) (not (singp x d col n
)))
93 on
(setq rule
(cons (list d s elm
(1- col
)) rule
))
96 (declare-top (special j
))
98 (defun singp (x ml col n
)
99 (declare (fixnum col n
))
107 (cond ((member i rzl
* :test
#'equal
) (return t
))
108 ((zrow x i col n
) (return (setq rzl
*(cons i rzl
*)))))
109 loop
(cond ((> j n
) (return nil
))
110 ((every #'(lambda (i) (equal (aref x i j
) 0)) l
)
115 (declare-top (unspecial j
))
119 (prog (a ml
* nl nml dd
)
121 (setq x
(get-array-pointer x
))
123 (setq x
(get-array-pointer 'x
*))
125 (when (member nil nl
:test
#'eq
) (return 0))
126 (setq a
(minorl x n
(list (cons (nreverse(index* n
)) 1)) nl
))
128 (when (null a
) (return 0))
131 (setq ml
* (cons (cons nil nil
) (car a
)))
133 (when (null a
) (return (if (= *detsign
* 1)
135 (gpctimes -
1 (cadadr ml
*)))))
137 tag1
(when (null nml
) (go tag2
))
145 (setq ans
0 r
(cadar rule
))
146 (when (equal r
0) (return 0))
147 (rplaca rule
(caar rule
))
148 loop
(when (null r
) (return (rplacd rule
(cons ans
(cdr rule
)))))
149 (setq a
(car r
) r
(cdr r
))
150 (setq ans
(gpplus ans
(gptimes (if (= (cadr a
) 1)
151 (aref x
(caddr a
) (cadddr a
))
152 (gpctimes (cadr a
) (aref x
(caddr a
) (cadddr a
))))
153 (getminor (car a
)))))
156 (defun getminor (index)
157 (cond ((null (setq index
(assoc index ml
* :test
#'equal
))) 0)
158 (t (rplacd (cdr index
) (1- (cddr index
)))
159 (when (= (cddr index
) 0)
160 (setf index
(delete index ml
* :test
#'equal
)))
164 (declare (fixnum n
))
165 (prog ((n-1 (1- n
)) b a
)
166 (declare (fixnum n-1
))
167 loop
(when (null l
) (return nil
))
168 (setq a
(car l
) l
(cdr l
) b
(car a
))
169 (rplacd a
(cons (gpdifference (gptimes (aref x
(car b
) n-1
) (aref x
(cadr b
) n
))
170 (gptimes (aref x
(car b
) n
) (aref x
(cadr b
) n-1
)))
174 (defun zrow (x i col n
)
175 (declare (fixnum i col n
))
180 ((equal (aref x i j
) 0)
186 (prog ((i 0) (j (- n
2)) d l
)
187 (declare (fixnum i j
))
188 loop0
(when (= j
0) (return l
))
195 (when (not (equal (aref a i j
) 0))
203 loop
(cond ((null l
) (return nil
))
204 ((equal e
(car l
)) (return i
)))
205 (setq l
(cdr l
) i
(- i
))
208 (defun membercar (e l
)
213 (return (rplacd (car l
) (1+ (cdar l
))))))
217 (declare-top (unspecial ml
* rzl
*))
219 (defun atranspose (a n
)
222 loop1
(setq i
(1+ i
) j i
)
223 (when (> i n
) (return nil
))
225 (when (> j n
) (go loop1
))
226 (setq d
(aref a i j
))
227 (setf (aref a i j
) (aref a j i
))
228 (setf (aref a j i
) d
)
231 (defun mxcomp (l1 l2
)
233 loop
(cond ((null l1
) (return t
))
234 ((car> (car l1
) (car l2
)) (return t
))
235 ((car> (car l2
) (car l1
)) (return nil
)))
236 (setq l1
(cdr l1
) l2
(cdr l2
))
242 loop
(when (null l
) (return (if (even b
) 1 -
1)))
243 (setq a
(car l
) l
(cdr l
) d l
)
244 loop1
(cond ((null d
) (go loop
))
245 ((> a
(car d
)) (incf b
)))
249 (defun detpivot (x n
)
251 (setq c0
(colrow0 x n nil
)
253 (setq c0
(nreverse (bbsort c0
#'car
>)))
254 (setq r0
(nreverse (bbsort r0
#'car
>)))
255 (when (not (mxcomp c0 r0
))
258 (setq *detsign
* (prmusign (mapcar #'car c0
)))
259 (newmat 'x
* x n c0
)))
261 (defun newmat(x y n l
)
263 (setf (symbol-value x
) (make-array (list (1+ n
) (1+ n
))))
264 (setq x
(get-array-pointer x
))
266 loop
(setq i
0 j
(1+ j
))
267 (when (null l
) (return nil
))
268 (setq jl
(cdar l
) l
(cdr l
))
270 (when (> i n
) (go loop
))
271 (setf (aref x i j
) (aref y i jl
))
277 ;; ind=t for row ortherwise col
279 (defun colrow0 (a n ind
)
281 (prog ((i 0) (j n
) l
(c 0))
282 (declare (fixnum i c j
))
283 loop0
(cond ((= j
0) (return l
)))
290 (when (equal (if ind
(aref a j i
) (aref a i j
)) 0)
295 (defun gpdifference (a b
)
298 (simplus(list '(mplus) a
(list '(mtimes) -
1 b
)) 1 nil
)))
303 (simptimes(list '(mtimes) a b
) 1 nil
)))
308 (simptimes (list '(mtimes) a b
) 1 nil
)))
313 (simplus(list '(mplus) a b
) 1 nil
)))