= y (Self-Classify)
A boolean table relating a given vector to its Nub (~.).
z=: 'abracadabra' ~.z NB. Nub z abrcd =z 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
Tabulated, we see the equalities clearer:
┌─┬─────────────────────┐ │=│a b r a c a d a b r a│ ├─┼─────────────────────┤ │a│1 0 0 1 0 1 0 1 0 0 1│ │b│0 1 0 0 0 0 0 0 1 0 0│ │r│0 0 1 0 0 0 0 0 0 1 0│ │c│0 0 0 0 1 0 0 0 0 0 0│ │d│0 0 0 0 0 0 1 0 0 0 0│ └─┴─────────────────────┘
Comparing Self-Classify with Table (/) we see that =z is the "equal-table" of z with repeated rows deleted (i.e. the Nub).
~. z=/z NB. Nub of: z =/ z 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
Common uses
An early feature of J, giving way to more powerful primitives. Not often used, except for visualising data, if you happen to find it helpful.
1. Count the occurrences of each distinct letter in a string.
+/"1 =z NB. sum the rows of: =z 5 2 2 1 1
See Also
x = y (Equal)
The boolean result of comparing two items, or lists of items.
See the J Dictionary for the tolerance rules governing equality between numbers. By default the tolerance is 2^_44 when recognising two numbers as being "equal" under =.
]z=: i.5 0 1 2 3 4 3 = z 0 0 0 1 0 z = z 1 1 1 1 1 z = |.z 0 0 1 0 0
Equal works between boxed items too:
z=: 'alpha' ; 'bravo' ; 'charlie' z = |.z 0 1 0 z = <'bravo' 0 1 0
To avoid x=y giving length error, the Shape Of ($) x and y must follow the rules for Plus (+).
Common uses
1. To construct criteria for conditional expressions in verb definitions
if. LF = {:z do. }:z end. NB. drop trailing LF if it's there2. To construct boolean vectors to work with strings.
z=: 'alpha bravo charlie' ]b=: z=' ' 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 ]i=: I.b 5 11 ]identifier=: '_' i } z alpha_bravo_charlie
See Also
Not-Equal (~:)
