Function Repository Resource:

SchroederSublistRank

Source Notebook

Rank a nested sublist

Contributed by: Ed Pegg Jr

ResourceFunction["SchroederSublistRank"][list]

returns the length of the flattened list and the simple nested sublist rank of list.

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 once interior braces are removed.
{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}}. These have ranks 1, 2, 3 and 4.
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.
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) 

Flatten a simple nested sublist and give its flattened length and sublist rank:

In[1]:=
ResourceFunction["SchroederSublistRank"][{1, {2}, {{3, {4}}, {{5}, {6}}}}]
Out[1]=

Different nestings give different ranks:

In[2]:=
ResourceFunction["SchroederSublistRank"][{1, {2}}]
Out[2]=
In[3]:=
ResourceFunction["SchroederSublistRank"][{{1}, 2}]
Out[3]=

Show flattened lengths and the ranks for all order-2 nested sublists:

In[4]:=
order2 = {{1, 2}, {1, {2}}, {{1}, 2}, {{1}, {2}}};
Grid[{order2, ResourceFunction["SchroederSublistRank"] /@ order2}, Frame -> All]
Out[5]=

Check the ranks of the 24 order-3 nested sublists:

In[6]:=
order3 = {{1, 2, 3}, {1, 2, {3}}, {1, {2}, 3}, {1, {2}, {3}}, {{1}, 2,
     3}, {{1}, 2, {3}}, {{1}, {2}, 3}, {{1}, {2}, {3}}, {1, {2, 3}}, {1, {2, {3}}}, {1, {{2}, 3}}, {1, {{2}, {3}}}, {{1}, {2, 3}}, {{1}, {2, {3}}}, {{1}, {{2},
      3}}, {{1}, {{2}, {3}}}, {{1, 2}, 3}, {{1, 2}, {3}}, {{1, {2}}, 3}, {{1, {2}}, {3}}, {{{1}, 2}, 3}, {{{1}, 2}, {3}}, {{{1}, {2}}, 3}, {{{1}, {2}}, {3}}};
Last[ResourceFunction["SchroederSublistRank"][#]] & /@ order3
Out[7]=

Scope (1) 

Get the rank for a long, deeply-nested sublist:

In[8]:=
ResourceFunction[
 "SchroederSublistRank"][{{1}, {{{2}, {3}, 4, {{5}, 6, 7}, {8}}, 9, {10, 11}}}]
Out[9]=

Properties and Relations (2) 

Show the growth of sublist ranks:

In[10]:=
val = Table[
  Last[ResourceFunction["SchroederSublistRank"][
    Partition[Range[a^2], a]]], {a, 2, 7}]
Out[10]=

Enumerate the number of sublists for each order:

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

Give the length and rank of the last nested sublist for each order:

In[12]:=
lastlists = {{1}, {{1}, {2}}, {{{1}, {2}}, {3}}, {{{{1}, {2}}, {3}}, {4}}, {{{{{1}, {2}}, {3}}, {4}}, {5}}, {{{{{{1}, {2}}, {3}}, {4}}, {5}}, {6}}, {{{{{{{1}, {2}}, {3}}, {4}}, {5}}, {6}}, {7}}, {{{{{{{{1}, {2}}, {3}}, {4}}, {5}}, {6}}, {7}}, {8}}};
Grid[{ResourceFunction["SchroederSublistRank"][#], #} & /@ lastlists]
Out[13]=

Possible Issues (1) 

SchroederSublistRank only works on simple sublist structures. The double list below is not supported:

In[14]:=
ResourceFunction["SchroederSublistRank"][{1, {{2}}}]
Out[14]=

Version History

  • 1.0.0 – 15 October 2025

Related Resources

License Information