Definitions for Programmable quantum gate arrays
DefinitionQAlgorithms_Papers_Independent_Extend50_P43The objects the formalized statements of Programmable quantum gate arrays (arXiv:quant-ph/9703032) are stated in. Each was checked against the paper by a blind read-back and a moderator.
ExactPhaseEquivalent: PDF p.2, Result: exact equality of operations modulo a global phase.ImplementsProgramUnitary: PDF p.1, Eqs.(1)–(3): one normalized program implements U exactly on all normalized data states. The residual program is initially allowed to vary with the data; its independence is a conclusion below.orderedBellKet: PDF p.2, Eqs.(12)–(13): ordered Bell kets on (A_i,B_i). Labels 0,1,2,3 mean Phi-plus, Phi-minus, Psi-plus, Psi-minus, respectively.bellProduct: PDF pp.2–3: the product Bell basis on all ordered pairs (A_i,B_i).successOutcome: PDF pp.2–3: the designated all-Phi-plus outcome. This flag is independent of the operation and the input state.program: PDF p.2, Eq.(11): the supplied 2m-qubit program on B,C is the constructed vector (I_B tensor U_C) Phi_m, using the frozen normalized EPR state.contractBellOutcome: PDF pp.2–3: the unnormalized C-register branch from measuring A,B in the product Bell basis. This is the Bell bra contraction, including its phase; it defines every outcome, including failures, without referring to U.bellOutcomeProbability: PDF pp.2–3: Born probability of a Bell outcome, computed from the branch.normalizedBellOutput: PDF p.3: normalized conditional C output. On a zero-probability branch this total function is zero; the success theorem proves strictly positive probability.BellCircuit: PDF pp.2–3, Fig.2: an instruction i is a two-qubit Bell measurement on the ordered pair (A_i,B_i), recording its four-valued outcome. A circuit is its actual instruction list; the C wires are the designated output. Each such primitive has a fixed constant-size elementary realization.fixedProcessor: PDF pp.2–3: the fixed processor measures each pair once, in wire order.bellProjectorAt: PDF p.2, Fig.2: the branch projector for one instruction, acting on A_i,B_i and as identity on the remaining wires, including C. This keeps the measured Bell state, so the full execution has the usual projective-measurement semantics.processorBranch: PDF pp.2–3: execute the instruction list on one recorded outcome path. The vector is subnormalized throughout; no free probability or cost field occurs.regroupABC: PDF p.3, systems A,B,C: regroup the frozen tensor coordinates to trace out A,B.processorOutputDensity: PDF p.3: the actual unnormalized output density on C of the listed processor. Its trace is the branch probability; the measured A,B registers are discarded.ClassicalGate: PDF pp.1,3: an arbitrary classical Boolean gate with a finite ordered input list and one output bit. Its function is unrestricted; this includes any maximum-fan-in-k gate set rather than only AND/OR/NOT.ClassicalArray: PDF pp.1,3: a classical programmable array with p program input bits, m data input bits, and m designated output wires. Gates are in topological order. Input wires are program first, then data; gate i creates wire p+m+i.ClassicalWellFormed: PDF pp.1,3: every gate reads an already defined wire and every output wire exists. This excludes the default getD value from all circuit evaluations.HasFanInAtMost: PDF p.3: maximum fan-in k bounds every actual gate occurrence.classicalEval: PDF pp.1,3: evaluate the fixed gates on program P and data d. Malformed wiring has a total default, excluded by ClassicalWellFormed.ClassicalUniversal: PDF pp.1,3: a classical universal array is one well-formed fixed circuit; only its program may depend on the selected function, and never on the data.
import Mathlib
import Definitions.Def_QAlgorithms_Defs_Basic
import Definitions.Def_QAlgorithms_Defs_Channel
/-!
Statements from Nielsen and Chuang, *Programmable quantum gate arrays*,
arXiv:quant-ph/9703032v1, PDF pp.1–3. All new objects are local to this paper.
Program preparation is a supplied resource. For the probabilistic processor,
register C is the output, as explicitly permitted on p.3.
-/
namespace QAlgorithms.Papers.Independent.Extend50.P43
open scoped ComplexConjugate
noncomputable section
/-- PDF p.2, Result: exact equality of operations modulo a global phase. -/
def ExactPhaseEquivalent {m : ℕ}
(U V : Matrix (Qubits m) (Qubits m) ℂ) : Prop :=
∃ z : ℂ, ‖z‖ = 1 ∧ U = z • V
/-- PDF p.1, Eqs.(1)–(3): one normalized program implements U exactly on
all normalized data states. The residual program is initially allowed to
vary with the data; its independence is a conclusion below. -/
def ImplementsProgramUnitary {m n : ℕ}
(G : Matrix (Qubits m × Qubits n) (Qubits m × Qubits n) ℂ)
(U : Matrix (Qubits m) (Qubits m) ℂ)
(P : EuclideanSpace ℂ (Qubits n)) : Prop :=
IsState P ∧ ∀ d : EuclideanSpace ℂ (Qubits m), IsState d →
∃ q : EuclideanSpace ℂ (Qubits n), IsState q ∧
act G (tensorVec d P) = tensorVec (act U d) q
/-- Sanity: the phase relation identifies each matrix with itself. -/
example {m : ℕ} (U : Matrix (Qubits m) (Qubits m) ℂ) :
ExactPhaseEquivalent U U := by
exact ⟨1, by simp, by simp⟩
/-- Sanity: an identity array implements the identity with any normalized program. -/
example {m n : ℕ} (P : EuclideanSpace ℂ (Qubits n)) (hP : IsState P) :
ImplementsProgramUnitary (1 : Matrix (Qubits m × Qubits n) (Qubits m × Qubits n) ℂ)
(1 : Matrix (Qubits m) (Qubits m) ℂ) P := by
refine ⟨hP, ?_⟩
intro d hd
exact ⟨P, hP, by simp [act]⟩
/-- PDF p.2, Eqs.(12)–(13): ordered Bell kets on (A_i,B_i).
Labels 0,1,2,3 mean Phi-plus, Phi-minus, Psi-plus, Psi-minus, respectively. -/
def orderedBellKet (r : Fin 4) : EuclideanSpace ℂ (Bool × Bool) :=
WithLp.toLp 2 fun p =>
let a : ℂ := ((Real.sqrt (2 : ℝ))⁻¹ : ℂ)
match r.val with
| 0 => if p.1 = p.2 then a else 0
| 1 => if p.1 = p.2 then (if p.1 then -a else a) else 0
| 2 => if p.1 ≠ p.2 then a else 0
| _ => if p.1 ≠ p.2 then (if p.1 then -a else a) else 0
/-- PDF pp.2–3: the product Bell basis on all ordered pairs (A_i,B_i). -/
def bellProduct {m : ℕ} (o : Fin m → Fin 4) :
EuclideanSpace ℂ (Qubits m × Qubits m) :=
WithLp.toLp 2 fun p => ∏ i, orderedBellKet (o i) (p.1 i, p.2 i)
/-- PDF pp.2–3: the designated all-Phi-plus outcome. This flag is independent
of the operation and the input state. -/
def successOutcome (m : ℕ) : Fin m → Fin 4 := fun _ => 0
/-- PDF p.2, Eq.(11): the supplied 2m-qubit program on B,C is the constructed
vector (I_B tensor U_C) Phi_m, using the frozen normalized EPR state. -/
def program {m : ℕ} (U : Matrix (Qubits m) (Qubits m) ℂ) :
EuclideanSpace ℂ (Qubits m × Qubits m) :=
act (Matrix.kronecker (1 : Matrix (Qubits m) (Qubits m) ℂ) U) (maxEntangled m)
/-- PDF pp.2–3: the unnormalized C-register branch from measuring A,B in
the product Bell basis. This is the Bell bra contraction, including its phase;
it defines every outcome, including failures, without referring to U. -/
def contractBellOutcome {m : ℕ} (o : Fin m → Fin 4)
(psi : EuclideanSpace ℂ (Qubits m × (Qubits m × Qubits m))) :
EuclideanSpace ℂ (Qubits m) :=
WithLp.toLp 2 fun c => ∑ a : Qubits m, ∑ b : Qubits m,
conj (bellProduct o (a, b)) * psi (a, (b, c))
/-- PDF pp.2–3: Born probability of a Bell outcome, computed from the branch. -/
def bellOutcomeProbability {m : ℕ} (o : Fin m → Fin 4)
(psi : EuclideanSpace ℂ (Qubits m × (Qubits m × Qubits m))) : ℝ :=
‖contractBellOutcome o psi‖ ^ 2
/-- PDF p.3: normalized conditional C output. On a zero-probability branch
this total function is zero; the success theorem proves strictly positive probability. -/
def normalizedBellOutput {m : ℕ} (o : Fin m → Fin 4)
(psi : EuclideanSpace ℂ (Qubits m × (Qubits m × Qubits m))) :
EuclideanSpace ℂ (Qubits m) :=
((Real.sqrt (bellOutcomeProbability o psi))⁻¹ : ℂ) • contractBellOutcome o psi
/-- Sanity: Phi-plus has the positive 00 amplitude; Psi-minus has negative 10 amplitude. -/
example : orderedBellKet 0 (false, false) = ((Real.sqrt (2 : ℝ))⁻¹ : ℂ) ∧
orderedBellKet 3 (true, false) = -((Real.sqrt (2 : ℝ))⁻¹ : ℂ) := by
simp [orderedBellKet]
/-- Sanity at the empty-register boundary: an empty Bell product has amplitude one. -/
example (o : Fin 0 → Fin 4) (a b : Qubits 0) : bellProduct o (a, b) = 1 := by
simp [bellProduct]
/-- Sanity: a zero input has zero branch amplitude and probability. -/
example {m : ℕ} (o : Fin m → Fin 4) :
contractBellOutcome o 0 = 0 ∧ bellOutcomeProbability o 0 = 0 := by
have h : contractBellOutcome o 0 = 0 := by
ext c
simp [contractBellOutcome]
exact ⟨h, by simp [bellOutcomeProbability, h]⟩
/-- PDF pp.2–3, Fig.2: an instruction i is a two-qubit Bell measurement
on the ordered pair (A_i,B_i), recording its four-valued outcome.
A circuit is its actual instruction list; the C wires are the designated output.
Each such primitive has a fixed constant-size elementary realization. -/
abbrev BellCircuit (m : ℕ) := List (Fin m)
/-- PDF pp.2–3: the fixed processor measures each pair once, in wire order. -/
def fixedProcessor (m : ℕ) : BellCircuit m := List.ofFn (fun i : Fin m => i)
/-- PDF p.2, Fig.2: the branch projector for one instruction, acting on A_i,B_i
and as identity on the remaining wires, including C. This keeps the measured
Bell state, so the full execution has the usual projective-measurement semantics. -/
def bellProjectorAt {m : ℕ} (i : Fin m) (r : Fin 4) :
Matrix (Qubits m × (Qubits m × Qubits m))
(Qubits m × (Qubits m × Qubits m)) ℂ :=
open Classical in
fun y z =>
if y.2.2 = z.2.2 ∧
(∀ j : Fin m, j ≠ i → y.1 j = z.1 j ∧ y.2.1 j = z.2.1 j) then
orderedBellKet r (y.1 i, y.2.1 i) * conj (orderedBellKet r (z.1 i, z.2.1 i))
else 0
/-- PDF pp.2–3: execute the instruction list on one recorded outcome path.
The vector is subnormalized throughout; no free probability or cost field occurs. -/
def processorBranch {m : ℕ} (circuit : BellCircuit m) (o : Fin m → Fin 4)
(psi : EuclideanSpace ℂ (Qubits m × (Qubits m × Qubits m))) :
EuclideanSpace ℂ (Qubits m × (Qubits m × Qubits m)) :=
circuit.foldl (fun v i => act (bellProjectorAt i (o i)) v) psi
/-- PDF p.3, systems A,B,C: regroup the frozen tensor coordinates to trace out A,B. -/
def regroupABC {m : ℕ}
(psi : EuclideanSpace ℂ (Qubits m × (Qubits m × Qubits m))) :
EuclideanSpace ℂ ((Qubits m × Qubits m) × Qubits m) :=
WithLp.toLp 2 fun p => psi (p.1.1, (p.1.2, p.2))
/-- PDF p.3: the actual unnormalized output density on C of the listed processor.
Its trace is the branch probability; the measured A,B registers are discarded. -/
def processorOutputDensity {m : ℕ} (circuit : BellCircuit m) (o : Fin m → Fin 4)
(psi : EuclideanSpace ℂ (Qubits m × (Qubits m × Qubits m))) :
Matrix (Qubits m) (Qubits m) ℂ :=
traceLeft (pureDensity (regroupABC (processorBranch circuit o psi)))
/-- Sanity: no instructions leave the complete state unchanged. -/
example {m : ℕ} (o : Fin m → Fin 4)
(psi : EuclideanSpace ℂ (Qubits m × (Qubits m × Qubits m))) :
processorBranch [] o psi = psi := rfl
/-- Sanity: regrouping does not change any amplitude. -/
example {m : ℕ}
(psi : EuclideanSpace ℂ (Qubits m × (Qubits m × Qubits m)))
(a b c : Qubits m) : regroupABC psi ((a, b), c) = psi (a, (b, c)) := rfl
/-- Sanity at m=0: the fixed processor has an empty instruction list. -/
example : fixedProcessor 0 = [] := by simp [fixedProcessor]
/-- PDF pp.1,3: an arbitrary classical Boolean gate with a finite ordered
input list and one output bit. Its function is unrestricted; this includes
any maximum-fan-in-k gate set rather than only AND/OR/NOT. -/
structure ClassicalGate where
arity : ℕ
inputs : Fin arity → ℕ
table : (Fin arity → Bool) → Bool
/-- PDF pp.1,3: a classical programmable array with p program input bits,
m data input bits, and m designated output wires. Gates are in topological
order. Input wires are program first, then data; gate i creates wire p+m+i. -/
structure ClassicalArray (m p : ℕ) where
gates : List ClassicalGate
outputs : Fin m → ℕ
/-- PDF pp.1,3: every gate reads an already defined wire and every output
wire exists. This excludes the default getD value from all circuit evaluations. -/
def ClassicalWellFormed {m p : ℕ} (circuit : ClassicalArray m p) : Prop :=
(∀ i : Fin circuit.gates.length, ∀ j : Fin (circuit.gates.get i).arity,
(circuit.gates.get i).inputs j < p + m + i.val) ∧
∀ j : Fin m, circuit.outputs j < p + m + circuit.gates.length
/-- PDF p.3: maximum fan-in k bounds every actual gate occurrence. -/
def HasFanInAtMost {m p : ℕ} (circuit : ClassicalArray m p) (k : ℕ) : Prop :=
∀ g ∈ circuit.gates, g.arity ≤ k
/-- PDF pp.1,3: evaluate the fixed gates on program P and data d.
Malformed wiring has a total default, excluded by ClassicalWellFormed. -/
def classicalEval {m p : ℕ} (circuit : ClassicalArray m p)
(P : Qubits p) (d : Qubits m) : Qubits m :=
let vals := circuit.gates.foldl
(fun vals g => vals ++ [g.table (fun j => vals.getD (g.inputs j) false)])
(List.ofFn (Fin.append P d))
fun j => vals.getD (circuit.outputs j) false
/-- PDF pp.1,3: a classical universal array is one well-formed fixed circuit;
only its program may depend on the selected function, and never on the data. -/
def ClassicalUniversal {m p : ℕ} (circuit : ClassicalArray m p) : Prop :=
ClassicalWellFormed circuit ∧
∀ f : Qubits m → Qubits m, ∃ P : Qubits p,
∀ d : Qubits m, classicalEval circuit P d = f d
/-- Sanity: a zero-gate array may output a program wire directly. Such
arrays are allowed in the model; universality, rather than an extra wiring
hypothesis, rules them out in the lower bound for nontrivial data. -/
example : classicalEval (⟨[], fun _ => 0⟩ : ClassicalArray 1 1)
![true] ![false] 0 = true := rfl
/-- Sanity: an arity-zero gate is a constant source, even with no available wires. -/
example : (ClassicalGate.mk 0 (fun i => Fin.elim0 i) (fun _ => true)).table
(fun i => Fin.elim0 i) = true := rfl
end
end QAlgorithms.Papers.Independent.Extend50.P43
Read-back
What the Lean code literally says, in plain math · gpt-6.1-sol
QAlgorithms.Papers.Independent.Extend50.P43.BellCircuit
For every natural number , a Bell circuit on positions is simply a finite list whose entries belong to . There are no restrictions on the list’s length, ordering, repeated entries, or omitted positions. When , the only such list is the empty list.
QAlgorithms.Papers.Independent.Extend50.P43.ClassicalArray
For every pair of natural numbers , a classical array consists of a finite list of classical gates and a function assigning a natural-number output index to each of the output positions. Each gate has a natural-number arity , an input-index function , and a truth table . The structure imposes no bounds on gate input indices or output indices and no restrictions on the gates; imposes no additional condition here. The gate list may be empty, and and may be zero.
QAlgorithms.Papers.Independent.Extend50.P43.ClassicalGate
A classical gate consists of a natural number , its arity; a function assigning to each position in a natural-number input index; and an arbitrary function , its truth table. The arity may be zero, in which case the truth table specifies a constant bit. Input indices may repeat and have no upper bound imposed by this structure.
QAlgorithms.Papers.Independent.Extend50.P43.ClassicalUniversal
For all natural numbers and every classical array with program bits and data and output bits, this property means that is well formed and can represent every function from -bit strings to -bit strings by choosing its program bits. Explicitly, write its ordered gate list as , where each gate has a natural-number arity, that many natural-number input indices, and an arbitrary Boolean table. Well-formedness requires every input index of gate to be strictly less than , and every output index to be strictly less than . The representation requirement is that for every function , there exists a program such that for every data string , evaluation of on equals . Evaluation starts with the program bits followed by the data bits, processes the gates in order by appending each table’s value on its indexed inputs, and reads the designated output indices; any read outside the current list returns . The program may depend on but must work for every , and need not be unique. Both and are included; for , the output-index requirements are vacuous and the representation requirement concerns the unique function on the singleton set of empty bit strings.
QAlgorithms.Papers.Independent.Extend50.P43.ClassicalWellFormed
For all natural numbers and every classical array consisting of a gate list and output indices for , this predicate means that every input index of gate is strictly less than , and every output index is strictly less than . Here each gate has a natural-number arity , an input-index function on , and an arbitrary Boolean truth table of that arity. Equivalently, each gate input refers to one of the initial positions or to a preceding gate’s position, and each output refers to an initial or gate position. A gate of arity zero has no input inequalities to satisfy, an empty gate list has no gate inequalities to satisfy, and makes the output condition vacuous.
QAlgorithms.Papers.Independent.Extend50.P43.ExactPhaseEquivalent
For any natural number , including , and any two complex matrices indexed by the -bit strings , exact phase equivalence means that there exists a complex number with such that , with scalar multiplication applied to every matrix entry. Neither matrix is required to be unitary. Zero matrices are permitted; if either matrix is zero, the condition holds exactly when both are zero. When , these are matrices.
QAlgorithms.Papers.Independent.Extend50.P43.HasFanInAtMost
For all natural numbers and every classical array consisting of a finite gate list and natural-number output indices, this predicate means that every gate in the list has arity at most . Each gate consists of its natural-number arity , an input-index function , and a Boolean truth table on bits. The predicate imposes no conditions on those indices, truth tables, or output indices. It holds vacuously for an empty gate list; when , every listed gate must have arity zero.
QAlgorithms.Papers.Independent.Extend50.P43.ImplementsProgramUnitary
For any natural numbers , any complex matrix indexed by pairs of an -bit string and an -bit string, any complex matrix indexed by -bit strings, and any vector , this condition means that and that, for every with , there exists with satisfying
Here matrix action is ordinary matrix-vector multiplication, and . The vector may depend on . No unitarity assumption on or is included in this definition. Both and are allowed, with the corresponding vector space one-dimensional.
QAlgorithms.Papers.Independent.Extend50.P43.bellOutcomeProbability
For every natural number , every assignment , and every vector , write with , and let denote coordinatewise addition modulo . This defines the real number
the squared Euclidean norm of the vector obtained by contracting the first two registers against the selected Bell amplitudes. No normalization assumption on is included, so the definition does not require this number to be at most . When , it is the squared absolute value of the sole coordinate of .
QAlgorithms.Papers.Independent.Extend50.P43.bellProduct
For every natural number and every assignment , write with . This defines the vector whose coordinate at a pair of bit strings is
where is addition modulo . Thus the coordinate is the product of the individual two-bit amplitudes selected by . When , there is one pair of empty strings, and its amplitude is the empty product .
QAlgorithms.Papers.Independent.Extend50.P43.bellProjectorAt
For every natural number , every position , and every , this defines a complex matrix indexed by triples of -bit strings, parenthesized as , where . Identifying bits with and , set
where is addition modulo . For row and column , the matrix entry is
Here denotes an indicator and the bar denotes complex conjugation. When , there is no position to supply.
QAlgorithms.Papers.Independent.Extend50.P43.classicalEval
For all natural numbers , a classical array consists of a finite ordered list of gates and natural-number output indices; each gate has a natural-number arity , input indices , and a Boolean table . Given a program bit string of length and a data bit string of length , the function returns a bit string of length as follows: start with the list of the bits of , followed by the bits of ; then process the gates in list order, appending for each gate the bit , where is the current list and any read outside that list returns . Output bit is the entry at ’s th output index in the final list, again returning if that index is outside the list. All list indices start at zero. No well-formedness condition is imposed here. Zero-arity gates are allowed, and or is included; when , the returned bit string is empty.
QAlgorithms.Papers.Independent.Extend50.P43.contractBellOutcome
For every natural number , every assignment , and every vector , write with . This defines a vector by
where is addition modulo . This is the sum over the first two registers against the complex conjugate of their product of selected Bell amplitudes. No normalization assumption on is imposed. When , the sole output coordinate is the sole coordinate of .
QAlgorithms.Papers.Independent.Extend50.P43.fixedProcessor
For every natural number , the fixed processor is the list
of all positions in increasing order, each appearing once. For , this is the empty list.
QAlgorithms.Papers.Independent.Extend50.P43.normalizedBellOutput
For every natural number , every assignment , and every vector , write with , let denote coordinatewise addition modulo , and define
The defined output vector has coordinate , where the scalar is specifically the reciprocal of the real square root of , embedded in . No normalization assumption on or positivity assumption on is imposed. If , the reciprocal is defined to be , and the output is the zero vector; if , the output has Euclidean norm . When , the same rule applies to the single coordinate of .
QAlgorithms.Papers.Independent.Extend50.P43.orderedBellKet
For every index , this defines a vector in , identifying false with and true with , by
where is the coordinate vector equal to at and elsewhere. The final branch of the definition applies only to , since the index is restricted to these four values.
QAlgorithms.Papers.Independent.Extend50.P43.processorBranch
For every natural number , every finite list of positions with , every assignment , and every complex vector indexed by , where , this defines a vector by the following successive matrix actions. For bits , let
with denoting addition modulo and an indicator. Start with , and, for , set
Here means replacement of bit by . The defined output is . The input vector need not be normalized, the list may repeat positions, and an empty list returns ; in particular, for the list is necessarily empty.
QAlgorithms.Papers.Independent.Extend50.P43.processorOutputDensity
For every natural number , every finite list of positions in , every assignment , and every complex vector indexed by , where , this defines a complex matrix indexed by as follows. For bits , write
where is addition modulo and an indicator. Starting with , successively define
where brackets denote replacement of a bit. The output matrix has entries
There is no normalization of or of the resulting matrix. Empty lists return this formula with , and is included.
QAlgorithms.Papers.Independent.Extend50.P43.program
For every natural number and every complex matrix indexed by -bit strings, this defines the vector obtained by applying to the vector whose coordinate at is when and otherwise. Explicitly, the resulting vector in has coordinates
There is no assumption that is unitary or that this vector has norm . When , its sole coordinate is the sole entry of .
QAlgorithms.Papers.Independent.Extend50.P43.regroupABC
For every natural number and every complex Euclidean vector indexed by , where , this defines the vector indexed by whose coordinate at is
Thus the coordinate values are preserved while the three registers are parenthesized differently. No normalization hypothesis is imposed, and the definition includes , when consists of the single empty bit string.
QAlgorithms.Papers.Independent.Extend50.P43.successOutcome
For every natural number , this defines the function from the positions to that assigns the value to every position. When , it is the unique function with empty domain.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.