g=: +`^ a=:< 2 a 3 1 2 [email protected] 3 8 3 [email protected] 2 5 +:`-:`*:`%: @. (4&|@<.)"0 i. 10 0 0.5 4 1.73205 8 2.5 36 2.64575 16 4.5The verb produced by [email protected] is often called a case or case statement, since it selects one of the "cases" of the gerund for execution.
c=:3 [ x=: 4 [ power=: _1 g/ c,x,power 3.25 3+x^_1 3.25The elements of the gerund are repeated as required. For example:
+`*/1,x,3,x,3,x,1 125The last sentence above corresponds to Horner's efficient evaluation of the polynomial with coefficients 1 3 3 1 and argument x .
Exercises
21.1 | Define a function f such that (x=: 4) f c=: 1 3 3 1
yields the result used as the argument to +`*/
in Horner's method. Answer: f=: }.@,@,. |