QuantumComputinglib learn · inspect · formalize
Checked on this commit 4,524 public declarations commit c681192368c2 Build record

Lean source module

QuantumBlockEncoding/PrimitiveCircuit.lean

39 explicit public declarations in source order.

Back to Library Explorer

inductive · line 17

QuantumBlockEncoding.ExactAngle

Compiled Compiled

This type lists the allowed alternatives for “exact angle”; its constructors are the cases that downstream code must handle.

inductive ExactAngle where
  | rational (value : Rat)
  | piRational (value : Rat)
  | twiceArccosRational (value : Rat)
      (bounded : |(value : Real)| ≤ 1)
  | twiceArccosSqrtRational (value : Rat)
      (bounded : 0 ≤ (value : Real) ∧ (value : Real) ≤ 1)
  /-- An exact real angle in the mathematical circuit. This constructor does
  not promise a computable decimal export; exporters must supply and audit
  their own numerical evaluation of the defining real expression. -/
  | real (value : Real)

commit-pinned source · Verso Blueprint panel

def · line 46

QuantumBlockEncoding.ExactAngle.eval

Compiled Compiled

This definition gives the library's named construction or computation for “eval”.

noncomputable def eval : ExactAngle → Real
  | .rational value => (value : Real)
  | .piRational value => Real.pi * (value : Real)
  | .twiceArccosRational value _ => 2 * Real.arccos (value : Real)
  | .twiceArccosSqrtRational value _ =>
      2 * Real.arccos (Real.sqrt (value : Real))
  | .real value => value
  | .add left right => left.eval + right.eval
  | .neg value => -value.eval
  | .scale factor value => (factor : Real) * value.eval

commit-pinned source · Verso Blueprint panel

theorem · line 57

QuantumBlockEncoding.ExactAngle.eval_add

Compiled Compiled

Lean checks the proposition indexed as “eval add”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem eval_add (left right : ExactAngle) :
    (add left right).eval = left.eval + right.eval := rfl

commit-pinned source · Verso Blueprint panel

theorem · line 60

QuantumBlockEncoding.ExactAngle.eval_neg

Compiled Compiled

Lean checks the proposition indexed as “eval neg”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem eval_neg (value : ExactAngle) :
    (neg value).eval = -value.eval := rfl

commit-pinned source · Verso Blueprint panel

theorem · line 63

QuantumBlockEncoding.ExactAngle.eval_scale

Compiled Compiled

Lean checks the proposition indexed as “eval scale”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem eval_scale (factor : Rat) (value : ExactAngle) :
    (scale factor value).eval = (factor : Real) * value.eval := rfl

commit-pinned source · Verso Blueprint panel

def · line 66

QuantumBlockEncoding.ExactAngle.sub

Compiled Compiled

This definition gives the library's named construction or computation for “sub”.

def sub (left right : ExactAngle) : ExactAngle :=
  add left (neg right)

commit-pinned source · Verso Blueprint panel

def · line 69

QuantumBlockEncoding.ExactAngle.halfAdd

Compiled Compiled

This definition gives the library's named construction or computation for “half add”.

def halfAdd (left right : ExactAngle) : ExactAngle :=
  scale (1 / 2) (add left right)

commit-pinned source · Verso Blueprint panel

def · line 72

QuantumBlockEncoding.ExactAngle.halfSub

Compiled Compiled

This definition gives the library's named construction or computation for “half sub”.

def halfSub (left right : ExactAngle) : ExactAngle :=
  scale (1 / 2) (sub left right)

commit-pinned source · Verso Blueprint panel

theorem · line 75

QuantumBlockEncoding.ExactAngle.eval_sub

Compiled Compiled

Lean checks the proposition indexed as “eval sub”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem eval_sub (left right : ExactAngle) :
    (sub left right).eval = left.eval - right.eval := by

commit-pinned source · Verso Blueprint panel

theorem · line 79

QuantumBlockEncoding.ExactAngle.eval_half_add

Compiled Compiled

Lean checks the proposition indexed as “eval half add”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem eval_half_add (left right : ExactAngle) :
    (halfAdd left right).eval = (left.eval + right.eval) / 2 := by

commit-pinned source · Verso Blueprint panel

theorem · line 86

QuantumBlockEncoding.ExactAngle.eval_half_sub

Compiled Compiled

Lean checks the proposition indexed as “eval half sub”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem eval_half_sub (left right : ExactAngle) :
    (halfSub left right).eval = (left.eval - right.eval) / 2 := by

commit-pinned source · Verso Blueprint panel

inductive · line 95

QuantumBlockEncoding.PrimitiveGate

Compiled Compiled

This type lists the allowed alternatives for “primitive gate”; its constructors are the cases that downstream code must handle.

inductive PrimitiveGate (qubits : Nat) where
  | x (target : Fin qubits)
  | ry (target : Fin qubits) (angle : ExactAngle)
  | rz (target : Fin qubits) (angle : ExactAngle)
  | cx (control target : Fin qubits) (distinct : control ≠ target)

commit-pinned source · Verso Blueprint panel

abbrev · line 101

QuantumBlockEncoding.PrimitiveCircuit

Compiled Compiled

This abbreviation gives a shorter name to the type or expression used for “primitive circuit”.

abbrev PrimitiveCircuit (qubits : Nat) := List (PrimitiveGate qubits)

/-- A primitive circuit together with an exact global phase. -/

commit-pinned source · Verso Blueprint panel

structure · line 104

QuantumBlockEncoding.PrimitiveProgram

Compiled Partial route

This record groups the data and proof fields needed for “primitive program”. A proposition-valued field is a requirement until a constructor supplies it. A primitive circuit together with an exact global phase.

structure PrimitiveProgram (qubits : Nat) where
  circuit : PrimitiveCircuit qubits
  globalPhase : ExactAngle

commit-pinned source · Verso Blueprint panel

def · line 110

QuantumBlockEncoding.PrimitiveGate.dagger

Compiled Compiled

This definition gives the library's named construction or computation for “dagger”.

def dagger {qubits : Nat} : PrimitiveGate qubits → PrimitiveGate qubits
  | .x target => .x target
  | .ry target angle => .ry target (.neg angle)
  | .rz target angle => .rz target (.neg angle)
  | .cx control target distinct => .cx control target distinct

commit-pinned source · Verso Blueprint panel

def · line 116

QuantumBlockEncoding.PrimitiveGate.touched

Compiled Compiled

This definition gives the library's named construction or computation for “touched”.

def touched {qubits : Nat} : PrimitiveGate qubits → Finset (Fin qubits)
  | .x target | .ry target _ | .rz target _ => {target}
  | .cx control target _ => {control, target}

commit-pinned source · Verso Blueprint panel

def · line 120

QuantumBlockEncoding.PrimitiveGate.oneQubitCount

Compiled Compiled

This definition gives the library's named construction or computation for “one qubit count”.

def oneQubitCount {qubits : Nat} : PrimitiveGate qubits → Nat
  | .x _ | .ry _ _ | .rz _ _ => 1
  | .cx _ _ _ => 0

commit-pinned source · Verso Blueprint panel

def · line 124

QuantumBlockEncoding.PrimitiveGate.twoQubitCount

Compiled Compiled

This definition gives the library's named construction or computation for “two qubit count”.

def twoQubitCount {qubits : Nat} : PrimitiveGate qubits → Nat
  | .cx _ _ _ => 1
  | _ => 0

commit-pinned source · Verso Blueprint panel

def · line 132

QuantumBlockEncoding.PrimitiveCircuit.gateCount

Compiled Compiled

This definition gives the library's named construction or computation for “gate count”.

def gateCount {qubits : Nat} (circuit : PrimitiveCircuit qubits) : Nat :=
  circuit.length

commit-pinned source · Verso Blueprint panel

def · line 135

QuantumBlockEncoding.PrimitiveCircuit.oneQubitCount

Compiled Compiled

This definition gives the library's named construction or computation for “one qubit count”.

def oneQubitCount {qubits : Nat} (circuit : PrimitiveCircuit qubits) : Nat :=
  circuit.foldl (fun total gate => total + gate.oneQubitCount) 0

commit-pinned source · Verso Blueprint panel

def · line 138

QuantumBlockEncoding.PrimitiveCircuit.twoQubitCount

Compiled Compiled

This definition gives the library's named construction or computation for “two qubit count”.

def twoQubitCount {qubits : Nat} (circuit : PrimitiveCircuit qubits) : Nat :=
  circuit.foldl (fun total gate => total + gate.twoQubitCount) 0

commit-pinned source · Verso Blueprint panel

def · line 141

QuantumBlockEncoding.PrimitiveCircuit.ryCount

Compiled Compiled

This definition gives the library's named construction or computation for “ry count”.

def ryCount {qubits : Nat} (circuit : PrimitiveCircuit qubits) : Nat :=
  circuit.countP fun gate => match gate with
    | .ry _ _ => true
    | _ => false

commit-pinned source · Verso Blueprint panel

def · line 146

QuantumBlockEncoding.PrimitiveCircuit.cxCount

Compiled Compiled

This definition gives the library's named construction or computation for “cx count”.

def cxCount {qubits : Nat} (circuit : PrimitiveCircuit qubits) : Nat :=
  circuit.countP fun gate => match gate with
    | .cx _ _ _ => true
    | _ => false

commit-pinned source · Verso Blueprint panel

theorem · line 151

QuantumBlockEncoding.PrimitiveCircuit.ryCount_append

Compiled Compiled

Lean checks the proposition indexed as “ry count append”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem ryCount_append {qubits : Nat}
    (left right : PrimitiveCircuit qubits) :
    (left ++ right).ryCount = left.ryCount + right.ryCount := by

commit-pinned source · Verso Blueprint panel

theorem · line 156

QuantumBlockEncoding.PrimitiveCircuit.cxCount_append

Compiled Compiled

Lean checks the proposition indexed as “cx count append”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem cxCount_append {qubits : Nat}
    (left right : PrimitiveCircuit qubits) :
    (left ++ right).cxCount = left.cxCount + right.cxCount := by

commit-pinned source · Verso Blueprint panel

theorem · line 161

QuantumBlockEncoding.PrimitiveCircuit.ryCount_singleton_ry

Compiled Compiled

Lean checks the proposition indexed as “ry count singleton ry”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem ryCount_singleton_ry {qubits : Nat}
    (target : Fin qubits) (angle : ExactAngle) :
    ryCount ([PrimitiveGate.ry target angle] : PrimitiveCircuit qubits) = 1 := by

commit-pinned source · Verso Blueprint panel

theorem · line 166

QuantumBlockEncoding.PrimitiveCircuit.ryCount_singleton_cx

Compiled Compiled

Lean checks the proposition indexed as “ry count singleton cx”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem ryCount_singleton_cx {qubits : Nat}
    (control target : Fin qubits) (distinct : control ≠ target) :
    ryCount ([PrimitiveGate.cx control target distinct] : PrimitiveCircuit qubits) = 0 := by

commit-pinned source · Verso Blueprint panel

theorem · line 171

QuantumBlockEncoding.PrimitiveCircuit.cxCount_singleton_ry

Compiled Compiled

Lean checks the proposition indexed as “cx count singleton ry”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem cxCount_singleton_ry {qubits : Nat}
    (target : Fin qubits) (angle : ExactAngle) :
    cxCount ([PrimitiveGate.ry target angle] : PrimitiveCircuit qubits) = 0 := by

commit-pinned source · Verso Blueprint panel

theorem · line 176

QuantumBlockEncoding.PrimitiveCircuit.cxCount_singleton_cx

Compiled Compiled

Lean checks the proposition indexed as “cx count singleton cx”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem cxCount_singleton_cx {qubits : Nat}
    (control target : Fin qubits) (distinct : control ≠ target) :
    cxCount ([PrimitiveGate.cx control target distinct] : PrimitiveCircuit qubits) = 1 := by

commit-pinned source · Verso Blueprint panel

def · line 181

QuantumBlockEncoding.PrimitiveCircuit.nextWireDepth

Compiled Compiled

This definition gives the library's named construction or computation for “next wire depth”.

def nextWireDepth {qubits : Nat} (depth : Fin qubits → Nat)
    (gate : PrimitiveGate qubits) : Fin qubits → Nat :=
  let layer := gate.touched.sup depth
  fun wire => if wire ∈ gate.touched then layer + 1 else depth wire

commit-pinned source · Verso Blueprint panel

def · line 186

QuantumBlockEncoding.PrimitiveCircuit.wireDepths

Compiled Compiled

This definition gives the library's named construction or computation for “wire depths”.

def wireDepths {qubits : Nat} (circuit : PrimitiveCircuit qubits) :
    Fin qubits → Nat :=
  circuit.foldl nextWireDepth (fun _ => 0)

commit-pinned source · Verso Blueprint panel

def · line 190

QuantumBlockEncoding.PrimitiveCircuit.depth

Compiled Compiled

This definition gives the library's named construction or computation for “depth”.

def depth {qubits : Nat} (circuit : PrimitiveCircuit qubits) : Nat :=
  Finset.univ.sup circuit.wireDepths

commit-pinned source · Verso Blueprint panel

def · line 193

QuantumBlockEncoding.PrimitiveCircuit.resource

Compiled Compiled

This definition gives the library's named construction or computation for “resource”.

def resource {qubits : Nat} (circuit : PrimitiveCircuit qubits) : Resource :=
  Resource.ofCountsWithDepth circuit.oneQubitCount circuit.twoQubitCount
    0 0 circuit.depth

commit-pinned source · Verso Blueprint panel

theorem · line 197

QuantumBlockEncoding.PrimitiveCircuit.gateCount_eq_length

Compiled Compiled

Lean checks the proposition indexed as “gate count eq length”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem gateCount_eq_length {qubits : Nat}
    (circuit : PrimitiveCircuit qubits) :
    circuit.gateCount = circuit.length := rfl

commit-pinned source · Verso Blueprint panel

theorem · line 201

QuantumBlockEncoding.PrimitiveCircuit.resource_oracleCalls_eq_zero

Compiled Compiled

Lean checks the proposition indexed as “resource oracle calls eq zero”; the hypotheses and conclusion in the code panel fix its exact scope.

@[simp] theorem resource_oracleCalls_eq_zero {qubits : Nat}
    (circuit : PrimitiveCircuit qubits) :
    circuit.resource.oracleCalls = 0 := rfl

commit-pinned source · Verso Blueprint panel

def · line 209

QuantumBlockEncoding.PrimitiveProgram.identity

Compiled Compiled

This definition gives the library's named construction or computation for “identity”.

def identity (qubits : Nat) : PrimitiveProgram qubits where
  circuit := []
  globalPhase := .rational 0

/-- Execute `left`, then `right`, using chronological list semantics. -/

commit-pinned source · Verso Blueprint panel

def · line 214

QuantumBlockEncoding.PrimitiveProgram.seq

Compiled Compiled

This definition gives the library's named construction or computation for “seq”. Execute 'left', then 'right', using chronological list semantics.

def seq {qubits : Nat} (left right : PrimitiveProgram qubits) :
    PrimitiveProgram qubits where
  circuit := left.circuit ++ right.circuit
  globalPhase := .add left.globalPhase right.globalPhase

commit-pinned source · Verso Blueprint panel

def · line 219

QuantumBlockEncoding.PrimitiveProgram.dagger

Compiled Compiled

This definition gives the library's named construction or computation for “dagger”.

def dagger {qubits : Nat} (program : PrimitiveProgram qubits) :
    PrimitiveProgram qubits where
  circuit := program.circuit.reverse.map PrimitiveGate.dagger
  globalPhase := .neg program.globalPhase

commit-pinned source · Verso Blueprint panel

def · line 224

QuantumBlockEncoding.PrimitiveProgram.resource

Compiled Compiled

This definition gives the library's named construction or computation for “resource”.

def resource {qubits : Nat} (program : PrimitiveProgram qubits) : Resource :=
  program.circuit.resource

commit-pinned source · Verso Blueprint panel