Under: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(→‎Close composition: Move ¨> description from history section)
(→‎History: Some info moved to Structural Under)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Built-in|Under|⍢}}, or '''Dual''' (<code>¨</code>), is a [[primitive operator|primitive]] [[dyadic operator]] which takes two [[function]] [[operand]]s. It pre-processes its argument(s) with the monadic right operand, before applying the left operand on/between the result(s), then undoing the pre-processing.<ref>[https://mlochbaum.github.io/BQN/help/under.html BQN: Circle Jot (⌾)]</ref>
{{Built-in|Under|⍢}}, or '''Dual''' (<syntaxhighlight lang=apl inline>¨</syntaxhighlight>), is a [[primitive operator|primitive]] [[dyadic operator]] which takes two [[function]] [[operand]]s. It pre-processes its argument(s) with the monadic right operand, before applying the left operand on/between the result(s), then undoing the pre-processing.<ref>[https://mlochbaum.github.io/BQN/help/under.html BQN: Circle Jot (⌾)]</ref>


== Model ==
== Model ==
In dialects that support user-defined operators and invertible functions, it can be defined as (or similar):
In dialects that support user-defined operators and invertible functions, it can be defined as (or similar):
        _U_ ← {⍺←{⍵ ⋄ ⍺⍺} ⋄ ⍵⍵⍣¯1⊢(⍵⍵ ⍺)⍺⍺(⍵⍵ ⍵)}
<syntaxhighlight lang=apl>      _U_ ← {⍺←{⍵ ⋄ ⍺⍺} ⋄ ⍵⍵⍣¯1⊢(⍵⍵ ⍺)⍺⍺(⍵⍵ ⍵)}</syntaxhighlight>


== Examples ==
== Examples ==
      ⍝ https://leetcode.com/problems/add-two-numbers/
The following example solves [https://leetcode.com/problems/add-two-numbers/ a LeetCode problem] which asks to add two numbers given as reversed digit lists:
      2 4 3 +_U_(10⊥⌽) 5 6 4
<syntaxhighlight lang=apl>
7 0 8


      2 4 3 +_U_(10⊥⌽) 5 6 4
7 0 8
</syntaxhighlight>
First, each argument is reversed, then decoded from base 10. The addition is performed. Finally, the result is encoded to base 10 and reversed.
== Close composition ==
== Close composition ==


In [[SHARP APL]] and [[J]], Under is implemented as a [[close composition]], meaning that (using SHARP syntax) <source lang=apl inline>f¨g</source> has the overall [[function rank]] of <source lang=apl inline>g</source>. This allows <code>¨></code> to serve the purpose of [[Each]] from a [[Nested array model|nested]] APL. J uses <code>&.</code> for the close form and <code>&.:</code> for the rankless form.
In [[SHARP APL]] and [[J]], Under is implemented as a [[close composition]], meaning that (using SHARP syntax) <syntaxhighlight lang=apl inline>f¨g</syntaxhighlight> has the overall [[function rank]] of <syntaxhighlight lang=apl inline>g</syntaxhighlight>. This allows <syntaxhighlight lang=apl inline>¨></syntaxhighlight> to serve the purpose of [[Each]] from a [[Nested array model|nested]] APL. J uses <syntaxhighlight lang=j inline>&.</syntaxhighlight> for the close form and <syntaxhighlight lang=j inline>&.:</syntaxhighlight> for the rankless form.


== History ==
== History ==


The most widely known form of Under for much of APL's history was [[SHARP APL]]'s Dual operator, written <code>¨</code> and defined as a [[close composition]]. It was presented by [[Ken Iverson]] and [[Bob Bernecky]] with the name "with" in 1980,<ref>[[Bob Bernecky]] and [[Ken Iverson]]. [https://www.jsoftware.com/papers/opea.htm Operators and Enclosed Arrays] at [[IPSA '80]]</ref> and implemented for only a small number of right operands in 1981.<ref>[https://www.jsoftware.com/papers/satn41.htm "Composition and Enclosure"]. SATN-41, 1981-06-20.</ref> The name "Dual" was used in [[Rationalized APL]] in 1983, and the full SHARP implementation using [[function rank]] was completed just after.<ref>[https://www.jsoftware.com/papers/satn45.htm "Language Extensions of May 1983"]. SATN-45, 1983-05-02.</ref> Iverson changed the name to Under for his 1987 [[A Dictionary of APL]], and [[J]] uses this name as well. It includes both a close form <source lang=j inline>&.</source> like SHARP and a non-close form <source lang=j inline>&.:</source>.
The most widely known form of Under for much of APL's history was [[SHARP APL]]'s Dual operator, written <syntaxhighlight lang=apl inline>¨</syntaxhighlight> and defined as a [[close composition]]. It was presented by [[Ken Iverson]] and [[Bob Bernecky]] with the name "with" in 1980,<ref>[[Bob Bernecky]] and [[Ken Iverson]]. [https://www.jsoftware.com/papers/opea.htm Operators and Enclosed Arrays] at [[IPSA '80]]</ref> and implemented for only a small number of right operands in 1981.<ref>[https://www.jsoftware.com/papers/satn41.htm "Composition and Enclosure"]. SATN-41, 1981-06-20.</ref> The name "Dual" was used in [[Rationalized APL]] in 1983, and the full SHARP implementation using [[function rank]] was completed just after.<ref>[https://www.jsoftware.com/papers/satn45.htm "Language Extensions of May 1983"]. SATN-45, 1983-05-02.</ref> Iverson changed the name to Under for his 1987 [[A Dictionary of APL]], and [[J]] uses this name as well. It includes both a close form <syntaxhighlight lang=j inline>&.</syntaxhighlight> like SHARP and a non-close form <syntaxhighlight lang=j inline>&.:</syntaxhighlight>.


However, Iverson had defined the Dual operator with glyph <source lang=apl inline>⍢</source> in his 1978 paper "Operators and Functions",<ref>[[Ken Iverson]]. [https://www.jsoftware.com/papers/opfns.htm ''Operators and Functions''], §8 Composition and Duality. IBM Research Report #RC7091. 1978-04-26.</ref> using a non-close form because [[function rank]] had not yet been invented. [[NARS]] featured this operator in 1981, preceding SHARP's limited implementation. [[Roger Hui]] proposed Under with the same definition as a potential addition to [[Dyalog APL]] at [[Dyalog '15]], and it was added to both [[Extended Dyalog APL]] and [[dzaima/APL]] in 2018.
However, Iverson had defined the Dual operator with glyph <syntaxhighlight lang=apl inline>⍢</syntaxhighlight> in his 1978 paper [[Operators and Functions]],<ref>[[Ken Iverson]]. [https://www.jsoftware.com/papers/opfns.htm ''Operators and Functions''], §8 Composition and Duality. IBM Research Report #RC7091. 1978-04-26.</ref> using a non-close form because [[function rank]] had not yet been invented. [[NARS]] featured this operator in 1981, preceding SHARP's limited implementation. [[Roger Hui]] proposed Under with the same definition as a potential addition to [[Dyalog APL]] at [[Dyalog '15]], and it was added to both [[Extended Dyalog APL]] and [[dzaima/APL]] in 2018.


Structural Under was developed by [[Marshall Lochbaum]] around 2017,<ref>[[Marshall Lochbaum]]. [https://mlochbaum.github.io/BQN/commentary/history.html#structural-under BQN's development history: Structural Under].</ref> and was included in Extended Dyalog initially and added to dzaima/APL in 2020. Later [[dzaima]] would implement <source lang=apl inline>⍢×</source> and <source lang=apl inline>⍢|</source> in the same spirit, now featured in dzaima/APL and [[dzaima/BQN]]. The language [[BQN]] has included structural and computational Under, using the glyph <code>⌾</code>, since its initial design in 2020.
[[Structural Under]] was conceptualized as an extension of Under by [[Marshall Lochbaum]] around 2017,<ref>[[Marshall Lochbaum]]. [https://mlochbaum.github.io/BQN/commentary/history.html#structural-under BQN's development history: Structural Under].</ref> and was included in Extended Dyalog initially and added to dzaima/APL in 2020. The language [[BQN]] has included structural and computational Under, using the glyph <code>⌾</code>, since its initial design in 2020. Structural Under also appears in [[Kap]], [[Uiua]], and [[TinyAPL]], and is implemented for a small number of cases in [[J]] version 9.5 (2023).


== External links ==
== External links ==


* [[J]]: <source lang=j inline>&.</source> [https://code.jsoftware.com/wiki/Vocabulary/ampdot NuVoc], [https://www.jsoftware.com/help/dictionary/d631.htm dictionary]; <source lang=j inline>&.:</source> [https://code.jsoftware.com/wiki/Vocabulary/ampdotco NuVoc], [https://www.jsoftware.com/help/dictionary/d631c.htm dictionary]
* [[J]]: <syntaxhighlight lang=j inline>&.</syntaxhighlight> [https://code.jsoftware.com/wiki/Vocabulary/ampdot NuVoc], [https://www.jsoftware.com/help/dictionary/d631.htm dictionary]; <syntaxhighlight lang=j inline>&.:</syntaxhighlight> [https://code.jsoftware.com/wiki/Vocabulary/ampdotco NuVoc], [https://www.jsoftware.com/help/dictionary/d631c.htm dictionary]
* [https://mlochbaum.github.io/BQN/doc/under.html BQN]
* [https://kapdemo.dhsdevelopments.com/reference.html#_structural_under Kap]
* [https://www.uiua.org/docs/under Uiua]


== References ==
== References ==
<references/>
<references/>
{{APL built-ins}}[[Category:Primitive operators]][[Category:Composition operators]]
{{APL built-ins}}[[Category:Primitive operators]][[Category:Composition operators]]

Latest revision as of 21:07, 16 October 2024

Under (), or Dual (¨), is a primitive dyadic operator which takes two function operands. It pre-processes its argument(s) with the monadic right operand, before applying the left operand on/between the result(s), then undoing the pre-processing.[1]

Model

In dialects that support user-defined operators and invertible functions, it can be defined as (or similar):

      _U_ ← {⍺←{⍵ ⋄ ⍺⍺} ⋄ ⍵⍵⍣¯1⊢(⍵⍵ ⍺)⍺⍺(⍵⍵ ⍵)}

Examples

The following example solves a LeetCode problem which asks to add two numbers given as reversed digit lists:


      2 4 3 +_U_(10⊥⌽) 5 6 4
7 0 8

First, each argument is reversed, then decoded from base 10. The addition is performed. Finally, the result is encoded to base 10 and reversed.

Close composition

In SHARP APL and J, Under is implemented as a close composition, meaning that (using SHARP syntax) f¨g has the overall function rank of g. This allows ¨> to serve the purpose of Each from a nested APL. J uses &. for the close form and &.: for the rankless form.

History

The most widely known form of Under for much of APL's history was SHARP APL's Dual operator, written ¨ and defined as a close composition. It was presented by Ken Iverson and Bob Bernecky with the name "with" in 1980,[2] and implemented for only a small number of right operands in 1981.[3] The name "Dual" was used in Rationalized APL in 1983, and the full SHARP implementation using function rank was completed just after.[4] Iverson changed the name to Under for his 1987 A Dictionary of APL, and J uses this name as well. It includes both a close form &. like SHARP and a non-close form &.:.

However, Iverson had defined the Dual operator with glyph in his 1978 paper Operators and Functions,[5] using a non-close form because function rank had not yet been invented. NARS featured this operator in 1981, preceding SHARP's limited implementation. Roger Hui proposed Under with the same definition as a potential addition to Dyalog APL at Dyalog '15, and it was added to both Extended Dyalog APL and dzaima/APL in 2018.

Structural Under was conceptualized as an extension of Under by Marshall Lochbaum around 2017,[6] and was included in Extended Dyalog initially and added to dzaima/APL in 2020. The language BQN has included structural and computational Under, using the glyph , since its initial design in 2020. Structural Under also appears in Kap, Uiua, and TinyAPL, and is implemented for a small number of cases in J version 9.5 (2023).

External links

References

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector