guan404ming commented on code in PR #630:
URL: https://github.com/apache/mahout/pull/630#discussion_r2529996055
##########
docs/basic_gates.md:
##########
@@ -46,10 +46,55 @@ The T-Gate applies a **π/4 phase shift** to the qubit. It
is essential for quan
\[ T|0⟩ = |0⟩ \]
\[ T|1⟩ = e^{i\pi/4} |1⟩ \]
+## CSWAP Gate (Controlled-SWAP / Fredkin Gate)
+The CSWAP gate, also known as the **Fredkin gate**, is a three-qubit gate that
conditionally swaps the states of two target qubits based on the state of a
control qubit. If the control qubit is in the |1⟩ state, it swaps the states of
the two target qubits; otherwise, it leaves them unchanged.
+
+### Mathematical Definition
+
+The CSWAP gate acts on three qubits: a control qubit |c⟩ and two target qubits
|t₁⟩ and |t₂⟩. The operation is:
+
+\[ \text{CSWAP}|c\rangle|t_1\rangle|t_2\rangle = \begin{cases}
|c\rangle|t_1\rangle|t_2\rangle & \text{if } c = 0 \\
|c\rangle|t_2\rangle|t_1\rangle & \text{if } c = 1 \end{cases} \]
+
+In matrix form (for the 8-dimensional space of three qubits), the CSWAP gate
is:
+
+\[ \text{CSWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 &
0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0
& 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0
& 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{pmatrix} \]
+
+The CSWAP gate is fundamental in quantum algorithms such as the swap test,
quantum error correction, and quantum state comparison. The CSWAP gate is
reversible and preserves the number of |1⟩ states in the system (conserves the
Hamming weight).
+
+## U Gate (Universal Single-Qubit Gate)
+The U gate is a **universal single-qubit gate** parameterized by three angles
(θ, φ, λ) that can represent any single-qubit unitary operation. It provides a
complete parameterization of single-qubit rotations and is essential for
implementing arbitrary quantum operations.
+
+### Mathematical Definition
+
+The U gate matrix representation is:
+
+\[ U(\theta, \phi, \lambda) = \begin{pmatrix} \cos(\theta/2) &
-e^{i\lambda}\sin(\theta/2) \\ e^{i\phi}\sin(\theta/2) &
e^{i(\phi+\lambda)}\cos(\theta/2) \end{pmatrix} \]
+
+The U gate can be decomposed into rotations around the Z, Y, and Z axes:
+
+\[ U(\theta, \phi, \lambda) = R_z(\phi) \cdot R_y(\theta) \cdot R_z(\lambda) \]
+
+This decomposition shows that the U gate applies:
+1. A rotation by λ around the Z-axis
+2. A rotation by θ around the Y-axis
+3. A rotation by φ around the Z-axis
+
+### Special Cases
+
+- **Identity**: U(0, 0, 0) = I
+- **Pauli X**: U(π, 0, π) = X
+- **Pauli Y**: U(π, π/2, π/2) = Y
+- **Pauli Z**: U(0, π, 0) = Z
Review Comment:
I think this one make sense to me, @rich7420 could you help take another
look? Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]