AFTD Auto-Formalizing Theoretical Domains

op2130_prepared_circuit_correct

theoremverified

For any number of alternating gates and any bit and dummy tapes, the prepared profile and reverse loading followed by left-to-right evaluation yield the precise last-vertex discrepancy as an alternating Boolean decision fold.

Statement

theorem op2130_prepared_circuit_correct (m : ℕ) (bits loadCoins evalCoins : ℕ → Bool)
    (c1 c2 c3 c4 : Bool) :
    let h0 := op2130_load_reverse bits loadCoins (m+1) (op2130_load_profile (m+1))
    let h1 := op2130_height_double h0 1 c1 c2
    let h2 := op2130_height_double h1 2 c3 c4
    let out := op2130_eval_steps evalCoins m 0 h2
    let v := 2+2*m
    out (v+1) - out v =
      if m%2=0 then
        (if bits m then 2 else 0) - (if op2130_value_fold (m+1) bits then 1 else -1)
      else (if bits m then 1 else -1) - (if op2130_value_fold (m+1) bits then 2 else 0)
Source
OP-2130, all-size prepared-profile decision circuit
Verified
23 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 5
  • op2130_load_profile_correctFor any number of gates and any bits and dummy coins, the reverse loading procedure transforms the prepared profile into the invariant…
  • op2130_load_to_eval_readyAfter the reverse loading invariant holds, four fixed local updates establish the initial invariant for the verified left-to-right gate…
  • op2130_eval_ready_inductionAn arbitrary number of four-request circuit advances preserves the encoded gate value, all untouched bit and gate coordinates, and the AND…
  • op2130_eval_matches_decision_foldThe recursive accumulator used by the verified gate-evaluation invariant equals the alternating OR/AND fold in the decision-circuit…
  • op2130_height_double_localTwo consecutive updates at one path height affect only that site, and their center value is the corresponding two-step scalar gate.

Lean source view module on GitHub

theorem op2130_prepared_circuit_correct (m : ℕ) (bits loadCoins evalCoins : ℕ → Bool)
    (c1 c2 c3 c4 : Bool) :
    let h0 := op2130_load_reverse bits loadCoins (m+1) (op2130_load_profile (m+1))
    let h1 := op2130_height_double h0 1 c1 c2
    let h2 := op2130_height_double h1 2 c3 c4
    let out := op2130_eval_steps evalCoins m 0 h2
    let v := 2+2*m
    out (v+1) - out v =
      if m%2=0 then
        (if bits m then 2 else 0) - (if op2130_value_fold (m+1) bits then 1 else -1)
      else (if bits m then 1 else -1) - (if op2130_value_fold (m+1) bits then 2 else 0) := by
  let h0 := op2130_load_reverse bits loadCoins (m+1) (op2130_load_profile (m+1))
  let h1 := op2130_height_double h0 1 c1 c2
  let h2 := op2130_height_double h1 2 c3 c4
  let out := op2130_eval_steps evalCoins m 0 h2
  have hload : op2130_load_inv (m+1) 0 h0 bits := op2130_load_profile_correct (m+1) bits loadCoins
  have hstart : op2130_eval_ready (m+1) 0 h2 bits (bits 0) :=
    op2130_load_to_eval_ready (m+1) h0 bits c1 c2 c3 c4 (by omega) hload
  have hfinish := op2130_eval_ready_induction (m+1) m 0 h2 bits evalCoins (bits 0) (by omega) hstart
  have hg := hfinish.1
  have hb := hfinish.2.1 m (by omega) (by omega)
  simp only [Nat.zero_add, op2130_eval_matches_decision_fold] at hg
  change out (2+2*m+1) - out (2+2*m) = _
  dsimp only [out]
  by_cases he : m%2=0
  · simp only [he, if_true] at hg hb ⊢
    rw [show 2+2*m+1 = 3+2*m by omega, hb, hg]
  · simp only [he, if_false] at hg hb ⊢
    rw [show 2+2*m+1 = 3+2*m by omega, hb, hg]
See it in the graphDiscuss this resultChallenge it