Intersection: Difference between revisions
Jump to navigation
Jump to search
m (Text replacement - "http://help.dyalog.com" to "https://help.dyalog.com") |
|||
Line 41: | Line 41: | ||
=== Documentation === | === Documentation === | ||
* [ | * [https://help.dyalog.com/latest/#Language/Primitive%20Functions/Intersection.htm Dyalog] | ||
* [http://microapl.com/apl_help/ch_020_020_394.htm APLX] | * [http://microapl.com/apl_help/ch_020_020_394.htm APLX] | ||
{{APL built-ins}}[[Category:Primitive functions]][[Category:Set functions]] | {{APL built-ins}}[[Category:Primitive functions]][[Category:Set functions]] |
Revision as of 14:43, 14 July 2020
∩
|
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" (X∊Y)/X
, which preserves the order and multiplicity in the left argument. Both arguments can be nested arrays.
'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│ └───┘
Extension
Some dialects allow Intersection to work on major cells:
X←4 2⍴'AABBCCCC' Y←3 2⍴'AABBAA' X∩Y AA BB
Works in: Extended Dyalog APL
Others can easily define such a function:
X←4 2⍴'AABBCCCC' Y←3 2⍴'AABBAA' Intersection←{⍺⌿⍨(≢⍵)≥⍵⍳⍺} X Intersection Y AA BB
Works in: Dyalog APL
External Links
Documentation