Function Repository Resource:

# DepthLeafCountSort

Sort expressions by depth and leaf count

Contributed by: Jan Mangaldan (original work by Stephen Wolfram)
 ResourceFunction["DepthLeafCountSort"][list] sort a List of expressions list by depth and leaf count.

## Details and Options

ResourceFunction["DepthLeafCountSort"] effectively sorts based on the global structure of expressions, while Sort sorts "lexicographically," looking only at the "early parts" of expressions.
This is the method of sorting used to order theorems in A New Kind of Science, page 817.

## Examples

### Basic Examples (2)

Sort a List of expressions by depth and leaf count:

 In[1]:=
 Out[1]=

Generate a List of expressions:

 In[2]:=
 Out[2]=

Show the tree forms of the expressions:

 In[3]:=
 Out[3]=

Sort by depth and leaf count:

 In[4]:=
 Out[4]=

### Properties and Relations (2)

Sort sorts first by length, then based on lexicographic ordering:

 In[5]:=
 Out[5]=

DepthLeafCountSort sorts first by Depth then LeafCount:

 In[6]:=
 Out[6]=

Generate a List of expressions:

 In[7]:=
 Out[7]=

Sort uses a lexicographic ordering:

 In[8]:=
 Out[8]=

DepthLeafCountSort orders expressions by their depth and then by their leaf count:

 In[9]:=
 Out[9]=

An equivalent ordering using SortBy:

 In[10]:=
 Out[10]=

## Version History

• 1.0.0 – 01 October 2020