Mesh

In Iverson notation, Mesh ($$\backslash{}a,u,b\backslash$$) is a three-argument operation which merges two equal-rank arguments according to a Boolean vector. The relationship between Mask and Mesh is similar to that between Compress and Expand. A related function also named Mesh is implemented in NARS and NARS2000 as a case of Compose:  combines   and   using an integer (not Boolean) control vector. Bob Bernecky has suggested the syntax  (requiring Expand to be an operator) for $$\backslash{}a,u,b\backslash$$.

In Iverson notation
Mesh in Iverson notation combines or interleaves two arguments according to a Boolean control. The result has the same shape as the control array, and contains entries taken from the left argument when the control is 0 and from the right when it is 1.

A Programming Language defines the Mesh $$\backslash{}a,u,b\backslash$$ for vectors $$a$$ and $$b$$ and Boolean vector $$u$$, where $$+/\overline{u}=\nu(a)$$, and $$+/u=\nu(b)$$, to be the vector $$c$$ whose compressions by $$u$$ and its negation yield the other arguments: $$\overline{u}/c=a$$ and $$u/c=b$$. Conformability requirements give $$\nu(c)=\nu(u)$$; because $$\nu(u)=(+/\overline{u})+(+/u)$$ we have $$\nu(c)=\nu(a)+\nu(b)$$.

Mesh $$\backslash{}a,u,b\backslash$$ is a generalization of Catenate $$a\oplus b$$, since meshing with a suffix vector $$\backslash{}a,\omega^{\nu(b)},b\backslash$$ produces $$a\oplus b$$.

Iverson notes the following relationships between Mask, Mesh, Compress, and Expand: $$ \begin{align} /a,u,b/ &= \backslash{}\overline{u}/a,u,u/b\backslash \\ \backslash{}a,u,b\backslash &= /\overline{u}\backslash{}a,u,u\backslash{}b/ \end{align} $$

The following forms of Mesh with matrices are defined. Below, matrices are denoted with capital letters while vectors use lowercase letters.

APL models
In all APLs, $$/a,u,b/$$ for vectors $$a$$, $$b$$, and $$u$$ can be implemented using the ordinal idiom consisting of two copies of Grade: These solutions were published in 1971 by Bob Smith, who attributes them to Luther Woodrum by way of Ken Iverson. They also appear in the FinnAPL idiom library. The idea is that every element of  and   should be included in the final result, but they are ordered based on , so that elements of   correspond to 0s and those of   correspond to 1s. Given such a vector, sorting it according to, or equivalently, permuting by the Grade of  , would return it to the separated vector. It follows that applying the inverse permutation  of   transforms   into the meshed vector.

Another, more straightforward strategy uses selective assignment and Expand. It creates a temporary vector, placing elements of   in the appropriate positions with Expand, and then inserts elements of   in the appropriate positions by assigning to the Compress of. The two steps can be reversed, as long as  is paired with   and   is paired with. Structural Under allows the assignment to be performed in a functional style, with no temporary variable. For example, in dzaima/APL, which implements Structural Under but not Expand, admits this implementation: Here any vector of the same length could be used in place of.

If Mask is available, for instance as a monadic operator, then Mesh can be obtained by masking together the expansion of each argument: Depending on available language facilities, this idea can be realized in a few different ways. Here the expressions which use indexing must have the index origin set to 0.

Documentation

 * NARS2000