Single-Qubit Rotor Compilation: Bloch Geometry Theorems and the ZYZ Euler Compiler
“A quantum state is a direction, and a quantum gate turns that direction; it can therefore be understood as a geometric structure with area.”
In Reducing Matrices to XOR: Three-Bit Blades and the XOR–Pauli Geometric Algebra Engine, we compressed the eight-dimensional real Clifford algebra into the 3-bit XOR blade engine GeometricState and verified the matrix core of the traceless Bloch operator (Corollary Kernel.4).
In this chapter we complete the single-qubit computational bridge by joining two halves:
-
On the state-geometry side (verified in the Lean 4 kernel): How does an arbitrary Hermitian matrix decompose into its real trace and three-dimensional Bloch vector ? Why do trace-one idempotent projectors () lie on the unit sphere , while every positive-semidefinite matrix (
M.PosSemidef) obeys the solid-ball bound ? -
On the gate-compilation side (the Python 3
RotorCompiler): Given any ZYZ Euler angle triple , how do we compile the three rotations directly inside the four-dimensional even subalgebra into a single unit rotorand rotate any vector via the two-sided sandwich product ?
Bloch rotations and ZYZ decomposition. The chapter at a glance. Panel I: the green Bloch ball; the amber pure-state arrow reaches the shell , and the dark point lies inside, where every trace-one positive semidefinite matrix lands (Proposition Kernel.12, Corollary Kernel.13). Panel II: the sandwich turns by about the violet axis; the cyan shadow stays on the axis, and the magenta fan is split by a dashed line into two half-angles. Panel III: in the order used by the rotor product, turns about by , then about by , and finally about by , with parameter tuple ; the amber path of three legs ends at (rotor compilation is a numerical illustration with no frozen theorem).
Bloch Matrix Trace and Coordinate Recovery
In the Lean 4 module D5/S3/Quantum/Information/ActualPureQubitGeometry.lean (within namespace D5.S3.Quantum.Information.ActualPureQubitCostInfimum), the exact bidirectional correspondence between Hermitian matrices and pairs consisting of a real trace scalar and a real Bloch three-vector is defined by two maps:
-
The Bloch coordinate extraction map
bloch: For any , -
The Bloch matrix reconstruction map
blochMatrix: For any real trace scalar and real three-vector ,
Our first two frozen results certify that blochMatrix a r recovers the exact trace scalar under Matrix.trace and the exact three-vector under bloch.
For every real scalar and every three-dimensional real vector , the trace of equals :
In D5/S3/Quantum/Information/ActualPureQubitGeometry.lean:58, simp [blochMatrix, Matrix.trace, Fin.sum_univ_two] expands the matrix trace into the sum of the two diagonal entries:
and ring cancels the terms to leave . The full proof is checked by the Lean kernel.
For every real scalar and every three-dimensional real vector , applying bloch to recovers :
In D5/S3/Quantum/Information/ActualPureQubitGeometry.lean:63, the proof applies ext i and fin_cases i <;> (simp [blochMatrix, bloch]; ring) across the three coordinates :
- At : ;
- At : ;
- At : .
Hence . The full proof is checked by the Lean kernel.
Reading the trace and the three coordinates back from the matrix. Take with : the two cyan diagonal cells add to the trace and subtract to ; the dark top-right cell gives and ; the dashed bottom-left cell is only its conjugate and is not read. What comes back is (Theorem Kernel.10, Lemma Kernel.11).
Hermitian Reconstruction, the Pure-State Sphere, and the Positive-Semidefinite Ball Bound
Conversely, start with an arbitrary Hermitian matrix (hM : M.IsHermitian). The next frozen proposition proves both that is reconstructed identically from its real trace (Matrix.trace M).re and its Bloch vector bloch M, and that whenever has unit trace () and is idempotent (), its Bloch vector lies on the unit sphere .
Let be a complex matrix satisfying hM : M.IsHermitian. Then both properties hold:
-
Exact Hermitian reconstruction:
-
Unit-sphere norm for trace-one idempotent projectors:
In D5/S3/Quantum/Information/ActualPureQubitGeometry.lean:68, Hermiticity yields four component relations: (h00), (h11), (h10r), and (h10i).
-
For the first conjunct,
ext i j,fin_cases i <;> fin_cases j, andComplex.extfollowed bysimpandringverify entrywise equality between and . -
For the second conjunct, assuming
ht : Matrix.trace M = 1andhp : M * M = M, taking the real part of the traces of and yields and . ExpandingEuclideanSpace.real_norm_sq_eqgivesand
nlinarithwithnorm_nonneg (bloch M)concludes .
The full proof is checked by the Lean kernel.
When idempotence is relaxed to positive semidefiniteness hM : M.PosSemidef (covering mixed states and general POVM effects, as in Chapter 4), the fourth frozen theorem proves that the Bloch norm is bounded above by the real trace (Matrix.trace M).re.
Let be a complex matrix. If is positive semidefinite (hM : M.PosSemidef), then
In D5/S3/Quantum/Information/ActualPureQubitGeometry.lean:100, hM.trace_nonneg and hM.det_nonneg imply (ht) and (hd). Rewriting via the first conjunct of Proposition Kernel.12 together with Theorem Kernel.10, Lemma Kernel.11, and Matrix.det_fin_two yields the determinant identity (he):
Since and both and are nonnegative, nlinarith derives . The full proof is checked by the Lean kernel.
With trace , the sign of the determinant says where the arrow ends. The – cross-section of the Bloch ball, with : the amber pure state on the green circle has ; the dark point inside has ; the magenta point outside has and is not positive semidefinite. The green disc is where positive semidefinite matrices can land (Corollary Kernel.13); the circle holds the trace-one idempotent pure states (Proposition Kernel.12).
Even-Subalgebra Bivectors and the Rotor Sandwich Action
Now let us see how rotations of the Bloch vector are compiled directly inside the four-dimensional even subalgebra .
In , the three right-handed unit rotation bivectors orthogonal to the axes () are
Because and for each axis , the elementary rotor for a right-handed rotation by angle about axis is given by the half-angle formula (Panel II of the chapter overview figure):
The rotor goes half the angle, the arrow the whole of it. With about : on the left, the violet point sits at on the unit circle, its scalar across and its coefficient up, and lying on the circle means ; on the right, the sandwich turns through the full of the magenta fan, to the amber .
with unit norm . Under the two-sided sandwich product , components parallel to axis commute with and remain fixed, whereas components lying in the plane anticommute with , combining the two half-angles into a full rotation .
The sandwich: the shadow on the axis stays, the plane turns in full. The amber arrow turns by about the violet axis: its cyan shadow stays on the axis, while the magenta part sweeps a fan in the plane , split by the dashed line into two halves of , the half-angles contributed by on the left and on the right. This is the hand computation of this section; the page is a numerical illustration.
Consequently, compiling a ZYZ Euler triple requires only two multivector multiplications in :
Three turns multiply into one rotor. With the triple of the example below, the amber arrow turns first by about the violet axis, then by about , and last by about ; the white tripod comes to rest at , , , and the top of the figure shows the compiled rotor . Rotor compilation has no frozen theorem; on the page it is a numerical illustration only.
Python 3 ZYZ Rotor Compiler Implementation and Numerical Verification
We keep the real coefficients of the preceding companion section’s engine: compilation produces real even rotors, whose unit condition makes reverse() their inverse; norm_squared() checks normalization within this same domain.
Below is the complete runnable Python 3 RotorCompiler and self_test() implementation (building directly on GeometricState from Reducing Matrices to XOR: Three-Bit Blades and the XOR–Pauli Geometric Algebra Engine):
from __future__ import annotations
from dataclasses import dataclass
from math import cos, sin, isclose, pi
from typing import Dict, Mapping, Tuple
BLADE_NAMES: Dict[int, str] = {
0: "1", 1: "e1", 2: "e2", 3: "e12",
4: "e3", 5: "e13", 6: "e23", 7: "e123",
}
def _blade_sign(left: int, right: int) -> int:
"""Sign of e_left * e_right in Cl(3,0), with e_i^2 = 1."""
inversions = 0
for i in range(3):
if (left >> i) & 1:
inversions += (right & ((1 << i) - 1)).bit_count()
return -1 if inversions % 2 else 1
@dataclass(frozen=True)
class GeometricState:
"""Sparse multivector in the eight-dimensional Cl(3,0) basis."""
terms: Mapping[int, complex]
def __post_init__(self) -> None:
clean = {int(k): complex(v) for k, v in self.terms.items() if abs(v) > 1e-14}
if any(k < 0 or k > 7 for k in clean):
raise ValueError("a Cl(3,0) blade mask must use three bits")
object.__setattr__(self, "terms", clean)
@staticmethod
def zero() -> "GeometricState":
return GeometricState({})
@staticmethod
def scalar(value: complex) -> "GeometricState":
return GeometricState({0: value})
@staticmethod
def basis(index: int) -> "GeometricState":
if index not in (0, 1, 2):
raise ValueError("basis index must be 0, 1, or 2")
return GeometricState({1 << index: 1})
@staticmethod
def pauli(x: int, z: int, phase: int = 0) -> "GeometricState":
"""Binary Pauli word, encoded by the X/Z symplectic bits."""
if x not in (0, 1) or z not in (0, 1):
raise ValueError("Pauli bits must be 0 or 1")
mask = (1 if x else 0) | (2 if z else 0)
return GeometricState({mask: (1j) ** phase})
def __add__(self, other: "GeometricState") -> "GeometricState":
out: Dict[int, complex] = dict(self.terms)
for mask, value in other.terms.items():
out[mask] = out.get(mask, 0j) + value
return GeometricState(out)
def __neg__(self) -> "GeometricState":
return GeometricState({m: -v for m, v in self.terms.items()})
def __sub__(self, other: "GeometricState") -> "GeometricState":
return self + (-other)
def __rmul__(self, scalar: complex) -> "GeometricState":
return GeometricState({m: scalar * v for m, v in self.terms.items()})
def __mul__(self, other: "GeometricState") -> "GeometricState":
out: Dict[int, complex] = {}
for left, a in self.terms.items():
for right, b in other.terms.items():
mask = left ^ right
value = a * b * _blade_sign(left, right)
out[mask] = out.get(mask, 0j) + value
return GeometricState(out)
def reverse(self) -> "GeometricState":
out = {}
for mask, value in self.terms.items():
grade = mask.bit_count()
out[mask] = value * (-1 if grade * (grade - 1) // 2 % 2 else 1)
return GeometricState(out)
def scalar_part(self) -> complex:
return self.terms.get(0, 0j)
def norm_squared(self) -> float:
value = (self * self.reverse()).scalar_part()
return float(value.real)
def close(self, other: "GeometricState", tol: float = 1e-10) -> bool:
return all(abs((self - other).terms.get(m, 0j)) <= tol
for m in set(self.terms) | set(other.terms))
def _bivector(axis: str) -> GeometricState:
# Right-handed rotation planes: z -> e12, y -> e31, x -> e23.
planes = {"x": (2, 4), "y": (4, 1), "z": (1, 2)}
try:
a, b = planes[axis.lower()]
except KeyError as exc:
raise ValueError("axis must be x, y, or z") from exc
return GeometricState.basis(a.bit_length() - 1) * GeometricState.basis(b.bit_length() - 1)
class RotorCompiler:
"""Compile a ZYZ Euler triple into an even Clifford rotor."""
@staticmethod
def rotor(axis: str, angle: float) -> GeometricState:
plane = _bivector(axis)
return GeometricState.scalar(cos(angle / 2.0)) - sin(angle / 2.0) * plane
@classmethod
def compile(cls, alpha: float, beta: float, gamma: float) -> GeometricState:
return cls.rotor("z", alpha) * cls.rotor("y", beta) * cls.rotor("z", gamma)
@staticmethod
def apply(rotor: GeometricState, vector: GeometricState) -> GeometricState:
return rotor * vector * rotor.reverse()
@classmethod
def zyz_matrix(cls, alpha: float, beta: float, gamma: float) -> Tuple[Tuple[float, ...], ...]:
ca, sa = cos(alpha), sin(alpha)
cb, sb = cos(beta), sin(beta)
cg, sg = cos(gamma), sin(gamma)
return (
(ca * cb * cg - sa * sg, -ca * cb * sg - sa * cg, ca * sb),
(sa * cb * cg + ca * sg, -sa * cb * sg + ca * cg, sa * sb),
(-sb * cg, sb * sg, cb),
)
def _assert_state(actual: GeometricState, expected: GeometricState) -> None:
assert actual.close(expected), (actual, expected)
def self_test() -> None:
e1, e2, e3 = (GeometricState.basis(i) for i in range(3))
one = GeometricState.scalar(1)
_assert_state(e1 * e1, one)
_assert_state(e1 * e2, -e2 * e1)
_assert_state(e1 * e2 * e3 * e1 * e2 * e3, GeometricState.scalar(-1))
_assert_state(GeometricState.pauli(1, 0) * GeometricState.pauli(0, 1), e1 * e2)
_assert_state(GeometricState.pauli(0, 1) * GeometricState.pauli(1, 0), -(e1 * e2))
_assert_state(GeometricState.pauli(1, 1, phase=1), 1j * (e1 * e2))
compiler = RotorCompiler()
rotor = compiler.compile(0.37, -0.81, 0.52)
_assert_state(rotor * rotor.reverse(), one)
assert isclose(rotor.norm_squared(), 1.0, abs_tol=1e-12)
x = e1
rotated = compiler.apply(compiler.rotor("z", 0.5), x)
assert isclose(rotated.terms.get(1, 0j).real, cos(0.5), abs_tol=1e-10)
assert isclose(rotated.terms.get(2, 0j).real, sin(0.5), abs_tol=1e-10)
matrix = compiler.zyz_matrix(0.37, -0.81, 0.52)
assert all(isclose(sum(row[k] * row[k] for k in range(3)), 1.0, abs_tol=1e-10)
for row in matrix)
r_h = compiler.compile(0.0, pi / 2.0, pi)
_assert_state(compiler.apply(r_h, e1), e3)
_assert_state(compiler.apply(r_h, e2), -e2)
_assert_state(compiler.apply(r_h, e3), e1)
print("part7_engine: self-test passed (Cl(3,0) XOR/Pauli + ZYZ rotor)")
self_test()
Let us verify the compiled multivector coefficients and rotated basis vectors on the test Euler triple as well as on the and Hadamard gates.
Three two-term rotors multiply into one four-term rotor. The four panels share one small chart, with violet bars for the coefficients of : , and have two bars each, the product has all four nonzero, and in every panel the squares add up to . These are the numbers of the example below; rotor compilation has no frozen theorem.
-
Nontrivial Euler triple : Calling
RotorCompiler.compile(0.37, -0.81, 0.52)produces an even multivector supported on masks0(),3(),5(), and6():where calling
rotor.norm_squared()((R * R.reverse()).scalar_part().real) on the unrounded floating-pointrotorobject returns a value that rounds to1.000000000000at twelve decimal places (while summing the squares of the 6-decimal rounded display coefficients gives ). Evaluatingapply(R, e_k)on reproduces the three columns ofzyz_matrix(0.37, -0.81, 0.52)to machine precision: -
Compiling the gate ( gate): Up to global phase , rotates the Bloch sphere by about the axis, so compiles to
-
Compiling the Hadamard gate (): On the Bloch sphere, swaps and negates (a rotation about the axis), corresponding to . Calling
compile(0, pi/2, pi)gives the pure bivector rotorsatisfying , , and to machine precision.
The Hadamard gate . By contrast, the gate has only a last turn of about , the same kind of picture as the sandwich card above; the Hadamard gate takes two turns. The first is about : the amber arrow sits at the north pole, on the axis, so only its cyan shadow is left while the tripod’s and flip over; the second turn is about and brings the arrow down to . The violet dashed line is the diagonal axis , and the tripod comes to rest at , , .
Literature result, not formalized in this book. Two classical theorems from quantum computation and Lie group theory frame the compiler construction above:
-
Universal ZYZ Euler decomposition for single-qubit unitaries (M. A. Nielsen & I. L. Chuang, Quantum Computation and Quantum Information, 10th Anniversary Ed., Cambridge University Press, 2010, Theorem 4.1, §4.2; A. Barenco et al., Phys. Rev. A 52, 3457, 1995, DOI 10.1103/PhysRevA.52.3457): For every , there exist real angles such that
-
The spin double cover : Inside , the norm-one rotor group acts on via , defining a surjective homomorphism onto with kernel . For a fixed plane of rotation, the topology of this two-to-one map — unique path lifting, no continuous global section, sign reversal of the rotor after a full turn — is verified by Theorem 5.4 in Chapter 5.
-
Exact scope of the frozen theorems: The four Lean-verified theorems in this chapter (
ActualPureQubitGeometry) prove the trace formula forblochMatrix a r(Theorem Kernel.10), coordinate recoverybloch (blochMatrix a r) = r(Lemma Kernel.11), Hermitian Bloch reconstruction and unit-sphere norm for trace-one idempotent projectors (Proposition Kernel.12), and the positive-semidefinite ball bound (Corollary Kernel.13). Surjectivity of and existence of ZYZ angles for arbitrary belong to the literature layer, whileRotorCompilerimplements the forward rotor synthesis from .
Three turns equal one turn about one axis. For the same angles , the violet dashed line is the compiled rotor’s own axis and the violet dashed arc a single turn of about it: leaving the white start ring, it lands exactly where the white road of the three turns ends. That a unit rotor is one turn about one axis belongs to the literature results above and is not formalized in this book; the axis and the angle are computed numerically by the page.
The of the violet dashed arc comes from the scalar part of the rotor in the example: the scalar is the cosine of the half-angle, and .
The ZYZ compilation lab. Drag the three Euler angles, move the arrow’s start, or switch on the single axis : in every turn the cyan shadow stays put while the magenta fan sweeps the whole angle, and in the strip scalar and area trade off with a sum that stays . The green boxes cite only this chapter’s four frozen theorems (Theorem Kernel.10, Lemma Kernel.11, Proposition Kernel.12, Corollary Kernel.13), which the page checks one by one on the pure state of the arrow.
Our executable Python 3 geometric algebra and rotor compilation engine is now complete.
Compiling a rotation into three turns: ZYZ and the sandwich action (2 min 5 s). Turning about the violet axis, the cyan shadow stays put and the magenta part sweeps the whole angle, while on the little dial the rotor moves only half as far; then the amber arrow turns about , and by , and , the three rotors multiply into one rotor with four coefficients, , and sandwiching the three basis vectors with it gives the columns of the ZYZ matrix; a single turn about its own axis lands on the same point (the single axis is the literature result of Remark Kernel.15; the rotor compilation is a numerical demonstration). The and Hadamard gates follow, and the film ends on the pure state with this chapter’s four frozen theorems (Theorem Kernel.10, Lemma Kernel.11, Proposition Kernel.12, Corollary Kernel.13).
From here we step directly into the frozen Lean 4 source files of trureturing@dev to audit a sample of the proof scripts that certify this monograph. Let us open Inside the Lean 4 Axiom Sanctuary (Part I): From the Parallelogram Law to Finite Record Pinching.