In the
J programming language,
self-classify is the
informal name for the
mondadic case of
=. It (unsurprisingly) marks each element by the
equivalence class to which it belongs. It is closely tied to the concept of the
nub of its argument (found by using
~.), which is the vector found by
eliminating duplicates. An instructive example (user interaction
indented three spaces, as in the
interpreter):
]v=: 3 4 5 3 4 6 5 7 3
3 4 5 3 4 6 5 7 3
~. v
3 4 5 6 7
= v
1 0 0 1 0 0 0 0 1
0 1 0 0 1 0 0 0 0
0 0 1 0 0 0 1 0 0
0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0
We see that the result of the nub, is, in fact, the unique elements of v in order of first appearance.
The result of self-classify is a boolean two-dimensional array (matrix or table) in which each column indicates which member of the nub the element at a given index matches. In fact, an alternative formulation for = v is ~. v =/ v, literally ``the equals table for v's nub and itself.''
A tacit definition of the self-classify above, using a hook and the passive adverb:
sc =: =/~ ~.
sc v
1 0 0 1 0 0 0 0 1
0 1 0 0 1 0 0 0 0
0 0 1 0 0 0 1 0 0
0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0