]> gitweb.factorcode.org Git - factor.git/commitdiff
m^n binary exponentiation of matrices
authorprunedtree <prunedtree@gmail.com>
Fri, 5 Jun 2009 03:42:29 +0000 (20:42 -0700)
committerprunedtree <prunedtree@gmail.com>
Fri, 5 Jun 2009 03:42:29 +0000 (20:42 -0700)
basis/math/matrices/matrices.factor [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index cfdbe17..61e98ee
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays kernel math math.order math.vectors
-sequences sequences.private accessors columns ;
+USING: accessors arrays columns kernel math math.bits
+math.order math.vectors sequences sequences.private ;
 IN: math.matrices
 
 ! Matrices
@@ -60,4 +60,9 @@ PRIVATE>
     gram-schmidt [ normalize ] map ;
 
 : cross-zip ( seq1 seq2 -- seq1xseq2 )
-    [ [ 2array ] with map ] curry map ;
\ No newline at end of file
+    [ [ 2array ] with map ] curry map ;
+    
+: m^n ( m n -- n ) 
+    make-bits over first length identity-matrix
+    [ [ dupd m. ] when [ dup m. ] dip ] reduce nip ;
+