# CNOT gate
controlled-NOT gate has two qubit input: control and target.
## CNOT on computational basis
| a | b | $CNOT\ket a\ket b$ | $XOR(a,b)$ |
| --- | --- | ------------------ | ---------- |
| 0 | 0 | $\ket {00}$ | 0 |
| 0 | 1 | $\ket {01}$ | 1 |
| 1 | 0 | $\ket {11}$ | 1 |
| 1 | 1 | $\ket {10}$ | 0 |
CNOT is the same as logic XOR : $\text{CNOT}|a,b\rangle=|a, a\oplus b\rangle$ for $a,b\in\{0,1\}$
note: CNOT can be applied on qubits in superposition and not only on computational basis.
## CNOT quantum circuit
```
a: ─────●─────
│
b: ─────⊕─────
```
note: The relationship of the name "control not" and the diagram: the bottom symbol is "xor". if $a=1$ then the result is $b\oplus1=NOT(b)$ i.e., it flips $b$.
## Example
Initialize the control in $\ket+$ and target in $\ket0$ i.e., $\ket+\ket{0}=\frac{1}{\sqrt2}(\ket{00}+\ket{10})$ .
Apply CNOT on both components: $\ket{00}\mapsto\ket{00}$ , $\ket{10}\mapsto\ket{11}$ .
Therefore, $CNOT\ket+\ket0=\frac{1}{\sqrt2}(\ket{00}+\ket{11})$.
This is the famous [[Bell state]].
## duplicating computation basis with CNOT
Given a qubit $\ket a$ s.t., $a\in\{0,1\}$ we can construct a new qubit with the same value: set $\ket a$ as the CNOT's control qubit and target as $\ket0$. The result qubits are $\ket a \ket{a\oplus 0}=\ket a\ket a$.
note: this is not cloning because the control and target qubits are dependent (entangled).
## Exercise: Computing XOR with CNOT gates
All qubits are computational-basis states. The output qubit begins in $\ket0$ : $\ket a\ket b\ket0$
Perform:
1. CNOT with a as control and the output as target.
2. CNOT with b as control and the same output as target.
Show that the result is $\ket a\ket b\ket{a\oplus b}$.
## Example: using CNOT for inner product
The inner product is computed between a computation basis vector and predefined vector. This is useful technique and it used e.g., in recent paper [[Classically-Verifiable Quantum Advantage from a Computational Bell Test]].
We build a quantum circuit with CNOT's that depends on the predefined vector. Given $\ket\psi$ is a computation basis with n bits e.g., $\ket{x_1x_2x_3x_4}$ where $x_i\in\{0,1\}$ and classic string $r$ of n-bits e.g., $1011$ .
Let's compute a single qubit containing the inner product $\ket{\psi\cdot r}$ e.g., $\ket{ x_1\cdot 1\oplus x_2\cdot0\oplus x_3\cdot 1\oplus x_4\cdot 1}=\ket{x_1\oplus x_3\oplus x_4}$
Solution:
```
x₁: ───●────────────────────────
│
x₂: ────────────────────────────
│
x₃: ───────────●────────────────
│ │
x₄: ───────────────────●────────
│ │ │
out: ───⊕───────⊕───────⊕──────── |x₁ ⊕ x₃ ⊕ x₄⟩
```
Tag: #tech
## Created 2026-01-14 15:25