Partitioned Enclose: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
mNo edit summary
m (Text replacement - "</source>" to "</syntaxhighlight>")
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Built-in|Partitioned Enclose|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the left argument.
{{Built-in|Partitioned Enclose|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the left argument.
 
== Basic functionality ==
In the simplest case, and on a vector right argument, the corresponding element in the left argument indicates where '''divisions''' begin:
In the simplest case, and on a vector right argument, the corresponding element in the left argument indicates where '''divisions''' begin:
<source lang=apl>
<syntaxhighlight lang=apl>
       1 0 1 0 0 0 0⊂'HiEarth'
       1 0 1 0 0 0 0⊂'HiEarth'
┌──┬─────┐
┌──┬─────┐
│Hi│Earth│
│Hi│Earth│
└──┴─────┘
└──┴─────┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]], [[Extended Dyalog APL]]}}
Almost all dialects restrict the left argument to provide only this functionality. However, the left argument can be interpreted as a count of how many partitions begin with a particular position:
== Non-Boolean left argument ==
<source lang=apl>
Almost all dialects restrict the left argument to provide only the above functionality. However, the left argument can be interpreted as a count of how many partitions begin with a particular position:
<syntaxhighlight lang=apl>
       2 0 3 0 0 0 0⊂'HiEarth'
       2 0 3 0 0 0 0⊂'HiEarth'
┌┬──┬┬┬─────┐
┌┬──┬┬┬─────┐
││Hi│││Earth│
││Hi│││Earth│
└┴──┴┴┴─────┘
└┴──┴┴┴─────┘
</source>
</syntaxhighlight>
Additional trailing empty divisions are thus created by adding an additional division count corresponding to the position beyond the end of the right argument:
== Short left argument ==
<source lang=apl>
The dialects that support this extension also allow omission of trailing zeros, which is useful if the partitioning vector is generated by [[indices#Inverse|where's inverse]]:
<syntaxhighlight lang=apl>
      ⍸⍣¯1⊢1 1 3 3 3
2 0 3
      2 0 3⊂'HiEarth'
┌┬──┬┬┬─────┐
││Hi│││Earth│
└┴──┴┴┴─────┘
</syntaxhighlight>
== Long left argument ==
Additional trailing empty divisions are created by adding an additional division count corresponding to the position beyond the end of the right argument:
<syntaxhighlight lang=apl>
       1 0 1 0 0 0 0 1⊂'HiEarth'
       1 0 1 0 0 0 0 1⊂'HiEarth'
┌──┬─────┬┐
┌──┬─────┬┐
│Hi│Earth││
│Hi│Earth││
└──┴─────┴┘
└──┴─────┴┘
</source>
</syntaxhighlight>
This interpretation allows a simple definition of a split-into-lengths function:
== Split into lengths ==
This above extensions allow a simple definition of a split-into-lengths function:


[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qLdP/VHf1GBXvZRHbROqNQxtH3UufNS7S/NRx/JHvWvAnC1AvhVQEVABkJWSVqJg8Ki7BSKQkllcABSshQgAjdEAUuHB6uquZal5JerqGurqwanFxZn5eQFFmSABBXX1FHV1zUddi4EKnSOBvLS8YqCA@v/ggpzMEpAjHvVuVXjU1fSod4XCo94dj3oXH1pvqKAdowCkHrVNNtQB2ff/v7GCsYKJAliTgrpHfrljUWpkfqm9OgA Try it online!]
[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qLdP/VHf1GBXvZRHbROqNQxtH3UufNS7S/NRx/JHvWvAnC1AvhVQEVABkJWSVqJg8Ki7BSKQkllcABSshQgAjdEAUuHB6uquZal5JerqGurqwanFxZn5eQFFmSABBXX1FHV1zUddi4EKnSOBvLS8YqCA@v/ggpzMEpAjHvVuVXjU1fSod4XCo94dj3oXH1pvqKAdowCkHrVNNtQB2ff/v7GCsYKJAliTgrpHfrljUWpkfqm9OgA Try it online!]
<source lang=apl>
<syntaxhighlight lang=apl>
       Split←{⍵ ⊂⍨ ⍸⍣¯1 +\ ¯1↓1,⍺}
       Split←{⍵ ⊂⍨ ⍸⍣¯1 +\ ¯1↓1,⍺}
       3 3 4 Split 'HowAreYou?'
       3 3 4 Split 'HowAreYou?'
Line 32: Line 45:
│How│Are│You?│
│How│Are│You?│
└───┴───┴────┘
└───┴───┴────┘
</source>
</syntaxhighlight>
{{Works in|[[Extended Dyalog APL]]}}
== See also ==
* [[Partition]]
* [[Cut (K)]]
* [[Partition representations]]
 
==External links==
==External links==
===Tutorials===
===Tutorials===
Line 39: Line 56:
===Documentation===
===Documentation===
* [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Functions/Partitioned%20Enclose.htm Dyalog]
* [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Functions/Partitioned%20Enclose.htm Dyalog]
{{APL built-ins}}
{{APL built-ins}}[[Category:Primitive functions]]

Revision as of 22:18, 10 September 2022

Partitioned Enclose () is a dyadic function which splits its right argument into differently sized pieces as determined by the left argument.

Basic functionality

In the simplest case, and on a vector right argument, the corresponding element in the left argument indicates where divisions begin:

      1 0 1 0 0 0 0⊂'HiEarth'
┌──┬─────┐
│Hi│Earth│
└──┴─────┘

Non-Boolean left argument

Almost all dialects restrict the left argument to provide only the above functionality. However, the left argument can be interpreted as a count of how many partitions begin with a particular position:

      2 0 3 0 0 0 0⊂'HiEarth'
┌┬──┬┬┬─────┐
││Hi│││Earth│
└┴──┴┴┴─────┘

Short left argument

The dialects that support this extension also allow omission of trailing zeros, which is useful if the partitioning vector is generated by where's inverse:

      ⍸⍣¯1⊢1 1 3 3 3
2 0 3
      2 0 3⊂'HiEarth'
┌┬──┬┬┬─────┐
││Hi│││Earth│
└┴──┴┴┴─────┘

Long left argument

Additional trailing empty divisions are created by adding an additional division count corresponding to the position beyond the end of the right argument:

      1 0 1 0 0 0 0 1⊂'HiEarth'
┌──┬─────┬┐
│Hi│Earth││
└──┴─────┴┘

Split into lengths

This above extensions allow a simple definition of a split-into-lengths function:

Try it online!

      Split←{⍵ ⊂⍨ ⍸⍣¯1 +\ ¯1↓1,⍺}
      3 3 4 Split 'HowAreYou?'
┌───┬───┬────┐
│How│Are│You?│
└───┴───┴────┘

See also

External links

Tutorials

Documentation

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
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 axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector