Identity element

From APL Wiki
Revision as of 22:04, 10 September 2022 by Adám Brudzewsky (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")
Jump to navigation Jump to search

The identity element for a dyadic function is a value inherent to that function. It is defined as the value which would preserve the other argument of the dyadic function application, possibly only for a well-defined subset of the function's domain.

Left and right identities

Since the identity element preserves the other argument, it can be a left and/or a right identity. For example, Add (<syntaxhighlight lang=apl inline>+</source>) has the left and right identity element <syntaxhighlight lang=apl inline>0</source> because <syntaxhighlight lang=apl inline>N≡N+0</source> and <syntaxhighlight lang=apl inline>N≡0+N</source> for all arrays <syntaxhighlight lang=apl inline>N</source> in the domain of <syntaxhighlight lang=apl inline>+</source>. However, the identity of Divide (<syntaxhighlight lang=apl inline>÷</source>), <syntaxhighlight lang=apl inline>1</source>, is only a right identity because while <syntaxhighlight lang=apl inline>N≡N÷1</source> is true for all <syntaxhighlight lang=apl inline>N</source> in the domain of <syntaxhighlight lang=apl inline>÷</source>, this isn't so for <syntaxhighlight lang=apl inline>N≡1÷N</source>, and no alternative identity element value exists which would fulfil the condition.

If a function <syntaxhighlight lang=apl inline>f</source> has both a left identity element and a right identity element (call them <syntaxhighlight lang=apl inline>l</source> and <syntaxhighlight lang=apl inline>r</source>), then they must be the same. This is because <syntaxhighlight lang=apl inline>l f r</source> <syntaxhighlight lang=apl inline>r</source>, since <syntaxhighlight lang=apl inline>l</source> is a left identity, and <syntaxhighlight lang=apl inline>l f r</source> <syntaxhighlight lang=apl inline>l</source>, since <syntaxhighlight lang=apl inline>r</source> is a right identity, so <syntaxhighlight lang=apl inline>l</source> <syntaxhighlight lang=apl inline>r</source>.

Reduction over a length-0 axis

If a reduction (using one of <syntaxhighlight lang=apl inline>/</source>, <syntaxhighlight lang=apl inline>⌿</source>, <syntaxhighlight lang=apl inline>\</source>, or <syntaxhighlight lang=apl inline>⍀</source>) is performed over an axis of length 0, the resulting array is filled with identity elements. For example, the sum of an empty list is <syntaxhighlight lang=apl inline>0</source>, while the columnar sum of a two-column matrix with no rows is <syntaxhighlight lang=apl inline>0 0</source>: <syntaxhighlight lang=apl>

     +/0⍴0

0

     +/0 2⍴0

0 0 </source>

Support

Dialects differ in their support for such reductions. All define identity elements for most scalar primitives, and some stop there (e.g. SAX), while others (e.g. Dyalog APL and APL2) define identity elements for various mixed functions.

The identity element value for each function is defined in terms of the prototype <syntaxhighlight lang=apl inline>P</source> of the array <syntaxhighlight lang=apl inline>Y</source>:

Function name Glyph Value Left Right Notes
Add <syntaxhighlight lang=apl inline>+</source> <syntaxhighlight lang=apl inline>0</source> Yes Yes
Subtract <syntaxhighlight lang=apl inline>-</source> <syntaxhighlight lang=apl inline>0</source> No Yes
Multiply <syntaxhighlight lang=apl inline>×</source> <syntaxhighlight lang=apl inline>1</source> Yes Yes
Divide <syntaxhighlight lang=apl inline>÷</source> <syntaxhighlight lang=apl inline>1</source> No Yes
Residue </source> <syntaxhighlight lang=apl inline>0</source> Yes No
Minimum <syntaxhighlight lang=apl inline>⌊</source> <syntaxhighlight lang=apl inline>∞</source> Yes Yes the maximum representable number
Maximum <syntaxhighlight lang=apl inline>⌈</source> <syntaxhighlight lang=apl inline>-∞</source> Yes Yes the minimum representable number
Power <syntaxhighlight lang=apl inline>*</source> <syntaxhighlight lang=apl inline>1</source> No Yes
Circle function <syntaxhighlight lang=apl inline>○</source> <syntaxhighlight lang=apl inline>¯9</source> Yes No
Binomial <syntaxhighlight lang=apl inline>!</source> <syntaxhighlight lang=apl inline>1</source> Yes No
Root <syntaxhighlight lang=apl inline>√</source> <syntaxhighlight lang=apl inline>1</source> Yes No
And/LCM <syntaxhighlight lang=apl inline>∧</source> <syntaxhighlight lang=apl inline>1</source> Yes Yes
Or/GCD <syntaxhighlight lang=apl inline>∨</source> <syntaxhighlight lang=apl inline>0</source> Yes Yes Non-negative reals only
Less <syntaxhighlight lang=apl inline><</source> <syntaxhighlight lang=apl inline>0</source> Yes No Booleans only
Less Or Equal <syntaxhighlight lang=apl inline>≤</source> <syntaxhighlight lang=apl inline>1</source> Yes No Booleans only
Equal to <syntaxhighlight lang=apl inline>=</source> <syntaxhighlight lang=apl inline>1</source> Yes Yes Booleans only
Greater Or Equal <syntaxhighlight lang=apl inline>≥</source> <syntaxhighlight lang=apl inline>1</source> No Yes Booleans only
Greater <syntaxhighlight lang=apl inline>></source> <syntaxhighlight lang=apl inline>0</source> No Yes Booleans only
Not Equal <syntaxhighlight lang=apl inline>≠</source> <syntaxhighlight lang=apl inline>0</source> Yes Yes Booleans only
Reshape <syntaxhighlight lang=apl inline>⍴</source> <syntaxhighlight lang=apl inline>⍴P</source> Yes No
Catenate <syntaxhighlight lang=apl inline>,</source> <syntaxhighlight lang=apl inline>P⍴⍨ρ∘⊂⍨0,⍨¯1↓ρP</source> Yes No <syntaxhighlight lang=apl inline>1≤≢⍴Y</source>
Rotate <syntaxhighlight lang=apl inline>⌽</source> <syntaxhighlight lang=apl inline>0</source> or <syntaxhighlight lang=apl inline>0⍴⍨¯1↓⍴P</source> Yes No
Rotate First <syntaxhighlight lang=apl inline>⊖</source> <syntaxhighlight lang=apl inline>0</source> or <syntaxhighlight lang=apl inline>0⍴⍨1↓⍴P</source> Yes No
Transpose <syntaxhighlight lang=apl inline>⍉</source> <syntaxhighlight lang=apl inline>⍳≢⍴P</source> Yes No
Pick <syntaxhighlight lang=apl inline>⊃</source> <syntaxhighlight lang=apl inline>⍬</source> Yes No
Drop <syntaxhighlight lang=apl inline>↓</source> <syntaxhighlight lang=apl inline>⍬</source> or <syntaxhighlight lang=apl inline>0×⍴P</source> Yes No
Take <syntaxhighlight lang=apl inline>↑</source> <syntaxhighlight lang=apl inline>⍬</source> or <syntaxhighlight lang=apl inline>⍴P</source> Yes No
Squad Index <syntaxhighlight lang=apl inline>⌷</source> <syntaxhighlight lang=apl inline>⍬</source> or <syntaxhighlight lang=apl inline>⍳¨⍴P</source> Yes No
Without <syntaxhighlight lang=apl inline>~</source> <syntaxhighlight lang=apl inline>0⌿P</source> No Yes <syntaxhighlight lang=apl inline>1≤≢⍴Y</source>
Matrix Divide <syntaxhighlight lang=apl inline>⌹</source> <syntaxhighlight lang=apl inline>∘.=⍨⍳≢P</source> No Yes
Encode <syntaxhighlight lang=apl inline>⊤</source> <syntaxhighlight lang=apl inline>0</source> No Yes
Union <syntaxhighlight lang=apl inline>∪</source> <syntaxhighlight lang=apl inline>0⌿P</source> Yes Yes <syntaxhighlight lang=apl inline>1≤≢⍴Y</source>
Replicate <syntaxhighlight lang=apl inline>/</source> <syntaxhighlight lang=apl inline>1</source> Yes No <syntaxhighlight lang=apl inline>1≤≢⍴Y</source>
Expand <syntaxhighlight lang=apl inline>\</source> <syntaxhighlight lang=apl inline>∘.=⍨⍳≢P</source> Yes No <syntaxhighlight lang=apl inline>1≤≢⍴Y</source>
Inner products <syntaxhighlight lang=apl inline>+.×</source>
<syntaxhighlight lang=apl inline>∨.∧</source>
<syntaxhighlight lang=apl inline>∘.=⍨⍳≢P</source> Yes Yes
Inner product <syntaxhighlight lang=apl inline>∧.∨</source> <syntaxhighlight lang=apl inline>∘.≠⍨⍳≢P</source> Yes Yes

External links

Documentation


APL features [edit]
Built-ins Primitives (functions, operators) ∙ Quad name
Array model ShapeRankDepthBoundIndex (Indexing) ∙ AxisRavelRavel orderElementScalarVectorMatrixSimple scalarSimple arrayNested arrayCellMajor cellSubarrayEmpty arrayPrototype
Data types Number (Boolean, Complex number) ∙ Character (String) ∙ BoxNamespaceFunction array
Concepts and paradigms Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity elementComplex floorArray ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ GlyphLeading axis theoryMajor cell searchFirst-class function
Errors LIMIT ERRORRANK ERRORSYNTAX ERRORDOMAIN ERRORLENGTH ERRORINDEX ERRORVALUE ERROREVOLUTION ERROR