In [ ]:
x=: 3
In [ ]:
+: x
In [ ]:
+: +: x
In [ ]:
+: +: +: x
In [ ]:
-: x
In [ ]:
-: -: x
In [ ]:
+:^:2 x
In [ ]:
+:^:3 x
In [ ]:
+:^:0 1 2 3 4 x
In [ ]:
i=: 0 1 2 3 4
In [ ]:
+:^:i x
In [ ]:
v=: 3 4 5
In [ ]:
+: v
In [ ]:
+:^:i v
We will illustrate the use of the power operator on other functions, including the square (^&2), subtotals (+/), and permutations or anagrams (k&A.) .
Further information on any of these expressions may be found by pressing the function key F1 to display the vocabulary, and then clicking the mouse on the desired item:
In [ ]:
^&2 ^: i i
In [ ]:
+/\ ^: i i
In [ ]:
3&A.^: i i
In [ ]:
3&A.^: i 'ABCDE'
In [ ]:
!! i
In [ ]:
!! x:i
In [ ]:
^&2 ^: i x:i
A table of binomial coefficients is often presented as a triangle (Pascals triangle) by suppressing the zeros that result from the number of ways that n elements can be chosen from a lesser number of items. Thus:
```1```
```1 1```
```1 2 1```
```1 3 3 1```
```1 4 6 4 1```
A row of these coefficients can be simply obtained from the preceding row, as illustrated below:
In [ ]:
r2=: 1 2 1
In [ ]:
0,r2
In [ ]:
r2,0
In [ ]:
(0,r2)+(r2,0)
In [ ]:
next=: 0&, + ,&0
In [ ]:
next r2
In [ ]:
next 1
In [ ]:
next next 1
In [ ]:
bct=: next ^: i 1
In [ ]:
bct
In [ ]:
abct=: %. bct
In [ ]:
abct
In [ ]:
mp=: +/ . * NB. Matrix product
In [ ]:
bct mp abct
In [ ]:
+: ^: _1 i
In [ ]:
+: ^: _2 i
In [ ]:
+/\ ^: i i
In [ ]:
+/\ ^: (-i) 0 1 6 21 56
In [ ]:
Cos=: 2&o.
In [ ]:
0 1r4p1 1p1 3r4p1 2p1 NB. Multiples of pi
In [ ]:
Cos 0 1r4p1 1p1 3r4p1 2p1
In [ ]:
i=: 0 1 2 3 4
In [ ]:
Cos^:i 1
In [ ]:
k=: i.4 5
In [ ]:
k
In [ ]:
Cos^: k 1
In [ ]:
y=: Cos^: _ (1)
In [ ]:
y
In [ ]:
Cos y
In [ ]:
y=Cos y
In [ ]: