! Copyright (C) 2013 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs fry kernel locals math math.matrices
-math.vectors sequences sequences.private ;
+USING: accessors classes kernel math math.matrices math.vectors
+sequences sequences.private ;
IN: math.matrices.laplace
<PRIVATE
INSTANCE: missing immutable-sequence
: first-sub-matrix ( matrix -- first-row seq )
- [ unclip-slice swap ] [ length iota ] bi
+ [ unclip-slice swap ] [ length <iota> ] bi
[ '[ _ <missing> ] map ] with map ;
:: laplace-expansion ( row matrix -- x )
v* [ odd? [ neg ] when ] map-index sum
] if ;
-ERROR: not-a-square-matrix matrix ;
-
-: check-square-matrix ( matrix -- matrix )
- dup square-matrix? [ not-a-square-matrix ] unless ; inline
-
PRIVATE>
: determinant ( matrix -- x )
- check-square-matrix 0 swap laplace-expansion ;
+ square-matrix check-instance 0 swap laplace-expansion ;