18. 顯性定義

下例句中:
   m=: '3 %: y.'
   d=: 'x.%: y.'
為討論文字構造所執行者,可套用顯性定義連接詞 : 以產生動詞:
   script=: 0 : 0
3 %: y.
:
x.%: y.
)

   roots=: 3 : script
   roots 27 4096
3 16

   4 roots 27 4096
2.27951 8
副詞與連接詞也可以顯性地定義。例如:
  表格=: 1 : 0
[ by ] over x./              Section 3的動詞 by  over 
)
  
   2 3 5 ^ 表格0 1 2 3
+-+----------+
| |0 1  2   3|
+-+----------+
|2|1 2  4   8|
|3|1 3  9  27|
|5|1 5 25 125|
+-+----------+
也可以用控制結構。例如:

f=: 3 : 0              
if. y.<0            
  do. *:y.             
  else. %:y.           
end. y.=. y.-1            
)
                 
   f"0 (_4 4)    
16 2                 
factorial=: 3 : 0
a=. 1
while. y.>1
do. a=. a*y.
end. a
)

   factorial"0 i. 6
1 1 2 6 24 120

練習

18.1   Experiment with與display 函數 roots=: 3 : script and 13 : script (which are equivalent).

18.2   See discussion of 控制結構 在dictionary, and use m in defining furr 動詞.

18.3   Experiment with expressions such as ! d b=: i.7 , after defining 副詞 d :
d=: 1 : 0
+:@x.
)
18.4   Using program pol from Exercise 14.2, perform following experiments與comment on ir results:

g=: 11 7 5 3 2 & pol
e=: 11 0 5 0 2 & pol
o=:  0 7 0 3 0 & pol
(g = e + o) b=: i.6
(e = e@-) b
(o = -@o@-) b
解答:函數 g is sum of 函數 e and o .Moreover, e is an even 函數 (whose graph is reflected 在vertical axis), and o is an odd 函數 (reflected 在origin).

18.5   Review Section H of Part II與 use scripts to make furr 明確定義.

18.6   Enter following 明確 定義 of 副詞 even and perform suggested experiments with it, using 函數 defined 在preceding exercise:
even=: 2 : 0
-:@(x.f. + x.f.@-)
)
ge=: g even
(e = ge) b
(e = e even) b
18.7   Define an 副詞 odd and use it 在 following experiments:
exp=: ^
sinh=: 5&o.
cosh=: 6&o.
(sinh = exp odd) b
(sinh = exp .: -) b            基本單字 odd 副詞 .: -
(cosh = exp even) b
(exp = exp even + exp odd) b
18.8   following experiments involve complex numbers, and should perhaps be ignored by anyone unfamiliar with m:
sin=: 1&o.
cos=: 2&o.
(cos = ^@j. even) b
(j.@sin = ^@j. odd) b

下個前個字彙索引主選單