Question: The degeneracy for an $p$-dimensional quantum harmonic oscillator is given by [[1](http://aapt.scitation.org/doi/pdf/10.1119/1.18185)] as

> 
> $$g(n,p) = \frac{(n+p-1)!}{n!(p-1)!}$$ 
> 
> 
> 

The $g$ is the number of degenerate states. Where of course we have that $n = n\_1 + n\_2 + \dots + n\_p$ and that the eigenvalues of the energy are given by 

$$E\_n = E\_{n\_1,n\_2,\dots,n\_p} = \hbar \omega\left(n + \frac{p}{2}\right)$$

How can I derive this formula? In the paper as reference I just didn't understand what he used to show that relation. If this question has an answer that is too big for this format then I'll accept a hint to show that, for $p = 3$ we have that $$g\_n = \frac{1}{2}(n+1)(n+2) \, .$$ Can this can be deduced in a counting way?

Answer: 
The formula can be written as
$$g= \binom{n+p-1}{p-1}$$
it corresponds to the number of [weak compositions](https://en.wikipedia.org/wiki/Composition_(combinatorics)) of the integer $n$ into $p$ integers. It is typically derived using the method of [stars and bars](https://en.wikipedia.org/wiki/Stars_and_bars_(combinatorics)):

You want to find the number of ways to write $n= n\_1 + \cdots + n\_p$ with $n\_j \in \mathbb{N}\_0.$ In order to find this, you imagine to have $n$ stars ($\star$) and $p-1$ bars ($|$). Each composition then corresponds to a way of placing the $p-1$ bars between the $n$ stars. The number $n\_j$ corresponds then to the number of stars in the $j$-th `compartement' (separated by the bars). 

For example ($p=3, n=6)$:

$$ \star \star | \star \star \star | \star \quad \Rightarrow \quad n\_1=2,n\_2=3, n\_3=1$$
$$ \star| \star \star \star \star \star| \quad \Rightarrow \quad n\_1=1,n\_2=5, n\_3=0.$$

Now it is well known that choosing the position of $p-1$ bars among the $n+(p-1)$ objects (stars and bars) corresponds to the binomial coefficient given above.
The degeracy is also given by the coefficient of $x^n$ in the partition function $1/(1-x)^p$. This, in turn, is the expression given above by the binomial theorem for $(1-x)^{-p}$.