Adverbs From Conjunctions A conjunction together with one of its arguments produces an adverb defined in an obvious way. For example, if a1=: &3, then ^ a1 is equivalent to ^&3 3 (the cube function), and if a2=: 3& then ^ a2 is equivalent to 3&^ (the three-to-the-power function). It is therefore easy to define useful families of adverbs from a conjunction, so easy that it is fruitless to attempt an exhaustive catalogue. The following list is intended to suggest the possibilities in various classes:
Explicit Definitions Especially for a beginner, it may be easier to read and write the definition of an adverb or conjunction in explicit form. In some cases a tacit definition is not possible; when it is it may be obtained from the explicit form by using the forms 11 : and 12 : instead of 1 : and 2 : for establishing the definitions. For example: |
split=: 2 : ',.@(x.@(y.&{.) ; x.@(y.&}.))' ]x=: i. 5 3 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 (+: split 2 ,. |. split 3 ,. +/ split 2) x +--------------------------+ �0 2 4 �6 7 8 �3 5 7 � �6 8 10 �3 4 5 � � � �0 1 2 � � +--------+--------+--------� �12 14 16�12 13 14�27 30 33� �18 20 22� 9 10 11� � �24 26 28� � � +--------------------------+ tacitsplit=: 12 : ',.@(x.@(y.&{.) ; x.@(y.&}.))' split 2 : ',.@(x.@(y.&{.) ; x.@(y.&}.))' tacitsplit ,. @ (([. @ (]. & {.)) ; ([. @ (]. & }.)))
Note that none of the spaces in the display of tacitsplit are required.
Noun Arguments Adverbs that apply to a noun argument, and conjunctions that apply to one noun argument and one verb argument are commonplace. For example: |
x=: 0 0 1 1 [ y=: 0 1 0 1 x *. y Boolean and 0 0 0 1 x 1 b. y Boolean adverb 0 0 0 1 x (i.16) b. y All sixteen Boolean functions 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 C=: &o. Circle adverb 1 C 0 1r4p1 1r3p1 1r2p1 1p1 Sine function 0 0.7071068 0.8660254 1 0 ^&3 x=: i. 6 Cube 0 1 8 27 64 125 2 |. !. 1 x Shift in ones 2 3 4 5 1 1
Conjunctions that apply to two nouns are less familiar, although the definitions of functions in terms of nouns occur frequently in math. For example, a rational function (the quotient of a polynomial a&p. divided by another b&p.) is defined by a pair of coefficients. Thus: |
a=: 1 4 6 4 1 [ b=: 1 2 1 RAT=: [. & p. % (]. & p.) a RAT b 1 4 6 4 1&p. % 1 2 1&p. a RAT b y=: i.6 1 4 9 16 25 36 b RAT a y 1 0.25 0.111111 0.0625 0.04 0.0277778 (a RAT b * b RAT a) y 1 1 1 1 1 1
We may also remark that expressions such as 2 x3 and 2 x3 + 4 x2 are commonly used in elementary math to define functions rather than to indicate explicit computation: the x in the foregoing can be construed (and defined) as a conjunction such that 2 x 3 is the function 2:*]^3: . Thus: |
x=: [.&* @ (^&].)"0 2 x 3 2&*@(^&3)"0 2 x 3 y=: 0 1 2 3 4 5 0 2 16 54 128 250 2 * y ^ 3 0 2 16 54 128 250 2 3 5 x 1 2 4 y 0 0 0 2 3 5 4 12 80 6 27 405 8 48 1280 10 75 3125
The last result above gave the values of the individual terms; in order to obtain their sums (and yet retain the behaviour for a single term), we redefine the conjunction x as follows: |
x=: +/@([.&*@ (^&].))"0 2 3 5 x 1 2 4 y 0 10 96 438 1336 3210 (2 x 1 + 3 x 2 + 5 x 4) y 0 10 96 438 1336 3210 2 x 3 y 0 2 16 54 128 250
It is often convenient to bind an argument to a monad, producing a function that ignores its argument. For example, using wdinfo, a monad that displays its argument in a message box, the definition fini=: wdinfo bind 'Job Finished' produces a function such that fini'' is equivalent to wdinfo 'Job Finished'. |