# How to create this list

Suppose I have two kinds of operators $$a[i,j],a^\dagger[i,j]$$ where i is a non-negative integer and $$j=\pm 1$$, I want to create a list containing all possible products of

$$a^{(\dagger)}[x_1,j_1]a^{(\dagger)}[x_2,j_2]a^{(\dagger)}[x_3,j_3]...a^{(\dagger)}[x_r,j_r]$$

where $$a^{(\dagger)}$$ could take the value of $$a$$ or $$a^\dagger$$

such that

$$r+ \sum_{i=1}^{r} |x_i|\leq K$$

where K is an integer I need to specify.

The first question is how to create this list?

The second question is what can I do to restrict all elements of this list in a "normal-ordered form" meaning that $$a^{\dagger}[i,j]$$ is always in front of $$a[i,j]$$ ([i,j] have the same value for $$a, a\dagger$$) with the anti-commutation relation $$a[i,j] a^\dagger[k,l] +a^\dagger[k,l] a[i,j]=\delta_{ik}\delta_{jl}$$ where $$\delta_{ij}=1$$ if $$i=j$$ and 0 for other cases.

It would be ideal if I can make all elements having the form

$$(a^{\dagger}[x1,1]a^{\dagger}[x1,1]...a[x1,1])(a^{\dagger}[x1,-1]a^{\dagger}[x1,-1]...a[x1,-1])(a^{\dagger}[x2,-1]a^{\dagger}[x2,-1]...a[x2,-1])...$$

meaning $$a^{(\dagger)}[i,j]$$ with same $$[i,j]$$ stays inside a parentheses.

• One possibility: mathematica.stackexchange.com/a/220765/29734 Sep 20, 2021 at 15:24
• (That's for the normal-ordering stuff, not the list-making stuff.) Sep 20, 2021 at 15:37
• For the set of possible $x_i$'s, I believe IntegerPartitions[k - r, k, Range[r]] should work. Or maybe, Flatten[Permutations /@ IntegerPartitions[k - r, k, Range[r]], 1] Sep 20, 2021 at 15:39
• @march Thank you very much! I'm still trying the normal ordering stuff but the list-making one works perfectly. Sep 20, 2021 at 18:20
• You might just want IntegerPartitions[k] (or perhaps Rest@IntegerPartitions[k]) to get them all at once. Sep 20, 2021 at 18:21