Function Repository Resource:

NextIntegerPartition

Source Notebook

Get the next partition of an integer in reverse lexicographic order

Contributed by: Sriram V. Pemmaraju and Steven S. Skiena, with contributions by Wolfram Staff

ResourceFunction["NextIntegerPartition"][p]

gives the integer partition following p in reverse lexicographic order.

Examples

Basic Examples (1) 

The partition of an integer following the given one in the reverse lexicographic order:

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

Properties and Relations (2) 

NextIntegerPartition[p] gives the successor to the integer partition p in the list returned by IntegerPartitions:

In[2]:=
ResourceFunction["NextIntegerPartition"][{5}]
Out[2]=
In[3]:=
IntegerPartitions[5]
Out[3]=

Applying NextIntegerPartition to a partition of all ones loops back to the singleton partition:

In[4]:=
ResourceFunction["NextIntegerPartition"][{1, 1, 1, 1, 1}]
Out[4]=

Possible Issues (2) 

The integer partition must be a list of non-increasing positive integers:

In[5]:=
ResourceFunction["IntegerPartitionQ"][{3, 2, 1, 5, 7}]
Out[5]=

As the input fails to meet the requirement, NextIntegerPartition returns unevaluated:

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

Version History

  • 1.0.1 – 17 April 2023
  • 1.0.0 – 02 March 2020

Related Resources

License Information