4,500
edits
(Editing; contrast shape rules with conformability) |
No edit summary |
||
Line 46: | Line 46: | ||
49 64 | 49 64 | ||
</source> | </source> | ||
== History == | |||
Inner product appeared in early [[Iverson Notation]] as <math>^f_g</math> and applied even to non-[[scalar function]]s, like [[Compress]], Iverson bringing: | |||
:<math> | |||
\begin{align} | |||
\text{For example, if}\\ | |||
\bf{A}&=\begin{pmatrix} | |||
1&3&2&0\\ | |||
2&1&0&1\\ | |||
2&0&0&2\\ | |||
\end{pmatrix} | |||
\qquad\text{and}\qquad | |||
\bf{B}=\begin{pmatrix} | |||
4&1\\ | |||
0&3\\ | |||
0&2\\ | |||
2&0\\ | |||
\end{pmatrix}\\ | |||
\text{then}\qquad\bf{A}\;^+_\times\,\bf{B}&=\begin{pmatrix} | |||
4&14\\ | |||
10&5\\ | |||
20&4\\ | |||
\end{pmatrix}, | |||
\quad\bf{A}\;^\and_=\,\bf{B}=\begin{pmatrix} | |||
0&1\\ | |||
0&0\\ | |||
1&0\\ | |||
\end{pmatrix}\text{,}\\ | |||
\bf{A}\;^\or_\neq\;\bf{B}&=\begin{pmatrix} | |||
1&0\\ | |||
1&1\\ | |||
0&1\\ | |||
\end{pmatrix}, | |||
\qquad\text{and}\qquad(\bf{A}\neq0)\;^+_{\,/}\,\bf{B}=\begin{pmatrix} | |||
4&6\\ | |||
6&4\\ | |||
6&1\\ | |||
\end{pmatrix}\text{.} | |||
\end{align} | |||
</math> | |||
When the inner product notation was linearised (made to fit on a single line of code) the [[glyph]] <source lang=apl inline>.</source> was chosed to denote what was previously indicated by positioning the two [[operand]]s vertically aligned. Thus, the above correspond to the following modern APL: | |||
<source lang=apl> | |||
</source> | |||
⍝ For example, if | |||
A←3 4⍴1 3 2 0 2 1 0 1 4 0 0 2 | |||
B←4 2⍴4 1 0 3 0 2 2 0 | |||
⍝ then | |||
A +.× B | |||
4 14 | |||
10 5 | |||
20 4 | |||
A ∧.= B | |||
0 1 | |||
0 0 | |||
1 0 | |||
A ∨.≠ B | |||
1 0 | |||
1 1 | |||
0 1 | |||
(A ≠ 0) +./ B | |||
4 6 | |||
6 4 | |||
6 1 | |||
</source> | |||
Note that some dialects implement [[Compress]] (<source lang=apl inline>/</source>) as a [[monadic operator]] rather than as a function, which means it cannot be an operand in the inner product. Instead, a cover function is necessary: | |||
<source lang=apl> | |||
∇z←a Compress b | |||
z←\/b | |||
∇ | |||
</source> | |||
== Differences between dialects == | |||
Implementations differ on the exact behaviour of inner product when the right operand is not a [[scalar function]]. It follows from page 121 of the ISO/IEC 13751:2001(E) [[standard]] specifies that <source lang=apl inline>X f.g Y</source> is equivalent to <source lang=apl inline>⊃⍤0 f/¨ (⊂[⍴⍴x]x)∘.g ⊂[1]y</source>. This is indeed what [[APL2]], [[APLX]], and [[ngn/apl]] follow, while [[Dyalog APL]] and [[GNU APL]] use <source lang=apl inline>⊃⍤0 f/¨ (⊂[⍴⍴x]x)∘.(g¨) ⊂[1]y</source>. | |||
== External links == | == External links == | ||