math.matrices: add error for negative m^n (and test).

db4
John Benediktsson 2014-01-05 20:08:55 -08:00
parent 97b0ad7499
commit abd069c1ad
2 changed files with 7 additions and 1 deletions

View File

@ -208,6 +208,7 @@ IN: math.matrices.tests
[ { { 4181 6765 } { 6765 10946 } } ]
[ { { 0 1 } { 1 1 } } 20 m^n ] unit-test
[ { { 0 1 } { 1 1 } } -20 m^n ] [ negative-power-matrix? ] must-fail-with
{
{ { 0 5 0 10 } { 6 7 12 14 } { 0 15 0 20 } { 18 21 24 28 } }

View File

@ -167,10 +167,15 @@ IN: math.matrices
: norm-gram-schmidt ( seq -- orthonormal )
gram-schmidt [ normalize ] map ;
: m^n ( m n -- n )
ERROR: negative-power-matrix m n ;
: (m^n) ( m n -- n )
make-bits over first length identity-matrix
[ [ dupd m. ] when [ dup m. ] dip ] reduce nip ;
: m^n ( m n -- n )
dup 0 >= [ (m^n) ] [ negative-power-matrix ] if ;
: stitch ( m -- m' )
[ ] [ [ append ] 2map ] map-reduce ;