1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancments. ;;;;;
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 newdet
)
15 ;; THIS IS A VERSION OF THE GENTLEMAN-JOHNSON TREE-MINOR DETERMINANT
16 ;; USING RATIONAL FUNCTIONS. "A" CAN BE A MATRIX OR AN ARRAY.
17 ;; ANSWER IS IN RATIONAL FORM.
20 (declare-top (special vlist varlist genvar aryp
))
22 ;;these are general type arrays
29 (defmfun $newdet
(mat)
30 (cond ((not (or (mbagp mat
) ($matrixp mat
)))
31 (if ($scalarp mat
) mat
(list '(%newdet simp
) mat
)))
33 (setq mat
(check mat
))
34 (unless (= (length mat
) (length (cadr mat
)))
37 "newdet: Matrix must be square; found ~M rows, ~M columns.")
39 (length (cdadr mat
))))
40 (newdet mat
(length (cdr mat
)) nil
))))
42 (defmfun $permanent
(mat)
43 (cond ((not (or (mbagp mat
) ($matrixp mat
)))
44 (if ($scalarp mat
) mat
(list '(%permanent simp
) mat
)))
46 (setq mat
(check mat
))
47 (unless (= (length mat
) (length (cadr mat
)))
50 "permanent: Matrix must be square; found ~M rows, ~M columns.")
52 (length (cdadr mat
))))
53 (newdet mat
(length (cdr mat
)) t
))))
55 (defun newdet (a n perm
)
56 (prog (rr k j old new vlist m loc addr sign
)
58 (merror (intl:gettext
"newdet: matrix must be 50 by 50 or smaller; found size: ~M") n
))
59 (setq *binom
* (make-array (list (1+ n
) (1+ n
)) :element-type
'integer
))
60 (setq *minor1
* (make-array (list 2 (1+ (setq rr
(pascal n
))))))
61 (setq *i
* (make-array (+ 2 n
)))
66 (setf (aref *minor1
* k j
) '(0 .
1))))
69 (setf (aref *i
* k
) -
1))
70 (setq *input
* (make-array (list (1+ n
) (1+ n
))))
75 (newvar1 (setf (aref *input
* k j
) (let ((aryp t
)) (maref a k j
))))))
76 (newvar (cons '(mtimes) vlist
))
81 (setf (aref *input
* k j
) (cdr (ratrep* (aref *input
* k j
))))))
85 (do ((loc 1 (1+ loc
)))
87 (setf (aref *minor1
* old
(1- loc
)) (aref *input
* 1 loc
)))
89 g0193
(when (> m
(1- n
)) (go ret
))
92 g0189
(when (> j m
) (go nextminor
))
93 (setf (aref *i
* j
) (- m j
))
97 (cond ((not (equal (aref *minor1
* old loc
) '(0 .
1)))
100 (setq addr
(+ loc
(aref *binom
* k
(1+ m
))))
105 ((equal k
(aref *i
* (1+ j
)))
107 (setq sign
(- sign
)))
109 (setf (aref *minor1
* new addr
)
111 (aref *minor1
* new addr
)
112 (rattimes (aref *minor1
* old loc
)
113 (cond ((or (= sign
1) perm
)
114 (aref *input
* (1+ m
) (1+ k
)))
115 (t (ratminus (aref *input
* (1+ m
) (1+ k
)))))
119 (decf addr
(aref *binom
* k
(- m j
)))
121 (setf (aref *minor1
* old loc
) '(0 .
1))
129 (setf (aref *i
* j
) (1+ (aref *i
* j
)))
130 (if (> (aref *i
* (1- j
)) (aref *i
* j
))
132 (setf (aref *i
* j
) (- m j
)))
137 (return (cons (list 'mrat
'simp varlist genvar
) (aref *minor1
* old
0)))))
140 (setf (aref *binom
* 0 0) 1)
142 ((> h n
) (1- (aref *binom
* n
(ash n -
1))))
143 (setf (aref *binom
* h
0) 1)
144 (setf (aref *binom
* (1- h
) h
) 0)
147 (setf (aref *binom
* h j
) (+ (aref *binom
* (1- h
) (1- j
)) (aref *binom
* (1- h
) j
))))))