7-5 The function in the sentence 7-5 applies to two 2 arguments to perform subtraction, but in the -5 sentence -5 it applies to a single argument to _5 perform negation. Adopting from chemistry the term valence, we say that the symbol - is ambivalent, its effective 7%5 binding power being determined by context. 1.4 %5 The ambivalence of - is familiar in arithmetic; 0.2 it is here extended to other functions. 3^2 9 ^2 Exponential (that is, 2.71828^2) 7.38906 a=: i. 5 The function integer or integer list a 0 1 2 3 4 List or vector a i. 3 1 The function index or index of 3 1 b=: 'Canada' Enclosing quotes denote literal characters b i. 'da' 4 1 $ a Shape function 5 3 4 $ a Reshape function 0 1 2 3 Table or matrix 4 0 1 2 3 4 0 1 3 4 $ b Cana daCa nada %a Functions apply to lists _ 1 0.5 0.333333 0.25 The symbol _ alone denotes infinity
Exercises
2.1 | Enter the following sentences (and perhaps related sentences
using different arguments), observe the results, and state what the two cases
(monadic and dyadic) of each function do:a=: 3 1 4 1 5 9 b=: 'Canada' #a 1 0 1 0 1 3 # a 1 0 1 0 1 3 # b /: a /: b a /: a a /: b b /: a b /: b c=: 'can''t' c #c c /: c | ||||||||||||||||||||||||||||||||||||||
2.2 | Make a summary table of the functions used thus far.
Then compare it with the following table (in which a bullet
separates the monadic case from the dyadic, as in Negate Subtract):
| ||||||||||||||||||||||||||||||||||||||
2.3 | Try to fill some of the gaps in the table of Exercise 2.2
by experimenting on the computer with appropriate expressions.
For example, enter ^.10 and ^. 2.71828
to determine the missing (monadic) case of ^. and
enter %: 4 and %: -4 and +%: -4
to determine the case of % followed by a colon. However, do not waste time on matters (such as, perhaps, complex numbers or the boxed results produced by the monad <) that are still beyond your grasp; it may be better to return to them after working through later sections. Note that the effects of certain functions become evident only when applied to arguments other than positive integers: try <.1 2 3 4 and <.3.4 5.2 3.6 to determine the effect of the monad <. . | ||||||||||||||||||||||||||||||||||||||
2.4 | If b=: 3.4 5.2 3.6 , then <.b
yields the argument b rounded down to the nearest integer.
Write and test a sentence that rounds the argument b to the
nearest integer. Answer: <.(b+0.5) or <.b+0.5 or <.b+1r2 | ||||||||||||||||||||||||||||||||||||||
2.5 | Enter 2 4 3 $ i. 5 to see an example of a
rank 3 array or report
(for two years of four quarters of three months each).
| ||||||||||||||||||||||||||||||||||||||
2.6 | Enter ?9 repeatedly and state what the
function ? does. Then enter t=: ?3 5 $ 9 to
make a table for use in further experiments. Answer: ? is a (pseudo-) random number generator; ?n produces an element from the population i.n |