(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 ${\displaystyle /a,u,b/}$

In Iverson notation, Mask (${\displaystyle /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: L(a∘/)R combines L and R 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 ${\displaystyle /a,u,b/}$ for vectors ${\displaystyle a}$ and ${\displaystyle b}$ and Boolean vector ${\displaystyle u}$, all of the same length, to be the vector ${\displaystyle c}$ whose compressions by ${\displaystyle u}$ and its negation match the compressions of the other arguments: ${\displaystyle {\overline {u}}/c={\overline {u}}/a}$ and ${\displaystyle u/c=u/b}$. The definition of Mesh differs from this in that it doesn't compress ${\displaystyle a}$ and ${\displaystyle 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 ${\displaystyle /A,U,B/}$ and ${\displaystyle /\!/A,U,B/\!/}$, which are identical because (for example) ${\displaystyle U/B}$ and ${\displaystyle U/\!/B}$ select the same elements, only arranging them in a different order.

Iverson notes the following relationships between Mask, Mesh, Compress, and Expand:

{\displaystyle {\begin{aligned}/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{aligned}}}

For numeric arrays, Mask ${\displaystyle /A,U,B/}$ can be defined algebraically as (A×1-U)+B×U or A+U×B-A, that is, a special case of linear interpolation. Similarly, possible implementations for Boolean arrays include (A∧~U)∨B∧U and A≠U∧B≠A.

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