trusted
83
edits
m (→Differences between dialects: fix typo) Tags: Mobile edit Mobile web edit |
m (Qualify as *structured* Cartesian product; split long paragraph) Tags: Mobile edit Mobile web edit |
||
Line 1: | Line 1: | ||
{{Built-in|Outer Product|<nowiki>∘.</nowiki>}}, or '''Table''' is a [[monadic operator]], which will produce a [[dyadic function]] when applied with a [[dyadic function]]. Outer product applies the [[operand]] function on each [[element]] of the left array with each element of the right array. It can be described as a shortcut for constructing nested [[wikipedia:for loop|for loop]]s, and as a | {{Built-in|Outer Product|<nowiki>∘.</nowiki>}}, or '''Table''' is a [[monadic operator]], which will produce a [[dyadic function]] when applied with a [[dyadic function]]. Outer product applies the [[operand]] function on each [[element]] of the left array with each element of the right array. It can be described as a shortcut for constructing nested [[wikipedia:for loop|for loop]]s, and as a structured [[wikipedia:Cartesian product|Cartesian product]] generalized to operations other than [[catenate|catenation]]. | ||
=== Syntax === | === Syntax === | ||
Line 86: | Line 86: | ||
=== Differences between dialects === | === Differences between dialects === | ||
[[J]]'s Table differs from APL's Outer Product by enabling Cartesian pairing between [[cell]]s of [[rank]]s other than 0, and between cells of different rank for the left vs. right arguments, without needing to first [[enclose]] the relevant cells. It is defined as <syntaxhighlight lang=j inline>u"(lu, _)</syntaxhighlight>, where <syntaxhighlight lang=j inline>lu</syntaxhighlight> is the left rank of operand <syntaxhighlight lang=j inline>u</syntaxhighlight> (<syntaxhighlight lang=j inline>"</syntaxhighlight> and <syntaxhighlight lang=j inline>_</syntaxhighlight> denote [[rank_(operator)|Rank]] and infinity, respectively, in J | [[J]]'s Table differs from APL's Outer Product by enabling Cartesian pairing between [[cell]]s of [[rank]]s other than 0, and between cells of different rank for the left vs. right arguments, without needing to first [[enclose]] the relevant cells. It is defined as <syntaxhighlight lang=j inline>u"(lu, _)</syntaxhighlight>, where <syntaxhighlight lang=j inline>lu</syntaxhighlight> is the left rank of operand <syntaxhighlight lang=j inline>u</syntaxhighlight> (<syntaxhighlight lang=j inline>"</syntaxhighlight> and <syntaxhighlight lang=j inline>_</syntaxhighlight> denote [[rank_(operator)|Rank]] and infinity, respectively, in J). | ||
<syntaxhighlight lang=j> | <syntaxhighlight lang=j> | ||
Line 135: | Line 135: | ||
{{Works in|[[J]]}} | {{Works in|[[J]]}} | ||
In APL this behavior can be accomplished by enclosing the relevant cells of each argument before applying the outer product operation (or by successive applications of Rank, e.g. <syntaxhighlight lang=apl inline> | In APL this behavior can be accomplished by enclosing the relevant cells of each argument before applying the outer product operation (or by successive applications of Rank, e.g. <syntaxhighlight lang=apl inline>f⍤99 1⍤2 99</syntaxhighlight>). Conversely, the behavior of APL's Outer Product on nested inputs can be accomplished in terms of J's Table by adding the Each modifier, as in <syntaxhighlight lang=j inline>u&.>/</syntaxhighlight>. | ||
The | The results of the individual applications of u are collectively [[frame]]d by the catenation of the frames of the left and right arguments relative to their lu- and ru-cells respectively, where lu and ru are the dyadic ranks of the operand u. | ||
Table does not allow for creating a Cartesian pairing involving cells of the left argument specified with negative rank (except trivially, in cases in which Table's application has no effect, e.g. <syntaxhighlight lang=j inline>u"_ _1"_2 _/</syntaxhighlight>). This is because negative assigned rank in J is encoded as infinite rank; in J's terminology, negative rank is "internal rank" only. | |||
<syntaxhighlight lang=j> | <syntaxhighlight lang=j> | ||
}.+"_1 _2 b.0 NB. dyadic ranks of derived verb +"_1 _2 as seen by Table | }.+"_1 _2 b.0 NB. dyadic ranks of derived verb +"_1 _2 as seen by Table |