!<arch>
#1/20           1696909081  501   20    100644  28        `
__.SYMDEF SORTED            #1/28           1696908991  501   20    100644  692       `
approx,derivative.lisp      (in-package :lizfcm.approx)

(defun central-derivative-at (f x &optional (delta 0.01))
  (let* ((x2 (+ x delta))
         (x1 (- x delta))
         (y2 (apply f (list x2)))
         (y1 (apply f (list x1))))
    (/ (- y2 y1)
       (- x2 x1))))

(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))))




#1/28           1696908123  501   20    100644  324       `
approx,maceps.lisp          (in-package :lizfcm.approx)

(defun compute-maceps (f a init)
  (let ((h init)
        (err init))
    (loop collect (list a h err)
          do
          (setf h (/ h 2)
                err (abs (- (funcall f (+ a h))
                            (funcall f a))))
          while (> err 0))))



#1/28           1696908999  501   20    100644  228       `
approx,package.lisp         (in-package :cl-user)
(defpackage lizfcm.approx
  (:use :cl)
  (:export :central-derivative-at
           :forward-derivative-at
           :backward-derivative-at
           :compute-maceps))







#1/20           1696908701  501   20    100644  1508      `
lizfcm.asd          (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))))



#1/28           1696908986  501   20    100644  1396      `
tests,approx.lisp           (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))))



#1/28           1696908124  501   20    100644  1092      `
tests,maceps.lisp           (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))))






#1/20           1696908124  501   20    100644  260       `
tests,suite.lisp    (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")







#1/20           1696908124  501   20    100644  996       `
tests,table.lisp    (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))))






#1/28           1696908124  501   20    100644  844       `
tests,vector.lisp           (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))))








#1/28           1696908123  501   20    100644  140       `
utils,package.lisp          (in-package :cl-user)
(defpackage lizfcm.utils
  (:use :cl)
  (:export :within-range-p
           :table))





#1/20           1696908123  501   20    100644  364       `
utils,table.lisp    (in-package :lizfcm.utils)

(defmacro table ((&key headers domain-order domain-values) &body body)
  `(cons
     ,headers
     (mapcar (lambda (tuple)
               (destructuring-bind ,domain-order tuple
                 (append tuple
                         (list
                           ,@body))))
             ,domain-values)))







#1/28           1696908124  501   20    100644  172       `
utils,within-range.lisp     (in-package :lizfcm.utils)

(defun within-range-p (x true-value delta)
  (and (< x (+ true-value delta))
       (> x (- true-value delta))))



#1/28           1696908124  501   20    100644  172       `
vector,distance.lisp        (in-package :lizfcm.vector)

(defun distance (v1 v2 norm)
  (let* ((d (mapcar #'- v1 v2))
         (length (funcall norm d)))
    length))





#1/20           1696908124  501   20    100644  300       `
vector,norm.lisp    (in-package :lizfcm.vector)

(defun p-norm (p)
  (lambda (v)
    (expt
      (reduce #'+
              (mapcar (lambda (x)
                        (abs
                          (expt x p)))
                      v))
      (/ 1 p))))

(defun max-norm (v)
  (reduce #'max v))





#1/28           1696908124  501   20    100644  148       `
vector,package.lisp         (in-package :cl-user)
(defpackage lizfcm.vector
  (:use :cl)
  (:export
    :p-norm
    :max-norm
    :distance))






