Function Repository Resource:

IntegerPartitionQ

Source Notebook

Check whether the argument is a weakly decreasing list of positive integers

Contributed by: Wolfram Staff

ResourceFunction["IntegerPartitionQ"][x]

checks whether x is a weakly decreasing list of positive integers.

ResourceFunction["IntegerPartitionQ"][x,n]

checks whether x is an integer partition of n.

Details

An integer partition is a multiset of positive integers and so not ordered. Therefore, any order can be used to represent it. Typically, the order chosen is weakly decreasing, as here; some people choose weakly increasing.

Examples

Basic Examples (2) 

Check an integer partition:

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

Check whether it is an integer partition of 6:

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

Here are the 5 integer partitions of 4:

In[3]:=
IntegerPartitions[4]
Out[3]=

They all pass the test for being an integer partition:

In[4]:=
ResourceFunction["IntegerPartitionQ"] /@ IntegerPartitions[4]
Out[4]=

Properties and Relations (3) 

The parts all have to be integers:

In[5]:=
ResourceFunction["IntegerPartitionQ"][{3., 3, 1}]
Out[5]=
In[6]:=
ResourceFunction["IntegerPartitionQ"][{3, 3, 1}]
Out[6]=

The parts have to be positive:

In[7]:=
ResourceFunction["IntegerPartitionQ"][{2, 1, 0}]
Out[7]=
In[8]:=
ResourceFunction["IntegerPartitionQ"][{2, 1}]
Out[8]=

The parts have to be in weakly decreasing order:

In[9]:=
ResourceFunction["IntegerPartitionQ"][{3, 1, 2, 1}]
Out[9]=
In[10]:=
ResourceFunction["IntegerPartitionQ"][{3, 2, 1, 1}]
Out[10]=

Publisher

George Beck

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.1 – 31 January 2022
  • 1.0.0 – 19 April 2019

Related Resources

License Information