Collecting questions about J

Fraser Jackson writes on Thursday, May 25:

Quote:

> I agree that mean"1 m is clear and specific and the preferred form,

> but for many users it will be just as clear if we define advervbs ForRows

> and ForColumns and write

> mean ForRows m

> mean ForColumns m

If mean"1 is clear and specific and preferred, and shorter, why have

the circumlocutory and less general ForRows and ForColumns? Actually,

to me, ForRows and ForColumns are less clear, for reasons stated in

my original msg: to me, "ForColumns" is as ambiguous as "the mean of

the columns":

: For example, what exactly is "the mean of the columns of m"?

: I can think of two interpretations: (a) add column 0 to column

: 1 to column 2 ..., then divide by the number of columns. (b)

: for each column, add element 0 to element 1 to element 2 ...,

: then divide by the number of elements.

Quote:

> mean is a rather special verb because all of the components in its definition

> have infinite monadic rank.

No. The nice behaviour for "mean" is due to its having infinite rank;

the ranks of its components are irrelevant. That is, "mean" is defined

to work on arrays of any rank, and that makes it possible to apply "mean"

to cells of any rank, through mean"r .

Quote:

> median is naturally defined over a vector - and with a monadic rank of 1.

> For such a verb the simple solution does not work so neatly. Whereas

> mean m automatically finds the mean of columns for a matrix m

> median m now will not work. Of course median "1 m still finds the medians

> of the rows - making Roger's point but to find the median of the columns

> requires

> median "1 |: m

> for objects with rank greater than two the first step must be a general

> transposition to put the dimension across which the median is to be taken

> last. Thus to find the median across the first dimension of a rank 3 array

> we need

> median "1 (0)|: m

If median indeed has a "natural" monadic rank of 1, with defn med1 (say),

I would make an infinite rank version of it thus:

Then "median" can be used the same way as "mean"; in particular,

median"r applies median to the rank r cells.

Quote:

> This structure is valuable for many functions which do not have infinite

> monadic rank.

But many functions are easily defined to have infinite rank (i.e.

easily defined to work on arrays of any rank): for example, variance,

standard deviation, sum of squares, average (mean), moving average,

maximum, minimum, range, etc. For such functions f"r suffices, and

f"1|:a has little to recommend it.