Reducing Matrices to XOR: Three-Bit Blades and the XOR–Pauli Geometric Algebra Engine
“Quantum = two particles = the measuring particle …”
Across Parts I through VI and the thirty-nine-chapter main narrative, we climbed the dimensional ladder — from point to line, line to plane, plane to sphere, coupled spheres, causal cones, and spheres beyond spheres — restoring quantum mechanics from mystical particle folklore to orthogonal projection, oriented bivector area, and spinor geometry on . Here we enter Forge and Sanctuary, the book’s unnumbered companion part: turning our geometric architecture into two concrete artifacts that any reader can run and audit line by line — a zero-dependency Python 3 geometric algebra and rotor compilation engine (Reducing Matrices to XOR and Single-Qubit Rotor Compilation), and a direct source-level audit of the frozen Lean 4 proofs (Inside the Lean 4 Axiom Sanctuary (Part I) and Part II).
Start with an elementary computational question. When we simulate single-qubit Pauli operators or the three-dimensional Euclidean Clifford algebra on a classical computer, do we actually need to allocate complex matrices and execute eight complex multiplications and four additions per product?
Not at all! Once we strip away matrix redundancy, the entire algebraic engine reduces to bitwise logic:
- In two-dimensional complex Hilbert space, the noncommutative structure of the qubit algebra is generated by the Weyl pair
qubitXandqubitZobeying three laws: involutory squares (), self-adjointness (), and anticommutation (); - In the eight-dimensional real Clifford algebra , the eight basis blades correspond bijectively to 3-bit integer masks : the metric rule is literally bitwise XOR (
left ^ right), while anticommutation () is simply the inversion parity sign counting bit crossings!
This chapter establishes four frozen Lean 4 theorems — the qubit Weyl star identities, the no-character theorem, the absence of common Pauli eigenvectors, and the traceless Bloch operator formula — adds a fifth, the composition, adjoint and conjugation laws of Weyl displacement words, as the kernel-checked basis of the “XOR plus sign” multiplication of Pauli words, and then builds the complete runnable zero-dependency Python 3 GeometricState engine.
Bitwise blade multiplication and anticommutation. The chapter at a glance. Panel I: the masks and of XOR bit by bit into the cyan , and two magenta strands cross once, so the result is . Panel II: two cyan dashed mirrors in the plane of state vectors; the amber reflected in then , or in then , gives two dark arrows at opposite ends (Theorem Kernel.1). Panel III: the amber vector splits into a vertical cyan part and a horizontal part; the vertical goes on the diagonal of the matrix, the horizontal in the two corners (Corollary Kernel.4).
The Weyl Pair, Anticommutation, and the No-Character Theorem
In the Lean 4 module D5/S3/Quantum/FiniteDimensional.lean, the single-qubit operator algebra is formalized as the complex matrix algebra (Matrix (Fin 2) (Fin 2) ℂ), generated by the standard bit-flip and phase-flip matrices:
Why do qubitX and qubitZ alone lock down the entire noncommutative structure of a single qubit? Our first frozen theorem packages their five fundamental -algebra identities — anticommutation, self-adjointness of both generators, and unit squares of both generators — into a single parameter-free conjunction.
In the single-qubit complex matrix algebra , the Pauli generators and simultaneously satisfy all five identities:
In D5/S3/Quantum/FiniteDimensional.lean:24, the proof splits the five conjuncts via four constructor steps, applies matrix extensionality ext i j and finite case enumeration fin_cases i <;> fin_cases j over Fin 2, and discharges each entry by simp [qubitX, qubitZ, pow_two, Matrix.mul_apply, Fin.sum_univ_two]. Explicitly,
while both real symmetric matrices equal their conjugate transposes and square to . The full proof is checked by the Lean kernel.
Swap the two mirrors and the arrow lands at the opposite end. In the real plane of state vectors, is the mirror along the slanted cyan dashed line and the mirror along the horizontal one. The amber reflected in and then (the dashed jumps) ends at ; reflected in and then (the solid jumps) it ends at . The two dark arrows make one diameter: (Theorem Kernel.1).
Directly from Theorem Kernel.1, a foundational obstruction follows: why can no classical valuation assign simultaneous complex numbers to every qubit observable while preserving algebra multiplication and the identity?
In algebraic terms, such a valuation would be a unital -algebra homomorphism (a character) . Using only the anticommutation and unit-square conjuncts of Theorem Kernel.1, the next frozen lemma proves that the type of unital algebra homomorphisms from to is empty (IsEmpty).
The type of unital -algebra homomorphisms from to is empty:
Suppose is a unital -algebra homomorphism. Applying to the anticommutation identity from Theorem Kernel.1 yields . Because multiplication in the target field is commutative (mul_comm), we have
so multiplying by (linear_combination (1 / 2 : ℂ) * hSelfNegating) forces . Since has no zero divisors (mul_eq_zero.mp), either or . Yet applying to and gives and ; either zero case reduces to , a contradiction. The full proof is checked by the Lean kernel.
No Common Eigenvector and the Traceless Bloch Operator Core
While Lemma Kernel.2 rules out multiplicative characters on the full matrix algebra, one might ask a weaker state-level question: does there exist a nonzero state vector that is simultaneously an eigenvector of both and ?
In D5/S3/Quantum/QubitWitnesses.lean, the next frozen proposition proves that any vector satisfying both and must vanish identically ().
Let be a two-component complex vector and let be complex scalars. If
then
In D5/S3/Quantum/QubitWitnesses.lean:18, evaluating hX and hZ at indices and (congrFun hX 0, congrFun hX 1, congrFun hZ 0, congrFun hZ 1) yields four scalar equations:
First we prove by contradiction (by_contra hPsi0): if , then forces ; meanwhile with implies . Substituting into gives , so multiplying by (linear_combination (-1 / 2 : ℂ) * hNeg) yields , contradicting . Thus . Substituting into gives , and function extensionality funext i with fin_cases i concludes . The full proof is checked by the Lean kernel.
The eigenlines of and sit apart and meet only at the origin. Drawn in the real plane of state vectors (every eigenvector is a complex multiple of a vector on one of these lines): the solid cyan lines are the two eigenlines of ( at , at ), the dashed cyan lines those of ( horizontal, vertical). No line belongs to both, and the only common point is the green (Proposition Kernel.3).
How, then, does a three-dimensional real vector (EuclideanSpace ℝ (Fin 3)) embed into ? In D5/S3/Quantum/Measurement/Bloch/QubitBloch.lean, the traceless Bloch operator B a is defined by
(alongside the shifted operator ). The fourth frozen result in this chapter gives the exact complex matrix representation of .
For every vector , the traceless Bloch operator equals the explicit complex matrix
In D5/S3/Quantum/Measurement/Bloch/QubitBloch.lean:31, the proof applies ext i j and fin_cases i <;> fin_cases j, unfolds B, pauliMatrix (where , , and ), qubitX, and qubitZ, and closes all four matrix entries by simp and ring. The full proof is checked by the Lean kernel.
Three-Bit Blade Masks, Inversion Parity, and Two-Bit Symplectic Pauli Words
Inspecting Theorem Kernel.1 and Corollary Kernel.4 together reveals why a real 3-vector requires complex matrices when written in standard quantum notation: the single-qubit Pauli algebra is the complex matrix representation of the three-dimensional real Euclidean Clifford algebra !
In , three mutually orthogonal unit vectors obey
Instead of storing matrices, we represent the basis blades of by a 3-bit integer blade mask , where bit (1 << 0 = 1) indicates the presence of , bit (1 << 1 = 2) indicates , and bit (1 << 2 = 4) indicates :
The eight blades are the corners of a cube, and multiplying by a blade walks one edge along each direction it lights up. Right is (bit ), into the page , up ; each corner carries its blade and mask. The two amber arrows leave (), walk one edge along and one along , and stop at (): multiplying by () lands on . The sign of this product is ; the figure draws no signs, which come from the inversion count below.
| Mask (dec) | Binary | Basis Blade | Grade | Square | Reverse | Complex Pauli Image |
|---|---|---|---|---|---|---|
0 | 000₂ | (scalar) | ||||
1 | 001₂ | (vector) | ||||
2 | 010₂ | (vector) | ||||
3 | 011₂ | (bivector) | ||||
4 | 100₂ | (vector) | ||||
5 | 101₂ | (bivector) | ||||
6 | 110₂ | (bivector) | ||||
7 | 111₂ | (pseudoscalar) |
The colours of the diagonal. With e₁₂ · e₁₂ chosen, the right panel shows the right e₁ moving past the left e₂: the two magenta lines cross once, then e₁e₁ and e₂e₂ each cancel to a cyan +1, and the result is −1. Along the dashed diagonal the cells of 1, e₁, e₂, e₃ are cyan (square +1) and those of e₁₂, e₁₃, e₂₃, I₃ magenta (square −1), as in the “Square” column of the table above.
With this 3-bit encoding, the geometric product of any two basis blades and reduces to two bitwise operations (Panel I of the chapter overview figure):
-
Target blade mask via bitwise XOR: Whenever a basis vector appears in both and , cancels that bit; basis vectors appearing in only one operand survive. Thus the product blade has mask
-
Sign factor via bit-inversion parity: Sorting the concatenated product into canonical order requires moving each active bit of past every active bit of (captured by the low-bit mask
(1 << i) - 1). Each crossing flips the sign via (), giving_blade_sign(left, right):
One swap, one sign: e₂ · e₁ = −e₁₂. In either order the masks give 001₂ ⊕ 010₂ = 011₂. In e₁ · e₂ the two factors are already in order, no swap is needed, and that cell of the table is cyan; in e₂ · e₁ the right e₁ has to move past the left e₂, the two magenta lines in the right panel cross once, the sign becomes −, and this cell is magenta.
Notice how both conventions in the code fit together with 100% consistency:
- 3-bit basis blades (
basis(0..2)at masks1, 2, 4) and pseudoscalar (mask = 7): The three orthogonal spatial axes occupy bits (masks 1, 2, 4). The oriented volume pseudoscalar (mask = 7) commutes with every blade and satisfies . Under the complex representation , the bivector equals (and similarly , ).
The square of the pseudoscalar: I₃ · I₃ = −1. All three bits cancel (three cyan crosses in the ⊕ row); the magenta crossings in the right panel number 0 + 1 + 2 = 3, an odd count, so the result is −1. The violet row and column of I₃ agree cell by cell: I₃ commutes with every blade.
-
2-bit symplectic Pauli words (
pauli(x, z, phase)at masks0..3): To model a binary Weyl pair directly via two anticommuting involutions,GeometricState.pauli(x, z, phase)places the bit on bit (, mask1) and the bit on bit (, mask2), formingmask = (1 if x else 0) | (2 if z else 0). When both bits are active (), the mask is011₂ = 3(), and XOR multiplication automatically satisfies
Finally, the reversion anti-involution (reverse()) reverses the order of vector factors in each -blade, multiplying grade by ( for grades and for grades ).
Reversing the factors takes swaps, and every swap flips the sign. Each panel has the factors of a grade- blade on top and the reversed order at the bottom; each swap of neighbours is two crossing magenta strands. Grades and need no swap and carry a cyan ; grade needs swap and grade needs , and both carry a magenta , as in the “Reverse” column of the table.
So far, the rule “XOR the indices, then multiply by a sign” has been obtained only by counting swaps against the Clifford axioms. For words built from one pair of generators it has a kernel-checked general form, and not only for two levels: replace “negate” by “multiply by an -th root of unity” and the same rule holds for any -level system. The module D5/S3/Quantum/Algebra/WeylDisplacement at the pinned commit, with its two follow-up modules, freezes it.
Let be a positive integer ([NeZero M]), with indices in (ZMod M); denotes the standard representative of .
- The window root
windowRootis ; - The clock matrix
clockMatrixis the diagonal complex matrix indexed by whose -th diagonal entry is , written ; - The shift matrix
shiftMatrixis the circulant matrixMatrix.circulant (fun i => if i = 1 then 1 else 0), whose entry is when and otherwise, written ; - The displacement word
displacementis , written .
Let be a positive integer, in the notation of Definition Kernel.5. For all (products and differences in the exponents are computed in and then replaced by their standard representatives):
- Composition law: ;
- Adjoint law: ;
- Exchange law: ;
- Conjugation law: ;
- The sign really occurs: for , .
The key step is pushing the clock past the shift: , hence ; moreover , so exponents matter only modulo . Claim 1 follows by reordering accordingly. Claim 2: , reordered by Claim 1 with phase . Claim 3 compares Claim 1 applied in the two orders. Claim 4 multiplies Claim 1 by Claim 2; the three phase exponents add up to . Claim 5 is Claim 1 with . The full proof is checked by the Lean kernel.
The exponent of Claim 4 is the symplectic pairing of the two index pairs and : it changes sign when the pairs are swapped and vanishes when a pair is paired with itself. Claim 3 yields a commutation criterion (a manual derivation, not formalized in this book; the Lean module itself states no such consequence): is invertible, so and commute if and only if , that is, .
For one swap is not a change of sign but a turn by . The left panel shows the three basis vectors of a three-level system: the cyan arrows are the shift , which pushes each one to the next round the ring, and the violet are the phases the clock gives them. The right panel is the unit circle of phases: by the composition law , and the violet arc turns from to ; the dashed arc is the same arc for , a turn of to , which is a change of sign (Theorem Kernel.6).
The multiplication law for several -level systems side by side is already cited in Chapter 14, Lemma 14.6: its cross-phase exponent is the exponent of Claim 1 summed over the systems.
Take . Then , and by Definition Kernel.5:
The four words are , , and . Addition in is XOR, so the composition law reads
Multiplication table (rows: left factor; columns: right factor; every entry obtained from the formula above and cross-checked by multiplying matrices):
| left \ right | ||||
|---|---|---|---|---|
Minus signs occur exactly in the four cells where the left factor contains () and the right factor contains (): this is the exponent . The bottom-right entry agrees with .
Comparison with the bit rule of this section. With in bit and in bit , the inversion-count formula of this section has a single term for two-bit masks:
which is the exponent of the composition law (, ); the XOR of the output mask corresponds to adding indices. The engine’s two-bit rule agrees entry by entry with the multiplication of the matrix words .
Commutation table. By the symplectic pairing : and give , so they anticommute; and give , anticommute; and give , anticommute; every word paired with itself gives . The three nontrivial words anticommute pairwise, in agreement with the opposite signs at mirrored positions of the multiplication table.
Three levels for comparison. For , and the composition law gives : one exchange is no longer a sign flip but a turn through ; two words commute if and only if .
The multiplication table of the four Pauli words. Two bits only: bit 0 is X, bit 1 is Z. The four magenta cells are exactly those whose left factor contains Z and right factor contains X; the chosen Z · X takes one swap and gives −XZ. This is the exponent bc of the composition law Theorem Kernel.6 for M = 2.
Zero-Dependency Python 3 Geometric Algebra Engine and Self-Test
The eight blades first combine with real coefficients: the table gives a faithful complex Pauli matrix representation of the real algebra , with its literature context in Remark Kernel.9. The code stores coefficients as complex, allowing an independent complex coefficient for every blade. The 1j in pauli(x, z, phase) is an external coefficient phase, kept separate from the real algebra’s volume blade ; the table no longer gives a faithful representation of this enlarged complex-coefficient container. reverse() reverses blade factors and extends linearly in the coefficients, without conjugating them. In the ideal real-coefficient algebra, the scalar part of a multivector times its reverse is the nonnegative sum of the squared blade coefficients. The actual norm_squared() uses floating-point arithmetic, and every construction (including each operation’s result) discards coefficients of absolute value at most 1e-14, so its return value need not equal that sum exactly. The next companion section uses real coefficients on even blades and imposes the unit condition on its rotors, so reversion supplies the inverse and the sandwich acts as a three-dimensional rotation.
Here is the complete, runnable, zero-dependency Python 3 implementation of GeometricState (the first half of what this book calls part7_engine.py):
from __future__ import annotations
from dataclasses import dataclass
from typing import Dict, Mapping
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))
Let us trace the bitwise arithmetic and Bloch-operator correspondence on concrete inputs.
-
Bitwise trace of
_blade_sign:- For : , , and
1 ^ 2 = 3(). In_blade_sign(1, 2), only is active in , and(2 & 0).bit_count() == 0, so and . - For : , , and
2 ^ 1 = 3. In_blade_sign(2, 1), is active in , and(1 & 1).bit_count() == 1, so and .
- For : , , and
-
Square of the volume pseudoscalar : With , the XOR mask is
7 ^ 7 = 0(the scalar ). Across ,_blade_sign(7, 7)counts inversions, yielding . -
Square of a Bloch vector : Take and form (
terms = {1: 3, 2: 4, 4: 12}). In , all six off-diagonal products cancel by opposite inversion parity, leaving only the scalar mask0:matching the square of the complex matrix from Corollary Kernel.4:
Cross terms cancel in pairs. The nine terms of v = 3e₁ + 4e₂ + 12e₃ squared come in one at a time: the three diagonal ones are the cyan 9, 16 and 144; each cross term comes once cyan and once magenta, the cyan and magenta bars on the right are equally long, and the net is 0. In the end v² = 169, matching the square 169 I₂ of B(3, 4, 12) from Corollary Kernel.4.
Literature result, not formalized in this book. Two bodies of classical literature surround the algebraic structures of this chapter:
- Isomorphism and Clifford algebra classification (P. Lounesto, Clifford Algebras and Spinors, 2nd Ed., Cambridge University Press, 2001, Ch. 3 & Ch. 16; H. B. Lawson & M.-L. Michelsohn, Spin Geometry, Princeton University Press, 1989, Ch. I): As an eight-dimensional real associative algebra, is isomorphic to with center , while its four-dimensional even subalgebra is isomorphic to the quaternion division ring .
- Binary symplectic Pauli representation and the Gottesman–Knill theorem (D. Gottesman, Stabilizer Codes and Quantum Error Correction, PhD thesis, Caltech, 1997, arXiv:quant-ph/9705052; S. Aaronson & D. Gottesman, Phys. Rev. A 70, 052328, 2004, DOI 10.1103/PhysRevA.70.052328): Modulo central phases, the -qubit Pauli group is isomorphic to the -dimensional binary symplectic space , where group multiplication is bitwise XOR and commutation is governed by the binary symplectic form. For a single -level system, the composition phase and the conjugation phase of displacement words ( being the one-qubit Pauli words) are verified by Theorem Kernel.6, and the multiplication of multi-mode Pauli words with its cross phase by Lemma 14.6 in Chapter 14; the global statement “isomorphic to a symplectic vector space modulo phases”, the stabilizer tableau, the action of Clifford gates on symplectic vectors and the Gottesman–Knill simulation theorem remain literature results.
- Exact scope of the frozen theorems: The five Lean-verified results in this chapter are the composition, adjoint, exchange and conjugation laws of Weyl displacement words (Theorem Kernel.6), the qubit Weyl star identities (Theorem Kernel.1), the no-character theorem on (Lemma Kernel.2), the absence of a nonzero common eigenvector of
qubitXandqubitZ(Proposition Kernel.3), and the explicit matrix formula for the traceless Bloch operator (Corollary Kernel.4). The Python 3GeometricStateengine provides an executable computational model of and does not claim a Lean formalization of the universal Clifford isomorphism or the -qubit Gottesman–Knill complexity theorem.
The blade-multiplication lab. Click any cell of the multiplication table and the right panel takes that product apart into swaps and cancellations; the “Pauli” and “Vector²” scenes correspond to Example Kernel.7 and Example Kernel.8.
With GeometricState in hand, we now ask: how do we compile an arbitrary single-qubit gate into an even-subalgebra rotor and rotate Bloch vectors via the double-sided sandwich product ? Let us turn to Single-Qubit Rotor Compilation: Bloch Geometry Theorems and the ZYZ Euler Compiler.