{
  "unit": "L-meta-33225",
  "title": "Can one NOT gate shorten edge detection on 0-3 1-4 0-5 1-5 3-5 0-6 1-6 3-6 5-6 0-7 2-7 3-7 4-7 5-7?",
  "level": null,
  "weight": 55,
  "state": "open",
  "file": "lean/PEqualNP/Outside/L_meta_33225.lean",
  "module": "PEqualNP.Outside.L_meta_33225",
  "imports": [
    "PEqualNP.Defs"
  ],
  "statement_sha256": "5c75a3db6b7fc38d96c83493a2723aab01d526eb532e8b938116cf21a23256d0",
  "proved": false,
  "lean": "import Mathlib\nimport PEqualNP.Defs\n\nnamespace PEqualNP.Outside.L_meta_33225\n\nopen PEqualNP.CircuitLowerBounds\n\ndef target (x : Fin 8 → Bool) : Bool :=\n  decide (∃ i < ([0, 3, 1, 4, 0, 5, 1, 5, 3, 5, 0, 6, 1, 6, 3, 6, 5, 6, 0, 7, 2, 7, 3, 7, 4, 7, 5, 7] : List ℕ).length / 2, (List.ofFn x).getD (([0, 3, 1, 4, 0, 5, 1, 5, 3, 5, 0, 6, 1, 6, 3, 6, 5, 6, 0, 7, 2, 7, 3, 7, 4, 7, 5, 7] : List ℕ).getD (2 * i) 0) false = true ∧ (List.ofFn x).getD (([0, 3, 1, 4, 0, 5, 1, 5, 3, 5, 0, 6, 1, 6, 3, 6, 5, 6, 0, 7, 2, 7, 3, 7, 4, 7, 5, 7] : List ℕ).getD (2 * i + 1) 0) false = true)\n\n-- The dense part is a two-of-four test on wires 0, 3, 5 and the disjunction of 6 and 7.\n-- The last branches add the edges incident to vertices 1, 2 and 4.\ndef monotoneGates : List Gate :=\n  [⟨.or, [0, 3]⟩,\n   ⟨.or, [6, 7]⟩,\n   ⟨.or, [5, 9]⟩,\n   ⟨.and, [8, 10]⟩,\n   ⟨.and, [5, 9]⟩,\n   ⟨.and, [0, 3]⟩,\n   ⟨.or, [5, 6]⟩,\n   ⟨.or, [4, 14]⟩,\n   ⟨.and, [1, 15]⟩,\n   ⟨.or, [2, 4]⟩,\n   ⟨.and, [7, 17]⟩,\n   ⟨.or, [11, 12]⟩,\n   ⟨.or, [13, 16]⟩,\n   ⟨.or, [19, 20]⟩,\n   ⟨.or, [18, 21]⟩]\n\ntheorem monotoneGates_legal :\n    ∀ g ∈ monotoneGates, (g.op = GateOp.and ∨ g.op = GateOp.or) ∧\n      g.inputs.length ≤ 2 := by\n  simp [monotoneGates]\n\nset_option maxRecDepth 14000 in\nset_option maxHeartbeats 6000000 in\ntheorem monotoneGates_correct :\n    ∀ x : Fin 8 → Bool, Circuit.eval ⟨monotoneGates, 22⟩ (List.ofFn x) = target x := by\n  decide +kernel\n\ntheorem monotone_upper_bound (k : ℕ) (hk : 15 ≤ k) :\n    ∃ (gates' : List Gate) (o' : ℕ),\n      (∀ g ∈ gates', (g.op = GateOp.and ∨ g.op = GateOp.or) ∧ g.inputs.length ≤ 2) ∧\n      gates'.length ≤ k ∧ ∀ x : Fin 8 → Bool,\n        Circuit.eval ⟨gates', o'⟩ (List.ofFn x) = target x :=\n  ⟨monotoneGates, 22, monotoneGates_legal, hk, monotoneGates_correct⟩\n\ndef forceNot (b : Bool) (g : Gate) : Gate :=\n  match g.op with\n  | .not => ⟨if b then .and else .or, []⟩\n  | _ => g\n\ndef gateValue (g : Gate) (w : List Bool) : Bool :=\n  g.op.eval (g.inputs.map fun i => w.getD i false)\n\ndef WireLe (u v : List Bool) : Prop :=\n  u.length = v.length ∧ ∀ i, u.getD i false ≤ v.getD i false\n\ntheorem wireLe_append {u v : List Bool} (h : WireLe u v) {a b : Bool} (hab : a ≤ b) :\n    WireLe (u ++ [a]) (v ++ [b]) := by\n  refine ⟨by simp [h.1], ?_⟩\n  intro i\n  by_cases hi : i < u.length\n  · rw [List.getD_append _ _ _ _ hi, List.getD_append _ _ _ _ (by rwa [← h.1])]\n    exact h.2 i\n  · rw [List.getD_append_right _ _ _ _ (by omega),\n      List.getD_append_right _ _ _ _ (by rw [← h.1]; omega), ← h.1]\n    cases i - u.length with\n    | zero => exact hab\n    | succ n => simp\n\ntheorem and_eval_mono (ins : List ℕ) {u v : List Bool} (h : WireLe u v) :\n    GateOp.and.eval (ins.map fun i => u.getD i false) ≤\n      GateOp.and.eval (ins.map fun i => v.getD i false) := by\n  induction ins with\n  | nil => exact le_rfl\n  | cons i ins ih =>\n    have hi := h.2 i\n    simp only [List.map_cons, GateOp.eval, List.all_cons, id_eq] at ih ⊢\n    generalize hu : u.getD i false = uᵢ at hi ⊢\n    generalize hv : v.getD i false = vᵢ at hi ⊢\n    cases uᵢ <;> cases vᵢ <;> simp_all\n    exact ((by decide : ¬ (true ≤ false)) hi).elim\n\ntheorem or_eval_mono (ins : List ℕ) {u v : List Bool} (h : WireLe u v) :\n    GateOp.or.eval (ins.map fun i => u.getD i false) ≤\n      GateOp.or.eval (ins.map fun i => v.getD i false) := by\n  induction ins with\n  | nil => exact le_rfl\n  | cons i ins ih =>\n    have hi := h.2 i\n    simp only [List.map_cons, GateOp.eval, List.any_cons, id_eq] at ih ⊢\n    generalize hu : u.getD i false = uᵢ at hi ⊢\n    generalize hv : v.getD i false = vᵢ at hi ⊢\n    cases uᵢ <;> cases vᵢ <;> simp_all\n    exact ((by decide : ¬ (true ≤ false)) hi).elim\n\ntheorem forced_eval_bound (g : Gate)\n    (hop : g.op = .and ∨ g.op = .or ∨ g.op = .not)\n    {u v : List Bool} (h : WireLe u v) :\n    gateValue (forceNot false g) u ≤ gateValue g v ∧\n      gateValue g u ≤ gateValue (forceNot true g) v := by\n  rcases g with ⟨o, ins⟩\n  rcases hop with ho | ho | ho\n  · change o = _ at ho\n    subst o\n    exact ⟨and_eval_mono ins h, and_eval_mono ins h⟩\n  · change o = _ at ho\n    subst o\n    exact ⟨or_eval_mono ins h, or_eval_mono ins h⟩\n  · change o = _ at ho\n    subst o\n    simp [gateValue, forceNot, GateOp.eval]\n\ntheorem forceNot_legal (b : Bool) (g : Gate)\n    (h : (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2) :\n    ((forceNot b g).op = .and ∨ (forceNot b g).op = .or) ∧\n      (forceNot b g).inputs.length ≤ 2 := by\n  rcases g with ⟨o, ins⟩\n  rcases h with ⟨ho | ho | ho, hi⟩\n  · change o = _ at ho\n    subst o\n    simp [forceNot, hi]\n  · change o = _ at ho\n    subst o\n    simp [forceNot, hi]\n  · change o = _ at ho\n    subst o\n    cases b <;> simp [forceNot]\n\ntheorem forceNot_all_legal (b : Bool) (gs : List Gate)\n    (h : ∀ g ∈ gs, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2) :\n    ∀ g ∈ gs.map (forceNot b), (g.op = .and ∨ g.op = .or) ∧ g.inputs.length ≤ 2 := by\n  intro g hg\n  obtain ⟨g₀, hg₀, rfl⟩ := List.mem_map.mp hg\n  exact forceNot_legal b g₀ (h g₀ hg₀)\n\ntheorem fold_gate_bound {a b : Gate → Gate} (gs : List Gate)\n    (h : ∀ g ∈ gs, ∀ u v, WireLe u v → gateValue (a g) u ≤ gateValue (b g) v)\n    {u v : List Bool} (huv : WireLe u v) :\n    WireLe ((gs.map a).foldl (fun w g => w ++ [gateValue g w]) u)\n      ((gs.map b).foldl (fun w g => w ++ [gateValue g w]) v) := by\n  induction gs generalizing u v with\n  | nil => exact huv\n  | cons g gs ih =>\n    exact ih (fun g' hg' => h g' (List.mem_cons_of_mem _ hg'))\n      (wireLe_append huv (h g (by simp) u v huv))\n\ntheorem forcing_bounds (gs : List Gate) (o : ℕ)\n    (h : ∀ g ∈ gs, g.op = .and ∨ g.op = .or ∨ g.op = .not) (x : List Bool) :\n    Circuit.eval ⟨gs.map (forceNot false), o⟩ x ≤ Circuit.eval ⟨gs, o⟩ x ∧\n      Circuit.eval ⟨gs, o⟩ x ≤ Circuit.eval ⟨gs.map (forceNot true), o⟩ x := by\n  have hxx : WireLe x x := ⟨rfl, fun _ => le_rfl⟩\n  have lower := fold_gate_bound (a := forceNot false) (b := id) gs\n    (fun g hg u v huv => (forced_eval_bound g (h g hg) huv).1) hxx\n  have upper := fold_gate_bound (a := id) (b := forceNot true) gs\n    (fun g hg u v huv => (forced_eval_bound g (h g hg) huv).2) hxx\n  exact ⟨by simpa [Circuit.eval, Circuit.wires, gateValue] using lower.2 o,\n    by simpa [Circuit.eval, Circuit.wires, gateValue] using upper.2 o⟩\n\nabbrev InputLe (x y : Fin 8 → Bool) : Prop :=\n  ∀ i, x i ≤ y i\n\ndef inputMask (mask : ℕ) (i : Fin 8) : Bool :=\n  mask.testBit i.val\n\n-- Bit i denotes that vertex i is present in the test input.\ndef edgeMasks : List ℕ :=\n  [9, 18, 33, 34, 40, 65, 66, 72, 96, 129, 132, 136, 144, 160]\n\ndef independentMasks : List ℕ :=\n  [7, 14, 21, 28, 52, 84, 130, 192]\n\nset_option maxRecDepth 14000 in\nset_option maxHeartbeats 6000000 in\ntheorem true_has_edge :\n    ∀ x : Fin 8 → Bool, target x = true →\n      (edgeMasks.any fun m => decide (InputLe (inputMask m) x)) = true := by\n  decide +kernel\n\nset_option maxRecDepth 14000 in\nset_option maxHeartbeats 6000000 in\ntheorem false_extends_to_independent :\n    ∀ x : Fin 8 → Bool, target x = false →\n      (independentMasks.any fun m => decide (InputLe x (inputMask m))) = true := by\n  decide +kernel\n\ntheorem inputWireLe {x y : Fin 8 → Bool} (h : InputLe x y) :\n    WireLe (List.ofFn x) (List.ofFn y) := by\n  refine ⟨by simp, ?_⟩\n  intro i\n  by_cases hi : i < 8\n  · simpa only [List.getD_eq_getElem?_getD, List.getElem?_ofFn, dite_eq_left hi, Option.getD_some] using h ⟨i, hi⟩\n  · simp [List.getD_eq_getElem?_getD, hi]\n\ntheorem eval_mono (gs : List Gate) (o : ℕ)\n    (h : ∀ g ∈ gs, g.op = .and ∨ g.op = .or)\n    {x y : Fin 8 → Bool} (hxy : InputLe x y) :\n    Circuit.eval ⟨gs, o⟩ (List.ofFn x) ≤ Circuit.eval ⟨gs, o⟩ (List.ofFn y) := by\n  have bound := fold_gate_bound (a := id) (b := id) gs\n      (fun g hg u v huv => by\n        rcases h g hg with hop | hop\n        · simpa [gateValue, hop] using and_eval_mono g.inputs huv\n        · simpa [gateValue, hop] using or_eval_mono g.inputs huv)\n      (inputWireLe hxy)\n  simpa [Circuit.eval, Circuit.wires, gateValue] using bound.2 o\n\ndef HasMonotoneImplementation (k : ℕ) : Prop :=\n  ∃ (gs : List Gate) (o : ℕ),\n    (∀ g ∈ gs, (g.op = .and ∨ g.op = .or) ∧ g.inputs.length ≤ 2) ∧\n    gs.length ≤ k ∧ ∀ x : Fin 8 → Bool, Circuit.eval ⟨gs, o⟩ (List.ofFn x) = target x\n\ndef forcedCircuit (b : Bool) (gs : List Gate) (o : ℕ) : Circuit :=\n  ⟨gs.map (forceNot b), o⟩\n\ntheorem improvement_constraints (gs : List Gate) (o : ℕ)\n    (legal : ∀ g ∈ gs, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2)\n    (computes : ∀ x : Fin 8 → Bool, Circuit.eval ⟨gs, o⟩ (List.ofFn x) = target x)\n    (improves : ¬ HasMonotoneImplementation gs.length) :\n    gs.length < 15 ∧\n      (∃ m ∈ edgeMasks, (forcedCircuit false gs o).eval (List.ofFn (inputMask m)) = false) ∧\n      (∃ m ∈ independentMasks, (forcedCircuit true gs o).eval (List.ofFn (inputMask m)) = true) := by\n  have force_legal (b : Bool) := forceNot_all_legal b gs legal\n  have bounds (x : Fin 8 → Bool) := forcing_bounds gs o (fun g hg => (legal g hg).1) (List.ofFn x)\n  have force_mono (b : Bool) {x y : Fin 8 → Bool} (hxy : InputLe x y) :\n      (forcedCircuit b gs o).eval (List.ofFn x) ≤ (forcedCircuit b gs o).eval (List.ofFn y) :=\n    eval_mono _ o (fun g hg => (force_legal b g hg).1) hxy\n  refine ⟨lt_of_not_ge (fun h => improves (monotone_upper_bound _ h)), ?_, ?_⟩\n  · by_contra! h\n    apply improves\n    refine ⟨gs.map (forceNot false), o, force_legal false, by simp, ?_⟩\n    intro x\n    apply le_antisymm\n    · exact (bounds x).1.trans (le_of_eq (computes x))\n    · cases hx : target x with\n      | false => simp\n      | true =>\n        obtain ⟨m, hm, hmx⟩ := List.any_eq_true.mp (true_has_edge x hx)\n        have h₀ : (forcedCircuit false gs o).eval (List.ofFn (inputMask m)) = true :=\n          Bool.eq_true_of_ne_false (h m hm)\n        have hh := force_mono false (of_decide_eq_true hmx)\n        rw [h₀] at hh\n        exact hh\n  · by_contra! h\n    apply improves\n    refine ⟨gs.map (forceNot true), o, force_legal true, by simp, ?_⟩\n    intro x\n    apply le_antisymm\n    · cases hx : target x with\n      | true => simp\n      | false =>\n        obtain ⟨m, hm, hxm⟩ := List.any_eq_true.mp (false_extends_to_independent x hx)\n        have h₁ : (forcedCircuit true gs o).eval (List.ofFn (inputMask m)) = false :=\n          Bool.eq_false_of_ne_true (h m hm)\n        have hh := force_mono true (of_decide_eq_true hxm)\n        rw [h₁] at hh\n        exact hh\n    · exact (le_of_eq (computes x).symm).trans (bounds x).2\n\ndef readWires (g : Gate) : List ℕ :=\n  match g.op with\n  | .not => g.inputs.take 1\n  | _ => g.inputs\n\ndef extraDemand (g : Gate) : ℕ :=\n  match g.op with\n  | .not => 0\n  | _ => 1\n\n-- Walk backward from the observed wires and expand any gate whose output is needed.\ndef demand : List Gate → ℕ → Finset ℕ → Finset ℕ\n  | [], _, s => s\n  | g :: gs, n, s =>\n    let d := demand gs (n + 1) s\n    if n ∈ d then d.erase n ∪ (readWires g).toFinset else d\n\ndef demandBudget (gs : List Gate) : ℕ :=\n  (gs.map extraDemand).sum\n\ntheorem readWires_bound (g : Gate) (h : g.inputs.length ≤ 2) :\n    (readWires g).toFinset.card ≤ extraDemand g + 1 := by\n  calc\n    _ ≤ (readWires g).length := List.toFinset_card_le _\n    _ ≤ _ := by\n      cases hg : g.op <;> simp [readWires, extraDemand, hg, h]\n\ntheorem demand_card (gs : List Gate) (n : ℕ) (s : Finset ℕ)\n    (legal : ∀ g ∈ gs, g.inputs.length ≤ 2) :\n    (demand gs n s).card ≤ s.card + demandBudget gs := by\n  induction gs generalizing n with\n  | nil => simp [demand, demandBudget]\n  | cons g gs ih =>\n    have ht := ih (n + 1) (fun j hj => legal j (List.mem_cons_of_mem _ hj))\n    simp only [demand, demandBudget, List.map_cons, List.sum_cons]\n    split\n    · rename_i h\n      have he := Finset.card_erase_add_one h\n      have hr := readWires_bound g (legal g (by simp))\n      have hu := Finset.card_union_le ((demand gs (n + 1) s).erase n) (readWires g).toFinset\n      change (demand gs (n + 1) s).card ≤ s.card + (gs.map extraDemand).sum at ht\n      omega\n    · change (demand gs (n + 1) s).card ≤ s.card + (gs.map extraDemand).sum at ht\n      omega\n\ntheorem demandBudget_bound (gs : List Gate) :\n    demandBudget gs ≤ gs.length ∧\n      ((∃ g ∈ gs, g.op = .not) → demandBudget gs + 1 ≤ gs.length) := by\n  induction gs with\n  | nil => simp [demandBudget]\n  | cons g gs ih =>\n    rcases ih with ⟨ih₁, ih₂⟩\n    have hb : extraDemand g ≤ 1 := by cases hg : g.op <;> simp [extraDemand, hg]\n    simp only [demandBudget, List.map_cons, List.sum_cons, List.length_cons] at *\n    refine ⟨by omega, ?_⟩\n    rintro ⟨j, hj, ho⟩\n    rcases List.mem_cons.mp hj with rfl | hj\n    · simp only [extraDemand, ho]\n      omega\n    · have := ih₂ ⟨j, hj, ho⟩\n      omega\n\ntheorem gateValue_agrees (g : Gate) {u v : List Bool}\n    (h : ∀ i ∈ readWires g, u.getD i false = v.getD i false) :\n    gateValue g u = gateValue g v := by\n  rcases g with ⟨op, ins⟩\n  cases op <;> simp only [readWires] at h <;>\n    simp only [gateValue, GateOp.eval]\n  all_goals first\n    | rw [List.map_congr_left h]\n    | cases ins with\n      | nil => rfl\n      | cons i ins =>\n        have hi := h i (by simp)\n        exact congrArg Bool.not hi\n\ntheorem demand_agrees (gs : List Gate) (s : Finset ℕ)\n    {u v : List Bool} (hLen : u.length = v.length)\n    (h : ∀ i ∈ demand gs u.length s, u.getD i false = v.getD i false) :\n    ∀ i ∈ s, (gs.foldl (fun w g => w ++ [gateValue g w]) u).getD i false =\n      (gs.foldl (fun w g => w ++ [gateValue g w]) v).getD i false := by\n  induction gs generalizing u v with\n  | nil => exact h\n  | cons g gs ih =>\n    intro i hi\n    simp only [List.foldl_cons]\n    apply ih (by simp [hLen]) ?_ i hi\n    intro j hj\n    simp only [List.length_append, List.length_singleton] at hj\n    by_cases he : j = u.length\n    · subst j\n      have hg : gateValue g u = gateValue g v := by\n        apply gateValue_agrees\n        intro k hk\n        apply h k\n        simp [demand, hj, hk]\n      rw [List.getD_append_right _ _ _ _ le_rfl,\n        List.getD_append_right _ _ _ _ (by omega)]\n      simpa [← hLen] using hg\n    · by_cases hlt : j < u.length\n      · rw [List.getD_append _ _ _ _ hlt, List.getD_append _ _ _ _ (by omega)]\n        apply h j\n        by_cases hn : u.length ∈ demand gs (u.length + 1) s\n        · simp [demand, hn, hj, he]\n        · simp [demand, hn, hj]\n      · rw [List.getD_append_right _ _ _ _ (by omega),\n          List.getD_append_right _ _ _ _ (by omega), ← hLen]\n        have hs : 1 ≤ j - u.length := by omega\n        rw [List.getD_eq_default _ false (by simpa using hs),\n          List.getD_eq_default _ false (by simpa using hs)]\n\ntheorem each_input_essential :\n    ∀ i : Fin 8, ∃ j : Fin 8,\n      target (fun k => decide (k = j)) = false ∧\n        target (fun k => decide (k = j ∨ k = i)) = true := by\n  decide +kernel\n\ntheorem demand_contains_inputs (gs : List Gate) (o : ℕ)\n    (computes : ∀ x : Fin 8 → Bool, Circuit.eval ⟨gs, o⟩ (List.ofFn x) = target x) :\n    Finset.range 8 ⊆ demand gs 8 {o} := by\n  intro n hn\n  have hn : n < 8 := Finset.mem_range.mp hn\n  by_contra hmissing\n  let i : Fin 8 := ⟨n, hn⟩\n  obtain ⟨j, hfalse, htrue⟩ := each_input_essential i\n  let x : Fin 8 → Bool := fun k => decide (k = j)\n  let y : Fin 8 → Bool := fun k => decide (k = j ∨ k = i)\n  have hEq (k : ℕ) (hk : k ∈ demand gs (List.ofFn x).length {o}) :\n      (List.ofFn x).getD k false = (List.ofFn y).getD k false := by\n    have hne : k ≠ n := by\n      intro he\n      subst k\n      exact hmissing (by simpa only [List.length_ofFn] using hk)\n    by_cases hlt : k < 8\n    · have hki : (⟨k, hlt⟩ : Fin 8) ≠ i := fun he => hne (congrArg Fin.val he)\n      simp only [List.getD_eq_getElem?_getD, List.getElem?_ofFn, dite_eq_left hlt,\n        Option.getD_some, x, y, hki, or_false]\n    · rw [List.getD_eq_default _ false (by simpa using Nat.le_of_not_gt hlt),\n        List.getD_eq_default _ false (by simpa using Nat.le_of_not_gt hlt)]\n  have he := demand_agrees gs {o} (by simp) hEq o (by simp)\n  change Circuit.eval ⟨gs, o⟩ (List.ofFn x) = Circuit.eval ⟨gs, o⟩ (List.ofFn y) at he\n  rw [computes x, computes y, hfalse, htrue] at he\n  contradiction\n\ntheorem gate_count_lower_bound (gs : List Gate) (o : ℕ)\n    (fanIn : ∀ g ∈ gs, g.inputs.length ≤ 2)\n    (computes : ∀ x : Fin 8 → Bool, Circuit.eval ⟨gs, o⟩ (List.ofFn x) = target x)\n    (notUsed : ∃ g ∈ gs, g.op = .not) :\n    8 ≤ gs.length := by\n  have h₁ := Finset.card_le_card (demand_contains_inputs gs o computes)\n  have h₂ := demand_card gs 8 {o} fanIn\n  have h₃ := (demandBudget_bound gs).2 notUsed\n  simp only [Finset.card_range, Finset.card_singleton] at h₁ h₂\n  omega\n\ntheorem improvement_requires_eight (gs : List Gate) (o : ℕ)\n    (legal : ∀ g ∈ gs, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2)\n    (computes : ∀ x : Fin 8 → Bool, Circuit.eval ⟨gs, o⟩ (List.ofFn x) = target x)\n    (improves : ¬ HasMonotoneImplementation gs.length) :\n    8 ≤ gs.length := by\n  have notUsed : ∃ g ∈ gs, g.op = .not := by\n    by_contra! none\n    apply improves\n    refine ⟨gs, o, ?_, le_rfl, computes⟩\n    intro g hg\n    obtain ⟨ho, hi⟩ := legal g hg\n    exact ⟨ho.elim Or.inl (fun h => Or.inr (h.resolve_right (none g hg))), hi⟩\n  exact gate_count_lower_bound gs o (fun g hg => (legal g hg).2) computes notUsed\n\n-- Sharing the disjunction of 5, 6 and 7 saves a gate and adds the unwanted edge 1-7.\ndef nearGates : List Gate :=\n  [⟨.or, [0, 3]⟩,\n   ⟨.or, [6, 7]⟩,\n   ⟨.or, [5, 9]⟩,\n   ⟨.and, [8, 10]⟩,\n   ⟨.and, [5, 9]⟩,\n   ⟨.and, [0, 3]⟩,\n   ⟨.or, [4, 10]⟩,\n   ⟨.and, [1, 14]⟩,\n   ⟨.or, [2, 4]⟩,\n   ⟨.and, [7, 16]⟩,\n   ⟨.or, [11, 12]⟩,\n   ⟨.or, [13, 15]⟩,\n   ⟨.or, [18, 19]⟩,\n   ⟨.or, [17, 20]⟩]\n\nset_option maxRecDepth 14000 in\nset_option maxHeartbeats 6000000 in\ntheorem nearGates_exact_error :\n    ∀ x : Fin 8 → Bool, Circuit.eval ⟨nearGates, 21⟩ (List.ofFn x) =\n      (target x || decide (∀ i : Fin 8, x i = inputMask 130 i)) := by\n  decide +kernel\n\ntheorem bounded_reduction : (¬ (∀ (gates : List PEqualNP.CircuitLowerBounds.Gate) (o : ℕ), (∀ g ∈ gates, (g.op = PEqualNP.CircuitLowerBounds.GateOp.and ∨ g.op = PEqualNP.CircuitLowerBounds.GateOp.or ∨ g.op = PEqualNP.CircuitLowerBounds.GateOp.not) ∧ g.inputs.length ≤ 2) → (∀ i j : Fin gates.length, (gates.get i).op = PEqualNP.CircuitLowerBounds.GateOp.not → (gates.get j).op = PEqualNP.CircuitLowerBounds.GateOp.not → i = j) → (∀ x : Fin 8 → Bool, PEqualNP.CircuitLowerBounds.Circuit.eval ⟨gates, o⟩ (List.ofFn x) = decide (∃ i < ([0, 3, 1, 4, 0, 5, 1, 5, 3, 5, 0, 6, 1, 6, 3, 6, 5, 6, 0, 7, 2, 7, 3, 7, 4, 7, 5, 7] : List ℕ).length / 2, (List.ofFn x).getD (([0, 3, 1, 4, 0, 5, 1, 5, 3, 5, 0, 6, 1, 6, 3, 6, 5, 6, 0, 7, 2, 7, 3, 7, 4, 7, 5, 7] : List ℕ).getD (2 * i) 0) false = true ∧ (List.ofFn x).getD (([0, 3, 1, 4, 0, 5, 1, 5, 3, 5, 0, 6, 1, 6, 3, 6, 5, 6, 0, 7, 2, 7, 3, 7, 4, 7, 5, 7] : List ℕ).getD (2 * i + 1) 0) false = true)) → ∃ (gates' : List PEqualNP.CircuitLowerBounds.Gate) (o' : ℕ), (∀ g ∈ gates', (g.op = PEqualNP.CircuitLowerBounds.GateOp.and ∨ g.op = PEqualNP.CircuitLowerBounds.GateOp.or) ∧ g.inputs.length ≤ 2) ∧ gates'.length ≤ gates.length ∧ ∀ x : Fin 8 → Bool, PEqualNP.CircuitLowerBounds.Circuit.eval ⟨gates', o'⟩ (List.ofFn x) = decide (∃ i < ([0, 3, 1, 4, 0, 5, 1, 5, 3, 5, 0, 6, 1, 6, 3, 6, 5, 6, 0, 7, 2, 7, 3, 7, 4, 7, 5, 7] : List ℕ).length / 2, (List.ofFn x).getD (([0, 3, 1, 4, 0, 5, 1, 5, 3, 5, 0, 6, 1, 6, 3, 6, 5, 6, 0, 7, 2, 7, 3, 7, 4, 7, 5, 7] : List ℕ).getD (2 * i) 0) false = true ∧ (List.ofFn x).getD (([0, 3, 1, 4, 0, 5, 1, 5, 3, 5, 0, 6, 1, 6, 3, 6, 5, 6, 0, 7, 2, 7, 3, 7, 4, 7, 5, 7] : List ℕ).getD (2 * i + 1) 0) false = true))) ↔\n    ∃ (gs : List Gate) (o : ℕ),\n      (∀ g ∈ gs, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2) ∧\n      (∀ i j : Fin gs.length, (gs.get i).op = .not → (gs.get j).op = .not → i = j) ∧\n      (∀ x : Fin 8 → Bool, Circuit.eval ⟨gs, o⟩ (List.ofFn x) = target x) ∧\n      ¬ HasMonotoneImplementation gs.length ∧\n      8 ≤ gs.length ∧ gs.length < 15 ∧\n      (∃ m ∈ edgeMasks, (forcedCircuit false gs o).eval (List.ofFn (inputMask m)) = false) ∧\n      (∃ m ∈ independentMasks, (forcedCircuit true gs o).eval (List.ofFn (inputMask m)) = true) := by\n  constructor\n  · intro answer\n    by_contra h\n    apply answer\n    intro gs o legal oneNot computes\n    change HasMonotoneImplementation gs.length\n    by_contra improves\n    have hlo := improvement_requires_eight gs o legal computes improves\n    obtain ⟨hhi, hf, ht⟩ := improvement_constraints gs o legal computes improves\n    exact h ⟨gs, o, legal, oneNot, computes, improves, hlo, hhi, hf, ht⟩\n  · rintro ⟨gs, o, legal, oneNot, computes, improves, _⟩ positive\n    exact improves (positive gs o legal oneNot computes)\n\nend PEqualNP.Outside.L_meta_33225\n",
  "lean_sha256": "04a2d318fe7d99e3683c0320c517cefb8f747451914fbbc38f16e37414a3ebfd",
  "build": {
    "command": "lake build PEqualNP.Outside.L_meta_33225",
    "exit": 0,
    "seconds": 53.14
  },
  "axioms": [
    "propext",
    "Classical.choice",
    "Quot.sound"
  ],
  "upstream_commit": "eb3fabd5a99d6b27e3e5b41f6506c5756d5c9a10",
  "approach": "The row asks for a strict size improvement by a circuit with at most one NOT. I followed its counterexample sketch. I evaluated all 256 assignments: the empty input and singletons lose, 14 two-vertex inputs win, and eight maximal independent sets account for all 29 losing inputs. Vertices 0, 3 and 5 together with the disjunction of 6 and 7 give a two-of-four test for the dense part. Adding the edges involving 1, 2 and 4 yields a 15-gate monotone circuit, checked in Lean for every assignment. Sharing one more disjunction yields a 14-gate circuit whose only error is accepting the input with exactly 1 and 7 set. I checked this characterization in Lean. A search over biclique covers with disjoint OR decompositions and shared intermediates also attained 15. Formula enumeration found no benefit from one NOT on four vertices or on five vertices through ten gates. Removing vertices 2 and 4 gave a six-input restriction for which SAT synthesis found a 10-gate monotone circuit. I inspected the sibling L_meta_33222 restriction and gate-elimination method. Its lower bound applies to a different graph. Tracing the target circuit backward shows that all eight inputs are needed and a live NOT adds no new dependency. The checked reduction limits any witness to 8–14 gates and requires failures on both an edge mask when NOT is forced false and an independent-set mask when it is forced true. I searched using SAT over topologically ordered gate descriptions, simulated candidate models on all assignments, and tried local rewiring of the 14-gate near match. A SAT query with up to four changed gates around that near match and one NOT was unsatisfiable even on the initial 32 inputs. The normalized eight-gate SAT instance was also unsatisfiable. The larger searches did not establish whether an exact improving witness exists or certify the monotone optimum. The partial module built and passed leanchecker and the axiom audit. Local peak RSS was 7.86 GiB. Lean with its 6000 MB memory cap failed even on a scratch file containing only the two required imports. The row did not supply a level.",
  "reason": "missing_lemma",
  "skipped": []
}
