Outer Product: Difference between revisions

Jump to navigation Jump to search
580 bytes removed ,  23:14, 4 September 2023
m
Qualify as *structured* Cartesian product; split long paragraph
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 generalization of the [[wikipedia:Cartesian product|Cartesian product]] to operations other than [[catenate|catenation]].
{{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). 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. Unlike APL's Outer Product, J's Table does not use an implicit [[Each]], so the results of the individual applications of its operand are not boxed (unless the given operand itself does so).
[[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>f⍤2 99⍤99 1</syntaxhighlight>). Conversely, the behavior of APL's Outer Product can be accomplished in terms of J's Table by adding the Each modifier, as in <syntaxhighlight lang=j inline>u&.>/</syntaxhighlight> or <syntaxhighlight lang=j inline>u&>/</syntaxhighlight>, depending on whether the given operand is a [[scalar function]].
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 Cartesian pairing behavior of J's Table results from each <syntaxhighlight lang=j inline>"(lu, _)</syntaxhighlight> cell-pairing being processed by <syntaxhighlight lang=j inline>u</syntaxhighlight>, which applies its own ranks to divide up the right argument into cells.
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.  


However, it does not allow for creating a Cartesian pairing involving cells of the left argument specified with negative left rank (except trivially, in cases in which Table's application has no effect, e.g. <syntaxhighlight lang=j inline>u"_2 _"_ _1/</syntaxhighlight>). This is because negative assigned rank in J is encoded as infinite rank; in J's terminology, negative rank is "internal rank" only.
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
trusted
83

edits

Navigation menu