From ee6a50f4e18dc259def285265883caefd8940309 Mon Sep 17 00:00:00 2001 From: Samyak Date: Mon, 2 Nov 2026 01:28:56 +0530 Subject: [PATCH 1/9] [QuantumInfo/StabilizerFormalism]: Added `PauliGroups.lean` Add structure for `n` qubit Pauli Operator using Tableau of X and Z bit strings, and added sympletic product of Operators to show commutation later. --- QuantumInfo.lean | 1 + .../StabilizerFormalism/PauliGroups.lean | 96 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 QuantumInfo/StabilizerFormalism/PauliGroups.lean diff --git a/QuantumInfo.lean b/QuantumInfo.lean index 250d0ab6d9..2c44ee02fd 100644 --- a/QuantumInfo.lean +++ b/QuantumInfo.lean @@ -77,6 +77,7 @@ public import QuantumInfo.Operators.Unitary public import QuantumInfo.ResourceTheory.FreeState public import QuantumInfo.ResourceTheory.HypothesisTesting public import QuantumInfo.ResourceTheory.SteinsLemma +public import QuantumInfo.StabilizerFormalism.PauliGroups public import QuantumInfo.States.Ensemble public import QuantumInfo.States.Entanglement public import QuantumInfo.States.Mixed.Fidelity diff --git a/QuantumInfo/StabilizerFormalism/PauliGroups.lean b/QuantumInfo/StabilizerFormalism/PauliGroups.lean new file mode 100644 index 0000000000..b6ab793c0d --- /dev/null +++ b/QuantumInfo/StabilizerFormalism/PauliGroups.lean @@ -0,0 +1,96 @@ +/- +Copyright (c) 2026 Samyak Rai. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Samyak Rai +-/ + +module + +public import Mathlib.Algebra.BigOperators.Group.Finset.Basic +public import Mathlib.Data.ZMod.Basic + +/-! + +# Pauli groups + +The binary symplectic representation of the `n`-qubit Pauli group. + +## i. Overview + +An `n`-qubit Pauli operator is, up to a phase in `{1, -1, i, -i}`, a tensor product of the +single-qubit Pauli matrices `I`, `X`, `Y` and `Z`. The Pauli group `Gₙ` is the group these +operators generate under matrix multiplication. It has order `4^(n+1)`, and any two of its +elements either commute or anticommute. + +Ignoring phases, a Pauli operator is described by two bit strings `x` and `z` of length `n`: +qubit `i` carries an `X` when `x i = 1` and a `Z` when `z i = 1`, so it carries a `Y` when both +are `1`. This identifies the quotient of the Pauli group by its phases with `(ℤ/2ℤ)^(2n)`, +represented here by the structure `PauliOp`. Under this identification, multiplication of Pauli +operators becomes componentwise addition of the bit strings, up to phase, and the commutator of +two operators is recorded by the symplectic product `PauliOp.symplectic`. + +## ii. Key results + +- `PauliOp` : the phase-free binary representation of an `n`-qubit Pauli operator. +- `PauliOp.symplectic` : the symplectic product detecting whether two Pauli operators commute. +- `PauliOp.symplectic_self` : the symplectic product of an operator with itself is zero. + +## iii. Table of contents + +- A. The binary representation of Pauli operators +- B. The symplectic product + +## iv. References + +- [Pauli group, Wikipedia](https://en.wikipedia.org/wiki/Pauli_group) +- [Nielsen and Chuang, Quantum Computation and Quantum Information][nielsen2010] + +## A. The binary representation of Pauli operators + +-/ + +/-- The binary symplectic representation of an `n`-qubit Pauli operator. + +The fields `x` and `z` encode, for each qubit, the presence of an `X` and a `Z` factor: +qubit `i` carries `X` when `x i = 1`, `Z` when `z i = 1`, `Y` when both are `1`, and `I` when +both are `0`. The phase of the operator, an element of `{1, -1, i, -i}`, is not recorded. -/ +@[ext] +structure PauliOp (n : ℕ) where + /-- The `X` component of the Pauli operator. -/ + x : Fin n → ZMod 2 + /-- The `Z` component of the Pauli operator. -/ + z : Fin n → ZMod 2 + +namespace PauliOp + +variable {n : ℕ} + +/-! + +## B. The symplectic product + +-/ + +/-- The symplectic product of two Pauli operators. + +Two `n`-qubit Pauli operators commute if and only if their symplectic product is `0`, and +anticommute if and only if it is `1`. -/ +def symplectic (P Q : PauliOp n) : ZMod 2 := + ∑ i, (P.x i * Q.z i - P.z i * Q.x i) + +/-- The symplectic product of a Pauli operator with itself is zero. -/ +lemma symplectic_self (P : PauliOp n) : P.symplectic P = 0 := by + apply Finset.sum_eq_zero + intro i _ + rw [mul_comm (P.z i) (P.x i), sub_self] + +end PauliOp + +/- +TODO: +- The additive group structure on `PauliOp n`, corresponding to multiplication of Pauli + operators up to phase. +- Bilinearity and symmetry of the symplectic product. +- The interpretation map sending `PauliOp n` to a unitary on `n` qubits, a group homomorphism + up to phase, and the lemma that `P.symplectic Q = 0` if and only if the operators commute. +-/ From 988674f156270a4ddfa280e49d7109882e9f5e08 Mon Sep 17 00:00:00 2001 From: Samyak Date: Mon, 2 Nov 2026 02:56:28 +0530 Subject: [PATCH 2/9] Refactored structure of Pauli Group Starting with single qubit and then building on that to multiqubit. --- .../StabilizerFormalism/PauliGroups.lean | 99 +++++++++++++------ 1 file changed, 69 insertions(+), 30 deletions(-) diff --git a/QuantumInfo/StabilizerFormalism/PauliGroups.lean b/QuantumInfo/StabilizerFormalism/PauliGroups.lean index b6ab793c0d..516ecd629b 100644 --- a/QuantumInfo/StabilizerFormalism/PauliGroups.lean +++ b/QuantumInfo/StabilizerFormalism/PauliGroups.lean @@ -6,59 +6,92 @@ Authors: Samyak Rai module -public import Mathlib.Algebra.BigOperators.Group.Finset.Basic -public import Mathlib.Data.ZMod.Basic +public import QuantumInfo.States.Pure.Qubit /-! # Pauli groups The binary symplectic representation of the `n`-qubit Pauli group. +A Pauli group is a group formed by tensor products of Pauli matrices, +including the identity. ## i. Overview -An `n`-qubit Pauli operator is, up to a phase in `{1, -1, i, -i}`, a tensor product of the -single-qubit Pauli matrices `I`, `X`, `Y` and `Z`. The Pauli group `Gₙ` is the group these -operators generate under matrix multiplication. It has order `4^(n+1)`, and any two of its -elements either commute or anticommute. +The single-qubit Pauli group is a 16-element matrix group, consisting +of the 4 Pauli matrices each with 4 possible phase factors. +The n-qubit Pauli group is a 4ⁿ⁺¹ element group consisting of tensor +products of single-qubit Paulis. -Ignoring phases, a Pauli operator is described by two bit strings `x` and `z` of length `n`: -qubit `i` carries an `X` when `x i = 1` and a `Z` when `z i = 1`, so it carries a `Y` when both -are `1`. This identifies the quotient of the Pauli group by its phases with `(ℤ/2ℤ)^(2n)`, -represented here by the structure `PauliOp`. Under this identification, multiplication of Pauli -operators becomes componentwise addition of the bit strings, up to phase, and the commutator of -two operators is recorded by the symplectic product `PauliOp.symplectic`. +An `n`-qubit Pauli operator is recorded by a phase `p : ZMod 4`, contributing the factor +`i^p`, and two bit strings `x` and `z` of length `n`: qubit `i` carries an `X` when `x i = 1` +and a `Z` when `z i = 1`, so it carries a `Y` when both are `1`. This is the structure +`PauliOp`. Multiplication of Pauli operators corresponds to componentwise addition of the bit +strings together with a phase update, and the commutator of two operators is recorded by the +symplectic product `PauliOp.symplectic`, which does not depend on the phases. ## ii. Key results -- `PauliOp` : the phase-free binary representation of an `n`-qubit Pauli operator. -- `PauliOp.symplectic` : the symplectic product detecting whether two Pauli operators commute. +- `Qubit.pauliSingle` : the single-qubit Pauli operator `i^p X^x Z^z` for phase `p` and bits + `x` and `z`. +- `Qubit.symplecticSingle` : the symplectic product of two single-qubit Pauli operators. +- `PauliOp` : the binary representation of an `n`-qubit Pauli operator, with phase. +- `PauliOp.symplectic` : the symplectic product of Pauli operators. - `PauliOp.symplectic_self` : the symplectic product of an operator with itself is zero. +- `PauliOp.symplectic_eq_sum` : the symplectic product is the sum of the single-qubit + symplectic products. ## iii. Table of contents -- A. The binary representation of Pauli operators -- B. The symplectic product +- A. The single-qubit Pauli operators +- B. The binary representation of Pauli operators +- C. The symplectic product ## iv. References - [Pauli group, Wikipedia](https://en.wikipedia.org/wiki/Pauli_group) - [Nielsen and Chuang, Quantum Computation and Quantum Information][nielsen2010] -## A. The binary representation of Pauli operators +## A. The single-qubit Pauli operators + +-/ + +@[expose] public section + +namespace Qubit + +/-- The single-qubit Pauli operator `i^p X^x Z^z`, for phase `p` and bits `x` and `z`. +As `p : ZMod 4`, `x : ZMod 2` and `z : ZMod 2` range over their values, these are the +16 elements of the one-qubit Pauli group. -/ +def PauliSingle (p : ZMod 4) (x z : ZMod 2) : Matrix Qubit Qubit ℂ := + Complex.I ^ p.val • (X ^ x.val * Z ^ z.val).val + + +/-- The symplectic product of two elements `u`, `v` ∈ `(ℤ/2ℤ)²` with +`z, x, z', x' ∈ ℤ/2ℤ`: +`u ⊙ v ≡ z x' - x z'`, +where `u = z|x` and `v = z'|x'` (this notation represents binary +string concatenation, e.g. `01 ≡ 0|1`). -/ +def symplecticSingle (z x z' x' : ZMod 2) : ZMod 2 := + z * x' - x * z' + +end Qubit + +/-! + +## B. The binary representation of Pauli operators -/ /-- The binary symplectic representation of an `n`-qubit Pauli operator. -The fields `x` and `z` encode, for each qubit, the presence of an `X` and a `Z` factor: -qubit `i` carries `X` when `x i = 1`, `Z` when `z i = 1`, `Y` when both are `1`, and `I` when -both are `0`. The phase of the operator, an element of `{1, -1, i, -i}`, is not recorded. -/ +The field `phase` records the scalar factor `i^phase`. The fields `x` and `z` encode, for each +qubit, the presence of an `X` and a `Z` factor: qubit `i` carries `X` when `x i = 1`, `Z` when +`z i = 1`, `Y` when both are `1`, and `I` when both are `0`. -/ @[ext] structure PauliOp (n : ℕ) where - /-- The `X` component of the Pauli operator. -/ + phase : ZMod 4 x : Fin n → ZMod 2 - /-- The `Z` component of the Pauli operator. -/ z : Fin n → ZMod 2 namespace PauliOp @@ -67,30 +100,36 @@ variable {n : ℕ} /-! -## B. The symplectic product +## C. The symplectic product -/ /-- The symplectic product of two Pauli operators. Two `n`-qubit Pauli operators commute if and only if their symplectic product is `0`, and -anticommute if and only if it is `1`. -/ +anticommute if and only if it is `1`. The product does not depend on the phases of the +operators. -/ def symplectic (P Q : PauliOp n) : ZMod 2 := - ∑ i, (P.x i * Q.z i - P.z i * Q.x i) + ∑ i, (P.z i * Q.x i - P.x i * Q.z i) + +/-- The symplectic product is the sum of the single-qubit symplectic products. -/ +lemma symplectic_eq_sum (P Q : PauliOp n) : + P.symplectic Q = ∑ i, Qubit.symplecticSingle (P.z i) (P.x i) (Q.z i) (Q.x i) := + rfl /-- The symplectic product of a Pauli operator with itself is zero. -/ lemma symplectic_self (P : PauliOp n) : P.symplectic P = 0 := by apply Finset.sum_eq_zero intro i _ - rw [mul_comm (P.z i) (P.x i), sub_self] + rw [mul_comm (P.x i) (P.z i), sub_self] end PauliOp /- TODO: -- The additive group structure on `PauliOp n`, corresponding to multiplication of Pauli - operators up to phase. +- The group structure on `PauliOp n`: the phase-aware multiplication law, corresponding to + matrix multiplication of Pauli operators. - Bilinearity and symmetry of the symplectic product. -- The interpretation map sending `PauliOp n` to a unitary on `n` qubits, a group homomorphism - up to phase, and the lemma that `P.symplectic Q = 0` if and only if the operators commute. +- The interpretation map sending `PauliOp n` to a unitary on `n` qubits, a group homomorphism, + and the lemma that `P.symplectic Q = 0` if and only if the operators commute. -/ From 63b26e186916892d058c33c8d41c34907610599f Mon Sep 17 00:00:00 2001 From: Samyak Date: Mon, 2 Nov 2026 03:25:54 +0530 Subject: [PATCH 3/9] Added n product tensor product multiplication for N Qubit Pauli Multiplication --- QuantumInfo/ForMathlib/Matrix.lean | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/QuantumInfo/ForMathlib/Matrix.lean b/QuantumInfo/ForMathlib/Matrix.lean index 9d57710eaa..fdf88377fd 100644 --- a/QuantumInfo/ForMathlib/Matrix.lean +++ b/QuantumInfo/ForMathlib/Matrix.lean @@ -1532,6 +1532,15 @@ lemma trace_piProd [CommSemiring R] : symm simp [trace, piProd, Fintype.prod_sum] +/-- Multiplication of `piProd` tensor products is entrywise: the tensor product of products is +the product of the tensor products. -/ +lemma piProd_mul [CommSemiring R] (A B : ∀ i, Matrix (d i) (d i) R) : + piProd (fun i ↦ A i * B i) = piProd A * piProd B := by + ext j k + simp only [piProd, Matrix.of_apply, Matrix.mul_apply] + rw [Fintype.prod_sum] + exact Finset.sum_congr rfl fun p _ ↦ Finset.prod_mul_distrib + open ComplexOrder MatrixOrder in lemma PosSemidef.piProd [RCLike R] (hA : ∀ i, (A i).PosSemidef) : (piProd A).PosSemidef := by From da3f8d2555a6c77fc3a22f2746307e4a98e94082 Mon Sep 17 00:00:00 2001 From: Samyak Date: Mon, 2 Nov 2026 04:16:56 +0530 Subject: [PATCH 4/9] Single Qubit Commutation is proven by Sympletic product Solving each case is just extremely painful. I think there has to be a better way to do this, currentlu just walking through all 4x4=16 cases. --- .../StabilizerFormalism/PauliGroups.lean | 73 ++++++++++++++++++- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/QuantumInfo/StabilizerFormalism/PauliGroups.lean b/QuantumInfo/StabilizerFormalism/PauliGroups.lean index 516ecd629b..2905d6c6e7 100644 --- a/QuantumInfo/StabilizerFormalism/PauliGroups.lean +++ b/QuantumInfo/StabilizerFormalism/PauliGroups.lean @@ -32,8 +32,11 @@ symplectic product `PauliOp.symplectic`, which does not depend on the phases. ## ii. Key results -- `Qubit.pauliSingle` : the single-qubit Pauli operator `i^p X^x Z^z` for phase `p` and bits +- `Qubit.PauliSingle` : the single-qubit Pauli operator `i^p X^x Z^z` for phase `p` and bits `x` and `z`. +- `Qubit.pauliSingle_commute_iff` : two single-qubit Pauli operators commute if and only if + their symplectic product is zero. +- `Qubit.symplecticSingle` : the symplectic product of two single-qubit Pauli operators. - `Qubit.symplecticSingle` : the symplectic product of two single-qubit Pauli operators. - `PauliOp` : the binary representation of an `n`-qubit Pauli operator, with phase. - `PauliOp.symplectic` : the symplectic product of Pauli operators. @@ -66,8 +69,11 @@ As `p : ZMod 4`, `x : ZMod 2` and `z : ZMod 2` range over their values, these ar def PauliSingle (p : ZMod 4) (x z : ZMod 2) : Matrix Qubit Qubit ℂ := Complex.I ^ p.val • (X ^ x.val * Z ^ z.val).val +/-- Every element of `ZMod 2` is `0` or `1`. -/ +lemma zmod2_eq_zero_or_one : ∀ a : ZMod 2, a = 0 ∨ a = 1 := by + decide -/-- The symplectic product of two elements `u`, `v` ∈ `(ℤ/2ℤ)²` with +/-- The symplectic product of two elements `u`, `v` ∈ `(ℤ/2ℤ)²` with `z, x, z', x' ∈ ℤ/2ℤ`: `u ⊙ v ≡ z x' - x z'`, where `u = z|x` and `v = z'|x'` (this notation represents binary @@ -75,6 +81,62 @@ string concatenation, e.g. `01 ≡ 0|1`). -/ def symplecticSingle (z x z' x' : ZMod 2) : ZMod 2 := z * x' - x * z' +/-- Two single-qubit Pauli operators commute if and only if their symplectic product is +zero. -/ +lemma pauliSingle_commute_iff (p q : ZMod 4) (x z x' z' : ZMod 2) : + Commute (PauliSingle p x z) (PauliSingle q x' z') ↔ symplecticSingle x z x' z' = 0 := by + have hphase0 : PauliSingle p (0 : ZMod 2) 0 + = Complex.I ^ p.val • (1 : Matrix Qubit Qubit ℂ) := by + simp only [PauliSingle, show (0 : ZMod 2).val = 0 from rfl, pow_zero, mul_one, + Submonoid.coe_one] + have hphase0' : PauliSingle q (0 : ZMod 2) 0 + = Complex.I ^ q.val • (1 : Matrix Qubit Qubit ℂ) := by + simp only [PauliSingle, show (0 : ZMod 2).val = 0 from rfl, pow_zero, mul_one, + Submonoid.coe_one] + rcases zmod2_eq_zero_or_one x with rfl | rfl <;> + rcases zmod2_eq_zero_or_one z with rfl | rfl <;> + rcases zmod2_eq_zero_or_one x' with rfl | rfl <;> + rcases zmod2_eq_zero_or_one z' with rfl | rfl + · -- (x, z) = (0, 0), (u, v) = (0, 0) + simp only [symplecticSingle, zero_mul, sub_self, iff_true, hphase0] + rw [commute_iff_eq, Matrix.smul_mul, Matrix.mul_smul, one_mul, mul_one] + · -- (x, z) = (0, 0), (u, v) = (0, 1) + simp only [symplecticSingle, zero_mul, sub_self, iff_true, hphase0] + rw [commute_iff_eq, Matrix.smul_mul, Matrix.mul_smul, one_mul, mul_one] + · -- (x, z) = (0, 0), (u, v) = (1, 0) + simp only [symplecticSingle, zero_mul, sub_self, iff_true, hphase0] + rw [commute_iff_eq, Matrix.smul_mul, Matrix.mul_smul, one_mul, mul_one] + · -- (x, z) = (0, 0), (u, v) = (1, 1) + simp only [symplecticSingle, zero_mul, sub_self, iff_true, hphase0] + rw [commute_iff_eq, Matrix.smul_mul, Matrix.mul_smul, one_mul, mul_one] + · -- (x, z) = (0, 1), (u, v) = (0, 0) + simp only [symplecticSingle, mul_zero, sub_self, iff_true, hphase0'] + rw [commute_iff_eq, Matrix.mul_smul, Matrix.smul_mul, mul_one, one_mul] + · -- (x, z) = (0, 1), (u, v) = (0, 1) + sorry + · -- (x, z) = (0, 1), (u, v) = (1, 0) + sorry + · -- (x, z) = (0, 1), (u, v) = (1, 1) + sorry + · -- (x, z) = (1, 0), (u, v) = (0, 0) + simp only [symplecticSingle, mul_zero, sub_self, iff_true, hphase0'] + rw [commute_iff_eq, Matrix.mul_smul, Matrix.smul_mul, mul_one, one_mul] + · -- (x, z) = (1, 0), (u, v) = (0, 1) + sorry + · -- (x, z) = (1, 0), (u, v) = (1, 0) + sorry + · -- (x, z) = (1, 0), (u, v) = (1, 1) + sorry + · -- (x, z) = (1, 1), (u, v) = (0, 0) + simp only [symplecticSingle, mul_zero, sub_self, iff_true, hphase0'] + rw [commute_iff_eq, Matrix.mul_smul, Matrix.smul_mul, mul_one, one_mul] + · -- (x, z) = (1, 1), (u, v) = (0, 1) + sorry + · -- (x, z) = (1, 1), (u, v) = (1, 0) + sorry + · -- (x, z) = (1, 1), (u, v) = (1, 1) + sorry + end Qubit /-! @@ -114,8 +176,11 @@ def symplectic (P Q : PauliOp n) : ZMod 2 := /-- The symplectic product is the sum of the single-qubit symplectic products. -/ lemma symplectic_eq_sum (P Q : PauliOp n) : - P.symplectic Q = ∑ i, Qubit.symplecticSingle (P.z i) (P.x i) (Q.z i) (Q.x i) := - rfl + P.symplectic Q = ∑ i, Qubit.symplecticSingle (P.x i) (P.z i) (Q.x i) (Q.z i) := by + simp only [symplectic, symplecticSingle] + apply Finset.sum_congr rfl + intro i _ + rw [CharTwo.sub_eq_add, CharTwo.sub_eq_add, add_comm] /-- The symplectic product of a Pauli operator with itself is zero. -/ lemma symplectic_self (P : PauliOp n) : P.symplectic P = 0 := by From bfb21b5f7c857d5fbf18cb66225901e43eee228e Mon Sep 17 00:00:00 2001 From: Samyak Date: Thu, 26 Nov 2026 01:58:32 +0530 Subject: [PATCH 5/9] [Refactor] Moved PauliGroups from QInfo to Physlib Move the single-qubit Pauli group from QuantumInfo to Physlib along with lemma for commutation and sympletic product. --- Physlib.lean | 1 + .../QuantumMechanics/Qubit/PauliGroups.lean | 141 ++++++++++++ QuantumInfo.lean | 1 - .../StabilizerFormalism/PauliGroups.lean | 200 ------------------ 4 files changed, 142 insertions(+), 201 deletions(-) create mode 100644 Physlib/QuantumMechanics/Qubit/PauliGroups.lean delete mode 100644 QuantumInfo/StabilizerFormalism/PauliGroups.lean diff --git a/Physlib.lean b/Physlib.lean index d5b3f53ada..b0e3415be1 100644 --- a/Physlib.lean +++ b/Physlib.lean @@ -476,6 +476,7 @@ public import Physlib.QuantumMechanics.PlanckConstant public import Physlib.QuantumMechanics.PoschlTeller.Basic public import Physlib.QuantumMechanics.PoschlTeller.Scattering public import Physlib.QuantumMechanics.QuantumSystem.Basic +public import Physlib.QuantumMechanics.Qubit.PauliGroups public import Physlib.QuantumMechanics.RectangularBarrier.Basic public import Physlib.QuantumMechanics.SpaceDQuantumSystem public import Physlib.Relativity.Bispinors.Basic diff --git a/Physlib/QuantumMechanics/Qubit/PauliGroups.lean b/Physlib/QuantumMechanics/Qubit/PauliGroups.lean new file mode 100644 index 0000000000..0bf93ca5a6 --- /dev/null +++ b/Physlib/QuantumMechanics/Qubit/PauliGroups.lean @@ -0,0 +1,141 @@ +/- +Copyright (c) 2026 Samyak Rai. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Samyak Rai +-/ + +module + +public import Mathlib.Data.ZMod.Basic +public import Physlib.Relativity.PauliMatrices.Basic + +/-! + +# Pauli groups + +The single-qubit Pauli group in its binary symplectic representation. + +## i. Overview + +The single-qubit Pauli group is a 16-element matrix group, consisting of the four Pauli +matrices, including the identity, each with four possible phase factors. A single-qubit Pauli +operator is recorded by a phase `p : ZMod 4`, contributing the factor `i^p`, and two bits +`x` and `z`: the operator carries an `X` when `x = 1` and a `Z` when `z = 1`, so it carries a +`Y` when both are `1`. This is the definition `PauliGroup.single`. + +Two single-qubit Pauli operators commute exactly when their symplectic product, which does not +depend on the phases, is zero. This is recorded by `PauliGroup.symplecticSingle` and proved in +`PauliGroup.single_commute_iff`. + +## ii. Key results + +- `PauliGroup.single` : the single-qubit Pauli operator `i^p X^x Z^z` for phase `p` and bits + `x` and `z`. +- `PauliGroup.symplecticSingle` : the symplectic product of two single-qubit Pauli operators. +- `PauliGroup.single_commute_iff` : two single-qubit Pauli operators commute if and only if + their symplectic product is zero. + +## iii. Table of contents + +- A. The single-qubit Pauli operators +- B. The symplectic product + +## iv. References + +- [Pauli group, Wikipedia](https://en.wikipedia.org/wiki/Pauli_group) +- [Nielsen and Chuang, Quantum Computation and Quantum Information][nielsen_chuang_qci] + +## A. The single-qubit Pauli operators + +-/ + +@[expose] public section + +open PauliMatrix +open KroneckerDelta + +namespace PauliGroup + +/-- The single-qubit Pauli operator `i^p X^x Z^z`, for phase `p` and bits `x` and `z`. +As `p : ZMod 4`, `x : ZMod 2` and `z : ZMod 2` range over their values, these are the +16 elements of the one-qubit Pauli group. -/ +def single (p : ZMod 4) (x z : ZMod 2) : Matrix (Fin 2) (Fin 2) ℂ := + Complex.I ^ p.val • (σ1 ^ x.val * σ3 ^ z.val) + +/-! + +## B. The symplectic product + +-/ + +/-- The symplectic product of two elements `(x, z)` and `(x', z')` of `(ℤ/2ℤ)²`: +`(x, z) ⊙ (x', z') = z x' - x z'`. +The bits record the presence of an `X` and a `Z` factor, as in `PauliGroup.single`. -/ +def symplecticSingle (x z x' z' : ZMod 2) : ZMod 2 := + z * x' - x * z' + +/-- A generic criterion: if two matrices differ in a single entry after multiplication in the +two possible orders, they do not commute. -/ +private lemma not_commute_of_entry_ne {A B : Matrix (Fin 2) (Fin 2) ℂ} {i j : Fin 2} + (h : (A * B) i j ≠ (B * A) i j) : ¬ Commute A B := by + intro hcomm + rw [commute_iff_eq] at hcomm + exact h (congrArg (fun M => M i j) hcomm) + +private lemma iff_of_true {P Q : Prop} (hQ : Q) (hP : P) : P ↔ Q := + ⟨fun _ => hQ, fun _ => hP⟩ + +private lemma iff_of_false {P Q : Prop} (hQ : ¬ Q) (hP : ¬ P) : P ↔ Q := + ⟨fun h => (hP h).elim, fun h => (hQ h).elim⟩ + +/-- The symplectic product vanishes exactly when the corresponding Pauli matrices commute. -/ +private lemma commute_pauli_iff (x z x' z' : ZMod 2) : + Commute (σ1 ^ x.val * σ3 ^ z.val) (σ1 ^ x'.val * σ3 ^ z'.val) ↔ + symplecticSingle x z x' z' = 0 := by + have hbits : ∀ a : ZMod 2, a = 0 ∨ a = 1 := by decide + have hval0 : (0 : ZMod 2).val = 0 := rfl + have hval1 : (1 : ZMod 2).val = 1 := rfl + rcases hbits x with rfl | rfl <;> + rcases hbits z with rfl | rfl <;> + rcases hbits x' with rfl | rfl <;> + rcases hbits z' with rfl | rfl <;> + simp only [hval0, hval1, pow_zero, pow_one, one_mul, mul_one, symplecticSingle, + mul_zero, sub_self, sub_zero] <;> + first + | exact iff_of_true (by decide) (Commute.refl _) + | exact iff_of_true (by decide) (Commute.one_left _) + | exact iff_of_true (by decide) (Commute.one_right _) + | exact iff_of_false (by decide) + (not_commute_of_entry_ne (A := σ1) (B := σ3) (i := 0) (j := 1) + (by norm_num [pauliMatrix])) + | exact iff_of_false (by decide) + (fun h => (not_commute_of_entry_ne (A := σ3) (B := σ1) (i := 0) (j := 1) + (by norm_num [pauliMatrix])) h) + | exact iff_of_false (by decide) + (not_commute_of_entry_ne (A := σ1) (B := σ1 * σ3) (i := 0) (j := 0) + (by norm_num [pauliMatrix])) + | exact iff_of_false (by decide) + (fun h => (not_commute_of_entry_ne (A := σ1 * σ3) (B := σ1) (i := 0) (j := 0) + (by norm_num [pauliMatrix])) h) + | exact iff_of_false (by decide) + (not_commute_of_entry_ne (A := σ3) (B := σ1 * σ3) (i := 0) (j := 1) + (by norm_num [pauliMatrix])) + | exact iff_of_false (by decide) + (fun h => (not_commute_of_entry_ne (A := σ1 * σ3) (B := σ3) (i := 0) (j := 1) + (by norm_num [pauliMatrix])) h) + +/-- Phases do not affect commutation. -/ +private lemma commute_single_iff (p q : ZMod 4) (x z x' z' : ZMod 2) : + Commute (single p x z) (single q x' z') ↔ + Commute (σ1 ^ x.val * σ3 ^ z.val) (σ1 ^ x'.val * σ3 ^ z'.val) := by + simp only [single] + rw [Commute.smul_left_iff₀ (pow_ne_zero p.val Complex.I_ne_zero), + Commute.smul_right_iff₀ (pow_ne_zero q.val Complex.I_ne_zero)] + +/-- Two single-qubit Pauli operators commute if and only if their symplectic product is +zero. -/ +lemma single_commute_iff (p q : ZMod 4) (x z x' z' : ZMod 2) : + Commute (single p x z) (single q x' z') ↔ symplecticSingle x z x' z' = 0 := by + rw [commute_single_iff, commute_pauli_iff] + +end PauliGroup diff --git a/QuantumInfo.lean b/QuantumInfo.lean index 2c44ee02fd..250d0ab6d9 100644 --- a/QuantumInfo.lean +++ b/QuantumInfo.lean @@ -77,7 +77,6 @@ public import QuantumInfo.Operators.Unitary public import QuantumInfo.ResourceTheory.FreeState public import QuantumInfo.ResourceTheory.HypothesisTesting public import QuantumInfo.ResourceTheory.SteinsLemma -public import QuantumInfo.StabilizerFormalism.PauliGroups public import QuantumInfo.States.Ensemble public import QuantumInfo.States.Entanglement public import QuantumInfo.States.Mixed.Fidelity diff --git a/QuantumInfo/StabilizerFormalism/PauliGroups.lean b/QuantumInfo/StabilizerFormalism/PauliGroups.lean deleted file mode 100644 index 2905d6c6e7..0000000000 --- a/QuantumInfo/StabilizerFormalism/PauliGroups.lean +++ /dev/null @@ -1,200 +0,0 @@ -/- -Copyright (c) 2026 Samyak Rai. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. -Authors: Samyak Rai --/ - -module - -public import QuantumInfo.States.Pure.Qubit - -/-! - -# Pauli groups - -The binary symplectic representation of the `n`-qubit Pauli group. -A Pauli group is a group formed by tensor products of Pauli matrices, -including the identity. - -## i. Overview - -The single-qubit Pauli group is a 16-element matrix group, consisting -of the 4 Pauli matrices each with 4 possible phase factors. -The n-qubit Pauli group is a 4ⁿ⁺¹ element group consisting of tensor -products of single-qubit Paulis. - -An `n`-qubit Pauli operator is recorded by a phase `p : ZMod 4`, contributing the factor -`i^p`, and two bit strings `x` and `z` of length `n`: qubit `i` carries an `X` when `x i = 1` -and a `Z` when `z i = 1`, so it carries a `Y` when both are `1`. This is the structure -`PauliOp`. Multiplication of Pauli operators corresponds to componentwise addition of the bit -strings together with a phase update, and the commutator of two operators is recorded by the -symplectic product `PauliOp.symplectic`, which does not depend on the phases. - -## ii. Key results - -- `Qubit.PauliSingle` : the single-qubit Pauli operator `i^p X^x Z^z` for phase `p` and bits - `x` and `z`. -- `Qubit.pauliSingle_commute_iff` : two single-qubit Pauli operators commute if and only if - their symplectic product is zero. -- `Qubit.symplecticSingle` : the symplectic product of two single-qubit Pauli operators. -- `Qubit.symplecticSingle` : the symplectic product of two single-qubit Pauli operators. -- `PauliOp` : the binary representation of an `n`-qubit Pauli operator, with phase. -- `PauliOp.symplectic` : the symplectic product of Pauli operators. -- `PauliOp.symplectic_self` : the symplectic product of an operator with itself is zero. -- `PauliOp.symplectic_eq_sum` : the symplectic product is the sum of the single-qubit - symplectic products. - -## iii. Table of contents - -- A. The single-qubit Pauli operators -- B. The binary representation of Pauli operators -- C. The symplectic product - -## iv. References - -- [Pauli group, Wikipedia](https://en.wikipedia.org/wiki/Pauli_group) -- [Nielsen and Chuang, Quantum Computation and Quantum Information][nielsen2010] - -## A. The single-qubit Pauli operators - --/ - -@[expose] public section - -namespace Qubit - -/-- The single-qubit Pauli operator `i^p X^x Z^z`, for phase `p` and bits `x` and `z`. -As `p : ZMod 4`, `x : ZMod 2` and `z : ZMod 2` range over their values, these are the -16 elements of the one-qubit Pauli group. -/ -def PauliSingle (p : ZMod 4) (x z : ZMod 2) : Matrix Qubit Qubit ℂ := - Complex.I ^ p.val • (X ^ x.val * Z ^ z.val).val - -/-- Every element of `ZMod 2` is `0` or `1`. -/ -lemma zmod2_eq_zero_or_one : ∀ a : ZMod 2, a = 0 ∨ a = 1 := by - decide - -/-- The symplectic product of two elements `u`, `v` ∈ `(ℤ/2ℤ)²` with -`z, x, z', x' ∈ ℤ/2ℤ`: -`u ⊙ v ≡ z x' - x z'`, -where `u = z|x` and `v = z'|x'` (this notation represents binary -string concatenation, e.g. `01 ≡ 0|1`). -/ -def symplecticSingle (z x z' x' : ZMod 2) : ZMod 2 := - z * x' - x * z' - -/-- Two single-qubit Pauli operators commute if and only if their symplectic product is -zero. -/ -lemma pauliSingle_commute_iff (p q : ZMod 4) (x z x' z' : ZMod 2) : - Commute (PauliSingle p x z) (PauliSingle q x' z') ↔ symplecticSingle x z x' z' = 0 := by - have hphase0 : PauliSingle p (0 : ZMod 2) 0 - = Complex.I ^ p.val • (1 : Matrix Qubit Qubit ℂ) := by - simp only [PauliSingle, show (0 : ZMod 2).val = 0 from rfl, pow_zero, mul_one, - Submonoid.coe_one] - have hphase0' : PauliSingle q (0 : ZMod 2) 0 - = Complex.I ^ q.val • (1 : Matrix Qubit Qubit ℂ) := by - simp only [PauliSingle, show (0 : ZMod 2).val = 0 from rfl, pow_zero, mul_one, - Submonoid.coe_one] - rcases zmod2_eq_zero_or_one x with rfl | rfl <;> - rcases zmod2_eq_zero_or_one z with rfl | rfl <;> - rcases zmod2_eq_zero_or_one x' with rfl | rfl <;> - rcases zmod2_eq_zero_or_one z' with rfl | rfl - · -- (x, z) = (0, 0), (u, v) = (0, 0) - simp only [symplecticSingle, zero_mul, sub_self, iff_true, hphase0] - rw [commute_iff_eq, Matrix.smul_mul, Matrix.mul_smul, one_mul, mul_one] - · -- (x, z) = (0, 0), (u, v) = (0, 1) - simp only [symplecticSingle, zero_mul, sub_self, iff_true, hphase0] - rw [commute_iff_eq, Matrix.smul_mul, Matrix.mul_smul, one_mul, mul_one] - · -- (x, z) = (0, 0), (u, v) = (1, 0) - simp only [symplecticSingle, zero_mul, sub_self, iff_true, hphase0] - rw [commute_iff_eq, Matrix.smul_mul, Matrix.mul_smul, one_mul, mul_one] - · -- (x, z) = (0, 0), (u, v) = (1, 1) - simp only [symplecticSingle, zero_mul, sub_self, iff_true, hphase0] - rw [commute_iff_eq, Matrix.smul_mul, Matrix.mul_smul, one_mul, mul_one] - · -- (x, z) = (0, 1), (u, v) = (0, 0) - simp only [symplecticSingle, mul_zero, sub_self, iff_true, hphase0'] - rw [commute_iff_eq, Matrix.mul_smul, Matrix.smul_mul, mul_one, one_mul] - · -- (x, z) = (0, 1), (u, v) = (0, 1) - sorry - · -- (x, z) = (0, 1), (u, v) = (1, 0) - sorry - · -- (x, z) = (0, 1), (u, v) = (1, 1) - sorry - · -- (x, z) = (1, 0), (u, v) = (0, 0) - simp only [symplecticSingle, mul_zero, sub_self, iff_true, hphase0'] - rw [commute_iff_eq, Matrix.mul_smul, Matrix.smul_mul, mul_one, one_mul] - · -- (x, z) = (1, 0), (u, v) = (0, 1) - sorry - · -- (x, z) = (1, 0), (u, v) = (1, 0) - sorry - · -- (x, z) = (1, 0), (u, v) = (1, 1) - sorry - · -- (x, z) = (1, 1), (u, v) = (0, 0) - simp only [symplecticSingle, mul_zero, sub_self, iff_true, hphase0'] - rw [commute_iff_eq, Matrix.mul_smul, Matrix.smul_mul, mul_one, one_mul] - · -- (x, z) = (1, 1), (u, v) = (0, 1) - sorry - · -- (x, z) = (1, 1), (u, v) = (1, 0) - sorry - · -- (x, z) = (1, 1), (u, v) = (1, 1) - sorry - -end Qubit - -/-! - -## B. The binary representation of Pauli operators - --/ - -/-- The binary symplectic representation of an `n`-qubit Pauli operator. - -The field `phase` records the scalar factor `i^phase`. The fields `x` and `z` encode, for each -qubit, the presence of an `X` and a `Z` factor: qubit `i` carries `X` when `x i = 1`, `Z` when -`z i = 1`, `Y` when both are `1`, and `I` when both are `0`. -/ -@[ext] -structure PauliOp (n : ℕ) where - phase : ZMod 4 - x : Fin n → ZMod 2 - z : Fin n → ZMod 2 - -namespace PauliOp - -variable {n : ℕ} - -/-! - -## C. The symplectic product - --/ - -/-- The symplectic product of two Pauli operators. - -Two `n`-qubit Pauli operators commute if and only if their symplectic product is `0`, and -anticommute if and only if it is `1`. The product does not depend on the phases of the -operators. -/ -def symplectic (P Q : PauliOp n) : ZMod 2 := - ∑ i, (P.z i * Q.x i - P.x i * Q.z i) - -/-- The symplectic product is the sum of the single-qubit symplectic products. -/ -lemma symplectic_eq_sum (P Q : PauliOp n) : - P.symplectic Q = ∑ i, Qubit.symplecticSingle (P.x i) (P.z i) (Q.x i) (Q.z i) := by - simp only [symplectic, symplecticSingle] - apply Finset.sum_congr rfl - intro i _ - rw [CharTwo.sub_eq_add, CharTwo.sub_eq_add, add_comm] - -/-- The symplectic product of a Pauli operator with itself is zero. -/ -lemma symplectic_self (P : PauliOp n) : P.symplectic P = 0 := by - apply Finset.sum_eq_zero - intro i _ - rw [mul_comm (P.x i) (P.z i), sub_self] - -end PauliOp - -/- -TODO: -- The group structure on `PauliOp n`: the phase-aware multiplication law, corresponding to - matrix multiplication of Pauli operators. -- Bilinearity and symmetry of the symplectic product. -- The interpretation map sending `PauliOp n` to a unitary on `n` qubits, a group homomorphism, - and the lemma that `P.symplectic Q = 0` if and only if the operators commute. --/ From 635f0acbffa14189f38a38f5ad3e5fe17c947aef Mon Sep 17 00:00:00 2001 From: Samyak Date: Thu, 26 Nov 2026 02:05:20 +0530 Subject: [PATCH 6/9] Removed pi prod mul created earlier for Quantum Info/Stabiliser Formalism --- QuantumInfo/ForMathlib/Matrix.lean | 9 --------- 1 file changed, 9 deletions(-) diff --git a/QuantumInfo/ForMathlib/Matrix.lean b/QuantumInfo/ForMathlib/Matrix.lean index fdf88377fd..9d57710eaa 100644 --- a/QuantumInfo/ForMathlib/Matrix.lean +++ b/QuantumInfo/ForMathlib/Matrix.lean @@ -1532,15 +1532,6 @@ lemma trace_piProd [CommSemiring R] : symm simp [trace, piProd, Fintype.prod_sum] -/-- Multiplication of `piProd` tensor products is entrywise: the tensor product of products is -the product of the tensor products. -/ -lemma piProd_mul [CommSemiring R] (A B : ∀ i, Matrix (d i) (d i) R) : - piProd (fun i ↦ A i * B i) = piProd A * piProd B := by - ext j k - simp only [piProd, Matrix.of_apply, Matrix.mul_apply] - rw [Fintype.prod_sum] - exact Finset.sum_congr rfl fun p _ ↦ Finset.prod_mul_distrib - open ComplexOrder MatrixOrder in lemma PosSemidef.piProd [RCLike R] (hA : ∀ i, (A i).PosSemidef) : (piProd A).PosSemidef := by From 69d3f317bb6f6023f7ae4528e51dbdfd69a4125b Mon Sep 17 00:00:00 2001 From: Samyak Date: Thu, 26 Nov 2026 02:15:39 +0530 Subject: [PATCH 7/9] Redundant lemmas removed --- .../QuantumMechanics/Qubit/PauliGroups.lean | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/Physlib/QuantumMechanics/Qubit/PauliGroups.lean b/Physlib/QuantumMechanics/Qubit/PauliGroups.lean index 0bf93ca5a6..120acdcc28 100644 --- a/Physlib/QuantumMechanics/Qubit/PauliGroups.lean +++ b/Physlib/QuantumMechanics/Qubit/PauliGroups.lean @@ -82,12 +82,6 @@ private lemma not_commute_of_entry_ne {A B : Matrix (Fin 2) (Fin 2) ℂ} {i j : rw [commute_iff_eq] at hcomm exact h (congrArg (fun M => M i j) hcomm) -private lemma iff_of_true {P Q : Prop} (hQ : Q) (hP : P) : P ↔ Q := - ⟨fun _ => hQ, fun _ => hP⟩ - -private lemma iff_of_false {P Q : Prop} (hQ : ¬ Q) (hP : ¬ P) : P ↔ Q := - ⟨fun h => (hP h).elim, fun h => (hQ h).elim⟩ - /-- The symplectic product vanishes exactly when the corresponding Pauli matrices commute. -/ private lemma commute_pauli_iff (x z x' z' : ZMod 2) : Commute (σ1 ^ x.val * σ3 ^ z.val) (σ1 ^ x'.val * σ3 ^ z'.val) ↔ @@ -102,27 +96,28 @@ private lemma commute_pauli_iff (x z x' z' : ZMod 2) : simp only [hval0, hval1, pow_zero, pow_one, one_mul, mul_one, symplecticSingle, mul_zero, sub_self, sub_zero] <;> first - | exact iff_of_true (by decide) (Commute.refl _) - | exact iff_of_true (by decide) (Commute.one_left _) - | exact iff_of_true (by decide) (Commute.one_right _) - | exact iff_of_false (by decide) + | exact iff_of_true (Commute.refl _) (by decide) + | exact iff_of_true (Commute.one_left _) (by decide) + | exact iff_of_true (Commute.one_right _) (by decide) + | exact iff_of_false (not_commute_of_entry_ne (A := σ1) (B := σ3) (i := 0) (j := 1) - (by norm_num [pauliMatrix])) - | exact iff_of_false (by decide) + (by norm_num [pauliMatrix])) (by decide) + | exact iff_of_false (fun h => (not_commute_of_entry_ne (A := σ3) (B := σ1) (i := 0) (j := 1) - (by norm_num [pauliMatrix])) h) - | exact iff_of_false (by decide) + (by norm_num [pauliMatrix])) h) (by decide) + | exact iff_of_false (not_commute_of_entry_ne (A := σ1) (B := σ1 * σ3) (i := 0) (j := 0) - (by norm_num [pauliMatrix])) - | exact iff_of_false (by decide) + (by norm_num [pauliMatrix])) (by decide) + | exact iff_of_false (fun h => (not_commute_of_entry_ne (A := σ1 * σ3) (B := σ1) (i := 0) (j := 0) - (by norm_num [pauliMatrix])) h) - | exact iff_of_false (by decide) + (by norm_num [pauliMatrix])) h) (by decide) + | exact iff_of_false (not_commute_of_entry_ne (A := σ3) (B := σ1 * σ3) (i := 0) (j := 1) - (by norm_num [pauliMatrix])) - | exact iff_of_false (by decide) + (by norm_num [pauliMatrix])) (by decide) + | exact iff_of_false (fun h => (not_commute_of_entry_ne (A := σ1 * σ3) (B := σ3) (i := 0) (j := 1) - (by norm_num [pauliMatrix])) h) + (by norm_num [pauliMatrix])) h) (by decide) + /-- Phases do not affect commutation. -/ private lemma commute_single_iff (p q : ZMod 4) (x z x' z' : ZMod 2) : From 5daff03f8bf58563ded9b718b476353a87d42541 Mon Sep 17 00:00:00 2001 From: Samyak Date: Fri, 4 Dec 2026 07:04:06 +0530 Subject: [PATCH 8/9] [Feat]: N Qubit Pauli Group Foundation --- .../QuantumMechanics/Qubit/PauliGroups.lean | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/Physlib/QuantumMechanics/Qubit/PauliGroups.lean b/Physlib/QuantumMechanics/Qubit/PauliGroups.lean index 120acdcc28..749c411947 100644 --- a/Physlib/QuantumMechanics/Qubit/PauliGroups.lean +++ b/Physlib/QuantumMechanics/Qubit/PauliGroups.lean @@ -13,7 +13,7 @@ public import Physlib.Relativity.PauliMatrices.Basic # Pauli groups -The single-qubit Pauli group in its binary symplectic representation. +The single- and n-qubit Pauli groups in their binary symplectic representation. ## i. Overview @@ -27,6 +27,13 @@ Two single-qubit Pauli operators commute exactly when their symplectic product, depend on the phases, is zero. This is recorded by `PauliGroup.symplecticSingle` and proved in `PauliGroup.single_commute_iff`. +The n-qubit Pauli group consists of tensor products of single-qubit Pauli operators with a +global phase. An n-qubit operator is recorded by a phase `p : ZMod 4` and two bitstrings +`x z : Fin n → ZMod 2`. The pair `(x, z)` is a row of a Pauli tableau: `x k` records an `X` on +qubit `k`, `z k` records a `Z`, and both together give `Y` up to phase. The operator itself is +`PauliGroup.multi`, a matrix on the computational basis `Fin n → Fin 2`. The symplectic product +of two such rows is `PauliGroup.symplectic`. + ## ii. Key results - `PauliGroup.single` : the single-qubit Pauli operator `i^p X^x Z^z` for phase `p` and bits @@ -34,11 +41,14 @@ depend on the phases, is zero. This is recorded by `PauliGroup.symplecticSingle` - `PauliGroup.symplecticSingle` : the symplectic product of two single-qubit Pauli operators. - `PauliGroup.single_commute_iff` : two single-qubit Pauli operators commute if and only if their symplectic product is zero. +- `PauliGroup.multi` : the n-qubit Pauli operator `i^p ⊗ₖ (X^{xₖ} Z^{zₖ})`. +- `PauliGroup.symplectic` : the symplectic product of two n-qubit Pauli labels. ## iii. Table of contents - A. The single-qubit Pauli operators - B. The symplectic product +- C. The n-qubit Pauli operators ## iv. References @@ -133,4 +143,37 @@ lemma single_commute_iff (p q : ZMod 4) (x z x' z' : ZMod 2) : Commute (single p x z) (single q x' z') ↔ symplecticSingle x z x' z' = 0 := by rw [commute_single_iff, commute_pauli_iff] +/-! + +## C. The n-qubit Pauli operators + +The computational basis of `n` qubits is `Fin n → Fin 2`: an element is a bitstring of length +`n`, indexing the rows and columns of a `2^n × 2^n` matrix. This is not the Pauli label. + +A Pauli label, or a row of a Pauli tableau, is a pair of bitstrings `x z : Fin n → ZMod 2`. +On qubit `k`, `x k = 1` records an `X` factor and `z k = 1` records a `Z` factor; both together +give `Y` up to phase. A global phase `p : ZMod 4` contributes the factor `i^p`. + +-/ + +variable {n : ℕ} + +/-- The n-fold Kronecker product of a family of square matrices, indexed by bitstrings. +Entrywise, `(tensorAll A) i j = ∏ k, A k (i k) (j k)`. -/ +private def tensorAll (A : Fin n → Matrix (Fin 2) (Fin 2) ℂ) : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + fun i j => ∏ k, A k (i k) (j k) + +/-- The `n`-qubit Pauli operator `i^p ⊗ₖ (X^{xₖ} Z^{zₖ})`, acting on the computational basis +`Fin n → Fin 2`. The bitstrings `x` and `z` are the Pauli labels, i.e. the tableau row: +`x k = 1` puts an `X` on qubit `k`, `z k = 1` puts a `Z`, and both give `Y` up to phase. -/ +def multi (p : ZMod 4) (x z : Fin n → ZMod 2) : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + fun i j => Complex.I ^ p.val * ∏ k, (σ1 ^ (x k).val * σ3 ^ (z k).val) (i k) (j k) + +/-- The symplectic product of two `n`-qubit Pauli labels, the sum of the single-qubit +symplectic products. It does not depend on the phases. -/ +def symplectic (x z x' z' : Fin n → ZMod 2) : ZMod 2 := + ∑ k, symplecticSingle (x k) (z k) (x' k) (z' k) + end PauliGroup From 1e3b5a53fcd05be3cd2ae7b65ced09b7f998e3ea Mon Sep 17 00:00:00 2001 From: Samyak Date: Fri, 4 Dec 2026 07:29:27 +0530 Subject: [PATCH 9/9] Commutation relation for N Qubit Pauli Groups using Symplectic Prod Added an N qubit `tensorAll` and it's private along with a `pauliTensor` for easier notation of the same. Finally a main `multi_commute_iff` showing the final commutation relation using sympletic products defined in `symplectic`. --- .../QuantumMechanics/Qubit/PauliGroups.lean | 147 +++++++++++++++++- 1 file changed, 143 insertions(+), 4 deletions(-) diff --git a/Physlib/QuantumMechanics/Qubit/PauliGroups.lean b/Physlib/QuantumMechanics/Qubit/PauliGroups.lean index 749c411947..6b0d24a03d 100644 --- a/Physlib/QuantumMechanics/Qubit/PauliGroups.lean +++ b/Physlib/QuantumMechanics/Qubit/PauliGroups.lean @@ -32,7 +32,8 @@ global phase. An n-qubit operator is recorded by a phase `p : ZMod 4` and two bi `x z : Fin n → ZMod 2`. The pair `(x, z)` is a row of a Pauli tableau: `x k` records an `X` on qubit `k`, `z k` records a `Z`, and both together give `Y` up to phase. The operator itself is `PauliGroup.multi`, a matrix on the computational basis `Fin n → Fin 2`. The symplectic product -of two such rows is `PauliGroup.symplectic`. +of two such rows is `PauliGroup.symplectic`. Two n-qubit Pauli operators commute exactly when +their symplectic product is zero, which is `PauliGroup.multi_commute_iff`. ## ii. Key results @@ -43,6 +44,8 @@ of two such rows is `PauliGroup.symplectic`. their symplectic product is zero. - `PauliGroup.multi` : the n-qubit Pauli operator `i^p ⊗ₖ (X^{xₖ} Z^{zₖ})`. - `PauliGroup.symplectic` : the symplectic product of two n-qubit Pauli labels. +- `PauliGroup.multi_commute_iff` : two n-qubit Pauli operators commute if and only if their + symplectic product is zero. ## iii. Table of contents @@ -147,9 +150,6 @@ lemma single_commute_iff (p q : ZMod 4) (x z x' z' : ZMod 2) : ## C. The n-qubit Pauli operators -The computational basis of `n` qubits is `Fin n → Fin 2`: an element is a bitstring of length -`n`, indexing the rows and columns of a `2^n × 2^n` matrix. This is not the Pauli label. - A Pauli label, or a row of a Pauli tableau, is a pair of bitstrings `x z : Fin n → ZMod 2`. On qubit `k`, `x k = 1` records an `X` factor and `z k = 1` records a `Z` factor; both together give `Y` up to phase. A global phase `p : ZMod 4` contributes the factor `i^p`. @@ -176,4 +176,143 @@ symplectic products. It does not depend on the phases. -/ def symplectic (x z x' z' : Fin n → ZMod 2) : ZMod 2 := ∑ k, symplecticSingle (x k) (z k) (x' k) (z' k) +-- Private proof infrastructure for the commutation criterion. + +/-- Tensor products multiply factorwise: the product of two `tensorAll`s is the `tensorAll` +of the factorwise products. This is the `∏`/`∑` swap `Fintype.prod_sum`. -/ +private lemma tensorAll_mul (A B : Fin n → Matrix (Fin 2) (Fin 2) ℂ) : + tensorAll A * tensorAll B = tensorAll (fun k => A k * B k) := by + classical + ext i j + simp only [tensorAll, Matrix.mul_apply, ← Finset.prod_mul_distrib] + exact (Fintype.prod_sum (fun k (l : Fin 2) => A k (i k) l * B k l (j k))).symm + +/-- Scalars pull out of a `tensorAll` as a single product. -/ +private lemma tensorAll_smul (c : Fin n → ℂ) (A : Fin n → Matrix (Fin 2) (Fin 2) ℂ) : + tensorAll (fun k => c k • A k) = (∏ k, c k) • tensorAll A := by + ext i j + simp [tensorAll, Finset.prod_mul_distrib] + +/-- A `tensorAll` of nonzero matrices is nonzero: pick a nonzero entry in each factor. -/ +private lemma tensorAll_ne_zero (A : Fin n → Matrix (Fin 2) (Fin 2) ℂ) + (hA : ∀ k, A k ≠ 0) : tensorAll A ≠ 0 := by + classical + have h : ∀ k, ∃ i j, A k i j ≠ 0 := by + intro k + by_contra! hne + exact hA k (Matrix.ext fun i j => hne i j) + choose i j hij using h + intro h0 + have h1 : ∏ k, A k (i k) (j k) = 0 := congr_fun (congr_fun h0 i) j + obtain ⟨k, _, hk⟩ := Finset.prod_eq_zero_iff.mp h1 + exact hij k hk + +/-- The sign `(-1)^e` attached to a symplectic bit `e : ZMod 2`. -/ +private def phaseSign (e : ZMod 2) : ℂ := (-1) ^ e.val + +/-- `phaseSign` turns addition of bits into multiplication of signs. -/ +private lemma phaseSign_add (a b : ZMod 2) : phaseSign (a + b) = phaseSign a * phaseSign b := by + have hbits : ∀ a : ZMod 2, a = 0 ∨ a = 1 := by decide + have hval0 : (0 : ZMod 2).val = 0 := rfl + have hval1 : (1 : ZMod 2).val = 1 := rfl + have h11 : (1 : ZMod 2) + 1 = 0 := rfl + rcases hbits a with rfl | rfl <;> rcases hbits b with rfl | rfl <;> + simp only [phaseSign, hval0, hval1, h11, pow_zero, pow_one, zero_add, add_zero] <;> + norm_num + +/-- A product of signs is the sign of the sum. -/ +private lemma phaseSign_prod (s : Finset (Fin n)) (e : Fin n → ZMod 2) : + ∏ k ∈ s, phaseSign (e k) = phaseSign (∑ k ∈ s, e k) := by + classical + induction s using Finset.induction_on with + | empty => simp [phaseSign] + | insert a s ha ih => + simp only [Finset.prod_insert ha, Finset.sum_insert ha, ih, phaseSign_add] + +/-- The sign is `1` exactly when the bit is `0`. -/ +private lemma phaseSign_eq_one_iff (e : ZMod 2) : phaseSign e = 1 ↔ e = 0 := by + have hbits : ∀ a : ZMod 2, a = 0 ∨ a = 1 := by decide + have hval0 : (0 : ZMod 2).val = 0 := rfl + have hval1 : (1 : ZMod 2).val = 1 := rfl + rcases hbits e with rfl | rfl + · simp [phaseSign, hval0] + · simp [phaseSign, hval1]; norm_num + +/-- The phase-free `n`-qubit Pauli tensor `⊗ₖ (X^{xₖ} Z^{zₖ})`, with no global phase. -/ +private def pauliTensor (x z : Fin n → ZMod 2) : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + tensorAll (fun k => σ1 ^ (x k).val * σ3 ^ (z k).val) + +/-- `multi` is a global phase times the phase-free tensor. -/ +private lemma multi_eq_smul (p : ZMod 4) (x z : Fin n → ZMod 2) : + multi p x z = Complex.I ^ p.val • pauliTensor x z := by + ext i j + simp [multi, pauliTensor, tensorAll] + +/-- Swapping two single-qubit Pauli factors produces the sign `(-1)` raised to their +symplectic product. This is the only 16-case check. -/ +private lemma sigma_mul_sigma (x z x' z' : ZMod 2) : + (σ1 ^ x.val * σ3 ^ z.val) * (σ1 ^ x'.val * σ3 ^ z'.val) = + phaseSign (symplecticSingle x z x' z') • + ((σ1 ^ x'.val * σ3 ^ z'.val) * (σ1 ^ x.val * σ3 ^ z.val)) := by + have hbits : ∀ a : ZMod 2, a = 0 ∨ a = 1 := by decide + have hval0 : (0 : ZMod 2).val = 0 := rfl + have hval1 : (1 : ZMod 2).val = 1 := rfl + rcases hbits x with rfl | rfl <;> + rcases hbits z with rfl | rfl <;> + rcases hbits x' with rfl | rfl <;> + rcases hbits z' with rfl | rfl <;> + simp only [hval0, hval1, pow_zero, pow_one, one_mul, mul_one, symplecticSingle, + phaseSign] <;> + ext i j <;> fin_cases i <;> fin_cases j <;> + simp [pauliMatrix, hval0, hval1] + +/-- The tensor product picks up the product of the single-qubit signs, which is the sign of +the symplectic sum. -/ +private lemma pauliTensor_comm_sign (x z x' z' : Fin n → ZMod 2) : + pauliTensor x z * pauliTensor x' z' = + phaseSign (symplectic x z x' z') • (pauliTensor x' z' * pauliTensor x z) := by + simp only [pauliTensor] + rw [tensorAll_mul] + have hfun : (fun k => (σ1 ^ (x k).val * σ3 ^ (z k).val) * + (σ1 ^ (x' k).val * σ3 ^ (z' k).val)) = + fun k => phaseSign (symplecticSingle (x k) (z k) (x' k) (z' k)) • + ((σ1 ^ (x' k).val * σ3 ^ (z' k).val) * (σ1 ^ (x k).val * σ3 ^ (z k).val)) := + funext fun k => sigma_mul_sigma (x k) (z k) (x' k) (z' k) + rw [hfun, tensorAll_smul] + have hprod : (∏ k, phaseSign (symplecticSingle (x k) (z k) (x' k) (z' k))) = + phaseSign (symplectic x z x' z') := by + simpa [symplectic] using + phaseSign_prod Finset.univ (fun k => symplecticSingle (x k) (z k) (x' k) (z' k)) + rw [hprod, ← tensorAll_mul] + +/-- A single phase-free Pauli factor `X^x Z^z` is a unit. -/ +private lemma pauliFactor_isUnit (x z : ZMod 2) : IsUnit (σ1 ^ x.val * σ3 ^ z.val) := + (isUnit_of_invertible (σ1 ^ x.val)).mul (isUnit_of_invertible (σ3 ^ z.val)) + +/-- Two `n`-qubit Pauli operators commute if and only if their symplectic product is zero. -/ +lemma multi_commute_iff (p q : ZMod 4) (x z x' z' : Fin n → ZMod 2) : + Commute (multi p x z) (multi q x' z') ↔ symplectic x z x' z' = 0 := by + -- Global phases do not affect commutation. + rw [multi_eq_smul, multi_eq_smul, + Commute.smul_left_iff₀ (pow_ne_zero p.val Complex.I_ne_zero), + Commute.smul_right_iff₀ (pow_ne_zero q.val Complex.I_ne_zero), commute_iff_eq, + pauliTensor_comm_sign] + set M := pauliTensor x' z' * pauliTensor x z with hMdef + -- The phase-free product is nonzero: each factor is a unit. + have hne : M ≠ 0 := by + rw [hMdef] + simp only [pauliTensor] + rw [tensorAll_mul] + exact tensorAll_ne_zero _ (fun k => + ((pauliFactor_isUnit (x' k) (z' k)).mul (pauliFactor_isUnit (x k) (z k))).ne_zero) + -- A nonzero matrix is fixed by a scalar only when the scalar is `1`. + have hcancel : phaseSign (symplectic x z x' z') • M = M ↔ + phaseSign (symplectic x z x' z') = 1 := by + have h1 : phaseSign (symplectic x z x' z') • M - M = + (phaseSign (symplectic x z x' z') - 1) • M := by + rw [sub_smul, one_smul] + rw [← sub_eq_zero, h1, smul_eq_zero_iff_left hne, sub_eq_zero] + rw [hcancel, phaseSign_eq_one_iff] + end PauliGroup