((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/linear-algebra" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg" "math") (toc) (p "This page is maintained in the package's " (link "https://github.com/abarbu/linear-algebra" "github repository") ".")) (section 2 "linear-algebra" (p "This implements various linear algebra and other math operations. Much of this code is originally from Jeff Siskind's QobiScheme.") (section 3 "Line segments" (def (sig (record "(define-structure line-segment p q)" (id define-structure)) (procedure "(p l)" (id p)) (procedure "(q l)" (id q)) (procedure "(collinear? l1 l2)" (id collinear?)) (procedure "(point-on-line-segment? r l)" (id point-on-line-segment?)) (procedure "(intersection-point l1 l2)" (id intersection-point)) (procedure "(cross? l1 l2)" (id cross?)) (procedure "(intersect? l1 l2)" (id intersect?)) (procedure "(line-tangent l)" (id line-tangent)) (procedure "(normal-2d l)" (id normal-2d)) (procedure "(line-segment-length l)" (id line-segment-length)) (procedure "(read-line-segments-from-file pathname)" (id read-line-segments-from-file)) (procedure "(write-line-segments-to-file line-segments pathname)" (id write-line-segments-to-file))))) (section 3 "Vectors" (def (sig (procedure "(x v)" (id x)) (procedure "(y v)" (id y)) (procedure "(z v)" (id z)) (procedure "(dot u v)" (id dot)) (procedure "(cross-2d u v)" (id cross-2d)) (procedure "(cross u v)" (id cross)) (procedure "(v+ u v)" (id v+)) (procedure "(v- u v)" (id v-)) (procedure "(k*v k v)" (id k*v)) (procedure "(v*k v k)" (id v*k)) (procedure "(k+v k v)" (id k+v)) (procedure "(v+k v k)" (id v+k)) (procedure "(v/k v k)" (id v/k)) (procedure "(v* u v)" (id v*)) (procedure "(v/ u v)" (id v/)) (procedure "(v= u v)" (id v=)) (procedure "(rotate-90 u)" (id rotate-90)) (procedure "(rotate-180 u)" (id rotate-180)) (procedure "(rotate-270 u)" (id rotate-270)) (procedure "(perpendicular? u v)" (id perpendicular?)) (procedure "(parallel? u v)" (id parallel?)) (procedure "(magnitude-squared v)" (id magnitude-squared)) (procedure "(magnitude v)" (id magnitude)) (procedure "(unit v)" (id unit)) (procedure "(distance-squared u v)" (id distance-squared)) (procedure "(distance u v)" (id distance)) (procedure "(clockwise-angle? u v w)" (id clockwise-angle?)) (procedure "(clockwise-or-same-angle? u v w)" (id clockwise-or-same-angle?)) (procedure "(append-vector vec1 vec2)" (id append-vector))))) (section 3 "Matrices" (def (sig (procedure "(matrix? v)" (id matrix?)) (procedure "(list->matrix l)" (id list->matrix)) (procedure "(make-matrix m n . &rest)" (id make-matrix)) (procedure "(make-3-by-3-matrix a11 a12 a13 a21 a22 a23 a31 a32 a33)" (id make-3-by-3-matrix)) (procedure "(matrix-copy m)" (id matrix-copy)) (procedure "(matrix-rows a)" (id matrix-rows)) (procedure "(matrix-columns a)" (id matrix-columns)) (procedure "(matrix-ref a i j)" (id matrix-ref)) (procedure "(matrix-set! a i j x)" (id matrix-set!)) (procedure "(matrix-row-ref a i)" (id matrix-row-ref)) (procedure "(matrix-column-ref a j)" (id matrix-column-ref)) (procedure "(matrix-row-set! a i v)" (id matrix-row-set!)) (procedure "(vector->row-matrix v)" (id vector->row-matrix)) (procedure "(vector->column-matrix v)" (id vector->column-matrix)) (procedure "(m+ a b)" (id m+)) (procedure "(m- a b)" (id m-)) (procedure "(m+k m k)" (id m+k)) (procedure "(m+k-diagonal m k)" (id m+k-diagonal)) (procedure "(k+m k m)" (id k+m)) (procedure "(m*v a v)" (id m*v)) (procedure "(matrix-transpose a)" (id matrix-transpose)) (procedure "(outer-product f u v)" (id outer-product)) (procedure "(self-outer-product f v)" (id self-outer-product)) (procedure "(m* a b)" (id m*)) (procedure "(m*. a b)" (id m*.)) (procedure "(m/. a b)" (id m/.)) (procedure "(v*m v a)" (id v*m)) (procedure "(k*m k m)" (id k*m)) (procedure "(m*k m k)" (id m*k)) (procedure "(m/k m k)" (id m/k)) (procedure "(v*m*v v m)" (id v*m*v)) (procedure "(determinant a)" (id determinant)) (procedure "(invert-matrix a)" (id invert-matrix)) (procedure "(simplex a m1 m2 m3)" (id simplex)) (procedure "(jacobi a)" (id jacobi)) (procedure "(eigenvalues a)" (id eigenvalues)) (procedure "(eigenvectors a)" (id eigenvectors)) (procedure "(vector->diagonal-matrix v)" (id vector->diagonal-matrix)) (procedure "(identity-matrix n)" (id identity-matrix)) (procedure "(clip-eigenvalues a v)" (id clip-eigenvalues)) (procedure "(eigenvector-angle1 m)" (id eigenvector-angle1)) (procedure "(eigenvector-angle2 m)" (id eigenvector-angle2)) (procedure "(left-pseudo-inverse m)" (id left-pseudo-inverse)) (procedure "(right-pseudo-inverse m)" (id right-pseudo-inverse)) (procedure "(ref-1d m a)" (id ref-1d)) (procedure "(ref-2d m a b)" (id ref-2d)) (procedure "(ref-3d m a b c)" (id ref-3d)) (procedure "(ref-4d m a b c d)" (id ref-4d)) (procedure "(ref-5d m a b c d e)" (id ref-5d)) (procedure "(map-n-vector-2d f m n)" (id map-n-vector-2d)) (procedure "(map-n-vector-3d f m n p)" (id map-n-vector-3d)) (procedure "(map-n-vector-4d f m n p q)" (id map-n-vector-4d)) (procedure "(map-n-vector-5d f m n p q r)" (id map-n-vector-5d)) (procedure "(matrix-sum f n i)" (id matrix-sum)) (procedure "(matrix-sum-2d f m n i)" (id matrix-sum-2d)) (procedure "(shape-matrix v c)" (id shape-matrix)) (procedure "(unshape-matrix m)" (id unshape-matrix)) (procedure "(crop m x y w h)" (id crop)) (procedure "(submatrix m x-offset y-offset x-size y-size)" (id submatrix)) (procedure "(matrix-ref-nd m . is)" (id matrix-ref-nd)) (procedure "(matrix-3d-ref a s i j)" (id matrix-3d-ref)) (procedure "(matrix-set-nd! m v . is)" (id matrix-set-nd!)) (procedure "(matrix-3d-set! a v s i j)" (id matrix-3d-set!)) (procedure "(map-matrix-nd f m n)" (id map-matrix-nd)) (procedure "(for-each-matrix-nd f m n)" (id for-each-matrix-nd)) (procedure "(map-matrix f m)" (id map-matrix)) (procedure "(for-each-matrix f m)" (id for-each-matrix)) (procedure "(map-matrix-3d f m)" (id map-matrix-3d)) (procedure "(for-each-matrix-3d f m)" (id for-each-matrix-3d)) (procedure "(map-n-matrix f i j)" (id map-n-matrix)) (procedure "(for-each-n-matrix f i j)" (id for-each-n-matrix)) (procedure "(map-indexed-matrix f m)" (id map-indexed-matrix)) (procedure "(for-each-indexed-matrix f m)" (id for-each-indexed-matrix)) (procedure "(map-indexed-matrix-3d f p)" (id map-indexed-matrix-3d)) (procedure "(for-each-indexed-matrix-3d f p)" (id for-each-indexed-matrix-3d))))) (section 3 "Sparse matrices" (def (sig (record "(define-structure sparse-matrix row column blank)" (id define-structure)) (record "(define-structure sparse-matrix-row element i up down)" (id define-structure)) (record "(define-structure sparse-matrix-column element j left right)" (id define-structure)) (record "(define-structure sparse-matrix-element value i up down j left right)" (id define-structure)) (procedure "(create-sparse-matrix blank)" (id create-sparse-matrix)) (procedure "(sparse-matrix-ref sparse-matrix i j)" (id sparse-matrix-ref))))) (section 3 "Traversal" (def (sig (procedure "(every-n-2d p v w)" (id every-n-2d)) (procedure "(every-n-3d p v w x)" (id every-n-3d)) (procedure "(every-n-4d p v w x y)" (id every-n-4d)) (procedure "(every-n-5d p v w x y z)" (id every-n-5d)) (procedure "(product-2d f m n)" (id product-2d)) (procedure "(sum-2d f m n)" (id sum-2d)) (procedure "(sum-3d f m n p)" (id sum-3d)) (procedure "(sum-4d f m n p q)" (id sum-4d)) (procedure "(sum-pairs f m)" (id sum-pairs)) (procedure "(vector-sum f n i)" (id vector-sum)) (procedure "(vector-sum-2d f m n i)" (id vector-sum-2d)) (procedure "(sum-f f l)" (id sum-f)) (procedure "(sum-vector v)" (id sum-vector)) (procedure "(sum-vector-f f v)" (id sum-vector-f))))) (section 3 "Statistics" (def (sig (procedure "(list-mean p)" (id list-mean)) (procedure "(list-covariance l)" (id list-covariance)) (procedure "(list-variance s)" (id list-variance)) (procedure "(list-skewness l)" (id list-skewness)) (procedure "(list-kurtosis l)" (id list-kurtosis)) (procedure "(list-correlation l1 l2)" (id list-correlation)) (procedure "(vector-mean v)" (id vector-mean)) (procedure "(vector-variance v)" (id vector-variance)) (procedure "(vector-skewness v)" (id vector-skewness)) (procedure "(vector-kurtosis v)" (id vector-kurtosis)) (procedure "(vector-correlation v1 v2)" (id vector-correlation)) (procedure "(coefficient-of-bimodality v)" (id coefficient-of-bimodality)) (procedure "(vectors-mean values)" (id vectors-mean)) (procedure "(vectors-variance mu values)" (id vectors-variance)) (procedure "(mahalanobis-distance val mu isigma)" (id mahalanobis-distance)) (procedure "(frequencies l)" (id frequencies))))) (section 3 "Misc" (def (sig (parameter "*linear-algebra:epsilon*" (id *linear-algebra:epsilon*)) (constant "pi" (id pi)) (constant "half-pi" (id half-pi)) (constant "two-pi" (id two-pi)) (constant "minus-pi" (id minus-pi)) (constant "two-pi/360" (id two-pi/360)) (constant "three-sixty/two-pi" (id three-sixty/two-pi)) (procedure "(sqr x)" (id sqr)) (procedure "(quadratic1 a b c)" (id quadratic1)) (procedure "(quadratic2 a b c)" (id quadratic2))))) (section 3 "License" (pre "  Copyright 2010-2012 Purdue University. All rights reserved.") (pre "  Contact Andrei Barbu, andrei@0xab.com.") (pre "  This program is free software: you can redistribute it and/or modify\n  it under the terms of the GNU Lesser General Public License as published by\n  the Free Software Foundation, either version 3 of the License, or\n  (at your option) any later version.\n  This program is distributed in the hope that it will be useful,\n  but WITHOUT ANY WARRANTY; without even the implied warranty of\n  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n  GNU Lesser General Public License for more details.\n  You should have received a copy of the GNU Lesser General Public License\n  along with this program.  If not, see http://www.gnu.org/licenses."))))