I asked this already in reddit but got now answers, so I hope here is the right place.
Question in short:
Is there a general form of the CNOT Gate, so I can apply it to an arbitrary entangled state with any target and control bit of my choosing?
In other words: I am looking for a general Matrix represantation of the CNOT Gate
My Problem a bit more in detail:
The CNOT gate normally acts on 2 qubits.
$CNOT^2=\begin{pmatrix} 1&0&0&0\\ 0&1&0&0\\0&0&0&1\\0&0&1&0 \end{pmatrix}$
I also now how I would apply the CNOT gate on any consecutive qubits for larger states. The answer is a simple tensor product between CNOT and the Identity
eg:for a three qubit state
$$ CNOT^3_{12}=(CNOT^2\otimes I) $$ $$ CNOT^3_{23}=(I\otimes CNOT^2) $$ but how would I implement it acting on the first as control and the third as target qubit?\ Is there a general $CNOT_{i_k}$ formulation?
In my program I would need $|0_c00_t000\rangle$ and $|00_c00_t00\rangle$
folllow up question regarding Jitandras answer
Okay, sorry for the misunderstandings, it was quite late yeasterday and I couldn't really process what you said anymore. Yes, what I need is the Matrix.
Regarding your answer:
I don't understand why you chose the state of the first pariticle as up the one of the last as down. Can they be chosen arbitrarily?
To check if the formula you wrote gives the desired result I calculated the CNOT for the case that I have a three qubit state where the first is the control and the second is the target one. Which flips if the control qubit is one, while the last one stays untouched. $$ CNOT(a|110\rangle+b|100\rangle+c|000\rangle+d|010\rangle+e|111\rangle+f|101\rangle+g|001\rangle+h|001\rangle ) = a|100\rangle+b|110\rangle c|000\rangle+d|010\rangle+e|111\rangle+f|101\rangle+g|001\rangle+h|001\rangle $$
I know that the following works:
$CNOT^3_{12} = \begin{pmatrix} 1& 0& 0&0\\0 &1 & 0& 0\\0 & 0& 0& 1\\ 0&0&1&0 \end{pmatrix}\otimes\begin{pmatrix} 1 &0\\0&1\end{pmatrix}$
Resulting in a 8x8 Matrix.
If undestand your formula correctly this would mean for a complete distciption $$CNOT^3_{12} = |100\rangle\langle100|\otimes\sigma_x + |000\rangle\langle000|\otimes I + |110\rangle\langle110|\otimes\sigma_x + |010\rangle\langle010|\otimes I +|101\rangle\langle101|\otimes\sigma_x + |001\rangle\langle001|\otimes I + |111\rangle\langle111|\otimes\sigma_x + |011\rangle\langle011|\otimes I $$
I get a completely different 16x16 Matrix. Where is my mistake?