Under: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(SHARP and J history)
(→‎History: History in Dyalog-family APLs and BQN)
Line 13: Line 13:


The Dual operator, written <code>¨</code>, appeared in 1983 both in [[Rationalized APL]] and [[SHARP APL]]<ref>[https://www.jsoftware.com/papers/satn45.htm "Language Extensions of May 1983"]. SATN-45, 1983-05-02.</ref> just after. In both cases it was defined to be a [[close composition]], so that the overall function has the rank of the right operand; this allows <code>¨></code> to serve the purpose of [[Each]] from a [[Nested array model|nested]] APL. 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 Dual operator, written <code>¨</code>, appeared in 1983 both in [[Rationalized APL]] and [[SHARP APL]]<ref>[https://www.jsoftware.com/papers/satn45.htm "Language Extensions of May 1983"]. SATN-45, 1983-05-02.</ref> just after. In both cases it was defined to be a [[close composition]], so that the overall function has the rank of the right operand; this allows <code>¨></code> to serve the purpose of [[Each]] from a [[Nested array model|nested]] APL. 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>.
[[Roger Hui]] proposed Under as a potential addition to [[Dyalog APL]] at [[Dyalog '15]], using the glyph <source lang=apl inline>⍢</source>. This definition 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, which are 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.


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

Revision as of 16:14, 25 April 2022

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

https://leetcode.com/problems/add-two-numbers/
      2 4 3 +_U_(10⊥⌽) 5 6 4
7 0 8

History

The Dual operator, written ¨, appeared in 1983 both in Rationalized APL and SHARP APL[2] just after. In both cases it was defined to be a close composition, so that the overall function has the rank of the right operand; this allows ¨> to serve the purpose of Each from a nested APL. 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 &.:.

Roger Hui proposed Under as a potential addition to Dyalog APL at Dyalog '15, using the glyph . This definition was added to both Extended Dyalog APL and dzaima/APL in 2018. Structural Under was developed by Marshall Lochbaum around 2017,[3] and was included in Extended Dyalog initially and added to dzaima/APL in 2020. Later dzaima would implement ⍢× and ⍢| in the same spirit, which are featured in dzaima/APL and dzaima/BQN. The language BQN has included structural and computational Under, using the glyph , since its initial design in 2020.

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