Documentation

CslibFrontier.Computability.Circuit.Quantum.Oracle.Controller.Handler

A stateful quantum handler for native controllers #

The handler uses the existing joint density matrix of a fixed active register and an untouched reference, together with the classical service state. The native word program is unchanged: ProbOracleComp.runWith interprets its requests through DeviceRequest.codec. One fixed H is passed to the complete run. Sampling H belongs outside that run, so adaptive stages share it.

Gates and coherent queries use the existing OracleGateCode decoder. A malformed instruction is a no-op. A measurement uses classicalDensityBranch and PMF.bindOnSupport; only supported branches are normalized. It measures one wire while retaining the complete joint state. Classical service replies have an explicit fixed bit width. Their implementation cost remains outside the native controller's cost, as with other external oracle services.

These are original interface and composition results. The quantum operations reuse the unitary and projective-measurement semantics of de Wolf, §15.1, p. 128. No density matrix is encoded as a classical machine word, and no efficient classical simulation is claimed.

Main definitions #

structure Cslib.Quantum.DeviceState (m : ℕ) (κ State : Type) [Fintype κ] :

The semantic state of the device: the existing joint density matrix and classical service state. The reference register is never addressed by a controller request.

  • density : Matrix ((Fin m → Bool) × κ) ((Fin m → Bool) × κ) ℂ

    Joint active/reference density matrix.

  • isDensityMatrix : IsDensityMatrix self.density

    Positivity and unit trace of that matrix.

  • serviceState : State

    State used only by the external classical service.

theorem Cslib.Quantum.DeviceState.ext {m : ℕ} {κ State : Type} [Fintype κ] {s t : DeviceState m κ State} (hρ : s.density = t.density) (hs : s.serviceState = t.serviceState) :
s = t
theorem Cslib.Quantum.DeviceState.ext_iff {m : ℕ} {κ State : Type} [Fintype κ] {s t : DeviceState m κ State} :
noncomputable def Cslib.Quantum.DeviceState.evolve {m : ℕ} {κ State : Type} [Fintype κ] [DecidableEq κ] (U : ↥(Matrix.unitaryGroup (Fin m → Bool) ℂ)) (s : DeviceState m κ State) :
DeviceState m κ State

Apply an existing unitary to the active register, retaining every reference correlation.

theorem Cslib.Quantum.DeviceState.evolve_density {m : ℕ} {κ State : Type} [Fintype κ] [DecidableEq κ] (U : ↥(Matrix.unitaryGroup (Fin m → Bool) ℂ)) (s : DeviceState m κ State) :
(evolve U s).density = (densityConj (Matrix.kroneckerMap (fun (x1 x2 : ℂ) => x1 * x2) (↑U) 1)) s.density

The state update is exactly the existing matrix conjugation by U ⊗ I.

@[simp]
theorem Cslib.Quantum.DeviceState.evolve_serviceState {m : ℕ} {κ State : Type} [Fintype κ] [DecidableEq κ] (U : ↥(Matrix.unitaryGroup (Fin m → Bool) ℂ)) (s : DeviceState m κ State) :

Every active-register unitary preserves the reference marginal, including entangled inputs.

noncomputable def Cslib.Quantum.DeviceState.instruction {m : ℕ} {κ State : Type} [Fintype κ] [DecidableEq κ] {a b : ℕ} (H : (Fin a → Bool) → Fin b → Bool) (code : OracleGateCode) (s : DeviceState m κ State) :
DeviceState m κ State

Execute one existing instruction. Malformed placements or an oversized query are skipped, exactly as in OracleCircuit.toCircuit.

theorem Cslib.Quantum.DeviceState.instruction_apply {m : ℕ} {κ State : Type} [Fintype κ] [DecidableEq κ] {a b : ℕ} (H : (Fin a → Bool) → Fin b → Bool) (code : OracleGateCode) (s : DeviceState m κ State) :
instruction H code s = match OracleGateCode.toPlacedGate? m H code with | some gate => evolve gate.matrix s | none => s

Instruction execution uses precisely the existing placed-gate decoder.

theorem Cslib.Quantum.DeviceState.instruction_of_invalid {m : ℕ} {κ State : Type} [Fintype κ] [DecidableEq κ] {a b : ℕ} (H : (Fin a → Bool) → Fin b → Bool) (code : OracleGateCode) (h : OracleGateCode.toPlacedGate? m H code = none) (s : DeviceState m κ State) :
instruction H code s = s

The existing decoder's rejection leaves the complete state unchanged.

noncomputable def Cslib.Quantum.DeviceState.measure {m : ℕ} {κ State : Type} [Fintype κ] [DecidableEq κ] {Outcome : Type} [DecidableEq Outcome] (read : (Fin m → Bool) → Outcome) (s : DeviceState m κ State) :
PMF (Outcome × DeviceState m κ State)

Read a finite classical function of the active basis index, retaining the supported normalized joint state. The native handler specializes this operation to reading one wire.

theorem Cslib.Quantum.DeviceState.measure_bind {m : ℕ} {κ State : Type} [Fintype κ] [DecidableEq κ] {Outcome : Type} [DecidableEq Outcome] {α : Type} (read : (Fin m → Bool) → Outcome) (s : DeviceState m κ State) (next : Outcome → DeviceState m κ State → PMF α) :
((measure read s).bind fun (p : Outcome × DeviceState m κ State) => next p.1 p.2) = (PMF.map (read ∘ Prod.fst) (POVM.basis.measureDensity s.density ⋯)).bindOnSupport fun (y : Outcome) (hy : y ∈ (PMF.map (read ∘ Prod.fst) (POVM.basis.measureDensity s.density ⋯)).support) => next y { density := normalizeDensity ((classicalDensityBranch (read ∘ Prod.fst) y) s.density), isDensityMatrix := ⋯, serviceState := s.serviceState }

Continue directly from the supported conditional states of a classical readout.

theorem Cslib.Quantum.DeviceState.measure_map_fst {m : ℕ} {κ State : Type} [Fintype κ] [DecidableEq κ] {Outcome : Type} [DecidableEq Outcome] (read : (Fin m → Bool) → Outcome) (s : DeviceState m κ State) :

Forgetting the conditional state gives exactly the existing mapped basis measurement.

theorem Cslib.Quantum.DeviceState.measure_eq_pure_of_branch {m : ℕ} {κ State : Type} [Fintype κ] [DecidableEq κ] {Outcome : Type} [DecidableEq Outcome] (read : (Fin m → Bool) → Outcome) (s : DeviceState m κ State) (y : Outcome) (hy : (classicalDensityBranch (read ∘ Prod.fst) y) s.density = s.density) :
measure read s = PMF.pure (y, s)

A readout whose selected branch already contains the whole state is deterministic and preserves that state, including its reference correlations.

noncomputable def Cslib.Quantum.deviceHandler {a b m r : ℕ} {κ State Operation : Type} [Fintype κ] [DecidableEq κ] (H : (Fin a → Bool) → Fin b → Bool) (service : Operation × List Bool → StateT State PMF (Fin r → Bool)) :
DeviceRequest m Operation → StateT (DeviceState m κ State) PMF (List Bool)

Typed device operations. The service returns exactly r bits and never accesses the joint quantum state. All coherent calls use the same supplied function H.

theorem Cslib.Quantum.deviceHandler_gate {a b m r : ℕ} {κ State Operation : Type} [Fintype κ] [DecidableEq κ] (H : (Fin a → Bool) → Fin b → Bool) (service : Operation × List Bool → StateT State PMF (Fin r → Bool)) (code : PhaseGateCode) (s : DeviceState m κ State) :

An elementary gate returns the empty acknowledgement.

theorem Cslib.Quantum.deviceHandler_query {a b m r : ℕ} {κ State Operation : Type} [Fintype κ] [DecidableEq κ] (H : (Fin a → Bool) → Fin b → Bool) (service : Operation × List Bool → StateT State PMF (Fin r → Bool)) (s : DeviceState m κ State) :

A coherent query returns the empty acknowledgement.

theorem Cslib.Quantum.deviceHandler_measure {a b m r : ℕ} {κ State Operation : Type} [Fintype κ] [DecidableEq κ] (H : (Fin a → Bool) → Fin b → Bool) (service : Operation × List Bool → StateT State PMF (Fin r → Bool)) (wire : Fin m) (s : DeviceState m κ State) :
deviceHandler H service (DeviceRequest.measure wire) s = PMF.map (fun (p : Bool × DeviceState m κ State) => ([p.1], p.2)) (DeviceState.measure (fun (x : Fin m → Bool) => x wire) s)

A wire measurement reports its single outcome bit.

theorem Cslib.Quantum.deviceHandler_service {a b m r : ℕ} {κ State Operation : Type} [Fintype κ] [DecidableEq κ] (H : (Fin a → Bool) → Fin b → Bool) (service : Operation × List Bool → StateT State PMF (Fin r → Bool)) (operation : Operation) (word : List Bool) (s : DeviceState m κ State) :
deviceHandler H service (DeviceRequest.service operation word) s = PMF.map (fun (p : (Fin r → Bool) × State) => (List.ofFn p.1, { density := s.density, isDensityMatrix := ⋯, serviceState := p.2 })) (service (operation, word) s.serviceState)

The classical service changes only its own state and reports exactly its fixed-width reply.

theorem Cslib.Quantum.deviceHandler_reply_length {a b m r : ℕ} {κ State Operation : Type} [Fintype κ] [DecidableEq κ] (H : (Fin a → Bool) → Fin b → Bool) (service : Operation × List Bool → StateT State PMF (Fin r → Bool)) (q : DeviceRequest m Operation) (s : DeviceState m κ State) (result : List Bool × DeviceState m κ State) (hresult : result ∈ (deviceHandler H service q s).support) :
result.1.length ≤ max 1 r

Every reply has an explicit size bound: quantum acknowledgements are empty, measurements return one bit, and classical services return their declared r bits.

noncomputable def Cslib.Quantum.deviceWordHandler {a b m r : ℕ} {κ State Operation : Type} [Fintype κ] [DecidableEq κ] (H : (Fin a → Bool) → Fin b → Bool) (service : Operation × List Bool → StateT State PMF (Fin r → Bool)) :
(DeviceOperation ⊕ Operation) × List Bool → StateT (DeviceState m κ State) PMF (List Bool)

The word interface uses OracleCodec.wordOracle; noncanonical words return [] without an operation or state change.

theorem Cslib.Quantum.deviceWordHandler_eq {a b m r : ℕ} {κ State Operation : Type} [Fintype κ] [DecidableEq κ] (H : (Fin a → Bool) → Fin b → Bool) (service : Operation × List Bool → StateT State PMF (Fin r → Bool)) :
deviceWordHandler H service = (DeviceRequest.codec m Operation).wordOracle (deviceHandler H service)

The word handler is the existing codec adaptation of the typed handler.

theorem Cslib.Quantum.deviceWordHandler_encode {a b m r : ℕ} {κ State Operation : Type} [Fintype κ] [DecidableEq κ] (H : (Fin a → Bool) → Fin b → Bool) (service : Operation × List Bool → StateT State PMF (Fin r → Bool)) (q : DeviceRequest m Operation) :
deviceWordHandler H service q.encode = deviceHandler H service q

A canonically encoded request executes its typed operation, with the same complete state.

theorem Cslib.Quantum.deviceWordHandler_of_invalid {a b m r : ℕ} {κ State Operation : Type} [Fintype κ] [DecidableEq κ] (H : (Fin a → Bool) → Fin b → Bool) (service : Operation × List Bool → StateT State PMF (Fin r → Bool)) (request : (DeviceOperation ⊕ Operation) × List Bool) (h : (DeviceRequest.codec m Operation).decodeQuery request = none) (s : DeviceState m κ State) :
deviceWordHandler H service request s = PMF.pure ([], s)

Rejected word requests have the explicit answer [] and preserve the full device state.