Difference between revisions of "Identity element"
Miraheze>Adám Brudzewsky (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...") 
m (→Support: Use a more common name for Circle) 

(5 intermediate revisions by 4 users not shown)  
Line 4:  Line 4:  
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.  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.  
+  
+  If a function <source lang=apl inline>f</source> has both a left identity element and a right identity element (call them <source lang=apl inline>l</source> and <source lang=apl inline>r</source>), then they must be the same. This is because <source lang=apl inline>l f r</source> {{←→}} <source lang=apl inline>r</source>, since <source lang=apl inline>l</source> is a left identity, and <source lang=apl inline>l f r</source> {{←→}} <source lang=apl inline>l</source>, since <source lang=apl inline>r</source> is a right identity, so <source lang=apl inline>l</source> {{←→}} <source lang=apl inline>r</source>.  
== Reduction over a length0 axis ==  == Reduction over a length0 axis ==  
Line 39:  Line 41:  
 [[Power]]  <source lang=apl inline>*</source>  <source lang=apl inline>1</source>  {{No}}  {{Yes}}    [[Power]]  <source lang=apl inline>*</source>  <source lang=apl inline>1</source>  {{No}}  {{Yes}}   
    
−   [[  +   [[Circle function]]  <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}}    [[Binomial]]  <source lang=apl inline>!</source>  <source lang=apl inline>1</source>  {{Yes}}  {{No}}   
Line 77:  Line 79:  
 [[Take]]  <source lang=apl inline>↑</source>  <source lang=apl inline>⍬</source> or <source lang=apl inline>⍴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  +   [[Squad Index]]  <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>  {{  +   [[Without]]  <source lang=apl inline>~</source>  <source lang=apl inline>0⌿P</source>  {{No}}  {{Yes}}  <source lang=apl inline>1≤≢⍴Y</source> 
    
 [[Matrix Divide]]  <source lang=apl inline>⌹</source>  <source lang=apl inline>∘.=⍨⍳≢P</source>  {{No}}  {{Yes}}    [[Matrix Divide]]  <source lang=apl inline>⌹</source>  <source lang=apl inline>∘.=⍨⍳≢P</source>  {{No}}  {{Yes}}   
Line 106:  Line 108:  
* [https://www.ibm.com/downloads/cas/ZOKMYKOY#page=227 APL2]  * [https://www.ibm.com/downloads/cas/ZOKMYKOY#page=227 APL2]  
−  {{APL  +  {{APL features}} 
Revision as of 16:38, 27 March 2020
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 welldefined subset of the function's domain.
Contents
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 N≡N+0
and N≡0+N
for all arrays N
in the domain of +
. However, the identity of Divide (÷
), 1
, is only a right identity because while N≡N÷1
is true for all N
in the domain of ÷
, this isn't so for N≡1÷N
, and no alternative identity element value exists which would fulfil the condition.
If a function f
has both a left identity element and a right identity element (call them l
and r
), then they must be the same. This is because l f r
r
, since l
is a left identity, and l f r
l
, since r
is a right identity, so l
r
.
Reduction over a length0 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 twocolumn matrix with no rows is 0 0
:
+/0⍴0
0
+/0 2⍴0
0 0
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 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  
Circle function  ○ 
¯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 0⍴⍨1↓⍴P 
Yes  No  
Transpose  ⍉ 
⍳≢⍴P 
Yes  No  
Pick  ⊃ 
⍬ 
Yes  No  
Drop  ↓ 
⍬ or 0×⍴P 
Yes  No  
Take  ↑ 
⍬ or ⍴P 
Yes  No  
Squad Index  ⌷ 
⍬ or ⍳¨⍴P 
Yes  No  
Without  ~ 
0⌿P 
No  Yes  1≤≢⍴Y

Matrix Divide  ⌹ 
∘.=⍨⍳≢P 
No  Yes  
Encode  ⊤ 
0 
No  Yes  
Union  ∪ 
0⌿P 
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
Documentation
APL features [edit]  

Builtins  Primitive function ∙ Primitive operator ∙ Quad name 
Array model  Shape ∙ Rank ∙ Depth ∙ Bound ∙ Index ∙ Axis ∙ Ravel ∙ Ravel order ∙ Element ∙ Scalar ∙ Vector ∙ Matrix ∙ Simple scalar ∙ Simple array ∙ Nested array ∙ Box ∙ Cell ∙ Major cell ∙ Subarray ∙ Empty array ∙ Prototype 
Concepts and paradigms  Leading axis theory ∙ Scalar extension ∙ Conformability ∙ Scalar function ∙ Pervasion ∙ Glyph ∙ Identity element ∙ Total array ordering 
Errors  LIMIT ERROR ∙ RANK ERROR ∙ SYNTAX ERROR ∙ DOMAIN ERROR ∙ LENGTH ERROR ∙ INDEX ERROR ∙ VALUE ERROR 