+Learned to count
[lineal.git] / src / overload / overload.lisp
blob46cf9286dc3d61a8abe58bb11956d6ef744b180b
2 ;V Just make the package exist here, V
3 ;V define its guts later in globals.lisp V
4 (defpackage :lineal)
6 (defpackage :lineal.overload
7 (:use :cl)
8 (:export *accep-table* mtrix tuple
9 make-tuple tuple-dim tuple-elems
10 make-mtrix mtrix-dimdom mtrix-dimcodom mtrix-elems
11 over-format over-ex
12 addn subtrn multn divisn exptn)
13 (:import-from
14 :lineal.math
15 det
16 dot-prod
17 factorial
18 mtrix-addn
19 mtrix-augment
20 mtrix-coltuple-multn
21 mtrix-inverse
22 mtrix-multn
23 mtrix-mult2n
24 mtrix-square-identity
25 mtrix-subtrn
26 mtrix-transpose
27 nAr nCr nPr
28 nullspace
29 output-tuple
30 output-matrix
31 r-ef
32 rr-ef
33 scalar-mtrix-multn
34 scalar-tuple-multn
35 tuple-addn
36 tuple-cross3
37 tuple-magnitude
38 tuple-orth
39 tuple-proj
40 tuple-scalar-divisn
41 tuple-subtrn))
43 (in-package :lineal.overload)
45 ;;; Multiplicative Inverse
46 (defgeneric over-multv-inverse (a))
47 ;;; Concatenate Horizontally
48 (defgeneric cat2 (term1 term2))
49 ;;; Concatenate Vertically (or vector-wise)
50 (defgeneric vcat2 (a b))
52 (defgeneric over-crop (a b))
53 (defgeneric over-vcrop (a b))
55 (defgeneric over-transpose (a))
56 (defmethod over-transpose (a)
57 (throw 'over-ex
58 "You can only tranpose vectors and matrices."))
61 ;;; Standard operations.
62 (defgeneric add2n (a b))
63 (defgeneric subtr2n (a b))
64 (defgeneric mult2n (a b))
65 (defgeneric divis2n (a b))
66 (defgeneric expt2n (a b))
68 (defun addn (&rest elems)
69 (reduce #'add2n elems))
71 (defun subtrn (&rest elems)
72 (if (cdr elems)
73 (reduce #'subtr2n elems)
74 ;V If only one element, follow V
75 ;V lisp style by negating it. V
76 (mult2n -1 (car elems))))
78 (defun multn (&rest elems)
79 (reduce #'mult2n elems))
81 (defun divisn (&rest elems)
82 (if (cdr elems)
83 (reduce #'divis2n elems)
84 (over-multv-inverse (car elems))))
86 (defun exptn (&rest elems)
87 (reduce #'expt2n elems))