>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Voc  !:  Help  Dictionary

27. Identity Functions and Neutral

The monads 0&+ and 1&* are identity functions, and 0 and 1 are said to be identity elements or neutrals of the dyads + and * respectively. Insertion on an empty list yields the neutral of the dyad inserted. For example:
```   +/ i.0         +/''           +/0{. 2 3 5
0              0              0

*/i.0          */''           */0{. 2 3 5
1              1              1
```
These results are useful in partitioning lists; they ensure that certain obvious relations continue to hold even when one of the partitions is empty. For example:
```   +/ a=: 2 3 5 7 11
28

(+/4{.a)+(+/4}.a)
28

(+/0{.a)+(+/0}.a)
28

*/a
2310

(*/4{.a)*(*/4}.a)
2310

(*/0{.a)*(*/0}.a)
2310
```
The identity functions and other basic characteristics of functions (such as rank) are given by the adverb b. , as illustrated below:
```   ^ b. _1     Inverse
^.

^ b. 0      Ranks
_ 0 0

^ b. 1      Identity function
\$&1@(}.@\$)
```

Exercises

27.1   Predict and test the results of the following expressions:
```*/''
<./''
>./''
>./0 4 4 \$ 0
+/ . */ 0 4 4 \$ 0
1 2 3 4 +&.^./ 5 6 7 8
```
27.2   Experiment with the dyad {@; and give the term used to describe it in mathematics.

27.3   Test the assertion that the monads (%:@~. +/ . * =) and %: are equivalent, and state the utility of the former when applied to a list such as 1 4 1 4 2 that has repeated elements.

Answer: The function %: (which could be a function costly to execute) is applied only to the distinct elements the argument (as selected by the nub function ~.).

27.4   Comment on the following experiments before reading the comments on the right:

 a=: 2 3 5 [ b=: 1 2 4 a (f=: *:@+) b Square of sum a (g=: +&*: + +:@*) b Sum of squares plus double product a (f=g) b Expression of the identity of the functions a (f-:g) b f and g in a tautology (whose result is taut=: f-:g always true; that is, 1).

27.5   A phrase such as f-:g may be a tautology for the dyadic case only, for the monadic case only, or for both. Use the following tautologies as reading and writing exercises, including statements of applicability (Dyad only, etc.):

 t1=: >: -: > +. = (Dyad only) The primitive >: is identical to greater than or equal t2=: <. -: -@>.&- (Both) Lesser-of is neg on greater-of on neg; Floor is neg on ceiling on neg t3=: <. -: >.&.- Same as t2 but uses under t4=: *:@>: -: *: + +: + 1: (Monad) Square of a+1 is square of a plus twice a plus 1 t5=: *:@>: -: #.&1 2 1"0 Same as t4 using polynomial t6=: ^&3@>: -: #.&1 3 3 1"0 Like t5 for cube bc=: i.@>: ! ] Binomial coefficients t7=: (>:@]^[) -: (]#.bc@[)"0 Like t6 with k&t7 for kth power s=: 1&o. Sine c=: 2&o. Cosine t8=: s@+-:(s@[*c@])+(c@[*s@]) (Dyad) Addition and Subtraction t9=: s@--:(s@[*c@])-(c@[*s@]) Formulas for sine det=: -/ . * Determinant perm=: +/ . * Permanent sct=: 1 2&o."0@(,"0) Sine and cosine tables t10=: s@- -: det@sct Same as t9 but using the determinant of the sin and cos table t11=: s@+ -: perm@sct Like t8 using the permanent S=: 5&o. Hyperbolic sine C=: 6&o. Hyperbolic cosine SCT=: 5 6&o."0@(,"0) Sinh and Cosh table t12=: S@+ -: perm@SCT Addition theorem for sinh SINH=: ^ .: - Odd part of exponential COSH=: ^ .. - Even part of exponential t13=: SINH -: S Sinh is odd part of exponential t14=: COSH -: C Cosh is the even part of exponential sine=: ^&.j. .: - Sine is the odd part of exponential t15=: sine -: s under multiplication by 0j1

27.6   Comment on the following expressions before reading the comments on the right:

 g=: + > >. Test if sum exceeds maximum 5 g 2 True for positive arguments 5 g _2 _1 0 1 2 but not true in general f=: *.&(0&<) Test if both arguments exceed 0 theorem=: f <: g The truth value of the result of f does not exceed that of g . This may also be stated as “if f (is true) then g (is true)” or as “f implies g” 5 theorem _2 _1 0 1 2

>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Voc  !:  Help  Dictionary