Number Partition Calculator

Use this free integer partition calculator to find all the ways a positive integer can be written as a sum of positive integers. The calculator also gives the partition function \(p(n)\), which counts the number of distinct integer partitions.

Integer Partition Calculator

Enter an integer from 1 to 25. The calculator will generate every integer partition and show the total number of partitions.

Maximum input: 25. Generating every partition becomes increasingly large as the input grows.

What Is an Integer Partition?

An integer partition is a way of writing a positive integer as a sum of positive integers, where the order of the terms does not matter.

For example, the partitions of 5 are:

\[ \begin{aligned} 5 &= 5 \\ 5 &= 4+1 \\ 5 &= 3+2 \\ 5 &= 3+1+1 \\ 5 &= 2+2+1 \\ 5 &= 2+1+1+1 \\ 5 &= 1+1+1+1+1 \end{aligned} \]

Therefore:

\[ p(5)=7 \]

The expressions \(4+1\) and \(1+4\) represent the same integer partition because their order is irrelevant.

The Partition Function \(p(n)\)

The partition function, written as \(p(n)\), counts the number of distinct integer partitions of \(n\).

Some initial values are:

\[ p(1)=1,\quad p(2)=2,\quad p(3)=3,\quad p(4)=5,\quad p(5)=7 \]

As \(n\) increases, the number of partitions grows rapidly. For example:

n p(n)
1 1
2 2
3 3
4 5
5 7
6 11
7 15
8 22
9 30
10 42
15 176
20 627
25 1958

How the Number Partition Calculator Works

The calculator uses a recursive partition-generation algorithm. At each stage, it chooses the next part of the partition while ensuring that the next part is no larger than the previous part.

This prevents different arrangements of the same numbers from being counted multiple times.

For example, after generating \(4+1\), the calculator does not separately generate \(1+4\), because both represent the same partition.

The algorithm uses memoization to reuse intermediate results. This makes the calculation considerably more efficient than independently generating every possible combination.

Integer Partition vs. Composition

Integer partitions and compositions both represent an integer as a sum, but they treat order differently.

Partition

In a partition, order does not matter.

\[ 5=4+1 \] and \[ 5=1+4 \] are the same partition.

Composition

In a composition, order matters. Therefore \(4+1\) and \(1+4\) are different compositions.

Examples of Integer Partitions

Partitions of 3

\[ 3,\quad 2+1,\quad 1+1+1 \]

Therefore: \[ p(3)=3 \]

Partitions of 4

\[ 4,\quad 3+1,\quad 2+2,\quad 2+1+1,\quad 1+1+1+1 \]

Therefore: \[ p(4)=5 \]

Partitions of 5

\[ p(5)=7 \]

Important Facts About Integer Partitions

Frequently Asked Questions

What is an integer partition?

An integer partition is a way of writing a positive integer as a sum of positive integers where the order of the terms does not matter.

What is the partition function?

The partition function \(p(n)\) gives the number of distinct integer partitions of \(n\).

How many partitions does 5 have?

The number 5 has 7 integer partitions: \(5\), \(4+1\), \(3+2\), \(3+1+1\), \(2+2+1\), \(2+1+1+1\), and \(1+1+1+1+1\).

Does order matter in an integer partition?

No. The order does not matter. For example, \(4+1\) and \(1+4\) are considered the same partition.

What is the difference between a partition and a composition?

The main difference is order. In an integer partition, order does not matter. In a composition, different orders are counted separately.

What is p(10)?

There are 42 integer partitions of 10, so \[ p(10)=42. \]

Why does this calculator only allow numbers up to 25?

The number of integer partitions increases quickly as the input grows. Because this calculator displays every partition, larger inputs can produce a very large result. The current limit keeps the tool practical and responsive.