AFTD Auto-Formalizing Theoretical Domains

clean_phase_odd_xor_extension

theoremverified

For any Boolean function invariant under complementing all inputs, an odd-query clean phase circuit yields a clean phase circuit with the same number of queries for the XOR of that function with one additional input bit.

Statement

theorem clean_phase_odd_xor_extension {N q : ℕ}
    (f : (Fin N → Bool) → Bool)
    (hinv : ∀ x, f (fun i => !(x i)) = f x)
    (hq : Odd q) (hclean : phase_query_computes_cleanly f q) :
    phase_query_computes_cleanly
      (fun x : Fin (N + 1) → Bool => Bool.xor (x 0) (f (fun i => x i.succ))) q
Source
Supporting circuit reduction for OP-1638 and the clean-phase adversary method in arXiv:2611.16412 Section 5.
Verified
17 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1
  • phase_query_computes_cleanlyThere is a normalized finite-dimensional q-query unitary phase-query circuit that returns its initial state with phase (-1) to the power…

The proof, explained

To compute the XOR of an extra input bit x 0 with an invariant function f, the circuit redirects dummy queries to x 0 and shifts the remaining queries to the tail bits. When x 0 = 0, the queries match the original circuit on the tail; when x 0 = 1, every query is negated, which by linearity scales every phase query step by -1. Because the number of queries q is odd, the entire circuit accumulates a global phase of (-1)^q = -1 when x 0 = 1 and 1 when x 0 = 0, implementing the XOR without affecting the clean output state.

  1. scalar multiplication commutes with matrix-vector product

    By evaluating at each component i and expanding the definitions of matrix-vector multiplication and dot product, the scalar factors out of the sum.

    lines 6–7

    uses Finset.mul_sum, mul_left_comm

      funext i
      simp [Matrix.mulVec, dotProduct, Finset.mul_sum, mul_left_comm]
  2. scaling each step's phase vector by z scales the final state by z^|L|

    By induction on L. In the nil case, L is empty and z^0 = 1. In the cons case, the first step produces an extra factor of z by the scalar lemma, and the induction hypothesis applies to the tail.

    lines 15–30

    uses List.foldl_cons, List.length_cons, phase_mat_mul_scalar, pow_succ

      induction L generalizing v c with
      | nil => simp
      | cons M L ih =>
          simp only [List.foldl_cons, List.length_cons]
          have hstep : M.mulVec (fun b => new b * (c * v b)) =
              fun b => (c * z) * M.mulVec (fun b => old b * v b) b := by
            have heq : (fun b => new b * (c * v b)) =
                (fun b => (c * z) * (old b * v b)) := by
              funext b
              rw [hphase b]
              ring
            rw [heq, phase_mat_mul_scalar]
          rw [hstep, ih]
          simp only [pow_succ]
          funext b
          ring
  3. the original circuit can be extended to an extra XOR input

    We unpack the clean phase circuit for f and construct a new query register map reg' where dummy queries are routed to input 0 and the rest are shifted to i + 1.

    lines 41–46

      rcases hclean with ⟨B, instF, instD, reg, ψ0, hnorm, U0, hU0, steps, hsteps, hresult⟩
      letI : Fintype B := instF
      letI : DecidableEq B := instD
      let reg' : B → Option (Fin (N + 1)) := fun b =>
        some (match reg b with | none => 0 | some i => i.succ)
      refine ⟨B, instF, instD, reg', ψ0, hnorm, U0, hU0, steps, hsteps, ?_⟩
  4. the phase factor at each basis state scales by z = (-1)^{x 0}

    By case analysis on whether reg b is dummy or queries an input bit, and on the boolean values of x 0 and x (i+1), we check that the phase under the new query differs from the old query by z.

    lines 47–59

      intro x b
      let y : Fin N → Bool := fun i => Bool.xor (x i.succ) (x 0)
      let z : ℂ := if x 0 then -1 else 1
      let old : B → ℂ := fun b => match reg b with
        | none => 1
        | some i => if y i then -1 else 1
      let new : B → ℂ := fun b => if x (match reg b with | none => 0 | some i => i.succ) then -1 else 1
      have hphase : ∀ b, new b = z * old b := by
        intro b
        cases hr : reg b with
        | none => simp [new, z, old, hr]
        | some i =>
            cases ha : x 0 <;> cases hi : x i.succ <;> simp [new, z, old, y, hr, ha, hi, Bool.xor]
  5. the extended circuit computes the XOR of x 0 with f applied to the remaining bits

    We apply the list scaling lemma to factor out z^q = (-1)^{x 0}. Since q is odd, z^q = z. Inverting all inputs preserves f, and combining this with the phase factor matches the clean phase condition for x 0 XOR f(x_{1..N}).

    lines 60–75

    uses phase_list_scaling, one_mul, List.length_ofFn, congrFun, hq.neg_one_pow

      have hfold := phase_list_scaling old new z hphase (List.ofFn steps) (Matrix.mulVec U0 ψ0) 1
      simp only [one_mul, List.length_ofFn] at hfold
      change ((List.ofFn steps).foldl (fun w M => M.mulVec (fun j => new j * w j))
        (Matrix.mulVec U0 ψ0)) b = _
      rw [congrFun hfold b]
      have ho := hresult y b
      change ((List.ofFn steps).foldl (fun w M => M.mulVec (fun j => old j * w j))
          (Matrix.mulVec U0 ψ0)) b = (if f y then (-1 : ℂ) else 1) * ψ0 b at ho
      rw [ho]
      have hf : f y = f (fun i => x i.succ) := by
        cases ha : x 0 with
        | false => simp [y, ha]
        | true => simpa [y, ha, Bool.xor] using hinv (fun i => x i.succ)
      rw [hf]
      cases ha : x 0 <;> cases hb : f (fun i => x i.succ) <;>
        simp [z, ha, hb, Bool.xor, hq.neg_one_pow]
hq.neg_one_pow
(-1)^n = -1 for odd n

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

sectionvariable {B : Type} [Fintype B]lemma phase_mat_mul_scalar (M : Matrix B B ℂ) (z : ℂ) (v : B → ℂ) :    M.mulVec (fun i => z * v i) = fun i => z * M.mulVec v i := by  funext i  simp [Matrix.mulVec, dotProduct, Finset.mul_sum, mul_left_comm]lemma phase_list_scaling (old new : B → ℂ) (z : ℂ)    (hphase : ∀ b, new b = z * old b) (L : List (Matrix B B ℂ))    (v : B → ℂ) (c : ℂ) :    L.foldl (fun w M => M.mulVec (fun b => new b * w b)) (fun b => c * v b) =      fun b => (c * z ^ L.length) *        (L.foldl (fun w M => M.mulVec (fun b => old b * w b)) v) b := by  induction L generalizing v c with  | nil => simp  | cons M L ih =>      simp only [List.foldl_cons, List.length_cons]      have hstep : M.mulVec (fun b => new b * (c * v b)) =          fun b => (c * z) * M.mulVec (fun b => old b * v b) b := by        have heq : (fun b => new b * (c * v b)) =            (fun b => (c * z) * (old b * v b)) := by          funext b          rw [hphase b]          ring        rw [heq, phase_mat_mul_scalar]      rw [hstep, ih]      simp only [pow_succ]      funext b      ringend/-- An odd clean-phase circuit extends to an extra XOR input using the original dummy query index. -/theorem clean_phase_odd_xor_extension {N q : ℕ}    (f : (Fin N → Bool) → Bool)    (hinv : ∀ x, f (fun i => !(x i)) = f x)    (hq : Odd q) (hclean : phase_query_computes_cleanly f q) :    phase_query_computes_cleanly      (fun x : Fin (N + 1) → Bool => Bool.xor (x 0) (f (fun i => x i.succ))) q := by  rcases hclean with ⟨B, instF, instD, reg, ψ0, hnorm, U0, hU0, steps, hsteps, hresult⟩  letI : Fintype B := instF  letI : DecidableEq B := instD  let reg' : B → Option (Fin (N + 1)) := fun b =>    some (match reg b with | none => 0 | some i => i.succ)  refine ⟨B, instF, instD, reg', ψ0, hnorm, U0, hU0, steps, hsteps, ?_⟩  intro x b  let y : Fin N → Bool := fun i => Bool.xor (x i.succ) (x 0)  let z : ℂ := if x 0 then -1 else 1  let old : B → ℂ := fun b => match reg b with    | none => 1    | some i => if y i then -1 else 1  let new : B → ℂ := fun b => if x (match reg b with | none => 0 | some i => i.succ) then -1 else 1  have hphase : ∀ b, new b = z * old b := by    intro b    cases hr : reg b with    | none => simp [new, z, old, hr]    | some i =>        cases ha : x 0 <;> cases hi : x i.succ <;> simp [new, z, old, y, hr, ha, hi, Bool.xor]  have hfold := phase_list_scaling old new z hphase (List.ofFn steps) (Matrix.mulVec U0 ψ0) 1  simp only [one_mul, List.length_ofFn] at hfold  change ((List.ofFn steps).foldl (fun w M => M.mulVec (fun j => new j * w j))    (Matrix.mulVec U0 ψ0)) b = _  rw [congrFun hfold b]  have ho := hresult y b  change ((List.ofFn steps).foldl (fun w M => M.mulVec (fun j => old j * w j))      (Matrix.mulVec U0 ψ0)) b = (if f y then (-1 : ℂ) else 1) * ψ0 b at ho  rw [ho]  have hf : f y = f (fun i => x i.succ) := by    cases ha : x 0 with    | false => simp [y, ha]    | true => simpa [y, ha, Bool.xor] using hinv (fun i => x i.succ)  rw [hf]  cases ha : x 0 <;> cases hb : f (fun i => x i.succ) <;>    simp [z, ha, hb, Bool.xor, hq.neg_one_pow]
See it in the graphDiscuss this resultChallenge it