Function Repository Resource:

SchroederSublistByRank

Source Notebook

Transform a flat list into a nested sublist with a given structure rank

Contributed by: Ed Pegg Jr

ResourceFunction["SchroederSublistByRank"][list,rank]

returns sublists containing the elements of list and nested according to rank.

ResourceFunction["SchroederSublistByRank"][list,{len,rank}]

returns list with length len as the nested sublist with the given rank.

Details

Arbitrary expressions other than lists are supports as elements. In other words, {"An", "element is anything", "that can be in", {"a", list}, "such as numbers:", 1, 2, "strings or variables like", x, "."}
The length of a flattened list is the total number of elements.
ResourceFunction["SchroederSublistByRank"] only supports simple sublists. {1,1}, {1,{1}}, {{1},1} and {{1},{1}} are simple order-2 nested sublist structures. Elements of the form {}, {{1}} are forbidden in a simple sublist. The elements can be changed: {a,a}, {a,{a}}, {{a},a} and {{a},{a}}.
The function 2n Hypergeometric2F1[-n,n+1,2,-1] or 1, 4, 24, 176, 1440, 12608, 115584, … (A156017) enumerates the number of simple nested sublists. Nested sublists have a 1-to-1 correspondence with 2-rise 2-color Schroeder paths, hence the term Schroeder rank. Giving a rank larger than this limit results in a $Failed output.
In a list structure, braces must be balanced. Double commas and hanging commas are disallowed. {,1,2} has a hanging comma at the start and {1,2,} has a hanging comma at the end. A list contains elements and balanced braces.

Examples

Basic Examples (4) 

Build a simple nested sublist from a given sublist rank:

In[1]:=
ResourceFunction["SchroederSublistByRank"][Range[6], 1000]
Out[1]=

The length of the list may also be given:

In[2]:=
ResourceFunction["SchroederSublistByRank"][Range[6], {6, 1000}]
Out[2]=

Show the order-2 simple nested sublists:

In[3]:=
Table[ResourceFunction["SchroederSublistByRank"][{a, b}, k], {k, 1, 4}]
Out[3]=

Show the order-3 simple nested sublists:

In[4]:=
Table[ResourceFunction["SchroederSublistByRank"][Range[3], k], {k, 1, 24}]
Out[4]=

Show the order-3 simple nested sublists with their ranks:

In[5]:=
Row[Grid[#, Frame -> All] & /@ Partition[{#, ResourceFunction["SchroederSublistByRank"][{1, 2, 3}, #]} & /@ Range[24], 8]]
Out[5]=

Scope (1) 

Create a nested sublist that may be tedious to input by hand:

In[6]:=
ResourceFunction["SchroederSublistByRank"][Range[11], {11, 387420489}]
Out[6]=

Properties and Relations (2) 

Do a Partition the hard way:

In[7]:=
ResourceFunction["SchroederSublistByRank"][Range[3^2], 5492225]
Out[7]=

Enumerate the number of sublists for each order:

In[8]:=
vals = Table[2^n Hypergeometric2F1[-n, n + 1, 2, -1], {n, 0, 7}]
Out[8]=

Show the last nested sublist for each order:

In[9]:=
Column[MapIndexed[
  ResourceFunction["SchroederSublistByRank"][Range[#2[[1]]], #1] &, vals]]
Out[9]=

Possible Issues (1) 

The list should have the same length as the specified list length:

In[10]:=
ResourceFunction["SchroederSublistByRank"][Range[4], {5, 1}]
Out[10]=

Version History

  • 1.0.0 – 15 October 2025

Related Resources

License Information