# How does the cnx gate work in Qiskit (Python)?

Could somebody explain the cnx operator, and how it operates on its qubit parameters to flip the target qubit in Qiskit (Python)?

• Could you explain what the function CNX is? It is not immediately obvious what you mean. May 6 '19 at 13:30
• it's CX with many control qbits C(N)X May 6 '19 at 13:31
• Check ~p. 180 in Nielsen and Chuang (10th edition). May 6 '19 at 13:43
• Are you asking for implementation details or for a comprehensive explanation of what does the $C^n(X)$ gate? May 6 '19 at 15:28
• Implementation details May 6 '19 at 15:37

The documentation for cnx says Control n-1 qubits, apply 'not' to last one.
So basically $$C^n(X)$$ in Qiskit is defined like $$C^n(X)|x_1\cdots x_{n-1}\rangle|\psi\rangle = |x_1\cdots x_{n-1}\rangle X^{x_1\cdots x_{n-1}}|\psi\rangle$$ where $$x_1\cdots x_{n-1}$$ in the exponent of $$U$$ means the product of the bits $$x_1,\cdots, x_{n-1}$$. That is, the Pauli-X gate gate gets applied to the $$n$$-th qubit $$|\psi\rangle$$ only when all of the first $$n-1$$ bits are $$1$$.
• You misinterpreted the documentation I guess. The line only means "we apply X controlled by $n-1$ other qubits" May 6 '19 at 15:23
• @Nelimee Hi! Erm, I'm not sure that recurrence is correct. You mean the $X$ gate will now get applied to the (n-1)-th qubit in case $x_1\cdots x_{n-2}$ is $1$? That doesn't seem like it; check page 180 of N&C for instance. May 6 '19 at 15:24