2,951
edits
m (remove reference to matrix multiplication, that should be for Inner Product instead) |
m (→Syntax) |
||
(2 intermediate revisions by the same user not shown) | |||
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]]. | {{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. | ||
=== Syntax === | === Syntax === | ||
Outer Product differs from all other [[monadic operator]]s, which are written as a single [[glyph]], with the operand on the left. For [[backwards compatibility|historical reasons]], the outer product operator is a [[bi-glyph]] denoted as <source lang=apl inline>∘.</source>, and its appears on the right. | |||
This syntactical inconsistency is resolved in [[J]] and [[BQN]], where the outer product operator, called Table, and denoted <source lang=j inline>/</source> and <code>⌜</code> respectively, has the usual operator syntax. | |||
=== Examples === | === Examples === | ||
Line 48: | Line 48: | ||
=== Applications === | === Applications === | ||
Outer product is useful for solving problems that intuitively | Outer product is useful for solving problems that intuitively require a [[wikipedia:Time_complexity#Polynomial_time|polynomial time]] algorithm. This may also indicate that such an algorithm is not the fastest solution. | ||
For example, suppose we want to find duplicated elements in an non-[[nested array]]. Intuitively speaking, the easiest way to solve this problem is to compare each element of the array with all other elements, which is exactly what an outer product does. | For example, suppose we want to find duplicated elements in an non-[[nested array]]. Intuitively speaking, the easiest way to solve this problem is to compare each element of the array with all other elements, which is exactly what an outer product does. | ||
Line 78: | Line 77: | ||
primes 20 | primes 20 | ||
2 3 5 7 11 13 17 19 | 2 3 5 7 11 13 17 19 | ||
</source> | </source> | ||
Here there are faster solutions such as the [[wikipedia:Sieve of Eratosthenes|Sieve of Eratosthenes]]. | |||
== External links == | == External links == | ||
* [https://mlochbaum.github.io/OuterProduct/ Outer Product as an Introduction to APL and a Pretty Cool Thing in General]: website for LambdaConf talk by [[Marshall Lochbaum]] | |||
=== Documentation === | === Documentation === | ||
Line 87: | Line 88: | ||
* [https://microapl.com/apl_help/ch_020_020_890.htm APLX] | * [https://microapl.com/apl_help/ch_020_020_890.htm APLX] | ||
* J [https://www.jsoftware.com/help/dictionary/d420.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/slash#dyadic NuVoc] | * J [https://www.jsoftware.com/help/dictionary/d420.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/slash#dyadic NuVoc] | ||
* [https://mlochbaum.github.io/BQN/doc/map.html#table BQN] | |||
{{APL built-ins}}[[Category:Primitive operators]] | {{APL built-ins}}[[Category:Primitive operators]] |