Implicit "tiled" extension?
Is this a thing in any language? Like if you were to add a 3x3 matrix and a 6x9 matrix, it seems logical (to me) for this to imply placing 6 copies of the 3x3 side by side to cover the 6x9. This is an error in most languages, so it's not like it would break or change the performance of existing code. Unless there's some non-obvious way it would cause problems?
Posted Sep 30, 2021, 12:01 AM UTC
33
You are right that this is a backwards-compatible extension.
However you have not justified it on its own merits. I certainly have never found apl's conformability rules lacking; but even if they were to be extended, I find this extension inconsistent.
First: it seems somewhat arbitrary to only consider arrays conformable each of whose axes is divisible by the corresponding axis of the other array. So we must also allow adding, for instance, a vector of length 2 to a vector of length 3, such that e.g. 1 2 + 100 200 300 -> 101 202 301.
This implies that all natural indices are valid for all (nonempty) arrays: arrays are extended cyclically to infinity. This is quite a convenient property, but it causes more important properties to stop holding.
We expect that (x + y)[i] is the same as x[i] + y[i] (where + is any scalar function). But if we apply this extension to array indexing, then 1 2[3] + 100 200 300[3] = 102, whereas 101 202 301[3] = 101. (Assuming an index origin of 0.)
Well, we chose somewhat arbitrarily that the shape of the result of a scalar function should be the maximum of the shapes of its operands. We could instead take the least common multiple, which would take care of that particular problem. But it should be clear at this point that, under this model, storing the shape of an array is an optimization, because conceptually arrays have all become infinite. The shape is just the minimum number of elements that we have to actually store in order to materialise arbitrary sections of an array. Some things that break (or bend) as a result:
Reshape
Catenate
Index-of
Where
I would much rather have an apl with reshape, catenate, index-of, and where than an apl where all arrays are infinite; and would prefer both to an inconsistent apl.
Good catch about that identity. Although if we only considered exact fits conformable, the identity isn't broken, is it? So it's actually not so arbitrary to do that. But I'm not sure it follows in the first place that treating some functions in this way means we'd treat indexing the same way. After all, scalars are extended for addition but not indexing. Of course J accepts negative indices to { but doesn't wrap around, which is either the best of both worlds or the worst.