Intersection
Intersection (∩
) is a dyadic set function which computes the set intersection of the two vector arguments.
Examples
Both arguments of Intersection is usually restricted to vectors. Unlike sets in the mathematical sense, duplicate elements are allowed in both sides, and Intersection is usually implemented as "left argument filtered by its existence in the right argument" <syntaxhighlight lang=apl inline>(X∊Y)/X</source>, which preserves the order and multiplicity in the left argument. Both arguments can be nested arrays.
<syntaxhighlight lang=apl>
'ABRA'∩'CAR'
ARA
A←'THIS' 'AND' 'THAT' A∩'T' ⍝ (No match for the single character T) A∩'AND' ⍝ (No match for any of the three characters A N D) A∩⊂'AND'
┌───┐ │AND│ └───┘ </source>
Extension
Some dialects allow Intersection to work on major cells: Try it online!<syntaxhighlight lang=apl>
X←4 2⍴'AABBCCCC' Y←3 2⍴'AABBAA' X∩Y
AA BB
</source>
Others can easily define such a function: Try it online!<syntaxhighlight lang=apl>
X←4 2⍴'AABBCCCC' Y←3 2⍴'AABBAA' Intersection←{⍺⌿⍨(≢⍵)≥⍵⍳⍺} X Intersection Y
AA BB
</source>
External Links
Documentation