1. Affine transformation
Where is the new coordinate and is the old coordinate.
The APL code mapping an image by this transformation is like:
| affine←{
| ⍝ affine transformation
| ⎕IO←0 ⋄ s←⍴⍵
| g←¯1↓⍉⌊0.5+⍺+.×⍤2 1⊢1,⍨⍉s⊤⍳×/s
5 | m←∧⌿(s>⍤0 1⊢g)∧0<g
| s⍴(0,,⍵)[m×1+s⊥g]
| }
2. Solve linear equations
For coefficient matrix , variable matrix and constant matrix , then
Then the APL code is just (⌹A)+.×B
, or even
simpler, B⌹A
. As the APL2 specification writes:
If
Z←L⌹R
is executable,Z
is determined to minimize the value of the least squares expression:|
+/,(L-R+.×Z)*2
In J the matrix division is B %. A
. Note that, if
possible, using exact number can produce more accurate result.
3. Norm in
The norm of inner product space, , is:
|2*∘÷⍨+.×⍨
4. Use linear transformation to define polynomial functions
Due to the "superposition" principle, for that basis , find that .
Then M is just:
This may comes handy when some extent of symbolic computation is needed.
5. Determinant, Generalized
There is already a general determinant from APLcart.info. However, I am not able to explain the mathematics behind it. I could only tell it involves taking the matrix product of upper matrix and diagonal replaced by accumulative sum minus the total sum and itself, negate it, and repeat with the result. Sorry, so far I am only familiar with cofactor expansion method
Actually, Iversion had assigned a
special combinator for determinant: monadic -.×
. This
would not work in most of today's APL implementations, but there is
the similar operator in J. Since he has recorded the definition, we
are still able to figure out what it means.
Let's first review the cofactor expansion method with a 3 by 3 matrix:
Then, here is a play on trick of visualizing the method in
APL(⎕IO←0
and remember the evaluation order in
APL):
⎕←perm←3 6⍴0 0 1 1 2 2 1 2 2 0 0 1 2 1 0 2 1 0
0 0 1 1 2 2
1 2 2 0 0 1
2 1 0 2 1 0
(⊣,'-',⊢)/(⊣,'×',⊢)/1 0 1⍉(3 3⍴'abcdefghi')[perm;]
┌───────────────────────────────────┐
│a×e×i-a×h×f-d×h×c-d×b×i-g×b×f-g×e×c│
└───────────────────────────────────┘
Now, the only problem left is what is perm
? It is not the unique index value since any
permutation that can correctly arrange the parity should work.
According to Iverson, matrix determinant can be characterized as:
| det ← {-/×/1 0 1⍉⍵[perm⍴⍵;]}
| mod ← {0=⊃⍴⍵:⍵ ⋄ ⍵[0;],[0]Z+⍵[(1↑⍴Z)⍴0;]≤Z←∇ 1 0↓⍵}
|perm ← {(mod Z)[;(⍳⍴P)+P-(⍴P←2|+⌿Z←rep ⍵)⍴0 1]}
| rep ← {(⊢⊤(⍳×/))⌽1+⍳1↑⍵}
Replacing -
and ×
by other functions
can give other interesting results, but that would not be covered
here. A similar implementation in Dyalog can be found at dfns.
Bibliography
[Iverson] Two combinatoric operators
. . Proceedings of the eighth
international conference on APL. 22 September 1976. G Truman Hunter. 233–237. Association
for Computing Machinery. New York, NY, United
States. doi:10.1145/800114.803681.
[dfns] Alternant. . https://dfns.dyalog.com/n_alt.htm.