Next: , Previous: , Up: k9: Manual  


9 Named Functions

This chapter covers the built-in named functions. This includes some math (eg. sqrt but not +), wrapper (eg. count for #) and range (eg. within) functions.

count first last min max sum dot avg var [dev med mode countd ..]
sqrt sqr exp log sin cos div mod bar in 

9.1 count ⇒ count x

Same as count.

 count 5 1 2
3

9.2 first ⇒ first x

Same as first.

 first 5 1 2
5

9.3 last ⇒ last x

Retrieve the last element of list x.

 last 5 1 2
2

9.4 min ⇒ min x

Retrieve the minimum element of list x. Same as |/.

 min 5 1 2
1

9.5 max ⇒ max x

Retrieve the maximum element of list x. Same as &/.

 max 5 1 2
5

9.6 sum ⇒ sum x

Compute the sum of list x. Same as +/.

 sum 5 1 2
8

9.7 dot ⇒ dot x

Compute the dot product of list x. Same as +/x*x.

 dot 1.2 1.3 1.4
5.09

 {+/x*x} 1.2 1.3 1.4
5.09

9.8 avg ⇒ avg x

Compute the average of list x. Same as +/x%#x.

 avg 2 4 7 10
5.75

 {+/x%#x} 2 4 7 10
5.75

9.9 var ⇒ var x

Compute the variance of list x.

 var !10
8.25

 {(+/x*x:x-avg x)%#x}@!10
8.25

9.10 dev ⇒ dev x

TBD

9.11 med ⇒ med x

TBD

9.12 mode ⇒ mode x

TBD

9.13 countd ⇒ countd x

TBD

9.14 exp ⇒ exp x

Compute the exponent of x, i.e. ex.

 exp 1
2.718282

9.15 log ⇒ log x

Log computes the natural log.

 log 10
2.302585

9.16 sin ⇒ sin x

sin computes the sine of x where x is in radians.

 sin 0
0f
 sin 3.1416%2
1.

9.17 cos ⇒ cos x

cos computes the cosine of x where x is in radians.

 cos 0
1f
 cos 3.1416%4
0.7071055

9.18 sqr ⇒ sqr x

Compute the square of x.

 sqr 2
4.0

9.19 prm ⇒ prm x

Write out all permutations of integers up x-1. Display them as columns.

 prm 3
0 1 1 0 2 2
1 0 2 2 0 1
2 2 0 1 1 0

9.20 sums ⇒ sums x

Compute the running sum of list x. Sames as +\.

 sums !10
0 1 3 6 10 15 21 28 36 45

9.21 deltas ⇒ deltas x and x deltas y

Compute the difference between each element in list x and the previous value. If delta is called with two parameters then x will be used as the first value to delta instead of the default 0.

 deltas 1 5 10
1 4 5

 1 deltas 1 5 10
0 4 5

9.22 has ⇒ x has y

Determine whether vector x has element y. Simliar to in but with the arguments reversed.

 `a`b`c`a`b has `a
1b

`a`b`c`a`b has `d
0b

 `a`b`c`a`b has `a`b`x`y`z
11000b

 (1 2;4 5 6;7 9)has(1 2;8 9)
10b

9.23 bin ⇒ x bin y

Given a sorted (increasing) list x, find the greatest index, i, where y>x[i].

 n:exp 0.01*!5;n
1 1.01005 1.020201 1.030455 1.040811
 n bin 1.025
3

9.24 in ⇒ x in y

Determine if x is in list y. Similar to has but arguments reversed.

 `b in `a`b`d`e
1b
 `c in `a`b`d`e
0b

9.25 within ⇒ x within y

Test if x is equal to or greater than y[0] and less than y[1].

 3 within 0 12
1b

0 within 0 12
1b

12 within 0 12
0b

23 within 0 12
0b

9.26 bar ⇒ x bar y

For each value in y determine the maximum multiple of x that is less than or equal to each y.

 10 bar 9 10 11 19 20 21
0 10 10 10 20 20

9.27 msum ⇒ x msum y

Compute the length x moving sum of list y.

 3 msum !10
0 1 3 6 9 12 15 18 21 24

9.28 mavg ⇒ x mavg y

Compute the length x moving average of list y.

 3 mavg !10
0 0.3333333 1 2 3 4 5 6 7 8

Next: Knit Functions, Previous: Expression Evaluation, Up: k9: Manual