28. 單位函數與Neutral

單邊詞 0&+ 1&* 單位函數,而 0 與 1 分別稱為雙邊詞 + *單位原子neutrals。 對空白數列做插入動作,產生所插入動作的單位原子。例如:
   +/ i.0         +/''           +/0{. 2 3 5
0              0              0

   */i.0          */''           */0{. 2 3 5
1              1              1
這樣的結果對分區數列很有用;因為可以確保即使有子分區為空集合,運算結果也不會出錯。例如:

   +/ 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

單位函數與其他函數的基本特徵(例如 ) 可由副詞 b. 得到, 舉例如下:

   ^ b. _1     Inverse
^.

   ^ b. 0      Ranks
_ 0 0

   ^ b. 1      Identity 函數
$&1@(}.@$)


練習

28.1   Predict與test results of following expressions:
*/''
<./''
>./''
>./0 4 4 $ 0
+/ . */ 0 4 4 $ 0
1 2 3 4 +&.^./ 5 6 7 8
28.2   Experiment with 雙邊 {@; and give term used to describe it in mamatics.

解答:Cartesian product
 
28.3   Test assertion that 單邊 (%:@~. +/ . * =) and %: are equivalent,與state utility of former when applied to a list such as 1 4 1 4 2 that has repeated 分子.

解答:函數 %: (which could be a 函數 costly to execute) is applied only to distinct 分子 引數(as selected by nub 函數 ~.).
 
28.4   Comment on following experiments before reading comments on 右:

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 identity of 函數
a (f-:g) b f and g in a tautology (whose result is
taut=: f-:g always true;亦即, 1).

28.5   A 片語such as f-:g may be a tautology for 雙邊case only, for 單邊case only, or for both. Use following tautologies as reading與writing exercises, including statements of applicability (雙邊only, etc.):

t1=: >: -: > +. = (雙邊only) 基本單字 >: is identical to greater than or equal
t2=: <. -: -@>.&- (Both) Lesser-of is neg on greater-of on neg; 下整數is neg on 上整數on neg
t3=: <. -: >.&.- Same as t2 but uses under
t4=: *:@>: -: *: + +: + 1: (單邊) Square of a+1 is square of a plus twice a plus 1
t5=: *:@>: -: #.&1 2 1"0 Same as t4 using 多項式
t6=: ^&3@>: -: #.&1 3 3 1"0 Like t5 for cube
bc=: i.@>: ! ] Binomial係數
t7=: (>:@]^[) -: (]#.bc@[)"0 Like t6 with k&t7 for kth power
s=: 1&o. [. c=: 2&o. Sine與Cosine
t8=: s@+-:(s@[*c@])+(c@[*s@])   (雙邊) Addition與Subtraction
t9=: s@--:(s@[*c@])-(c@[*s@]) Formulas for sine
det=: -/ . * 行列式
perm=: +/ . * Permanent
sct=: 1 2&o."0@(,"0) Sine與cosine表格
t10=: s@- -: det@sct Same as t9 but using 行列式 of sin與cos表格
t11=: s@+ -: perm@sct Like t8 using permanent
S=: 5&o. [. C=: 6&o. Hyperbolic sine與cosine
SCT=: 5 6&o."0@(,"0) Sinh與Cosh表格
t12=: S@+ -: perm@SCT Addition orem for sinh
SINH=: ^ .: - Odd part of 指數
COSH=: ^ .. - Even part of 指數
t13=: SINH -: S Sinh is odd part of 指數
t14=: COSH -: C Cosh is even part of 指數
sine=: ^&.j. .: - Sine is odd part of 指數
t15=: sine -: s under multiplication by 0j1

28.6   Comment on following expressions before reading comments on 右:

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

下個前個字彙索引主選單