Changes

Jump to navigation Jump to search

Identity element

7,637 bytes added, 13:49, 13 November 2019
Created page with "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..."
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]] (<source lang=apl inline>+</source>) has the left and right identity element <source lang=apl inline>0</source> because <source lang=apl inline>N≡N+0</source> and <source lang=apl inline>N≡0+N</source> for all arrays <source lang=apl inline>N</source> in the domain of <source lang=apl inline>+</source>. However, the identity of [[Divide]] (<source lang=apl inline>÷</source>), <source lang=apl inline>1</source>, is only a right identity because while <source lang=apl inline>N≡N÷1</source> is true for all <source lang=apl inline>N</source> in the domain of <source lang=apl inline>÷</source>, this isn't so for <source lang=apl inline>N≡1÷N</source>, and no alternative identity element value exists which would fulfil the condition.

== Reduction over a length-0 axis ==

If a [[reduce|reduction]] (using one of <source lang=apl inline>/</source>, <source lang=apl inline>⌿</source>, <source lang=apl inline>\</source>, or <source 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 <source lang=apl inline>0</source>, while the columnar sum of a two-column [[matrix]] with no rows is <source lang=apl inline>0 0</source>:
<source 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]] <source lang=apl inline>P</source> of the array <source lang=apl inline>Y</source>:
{| class=wikitable
! Function name || [[Glyph]] || Value || Left || Right || Notes
|-
| [[Add]] || <source lang=apl inline>+</source> || <source lang=apl inline>0</source> || {{Yes}} || {{Yes}} ||
|-
| [[Subtract]] || <source lang=apl inline>-</source> || <source lang=apl inline>0</source> || {{No}} || {{Yes}} ||
|-
| [[Multiply]] || <source lang=apl inline>×</source> || <source lang=apl inline>1</source> || {{Yes}} || {{Yes}} ||
|-
| [[Divide]] || <source lang=apl inline>÷</source> || <source lang=apl inline>1</source> || {{No}} || {{Yes}} ||
|-
| [[Residue]] || <source lang=apl inline>|</source> || <source lang=apl inline>0</source> || {{Yes}} || {{No}} ||
|-
| [[Minimum]] || <source lang=apl inline>⌊</source> || <source lang=apl inline>∞</source> || {{Yes}} || {{Yes}} || the maximum representable number
|-
| [[Maximum]] || <source lang=apl inline>⌈</source> || <source lang=apl inline>-∞</source> || {{Yes}} || {{Yes}} || the minimum representable number
|-
| [[Power]] || <source lang=apl inline>*</source> || <source lang=apl inline>1</source> || {{No}} || {{Yes}} ||
|-
| [[Circular]] || <source lang=apl inline>○</source> || <source lang=apl inline>¯9</source> || {{Yes}} || {{No}} ||
|-
| [[Binomial]] || <source lang=apl inline>!</source> || <source lang=apl inline>1</source> || {{Yes}} || {{No}} ||
|-
| [[Root]] || <source lang=apl inline>√</source> || <source lang=apl inline>1</source> || {{Yes}} || {{No}} ||
|-
| [[And]]/[[LCM]] || <source lang=apl inline>∧</source> || <source lang=apl inline>0</source> || {{Yes}} || {{Yes}} ||
|-
| [[Or]]/[[GCD]] || <source lang=apl inline>∨</source> || <source lang=apl inline>1</source> || {{Yes}} || {{Yes}} ||
|-
| [[Less]] || <source lang=apl inline><</source> || <source lang=apl inline>0</source> || {{Yes}} || {{No}} || [[Boolean]]s only
|-
| [[Less Or Equal]] || <source lang=apl inline>≤</source> || <source lang=apl inline>1</source> || {{Yes}} || {{No}} || [[Boolean]]s only
|-
| [[Equal to]] || <source lang=apl inline>=</source> || <source lang=apl inline>1</source> || {{Yes}} || {{Yes}} || [[Boolean]]s only
|-
| [[Greater Or Equal]] || <source lang=apl inline>≥</source> || <source lang=apl inline>1</source> || {{No}} || {{Yes}} || [[Boolean]]s only
|-
| [[Greater]] || <source lang=apl inline>></source> || <source lang=apl inline>0</source> || {{No}} || {{Yes}} || [[Boolean]]s only
|-
| [[Not Equal]] || <source lang=apl inline>≠</source> || <source lang=apl inline>0</source> || {{Yes}} || {{Yes}} || [[Boolean]]s only
|-
| [[Reshape]] || <source lang=apl inline>⍴</source> || <source lang=apl inline>⍴P</source> || {{Yes}} || {{No}} ||
|-
| [[Catenate]] || <source lang=apl inline>,</source> || <source lang=apl inline>P⍴⍨ρ∘⊂⍨0,⍨¯1↓ρP</source> || {{Yes}} || {{No}} || <source lang=apl inline>1≤≢⍴Y</source>
|-
| [[Rotate]] || <source lang=apl inline>⌽</source> || <source lang=apl inline>0</source> or <source lang=apl inline>0⍴⍨¯1↓⍴P</source> || {{Yes}} || {{No}} ||
|-
| [[Rotate First]] || <source lang=apl inline>⊖</source> || <source lang=apl inline>0</source> or <source lang=apl inline>0⍴⍨1↓⍴P</source> || {{Yes}} || {{No}} ||
|-
| [[Transpose]] || <source lang=apl inline>⍉</source> || <source lang=apl inline>⍳≢⍴P</source> || {{Yes}} || {{No}} ||
|-
| [[Pick]] || <source lang=apl inline>⊃</source> || <source lang=apl inline>⍬</source> || {{Yes}} || {{No}} ||
|-
| [[Drop]] || <source lang=apl inline>↓</source> || <source lang=apl inline>⍬</source> or <source lang=apl inline>0×⍴P</source> || {{Yes}} || {{No}} ||
|-
| [[Take]] || <source lang=apl inline>↑</source> || <source lang=apl inline>⍬</source> or <source lang=apl inline>⍴P</source>|| {{Yes}} || {{No}} ||
|-
| [[Squad Indexing]] || <source lang=apl inline>⌷</source> || <source lang=apl inline>⍬</source> or <source lang=apl inline>⍳¨⍴P</source>|| {{Yes}} || {{No}} ||
|-
| [[Without]] || <source lang=apl inline>~</source> || <source lang=apl inline>0⌿P</source> || {{Yes}} || {{Yes}} || <source lang=apl inline>1≤≢⍴Y</source>
|-
| [[Matrix Divide]] || <source lang=apl inline>⌹</source> || <source lang=apl inline>∘.=⍨⍳≢P</source> || {{No}} || {{Yes}} ||
|-
| [[Encode]] || <source lang=apl inline>⊤</source> || <source lang=apl inline>0</source> || {{No}} || {{Yes}} ||
|-
| [[Union]] || <source lang=apl inline>∪</source> || <source lang=apl inline>0⌿P</source> || {{Yes}} || {{Yes}} || <source lang=apl inline>1≤≢⍴Y</source>
|-
| [[Replicate]] || <source lang=apl inline>/</source> || <source lang=apl inline>1</source> || {{Yes}} || {{No}} || <source lang=apl inline>1≤≢⍴Y</source>
|-
| [[Expand]] || <source lang=apl inline>\</source> || <source lang=apl inline>∘.=⍨⍳≢P</source> || {{Yes}} || {{No}} || <source lang=apl inline>1≤≢⍴Y</source>
|-
| [[Inner product]]s || <source lang=apl inline>+.×</source><br><source lang=apl inline>∨.∧</source> || <source lang=apl inline>∘.=⍨⍳≢P</source> || {{Yes}} || {{Yes}} ||
|-
| [[Inner product]] || <source lang=apl inline>∧.∨</source> || <source lang=apl inline>∘.≠⍨⍳≢P</source> || {{Yes}} || {{Yes}} ||
|}

== External links ==

* [[wikipedia:Identity element|Wikipedia]]

=== Documentation ===

* [http://help.dyalog.com/latest/#Language/Primitive%20Operators/Reduce.htm Dyalog APL]

* [https://www.ibm.com/downloads/cas/ZOKMYKOY#page=227 APL2]

{{APL programming language}}

Navigation menu