+Most files' packages determined in src/devvars
[lineal.git] / src / overload / row-operns.lisp
blob2e2f8bc3f41460a305edd04db15ee873f851bb24
2 (defun over-det (a)
3 (if (= (mtrix-dimdom a) (mtrix-dimcodom a))
4 (det (mtrix-elems a))
5 (throw 'over-ex "Determinants only work with square matrices.")))
7 (defun over-r-ef (&rest args)
8 (let ((a (apply #'over-cat args)))
9 (make-mtrix-like
10 a (r-ef (mtrix-elems a)))))
12 (defun over-rr-ef (&rest args)
13 (let ((a (apply #'over-cat args)))
14 (make-mtrix-like
15 a (rr-ef (mtrix-elems a)))))
17 (defmethod over-multv-inverse ((a mtrix))
18 (when (zerop (over-det a))
19 (throw 'over-ex "Determinant is zero, no inverse exists."))
20 (make-mtrix-like
21 a (mtrix-inverse (mtrix-elems a))))
23 ;V Raise matrix /a/ to exponent /b/.V
24 (defmethod expt2n ((a mtrix) (b integer))
25 ;V Matrix must be square.V
26 (unless (= (mtrix-dimdom a)
27 (mtrix-dimcodom a))
28 (throw 'over-ex "Only square matrices can be raised to exponents."))
29 ;V If negative power, raise inverse V
30 ;V of /a/ to negative /b/ power. V
31 (when (minusp b)
32 (setq a (over-multv-inverse a)
33 b (- b)))
34 ;V When /b/ is zero, return the identity matrix.V
35 (if (zerop b)
36 (make-mtrix
37 :dimdom (mtrix-dimdom a)
38 :dimcodom (mtrix-dimdom a)
39 :elems (mtrix-square-identity (mtrix-dimdom a)))
40 (loop :repeat b
41 :for c = a :then (mult2n a c)
42 :finally (return c))))