rslt ← (f ##.alt g) mat ⍝ Alternant.
From Adám Brudzewsky, who says:
Direct translation from the SAX 6.1 manual, from which I quote:
f.g ⍵ Alternant
The expressions -.×⍵ and +.×⍵ are for square matrix arguments ⍵, the determinant
and the permanent of mathematics. The generalization to arguments other than
plus, minus and times is based on construing the determinant as an alternating
sum (-⌿) over products over the diagonals of tables obtained by permuting the
major cells of ⍵.
The model for the determinant described here is illuminating for what it reveals
about the close association between the monadic and dyadic forms of the dot
operator (f.g). The determinant is generated by the expression -.×⍵, where ⍵ is
a matrix of integers (usually square, but possibly with more rows than columns).
Only the top-left square portion of an array with more columns than rows is con-
sidered; that is, ⍵ is truncated to be (⌊/⍴⍵)↑⍵.
A model supplied by McDonnell and Hui for monadic inner product is available in
the recursive function DOT shown below; the two functions f and g are assumed to
be subtract (⍺-⍵) and times (⍺×⍵) in the following example.
∇ z←DOT ⍵;M
[1] →(1≠¯1↑⍴⍵)/L0
[2] →0⊣z←f⌿⍵ ⍝ one-column case
[3] L0:M←~⍤1 0 ⊂ ⍳0@⍴⍵ ⍝ minors
[4] z←⍵[;⎕io] f.g DOT⍤2 ⍵[M;1↓⍳(⍴⍵)[1+⎕io]]
∇
For example, given the array M:
⊢M←3 3⍴6 7 2 1 5 9 8 3 4
6 7 2
1 5 9
8 3 4
the expression which DOT evaluates to produce the determinant uses each scalar
in the first column of M with subarrays called minors derived from the remaining
columns of the remaining rows:
(6×(5×4)-3×9) - (1×(7×4)-3×2) - 8×(7×9)-5×2
360
Examples:
det ← -alt× ⍝ determinant
det 2 2⍴2 3 4 5
¯2
det 0⍪⍨ 2 2⍴2 3 4 5
¯2
det 2 2⍴0 1,1 0
¯1
det 1 1⍴3
3
det 1 0⍴3
0
det 0 1⍴3
1
det 0 0⍴3
1
hil ← {÷1+∘.+⍨(⍳⍵)-⎕io} ⍝ Order-⍵ Hilbert matrix.
det hil 5
3.749295132E¯12
det 2 2⍴ 0 1, 1 0
¯1
,alt, ⎕←3 3⍴⎕A
ABC
DEF
GHI
┌───────────────┐
│AEIHFDBIHCGBFEC│
└───────────────┘
{⍺ ⍵}alt{⍺ ⍵} ⎕←3 3⍴⎕A
ABC
DEF
GHI
┌───────────────────────────────────────┐
│┌───────────┬─────────────────────────┐│
││┌─┬───────┐│┌───────────┬───────────┐││
│││A│┌──┬──┐│││┌─┬───────┐│┌─┬───────┐│││
│││ ││EI│HF│││││D│┌──┬──┐│││G│┌──┬──┐││││
│││ │└──┴──┘││││ ││BI│HC││││ ││BF│EC│││││
││└─┴───────┘│││ │└──┴──┘│││ │└──┴──┘││││
││ ││└─┴───────┘│└─┴───────┘│││
││ │└───────────┴───────────┘││
│└───────────┴─────────────────────────┘│
└───────────────────────────────────────┘
+alt+ 2 2⍴⍳4
10
+alt- 2 2⍴⍳4
¯2
+alt× ⎕←4 4⍴ 1 1 1 1, 2 1 0 0, 3 0 1 0, 4 0 0 1 ⍝ permanent
1 1 1 1
2 1 0 0
3 0 1 0
4 0 0 1
10
See also: det
Back to: contents
Back to: Workspaces