diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-09 21:37:44 -0600 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-09 21:37:44 -0600 |
commit | e46e5eee74af75aa1123b2370ff2f4587f4adc2a (patch) | |
tree | ae793dd22176613282e41ce6d15f481c072a8a57 /src | |
parent | adda6869cb2a07984b48c39fcd70ee76449c353d (diff) | |
download | cmath-e46e5eee74af75aa1123b2370ff2f4587f4adc2a.tar.gz cmath-e46e5eee74af75aa1123b2370ff2f4587f4adc2a.zip |
flatten directory structure to appease dr koebbe
Diffstat (limited to 'src')
-rw-r--r-- | src/approx,derivative.lisp (renamed from src/approx/derivative.lisp) | 10 | ||||
-rw-r--r-- | src/approx,maceps.lisp (renamed from src/approx/maceps.lisp) | 0 | ||||
-rw-r--r-- | src/approx,package.lisp (renamed from src/approx/package.lisp) | 3 | ||||
-rw-r--r-- | src/lizfcm.asd | 32 | ||||
-rw-r--r-- | src/package.lisp | 7 | ||||
-rw-r--r-- | src/tests,approx.lisp | 48 | ||||
-rw-r--r-- | src/tests,maceps.lisp | 27 | ||||
-rw-r--r-- | src/tests,suite.lisp | 10 | ||||
-rw-r--r-- | src/tests,table.lisp | 31 | ||||
-rw-r--r-- | src/tests,vector.lisp | 31 | ||||
-rw-r--r-- | src/utils,package.lisp (renamed from src/utils/package.lisp) | 0 | ||||
-rw-r--r-- | src/utils,table.lisp (renamed from src/utils/table.lisp) | 0 | ||||
-rw-r--r-- | src/utils,within-range.lisp (renamed from src/utils/within-range.lisp) | 0 | ||||
-rw-r--r-- | src/vector,distance.lisp (renamed from src/vector/distance.lisp) | 0 | ||||
-rw-r--r-- | src/vector,norm.lisp (renamed from src/vector/norm.lisp) | 0 | ||||
-rw-r--r-- | src/vector,package.lisp (renamed from src/vector/package.lisp) | 0 |
16 files changed, 190 insertions, 9 deletions
diff --git a/src/approx/derivative.lisp b/src/approx,derivative.lisp index 8aa171a..631a5c0 100644 --- a/src/approx/derivative.lisp +++ b/src/approx,derivative.lisp @@ -8,10 +8,18 @@ (/ (- y2 y1) (- x2 x1)))) -(defun fwd-derivative-at (f x &optional (delta 0.01)) +(defun forward-derivative-at (f x &optional (delta 0.01)) (let* ((x2 (+ x delta)) (x1 x) (y2 (apply f (list x2))) (y1 (apply f (list x1)))) (/ (- y2 y1) (- x2 x1)))) + +(defun backward-derivative-at (f x &optional (delta 0.01)) + (let* ((x2 x) + (x1 (- x delta)) + (y2 (apply f (list x2))) + (y1 (apply f (list x1)))) + (/ (- y2 y1) + (- x2 x1)))) diff --git a/src/approx/maceps.lisp b/src/approx,maceps.lisp index e2738e4..e2738e4 100644 --- a/src/approx/maceps.lisp +++ b/src/approx,maceps.lisp diff --git a/src/approx/package.lisp b/src/approx,package.lisp index 67c6a90..a0eac80 100644 --- a/src/approx/package.lisp +++ b/src/approx,package.lisp @@ -2,5 +2,6 @@ (defpackage lizfcm.approx (:use :cl) (:export :central-derivative-at - :fwd-derivative-at + :forward-derivative-at + :backward-derivative-at :compute-maceps)) diff --git a/src/lizfcm.asd b/src/lizfcm.asd new file mode 100644 index 0000000..ee8beb0 --- /dev/null +++ b/src/lizfcm.asd @@ -0,0 +1,32 @@ +(asdf:defsystem "lizfcm" + :version "0.1.0" + :author "Elizabeth Hunt" + :license "MIT" + :components + ((:file "utils,within-range" :depends-on ("utils,package")) + (:file "utils,table" :depends-on ("utils,package")) + (:file "utils,package") + (:file "approx,maceps" :depends-on ("approx,package")) + (:file "approx,derivative" :depends-on ("approx,package")) + (:file "approx,package") + (:file "vector,distance" :depends-on ("vector,norm" "vector,package")) + (:file "vector,norm" :depends-on ("vector,package")) + (:file "vector,package"))) + + +(asdf:defsystem "lizfcm/tests" + :author "Elizabeth Hunt" + :license "MIT" + :depends-on + (:fiveam + :lizfcm) + :components + ((:file "tests,table" :depends-on ("tests,suite")) + (:file "tests,maceps" :depends-on ("tests,suite")) + (:file "tests,approx" :depends-on ("tests,suite")) + (:file "tests,vector" :depends-on ("tests,suite")) + (:file "tests,suite")) + :perform + (asdf:test-op (o c) (uiop:symbol-call + :fiveam :run! + (uiop:find-symbol* :lizfcm-test-suite :lizfcm/tests)))) diff --git a/src/package.lisp b/src/package.lisp deleted file mode 100644 index 88b10eb..0000000 --- a/src/package.lisp +++ /dev/null @@ -1,7 +0,0 @@ -(in-package :cl-user) -(defpackage lizfcm.vector - (:use :cl) - (:export - :n-norm - :max-norm - :distance)) diff --git a/src/tests,approx.lisp b/src/tests,approx.lisp new file mode 100644 index 0000000..678ff8c --- /dev/null +++ b/src/tests,approx.lisp @@ -0,0 +1,48 @@ +(defpackage lizfcm/tests.approx + (:use :cl + :fiveam + :lizfcm.approx + :lizfcm.utils + :lizfcm/tests) + (:export :approx-suite)) +(in-package :lizfcm/tests.approx) + +(def-suite approx-suite + :in lizfcm-test-suite) +(in-suite approx-suite) + +(test central-derivative-at + :description "derivative at is within bounds" + (let ((f (lambda (x) (* x x))) + (x 2) + (accepted-delta 0.02) + (f-prime-at-x 4) + (delta 0.01)) + (is (within-range-p + (central-derivative-at f x delta) + f-prime-at-x + accepted-delta)))) + +(test fwd-derivative-at + :description "forward derivative at is within bounds" + (let ((f (lambda (x) (* x x))) + (x 2) + (accepted-delta 0.02) + (f-prime-at-x 4) + (delta 0.01)) + (is (within-range-p + (forward-derivative-at f x delta) + f-prime-at-x + accepted-delta)))) + +(test bwd-derivative-at + :description "backward derivative at is within bounds" + (let ((f (lambda (x) (* x x))) + (x 2) + (accepted-delta 0.02) + (f-prime-at-x 4) + (delta 0.01)) + (is (within-range-p + (backward-derivative-at f x delta) + f-prime-at-x + accepted-delta)))) diff --git a/src/tests,maceps.lisp b/src/tests,maceps.lisp new file mode 100644 index 0000000..cd5ced9 --- /dev/null +++ b/src/tests,maceps.lisp @@ -0,0 +1,27 @@ +(defpackage lizfcm/tests.maceps + (:use :cl + :fiveam + :lizfcm.approx + :lizfcm.utils + :lizfcm/tests) + (:export :approx-suite)) +(in-package :lizfcm/tests.maceps) + +(def-suite maceps-suite + :in lizfcm-test-suite) +(in-suite maceps-suite) + +(test maceps + :description "double precision provides precision about (mac eps of single precision) squared" + (let* ((maceps-computation-double (compute-maceps (lambda (x) x) + 1.0d0 + 1.0d0)) + (maceps-computation-single (compute-maceps (lambda (x) x) + 1.0 + 1.0)) + (last-double-h (cadar (last maceps-computation-double))) + (last-single-h (cadar (last maceps-computation-single)))) + (is (within-range-p + (- last-double-h (* last-single-h last-single-h)) + 0 + last-single-h)))) diff --git a/src/tests,suite.lisp b/src/tests,suite.lisp new file mode 100644 index 0000000..e23cfaf --- /dev/null +++ b/src/tests,suite.lisp @@ -0,0 +1,10 @@ +(in-package :cl-user) +(defpackage lizfcm/tests + (:use :cl + :fiveam) + (:export :run! + :lizfcm-test-suite)) +(in-package :lizfcm/tests) + +(def-suite lizfcm-test-suite + :description "The ultimate parent test suite") diff --git a/src/tests,table.lisp b/src/tests,table.lisp new file mode 100644 index 0000000..33d4e86 --- /dev/null +++ b/src/tests,table.lisp @@ -0,0 +1,31 @@ +(defpackage lizfcm/tests.table + (:use :cl + :fiveam + :lizfcm.utils + :lizfcm/tests) + (:export :approx-suite)) +(in-package :lizfcm/tests.table) + +(def-suite table-suite + :in lizfcm-test-suite) +(in-suite table-suite) + +(defun fib (n) + (cond ((< n 2) n) + (t (+ (fib (- n 1)) (fib (- n 2)))))) + +(test table-of-fib-vals + :description "table generates correctly" + (let* ((headers '("n" "fib(n)")) + (n-values '((1) (2) (3) (4))) + (expected `(("n" "fib(n)") + (1 ,(fib 1)) + (2 ,(fib 2)) + (3 ,(fib 3)) + (4 ,(fib 4)))) + (tabled (lizfcm.utils:table (:headers headers + :domain-order (n) + :domain-values n-values) + (fib n)))) + (is (equal expected tabled)))) + diff --git a/src/tests,vector.lisp b/src/tests,vector.lisp new file mode 100644 index 0000000..3ffe5a8 --- /dev/null +++ b/src/tests,vector.lisp @@ -0,0 +1,31 @@ +(defpackage lizfcm/tests.vector + (:use :cl + :fiveam + :lizfcm.vector + :lizfcm.utils + :lizfcm/tests) + (:export :vector-suite)) +(in-package :lizfcm/tests.vector) + +(def-suite vector-suite + :in lizfcm-test-suite) +(in-suite vector-suite) + +(test p-norm + :description "computes p-norm" + (let ((v '(1 1)) + (length (sqrt 2)) + (2-norm (p-norm 2))) + (is (within-range-p (funcall 2-norm v) + length + 0.00001)))) + +(test vector-distance + :description "computes distance via norm" + (let ((v1 '(0 0)) + (v2 '(1 1)) + (dist (sqrt 2))) + (is (within-range-p (distance v1 v2 (p-norm 2)) + dist + 0.00001)))) + diff --git a/src/utils/package.lisp b/src/utils,package.lisp index bdd5589..bdd5589 100644 --- a/src/utils/package.lisp +++ b/src/utils,package.lisp diff --git a/src/utils/table.lisp b/src/utils,table.lisp index e96f37b..e96f37b 100644 --- a/src/utils/table.lisp +++ b/src/utils,table.lisp diff --git a/src/utils/within-range.lisp b/src/utils,within-range.lisp index 9a0b762..9a0b762 100644 --- a/src/utils/within-range.lisp +++ b/src/utils,within-range.lisp diff --git a/src/vector/distance.lisp b/src/vector,distance.lisp index 74631ce..74631ce 100644 --- a/src/vector/distance.lisp +++ b/src/vector,distance.lisp diff --git a/src/vector/norm.lisp b/src/vector,norm.lisp index aa51bce..aa51bce 100644 --- a/src/vector/norm.lisp +++ b/src/vector,norm.lisp diff --git a/src/vector/package.lisp b/src/vector,package.lisp index 009b190..009b190 100644 --- a/src/vector/package.lisp +++ b/src/vector,package.lisp |