# Find orthogonal state for random 7 qubit state

I have a system that generates a random 7 qubit state and I need a method to always find the orthogonal state.

I'm currently using python and qutip for this, representing this 7 qubit state by a 128-dimensional vector.

Basically, you divide the entire $$7$$-qubit Hilbert space into two subspaces: the one spanned by your state (let's call the state $$|\psi\rangle$$), let's call that subspace $$W$$, and it's orthogonal complement $$V = W^{\perp}$$. You want any vector from $$V$$, because this will by definition be orthogonal.

We know that $$P_{V}$$ + $$P_{W} = I$$, with $$P_{V}$$ and $$P_{W}$$ being the projectors upon the $$V$$ and $$W$$ subspaces. Since $$P_{W} = |\psi\rangle\langle\psi|$$, we can easily calculate $$P_{V}$$:

$$P_{V} = I - |\psi\rangle\langle\psi|.$$ We can let this projection matrix act on virtually any state to obtain a state orthogonal on $$|\psi\rangle$$, lets use the $$0$$ vector $$|00....0\rangle$$. An orthogonal state $$|\psi^{\perp}\rangle$$ to $$|\psi\rangle$$ is thus:

$$|\psi^{\perp}\rangle = P_{V}|00...0\rangle = (I - |\psi\rangle\langle\psi|)|00...0\rangle = |00...0\rangle - \langle\psi|00...0\rangle|\psi\rangle$$

which is more or less the Gram-Schmidt process.

Note that you can use (almost) any state instead of $$|00...0\rangle$$; the only state that you cannot use is $$|\psi\rangle$$ itself.

In python, this becomes something like:

from numpy import zeros_like, inner

zeros_vect = zeros_like(psi_orig)

psi_orth = zeros_vect - inner(zeros_vect,psi_orig).conj()*psi_orig