 Slice - Maple Help

ListTools

 Slice
 slice a 1-D container into a sequence of sub-containers with the number of elements in each sub-container differing by at most one Calling Sequence Slice( Container, numslices, slicesreturned ) Parameters

 Container - container (list, set, or 1-D rtable), to be sliced into sub-containers numslices - positive integer, specifying the target number of sub-containers slicesreturned - (optional) positive or negative integer, or list/set of positive or negative integers, specifying which sub-containers are to be returned. The default is [seq(1..numslices)]. Description

 • The command slices a container into a sequence of sub-containers with the number of elements in each sub-container differing by at most one.
 • If not all the sub-containers are of the same length, the longer containers appear first.
 • Elements in the returned sequence of sub-containers appear in the same order as the original container.
 • If the specified number of sub-containers is greater than the number of elements in the original container, then the container is sliced into sub-containers of single elements, followed by empty sub-containers.
 • When the optional parameter slicesreturned is passed, only the specified sub-containers are computed and returned. Note that an error will be thrown if 0, or any number larger than numslices or smaller than -numslices, is passed. Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$ Example 1

 > $\mathrm{Slice}\left(\left[\right],1\right)$
 $\left[\right]$ (1)
 > $\mathrm{Slice}\left(\left[\right],2\right)$
 $\left[\right]{,}\left[\right]$ (2) Example 2

 > $L≔\left[a,b,c,d,e\right]$
 ${L}{≔}\left[{a}{,}{b}{,}{c}{,}{d}{,}{e}\right]$ (3)
 > $\mathrm{Slice}\left(L,1\right)$
 $\left[{a}{,}{b}{,}{c}{,}{d}{,}{e}\right]$ (4)
 > $\mathrm{Slice}\left(L,2\right)$
 $\left[{a}{,}{b}{,}{c}\right]{,}\left[{d}{,}{e}\right]$ (5)
 > $\mathrm{Slice}\left(L,3\right)$
 $\left[{a}{,}{b}\right]{,}\left[{c}{,}{d}\right]{,}\left[{e}\right]$ (6)
 > $\mathrm{Slice}\left(L,4\right)$
 $\left[{a}{,}{b}\right]{,}\left[{c}\right]{,}\left[{d}\right]{,}\left[{e}\right]$ (7)
 > $\mathrm{Slice}\left(L,5\right)$
 $\left[{a}\right]{,}\left[{b}\right]{,}\left[{c}\right]{,}\left[{d}\right]{,}\left[{e}\right]$ (8)
 > $\mathrm{Slice}\left(L,6\right)$
 $\left[{a}\right]{,}\left[{b}\right]{,}\left[{c}\right]{,}\left[{d}\right]{,}\left[{e}\right]{,}\left[\right]$ (9)
 > $\mathrm{Slice}\left(L,3,\left[1,3\right]\right)$
 $\left[{a}{,}{b}\right]{,}\left[{e}\right]$ (10)
 > $\mathrm{Slice}\left(L,3,2\right)$
 $\left[{c}{,}{d}\right]$ (11) Example 3

 > $S≔\left\{"a","b","c","d"\right\}$
 ${S}{≔}\left\{{"a"}{,}{"b"}{,}{"c"}{,}{"d"}\right\}$ (12)
 > $\mathrm{Slice}\left(S,3\right)$
 $\left\{{"a"}{,}{"b"}\right\}{,}\left\{{"c"}\right\}{,}\left\{{"d"}\right\}$ (13) Example 4

 > $V≔⟨\mathrm{seq}\left(1..12\right)⟩$ > $\mathrm{Slice}\left(V,3\right)$
 $\left[\begin{array}{c}{1}\\ {2}\\ {3}\\ {4}\end{array}\right]{,}\left[\begin{array}{c}{5}\\ {6}\\ {7}\\ {8}\end{array}\right]{,}\left[\begin{array}{c}{9}\\ {10}\\ {11}\\ {12}\end{array}\right]$ (14)
 > $\mathrm{Slice}\left(V,4,\left[1,-1\right]\right)$
 $\left[\begin{array}{c}{1}\\ {2}\\ {3}\end{array}\right]{,}\left[\begin{array}{c}{10}\\ {11}\\ {12}\end{array}\right]$ (15) Compatibility

 • The ListTools[Slice] command was introduced in Maple 2020.