Partition: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "{{APL built-ins}}" to "{{APL built-ins}}Category:Primitive functions")
m (Text replacement - "<source" to "<syntaxhighlight")
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Built-ins|Partition|⊆|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the non-negative integer left argument. This article uses <source lang=apl inline>⊆</source> to distinguish Partition from [[Partitioned Enclose]] (which is always <source lang=apl inline>⊂</source>), but the actual [[glyph]] used [[Migration level|varies by dialect]].
{{Built-ins|Partition|⊆|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the non-negative integer left argument. This article uses <syntaxhighlight lang=apl inline>⊆</syntaxhighlight> to distinguish Partition from [[Partitioned Enclose]] (which is always <syntaxhighlight lang=apl inline>⊂</syntaxhighlight>), but the actual [[glyph]] used [[Migration level|varies by dialect]].


On a vector right argument, the arguments must have the same length with each element in the left argument corresponding to an element in the right argument. Partition begins a new '''division''' of its right argument whenever a left argument element is greater than its neighbour on the left (with a 0 assumed to the left of the first element):
On a vector right argument, the arguments must have the same length with each element in the left argument corresponding to an element in the right argument. Partition begins a new '''division''' of its right argument whenever a left argument element is greater than its neighbour on the left (with a 0 assumed to the left of the first element):


[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qLdP/VHf1GBXvZRHbROqNQxtH3UufNS7S/NRx/JHvWvAnC1AvhVQEVABkJWSVqJg8Ki7BSKQkllcABSshQgAjdEAUuHB6uquZal5JerqGurqwanFxZn5eQFFmSABBXX1FHV1zUddi4EKnSOBvLS8YqCA@v///w0VDBWMYPBRV5u6R6ZrYlFJhjoA Try it online!]
[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qLdP/VHf1GBXvZRHbROqNQxtH3UufNS7S/NRx/JHvWvAnC1AvhVQEVABkJWSVqJg8Ki7BSKQkllcABSshQgAjdEAUuHB6uquZal5JerqGurqwanFxZn5eQFFmSABBXX1FHV1zUddi4EKnSOBvLS8YqCA@v///w0VDBWMYPBRV5u6R6ZrYlFJhjoA Try it online!]
<source lang=apl>
<syntaxhighlight lang=apl>
       1 1 2 2 2 2 2⊆'HiEarth'
       1 1 2 2 2 2 2⊆'HiEarth'
┌──┬─────┐
┌──┬─────┐
│Hi│Earth│
│Hi│Earth│
└──┴─────┘
└──┴─────┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
Right argument elements can be skipped by having their corresponding left argument element be 0:
Right argument elements can be skipped by having their corresponding left argument element be 0:
<source lang=apl>
<syntaxhighlight lang=apl>
       1 1 2 2 2 0 0⊆'HiEarth'
       1 1 2 2 2 0 0⊆'HiEarth'
┌──┬───┐
┌──┬───┐
│Hi│Ear│
│Hi│Ear│
└──┴───┘
└──┴───┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
In the case where the left argument is [[Boolean]], Partition splits its right argument on runs of 0s in the left argument, allowing a very short split-on-delimiter function:
In the case where the left argument is [[Boolean]], Partition splits its right argument on runs of 0s in the left argument, allowing a very short split-on-delimiter function:


[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qLdP/VHf1GBXvZRHbROqNQxtH3UufNS7S/NRx/JHvWvAnC1AvhVQEVABkJWSVqJg8Ki7BSKQkllcABSshQgAjdEAUuHB6uquZal5JerqGurqwanFxZn5eQFFmSABBXX1FHV1zUddi4EKnSOBvLS8YqCA@v///w0VQNBAAZU2fNTVpu6RX66QWJSqUJlfaq/OBTRF41HnAqDEo65FmqiSAA Try it online!]
[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qLdP/VHf1GBXvZRHbROqNQxtH3UufNS7S/NRx/JHvWvAnC1AvhVQEVABkJWSVqJg8Ki7BSKQkllcABSshQgAjdEAUuHB6uquZal5JerqGurqwanFxZn5eQFFmSABBXX1FHV1zUddi4EKnSOBvLS8YqCA@v///w0VQNBAAZU2fNTVpu6RX66QWJSqUJlfaq/OBTRF41HnAqDEo65FmqiSAA Try it online!]
<source lang=apl>
<syntaxhighlight lang=apl>
       1 1 1 0 1 1 1 0 1 1 1 1⊆'How are you?'
       1 1 1 0 1 1 1 0 1 1 1 1⊆'How are you?'
┌───┬───┬────┐
┌───┬───┬────┐
Line 31: Line 31:
│How│are│you?│
│How│are│you?│
└───┴───┴────┘
└───┴───┴────┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
== See also ==
* [[Partitioned Enclose]]
* [[Cut (K)]]
* [[Partition representations]]
==External links==
==External links==
===Tutorials===
===Tutorials===

Latest revision as of 22:18, 10 September 2022

Partition (, ) is a dyadic function which splits its right argument into differently sized pieces as determined by the non-negative integer left argument. This article uses to distinguish Partition from Partitioned Enclose (which is always ), but the actual glyph used varies by dialect.

On a vector right argument, the arguments must have the same length with each element in the left argument corresponding to an element in the right argument. Partition begins a new division of its right argument whenever a left argument element is greater than its neighbour on the left (with a 0 assumed to the left of the first element):

Try it online!

      1 1 2 2 2 2 2⊆'HiEarth'
┌──┬─────┐
│Hi│Earth│
└──┴─────┘
Works in: Dyalog APL

Right argument elements can be skipped by having their corresponding left argument element be 0:

      1 1 2 2 2 0 0⊆'HiEarth'
┌──┬───┐
│Hi│Ear│
└──┴───┘
Works in: Dyalog APL

In the case where the left argument is Boolean, Partition splits its right argument on runs of 0s in the left argument, allowing a very short split-on-delimiter function:

Try it online!

      1 1 1 0 1 1 1 0 1 1 1 1⊆'How are you?'
┌───┬───┬────┐
│How│are│you?│
└───┴───┴────┘
      ' '(≠⊆⊢)'How are you?'
┌───┬───┬────┐
│How│are│you?│
└───┴───┴────┘
Works in: Dyalog APL

See also

External links

Tutorials

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