{
  "unit": "L-meta-32468",
  "title": "Can one NOT gate shorten edge detection on 0-3 1-4 2-4 0-5 1-5 2-5 0-6 1-6 3-6 4-6 1-7 2-7 4-7 5-7 6-7?",
  "level": null,
  "weight": 55,
  "state": "open",
  "file": "lean/PEqualNP/Outside/L_meta_32468.lean",
  "module": "PEqualNP.Outside.L_meta_32468",
  "imports": [
    "PEqualNP.Defs"
  ],
  "statement_sha256": "6b92f643a27d51232e4fe07146c49cfe4d8db92588b2da725d44a0a0e8f801d7",
  "proved": false,
  "lean": "import Mathlib\nimport PEqualNP.Defs\n\nnamespace PEqualNP.Outside.L_meta_32468\n\nopen PEqualNP.CircuitLowerBounds\n\ndef target (x : Fin 8 → Bool) : Bool :=\n  decide (∃ i < ([0, 3, 1, 4, 2, 4, 0, 5, 1, 5, 2, 5, 0, 6, 1, 6, 3, 6, 4, 6, 1, 7, 2, 7, 4, 7, 5, 7, 6, 7] : List ℕ).length / 2, (List.ofFn x).getD (([0, 3, 1, 4, 2, 4, 0, 5, 1, 5, 2, 5, 0, 6, 1, 6, 3, 6, 4, 6, 1, 7, 2, 7, 4, 7, 5, 7, 6, 7] : List ℕ).getD (2 * i) 0) false = true ∧ (List.ofFn x).getD (([0, 3, 1, 4, 2, 4, 0, 5, 1, 5, 2, 5, 0, 6, 1, 6, 3, 6, 4, 6, 1, 7, 2, 7, 4, 7, 5, 7, 6, 7] : List ℕ).getD (2 * i + 1) 0) false = true)\n\ndef monotoneWitness : List Gate :=\n  [⟨.or, [5, 6]⟩, ⟨.or, [7, 1]⟩, ⟨.or, [9, 2]⟩, ⟨.or, [9, 0]⟩, ⟨.or, [6, 0]⟩, ⟨.and, [8, 11]⟩, ⟨.or, [10, 6]⟩, ⟨.and, [3, 12]⟩, ⟨.or, [2, 1]⟩, ⟨.and, [14, 4]⟩, ⟨.or, [7, 5]⟩, ⟨.or, [17, 13]⟩, ⟨.and, [18, 16]⟩, ⟨.or, [15, 19]⟩, ⟨.or, [20, 21]⟩]\n\ntheorem monotoneWitness_legal : ∀ g ∈ monotoneWitness,\n    (g.op = .and ∨ g.op = .or) ∧ g.inputs.length ≤ 2 := by\n  intro g hg\n  simp only [monotoneWitness, List.mem_cons, List.not_mem_nil, or_false] at hg\n  rcases hg with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> simp\n\nset_option maxRecDepth 16000 in\nset_option maxHeartbeats 0 in\ntheorem monotoneWitness_eval : ∀ x : Fin 8 → Bool,\n    Circuit.eval ⟨monotoneWitness, 22⟩ (List.ofFn x) = target x := by\n  decide +kernel\n\nabbrev Assignment := Fin 8 → Bool\nabbrev Wire := Assignment → Bool\n\ndef readWire (w : List Wire) (i : ℕ) : Wire :=\n  fun x => (w.map fun f => f x).getD i false\n\ndef gateValue (w : List Wire) (g : Gate) : Wire :=\n  fun x => g.op.eval (g.inputs.map (fun i => readWire w i x))\n\ndef binaryCharge (g : Gate) : ℕ :=\n  match g.op with\n  | .not => 0\n  | _ => 1\n\ndef Determines (s : Finset Wire) (f : Wire) : Prop :=\n  ∀ x y, (∀ u ∈ s, u x = u y) → f x = f y\n\ndef Supported (w : List Wire) (k : ℕ) (f : Wire) : Prop :=\n  ∃ s : Finset Wire, (∀ u ∈ s, u ∈ w) ∧ s.card ≤ k ∧ Determines s f\n\ntheorem readWire_support (w : List Wire) (i : ℕ) : Supported w 1 (readWire w i) := by\n  classical\n  by_cases h : i < w.length\n  · refine ⟨{w[i]}, ?_, by simp, ?_⟩\n    · intro u hu\n      have e : u = w[i] := Finset.mem_singleton.mp hu\n      exact e ▸ List.getElem_mem h\n    · intro x y a\n      simpa [readWire, h] using a w[i] (Finset.mem_singleton_self _)\n  · refine ⟨∅, by simp, by simp, ?_⟩\n    intro x y _\n    simp [readWire, Nat.le_of_not_lt h]\n\ntheorem constant_support (w : List Wire) (k : ℕ) (b : Bool) :\n    Supported w k (fun _ => b) := by\n  exact ⟨∅, by simp, by simp, fun _ _ _ => rfl⟩\n\ntheorem unary_support (w : List Wire) (i : ℕ) (k : ℕ) (hk : 1 ≤ k) (op : Bool → Bool) :\n    Supported w k (fun x => op (readWire w i x)) := by\n  obtain ⟨s, live, card, h⟩ := readWire_support w i\n  exact ⟨s, live, card.trans hk, fun x y e => congrArg op (h x y e)⟩\n\ntheorem binary_support (w : List Wire) (i j : ℕ) (op : Bool → Bool → Bool) :\n    Supported w 2 (fun x => op (readWire w i x) (readWire w j x)) := by\n  classical\n  obtain ⟨s, slive, scard, hs⟩ := readWire_support w i\n  obtain ⟨t, tlive, tcard, ht⟩ := readWire_support w j\n  refine ⟨s ∪ t, ?_, (Finset.card_union_le s t).trans (by omega), ?_⟩\n  · intro u hu\n    exact (Finset.mem_union.mp hu).elim (slive u) (tlive u)\n  · intro x y e\n    change op (readWire w i x) (readWire w j x) = op (readWire w i y) (readWire w j y)\n    rw [hs x y (fun u hu => e u (Finset.mem_union_left _ hu)),\n      ht x y (fun u hu => e u (Finset.mem_union_right _ hu))]\n\ntheorem gateValue_support (w : List Wire) (g : Gate)\n    (hg : (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2) :\n    Supported w (binaryCharge g + 1) (gateValue w g) := by\n  obtain ⟨op, args⟩ := g\n  obtain ⟨hop, hl⟩ := hg\n  change op = .and ∨ op = .or ∨ op = .not at hop\n  change args.length ≤ 2 at hl\n  rcases args with _ | ⟨i, _ | ⟨j, _ | ⟨k, rest⟩⟩⟩\n  · exact constant_support w _ (op.eval [])\n  · rcases hop with rfl | rfl | rfl\n    · rw [show gateValue w ⟨.and, [i]⟩ = readWire w i by funext x; simp [gateValue, GateOp.eval]]\n      exact unary_support w i 2 (by decide) id\n    · rw [show gateValue w ⟨.or, [i]⟩ = readWire w i by funext x; simp [gateValue, GateOp.eval]]\n      exact unary_support w i 2 (by decide) id\n    · exact unary_support w i 1 (by decide) Bool.not\n  · rcases hop with rfl | rfl | rfl\n    · rw [show gateValue w ⟨.and, [i, j]⟩ = (fun x => readWire w i x && readWire w j x) by\n        funext x\n        simp [gateValue, GateOp.eval]]\n      exact binary_support w i j Bool.and\n    · rw [show gateValue w ⟨.or, [i, j]⟩ = (fun x => readWire w i x || readWire w j x) by\n        funext x\n        simp [gateValue, GateOp.eval]]\n      exact binary_support w i j Bool.or\n    · exact unary_support w i 1 (by decide) Bool.not\n  · simp at hl\n\ntheorem fold_support (gs : List Gate) (o : ℕ)\n    (legal : ∀ g ∈ gs, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2)\n    (w : List Wire) :\n    Supported w ((gs.map binaryCharge).sum + 1)\n      (readWire (gs.foldl (fun us g => us ++ [gateValue us g]) w) o) := by\n  classical\n  induction gs generalizing w with\n  | nil => exact readWire_support w o\n  | cons g gs ih =>\n    let new := gateValue w g\n    obtain ⟨s, stock, hcard, hdet⟩ :=\n      ih (fun h hh => legal h (List.mem_cons_of_mem _ hh)) (w ++ [new])\n    change Supported w (binaryCharge g + (gs.map binaryCharge).sum + 1)\n      (readWire (gs.foldl (fun us g => us ++ [gateValue us g]) (w ++ [new])) o)\n    by_cases hn : new ∈ s\n    · obtain ⟨t, tstock, tcard, tdet⟩ := gateValue_support w g (legal g (by simp))\n      refine ⟨s.erase new ∪ t, ?_, ?_, ?_⟩\n      · intro u hu\n        rcases Finset.mem_union.mp hu with h | h\n        · rcases List.mem_append.mp (stock u (Finset.mem_of_mem_erase h)) with hw | hw\n          · exact hw\n          · exact (Finset.ne_of_mem_erase h (List.mem_singleton.mp hw)).elim\n        · exact tstock _ h\n      · have hpos := Finset.card_pos.mpr ⟨new, hn⟩\n        have hle := Finset.card_union_le (s.erase new) t\n        rw [Finset.card_erase_of_mem hn] at hle\n        omega\n      · intro x y hxy\n        apply hdet x y\n        intro u hu\n        by_cases e : u = new\n        · subst u\n          exact tdet x y (fun v hv => hxy v (Finset.mem_union_right _ hv))\n        · exact hxy u (Finset.mem_union_left _ (Finset.mem_erase.mpr ⟨e, hu⟩))\n    · refine ⟨s, ?_, by omega, hdet⟩\n      intro u hu\n      rcases List.mem_append.mp (stock u hu) with hw | hw\n      · exact hw\n      · exact (hn ((List.mem_singleton.mp hw) ▸ hu)).elim\n\ntheorem fold_eval (gs : List Gate) (x : Assignment) (w : List Wire) :\n    (gs.foldl (fun us g => us ++ [gateValue us g]) w).map (fun f => f x) =\n      gs.foldl (fun bs g => bs ++ [g.op.eval (g.inputs.map (fun i => bs.getD i false))])\n        (w.map fun f => f x) := by\n  induction gs generalizing w with\n  | nil => rfl\n  | cons g gs ih =>\n    simp only [List.foldl_cons, ih, List.map_append, List.map_cons, List.map_nil]\n    rfl\n\ndef partner (i : Fin 8) : Fin 8 :=\n  ([3, 4, 4, 0, 1, 0, 0, 1] : List (Fin 8)).getD i.val 0\n\ndef singletonInput (i : Fin 8) : Assignment := fun j => decide (j = partner i)\n\ndef edgeInput (i : Fin 8) : Assignment := fun j => decide (j = partner i ∨ j = i)\n\ntheorem edgeDistinguishes : ∀ i : Fin 8, target (singletonInput i) ≠ target (edgeInput i) := by\n  decide +kernel\n\ntheorem allInputsMatter : ∀ i : Fin 8, ∃ x y : Assignment,\n    (∀ j : Fin 8, j ≠ i → x j = y j) ∧ target x ≠ target y := by\n  intro i\n  refine ⟨singletonInput i, edgeInput i, ?_, edgeDistinguishes i⟩\n  intro j ne\n  simp [singletonInput, edgeInput, ne]\n\ntheorem target_binary_lower_bound (gs : List Gate) (o : ℕ)\n    (legal : ∀ g ∈ gs, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2)\n    (computes : ∀ x : Assignment, Circuit.eval ⟨gs, o⟩ (List.ofFn x) = target x) :\n    7 ≤ (gs.map binaryCharge).sum := by\n  classical\n  let proj : Fin 8 → Wire := fun i x => x i\n  let stock := List.ofFn proj\n  obtain ⟨s, hstock, hcard, hdet⟩ := fold_support gs o legal stock\n  have eval_eq (x : Assignment) :\n      readWire (gs.foldl (fun us g => us ++ [gateValue us g]) stock) o x = target x := by\n    unfold readWire\n    rw [fold_eval]\n    have hmap : stock.map (fun f => f x) = List.ofFn x := by\n      simp [stock, proj]\n    rw [hmap]\n    exact computes x\n  have all (i : Fin 8) : proj i ∈ s := by\n    by_contra absent\n    obtain ⟨x, y, same, different⟩ := allInputsMatter i\n    apply different\n    rw [← eval_eq x, ← eval_eq y]\n    apply hdet x y\n    intro u hu\n    obtain ⟨j, rfl⟩ := List.mem_ofFn.mp (hstock u hu)\n    exact same j (fun e => absent (e ▸ hu))\n  have inj : Function.Injective proj := by\n    intro i j h\n    by_contra e\n    have hvalue := congrFun h (fun k => decide (i = k))\n    simpa [proj, e] using hvalue\n  have lower : 8 ≤ s.card := by\n    let embed : Fin 8 ↪ Wire := ⟨proj, inj⟩\n    have sub : (Finset.univ.map embed) ⊆ s := by\n      intro a ha\n      obtain ⟨b, _, rfl⟩ := Finset.mem_map.mp ha\n      exact all b\n    simpa [embed] using Finset.card_le_card sub\n  omega\n\ntheorem binaryCharge_le (g : Gate) : binaryCharge g ≤ 1 := by\n  cases g\n  rename_i op inputs\n  cases op <;> simp [binaryCharge]\n\ntheorem binarySum_le (gs : List Gate) : (gs.map binaryCharge).sum ≤ gs.length := by\n  induction gs with\n  | nil => simp\n  | cons g gs ih =>\n    have h := binaryCharge_le g\n    simp only [List.map_cons, List.sum_cons, List.length_cons]\n    omega\n\ntheorem binarySum_lt (gs : List Gate) (h : ∃ g ∈ gs, g.op = .not) :\n    (gs.map binaryCharge).sum < gs.length := by\n  induction gs with\n  | nil => simp at h\n  | cons g gs ih =>\n    obtain ⟨n, hn, hop⟩ := h\n    simp only [List.map_cons, List.sum_cons, List.length_cons]\n    rcases List.mem_cons.mp hn with rfl | hn\n    · have hzero : binaryCharge n = 0 := by simp [binaryCharge, hop]\n      have hle := binarySum_le gs\n      omega\n    · have hgt := ih ⟨n, hn, hop⟩\n      have hle := binaryCharge_le g\n      omega\n\ntheorem counterexample_restriction (gates : List Gate) (o : ℕ)\n    (legal : ∀ g ∈ gates, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2)\n    (computes : ∀ x : Fin 8 → Bool, Circuit.eval ⟨gates, o⟩ (List.ofFn x) = target x)\n    (noReplacement : ¬ ∃ (other : List Gate) (out : ℕ),\n      (∀ g ∈ other, (g.op = .and ∨ g.op = .or) ∧ g.inputs.length ≤ 2) ∧\n      other.length ≤ gates.length ∧\n      ∀ x : Fin 8 → Bool, Circuit.eval ⟨other, out⟩ (List.ofFn x) = target x) :\n    8 ≤ gates.length ∧ gates.length < 15 ∧ ∃ g ∈ gates, g.op = .not := by\n  have hnot : ∃ g ∈ gates, g.op = .not := by\n    by_contra! h\n    refine noReplacement ⟨gates, o, ?_, le_rfl, computes⟩\n    intro g hg\n    obtain ⟨hop, hlen⟩ := legal g hg\n    rcases hop with ha | ho | hn\n    · exact ⟨Or.inl ha, hlen⟩\n    · exact ⟨Or.inr ho, hlen⟩\n    · exact (h g hg hn).elim\n  refine ⟨?_, ?_, hnot⟩\n  · have hsum := target_binary_lower_bound gates o legal computes\n    have hlt := binarySum_lt gates hnot\n    omega\n  · by_contra! h\n    exact noReplacement ⟨monotoneWitness, 22, monotoneWitness_legal, h, monotoneWitness_eval⟩\n\ndef extremal (b : Bool) (g : Gate) : Gate :=\n  match g.op with\n  | .not => ⟨if b then .and else .or, []⟩\n  | _ => g\n\ndef WireOrder (b original replaced : Bool) : Prop :=\n  if b then original ≤ replaced else replaced ≤ original\n\ntheorem wireOrder_refl (b a : Bool) : WireOrder b a a := by\n  cases b <;> simp [WireOrder]\n\ntheorem wireOrder_extreme (b a : Bool) : WireOrder b a b := by\n  cases b <;> cases a <;> simp [WireOrder]\n\ntheorem extrema_legal (b : Bool) (gs : List Gate)\n    (legal : ∀ g ∈ gs, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2) :\n    ∀ g ∈ gs.map (extremal b), (g.op = .and ∨ g.op = .or) ∧ g.inputs.length ≤ 2 := by\n  intro g hg\n  obtain ⟨v, hv, rfl⟩ := List.mem_map.mp hg\n  rcases legal v hv with ⟨h | h | h, hlen⟩\n  · simpa [extremal, h] using hlen\n  · simpa [extremal, h] using hlen\n  · cases b <;> simp [extremal, h]\n\ntheorem wireOrder_getD (b : Bool) {as bs : List Bool}\n    (h : List.Forall₂ (WireOrder b) as bs) (i : ℕ) :\n    WireOrder b (as.getD i false) (bs.getD i false) := by\n  induction h generalizing i with\n  | nil => exact wireOrder_refl b false\n  | cons hr _ ih =>\n    cases i with\n    | zero => simpa using hr\n    | succ i => simpa only [List.getD_cons_succ] using ih i\n\ntheorem wireOrder_maps (b : Bool) {as bs : List Bool}\n    (h : List.Forall₂ (WireOrder b) as bs) (is : List ℕ) :\n    List.Forall₂ (WireOrder b) (is.map (fun i => as.getD i false))\n      (is.map (fun i => bs.getD i false)) := by\n  induction is with\n  | nil => exact .nil\n  | cons i is ih => exact .cons (wireOrder_getD b h i) ih\n\ntheorem wireOrder_all_any (b : Bool) {as bs : List Bool}\n    (h : List.Forall₂ (WireOrder b) as bs) :\n    WireOrder b (as.all id) (bs.all id) ∧ WireOrder b (as.any id) (bs.any id) := by\n  induction h with\n  | nil => exact ⟨wireOrder_refl b true, wireOrder_refl b false⟩\n  | @cons a a' as bs hd ht ih =>\n    obtain ⟨ha, ho⟩ := ih\n    constructor\n    · change WireOrder b (a && as.all id) (a' && bs.all id)\n      cases b <;> cases a <;> cases a' <;> simp_all [WireOrder, show (true : Bool) ≤ false ↔ False by decide]\n    · change WireOrder b (a || as.any id) (a' || bs.any id)\n      cases b <;> cases a <;> cases a' <;> simp_all [WireOrder, show (true : Bool) ≤ false ↔ False by decide]\n\ntheorem extremal_next (b : Bool) (g : Gate)\n    (hg : g.op = .and ∨ g.op = .or ∨ g.op = .not) {as bs : List Bool}\n    (h : List.Forall₂ (WireOrder b) as bs) :\n    WireOrder b (g.op.eval (g.inputs.map fun i => as.getD i false))\n      ((extremal b g).op.eval ((extremal b g).inputs.map fun i => bs.getD i false)) := by\n  have hm := wireOrder_all_any b (wireOrder_maps b h g.inputs)\n  rcases hg with e | e | e\n  · simpa [extremal, e, GateOp.eval] using hm.1\n  · simpa [extremal, e, GateOp.eval] using hm.2\n  · have he : (extremal b g).op.eval ((extremal b g).inputs.map fun i => bs.getD i false) = b := by\n      cases b <;> simp [extremal, e, GateOp.eval]\n    rw [he]\n    exact wireOrder_extreme b _\n\ntheorem extremal_fold (b : Bool) (gs : List Gate)\n    (legal : ∀ g ∈ gs, g.op = .and ∨ g.op = .or ∨ g.op = .not) {as bs : List Bool}\n    (h : List.Forall₂ (WireOrder b) as bs) :\n    List.Forall₂ (WireOrder b)\n      (gs.foldl (fun w g => w ++ [g.op.eval (g.inputs.map fun i => w.getD i false)]) as)\n      ((gs.map (extremal b)).foldl\n        (fun w g => w ++ [g.op.eval (g.inputs.map fun i => w.getD i false)]) bs) := by\n  induction gs generalizing as bs with\n  | nil => exact h\n  | cons g gs ih =>\n    have out := extremal_next b g (legal g (by simp)) h\n    exact ih (fun v hv => legal v (List.mem_cons_of_mem _ hv))\n      (List.rel_append h (.cons out .nil))\n\ntheorem extremal_eval (b : Bool) (gs : List Gate) (o : ℕ)\n    (legal : ∀ g ∈ gs, g.op = .and ∨ g.op = .or ∨ g.op = .not) (x : Assignment) :\n    WireOrder b (Circuit.eval ⟨gs, o⟩ (List.ofFn x))\n      (Circuit.eval ⟨gs.map (extremal b), o⟩ (List.ofFn x)) := by\n  exact wireOrder_getD b\n    (extremal_fold b gs legal (List.forall₂_same.mpr fun a _ => wireOrder_refl b a)) o\n\ntheorem extremal_counterexample (gs : List Gate) (o : ℕ)\n    (legal : ∀ g ∈ gs, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2)\n    (computes : ∀ x : Assignment, Circuit.eval ⟨gs, o⟩ (List.ofFn x) = target x)\n    (noReplacement : ¬ ∃ (other : List Gate) (out : ℕ),\n      (∀ g ∈ other, (g.op = .and ∨ g.op = .or) ∧ g.inputs.length ≤ 2) ∧\n      other.length ≤ gs.length ∧\n      ∀ x : Assignment, Circuit.eval ⟨other, out⟩ (List.ofFn x) = target x) :\n    ∀ b : Bool, ∃ x : Assignment,\n      target x = !b ∧ Circuit.eval ⟨gs.map (extremal b), o⟩ (List.ofFn x) = b := by\n  intro b\n  have hnot : ¬ ∀ x : Assignment, Circuit.eval ⟨gs.map (extremal b), o⟩ (List.ofFn x) = target x :=\n    fun h => noReplacement ⟨_, o, extrema_legal b gs legal, by simp, h⟩\n  obtain ⟨x, hx⟩ := not_forall.mp hnot\n  refine ⟨x, ?_⟩\n  have hb := extremal_eval b gs o (fun g hg => (legal g hg).1) x\n  rw [computes x] at hb\n  cases b <;>\n    cases hT : target x <;>\n    cases hE : Circuit.eval ⟨gs.map (extremal _), o⟩ (List.ofFn x) <;>\n    simp_all [WireOrder, show (true : Bool) ≤ false ↔ False by decide]\n\ndef maskInput (mask : ℕ) : Assignment := fun i => mask.testBit i.val\n\ndef edgeMasks : List ℕ := [9, 18, 20, 33, 34, 36, 65, 66, 72, 80, 130, 132, 144, 160, 192]\n\ndef independentMasks : List ℕ := [7, 14, 17, 56, 68, 96, 129, 136]\n\nset_option maxRecDepth 16000 in\nset_option maxHeartbeats 0 in\ntheorem edgeBelow : ∀ x : Assignment, target x = true →\n    ∃ m ∈ edgeMasks, target (maskInput m) = true ∧ ∀ i, maskInput m i ≤ x i := by\n  decide +kernel\n\nset_option maxRecDepth 16000 in\nset_option maxHeartbeats 0 in\ntheorem independentAbove : ∀ x : Assignment, target x = false →\n    ∃ m ∈ independentMasks, target (maskInput m) = false ∧ ∀ i, x i ≤ maskInput m i := by\n  decide +kernel\n\ntheorem monotone_eval (gs : List Gate) (o : ℕ)\n    (legal : ∀ g ∈ gs, g.op = .and ∨ g.op = .or) {x y : Assignment}\n    (h : ∀ i, x i ≤ y i) :\n    Circuit.eval ⟨gs, o⟩ (List.ofFn x) ≤ Circuit.eval ⟨gs, o⟩ (List.ofFn y) := by\n  have hxy : List.Forall₂ (WireOrder true) (List.ofFn x) (List.ofFn y) := by\n    apply List.forall₂_of_length_eq_of_get\n    · simp\n    · intro i hi hj\n      simp only [List.get_eq_getElem, List.getElem_ofFn]\n      exact h ⟨i, by simpa only [List.length_ofFn] using hi⟩\n  have same : gs.map (extremal true) = gs := by\n    induction gs with\n    | nil => rfl\n    | cons g tail ih =>\n      have eg : extremal true g = g := by\n        rcases legal g (by simp) with e | e <;> simp [extremal, e]\n      simp only [List.map_cons, eg, ih (fun v hv => legal v (List.mem_cons_of_mem _ hv))]\n  have hs := extremal_fold true gs\n    (fun g hg => (legal g hg).imp_right Or.inl) hxy\n  rw [same] at hs\n  exact wireOrder_getD true hs o\n\ntheorem extremal_mask_obstructions (gs : List Gate) (o : ℕ)\n    (legal : ∀ g ∈ gs, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2)\n    (computes : ∀ x : Assignment, Circuit.eval ⟨gs, o⟩ (List.ofFn x) = target x)\n    (noReplacement : ¬ ∃ (other : List Gate) (out : ℕ),\n      (∀ g ∈ other, (g.op = .and ∨ g.op = .or) ∧ g.inputs.length ≤ 2) ∧\n      other.length ≤ gs.length ∧\n      ∀ x : Assignment, Circuit.eval ⟨other, out⟩ (List.ofFn x) = target x) :\n    (∃ e ∈ edgeMasks, Circuit.eval ⟨gs.map (extremal false), o⟩ (List.ofFn (maskInput e)) = false) ∧\n    (∃ i ∈ independentMasks,\n      Circuit.eval ⟨gs.map (extremal true), o⟩ (List.ofFn (maskInput i)) = true) := by\n  have ht := extremal_counterexample gs o legal computes noReplacement\n  have hm (b : Bool) {x y : Assignment} (h : ∀ i, x i ≤ y i) :=\n    monotone_eval (gs.map (extremal b)) o (fun g hg => (extrema_legal b gs legal g hg).1) h\n  constructor\n  · obtain ⟨x, hx, hw⟩ := ht false\n    obtain ⟨e, he, _, hle⟩ := edgeBelow x hx\n    refine ⟨e, he, ?_⟩\n    have hl := hm false hle\n    rw [hw] at hl\n    exact Bool.eq_false_of_le_false hl\n  · obtain ⟨x, hx, hw⟩ := ht true\n    obtain ⟨i, hi, _, hle⟩ := independentAbove x hx\n    refine ⟨i, hi, ?_⟩\n    have hl := hm true hle\n    rw [hw] at hl\n    exact Bool.eq_true_of_true_le hl\n\ndef Fits (gs : List Gate) : Prop :=\n  ∀ g ∈ gs, (g.op = .and ∨ g.op = .or ∨ g.op = .not) ∧ g.inputs.length ≤ 2\n\ndef OneNot (gs : List Gate) : Prop :=\n  ∀ i j : Fin gs.length, (gs.get i).op = .not → (gs.get j).op = .not → i = j\n\ndef Computes (gs : List Gate) (o : ℕ) : Prop :=\n  ∀ x : Assignment, Circuit.eval ⟨gs, o⟩ (List.ofFn x) = target x\n\ndef Replaceable (gs : List Gate) : Prop :=\n  ∃ (other : List Gate) (out : ℕ),\n    (∀ g ∈ other, (g.op = .and ∨ g.op = .or) ∧ g.inputs.length ≤ 2) ∧\n    other.length ≤ gs.length ∧ Computes other out\n\ndef RestrictedCandidate (gs : List Gate) (o : ℕ) : Prop :=\n  Fits gs ∧ OneNot gs ∧ Computes gs o ∧ ¬ Replaceable gs ∧\n  8 ≤ gs.length ∧ gs.length < 15 ∧ (∃ g ∈ gs, g.op = .not) ∧\n  (∃ e ∈ edgeMasks, Circuit.eval ⟨gs.map (extremal false), o⟩ (List.ofFn (maskInput e)) = false) ∧\n  (∃ i ∈ independentMasks,\n    Circuit.eval ⟨gs.map (extremal true), o⟩ (List.ofFn (maskInput i)) = true)\n\ntheorem search_equivalence :\n    (¬ (∀ (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, 2, 4, 0, 5, 1, 5, 2, 5, 0, 6, 1, 6, 3, 6, 4, 6, 1, 7, 2, 7, 4, 7, 5, 7, 6, 7] : List ℕ).length / 2, (List.ofFn x).getD (([0, 3, 1, 4, 2, 4, 0, 5, 1, 5, 2, 5, 0, 6, 1, 6, 3, 6, 4, 6, 1, 7, 2, 7, 4, 7, 5, 7, 6, 7] : List ℕ).getD (2 * i) 0) false = true ∧ (List.ofFn x).getD (([0, 3, 1, 4, 2, 4, 0, 5, 1, 5, 2, 5, 0, 6, 1, 6, 3, 6, 4, 6, 1, 7, 2, 7, 4, 7, 5, 7, 6, 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, 2, 4, 0, 5, 1, 5, 2, 5, 0, 6, 1, 6, 3, 6, 4, 6, 1, 7, 2, 7, 4, 7, 5, 7, 6, 7] : List ℕ).length / 2, (List.ofFn x).getD (([0, 3, 1, 4, 2, 4, 0, 5, 1, 5, 2, 5, 0, 6, 1, 6, 3, 6, 4, 6, 1, 7, 2, 7, 4, 7, 5, 7, 6, 7] : List ℕ).getD (2 * i) 0) false = true ∧ (List.ofFn x).getD (([0, 3, 1, 4, 2, 4, 0, 5, 1, 5, 2, 5, 0, 6, 1, 6, 3, 6, 4, 6, 1, 7, 2, 7, 4, 7, 5, 7, 6, 7] : List ℕ).getD (2 * i + 1) 0) false = true))) ↔\n      ∃ (gs : List Gate) (o : ℕ), RestrictedCandidate gs o := by\n  change (¬ ∀ (gs : List Gate) (o : ℕ), Fits gs → OneNot gs → Computes gs o → Replaceable gs) ↔ _\n  simp only [not_forall]\n  constructor\n  · rintro ⟨gs, o, hfit, hone, he, hr⟩\n    obtain ⟨hmin, hmax, hn⟩ := counterexample_restriction gs o hfit he hr\n    exact ⟨gs, o, hfit, hone, he, hr, hmin, hmax, hn, extremal_mask_obstructions gs o hfit he hr⟩\n  · rintro ⟨gs, o, hfit, hone, he, hr, _⟩\n    exact ⟨gs, o, hfit, hone, he, hr⟩\n\nend PEqualNP.Outside.L_meta_32468\n",
  "lean_sha256": "1ddf98076fa55f79e61c5949d085d2e654214772d677e00b9d22ac31703e53ce",
  "build": {
    "command": "lake build PEqualNP.Outside.L_meta_32468",
    "exit": 0,
    "seconds": 144
  },
  "axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "upstream_commit": "eb3fabd5a99d6b27e3e5b41f6506c5756d5c9a10",
  "approach": "The first candidate was open. The row did not supply a level. I used the pinned Lean 4.36.0 and Mathlib checkout and followed the sketch by looking for a circuit with one NOT that beats the best AND/OR circuit.\n\nI evaluated all 256 input masks. The output is false on the empty mask and singletons, true on precisely the stated 15 weight-two masks, and true on 231 masks in total. The maximal independent masks are 7, 14, 17, 56, 68, 96, 129 and 136, with vertex 0 the least significant bit. On the induced path 3–0–5–2, the circuit x0 ∧ (x3 ∨ x5), x2 ∧ x5, then OR uses four gates. The small SAT models found no saving from a NOT on that path, the four five-vertex restrictions, or the six-vertex restriction on {0,1,2,3,6,7}.\n\nI used sibling units' upper-witness and live-wire methods. Biclique factoring with shared OR gates and truth-table-guided search both produced 15-gate monotone circuits. The partial Lean file verifies one such circuit on every assignment. It also shows that eight essential inputs require at least seven AND/OR gates even with NOT gates, and that a counterexample must use 8–14 gates and fail replacement of its NOT by each constant. The false replacement must fail on an edge and the true replacement on a maximal independent set.\n\nI tried ordered SAT encodings, tests requiring a live NOT, and rewiring neighborhoods. A 13-live-gate monotone near miss differed only on the independent pair {2,6}. The circuit search produced no certified strict improvement, and the broad SAT runs did not settle the optimum. The partial file passed lake build, Lean kernel replay with leanchecker, and a scratch axiom check. I worked as the sole agent. No submissions, acceptances or awarded points resulted, and there was no reported competition cost.",
  "reason": "missing_lemma",
  "skipped": []
}
