{
"unit": "L-meta-33679",
"statement_sha256": "c84c11d9880b1d446f0ac95873ebd36e68046126cfca984fb944d055cbe0cf8c",
"statement_note": "GET https://pequalnp.com/desk/row?gap=L-meta-33679 returned gaps: [] with withdrawn {L-meta-33679: proved} and checked file lean/PEqualNP/Outside/L_meta_33679.lean, so gaps[0].statement could not be read and its SHA-256 could not be compared. The statement was taken instead from the theorem in the merged upstream file at the commit below; that text (with or without the theorem header, outer parentheses, := by, or trailing newline) did not reproduce c84c11d9..., so the exact hashed form is unknown. The value above is the partial input, unverified.",
"unit_state": "Upstream already holds a merged, proved L_meta_33679.lean (139,785 bytes, an independent proof); this piece is not a new solution of an open gap.",
"partial_builds": {
"value": true,
"seconds": 23.13,
"peak_memory_gb": 7.34,
"command": "lake build PEqualNP.Scratch.Partial (partial copied unchanged to lean/PEqualNP/Scratch/Partial.lean)",
"exit": 0,
"note": "peak RSS 7,165,840 KiB, above 6.5 GB; the partial imports all of Mathlib"
},
"piece_complete": true,
"lean": "\nimport Mathlib.LinearAlgebra.Matrix.Rank\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.FinCases\nimport Mathlib.Tactic.Abel\nimport PEqualNP.Defs\n\nnamespace PEqualNP.Outside.L_meta_33679\n\nopen PEqualNP.CircuitLowerBounds PEqualNP.MetaComplexity.NestedCover PEqualNP.Represents\nopen scoped BigOperators\n\nabbrev F := ZMod 2\n\ndef b2z (b : Bool) : F := if b then 1 else 0\ndef nonlinear (g : Gate) : Bool :=\n  (g.inputs.length == 2) &&\n    xor (xor (g.op.eval [false, false]) (g.op.eval [false, true]))\n        (xor (g.op.eval [true, false]) (g.op.eval [true, true]))\n\ndef depthList (w : ℕ) (gs : List Gate) : List ℕ :=\n  gs.foldl (fun (ds : List ℕ) g =>\n    ds ++ [(g.inputs.map (fun h => ds.getD h 0)).foldr max 0 + (nonlinear g).toNat])\n    (List.replicate w 0)\nsection Algebra\nopen Finset\nvariable {α β : Type*}\ndef anchor (a₀ : α) (b₀ : β) : (α → β → F) →ₗ[F] Matrix α β F where\n  toFun f a b := f a b + f a b₀ + f a₀ b + f a₀ b₀\n  map_add' f g := by\n    ext a b\n    change (_ : F) = f a b + f a b₀ + f a₀ b + f a₀ b₀ + (g a b + g a b₀ + g a₀ b + g a₀ b₀)\n    simp only [Pi.add_apply]\n    abel\n  map_smul' t f := by\n    ext a b\n    change (_ : F) = t * (f a b + f a b₀ + f a₀ b + f a₀ b₀)\n    simp only [Pi.smul_apply, smul_eq_mul, mul_add]\n\nend Algebra\n\nopen Finset\nabbrev Vec (k : ℕ) := Fin k → Bool → F\n\ndef quad {k : ℕ} (x : Vec k) : F := ∑ l, x l false * x l true\n\ndef polar {k : ℕ} (x y : Vec k) : F :=\n  ∑ l, (x l false * y l true + x l true * y l false)\ndef edges {s k : ℕ} (m : Fin s → Vec k) : Finset (Fin s × Fin s) :=\n  univ.filter (fun ij => ij.1 < ij.2 ∧ polar (m ij.1) (m ij.2) ≠ 0)\ndef balancedPairs (s k : ℕ) : Finset (Fin s × Fin s) :=\n  univ.filter (fun ij => ij.1 < ij.2 ∧ ij.1.val % (2*k+1) ≠ ij.2.val % (2*k+1))\ndef Fits (s k : ℕ) {n m : ℕ} (G : Fin n → Fin m → Bool) : Prop :=\n  ∃ (C : Circuit) (cut : ℕ), cut ≤ C.gates.length ∧\n    ReadsBack (n+m) C ∧\n    (∀ g ∈ C.gates, g.inputs.length ≤ 2) ∧\n    (C.gates.take cut).countP nonlinear ≤ s ∧ (C.gates.drop cut).countP nonlinear ≤ k ∧\n    (∀ d ∈ depthList (n+m) (C.gates.take cut), d ≤ 1) ∧\n    (∀ d ∈ depthList (n+m+cut) (C.gates.drop cut), d ≤ 1) ∧\n    Represents G C\n\nnoncomputable def anchoredRank {n m : ℕ} (G : Fin n → Fin m → Bool) (u : Fin n) (v : Fin m) : ℕ :=\n  (anchor u v (fun i j => b2z (G i j))).rank\n\ndef budget (s k : ℕ) : ℕ := if k = 0 then 2*s else 2*k+4*s+4*(balancedPairs s k).card\nabbrev Coords (n : ℕ) := Fin n × Bool\nabbrev Cube (s k : ℕ) := (Coords k → F) × (Coords s → F)\ndef fromCoords {k : ℕ} (x : Coords k → F) : Vec k := fun i t => x (i,t)\ndef witnessZ {s k : ℕ} (i : Fin s) (x y : Cube s k) : F :=\n  x.2 (i,false) * y.2 (i,false) + x.2 (i,true) * y.2 (i,true)\n\ndef witnessFun {s k : ℕ} (m : Fin s → Vec k) (x y : Cube s k) : F :=\n  (∑ i, quad (m i) * witnessZ i x y) +\n    quad (fromCoords x.1 + fromCoords y.1 + ∑ i, witnessZ i x y • m i)\n\nnamespace Build\n\nabbrev Field := ZMod 2\nlemma f2_cases (a : ZMod 2) : a = 0 ∨ a = 1 := by\n  fin_cases a\n  · left; rfl\n  · right; rfl\n\ndef depths (width : ℕ) (C : Circuit) : List ℕ :=\n  C.gates.foldl (fun (ds : List ℕ) g =>\n    ds ++ [(g.inputs.map (fun a => ds.getD a 0)).foldr max 0 + (nonlinear g).toNat])\n    (List.replicate width 0)\n\ndef wiresStep (w : List Bool) (g : Gate) : List Bool :=\n  w ++ [g.op.eval (g.inputs.map fun i => w.getD i false)]\n\ndef depthsStep (ds : List ℕ) (g : Gate) : List ℕ :=\n  ds ++ [(g.inputs.map (fun a => ds.getD a 0)).foldr max 0 + (nonlinear g).toNat]\n\nlemma getD_append_left {α : Type} (l1 l2 : List α) (i : ℕ) (d : α) (hi : i < l1.length) :\n    (l1 ++ l2).getD i d = l1.getD i d := by\n  simp only [List.getD_eq_getElem?_getD, List.getElem?_append_left hi]\n\nlemma getD_append_right {α : Type} (l1 l2 : List α) (i : ℕ) (d : α) (hi : l1.length ≤ i) :\n    (l1 ++ l2).getD i d = l2.getD (i - l1.length) d := by\n  simp only [List.getD_eq_getElem?_getD, List.getElem?_append_right hi]\n\nlemma getD_concat_last {α : Type} (l : List α) (a d : α) :\n    (l ++ [a]).getD l.length d = a := by\n  rw [getD_append_right l [a] l.length d (le_refl _)]\n  simp\n\nlemma wires_fold_length (gs : List Gate) (x : List Bool) :\n    (gs.foldl wiresStep x).length = x.length + gs.length := by\n  induction gs generalizing x with\n  | nil => simp\n  | cons g gs ih =>\n    simp only [List.foldl_cons, ih, wiresStep, List.length_append, List.length_cons, List.length_nil]\n    omega\n\nlemma depths_fold_length (gs : List Gate) (ds : List ℕ) :\n    (gs.foldl depthsStep ds).length = ds.length + gs.length := by\n  induction gs generalizing ds with\n  | nil => simp\n  | cons g gs ih =>\n    simp only [List.foldl_cons, ih, depthsStep, List.length_append, List.length_cons, List.length_nil]\n    omega\n\nlemma foldr_max_le_iff (l : List ℕ) (k : ℕ) :\n    l.foldr max 0 ≤ k ↔ ∀ a ∈ l, a ≤ k := by\n  induction l with\n  | nil => simp\n  | cons x xs ih =>\n    simp only [List.foldr_cons, max_le_iff, List.mem_cons, forall_eq_or_imp, ih]\n\nlemma getD_le_foldr_max (l : List ℕ) (w : ℕ) : l.getD w 0 ≤ l.foldr max 0 := by\n  by_cases hlt : w < l.length\n  · have hmem : l.getD w 0 ∈ l := by\n      simp only [List.getD_eq_getElem?_getD, List.getElem?_eq_getElem hlt, Option.getD_some]\n      exact List.getElem_mem hlt\n    exact (foldr_max_le_iff l _).mp (le_refl _) _ hmem\n  · have hnone : l[w]? = none := List.getElem?_eq_none (by omega)\n    simp only [List.getD_eq_getElem?_getD, hnone, Option.getD_none]\n    exact Nat.zero_le _\n\ndef b2f (b : Bool) : ZMod 2 := if b then 1 else 0\n\nlemma b2f_injective : Function.Injective b2f := by\n  intro a b h\n  cases a <;> cases b <;> first | rfl | exact absurd h (by decide)\n\nlemma b2f_xor (a b : Bool) : b2f (xor a b) = b2f a + b2f b := by\n  cases a <;> cases b <;> decide\n\nlemma b2f_and (a b : Bool) : b2f (a && b) = b2f a * b2f b := by\n  cases a <;> cases b <;> decide\n\nlemma oneEach_length {n m : ℕ} (x : Fin n) (y : Fin m) :\n    (oneEach x y).length = n + m := by\n  simp [oneEach]\n\nlemma oneEach_getD_left {n m : ℕ} (x : Fin n) (y : Fin m) (i : ℕ) (hi : i < n) :\n    (oneEach x y).getD i false = decide (⟨i, hi⟩ = x) := by\n  simp only [oneEach]\n  rw [getD_append_left _ _ i false (by simp [hi])]\n  simp [List.getD_eq_getElem?_getD, hi]\n\nlemma oneEach_getD_right {n m : ℕ} (x : Fin n) (y : Fin m) (j : ℕ) (hj : j < m) :\n    (oneEach x y).getD (n + j) false = decide (⟨j, hj⟩ = y) := by\n  simp only [oneEach]\n  rw [getD_append_right _ _ (n + j) false (by simp)]\n  simp [List.getD_eq_getElem?_getD, hj]\n\nstructure Builder (width : ℕ) where\n  gates : List Gate\n  hRB : ∀ j < gates.length, ∀ i ∈ (gates.getD j ⟨GateOp.or, []⟩).inputs, i < width + j\n  hFan : ∀ g ∈ gates, g.inputs.length ≤ 2\n\ndef Builder.empty (width : ℕ) : Builder width :=\n  ⟨[], fun _ h => by simp at h, fun _ h => by simp at h⟩\n\ndef Builder.push {width : ℕ} (B : Builder width) (g : Gate)\n    (hgRB : ∀ i ∈ g.inputs, i < width + B.gates.length) (hgFan : g.inputs.length ≤ 2) :\n    Builder width × ℕ :=\n  (⟨B.gates ++ [g], by\n      intro j hj i hi\n      rw [List.length_append, List.length_singleton] at hj\n      by_cases hlt : j < B.gates.length\n      · rw [getD_append_left B.gates [g] j _ hlt] at hi\n        exact B.hRB j hlt i hi\n      · have heq : j = B.gates.length := by omega\n        subst heq\n        rw [getD_concat_last] at hi\n        exact hgRB i hi,\n    by\n      intro g' hg'\n      rcases List.mem_append.mp hg' with h1 | h2\n      · exact B.hFan g' h1\n      · simp only [List.mem_singleton] at h2\n        subst h2\n        exact hgFan⟩,\n   width + B.gates.length)\n\ndef Builder.wires {width : ℕ} (B : Builder width) (x : List Bool) : List Bool :=\n  B.gates.foldl wiresStep x\n\ndef Builder.depths {width : ℕ} (B : Builder width) : List ℕ :=\n  B.gates.foldl depthsStep (List.replicate width 0)\n\ndef Builder.nlCount {width : ℕ} (B : Builder width) : ℕ :=\n  B.gates.countP nonlinear\n\nlemma builder_push_wires_old {width : ℕ} (B : Builder width) (g : Gate)\n    (hgRB : ∀ i ∈ g.inputs, i < width + B.gates.length) (hgFan : g.inputs.length ≤ 2)\n    (x : List Bool) (hx : x.length = width) (w : ℕ) (hw : w < width + B.gates.length) :\n    ((B.push g hgRB hgFan).1.wires x).getD w false = (B.wires x).getD w false := by\n  simp only [Builder.push, Builder.wires, List.foldl_append, List.foldl_cons, List.foldl_nil, wiresStep]\n  rw [getD_append_left]\n  rw [wires_fold_length, hx]\n  exact hw\n\nlemma builder_push_wires_new {width : ℕ} (B : Builder width) (g : Gate)\n    (hgRB : ∀ i ∈ g.inputs, i < width + B.gates.length) (hgFan : g.inputs.length ≤ 2)\n    (x : List Bool) (hx : x.length = width) :\n    ((B.push g hgRB hgFan).1.wires x).getD (B.push g hgRB hgFan).2 false =\n      g.op.eval (g.inputs.map fun i => (B.wires x).getD i false) := by\n  simp only [Builder.push, Builder.wires, List.foldl_append, List.foldl_cons, List.foldl_nil, wiresStep]\n  have hlen : (B.gates.foldl wiresStep x).length = width + B.gates.length := by\n    rw [wires_fold_length, hx]\n  rw [← hlen, getD_concat_last]\n\nlemma builder_push_depths_old {width : ℕ} (B : Builder width) (g : Gate)\n    (hgRB : ∀ i ∈ g.inputs, i < width + B.gates.length) (hgFan : g.inputs.length ≤ 2)\n    (w : ℕ) (hw : w < width + B.gates.length) :\n    ((B.push g hgRB hgFan).1.depths).getD w 0 = (B.depths).getD w 0 := by\n  simp only [Builder.push, Builder.depths, List.foldl_append, List.foldl_cons, List.foldl_nil, depthsStep]\n  rw [getD_append_left]\n  rw [depths_fold_length, List.length_replicate]\n  exact hw\n\nlemma builder_push_depths_new {width : ℕ} (B : Builder width) (g : Gate)\n    (hgRB : ∀ i ∈ g.inputs, i < width + B.gates.length) (hgFan : g.inputs.length ≤ 2) :\n    ((B.push g hgRB hgFan).1.depths).getD (B.push g hgRB hgFan).2 0 =\n      (g.inputs.map fun i => (B.depths).getD i 0).foldr max 0 + (nonlinear g).toNat := by\n  simp only [Builder.push, Builder.depths, List.foldl_append, List.foldl_cons, List.foldl_nil, depthsStep]\n  have hlen : (B.gates.foldl depthsStep (List.replicate width 0)).length = width + B.gates.length := by\n    rw [depths_fold_length, List.length_replicate]\n  rw [← hlen, getD_concat_last]\n\nlemma builder_push_nlCount {width : ℕ} (B : Builder width) (g : Gate)\n    (hgRB : ∀ i ∈ g.inputs, i < width + B.gates.length) (hgFan : g.inputs.length ≤ 2) :\n    (B.push g hgRB hgFan).1.nlCount = B.nlCount + (nonlinear g).toNat := by\n  simp only [Builder.push, Builder.nlCount, List.countP_append, List.countP_singleton]\n  cases nonlinear g <;> simp\n\nlemma builder_push_len {width : ℕ} (B : Builder width) (g : Gate)\n    (hgRB : ∀ i ∈ g.inputs, i < width + B.gates.length) (hgFan : g.inputs.length ≤ 2) :\n    (B.push g hgRB hgFan).1.gates.length = B.gates.length + 1 := by\n  simp [Builder.push]\n\nlemma nonlinear_or_nil : nonlinear ⟨GateOp.or, []⟩ = false := rfl\nlemma nonlinear_not (w : ℕ) : nonlinear ⟨GateOp.not, [w]⟩ = false := rfl\nlemma nonlinear_mod2 (a b : ℕ) : nonlinear ⟨GateOp.mod 2, [a, b]⟩ = false := rfl\nlemma nonlinear_and (a b : ℕ) : nonlinear ⟨GateOp.and, [a, b]⟩ = true := rfl\n\nlemma eval_mod2_not (a b : Bool) :\n    (!(GateOp.eval (GateOp.mod 2) [a, b])) = xor a b := by\n  cases a <;> cases b <;> decide\n\ndef Builder.pushXor {width : ℕ} (B : Builder width) (a b : ℕ)\n    (ha : a < width + B.gates.length) (hb : b < width + B.gates.length) :\n    Builder width × ℕ :=\n  let p1 := B.push ⟨GateOp.mod 2, [a, b]⟩\n    (by intro i hi; simp only [List.mem_cons, List.not_mem_nil, or_false] at hi; rcases hi with rfl | rfl <;> assumption)\n    (by simp)\n  let p2 := p1.1.push ⟨GateOp.not, [p1.2]⟩\n    (by intro i hi; simp only [List.mem_singleton] at hi; subst hi; simp [p1, Builder.push])\n    (by simp)\n  p2\n\nlemma pushXor_len {width : ℕ} (B : Builder width) (a b : ℕ)\n    (ha : a < width + B.gates.length) (hb : b < width + B.gates.length) :\n    (B.pushXor a b ha hb).1.gates.length = B.gates.length + 2 := by\n  simp [Builder.pushXor, Builder.push]\n\nlemma pushXor_out_lt {width : ℕ} (B : Builder width) (a b : ℕ)\n    (ha : a < width + B.gates.length) (hb : b < width + B.gates.length) :\n    (B.pushXor a b ha hb).2 < width + (B.pushXor a b ha hb).1.gates.length := by\n  simp [Builder.pushXor, Builder.push]\n\nlemma pushXor_nlCount {width : ℕ} (B : Builder width) (a b : ℕ)\n    (ha : a < width + B.gates.length) (hb : b < width + B.gates.length) :\n    (B.pushXor a b ha hb).1.nlCount = B.nlCount := by\n  simp only [Builder.pushXor, builder_push_nlCount, nonlinear_mod2, nonlinear_not]\n  rfl\n\nlemma pushXor_wires_old {width : ℕ} (B : Builder width) (a b : ℕ)\n    (ha : a < width + B.gates.length) (hb : b < width + B.gates.length)\n    (x : List Bool) (hx : x.length = width) (w : ℕ) (hw : w < width + B.gates.length) :\n    ((B.pushXor a b ha hb).1.wires x).getD w false = (B.wires x).getD w false := by\n  simp only [Builder.pushXor]\n  rw [builder_push_wires_old _ _ _ _ x hx w (by simp [Builder.push]; omega)]\n  rw [builder_push_wires_old _ _ _ _ x hx w hw]\n\nlemma pushXor_wires_new {width : ℕ} (B : Builder width) (a b : ℕ)\n    (ha : a < width + B.gates.length) (hb : b < width + B.gates.length)\n    (x : List Bool) (hx : x.length = width) :\n    ((B.pushXor a b ha hb).1.wires x).getD (B.pushXor a b ha hb).2 false =\n      xor ((B.wires x).getD a false) ((B.wires x).getD b false) := by\n  simp only [Builder.pushXor]\n  rw [builder_push_wires_new _ _ _ _ x hx]\n  simp only [List.map_cons, List.map_nil]\n  rw [builder_push_wires_new _ _ _ _ x hx]\n  simp only [List.map_cons, List.map_nil]\n  have hnot : GateOp.eval GateOp.not [(GateOp.mod 2).eval [(B.wires x).getD a false, (B.wires x).getD b false]] =\n      !((GateOp.mod 2).eval [(B.wires x).getD a false, (B.wires x).getD b false]) := rfl\n  rw [hnot]\n  exact eval_mod2_not _ _\n\nlemma pushXor_depths_old {width : ℕ} (B : Builder width) (a b : ℕ)\n    (ha : a < width + B.gates.length) (hb : b < width + B.gates.length)\n    (w : ℕ) (hw : w < width + B.gates.length) :\n    ((B.pushXor a b ha hb).1.depths).getD w 0 = (B.depths).getD w 0 := by\n  simp only [Builder.pushXor]\n  rw [builder_push_depths_old _ _ _ _ w (by simp [Builder.push]; omega)]\n  rw [builder_push_depths_old _ _ _ _ w hw]\n\nlemma pushXor_depths_new {width : ℕ} (B : Builder width) (a b : ℕ)\n    (ha : a < width + B.gates.length) (hb : b < width + B.gates.length) :\n    ((B.pushXor a b ha hb).1.depths).getD (B.pushXor a b ha hb).2 0 =\n      max ((B.depths).getD a 0) ((B.depths).getD b 0) := by\n  simp only [Builder.pushXor]\n  rw [builder_push_depths_new]\n  simp only [List.map_cons, List.map_nil, List.foldr_cons, List.foldr_nil, nonlinear_not, Bool.toNat_false, add_zero]\n  rw [builder_push_depths_new]\n  simp only [List.map_cons, List.map_nil, List.foldr_cons, List.foldr_nil, nonlinear_mod2, Bool.toNat_false, add_zero]\n  omega\n\ndef Builder.foldXor {width : ℕ} (B : Builder width) (acc : ℕ) (hacc : acc < width + B.gates.length)\n    (ws : List ℕ) (hws : ∀ w ∈ ws, w < width + B.gates.length) : Builder width × ℕ :=\n  match ws with\n  | [] => (B, acc)\n  | w :: rest =>\n    let p := B.pushXor acc w hacc (hws w (by simp))\n    have hlen : B.gates.length ≤ p.1.gates.length := by rw [pushXor_len]; omega\n    p.1.foldXor p.2 (pushXor_out_lt B acc w hacc _) rest\n      (fun u hu => lt_of_lt_of_le (hws u (by simp [hu])) (Nat.add_le_add_left hlen width))\n\nlemma foldXor_spec {width : ℕ} (B : Builder width) (acc : ℕ) (hacc : acc < width + B.gates.length)\n    (ws : List ℕ) (hws : ∀ w ∈ ws, w < width + B.gates.length) (D : ℕ)\n    (hdAcc : (B.depths).getD acc 0 ≤ D) (hdWs : ∀ w ∈ ws, (B.depths).getD w 0 ≤ D) :\n    let res := B.foldXor acc hacc ws hws\n    B.gates.length ≤ res.1.gates.length ∧\n    res.2 < width + res.1.gates.length ∧\n    res.1.nlCount = B.nlCount ∧\n    (res.1.depths).getD res.2 0 ≤ D ∧\n    (∀ w < width + B.gates.length, (res.1.depths).getD w 0 = (B.depths).getD w 0) ∧\n    (∀ (x : List Bool), x.length = width →\n      (∀ w < width + B.gates.length, (res.1.wires x).getD w false = (B.wires x).getD w false) ∧\n      (res.1.wires x).getD res.2 false =\n        ws.foldl (fun b w => xor b ((B.wires x).getD w false)) ((B.wires x).getD acc false)) := by\n  induction ws generalizing B acc with\n  | nil =>\n    refine ⟨le_refl _, hacc, rfl, hdAcc, fun _ _ => rfl, fun x _ => ⟨fun _ _ => rfl, rfl⟩⟩\n  | cons w rest ih =>\n    simp only [Builder.foldXor]\n    set p := B.pushXor acc w hacc (hws w (by simp))\n    have hlen1 : B.gates.length ≤ p.1.gates.length := by rw [pushXor_len]; omega\n    have hdP : (p.1.depths).getD p.2 0 ≤ D := by\n      rw [pushXor_depths_new]\n      exact max_le hdAcc (hdWs w (by simp))\n    have hdRest : ∀ u ∈ rest, (p.1.depths).getD u 0 ≤ D := by\n      intro u hu\n      rw [pushXor_depths_old B acc w _ _ u (hws u (by simp [hu]))]\n      exact hdWs u (by simp [hu])\n    have hih := ih p.1 p.2 (pushXor_out_lt B acc w _ _)\n      (fun u hu => lt_of_lt_of_le (hws u (by simp [hu])) (Nat.add_le_add_left hlen1 width))\n      hdP hdRest\n    rcases hih with ⟨hlen2, hout, hnl, hdOut, hdOld, hW⟩\n    refine ⟨le_trans hlen1 hlen2, hout, by rw [hnl, pushXor_nlCount], hdOut, ?_, ?_⟩\n    · intro u hu\n      rw [hdOld u (by omega), pushXor_depths_old B acc w _ _ u hu]\n    · intro x hx\n      obtain ⟨hwOld, hwNew⟩ := hW x hx\n      refine ⟨fun u hu => by rw [hwOld u (by omega), pushXor_wires_old B acc w _ _ x hx u hu], ?_⟩\n      rw [hwNew, List.foldl_cons, pushXor_wires_new B acc w _ _ x hx]\n      have hcongr : ∀ (b0 : Bool) (l : List ℕ), (∀ u ∈ l, u < width + B.gates.length) →\n          l.foldl (fun b u => xor b ((p.1.wires x).getD u false)) b0 =\n          l.foldl (fun b u => xor b ((B.wires x).getD u false)) b0 := by\n        intro b0 l hl\n        induction l generalizing b0 with\n        | nil => rfl\n        | cons u us ih2 =>\n          simp only [List.foldl_cons]\n          rw [pushXor_wires_old B acc w _ _ x hx u (hl u (by simp))]\n          exact ih2 _ (fun v hv => hl v (by simp [hv]))\n      exact hcongr _ rest (fun u hu => hws u (by simp [hu]))\n\ndef Builder.pushXorList {width : ℕ} (B : Builder width) (ws : List ℕ)\n    (hws : ∀ w ∈ ws, w < width + B.gates.length) : Builder width × ℕ :=\n  let p0 := B.push ⟨GateOp.or, []⟩ (by intro _ h; simp at h) (by simp)\n  have hlen : B.gates.length ≤ p0.1.gates.length := by rw [builder_push_len]; omega\n  p0.1.foldXor p0.2 (by simp [p0, Builder.push]) ws\n    (fun u hu => lt_of_lt_of_le (hws u hu) (Nat.add_le_add_left hlen width))\n\nlemma b2f_foldl_xor {α : Type} (l : List α) (f : α → Bool) (b0 : Bool) :\n    b2f (l.foldl (fun b a => xor b (f a)) b0) = b2f b0 + (l.map fun a => b2f (f a)).sum := by\n  induction l generalizing b0 with\n  | nil => simp\n  | cons a rest ih =>\n    simp only [List.foldl_cons, List.map_cons, List.sum_cons, ih, b2f_xor, add_assoc]\n\nlemma pushXorList_spec {width : ℕ} (B : Builder width) (ws : List ℕ)\n    (hws : ∀ w ∈ ws, w < width + B.gates.length) (D : ℕ)\n    (hdWs : ∀ w ∈ ws, (B.depths).getD w 0 ≤ D) :\n    let res := B.pushXorList ws hws\n    B.gates.length ≤ res.1.gates.length ∧\n    res.2 < width + res.1.gates.length ∧\n    res.1.nlCount = B.nlCount ∧\n    (res.1.depths).getD res.2 0 ≤ D ∧\n    (∀ w < width + B.gates.length, (res.1.depths).getD w 0 = (B.depths).getD w 0) ∧\n    (∀ (x : List Bool), x.length = width →\n      (∀ w < width + B.gates.length, (res.1.wires x).getD w false = (B.wires x).getD w false) ∧\n      b2f ((res.1.wires x).getD res.2 false) = (ws.map fun w => b2f ((B.wires x).getD w false)).sum) := by\n  simp only [Builder.pushXorList]\n  set p0 := B.push ⟨GateOp.or, []⟩ (by intro _ h; simp at h) (by simp)\n  have hlen0 : B.gates.length ≤ p0.1.gates.length := by rw [builder_push_len]; omega\n  have hd0 : (p0.1.depths).getD p0.2 0 ≤ D := by\n    rw [builder_push_depths_new]\n    simp [nonlinear_or_nil]\n  have hdWs' : ∀ w ∈ ws, (p0.1.depths).getD w 0 ≤ D := by\n    intro w hw\n    rw [builder_push_depths_old B _ _ _ w (hws w hw)]\n    exact hdWs w hw\n  have hspec := foldXor_spec p0.1 p0.2 (by simp [p0, Builder.push]) ws\n    (fun u hu => lt_of_lt_of_le (hws u hu) (Nat.add_le_add_left hlen0 width)) D hd0 hdWs'\n  rcases hspec with ⟨hlen1, hout, hnl, hdOut, hdOld, hW⟩\n  refine ⟨le_trans hlen0 hlen1, hout, ?_, hdOut, ?_, ?_⟩\n  · rw [hnl, builder_push_nlCount, nonlinear_or_nil]; rfl\n  · intro w hw\n    rw [hdOld w (by omega), builder_push_depths_old B _ _ _ w hw]\n  · intro x hx\n    obtain ⟨hwOld, hwNew⟩ := hW x hx\n    refine ⟨fun w hw => by rw [hwOld w (by omega), builder_push_wires_old B _ _ _ x hx w hw], ?_⟩\n    rw [hwNew, b2f_foldl_xor, builder_push_wires_new B _ _ _ x hx]\n    simp only [List.map_nil, GateOp.eval, List.any_nil, b2f, Bool.false_eq_true, ↓reduceIte, zero_add]\n    congr 1\n    apply List.map_congr_left\n    intro w hw\n    rw [builder_push_wires_old B _ _ _ x hx w (hws w hw)]\n\nprivate def DepthBound {width : ℕ} (B : Builder width) (d : ℕ) : Prop :=\n  ∀ x ∈ B.depths, x ≤ d\n\nprivate theorem depthBound_input {w D : ℕ} (B : Builder w) (h : DepthBound B D) (i : ℕ) :\n    B.depths.getD i 0 ≤ D := by\n  by_cases hi : i < B.depths.length\n  · rw [List.getD_eq_getElem?_getD, List.getElem?_eq_getElem hi, Option.getD_some]\n    exact h _ (List.getElem_mem hi)\n  · rw [List.getD_eq_default _ _ (by omega)]\n    exact Nat.zero_le _\n\nprivate theorem pushDepthBound {w D T : ℕ} (B : Builder w) (g : Gate)\n    (hRB : ∀ i ∈ g.inputs, i < w + B.gates.length) (hFan : g.inputs.length ≤ 2)\n    (hB : DepthBound B D)\n    (hin : ∀ i ∈ g.inputs, B.depths.getD i 0 ≤ T)\n    (hout : T + (nonlinear g).toNat ≤ D) :\n    DepthBound (B.push g hRB hFan).1 D := by\n  intro d hd\n  simp only [Builder.push, Builder.depths, List.foldl_append, List.foldl_cons,\n    List.foldl_nil, depthsStep, List.mem_append, List.mem_singleton] at hd\n  rcases hd with old | rfl\n  · exact hB d old\n  · have hmax : (g.inputs.map fun i => B.depths.getD i 0).foldr max 0 ≤ T := by\n      apply (foldr_max_le_iff _ _).mpr\n      intro a ha\n      obtain ⟨i,hi,rfl⟩ := List.mem_map.mp ha\n      exact hin i hi\n    exact (Nat.add_le_add_right hmax _).trans hout\n\nprivate theorem pushAffineBound {w D : ℕ} (B : Builder w) (g : Gate)\n    (hRB : ∀ i ∈ g.inputs, i < w + B.gates.length) (hFan : g.inputs.length ≤ 2)\n    (hlin : nonlinear g = false) (hB : DepthBound B D) :\n    DepthBound (B.push g hRB hFan).1 D :=\n  pushDepthBound B g hRB hFan hB (fun i _ => depthBound_input B hB i) (by simp [hlin])\n\nprivate theorem pushXorBound {w D : ℕ} (B : Builder w) (a b : ℕ)\n    (ha : a < w+B.gates.length) (hb : b < w+B.gates.length) (hB : DepthBound B D) :\n    DepthBound (B.pushXor a b ha hb).1 D := by\n  unfold Builder.pushXor\n  apply pushAffineBound _ _ _ _ (nonlinear_not _)\n  exact pushAffineBound _ _ _ _ (nonlinear_mod2 _ _) hB\n\nprivate theorem foldXorBound {w D : ℕ} (B : Builder w) (a : ℕ)\n    (ha : a < w+B.gates.length) (ws : List ℕ)\n    (hws : ∀ i ∈ ws, i < w+B.gates.length) (hB : DepthBound B D) :\n    DepthBound (B.foldXor a ha ws hws).1 D := by\n  induction ws generalizing B a with\n  | nil => exact hB\n  | cons b rest ih =>\n    simp only [Builder.foldXor]\n    apply ih\n    exact pushXorBound _ _ _ _ _ hB\n\nprivate theorem pushXorListBound {w D : ℕ} (B : Builder w) (ws : List ℕ)\n    (hws : ∀ i ∈ ws, i < w+B.gates.length) (hB : DepthBound B D) :\n    DepthBound (B.pushXorList ws hws).1 D := by\n  unfold Builder.pushXorList\n  apply foldXorBound\n  exact pushAffineBound _ _ _ _ nonlinear_or_nil hB\n\ndef pushManyXor {width : ℕ} (B : Builder width) (n : ℕ)\n    (ws : Fin n → List ℕ) (hws : ∀ i w, w ∈ ws i → w < width + B.gates.length) :\n    { p : Builder width × (Fin n → ℕ) //\n      B.gates.length ≤ p.1.gates.length ∧\n      (∀ i, p.2 i < width + p.1.gates.length) ∧\n      p.1.nlCount = B.nlCount ∧\n      (∀ D, (∀ i w, w ∈ ws i → (B.depths).getD w 0 ≤ D) → ∀ i, (p.1.depths).getD (p.2 i) 0 ≤ D) ∧\n      (∀ w < width + B.gates.length, (p.1.depths).getD w 0 = (B.depths).getD w 0) ∧\n      (∀ x : List Bool, x.length = width →\n        (∀ w < width + B.gates.length, (p.1.wires x).getD w false = (B.wires x).getD w false) ∧\n        ∀ i, b2f ((p.1.wires x).getD (p.2 i) false) = (ws i |>.map fun w => b2f ((B.wires x).getD w false)).sum) ∧\n      (∀ D, DepthBound B D → DepthBound p.1 D) } := by\n  induction n generalizing B with\n  | zero =>\n    exact ⟨(B, Fin.elim0), le_refl _, fun i => i.elim0, rfl, fun _ _ i => i.elim0,\n      fun _ _ => rfl, ⟨fun _ _ => ⟨fun _ _ => rfl, fun i => i.elim0⟩, fun _ h => h⟩⟩\n  | succ n ih =>\n    let p1 := B.pushXorList (ws 0) (hws 0)\n    have hbase := pushXorList_spec B (ws 0) (hws 0) (B.depths.foldr max 0) (fun w _ => getD_le_foldr_max B.depths w)\n    have hlen1 : B.gates.length ≤ p1.1.gates.length := hbase.1\n    let ws' : Fin n → List ℕ := fun i => ws i.succ\n    have hws' : ∀ i w, w ∈ ws' i → w < width + p1.1.gates.length := fun i w hw =>\n      lt_of_lt_of_le (hws i.succ w hw) (Nat.add_le_add_left hlen1 width)\n    let r2 := ih p1.1 ws' hws'\n    refine ⟨(r2.val.1, Fin.cons p1.2 r2.val.2), ?_, ?_, ?_, ?_, ?_, ?_⟩\n    · exact le_trans hlen1 r2.property.1\n    · intro i\n      refine Fin.cases ?_ ?_ i\n      · simp only [Fin.cons_zero]\n        have h1 : p1.2 < width + p1.1.gates.length := hbase.2.1\n        have h2 : p1.1.gates.length ≤ r2.val.1.gates.length := r2.property.1\n        omega\n      · intro j; simp only [Fin.cons_succ]; exact r2.property.2.1 j\n    · rw [r2.property.2.2.1, hbase.2.2.1]\n    · intro D hD i\n      have hs1 := pushXorList_spec B (ws 0) (hws 0) D (hD 0)\n      refine Fin.cases ?_ ?_ i\n      · simp only [Fin.cons_zero]\n        rw [r2.property.2.2.2.2.1 p1.2 hs1.2.1]\n        exact hs1.2.2.2.1\n      · intro j\n        simp only [Fin.cons_succ]\n        refine r2.property.2.2.2.1 D ?_ j\n        intro k w hw\n        rw [hs1.2.2.2.2.1 w (hws k.succ w hw)]\n        exact hD k.succ w hw\n    · intro w hw\n      rw [r2.property.2.2.2.2.1 w (by omega), hbase.2.2.2.2.1 w hw]\n    · constructor\n      · intro x hx\n        obtain ⟨hwOld1, hwNew1⟩ := hbase.2.2.2.2.2 x hx\n        obtain ⟨hwOld2, hwNew2⟩ := r2.property.2.2.2.2.2.1 x hx\n        refine ⟨fun w hw => by rw [hwOld2 w (by omega), hwOld1 w hw], fun i => ?_⟩\n        refine Fin.cases ?_ ?_ i\n        · simp only [Fin.cons_zero]\n          rw [hwOld2 p1.2 hbase.2.1, hwNew1]\n        · intro j\n          simp only [Fin.cons_succ]\n          rw [hwNew2 j]\n          congr 1\n          apply List.map_congr_left\n          intro w hw\n          rw [hwOld1 w (hws j.succ w hw)]\n      · intro D hD\n        exact r2.property.2.2.2.2.2.2 D (pushXorListBound B (ws 0) (hws 0) hD)\n\ndef pushManyAnd {width : ℕ} (B : Builder width) (n : ℕ)\n    (a b : Fin n → ℕ) (ha : ∀ i, a i < width + B.gates.length) (hb : ∀ i, b i < width + B.gates.length) :\n    { p : Builder width × (Fin n → ℕ) //\n      B.gates.length ≤ p.1.gates.length ∧\n      (∀ i, p.2 i < width + p.1.gates.length) ∧\n      p.1.nlCount = B.nlCount + n ∧\n      (∀ D, (∀ i, (B.depths).getD (a i) 0 ≤ D) → (∀ i, (B.depths).getD (b i) 0 ≤ D) →\n        ∀ i, (p.1.depths).getD (p.2 i) 0 ≤ D + 1) ∧\n      (∀ w < width + B.gates.length, (p.1.depths).getD w 0 = (B.depths).getD w 0) ∧\n      (∀ x : List Bool, x.length = width →\n        (∀ w < width + B.gates.length, (p.1.wires x).getD w false = (B.wires x).getD w false) ∧\n        ∀ i, b2f ((p.1.wires x).getD (p.2 i) false) =\n          b2f ((B.wires x).getD (a i) false) * b2f ((B.wires x).getD (b i) false)) ∧\n      (∀ D, DepthBound B (D+1) → (∀ i, B.depths.getD (a i) 0 ≤ D) →\n        (∀ i, B.depths.getD (b i) 0 ≤ D) → DepthBound p.1 (D+1)) } := by\n  induction n generalizing B with\n  | zero =>\n    exact ⟨(B, Fin.elim0), le_refl _, fun i => i.elim0, by simp, fun _ _ _ i => i.elim0,\n      fun _ _ => rfl, ⟨fun _ _ => ⟨fun _ _ => rfl, fun i => i.elim0⟩, fun _ h _ _ => h⟩⟩\n  | succ n ih =>\n    let p1 := B.push ⟨GateOp.and, [a 0, b 0]⟩ (by\n      intro i hi\n      simp only [List.mem_cons, List.not_mem_nil, or_false] at hi\n      rcases hi with rfl | rfl\n      · exact ha 0\n      · exact hb 0) (by simp)\n    have hlen1 : B.gates.length ≤ p1.1.gates.length := by rw [builder_push_len]; omega\n    have hout1 : p1.2 < width + p1.1.gates.length := by simp [p1, Builder.push]\n    let r2 := ih p1.1 (fun i => a i.succ) (fun i => b i.succ)\n      (fun i => lt_of_lt_of_le (ha i.succ) (Nat.add_le_add_left hlen1 width))\n      (fun i => lt_of_lt_of_le (hb i.succ) (Nat.add_le_add_left hlen1 width))\n    refine ⟨(r2.val.1, Fin.cons p1.2 r2.val.2), ?_, ?_, ?_, ?_, ?_, ?_⟩\n    · exact le_trans hlen1 r2.property.1\n    · intro i\n      refine Fin.cases ?_ ?_ i\n      · simp only [Fin.cons_zero]\n        have := r2.property.1\n        omega\n      · intro j; simp only [Fin.cons_succ]; exact r2.property.2.1 j\n    · rw [r2.property.2.2.1, builder_push_nlCount, nonlinear_and]\n      simp only [Bool.toNat_true]\n      omega\n    · intro D hDa hDb i\n      refine Fin.cases ?_ ?_ i\n      · simp only [Fin.cons_zero]\n        rw [r2.property.2.2.2.2.1 p1.2 hout1, builder_push_depths_new]\n        simp only [List.map_cons, List.map_nil, List.foldr_cons, List.foldr_nil, nonlinear_and, Bool.toNat_true]\n        have := hDa 0\n        have := hDb 0\n        omega\n      · intro j\n        simp only [Fin.cons_succ]\n        refine r2.property.2.2.2.1 D ?_ ?_ j\n        · intro k; rw [builder_push_depths_old B _ _ _ _ (ha k.succ)]; exact hDa k.succ\n        · intro k; rw [builder_push_depths_old B _ _ _ _ (hb k.succ)]; exact hDb k.succ\n    · intro w hw\n      rw [r2.property.2.2.2.2.1 w (by omega), builder_push_depths_old B _ _ _ w hw]\n    · constructor\n      · intro x hx\n        obtain ⟨hwOld2, hwNew2⟩ := r2.property.2.2.2.2.2.1 x hx\n        refine ⟨fun w hw => by rw [hwOld2 w (by omega), builder_push_wires_old B _ _ _ x hx w hw], fun i => ?_⟩\n        refine Fin.cases ?_ ?_ i\n        · simp only [Fin.cons_zero]\n          rw [hwOld2 p1.2 hout1, builder_push_wires_new B _ _ _ x hx]\n          simp only [List.map_cons, List.map_nil, GateOp.eval, List.all_cons, List.all_nil, id_eq, Bool.and_true]\n          exact b2f_and _ _\n        · intro j\n          simp only [Fin.cons_succ]\n          rw [hwNew2 j, builder_push_wires_old B _ _ _ x hx _ (ha j.succ),\n            builder_push_wires_old B _ _ _ x hx _ (hb j.succ)]\n      · intro D hD hDa hDb\n        apply r2.property.2.2.2.2.2.2 D\n        · apply pushDepthBound (T := D) B _ _ _ hD\n          · intro i hi\n            simp only [List.mem_cons, List.not_mem_nil, or_false] at hi\n            rcases hi with rfl | rfl\n            · exact hDa 0\n            · exact hDb 0\n          · simp [nonlinear_and]\n        · intro i\n          rw [builder_push_depths_old B _ _ _ _ (ha i.succ)]\n          exact hDa i.succ\n        · intro i\n          rw [builder_push_depths_old B _ _ _ _ (hb i.succ)]\n          exact hDb i.succ\n\nlemma list_sum_finRange_eq {n : ℕ} (f : Fin n → ZMod 2) :\n    ((List.finRange n).map f).sum = ∑ i : Fin n, f i := by\n  induction n with\n  | zero => simp\n  | succ n ih =>\n    rw [List.finRange_succ, List.map_cons, List.sum_cons, List.map_map, Fin.sum_univ_succ]\n    exact congrArg (f 0 + ·) (ih (fun i => f i.succ))\n\nlemma list_sum_filter_finRange {n : ℕ} (p : Fin n → Bool) (f : Fin n → ZMod 2) :\n    (((List.finRange n).filter p).map f).sum = ∑ i : Fin n, if p i then f i else 0 := by\n  rw [← list_sum_finRange_eq]\n  have : ∀ (l : List (Fin n)), ((l.filter p).map f).sum = (l.map fun i => if p i then f i else 0).sum := by\n    intro l\n    induction l with\n    | nil => simp\n    | cons a rest ih =>\n      simp only [List.filter_cons, List.map_cons, List.sum_cons]\n      cases hp : p a <;> simp [ih]\n  exact this (List.finRange n)\n\nprivate theorem compileStage (w p : ℕ) (left right : Fin p → List ℕ)\n    (hl : ∀ i a, a ∈ left i → a < w) (hr : ∀ i a, a ∈ right i → a < w) :\n    ∃ (B : Builder w) (port : Fin p → ℕ), B.nlCount = p ∧ DepthBound B 1 ∧\n      (∀ i, port i < w + B.gates.length) ∧\n      ∀ xs : List Bool, xs.length = w →\n        (∀ a < w, (B.wires xs).getD a false = xs.getD a false) ∧\n        ∀ i, b2f ((B.wires xs).getD (port i) false) =\n          ((left i).map fun a => b2f (xs.getD a false)).sum *\n          ((right i).map fun a => b2f (xs.getD a false)).sum := by\n  let B0 := Builder.empty w\n  let A := pushManyXor B0 p left (fun i a ha => by simpa [B0, Builder.empty] using hl i a ha)\n  let B := pushManyXor A.val.1 p right (fun i a ha => by have := hr i a ha; omega)\n  let X := pushManyAnd B.val.1 p A.val.2 B.val.2\n    (fun i => by\n      have ha := A.property.2.1 i\n      have hb := B.property.1\n      omega)\n    B.property.2.1\n  have hb0 : DepthBound B0 0 := by\n    intro d hd\n    simp [B0, Builder.empty, Builder.depths] at hd\n    omega\n  have haD := A.property.2.2.2.2.2.2 0 hb0\n  have hbD := B.property.2.2.2.2.2.2 0 haD\n  have hxD : DepthBound X.val.1 1 := by\n    refine X.property.2.2.2.2.2.2 0 ?_\n      (fun i => depthBound_input B.val.1 hbD (A.val.2 i))\n      (fun i => depthBound_input B.val.1 hbD (B.val.2 i))\n    exact fun d hd => (hbD d hd).trans (by decide)\n  refine ⟨X.val.1, X.val.2, ?_, hxD, X.property.2.1, ?_⟩\n  · rw [X.property.2.2.1, B.property.2.2.1, A.property.2.2.1]\n    simp [B0, Builder.empty, Builder.nlCount]\n  · intro xs hxs\n    obtain ⟨haOld,haNew⟩ := A.property.2.2.2.2.2.1 xs hxs\n    obtain ⟨hbOld,hbNew⟩ := B.property.2.2.2.2.2.1 xs hxs\n    obtain ⟨hxOld,hxNew⟩ := X.property.2.2.2.2.2.1 xs hxs\n    refine ⟨fun a ha => ?_, fun i => ?_⟩\n    · rw [hxOld a (by omega), hbOld a (by omega), haOld a (by omega)]\n      rfl\n    · rw [hxNew i, hbOld _ (A.property.2.1 i), haNew i, hbNew i]\n      congr 1\n      apply congrArg List.sum\n      apply List.map_congr_left\n      intro a ha\n      rw [haOld a (by have := hr i a ha; omega)]\n      rfl\n\nprivate def oneBank {n m : ℕ} (a : Fin n → Field) (b : Fin m → Field) : List ℕ :=\n  ((List.finRange n).filter (fun i => decide (a i = 1))).map Fin.val ++\n    ((List.finRange m).filter (fun i => decide (b i = 1))).map (fun i => n+i.val)\n\nprivate theorem oneBank_bound {n m : ℕ} (a : Fin n → Field) (b : Fin m → Field) :\n    ∀ i ∈ oneBank a b, i < n+m := by\n  intro i hi\n  rw [oneBank, List.mem_append] at hi\n  obtain hi | hi := hi\n  · obtain ⟨a,_,rfl⟩ := List.mem_map.mp hi\n    have := a.isLt\n    omega\n  · obtain ⟨b,_,rfl⟩ := List.mem_map.mp hi\n    have := b.isLt\n    omega\n\nprivate theorem oneBank_sum {n m : ℕ} (a : Fin n → Field) (b : Fin m → Field)\n    (x : Fin n) (y : Fin m) (inp : List Bool)\n    (h : ∀ i < n+m, inp.getD i false = (oneEach x y).getD i false) :\n    ((oneBank a b).map (fun i => b2f (inp.getD i false))).sum = a x + b y := by\n  classical\n  simp only [oneBank, List.map_append, List.sum_append, List.map_map, Function.comp_def,\n    list_sum_filter_finRange]\n  congr 1\n  · have hx (i : Fin n) : inp.getD i.val false = decide (i=x) := by\n      rw [h _ (by have := i.isLt; omega), oneEach_getD_left x y _ i.isLt]\n    simp only [hx]\n    rw [Finset.sum_eq_single x]\n    · rcases f2_cases (a x) with hz | ho\n      · simp [hz, b2f]\n      · simp [ho, b2f]\n    · intro j _ hj; simp [hj, b2f]\n    · simp\n  · have hy (i : Fin m) : inp.getD (n+i.val) false = decide (i=y) := by\n      rw [h _ (by have := i.isLt; omega), oneEach_getD_right x y _ i.isLt]\n    simp only [hy]\n    rw [Finset.sum_eq_single y]\n    · rcases f2_cases (b y) with hz | ho\n      · simp [hz, b2f]\n      · simp [ho, b2f]\n    · intro j _ hj; simp [hj, b2f]\n    · simp\n\nprivate def selected {n : ℕ} (ix : Fin n → ℕ) (coeff : Fin n → Field) : List ℕ :=\n  ((List.finRange n).filter (fun i => decide (coeff i = 1))).map ix\n\nprivate theorem selected_bound {n w : ℕ} (ix : Fin n → ℕ) (coeff : Fin n → Field)\n    (h : ∀ i, ix i < w) : ∀ j ∈ selected ix coeff, j < w := by\n  intro j hj\n  obtain ⟨i,_,rfl⟩ := List.mem_map.mp hj\n  exact h i\n\nprivate theorem selected_sum {n : ℕ} (ix : Fin n → ℕ) (coeff : Fin n → Field)\n    (inp : List Bool) :\n    ((selected ix coeff).map (fun j => b2f (inp.getD j false))).sum =\n      ∑ i : Fin n, coeff i * b2f (inp.getD (ix i) false) := by\n  classical\n  simp only [selected, List.map_map, Function.comp_def, list_sum_filter_finRange]\n  apply Finset.sum_congr rfl\n  intro i _\n  rcases f2_cases (coeff i) with h0 | h1\n  · simp [h0]\n  · simp [h1]\n\nprivate def Fits (n m s k : ℕ) (G : Fin n → Fin m → Bool) : Prop :=\n  ∃ (C : Circuit) (cut : ℕ), cut ≤ C.gates.length ∧\n    ReadsBack (n+m) C ∧\n    (∀ g ∈ C.gates, g.inputs.length ≤ 2) ∧\n    (C.gates.take cut).countP nonlinear ≤ s ∧ (C.gates.drop cut).countP nonlinear ≤ k ∧\n    (∀ d ∈ depths (n+m) ⟨C.gates.take cut,0⟩, d ≤ 1) ∧\n    (∀ d ∈ depths (n+m+cut) ⟨C.gates.drop cut,0⟩, d ≤ 1) ∧ Represents G C\n\nprivate theorem bitOfField (a : Field) : b2f (decide (a = 1)) = a := by\n  rcases f2_cases a with rfl | rfl <;> decide\n\nprivate theorem buildPolynomial (n m s k : ℕ)\n    (pa pa' : Fin s → Fin n → Field) (pb pb' : Fin s → Fin m → Field)\n    (Aout : Fin n → Field) (Bout : Fin m → Field) (cout : Fin s → Field)\n    (U U' : Fin k → Fin n → Field) (V V' : Fin k → Fin m → Field)\n    (mu nu : Fin k → Fin s → Field) :\n    let P := fun i x y => pa i x * pb' i y + pa' i x * pb i y\n    let M := fun x y => Aout x + Bout y + (∑ i : Fin s, cout i * P i x y) +\n      ∑ j : Fin k,\n        (U j x + V j y + ∑ i : Fin s, mu j i * P i x y) *\n        (U' j x + V' j y + ∑ i : Fin s, nu j i * P i x y)\n    Fits n m s k (fun x y => decide (M x y = 1)) := by\n  classical\n  intro P M\n  let w := n+m\n  let low := fun i : Fin s => oneBank (pa i) (pb i)\n  let high := fun i : Fin s => oneBank (pa' i) (pb' i)\n  obtain ⟨pre, port, preCount, preDepth, preBound, preEval⟩ :=\n    compileStage w s low high (fun i => oneBank_bound _ _) (fun i => oneBank_bound _ _)\n  let w2 := w + pre.gates.length\n  let prepReads := fun (c : Fin s → Field) (a : Fin n → Field) (b : Fin m → Field) =>\n    oneBank (fun x => a x + ∑ i, c i * pa i x * pa' i x)\n      (fun y => b y + ∑ i, c i * pb i y * pb' i y) ++ selected port c\n  have prepReadsBound (c : Fin s → Field) (a : Fin n → Field) (b : Fin m → Field) :\n      ∀ v ∈ prepReads c a b, v < w2 := by\n    intro v hv\n    obtain hv | hv := List.mem_append.mp hv\n    · have := oneBank_bound _ _ v hv\n      change v < n+m at this\n      dsimp only [w2,w]\n      omega\n    · exact selected_bound port c preBound v hv\n  have prepWiresLength (x : Fin n) (y : Fin m) :\n      (pre.wires (oneEach x y)).length = w2 := by\n    rw [Builder.wires, wires_fold_length, oneEach_length]\n  have prepReadsSum (c : Fin s → Field) (a : Fin n → Field) (b : Fin m → Field)\n      (x : Fin n) (y : Fin m) :\n      ((prepReads c a b).map (fun v => b2f ((pre.wires (oneEach x y)).getD v false))).sum =\n        a x + b y + ∑ i : Fin s, c i * P i x y := by\n    have hpre := preEval (oneEach x y) (oneEach_length x y)\n    simp only [prepReads, List.map_append, List.sum_append]\n    rw [oneBank_sum _ _ x y _ hpre.1, selected_sum]\n    have portEval (i : Fin s) :\n        b2f ((pre.wires (oneEach x y)).getD (port i) false) =\n          (pa i x + pb i y) * (pa' i x + pb' i y) := by\n      rw [hpre.2 i]\n      change (((oneBank (pa i) (pb i)).map\n        (fun v => b2f ((oneEach x y).getD v false))).sum) *\n          (((oneBank (pa' i) (pb' i)).map\n            (fun v => b2f ((oneEach x y).getD v false))).sum) = _\n      rw [oneBank_sum _ _ x y _ (fun _ _ => rfl), oneBank_sum _ _ x y _ (fun _ _ => rfl)]\n    simp only [portEval]\n    have expand :\n        (∑ i : Fin s, c i * ((pa i x + pb i y) * (pa' i x + pb' i y))) =\n          (∑ i : Fin s, c i * pa i x * pa' i x) +\n          (∑ i : Fin s, c i * pb i y * pb' i y) +\n          ∑ i : Fin s, c i * P i x y := by\n      rw [← Finset.sum_add_distrib, ← Finset.sum_add_distrib]\n      exact Finset.sum_congr rfl fun i _ => by dsimp only [P]; ring\n    rw [expand]\n    ring_nf\n    simp only [show (2 : ZMod 2) = 0 by decide, mul_zero, zero_add, add_zero]\n  let outL := fun j : Fin k => prepReads (mu j) (U j) (V j)\n  let outR := fun j : Fin k => prepReads (nu j) (U' j) (V' j)\n  obtain ⟨post, qport, postCount, postDepth, postBound, postEval⟩ :=\n    compileStage w2 k outL outR (fun j => prepReadsBound _ _ _) (fun j => prepReadsBound _ _ _)\n  let finalReads := prepReads cout Aout Bout ++ (List.finRange k).map qport\n  have finalBounds : ∀ i ∈ finalReads, i < w2 + post.gates.length := by\n    intro i hi\n    obtain hi | hi := List.mem_append.mp hi\n    · exact lt_of_lt_of_le (prepReadsBound _ _ _ i hi) (Nat.le_add_right _ _)\n    · obtain ⟨j,_,rfl⟩ := List.mem_map.mp hi\n      exact postBound j\n  let last := post.pushXorList finalReads finalBounds\n  have hlast := pushXorList_spec post finalReads finalBounds 1\n    (fun i _ => depthBound_input post postDepth i)\n  have depthLast : DepthBound last.1 1 := pushXorListBound post finalReads finalBounds postDepth\n  let C : Circuit := ⟨pre.gates ++ last.1.gates, last.2⟩\n  have hTake : C.gates.take pre.gates.length = pre.gates := by simp [C]\n  have hDrop : C.gates.drop pre.gates.length = last.1.gates := by simp [C]\n  refine ⟨C, pre.gates.length, by simp [C], ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩\n  · intro j hj i hi\n    change j < (pre.gates ++ last.1.gates).length at hj\n    change i ∈ ((pre.gates ++ last.1.gates).getD j ⟨GateOp.or,[]⟩).inputs at hi\n    by_cases jLeft : j < pre.gates.length\n    · rw [getD_append_left _ _ _ _ jLeft] at hi\n      exact pre.hRB j jLeft i hi\n    · rw [getD_append_right _ _ _ _ (by omega)] at hi\n      have hjR : j-pre.gates.length < last.1.gates.length := by\n        simp only [List.length_append] at hj\n        omega\n      have hb := last.1.hRB (j-pre.gates.length) hjR i hi\n      dsimp only [w2,w] at hb\n      omega\n  · intro g h\n    obtain h | h := List.mem_append.mp h\n    · exact pre.hFan g h\n    · exact last.1.hFan g h\n  · rw [hTake]\n    exact le_of_eq preCount\n  · rw [hDrop]\n    exact le_of_eq (hlast.2.2.1.trans postCount)\n  · rw [hTake]\n    exact preDepth\n  · rw [hDrop]\n    exact depthLast\n  · intro x y\n    apply b2f_injective\n    rw [bitOfField]\n    let inp := pre.wires (oneEach x y)\n    have hinp : inp.length = w2 := prepWiresLength x y\n    have hp := postEval inp hinp\n    have hval := (hlast.2.2.2.2.2 inp hinp).2\n    unfold Circuit.eval\n    change b2f (((pre.gates ++ last.1.gates).foldl wiresStep (oneEach x y)).getD last.2 false) = M x y\n    rw [List.foldl_append]\n    change b2f ((last.1.wires inp).getD last.2 false) = M x y\n    rw [hval]\n    simp only [finalReads, List.map_append, List.sum_append, List.map_map, Function.comp_def,\n      list_sum_finRange_eq]\n    have hOut : ((prepReads cout Aout Bout).map\n        (fun v => b2f ((post.wires inp).getD v false))).sum =\n        Aout x + Bout y + ∑ i : Fin s, cout i * P i x y := by\n      rw [← prepReadsSum cout Aout Bout x y]\n      congr 1\n      apply List.map_congr_left\n      intro i hi\n      rw [hp.1 i (prepReadsBound _ _ _ i hi)]\n    rw [hOut]\n    dsimp only [M]\n    apply congrArg (fun z : Field => Aout x + Bout y + (∑ i : Fin s, cout i * P i x y) + z)\n    apply Finset.sum_congr rfl\n    intro j _\n    rw [hp.2 j]\n    change (((prepReads (mu j) (U j) (V j)).map\n      (fun v => b2f (inp.getD v false))).sum) *\n        (((prepReads (nu j) (U' j) (V' j)).map\n          (fun v => b2f (inp.getD v false))).sum) = _\n    rw [prepReadsSum _ _ _ x y, prepReadsSum _ _ _ x y]\n\nprivate theorem rawEvalIndependent (B : Type) [Fintype B] [DecidableEq B] :\n    LinearIndependent Field (fun i : B => fun x : B → Field => x i) := by\n  rw [Fintype.linearIndependent_iff]\n  intro v hv i\n  have h := congrFun hv (Pi.single i (1 : Field))\n  simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Pi.zero_apply] at h\n  rwa [Finset.sum_eq_single i, Pi.single_eq_same, mul_one] at h\n  · intro j _ hj; simp [Pi.single_eq_of_ne hj]\n  · simp\n\nprivate theorem rawEvalRank (B : Type) [Fintype B] [DecidableEq B] :\n    Matrix.rank (m := B → Field) (n := B → Field)\n      (fun x y => ∑ i : B, x i * y i) = Fintype.card B := by\n  let L : Matrix (B → Field) B Field := fun x i => x i\n  let R : Matrix B (B → Field) Field := fun i x => x i\n  have hL : L.rank = Fintype.card B := by\n    rw [← Matrix.rank_transpose L]\n    exact LinearIndependent.rank_matrix (rawEvalIndependent B)\n  have hR : R.rank = Fintype.card B := LinearIndependent.rank_matrix (rawEvalIndependent B)\n  change (L * R).rank = _\n  have le := Matrix.rank_mul_le_left L R\n  have ge := Matrix.rank_mul_ge L R\n  omega\nend Build\n\nlemma b2z_decide (a : F) : b2z (decide (a = 1)) = a := by\n  rcases Build.f2_cases a with rfl | rfl <;> decide\n\nlemma anchor_apply {α β : Type*} (a₀ : α) (b₀ : β) (f : α → β → F) (a : α) (b : β) :\n    anchor a₀ b₀ f a b = f a b + f a b₀ + f a₀ b + f a₀ b₀ := rfl\n\nlemma fits_of_build {n m s k : ℕ} {G : Fin n → Fin m → Bool} (h : Build.Fits n m s k G) :\n    Fits s k G := h\n\nlemma anchoredRank_equiv {α : Type} [Fintype α] [DecidableEq α] {N : ℕ} (e : Fin N ≃ α)\n    (a₀ : α) (f : α → α → F) :\n    anchoredRank (fun x y => decide (f (e x) (e y) = 1)) (e.symm a₀) (e.symm a₀) =\n      (anchor a₀ a₀ f).rank := by\n  unfold anchoredRank\n  have h : anchor (e.symm a₀) (e.symm a₀) (fun x y => b2z (decide (f (e x) (e y) = 1))) =\n      (anchor a₀ a₀ f).submatrix e e := by\n    ext x y\n    simp only [anchor_apply, Matrix.submatrix_apply, Equiv.apply_symm_apply, b2z_decide]\n  rw [h, Matrix.rank_submatrix]\n\ntheorem attain_witness (s k : ℕ) (m : Fin s → Vec k) :\n    ∃ (n n' : ℕ) (G : Fin n → Fin n' → Bool) (u : Fin n) (v : Fin n'),\n      Fits s k G ∧ anchoredRank G u v = (anchor ((0,0) : Cube s k) (0,0) (witnessFun m)).rank := by\n  classical\n  let N := Fintype.card (Cube s k)\n  let e : Fin N ≃ Cube s k := (Fintype.equivFin _).symm\n  refine ⟨N, N, fun x y => decide (witnessFun m (e x) (e y) = 1), e.symm 0, e.symm 0, ?_,\n    anchoredRank_equiv e 0 (witnessFun m)⟩\n  have h := Build.buildPolynomial N N s k\n    (fun i x => (e x).2 (i,false)) (fun i x => (e x).2 (i,true))\n    (fun i y => (e y).2 (i,true)) (fun i y => (e y).2 (i,false))\n    0 0 (fun i => quad (m i))\n    (fun j x => (e x).1 (j,false)) (fun j x => (e x).1 (j,true))\n    (fun j y => (e y).1 (j,false)) (fun j y => (e y).1 (j,true))\n    (fun j i => m i j false) (fun j i => m i j true)\n  apply fits_of_build\n  convert h using 4 with x y\n  have hsm : ∀ a b : F, a • b = b * a := fun a b => (smul_eq_mul a b).trans (mul_comm a b)\n  simp only [witnessFun, quad, witnessZ, fromCoords, Pi.add_apply, Finset.sum_apply,\n    Pi.smul_apply, hsm, Pi.zero_apply, zero_add]\n\ntheorem attain_zero (s : ℕ) :\n    ∃ (n n' : ℕ) (G : Fin n → Fin n' → Bool) (u : Fin n) (v : Fin n'),\n      Fits s 0 G ∧ anchoredRank G u v = 2*s := by\n  classical\n  let N := Fintype.card (Coords s → F)\n  let e : Fin N ≃ (Coords s → F) := (Fintype.equivFin _).symm\n  let f : (Coords s → F) → (Coords s → F) → F := fun x y => ∑ i : Coords s, x i * y i\n  refine ⟨N, N, fun x y => decide (f (e x) (e y) = 1), e.symm 0, e.symm 0, ?_, ?_⟩\n  · have h := Build.buildPolynomial N N s 0 (fun i x => e x (i,false)) (fun i x => e x (i,true))\n      (fun i y => e y (i,true)) (fun i y => e y (i,false)) 0 0 1 0 0 0 0 0 0\n    apply fits_of_build\n    simpa [f, Coords, Fintype.sum_prod_type, Fintype.sum_bool, add_comm] using h\n  · rw [anchoredRank_equiv e 0 f]\n    have ha : anchor (0 : Coords s → F) 0 f = Matrix.of f := by\n      ext x y\n      simp [anchor_apply, f]\n    rw [ha]\n    have hr := Build.rawEvalRank (Coords s)\n    change (Matrix.of f).rank = _ at hr\n    rw [hr]\n    simp [Coords, mul_comm]\n\ntheorem attain_isGreatest\n    (hup : ∀ {n m s k : ℕ} {G : Fin n → Fin m → Bool}, Fits s k G →\n      ∀ (u : Fin n) (v : Fin m), anchoredRank G u v ≤ budget s k)\n    (hmask : ∀ s k : ℕ, k ≠ 0 →\n      ∃ m : Fin s → Vec k, (∀ i, m i ≠ 0) ∧ edges m = balancedPairs s k)\n    (hwit : ∀ {s k : ℕ} (m : Fin s → Vec k), (∀ i, m i ≠ 0) →\n      (anchor ((0,0) : Cube s k) (0,0) (witnessFun m)).rank = 2*k+4*s+4*(edges m).card)\n    (s k : ℕ) :\n    IsGreatest {r : ℕ | ∃ (n m : ℕ) (G : Fin n → Fin m → Bool) (u : Fin n) (v : Fin m),\n      Fits s k G ∧ anchoredRank G u v = r} (budget s k) := by\n  refine ⟨?_, ?_⟩\n  · by_cases hk : k = 0\n    · subst hk\n      obtain ⟨n, n', G, u, v, hf, hr⟩ := attain_zero s\n      exact ⟨n, n', G, u, v, hf, by rw [hr]; simp [budget]⟩\n    · obtain ⟨m, hm0, hme⟩ := hmask s k hk\n      obtain ⟨n, n', G, u, v, hf, hr⟩ := attain_witness s k m\n      refine ⟨n, n', G, u, v, hf, ?_⟩\n      rw [hr, hwit m hm0, hme]\n      simp [budget, hk]\n  · rintro r ⟨n, n', G, u, v, hf, rfl⟩\n    exact hup hf u v\n\ntheorem statement_of_parts\n    (hup : ∀ {n m s k : ℕ} {G : Fin n → Fin m → Bool}, Fits s k G →\n      ∀ (u : Fin n) (v : Fin m), anchoredRank G u v ≤ budget s k)\n    (hmask : ∀ s k : ℕ, k ≠ 0 →\n      ∃ m : Fin s → Vec k, (∀ i, m i ≠ 0) ∧ edges m = balancedPairs s k)\n    (hwit : ∀ {s k : ℕ} (m : Fin s → Vec k), (∀ i, m i ≠ 0) →\n      (anchor ((0,0) : Cube s k) (0,0) (witnessFun m)).rank = 2*k+4*s+4*(edges m).card) : (\n\nlet nonlinear := fun (g : PEqualNP.CircuitLowerBounds.Gate) =>\n  (g.inputs.length == 2) &&\n  xor (xor (g.op.eval [false, false]) (g.op.eval [false, true]))\n      (xor (g.op.eval [true, false]) (g.op.eval [true, true]))\nlet depths := fun (width : ℕ) (C : PEqualNP.CircuitLowerBounds.Circuit) =>\n  C.gates.foldl (fun (ds : List ℕ) g =>\n    ds ++ [(g.inputs.map (fun a => ds.getD a 0)).foldr max 0 + (nonlinear g).toNat])\n    (List.replicate width 0)\nlet F := ZMod 2\n∀ s k : ℕ,\n  let pairs := ((Finset.univ : Finset (Fin s × Fin s)).filter (fun ij =>\n    ij.1 < ij.2 ∧ ij.1.val % (2*k+1) ≠ ij.2.val % (2*k+1))).card\n  let bound := if k = 0 then 2*s else 2*k+4*s+4*pairs\n  let fit := fun (n m : ℕ) (G : Fin n → Fin m → Bool) =>\n    ∃ (C : PEqualNP.CircuitLowerBounds.Circuit) (cut : ℕ), cut ≤ C.gates.length ∧\n      PEqualNP.MetaComplexity.NestedCover.ReadsBack (n+m) C ∧\n      (∀ g ∈ C.gates, g.inputs.length ≤ 2) ∧\n      (C.gates.take cut).countP nonlinear ≤ s ∧ (C.gates.drop cut).countP nonlinear ≤ k ∧\n      (∀ d ∈ depths (n+m) ⟨C.gates.take cut,0⟩, d ≤ 1) ∧\n      (∀ d ∈ depths (n+m+cut) ⟨C.gates.drop cut,0⟩, d ≤ 1) ∧\n      PEqualNP.Represents.Represents G C\n  let rk := fun {n m : ℕ} (G : Fin n → Fin m → Bool) (u : Fin n) (v : Fin m) =>\n    let bit := fun i j => if G i j then (1 : F) else 0\n    let X : Matrix (Fin n) (Fin m) F := fun i j => bit i j + bit i v + bit u j + bit u v\n    X.rank\n  IsGreatest {r : ℕ | ∃ (n m : ℕ) (G : Fin n → Fin m → Bool)\n    (u : Fin n) (v : Fin m), fit n m G ∧ rk G u v = r} bound) := by\n  dsimp only\n  intro s k\n  exact attain_isGreatest hup hmask hwit s k\n\nend PEqualNP.Outside.L_meta_33679\n",
"lean_bytes": 51295,
"lean_sha256": "c2665ef58f0c196df255f05b69e18f93e541b21a9da5ab34c952a35721694124",
"module": "PEqualNP.Scratch.Attain (file lean/PEqualNP/Scratch/Attain.lean)",
"proved": [
{
"name": "PEqualNP.Outside.L_meta_33679.attain_witness",
"statement": "∀ (s k : ℕ) (m : Fin s → Vec k), ∃ (n n' : ℕ) (G : Fin n → Fin n' → Bool) (u : Fin n) (v : Fin n'), Fits s k G ∧ anchoredRank G u v = (anchor ((0,0) : Cube s k) (0,0) (witnessFun m)).rank",
"note": "part (1); holds for every mask family m (so in particular for k>0 and the masks of balanced_masks), with witness_rank giving 2*k+4*s+4*(edges m).card"
},
{
"name": "PEqualNP.Outside.L_meta_33679.attain_zero",
"statement": "∀ s : ℕ, ∃ (n n' : ℕ) (G : Fin n → Fin n' → Bool) (u : Fin n) (v : Fin n'), Fits s 0 G ∧ anchoredRank G u v = 2*s",
"note": "part (2)"
},
{
"name": "PEqualNP.Outside.L_meta_33679.attain_isGreatest",
"statement": "(hup : ∀ {n m s k : ℕ} {G : Fin n → Fin m → Bool}, Fits s k G → ∀ (u : Fin n) (v : Fin m), anchoredRank G u v ≤ budget s k) (hmask : ∀ s k : ℕ, k ≠ 0 → ∃ m : Fin s → Vec k, (∀ i, m i ≠ 0) ∧ edges m = balancedPairs s k) (hwit : ∀ {s k : ℕ} (m : Fin s → Vec k), (∀ i, m i ≠ 0) → (anchor ((0,0) : Cube s k) (0,0) (witnessFun m)).rank = 2*k+4*s+4*(edges m).card) (s k : ℕ) : IsGreatest {r : ℕ | ∃ (n m : ℕ) (G : Fin n → Fin m → Bool) (u : Fin n) (v : Fin m), Fits s k G ∧ anchoredRank G u v = r} (budget s k)",
"note": "part (3), with fits_upper, balanced_masks and witness_rank as hypotheses"
},
{
"name": "PEqualNP.Outside.L_meta_33679.statement_of_parts",
"statement": "(hup : ∀ {n m s k : ℕ} {G : Fin n → Fin m → Bool}, Fits s k G → ∀ (u : Fin n) (v : Fin m), anchoredRank G u v ≤ budget s k) (hmask : ∀ s k : ℕ, k ≠ 0 → ∃ m : Fin s → Vec k, (∀ i, m i ≠ 0) ∧ edges m = balancedPairs s k) (hwit : ∀ {s k : ℕ} (m : Fin s → Vec k), (∀ i, m i ≠ 0) → (anchor ((0,0) : Cube s k) (0,0) (witnessFun m)).rank = 2*k+4*s+4*(edges m).card) : (<the unit statement, the let-block from let nonlinear := ... to IsGreatest {...} bound, as in the upstream theorem>)",
"note": "the unit statement itself, from the same three hypotheses; the text inside the parentheses is in the lean field"
},
{
"name": "Fits for every gate list built: fits_of_build, anchoredRank_equiv, anchor_apply, b2z_decide",
"statement": "helper lemmas, see lean"
}
],
"build": {
"command": "lake build PEqualNP.Scratch.Attain",
"exit": 0,
"seconds": 13.6,
"peak_memory_gb": 3.13,
"note": "Lean v4.36.0, Mathlib from lake exe cache get; 0 errors, linter warnings only (unused simp args etc.)"
},
"axioms": [
"propext",
"Classical.choice",
"Quot.sound"
],
"axioms_note": "#print axioms on attain_witness, attain_zero, attain_isGreatest, statement_of_parts, run from a separate scratch file that is not delivered",
"checker_rules": "scanned: no sorry, axiom, native_decide, # command, macro/syntax/notation/elab/initialize/attribute command, @[...] attribute, double quote, or set_option in the file",
"join": "Take the partial unchanged (it imports all of Mathlib, which covers this file's imports). Before its final end PEqualNP.Outside.L_meta_33679, insert open Finset and then everything in this file from namespace Build up to, but not including, its final end line. The definitions this file repeats (F, b2z, nonlinear, depthList, anchor, Vec, quad, polar, edges, balancedPairs, Fits, anchoredRank, budget, Coords, Cube, fromCoords, witnessZ, witnessFun) are copied byte for byte from the partial and are dropped. Then close with theorem PEqualNP.Outside.L_meta_33679 : (<statement>) := statement_of_parts (fun h u v => fits_upper h u v) (fun s k hk => balanced_masks s k hk) (fun m hm => witness_rank m hm). Tested: this join (109,272 bytes, inside a renamed namespace with a closing theorem named joined_check) checked with lake env lean, exit 0, 14.5 s, peak 7.20 GB. The joined file is larger than 64,000 bytes, and with import Mathlib its peak is above 6.5 GB.",
"missing": "Nothing mathematical: (1), (2) and (3) are proved, and the joined file proves the unit statement. Still open: (a) the statement SHA-256 could not be checked, because the desk no longer lists the gap; (b) the joined file has not been run through the official checker (tools/pnp.sh check), and its peak memory with import Mathlib was 7.2 GB here, above the 6.5 GB limit; narrower imports, as this file uses (3.1 GB), would probably fix that, but this was not tested on the joined file; (c) the root theorem name PEqualNP.Outside.L_meta_33679 is the same as the namespace, which the upstream file shows is allowed but which was not tested in the join.",
"approach": "Circuits come from a general builder adapted, under Apache-2.0, from the merged upstream L_meta_33679.lean (Builder, compileStage, buildPolynomial). For any s,k and linear forms it builds a ReadsBack, fan-in-2 gate list with a cut, s AND gates in a depth-1 preparation layer and k after it, that Represents decide(M=1) for M = A(x)+B(y)+sum c_i P_i + sum_j (U_j+V_j+sum mu_ji P_i)(U_j'+V_j'+sum nu_ji P_i), with P_i a two-term product. It is placed in sub-namespace Build. With table rows and columns being Cube s k, P_i=witnessZ i, cout=quad(m i) and mu,nu=the mask coordinates, M equals witnessFun m, and anchoredRank equals the rank of anchor 0 0 witnessFun by reindexing through Fin N. For k=0, M=sum x_i y_i over 2s coordinates, rank 2s. A Python check gave anchored rank = budget for s,k in 0..2.",
"self_test": "s,k in {0,1,2}: anchored rank of the witness table (k>0, masks as in exists_mask_family/balanced_masks) and of the inner-product table (k=0) equals budget: 0,2,4 (k=0); 2,6,14 (k=1); 4,8,16 (k=2)",
"upstream_commit": "b09551e9cb2cf5d75dae8c5535868baa9868cf9f",
"partial_upstream_commit": "32d0fff5a2b223f305f5e23d96b07f6d18c39545"
}