Chapter 15: Tacit Operators
J provides a number of built-in operators - adverbs and conjunctions. In Chapter 13 we looked at defining our own operators explicitly. In this chapter we look at defining adverbs tacitly.
15.2 Adverbs from Conjunctions
Recall from Chapter 07 the Rank conjunction, ("). For example, the verb (< " 0) applies Box (<) to each rank-0 (scalar) item of the argument.
< " 0 'abc' +-+-+-+ |a|b|c| +-+-+-+
The scheme is, that for a conjunction C and a noun N, the expression (C N) denotes an adverb such that:
x (C N) means x C N
The argument to be supplied to the conjunction can be a noun or a verb, and on the left or on the right. Altogether there are four similar schemes:
The sequences CN CV NC and CV are called "bidents". They are a form of bonding whereby we take a two-argument function and fix the value of one of its arguments to get a one-argument function. However, there is a difference between bonding a dyadic verb (as in + & 2 for example) and bonding a conjunction. With the conjunction, there is no need for a bonding operator such as &. We just write (" 0) with no intervening operator. The reason is that in the case of + & 2, omitting the & would give + 2 which means: apply the monadic case of + to 2, giving 2. However, conjunctions don't have monadic cases, so the bident (" 0) is recognised as a bonding.
Recall the "Under" conjunction &. from Chapter 08 whereby f&.g is a verb which applies g to its argument, then f then the inverse of g. If we take f and g to be:
f =: 'f' & , g =: >
then we see that f is applied inside each box:
15.3 Compositions of Adverbs
If A and B are adverbs, then the bident (A B) denotes an adverb which applies A and then B. The scheme is:
15.3.1 Example: Cumulative Sums and Products
There is a built-in adverb \ (backslash, called Prefix). In the expression f \ y the verb f is applied to successively longer leading segments of y. For example:
< \ 'abc' +-+--+---+ |a|ab|abc| +-+--+---+
The expression +/ \ y produces cumulative sums of y:
+/ \ 1 2 3 1 3 6
An adverb to produce cumulative sums, products, and so on can be written as a bident of two adverbs:
cum =: / \ NB. adverb adverb
15.3.2 Generating Trains
Now we look at defining adverbs to generate trains of verbs, that is, hooks or forks.
First recall from Chapter 14 the Tie conjunction (`), which makes gerunds, and the Evoke Gerund adverb (`: 6) which makes trains from gerunds.
Now suppose that A and B are the adverbs:
A =: * ` NB. verb conjunction B =: `: 6 NB. conjunction noun
Then the compound adverb
H =: A B
is a hook-maker. Thus <: H generates the hook * <: , that is "x times x-1"
It is possible to rewrite the definition of a verb to an equivalent form, by rearranging its terms. Suppose we start with a definition of the factorial function f. Factorial 5 is 120.
f =: (* ($: @: <:)) ` 1: @. (= 0:) f 5 120
The idea now is to rewrite f to the form $: adverb, by a sequence of steps. Each step introduces a new adverb. The first new adverb is A1, which has the form conj verb.
A1 =: @. (= 0:) g =: (* ($: @: <:)) ` 1: A1 g 5 120
Adverb A2 has the form conj verb
A2 =: ` 1: h =: (* ($: @: <:)) A2 A1 h 5 120
Adverb A3 has the form adv adv
A3 =: (* `) (`: 6) i =: ($: @: <:) A3 A2 A1 i 5 120
Adverb A4 has the form conj verb
A4=: @: <: j =: $: A4 A3 A2 A1 j 5 120
Combining A1 to A4:
A =: A4 A3 A2 A1 k =: $: A k 5 120
m =: $: (@: <:) (* `) (`: 6) (` 1:) (@. (= 0:)) m 5 120
We see that m and f are the same verb:
This is the end of Chapter 15.
Table of Contents
The examples in this chapter
were executed using J version 601 beta.
This chapter last updated 12 Jun 2006 .
Copyright © Roger Stokes 2006. This material may be freely reproduced, provided that this copyright notice is also reproduced.