General counting of microstates for a specific energy. Indistinguishable vs distinguishable I have the following problem: I have two  systems $A$ and $B$, each one with 5 distinguishable particles, $N_A=N_B=5$. The systems have infinite energy levels with energy $E_m = m \cdot \epsilon$ with $m=0,1,2,3...$ and I want to know the number of micro-states that are compatible with the macro-states $E_A=10 \epsilon $ (for system A) and $E_b=5 \epsilon$ (for system B) for each isolated system
Since all energies are positive (or zero), I start to do it by hand doing all the possible combinations for $A$ using only the first eleven levels ($m=0,...,10$) because it's impossible to find a macro-state $E_A=10 \epsilon $  in this system with some particle in $m>10$. For example I start for $A$ system with $N_0=4,N_1=0,N_2=0,...,N_9=0,N_{10}=1$. Maybe as you guess, this make me loss a lot of time, but finally I found the number of micro-states $\Omega_A (E_A) =841$ (I'm almost sure that this number is wrong). Also I repeat this for $B$. I wonder if there is an easy way to calculate the number of micro-states with this energy for each isolated system
Also I want to put both system in thermal contact and equilibrate, then calculate the probability that the system $A$ have an energy $E$, $P_A(E)$. I'm not sure how can I do that in a general way. And how can I do it if particles are indistinguishable?
 A: I wrote a quick python script (see below), which finds that there are $\Omega_{\text{dist.}}(10) = 1001$ inequivalent ways of writing $E_A = 10$ as a sum of 5 non-negative integers. Similarly, for $E_B = 5$ the script gives $\Omega_{\text{dist.}}(5) = 126$.
For indistinguishable particles, we do the same but insist that $n_1 \le n_2 \le \ldots \le n_5$ to prevent over-counting. The script then gives $\Omega_{\text{indist.}}(10) = 30$ and $\Omega_{\text{indist.}}(5)=7$. These last ones are easy to verify by hand.

This brute-force approach is fairly unsatisfactory, since it does not really give any insight. But I hope it will help you cross-check any formula you might come up with.

Now here's the weird part. It feels like there should be a clear formula that calculates this, but I could not find anything in my statistical mechanics lecture notes. By chance I found that dropping the condition (if 0 <= n5 and n5 <= n4:) in the second script seems to give exactly the answer of the first script (i.e. $1001$ if $E = 10$ and $126$ if $E=5$).
Intrigued by this, I did a bit of algebra to find that the sum that is being calculated can be represented as a polynomial as follows:
$$
 \Omega_{\text{dist.}}(E) \stackrel{?}{=}\sum_{i=0}^{E}\sum_{j=0}^{i}\sum_{k=0}^{j}\sum_{l=0}^{k} 1 = \frac{1}{24} ( E^4 + 10 E^3 + 35 E^2 + 50 E + 24).
$$
Super random I know, but I checked it against the first script for $0 \le E \le 100$ and it seems to work.
It might be that this formula ceases to hold for higher values of $E$, and I cannot really explain why it should be correct in the first place, but it is certainly interesting.

Python scripts:
# Distinguishable Particles:
E = 10  # system A
count = 0
for n1 in range(E+1):
    for n2 in range(E+1-n1):
        for n3 in range(E+1-(n1+n2)):
            for n4 in range(E+1-(n3+n2+n1)):
                print(n1, n2, n3, n4, E-(n1+n2+n3+n4))
                count += 1
print(count)

For system B, just change E = 10 to E = 5.
# Indistinguishable Particles
E = 10  # System A
count = 0
for n1 in range(E+1):
    for n2 in range(n1+1):
        for n3 in range(n2+1):
            for n4 in range(n3+1):
                n5 = E-(n1+n2+n3+n4)
                if 0 <= n5 and n5 <= n4:
                    print(n1, n2, n3, n4, E-(n1+n2+n3+n4))
                    count += 1
print(count)

