Documentation

LeanPool.LeanQuantumAlg.Core.Gate

Hilbert operators and unitary gates #

HilbertOperator n is the raw 2^n × 2^n complex matrix type. It is used for observables, projectors, matrix sums, and block-encoding operators that are not necessarily unitary.

Gate n is a unitary Hilbert operator. Gate application maps pure states to pure states; arbitrary linear combinations stay at the raw StateVector layer until separately normalized.

Pinned Mathlib API: Matrix.mulVec (and mulVec_add/smul/single_one, one_mulVec, mulVec_mulVec), Matrix.mem_unitaryGroup_iff, Equiv.Perm.permMatrix (and Matrix.permMatrix_mulVec, Matrix.conjTranspose_permMatrix, Matrix.permMatrix_mul, Matrix.permMatrix_one), Finset.sum_ite_eq'.

@[reducible, inline]

Raw linear operator on an n-qubit Hilbert space.

Equations
Instances For

    A Hilbert operator acts on a raw state vector by matrix-vector multiplication.

    Equations
    Instances For
      @[simp]
      theorem QuantumAlg.HilbertOperator.applyVec_apply {n : } (A : HilbertOperator n) (ψ : StateVector n) (i : Fin (2 ^ n)) :
      (A.applyVec ψ).ofLp i = j : Fin (2 ^ n), A i j * ψ.ofLp j
      @[simp]
      theorem QuantumAlg.HilbertOperator.applyVec_add {n : } (A : HilbertOperator n) (ψ φ : StateVector n) :
      A.applyVec (ψ + φ) = A.applyVec ψ + A.applyVec φ
      @[simp]
      theorem QuantumAlg.HilbertOperator.applyVec_sub {n : } (A : HilbertOperator n) (ψ φ : StateVector n) :
      A.applyVec (ψ - φ) = A.applyVec ψ - A.applyVec φ
      @[simp]
      @[simp]
      @[simp]
      theorem QuantumAlg.HilbertOperator.applyVec_ket {n : } (A : HilbertOperator n) (x i : Fin (2 ^ n)) :
      (A.applyVec (PureState.ket x).vec).ofLp i = A i x

      A Hilbert operator sends a basis ket to its corresponding column.

      A unitary Hilbert operator preserves inner products on raw state vectors.

      A unitary Hilbert operator preserves raw vector norms.

      structure QuantumAlg.Gate (n : ) :

      A unitary gate on an n-qubit Hilbert space.

      Instances For
        @[implicit_reducible]
        instance QuantumAlg.Gate.instCoeFunForallFinHPowNatOfNatForallComplex {n : } :
        CoeFun (Gate n) fun (x : Gate n) => Fin (2 ^ n)Fin (2 ^ n)
        Equations
        theorem QuantumAlg.Gate.ext {n : } {G K : Gate n} (h : ∀ (i j : Fin (2 ^ n)), G.op i j = K.op i j) :
        G = K
        theorem QuantumAlg.Gate.ext_iff {n : } {G K : Gate n} :
        G = K ∀ (i j : Fin (2 ^ n)), G.op i j = K.op i j

        Build a gate from a unitary Hilbert operator.

        Equations
        Instances For
          @[simp]
          theorem QuantumAlg.Gate.coe_ofUnitary {n : } (U : HilbertOperator n) (hU : U Matrix.unitaryGroup (Fin (2 ^ n)) ) :
          (ofUnitary U hU).op = U
          @[implicit_reducible]
          Equations
          • One or more equations did not get rendered due to their size.
          @[simp]
          theorem QuantumAlg.Gate.coe_one {n : } :
          op 1 = 1
          @[simp]
          theorem QuantumAlg.Gate.coe_mul {n : } (G K : Gate n) :
          (G * K).op = G.op * K.op

          Conjugate transpose of a unitary gate, again as a gate.

          Equations
          Instances For
            @[implicit_reducible]
            instance QuantumAlg.Gate.instInv {n : } :
            Inv (Gate n)
            Equations
            noncomputable def QuantumAlg.Gate.applyVec {n : } (G : Gate n) (ψ : StateVector n) :

            A gate acts on a raw vector by its underlying Hilbert operator.

            Equations
            Instances For
              noncomputable def QuantumAlg.Gate.apply {n : } (G : Gate n) (ψ : PureState n) :

              A gate evolves a pure state to a pure state.

              Equations
              Instances For
                noncomputable def QuantumAlg.Gate.evolve {n : } (G : Gate n) (ψ : PureState n) :

                Alias for apply, emphasizing unitary time evolution.

                Equations
                Instances For
                  @[simp]
                  theorem QuantumAlg.Gate.applyVec_apply {n : } (G : Gate n) (ψ : StateVector n) (i : Fin (2 ^ n)) :
                  (G.applyVec ψ).ofLp i = j : Fin (2 ^ n), G.op i j * ψ.ofLp j
                  @[simp]
                  theorem QuantumAlg.Gate.apply_apply {n : } (G : Gate n) (ψ : PureState n) (i : Fin (2 ^ n)) :
                  (G.apply ψ).vec.ofLp i = j : Fin (2 ^ n), G.op i j * ψ.vec.ofLp j
                  @[simp]
                  theorem QuantumAlg.Gate.applyVec_add {n : } (G : Gate n) (ψ φ : StateVector n) :
                  G.applyVec (ψ + φ) = G.applyVec ψ + G.applyVec φ
                  @[simp]
                  theorem QuantumAlg.Gate.applyVec_sub {n : } (G : Gate n) (ψ φ : StateVector n) :
                  G.applyVec (ψ - φ) = G.applyVec ψ - G.applyVec φ
                  @[simp]
                  theorem QuantumAlg.Gate.applyVec_smul {n : } (G : Gate n) (c : ) (ψ : StateVector n) :
                  G.applyVec (c ψ) = c G.applyVec ψ
                  @[simp]
                  theorem QuantumAlg.Gate.applyVec_neg {n : } (G : Gate n) (ψ : StateVector n) :
                  G.applyVec (-ψ) = -G.applyVec ψ
                  theorem QuantumAlg.Gate.apply_add {n : } (G : Gate n) (ψ φ : StateVector n) :
                  G.applyVec (ψ + φ) = G.applyVec ψ + G.applyVec φ
                  theorem QuantumAlg.Gate.apply_sub {n : } (G : Gate n) (ψ φ : StateVector n) :
                  G.applyVec (ψ - φ) = G.applyVec ψ - G.applyVec φ
                  theorem QuantumAlg.Gate.apply_smul {n : } (G : Gate n) (c : ) (ψ : StateVector n) :
                  G.applyVec (c ψ) = c G.applyVec ψ
                  theorem QuantumAlg.Gate.apply_neg {n : } (G : Gate n) (ψ : StateVector n) :
                  G.applyVec (-ψ) = -G.applyVec ψ
                  @[simp]
                  theorem QuantumAlg.Gate.one_apply {n : } (ψ : PureState n) :
                  apply 1 ψ = ψ
                  @[simp]
                  theorem QuantumAlg.Gate.one_applyVec {n : } (ψ : StateVector n) :
                  applyVec 1 ψ = ψ
                  theorem QuantumAlg.Gate.mul_applyVec {n : } (G K : Gate n) (ψ : StateVector n) :
                  (G * K).applyVec ψ = G.applyVec (K.applyVec ψ)
                  theorem QuantumAlg.Gate.mul_apply {n : } (G K : Gate n) (ψ : PureState n) :
                  (G * K).apply ψ = G.apply (K.apply ψ)
                  theorem QuantumAlg.Gate.apply_ket {n : } (G : Gate n) (x i : Fin (2 ^ n)) :
                  (G.apply (PureState.ket x)).vec.ofLp i = G.op i x

                  A gate sends the basis ket |x⟩ to its x-th column.

                  Permutation gates #

                  def QuantumAlg.Gate.ofPerm {n : } (σ : Equiv.Perm (Fin (2 ^ n))) :

                  The gate permuting the computational basis by σ: (ofPerm σ).apply (ket x) = ket (σ⁻¹ x). Unitary by construction.

                  Equations
                  Instances For
                    theorem QuantumAlg.Gate.ofPerm_apply {n : } (σ : Equiv.Perm (Fin (2 ^ n))) (ψ : PureState n) (i : Fin (2 ^ n)) :
                    ((ofPerm σ).apply ψ).vec.ofLp i = ψ.vec.ofLp (σ i)
                    theorem QuantumAlg.Gate.ofPerm_apply_ket {n : } (σ : Equiv.Perm (Fin (2 ^ n))) (x : Fin (2 ^ n)) :

                    Unitary gates preserve inner products and norms #

                    theorem QuantumAlg.Gate.inner_apply_apply_of_mem_unitaryGroup {n : } {U : Gate n} (_hU : U.op Matrix.unitaryGroup (Fin (2 ^ n)) ) (ψ φ : PureState n) :
                    inner (U.apply ψ).vec (U.apply φ).vec = inner ψ.vec φ.vec

                    Unitary gates preserve the inner product.

                    Unitary gates preserve the norm.

                    theorem QuantumAlg.Gate.norm_apply {n : } (U : Gate n) (ψ : PureState n) :
                    (U.apply ψ).vec = 1