Documentation

LeanPool.LeanQuantumAlg.Primitives.WalshHadamard

Walsh-Hadamard transform and the XOR phase-query pipeline #

The reusable machinery shared by the single-query Hadamard-oracle-Hadamard algorithms (Deutsch-Jozsa, Bernstein-Vazirani): the n-qubit Hadamard layer in Walsh-Hadamard closed form [dW19, qcnotes.tex:1005-1006], and the XOR-oracle phase-query pipeline that runs a Boolean oracle on the uniform input register with a |−⟩ target.

The central bridge postOracleState_eq_afterPhaseQuery_tensor rewrites the actual XOR-oracle query as the phase pattern (√(2^n))⁻¹ ∑ x (-1)^{f x}|x⟩ tensored with the unchanged |−⟩ target, so a single query followed by the second Hadamard layer (finalJointState) factors through the input-register finalState.

These pieces sit in a Primitives module so the Deutsch-Jozsa and Bernstein-Vazirani algorithms can both build on them without importing one another; each algorithm keeps only its target-specific content (the constant/balanced promise and amplitude test for Deutsch-Jozsa; Walsh-character orthogonality and string recovery for Bernstein-Vazirani).

Main definitions #

@[reducible, inline]

A Boolean oracle on 2^n input labels. It is queried through Gate.xorOracle, not through a separate oracle type.

Equations
Instances For
    @[reducible, inline]

    The standard XOR query gate for a Boolean oracle.

    Equations
    Instances For
      def QuantumAlg.WalshHadamard.phaseSign {n : } (f : Oracle n) (x : Fin (2 ^ n)) :

      The phase (-1)^{f x}, written as a complex scalar.

      Equations
      Instances For

        The Walsh-Hadamard transform #

        def QuantumAlg.WalshHadamard.bit {n : } (x : Fin (2 ^ n)) (k : Fin n) :

        The bit of a basis label used in the Walsh-Hadamard character. The bit order only affects nonzero rows; the zero row used by Deutsch-Jozsa is independent of it.

        Equations
        Instances For

          Parity of the bitwise inner product of two basis labels.

          Equations
          Instances For

            The Walsh-Hadamard sign (-1)^{x · y}.

            Equations
            Instances For

              (√(2^n))⁻¹, the normalization scalar of the n-qubit Hadamard layer.

              Equations
              Instances For
                @[simp]
                @[simp]
                @[simp]
                @[simp]
                theorem QuantumAlg.WalshHadamard.star_walshSign {n : } (x y : Fin (2 ^ n)) :
                @[simp]

                Walsh-character orthogonality #

                def QuantumAlg.WalshHadamard.flipBit {n : } (x : Fin (2 ^ n)) (k : Fin n) :
                Fin (2 ^ n)

                Flip bit k of a basis label.

                Equations
                Instances For
                  theorem QuantumAlg.WalshHadamard.bit_flipBit {n : } (x : Fin (2 ^ n)) (k k' : Fin n) :
                  bit (flipBit x k) k' = (bit x k' ^^ decide (k = k'))
                  theorem QuantumAlg.WalshHadamard.flipBit_flipBit {n : } (x : Fin (2 ^ n)) (k : Fin n) :
                  flipBit (flipBit x k) k = x
                  theorem QuantumAlg.WalshHadamard.flipBit_ne {n : } (x : Fin (2 ^ n)) (k : Fin n) :
                  flipBit x k x
                  theorem QuantumAlg.WalshHadamard.dotParity_flipBit {n : } (x z : Fin (2 ^ n)) (k : Fin n) :
                  dotParity (flipBit x k) z = (dotParity x z ^^ bit z k)

                  Flipping bit k of x toggles the parity x · z exactly when bit k of z is set.

                  theorem QuantumAlg.WalshHadamard.exists_bit_ne {n : } {y s : Fin (2 ^ n)} (h : y s) :
                  ∃ (k : Fin n), bit y k bit s k

                  Two distinct labels differ at some bit.

                  theorem QuantumAlg.WalshHadamard.walshSign_mul_walshSign_flipBit {n : } {y s : Fin (2 ^ n)} {k : Fin n} (hk : bit y k bit s k) (x : Fin (2 ^ n)) :

                  Flipping a bit on which y and s disagree negates the product of their Walsh signs.

                  theorem QuantumAlg.WalshHadamard.sum_walshSign_mul_walshSign {n : } {y s : Fin (2 ^ n)} (h : y s) :
                  x : Fin (2 ^ n), walshSign y x * walshSign s x = 0

                  Walsh-character orthogonality: for y ≠ s the signed sum over all basis labels cancels in pairs under the bit-flip involution.

                  theorem QuantumAlg.WalshHadamard.sum_walshSign_mul_walshSign_eq {n : } (y s : Fin (2 ^ n)) :
                  x : Fin (2 ^ n), walshSign y x * walshSign s x = if y = s then ↑(2 ^ n) else 0
                  @[simp]
                  theorem QuantumAlg.WalshHadamard.norm_phaseSign {n : } (f : Oracle n) (x : Fin (2 ^ n)) :

                  A Boolean phase has unit norm.

                  Raw n-qubit Hadamard layer in Walsh-Hadamard closed form.

                  Equations
                  Instances For

                    The Walsh-Hadamard closed-form matrix is unitary.

                    The n-qubit Hadamard layer as a unitary gate.

                    Equations
                    Instances For

                      Raw uniform input-register vector produced by the first Hadamard layer.

                      Equations
                      Instances For

                        The uniform input-register vector has unit norm.

                        The uniform input-register state produced by the first Hadamard layer.

                        Equations
                        Instances For

                          The first Hadamard layer sends |0^n⟩ to the uniform superposition.

                          The XOR phase-query pipeline #

                          The pre-Hadamard joint basis state |0^n⟩ ⊗ |−⟩.

                          Equations
                          Instances For
                            noncomputable def QuantumAlg.WalshHadamard.initialState (n : ) :
                            PureState (n + 1)

                            The joint state queried by the XOR oracle, obtained by applying the first Hadamard layer to the input register and leaving the |−⟩ target alone.

                            Equations
                            Instances For

                              The queried state is the uniform input register tensored with |−⟩.

                              noncomputable def QuantumAlg.WalshHadamard.postOracleState {n : } (f : Oracle n) :
                              PureState (n + 1)

                              The actual post-query joint state, using the XOR oracle gate.

                              Equations
                              Instances For

                                The input-register state after rewriting the oracle query by phase kickback: (√(2^n))⁻¹ ∑ x, (-1)^{f x}|x⟩.

                                Equations
                                Instances For

                                  The phase-query vector has unit norm.

                                  The input register after the XOR oracle has been converted into a phase query.

                                  Equations
                                  Instances For

                                    The actual XOR-oracle query on the uniform input register and |−⟩ target is exactly the phase-query state tensored with the unchanged target.

                                    noncomputable def QuantumAlg.WalshHadamard.finalState {n : } (f : Oracle n) :

                                    The final input-register state after the second Hadamard layer, in the phase-query view.

                                    Equations
                                    Instances For
                                      noncomputable def QuantumAlg.WalshHadamard.finalJointState {n : } (f : Oracle n) :
                                      PureState (n + 1)

                                      The actual final joint state: apply the second Hadamard layer to the input register and leave the target qubit alone.

                                      Equations
                                      Instances For

                                        The actual final joint state factors as the final input-register state and the unchanged |−⟩ target.