Determinant and permanent: Difference between revisions
Add Factor example
m (correct a misspelling) |
(Add Factor example) |
||
Line 469:
</lang>
=={{header|Factor}}==
<lang factor>USING: fry kernel math.combinatorics math.matrices sequences ;
: permanent ( matrix -- x )
dup square-matrix? [ "Matrix must be square." throw ] unless
[ dim first <iota> ] keep
'[ [ _ nth nth ] map-index product ] map-permutations sum ;</lang>
Example output:
<pre>
IN: scratchpad USE: math.matrices.laplace ! for determinant
{ { 2 9 4 } { 7 5 3 } { 6 1 8 } }
[ determinant ] [ permanent ] bi
--- Data stack:
-360
900
</pre>
=={{header|Forth}}==
{{libheader|Forth Scientific Library}}
|