Partitioned Enclose: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "<source" to "<syntaxhighlight")
m (Text replacement - "KAP" to "Kap")
 
(3 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.
:''In the [[APL2]] family and many related dialects, <syntaxhighlight lang=apl inline>⊂</syntaxhighlight> indicates [[Partition]].''
== Basic functionality ==
 
{{Built-in|Partitioned Enclose|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the left argument. It was introduced by [[NARS]] and appears in [[Dyalog APL]] and some newer dialects influenced by it.
== Description ==
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:
<syntaxhighlight lang=apl>
<syntaxhighlight lang=apl>
Line 7: Line 9:
│Hi│Earth│
│Hi│Earth│
└──┴─────┘
└──┴─────┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]], [[Extended Dyalog APL]]}}
{{Works in|[[Dyalog APL]], [[Extended Dyalog APL]]}}
== Non-Boolean left argument ==
=== 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:
Older 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>
<syntaxhighlight lang=apl>
       2 0 3 0 0 0 0⊂'HiEarth'
       2 0 3 0 0 0 0⊂'HiEarth'
Line 16: Line 18:
││Hi│││Earth│
││Hi│││Earth│
└┴──┴┴┴─────┘
└┴──┴┴┴─────┘
</source>
</syntaxhighlight>
== Short left argument ==
=== 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 [[indices#Inverse|where's inverse]]:
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>
<syntaxhighlight lang=apl>
Line 26: Line 28:
││Hi│││Earth│
││Hi│││Earth│
└┴──┴┴┴─────┘
└┴──┴┴┴─────┘
</source>
</syntaxhighlight>
== Long left argument ==
=== 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:
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>
<syntaxhighlight lang=apl>
Line 34: Line 36:
│Hi│Earth││
│Hi│Earth││
└──┴─────┴┘
└──┴─────┴┘
</source>
</syntaxhighlight>
 
== Split into lengths ==
== Split into lengths ==
This above extensions allow a simple definition of a split-into-lengths function:
The 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!]
Line 45: Line 48:
│How│Are│You?│
│How│Are│You?│
└───┴───┴────┘
└───┴───┴────┘
</source>
</syntaxhighlight>
 
== Extension support ==
The following table shows which of the extensions to <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> introduced by [[Dyalog APL 18.0]] are supported in various dialects. [[dzaima/APL]] doesn't support extended lengths but instead requires a short <syntaxhighlight lang=apl inline>⍺</syntaxhighlight>, assuming the first value is 1. This means it can't drop elements as the original Partitioned Enclose typically does, but also means it can't produce leading or trailing empty partitions.
{| class=wikitable
! Languages                !! Non-boolean !! Left argument length
|-
| [[NARS]]                  || {{No}}      || <syntaxhighlight lang=apl inline>=≢⍵</syntaxhighlight>
|-
| [[Dyalog APL]], [[April]] || {{Yes}}    || <syntaxhighlight lang=apl inline>≤1+≢⍵</syntaxhighlight>
|-
| [[dzaima/APL]]            || {{Yes}}    || <syntaxhighlight lang=apl inline>=¯1+≢⍵</syntaxhighlight> (first entry assumed 1)
|-
| [[Kap]] (<syntaxhighlight lang=apl inline>⊆</syntaxhighlight>) || {{Yes}}          || <syntaxhighlight lang=apl inline>=≢⍵</syntaxhighlight>
|}
 
== See also ==
== See also ==
* [[Partition]]
* [[Partition]]

Latest revision as of 21:33, 28 January 2024

In the APL2 family and many related dialects, indicates Partition.

Partitioned Enclose () is a dyadic function which splits its right argument into differently sized pieces as determined by the left argument. It was introduced by NARS and appears in Dyalog APL and some newer dialects influenced by it.

Description

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

Older 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

The 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?│
└───┴───┴────┘

Extension support

The following table shows which of the extensions to introduced by Dyalog APL 18.0 are supported in various dialects. dzaima/APL doesn't support extended lengths but instead requires a short , assuming the first value is 1. This means it can't drop elements as the original Partitioned Enclose typically does, but also means it can't produce leading or trailing empty partitions.

Languages Non-boolean Left argument length
NARS No =≢⍵
Dyalog APL, April Yes ≤1+≢⍵
dzaima/APL Yes =¯1+≢⍵ (first entry assumed 1)
Kap () Yes =≢⍵

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