 : norm-gram-schmidt ( seq -- orthonormal )
     gram-schmidt [ normalize ] map ;
 
-: m^n ( m n -- n ) 
+: m^n ( m n -- n )
     make-bits over first length identity-matrix
     [ [ dupd m. ] when [ dup m. ] dip ] reduce nip ;
 


GENERIC: square-rows ( object -- matrix )
M: integer square-rows iota square-rows ;
M: sequence square-rows dup [ nip ] cartesian-map ; 

GENERIC: square-cols ( object -- matrix )
M: integer square-cols iota square-cols ;
M: sequence square-cols dup [ drop ] cartesian-map ; 

: make-matrix-with-indices ( m n quot -- matrix )
    [ [ iota ] bi@ ] dip '[ @ ] cartesian-map ; inline

: null-matrix? ( matrix -- ? ) empty? ;

: well-formed-matrix? ( matrix -- ? )
    dup null-matrix? [
        drop t
    ] [
        [ ] [ first length ] bi
        '[ length _ = ] all?
    ] if ;

: dim ( matrix -- pair/f )
    [ 2 0 <array> ]


: set-indices ( object sequence matrix -- )
    '[ _ set-index ] with each ; inline

: matrix-map ( matrix quot -- )
    '[ _ map ] map ; inline
