+USING: math.matrices math.vectors tools.test math kernel ;
IN: math.matrices.tests
-USING: math.matrices math.vectors tools.test math ;
[
{ { 0 } { 0 } { 0 } }
[ { { 4181 6765 } { 6765 10946 } } ]
[ { { 0 1 } { 1 1 } } 20 m^n ] unit-test
+
+{
+ { { 0 5 0 10 } { 6 7 12 14 } { 0 15 0 20 } { 18 21 24 28 } }
+}
+[ { { 1 2 } { 3 4 } } { { 0 5 } { 6 7 } } kron ] unit-test
+
+{
+ {
+ { 1 1 1 1 }
+ { 1 -1 1 -1 }
+ { 1 1 -1 -1 }
+ { 1 -1 -1 1 }
+ }
+} [ { { 1 1 } { 1 -1 } } dup kron ] unit-test
+
+{
+ {
+ { 1 1 1 1 1 1 1 1 }
+ { 1 -1 1 -1 1 -1 1 -1 }
+ { 1 1 -1 -1 1 1 -1 -1 }
+ { 1 -1 -1 1 1 -1 -1 1 }
+ { 1 1 1 1 -1 -1 -1 -1 }
+ { 1 -1 1 -1 -1 1 -1 1 }
+ { 1 1 -1 -1 -1 -1 1 1 }
+ { 1 -1 -1 1 -1 1 1 -1 }
+ }
+} [ { { 1 1 } { 1 -1 } } dup dup kron kron ] unit-test
+
+{
+ {
+ { 1 1 1 1 1 1 1 1 }
+ { 1 -1 1 -1 1 -1 1 -1 }
+ { 1 1 -1 -1 1 1 -1 -1 }
+ { 1 -1 -1 1 1 -1 -1 1 }
+ { 1 1 1 1 -1 -1 -1 -1 }
+ { 1 -1 1 -1 -1 1 -1 1 }
+ { 1 1 -1 -1 -1 -1 1 1 }
+ { 1 -1 -1 1 -1 1 1 -1 }
+ }
+} [ { { 1 1 } { 1 -1 } } dup dup kron swap kron ] unit-test
: m^n ( m n -- n )
make-bits over first length identity-matrix
[ [ dupd m. ] when [ dup m. ] dip ] reduce nip ;
+
+
+: stitch ( m -- m' )
+ [ ] [ [ append ] 2map ] map-reduce ;
+
+: kron ( m1 m2 -- m )
+ '[ [ _ n*m ] map ] map stitch stitch ;