Difference between revisions of "Identity element"

From APL Wiki
Jump to navigation Jump to search
Miraheze>Adám Brudzewsky
m (Text replacement - "{{APL programming language}}" to "{{APL features}}")
m (2 revisions imported: Migrate from miraheze)
(No difference)

Revision as of 15:21, 20 November 2019

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 (+) has the left and right identity element 0 because NN+0 and N0+N for all arrays N in the domain of +. However, the identity of Divide (÷), 1, is only a right identity because while NN÷1 is true for all N in the domain of ÷, this isn't so for N1÷N, and no alternative identity element value exists which would fulfil the condition.

Reduction over a length-0 axis

If a reduction (using one of /, , \, or ) 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 0, while the columnar sum of a two-column matrix with no rows is 0 0:

      +/0 20
0 0


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 P of the array Y:

Function name Glyph Value Left Right Notes
Add + 0 Yes Yes
Subtract - 0 No Yes
Multiply × 1 Yes Yes
Divide ÷ 1 No Yes
Residue | 0 Yes No
Minimum Yes Yes the maximum representable number
Maximum - Yes Yes the minimum representable number
Power * 1 No Yes
Circular ¯9 Yes No
Binomial ! 1 Yes No
Root 1 Yes No
And/LCM 0 Yes Yes
Or/GCD 1 Yes Yes
Less < 0 Yes No Booleans only
Less Or Equal 1 Yes No Booleans only
Equal to = 1 Yes Yes Booleans only
Greater Or Equal 1 No Yes Booleans only
Greater > 0 No Yes Booleans only
Not Equal 0 Yes Yes Booleans only
Reshape P Yes No
Catenate , Pρ0,¯1ρP Yes No 1≤≢⍴Y
Rotate 0 or 0¯1↓⍴P Yes No
Rotate First 0 or 01↓⍴P Yes No
Transpose ⍳≢⍴P Yes No
Pick Yes No
Drop or 0×⍴P Yes No
Take or P Yes No
Squad Indexing or ¨P Yes No
Without ~ 0P Yes Yes 1≤≢⍴Y
Matrix Divide ∘.=⍳≢P No Yes
Encode 0 No Yes
Union 0P Yes Yes 1≤≢⍴Y
Replicate / 1 Yes No 1≤≢⍴Y
Expand \ ∘.=⍳≢P Yes No 1≤≢⍴Y
Inner products +.×
∘.=⍳≢P Yes Yes
Inner product . ∘.⍳≢P Yes Yes

External links


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) ∙ BoxNamespace
Concepts and paradigms Leading axis theoryScalar extensionConformabilityLeading axis agreementScalar functionPervasionGlyphIdentity elementComplex floorTotal array ordering