## unique integer partitions

### Remember to vote up questions/answers you find interesting or helpful (requires 15 reputation points)

Let me motivate my general question with an explicit example:

Suppose I am looking for all unique combinations of exactly three non-negative integers that sum to five. The solutions are 005, 014, 023, 113, and 122. Which means that there are five unique combinations.

Is there a way to find the $\textit{number}$ of unique combinations of exactly $k$ non-negative integers that sum to $n$? I'd rather not generate all the unique combinations and then count. I am hoping that there is a straightforward combinatoric solution to this.

Please let me know if more clarification is needed.

Thanks!

-

## 4 Answers

For fixed k

$p_k(n) \sim {n^{k-1} \over k!(k-1)!}.$

Maybe this limitingform will be of some use to you.

-

### You can accept an answer to one of your own questions by clicking the check mark next to it. This awards 15 reputation points to the person who answered and 2 reputation points to you.

If you need an algorithm to calculate this number, you can use the following. Let $a_{nk}$ be an answer to your question, then it's not hard to prove that $a_{nk} = a_{n,k-1} + a_{n - k, k}$. So you can fill in the table of all $a_{nk}$ using this formulae.

-

+1 thanks for the answer. but if, say, $n = 10^{7}$ and $k = 2000$, i fear that i'd be sitting around for quite a while for the recursion to finish or i might reach the recursion depth of my programming language. do you know of any asymptotic results? maybe along the lines of hardy-ramanujan? – B Rivera Jul 10 2010 at 1:50
For those $n$n and $k$ I can suggest the following. Start with the approach suggested by Qiaochu Yuan. Take polynomial $f(x) = (1-x)(1-x^2)\cdots(1-x^k)$ and calculate it as $f(x) = f_0 + f_1 x + \cdots + f_{k(k+1)/2} x^{k(k+1)/2}$. Now you need coefficient with $x^n$ in $1/f(x)$. To calculate it apply Fast Fourier Transform to inverse polynomial $f(x)$. This works in $O(n \log n)$ basic operations (multiplications and additions). So the overall complexity is $O(n \log n)$ – falagar Jul 10 2010 at 5:22

Nothing wrong with Qiaochu Yuan's answer, but here's an orthogonal approach; for fixed $k$, calculate the first 5 or 10 $n$ values and then look up the resulting sequence at the Online Encyclopedia of Integer Sequences.

-

For fixed $k$ and large $n$ this is pretty doable. You want to find solutions to

$$x_1 + x_2 + ... + x_k = n$$

where $x_1 \ge x_2 \ge ... \ge x_k$. Letting $y_i = x_i - x_{i+1}$ and $y_k = x_k$, this is equivalent to finding solutions to

$$y_1 + 2y_2 + ... + ky_k = n$$

where $y_i \ge 0$. If $p_k(n)$ denotes the number of ways to do this, it follows by a standard generating function trick that

$$\sum_{k \ge 0} p_k(n) x^n = \frac{1}{(1 - x)(1 - x^2)...(1 - x^k)}.$$

In principle one can find the partial fraction decomposition of the RHS, allowing us to write $p_k(n)$ as a quasi-polynomial.

-

+1 thanks for the answer. perhaps i should have given my actual numerical constraints. i was looking for some type of method that would allow me to solve for cases of $n > 10^{6}$ and $k > 1000$ in a reasonable amount of time. perhaps it is not possible? – B Rivera Jul 10 2010 at 1:45
It's always a good idea to give your actual numerical constraints.  It is actually quite feasible to read off the leading terms of p_k(n) in terms of n from the generating function; the leading term is something like 1/k! {n+k-1 choose k} and this should give a pretty reasonable approximation.   – Qiaochu Yuan Jul 10 2010 at 1:58
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 30, "mathjax_display_tex": 3, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": false, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.924838662147522, "perplexity_flag": "head"}