Is it possible to invert a sum of creation and annihilation operators, $A=\sum_iB_i c_i^\dagger c_i$, to find the $c_i$ in terms of $A$ and the $B_i$? I have a complicated transformation which I have to reverse. In the process I would also have to reverse an expression of the form $$A=\sum_i B_i c_i^\dagger c_i$$ where the $c_i,c_i^\dagger$ are creation and annihilation operators. Is it somehow possible to properly find an expression of $c_i^\dagger c_i$ in terms of $A$ and $B_i$?
 A: I’ll only treat the case of real $B_i$ so that $A$ is hermitian. I’ll write $n_i=c_i^\dagger c_i$ which commute. Therefore, $n_i$ commutes with $A$.
To make things more simple, I’ll stick to the fermion case so that the Hilbert space is finite dimensional. If the spectrum of $A$ is non degenerate, then set of commuting operators are just functions (polynomials) of $A$, so in particular this is true for the $n_i$. Note that the non-degeneracy condition on the spectrum is generic (unless there are underlying symmetries) ie mathematically it is true a.s. for any $B_i$.
In practice, you could calculate the spectral projectors of $A$ which gives you the product of $n_i$ or $1-n_i$. Then by summing correctly chosen terms, you retrieve the $n_i$.
To obtain the spectral projectors of $A$ the general method is to use the minimal polynomial of $A$ (which is non zero since the dimension is finite). There is a more physical way to obtain the spectral projector of $A$, $p$ of largest eigenvalue $a$. This inspired from techniques of statistical mechanics at low temperature. It is given by:
$$
p=\lim_{\beta\to+\infty}e^{-\beta(A-a)}
$$
By induction, you can similarly get the other projectors.
Hope this helps.
Edit
Say you have $N$ fermions, so your Hilbert space is of dimension $2^N$. I’ll write
$$
n_i^+=n_i \\
n_i^-=1-n_i
$$
which are the projections onto the states with a particle and a hole respectively at the $i$th orbital. For any $s\in\pm^N$, you can define the projector:
$$
p_s=\prod_{i=1}^N n_i^{s_i}
$$
You can obtain $n_i$ from the $p_s$ simply by:
$$
n_i=\sum_{s,s_i=1}p_s
$$
The key is that when $A$ is non degenerate, the $p_s$ are the spectral projectors of $A$, namely:
$$
Ap_s=A_sp_s\\
A_s=\sum_{i=1}^NB_i\frac{1+s_i}{2}
$$
The general theory for calculating the spectral projectors is using the minimal polynomial $\mu$ of $A$ by:
$$
p_s=\frac{\mu}{\mu’(A_s)(X-A_s)}(A)
$$
with the fraction gives a polynomial since $X-A_s$ divides $\mu$.
