]> gitweb.factorcode.org Git - factor.git/commitdiff
Initial checkin from library/math/matrices.factor without the vector words
authorDoug Coleman <erg@trifocus.net>
Thu, 20 Oct 2005 23:59:26 +0000 (23:59 +0000)
committerDoug Coleman <erg@trifocus.net>
Thu, 20 Oct 2005 23:59:26 +0000 (23:59 +0000)
contrib/math/matrices.factor [new file with mode: 0644]

diff --git a/contrib/math/matrices.factor b/contrib/math/matrices.factor
new file mode 100644 (file)
index 0000000..5fb0973
--- /dev/null
@@ -0,0 +1,29 @@
+! Copyright (C) 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
+IN: math
+USING: arrays generic kernel sequences ;
+
+! Matrices
+: zero-matrix ( m n -- matrix )
+    swap [ drop zero-array ] map-with ;
+
+: identity-matrix ( n -- matrix )
+    #! Make a nxn identity matrix.
+    dup [ swap [ = 1 0 ? ] map-with ] map-with ;
+
+! Matrix operations
+: mneg ( m -- m ) [ vneg ] map ;
+
+: n*m ( n m -- m ) [ n*v ] map-with ;
+: m*n ( m n -- m ) swap n*m ;
+: n/m ( n m -- m ) [ n/v ] map-with ;
+: m/n ( m n -- m ) swap [ swap v/n ] map-with ;
+
+: m+   ( m m -- m ) [ v+ ] 2map ;
+: m-   ( m m -- m ) [ v- ] 2map ;
+: m*   ( m m -- m ) [ v* ] 2map ;
+: m/   ( m m -- m ) [ v/ ] 2map ;
+
+: v.m ( v m -- v ) flip [ v. ] map-with ;
+: m.v ( m v -- v ) swap [ v. ] map-with ;
+: m.  ( m m -- m ) flip swap [ m.v ] map-with ;