Mask

In Iverson notation, Mask ($$/a,u,b/$$) is a three-argument operation which merges two arguments according to a Boolean array, all with matching shape. The relationship between Mask and Mesh is similar to that between Compress and Expand. The Case function can also be seen as a generalization of Mask. A related function also named Mask is implemented in NARS and NARS2000 as a case of Compose:  combines   and   along one axis using an integer vector, which is negative to indicate values from the left argument and positive to indicate values from the right, with absolute value giving the number of repetitions.

A Programming Language defines the Mask $$/a,u,b/$$ for vectors $$a$$ and $$b$$ and Boolean vector $$u$$, all of the same length, to be the vector $$c$$ whose compressions by $$u$$ and its negation match the compressions of the other arguments: $$\overline{u}/c=\overline{u}/a$$ and $$u/c=u/b$$. The definition of Mesh differs from this in that it doesn't compress $$a$$ and $$b$$, so that all elements from these arguments are used, while Mask discards half of the total elements. Various extensions are defined using compression on matrices, including $$/A,U,B/$$ and $$/\!/A,U,B/\!/$$, which are identical because (for example) $$U/B$$ and $$U/\!/B$$ select the same elements, only arranging them in a different order.

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} $$

For numeric arrays, Mask $$/A,U,B/$$ can be defined algebraically as  or , that is, a special case of linear interpolation. Similarly, possible implementations for Boolean arrays include  and.

The operation performed by Mask may be supported by dedicated instructions in SIMD programming, often called "blend" instructions.

Documentation

 * NARS2000