# Constructing a function for expanding general $n$ products

I have the following quantum mechanically motivated product:

$\langle0\vert(A_1b_1 + A_2b_2 + A_3b_3)(B_1b_1 + B_2b_2 + B_3b_3)(C_1b_1 + C_2b_2 + C_3b_3)$,

where $b_i$ is an annihilation operator acting on the $i^{\text{th}}$ vaccum state of $\langle0\vert$ which more explicitly in this case takes the form $\langle0, 0, 0\vert$.

I can easily use the Expand function in Mathematica to achieve the expansion of the product. However, with each term associated in the expansion I would like it multiplied with its corresponding Bra term. For example, consider the following terms:

1. $A_1B_1C_1$ should be multiplied by the term $\langle3, 0 , 0\vert$,
2. $A_3B_2C_2$ multiplied by $\langle0, 2 , 1\vert$,
3. $A_1B_3C_2$ multiplied by $\langle1, 1 , 1\vert$,
4. $A_3B_1C_2$ multiplied by $\langle1, 1 , 1\vert$,
5. $A_3B_1C_3$ multiplied by $\langle1, 0 , 2\vert$,

which hopefully makes clear what the pattern is. The number at each position $i$ within the Bra term is equivalent to the number of times that $i$ appears in the expansion terms.

A further difficulty arises when I would like to consider a general $n$ term expansion i.e. for $n = 4$ the expansion should be of:

$\langle0\vert(A_1b_1 + A_2b_2 + A_3b_3 + A_4b_4)(B_1b_1 + B_2b_2 + B_3b_3 + B_4b_4)(C_1b_1 + C_2b_2 + C_3b_3 + C_4b_4)(D_1b_1 + D_2b_2 + D_3b_3 + D_4b_4)$,

i.e each bracket has 4 terms and there are 4 terms and for which the vacuum state would now be the $4$-mode state $\langle0,0,0,0\vert$. The same rules above would still apply here.

Could we construct a function which achieves the expansion of these products and multiplies it with its coressponding Bra terms for general $n$. Thank you.

• I wonder if the Quantum package may be of help to you. – MarcoB Jun 7 '15 at 23:41
• @MarcoB, I have found a solution to this - I will post my solution to the question soon. – Sid Jun 8 '15 at 10:44
• Sid, that's excellent. I'm looking forward to it. – MarcoB Jun 8 '15 at 13:34
• Are you going to post the solution and accept it? That would be helpful for us, because it would get this question off the unanswered list. – march Aug 24 '15 at 4:04