Could somebody explain the cnx operator, and how it operates on its qubit parameters to flip the target qubit in Qiskit (Python)?
-
$\begingroup$ Could you explain what the function CNX is? It is not immediately obvious what you mean. $\endgroup$– Niel de BeaudrapCommented May 6, 2019 at 13:30
-
$\begingroup$ it's CX with many control qbits C(N)X $\endgroup$– user1319236Commented May 6, 2019 at 13:31
-
$\begingroup$ Check ~p. 180 in Nielsen and Chuang (10th edition). $\endgroup$– Sanchayan DuttaCommented 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$– Adrien SuauCommented May 6, 2019 at 15:28
-
$\begingroup$ Implementation details $\endgroup$– user1319236Commented May 6, 2019 at 15:37
1 Answer
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$.
-
$\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