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$
  • $\begingroup$ Could you explain what the function CNX is? It is not immediately obvious what you mean. $\endgroup$ – Niel de Beaudrap May 6 at 13:30
  • $\begingroup$ it's CX with many control qbits C(N)X $\endgroup$ – user1319236 May 6 at 13:31
  • $\begingroup$ Check ~p. 180 in Nielsen and Chuang (10th edition). $\endgroup$ – Sanchayan Dutta May 6 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$ – Nelimee May 6 at 15:28
  • $\begingroup$ Implementation details $\endgroup$ – user1319236 May 6 at 15:37
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$
  • $\begingroup$ You misinterpreted the documentation I guess. The line only means "we apply X controlled by $n-1$ other qubits" $\endgroup$ – Nelimee May 6 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$ – Sanchayan Dutta May 6 at 15:24
  • $\begingroup$ OK, read too quickly, you are right! $\endgroup$ – Nelimee May 6 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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