Membership: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
mNo edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Built-in|Membership|∊}}, also called '''Member Of''' or '''Member In''', is a [[dyadic]] [[primitive function]] which tests if each of the elements of the left [[argument]] appears as an element of the right argument. Membership derives from the traditional mathematical notation <math>\in</math> (''Element of'') and therefore uses that [[glyph]] (lunate epsilon).
{{Built-in|Membership|∊}}, also called '''Member In''', '''Member Of''', or '''Element Of''', is a [[dyadic]] [[primitive function]] which tests if each of the elements of the left [[argument]] appears as an element of the right argument. Membership derives from the traditional mathematical notation <math>\in</math> (''Element of'') and therefore uses that [[glyph]] (lunate epsilon).


== Examples ==
== Examples ==
Line 5: Line 5:
Both arguments can be arrays of any [[shape]]. Each element of the left argument is tested against elements of the right argument, and the result is a [[boolean]] array having the same shape as the left argument.
Both arguments can be arrays of any [[shape]]. Each element of the left argument is tested against elements of the right argument, and the result is a [[boolean]] array having the same shape as the left argument.


<source lang=apl>
<syntaxhighlight lang=apl>
       'THIS NOUN'∊'THAT WORD'
       'THIS NOUN'∊'THAT WORD'
1 1 0 0 1 0 1 0 0
1 1 0 0 1 0 1 0 0
Line 14: Line 14:
0 0 1
0 0 1
0 0 1
0 0 1
</source>
</syntaxhighlight>


For [[nested array|nested arrays]], Membership tests for exact [[match]] between the elements.
For [[nested array|nested arrays]], Membership tests for exact [[match]] between the elements.


<source lang=apl>
<syntaxhighlight lang=apl>
       'CAT' 'DOG' 'MOUSE' ∊ 'CAT' 'FOX' 'DOG' 'LLAMA'
       'CAT' 'DOG' 'MOUSE' ∊ 'CAT' 'FOX' 'DOG' 'LLAMA'
1 1 0
1 1 0
</source>
</syntaxhighlight>


=== Leading axis model ===
=== Leading axis model ===


The behavior of Membership was changed to follow [[leading axis model]] in some implementations such as [[J]] (spelled <source lang=j inline>e.</source>). In this case, if the right argument is a higher-[[rank]] array, the [[cell|cells]] of the left argument with appropriate rank are compared against the [[major cell|major cells]] of the right argument.
The behavior of Membership was changed to follow [[leading axis model]] in some implementations such as [[J]] (spelled <syntaxhighlight lang=j inline>e.</syntaxhighlight>). In this case, if the right argument is a higher-[[rank]] array, the [[cell|cells]] of the left argument with appropriate rank are compared against the [[major cell|major cells]] of the right argument.


<source lang=j>
<syntaxhighlight lang=j>
       ]mat=.>'able';'acre';'idle'
       ]mat=.>'able';'acre';'idle'
able
able
Line 42: Line 42:
1 1 1
1 1 1
1 1 1
1 1 1
</source>
</syntaxhighlight>
In other dialects, a leading axis membership function can be defined as:
In other dialects, a leading axis membership function can be defined as:
<source lang=apl>
<syntaxhighlight lang=apl>
       Membership←{(≢⍵)≥⍵⍳⍺}
       Membership←{(≢⍵)≥⍵⍳⍺}
       ⎕←mat←3 4⍴'ableacreidle'
       ⎕←mat←3 4⍴'ableacreidle'
Line 52: Line 52:
       'able' Membership mat
       'able' Membership mat
1
1
</source>{{Works in|[[Dyalog APL]], [[NARS2000]], [[dzaima/APL]], [[Extended Dyalog APL]], [[GNU APL]]}}
</syntaxhighlight>{{Works in|[[Dyalog APL]], [[NARS2000]], [[dzaima/APL]], [[Extended Dyalog APL]], [[GNU APL]]}}


== See also ==
== See also ==
Line 66: Line 66:
* [http://microapl.com/apl_help/ch_020_020_380.htm APLX]
* [http://microapl.com/apl_help/ch_020_020_380.htm APLX]
* J [https://www.jsoftware.com/help/dictionary/dedot.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/edot#dyadic NuVoc]
* J [https://www.jsoftware.com/help/dictionary/dedot.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/edot#dyadic NuVoc]
* [https://mlochbaum.github.io/BQN/doc/search.html#member-of BQN]


{{APL built-ins}}[[Category:Primitive functions]]
{{APL built-ins}}[[Category:Primitive functions]]

Latest revision as of 15:33, 11 January 2024

Membership (), also called Member In, Member Of, or Element Of, is a dyadic primitive function which tests if each of the elements of the left argument appears as an element of the right argument. Membership derives from the traditional mathematical notation (Element of) and therefore uses that glyph (lunate epsilon).

Examples

Both arguments can be arrays of any shape. Each element of the left argument is tested against elements of the right argument, and the result is a boolean array having the same shape as the left argument.

      'THIS NOUN'∊'THAT WORD'
1 1 0 0 1 0 1 0 0
      3 6 9∊3 3⍴⍳9
1 1 1
      (3 3⍴⍳9)∊3 6 9
0 0 1
0 0 1
0 0 1

For nested arrays, Membership tests for exact match between the elements.

      'CAT' 'DOG' 'MOUSE' ∊ 'CAT' 'FOX' 'DOG' 'LLAMA'
1 1 0

Leading axis model

The behavior of Membership was changed to follow leading axis model in some implementations such as J (spelled e.). In this case, if the right argument is a higher-rank array, the cells of the left argument with appropriate rank are compared against the major cells of the right argument.

      ]mat=.>'able';'acre';'idle'
able
acre
idle
      'able' e. mat
1
      (<'able') e. mat
0
      'ab' e. mat
0
      (3 3 4$'able') e. mat  NB. the resulting shape is trailing axes (corresponding to the major cells of mat) removed
1 1 1
1 1 1
1 1 1

In other dialects, a leading axis membership function can be defined as:

      Membership←{(≢⍵)≥⍵⍳⍺}
      ⎕←mat←3 4⍴'ableacreidle'
able
acre
idle
      'able' Membership mat
1

See also

External links

Documentation


APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector