3
$\begingroup$

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

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

1 Answer 1

3
$\begingroup$

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$.

$\endgroup$
3
  • $\begingroup$ You misinterpreted the documentation I guess. The line only means "we apply X controlled by $n-1$ other qubits" $\endgroup$ Commented May 6, 2019 at 15:23
  • 1
    $\begingroup$ @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. $\endgroup$ Commented May 6, 2019 at 15:24
  • $\begingroup$ OK, read too quickly, you are right! $\endgroup$ Commented May 6, 2019 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.