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