{
  "gap": "L-meta-1406",
  "base_commit": "605dc84be40929b8c04c6b206c363d69dc369d12",
  "path": "lean/PEqualNP/Outside/L_meta_1406.lean",
  "status": "checked",
  "source": "import Mathlib\nimport PEqualNP.Defs\n\nopen PEqualNP.CircuitLowerBounds\n\nnamespace PEqualNP.Outside.L_meta_1406\n\ndef value (w : List Bool) (g : Gate) : Bool :=\n  g.op.eval (g.inputs.map fun j => w.getD j false)\n\ndef step (w : List Bool) (g : Gate) : List Bool := w ++ [value w g]\n\ndef run (gs : List Gate) (x : List Bool) : List Bool := gs.foldl step x\n\nlemma wires_run (gs : List Gate) (o : ℕ) (x : List Bool) :\n    Circuit.wires ⟨gs, o⟩ x = run gs x := rfl\n\nlemma run_cons (g : Gate) (gs : List Gate) (x : List Bool) :\n    run (g :: gs) x = run gs (step x g) := rfl\n\nlemma run_append (gs hs : List Gate) (x : List Bool) :\n    run (gs ++ hs) x = run hs (run gs x) := List.foldl_append\n\nlemma length_step (x : List Bool) (g : Gate) : (step x g).length = x.length + 1 := by\n  simp [step]\n\nlemma length_run (gs : List Gate) (x : List Bool) :\n    (run gs x).length = x.length + gs.length := by\n  induction gs generalizing x with\n  | nil => simp [run]\n  | cons g gs ih =>\n    rw [run_cons, ih, length_step, List.length_cons]\n    omega\n\nlemma getD_step_lt (x : List Bool) (g : Gate) (j : ℕ) (hj : j < x.length) :\n    (step x g).getD j false = x.getD j false := by\n  simp [step, List.getD_eq_getElem?_getD, List.getElem?_append, hj]\n\nlemma getD_step_at (x : List Bool) (g : Gate) :\n    (step x g).getD x.length false = value x g := by\n  simp [step, List.getD_eq_getElem?_getD]\n\nlemma getD_step_gt (x : List Bool) (g : Gate) (j : ℕ) (hj : x.length < j) :\n    (step x g).getD j false = false := by\n  rw [List.getD_eq_getElem?_getD, List.getElem?_eq_none (by rw [length_step]; omega)]\n  rfl\n\nlemma getD_run_lt (gs : List Gate) (x : List Bool) (j : ℕ) (hj : j < x.length) :\n    (run gs x).getD j false = x.getD j false := by\n  induction gs generalizing x with\n  | nil => rfl\n  | cons g gs ih =>\n    rw [run_cons, ih (step x g) (by rw [length_step]; omega), getD_step_lt _ _ _ hj]\n\nlemma gate_at (gs : List Gate) (i : Fin gs.length) (x : List Bool) :\n    (run gs x).getD (x.length + i.val) false = value (run (gs.take i.val) x) (gs.get i) := by\n  have ht : gs.take (i.val + 1) = gs.take i.val ++ [gs.get i] := by\n    rw [List.take_add_one, List.getElem?_eq_getElem i.isLt]\n    rfl\n  have hl : (run (gs.take i.val) x).length = x.length + i.val := by\n    simp [length_run]\n  have h := congrArg (fun l => (run l x).getD (x.length + i.val) false)\n    (List.take_append_drop (i.val + 1) gs)\n  change (run (gs.take (i.val + 1) ++ gs.drop (i.val + 1)) x).getD\n    (x.length + i.val) false = (run gs x).getD (x.length + i.val) false at h\n  rw [run_append, getD_run_lt _ _ _ (by rw [length_run, List.length_take]; omega)] at h\n  rw [← h, ht, run_append]\n  change (step (run (gs.take i.val) x) (gs.get i)).getD (x.length + i.val) false = _\n  rw [← hl, getD_step_at]\n\nlemma gate_at_ofFn {n : ℕ} (gs : List Gate) (i : Fin gs.length) (x : Fin n → Bool) :\n    (run gs (List.ofFn x)).getD (n + i.val) false =\n      value (run (gs.take i.val) (List.ofFn x)) (gs.get i) := by\n  simpa only [List.length_ofFn] using gate_at gs i (List.ofFn x)\n\ndef MonotoneGates (gs : List Gate) : Prop :=\n  ∀ g ∈ gs, g.op = GateOp.and ∨ g.op = GateOp.or\n\ndef Silent (gs : List Gate) (x : List Bool) : Prop :=\n  ∀ i : Fin gs.length, (gs.get i).op = GateOp.and →\n    (run gs x).getD (x.length + i.val) false ≠ true\n\nlemma value_and (w : List Bool) (g : Gate) (h : g.op = GateOp.and) :\n    value w g = true ↔ ∀ j ∈ g.inputs, w.getD j false = true := by\n  simp [value, h, GateOp.eval, List.all_eq_true]\n\nlemma value_or (w : List Bool) (g : Gate) (h : g.op = GateOp.or) :\n    value w g = true ↔ ∃ j ∈ g.inputs, w.getD j false = true := by\n  simp [value, h, GateOp.eval, List.any_eq_true]\n\nlemma run_mono (gs : List Gate) (hg : MonotoneGates gs) (x y : List Bool)\n    (hlen : x.length = y.length)\n    (hxy : ∀ j, x.getD j false = true → y.getD j false = true) :\n    ∀ j, (run gs x).getD j false = true → (run gs y).getD j false = true := by\n  induction gs generalizing x y with\n  | nil => exact hxy\n  | cons g gs ih =>\n    rw [run_cons, run_cons]\n    apply ih (fun k hk => hg k (List.mem_cons_of_mem _ hk)) _ _\n      (by simp [length_step, hlen])\n    intro j hj\n    rcases lt_trichotomy j x.length with h | rfl | h\n    · rw [getD_step_lt _ _ _ h] at hj\n      rw [getD_step_lt _ _ _ (by omega)]\n      exact hxy _ hj\n    · rw [getD_step_at] at hj\n      rw [hlen, getD_step_at]\n      rcases hg g (by simp) with ha | ho\n      · exact (value_and _ _ ha).2\n          (fun k hk => hxy k ((value_and _ _ ha).1 hj k hk))\n      · obtain ⟨k, hk, hv⟩ := (value_or _ _ ho).1 hj\n        exact (value_or _ _ ho).2 ⟨k, hk, hxy k hv⟩\n    · rw [getD_step_gt _ _ _ h] at hj\n      contradiction\n\nlemma run_split (gs : List Gate) (hg : MonotoneGates gs) (x y z : List Bool)\n    (hxy : x.length = y.length) (hxz : x.length = z.length)\n    (hs : Silent gs x)\n    (hxyz : ∀ j, x.getD j false = true → y.getD j false = true ∨ z.getD j false = true) :\n    ∀ j, (run gs x).getD j false = true →\n      (run gs y).getD j false = true ∨ (run gs z).getD j false = true := by\n  induction gs generalizing x y z with\n  | nil => exact hxyz\n  | cons g gs ih =>\n    rw [run_cons, run_cons, run_cons]\n    apply ih (fun k hk => hg k (List.mem_cons_of_mem _ hk)) _ _ _\n      (by simp [length_step, hxy]) (by simp [length_step, hxz])\n    · intro i hi\n      let k : Fin (g :: gs).length := ⟨i.val + 1, by simp⟩\n      have hk : ((g :: gs).get k).op = GateOp.and := hi\n      have h := hs k hk\n      have he : x.length + k.val = (step x g).length + i.val := by\n        simp [k, length_step]\n        omega\n      rwa [run_cons, he] at h\n    · intro j hj\n      rcases lt_trichotomy j x.length with h | rfl | h\n      · rw [getD_step_lt _ _ _ h] at hj\n        rw [getD_step_lt _ _ _ (by omega), getD_step_lt _ _ _ (by omega)]\n        exact hxyz j hj\n      · rw [getD_step_at] at hj\n        have hy : (step y g).getD x.length false = value y g := by rw [hxy, getD_step_at]\n        have hz : (step z g).getD x.length false = value z g := by rw [hxz, getD_step_at]\n        rw [hy, hz]\n        rcases hg g (by simp) with ha | ho\n        · have h := hs ⟨0, by simp⟩ ha\n          rw [gate_at] at h\n          exact (h hj).elim\n        · obtain ⟨k, hk, hv⟩ := (value_or _ _ ho).1 hj\n          rcases hxyz k hv with hy | hz\n          · exact Or.inl ((value_or _ _ ho).2 ⟨k, hk, hy⟩)\n          · exact Or.inr ((value_or _ _ ho).2 ⟨k, hk, hz⟩)\n      · rw [getD_step_gt _ _ _ h] at hj\n        contradiction\n\nlemma silent_take {gs : List Gate} {x : List Bool} {k : ℕ}\n    (hk : k ≤ gs.length)\n    (hs : ∀ i : Fin gs.length, i.val < k → (gs.get i).op = GateOp.and →\n      (run gs x).getD (x.length + i.val) false ≠ true) :\n    Silent (gs.take k) x := by\n  intro i hi\n  have hik : i.val < k := by simpa [Nat.min_eq_left hk] using i.isLt\n  let j : Fin gs.length := ⟨i.val, by omega⟩\n  have hg : (gs.take k).get i = gs.get j := List.getElem_take\n  have h := hs j hik (hg ▸ hi)\n  have he : (run gs x).getD (x.length + i.val) false =\n      (run (gs.take k) x).getD (x.length + i.val) false := by\n    calc\n      _ = (run (gs.take k ++ gs.drop k) x).getD (x.length + i.val) false :=\n        congrArg (fun l : List Gate => (run l x).getD (x.length + i.val) false)\n          (List.take_append_drop k gs).symm\n      _ = _ := by\n        rw [run_append, getD_run_lt]\n        simp [length_run, Nat.min_eq_left hk, hik]\n  exact fun hv => h (he.trans hv)\n\ndef singletonBits {n : ℕ} (a : Fin n) (j : Fin n) : Bool := decide (j = a)\n\ndef pairBits {n : ℕ} (a b : Fin n) (j : Fin n) : Bool := decide (j = a ∨ j = b)\n\nlemma singleton_le_pair {n : ℕ} (a b : Fin n) (j : ℕ) :\n    (List.ofFn (singletonBits a)).getD j false = true →\n    (List.ofFn (pairBits a b)).getD j false = true := by\n  by_cases hj : j < n\n  · simp only [List.getD_eq_getElem?_getD, List.getElem?_ofFn, dif_pos hj,\n      Option.getD_some, singletonBits, pairBits, decide_eq_true_eq]\n    exact Or.inl\n  · simp [List.getD_eq_getElem?_getD, hj]\n\nlemma second_le_pair {n : ℕ} (a b : Fin n) (j : ℕ) :\n    (List.ofFn (singletonBits b)).getD j false = true →\n    (List.ofFn (pairBits a b)).getD j false = true := by\n  by_cases hj : j < n\n  · simp only [List.getD_eq_getElem?_getD, List.getElem?_ofFn, dif_pos hj,\n      Option.getD_some, singletonBits, pairBits, decide_eq_true_eq]\n    exact Or.inr\n  · simp [List.getD_eq_getElem?_getD, hj]\n\nlemma pair_split {n : ℕ} (a b : Fin n) (j : ℕ) :\n    (List.ofFn (pairBits a b)).getD j false = true →\n    (List.ofFn (singletonBits a)).getD j false = true ∨\n      (List.ofFn (singletonBits b)).getD j false = true := by\n  by_cases hj : j < n <;>\n    simp [List.getD_eq_getElem?_getD, hj, singletonBits, pairBits]\n\nabbrev HasEdge {n : ℕ} (G : SimpleGraph (Fin n)) (x : Fin n → Bool) : Prop :=\n  ∃ u v, G.Adj u v ∧ x u = true ∧ x v = true\n\nlemma no_singleton_edge {n : ℕ} (G : SimpleGraph (Fin n)) (a : Fin n) :\n    ¬ HasEdge G (singletonBits a) := by\n  rintro ⟨u, v, huv, hu, hv⟩\n  simp [singletonBits] at hu hv\n  subst u\n  subst v\n  exact G.irrefl huv\n\nlemma pair_edge {n : ℕ} (G : SimpleGraph (Fin n)) (a b : Fin n) :\n    HasEdge G (pairBits a b) ↔ G.Adj a b := by\n  constructor\n  · rintro ⟨u, v, huv, hu, hv⟩\n    simp [pairBits] at hu hv\n    rcases hu with rfl | rfl <;> rcases hv with rfl | rfl\n    · exact (G.irrefl huv).elim\n    · exact huv\n    · exact huv.symm\n    · exact (G.irrefl huv).elim\n  · intro h\n    exact ⟨a, b, h, by simp [pairBits], by simp [pairBits]⟩\n\ndef Clean {n : ℕ} (G : SimpleGraph (Fin n)) (gs : List Gate) : Prop :=\n  ∀ (i : Fin gs.length) (x : Fin n → Bool), (gs.get i).op = GateOp.and →\n    (run gs (List.ofFn x)).getD (n + i.val) false = true → HasEdge G x\n\ndef First {n : ℕ} (gs : List Gate) (i : Fin gs.length) (a b : Fin n) : Prop :=\n  (gs.get i).op = GateOp.and ∧\n  (run gs (List.ofFn (pairBits a b))).getD (n + i.val) false = true ∧\n  ∀ j : Fin gs.length, j.val < i.val → (gs.get j).op = GateOp.and →\n    (run gs (List.ofFn (pairBits a b))).getD (n + j.val) false ≠ true\n\nlemma first_exists {n : ℕ} (G : SimpleGraph (Fin n)) [DecidableRel G.Adj]\n    (gs : List Gate) (out : ℕ) (hg : MonotoneGates gs)\n    (heval : ∀ x : Fin n → Bool,\n      Circuit.eval ⟨gs, out⟩ (List.ofFn x) = decide (HasEdge G x))\n    {a b : Fin n} (hab : G.Adj a b) : ∃ i, First gs i a b := by\n  classical\n  let Fires (i : Fin gs.length) :=\n    (gs.get i).op = GateOp.and ∧\n      (run gs (List.ofFn (pairBits a b))).getD (n + i.val) false = true\n  have hex : ∃ i, Fires i := by\n    by_contra h\n    have hs : Silent gs (List.ofFn (pairBits a b)) := by\n      intro i hi hv\n      apply h\n      exact ⟨i, hi, by simpa using hv⟩\n    have hout : (run gs (List.ofFn (pairBits a b))).getD out false = true := by\n      change Circuit.eval ⟨gs, out⟩ (List.ofFn (pairBits a b)) = true\n      rw [heval, decide_eq_true_eq]\n      exact (pair_edge G a b).2 hab\n    have hsplit := run_split gs hg (List.ofFn (pairBits a b))\n      (List.ofFn (singletonBits a)) (List.ofFn (singletonBits b))\n      (by simp) (by simp) hs (pair_split a b) out hout\n    have hno (v : Fin n) :\n        (run gs (List.ofFn (singletonBits v))).getD out false ≠ true := by\n      change Circuit.eval ⟨gs, out⟩ (List.ofFn (singletonBits v)) ≠ true\n      rw [heval]\n      intro hv\n      exact no_singleton_edge G v (of_decide_eq_true hv)\n    exact hsplit.elim (hno a) (hno b)\n  let P (k : ℕ) := ∃ i : Fin gs.length, i.val = k ∧ Fires i\n  have hp : ∃ k, P k := by\n    obtain ⟨i, hi⟩ := hex\n    exact ⟨i.val, i, rfl, hi⟩\n  obtain ⟨i, hi, hf⟩ := Nat.find_spec hp\n  refine ⟨i, hf.1, hf.2, ?_⟩\n  intro j hj hop hv\n  exact (Nat.find_min' hp (show P j.val from ⟨j, rfl, hop, hv⟩)).not_gt (hi ▸ hj)\n\ndef SingletonAccept {n : ℕ} {gs : List Gate} (i : Fin gs.length) (wire : ℕ) (a : Fin n) :\n    Prop :=\n  (run (gs.take i.val) (List.ofFn (singletonBits a))).getD wire false = true\n\nlemma first_operand {n : ℕ} {gs : List Gate} (hg : MonotoneGates gs)\n    {i : Fin gs.length} {a b : Fin n} (hf : First gs i a b) :\n    ∀ wire ∈ (gs.get i).inputs, SingletonAccept i wire a ∨ SingletonAccept i wire b := by\n  have hv := hf.2.1\n  rw [gate_at_ofFn] at hv\n  have hs : Silent (gs.take i.val) (List.ofFn (pairBits a b)) :=\n    silent_take i.isLt.le (by simpa using hf.2.2)\n  intro wire hw\n  exact run_split (gs.take i.val) (fun g hm => hg g (List.mem_of_mem_take hm))\n    (List.ofFn (pairBits a b)) (List.ofFn (singletonBits a)) (List.ofFn (singletonBits b))\n    (by simp) (by simp) hs (pair_split a b) wire ((value_and _ _ hf.1).1 hv wire hw)\n\nlemma no_singleton_and {n : ℕ} {gs : List Gate} {G : SimpleGraph (Fin n)}\n    (hc : Clean G gs) {i : Fin gs.length} (hi : (gs.get i).op = GateOp.and)\n    (v : Fin n) : ¬ (∀ j ∈ (gs.get i).inputs, SingletonAccept i j v) := by\n  intro h\n  apply no_singleton_edge G v\n  apply hc i _ hi\n  rw [gate_at_ofFn]\n  exact (value_and _ _ hi).2 h\n\nlemma first_binary {n : ℕ} {gs : List Gate} {G : SimpleGraph (Fin n)}\n    (hg : MonotoneGates gs) (hc : Clean G gs) {i : Fin gs.length}\n    (hi : (gs.get i).inputs.length ≤ 2) {a b : Fin n} (hf : First gs i a b) :\n    ∃ p q, (gs.get i).inputs = [p, q] := by\n  have h := first_operand hg hf\n  have hna := no_singleton_and hc hf.1 a\n  have hnb := no_singleton_and hc hf.1 b\n  cases he : (gs.get i).inputs with\n  | nil =>\n    rw [he] at hna\n    simp at hna\n  | cons p rest =>\n    cases rest with\n    | nil =>\n      rw [he] at h hna hnb\n      simp at h hna hnb\n      exact (h.elim hna hnb).elim\n    | cons q rest =>\n      cases rest with\n      | nil => exact ⟨p, q, rfl⟩\n      | cons r rest =>\n        rw [he] at hi\n        simp at hi\n\nlemma first_orientation {n : ℕ} {gs : List Gate} {G : SimpleGraph (Fin n)}\n    (hg : MonotoneGates gs) (hc : Clean G gs) {i : Fin gs.length} {p q : ℕ}\n    (hw : (gs.get i).inputs = [p, q]) {a b : Fin n} (hf : First gs i a b) :\n    (SingletonAccept i p a ∧ SingletonAccept i q b) ∨\n      (SingletonAccept i p b ∧ SingletonAccept i q a) := by\n  have hp := first_operand hg hf p (by rw [hw]; simp)\n  have hq := first_operand hg hf q (by rw [hw]; simp)\n  have hna : ¬ (SingletonAccept i p a ∧ SingletonAccept i q a) := by\n    have h := no_singleton_and hc hf.1 a\n    rw [hw] at h\n    simpa using h\n  have hnb : ¬ (SingletonAccept i p b ∧ SingletonAccept i q b) := by\n    have h := no_singleton_and hc hf.1 b\n    rw [hw] at h\n    simpa using h\n  tauto\n\nlemma cross_edge {n : ℕ} {gs : List Gate} {G : SimpleGraph (Fin n)}\n    (hg : MonotoneGates gs) (hc : Clean G gs) {i : Fin gs.length}\n    (hi : (gs.get i).op = GateOp.and) {p q : ℕ} (hw : (gs.get i).inputs = [p, q])\n    {a b : Fin n} (ha : SingletonAccept i p a) (hb : SingletonAccept i q b) :\n    G.Adj a b := by\n  apply (pair_edge G a b).1\n  apply hc i _ hi\n  rw [gate_at_ofFn]\n  apply (value_and _ _ hi).2\n  have hm := run_mono (gs.take i.val) (fun g hm => hg g (List.mem_of_mem_take hm))\n  have hp := hm _ _ (by simp) (singleton_le_pair a b) p ha\n  have hq := hm _ _ (by simp) (second_le_pair a b) q hb\n  intro j hj\n  rw [hw] at hj\n  simp at hj\n  rcases hj with rfl | rfl\n  · exact hp\n  · exact hq\n\nlemma rectangle_star {n : ℕ} {G : SimpleGraph (Fin n)}\n    (hcycle : ∀ a b c d, a ≠ c → b ≠ d →\n      ¬ (G.Adj a b ∧ G.Adj b c ∧ G.Adj c d ∧ G.Adj d a))\n    (A B : Fin n → Prop) {a b : Fin n} (ha : A a) (hb : B b)\n    (hcross : ∀ u v, A u → B v → G.Adj u v) :\n    ∃ c, ∀ u v, A u → B v → c = u ∨ c = v := by\n  classical\n  by_cases h : ∀ u, A u → a = u\n  · exact ⟨a, fun u _ hu _ => Or.inl (h u hu)⟩\n  · push Not at h\n    obtain ⟨u, hu, hau⟩ := h\n    refine ⟨b, fun _ v _ hv => Or.inr ?_⟩\n    by_contra hbv\n    exact hcycle a b u v hau hbv\n      ⟨hcross a b ha hb, (hcross u b hu hb).symm,\n       hcross u v hu hv, (hcross a v ha hv).symm⟩\n\nlemma first_star {n : ℕ} {gs : List Gate} {G : SimpleGraph (Fin n)}\n    (hcycle : ∀ a b c d, a ≠ c → b ≠ d →\n      ¬ (G.Adj a b ∧ G.Adj b c ∧ G.Adj c d ∧ G.Adj d a))\n    (hg : MonotoneGates gs) (hc : Clean G gs) {i : Fin gs.length}\n    (hi : (gs.get i).inputs.length ≤ 2) (hused : ∃ a b, First (n := n) gs i a b) :\n    ∃ c, ∀ a b, First (n := n) gs i a b → c = a ∨ c = b := by\n  obtain ⟨a, b, hf⟩ := hused\n  obtain ⟨p, q, hw⟩ := first_binary hg hc hi hf\n  have hx (u v : Fin n) : SingletonAccept i p u → SingletonAccept i q v → G.Adj u v :=\n    cross_edge hg hc hf.1 hw\n  have hcenter : ∃ c, ∀ u v : Fin n,\n      SingletonAccept i p u → SingletonAccept i q v → c = u ∨ c = v := by\n    rcases first_orientation hg hc hw hf with ⟨hp, hq⟩ | ⟨hp, hq⟩\n    · exact rectangle_star hcycle _ _ hp hq hx\n    · exact rectangle_star hcycle _ _ hp hq hx\n  obtain ⟨c, h⟩ := hcenter\n  refine ⟨c, fun u v huv => ?_⟩\n  rcases first_orientation hg hc hw huv with ⟨hp, hq⟩ | ⟨hp, hq⟩\n  · exact h u v hp hq\n  · exact (h v u hp hq).symm\n\nend PEqualNP.Outside.L_meta_1406\n\nopen PEqualNP.Outside.L_meta_1406\n\ntheorem PEqualNP.Outside.L_meta_1406 :\n    ∀ (n : ℕ) (G : SimpleGraph (Fin n)) [DecidableRel G.Adj],\n    (∀ a b c d : Fin n, a ≠ c → b ≠ d →\n      ¬ (G.Adj a b ∧ G.Adj b c ∧ G.Adj c d ∧ G.Adj d a)) →\n    ∀ (gates : List PEqualNP.CircuitLowerBounds.Gate) (out : ℕ),\n    (∀ g ∈ gates, (g.op = PEqualNP.CircuitLowerBounds.GateOp.and ∨\n      g.op = PEqualNP.CircuitLowerBounds.GateOp.or) ∧ g.inputs.length ≤ 2) →\n    (∀ x : Fin n → Bool, PEqualNP.CircuitLowerBounds.Circuit.eval ⟨gates, out⟩ (List.ofFn x) =\n      decide (∃ u v : Fin n, G.Adj u v ∧ x u = true ∧ x v = true)) →\n    (∀ (i : Fin gates.length) (x : Fin n → Bool),\n      (gates.get i).op = PEqualNP.CircuitLowerBounds.GateOp.and →\n      (PEqualNP.CircuitLowerBounds.Circuit.wires ⟨gates, 0⟩ (List.ofFn x)).getD\n        (n + (i : ℕ)) false = true →\n      ∃ u v : Fin n, G.Adj u v ∧ x u = true ∧ x v = true) →\n    ∀ I : Finset (Fin gates.length),\n    (∀ i : Fin gates.length, (gates.get i).op = PEqualNP.CircuitLowerBounds.GateOp.and →\n      i ∈ I) →\n    ∃ T : Finset (Fin n), (∀ u v : Fin n, G.Adj u v → u ∈ T ∨ v ∈ T) ∧\n      T.card ≤ I.card := by\n  intro n G inst hcycle gates out hgate heval hc I hI\n  classical\n  have hg : MonotoneGates gates := fun g hm => (hgate g hm).1\n  have hclean : Clean G gates := hc\n  by_cases hE : ∃ a b : Fin n, G.Adj a b\n  · obtain ⟨a, b, _⟩ := hE\n    have hcent (i : Fin gates.length) :\n        ∃ c : Fin n, ∀ u v, First gates i u v → c = u ∨ c = v := by\n      by_cases hused : ∃ u v : Fin n, First gates i u v\n      · exact first_star hcycle hg hclean ((hgate _ (List.get_mem _ _)).2) hused\n      · exact ⟨a, fun u v h => (hused ⟨u, v, h⟩).elim⟩\n    choose center hcenter using hcent\n    refine ⟨I.image center, ?_, Finset.card_image_le⟩\n    intro u v huv\n    obtain ⟨i, hi⟩ := first_exists G gates out hg heval huv\n    have hm : center i ∈ I.image center := Finset.mem_image_of_mem center (hI i hi.1)\n    rcases hcenter i u v hi with hu | hv\n    · exact Or.inl (hu ▸ hm)\n    · exact Or.inr (hv ▸ hm)\n  · exact ⟨∅, fun u v huv => (hE ⟨u, v, huv⟩).elim, by simp⟩\n",
  "evidence": {
    "lemma": "PEqualNP.Outside.L_meta_1406.first_star",
    "argument": [
      "gate_at and gate_at_ofFn recover the gate output from the prefix fold. Later gates preserve that output. Every operand is read from exactly that prefix, with getD false at each nonexistent index.",
      "run_split shows that if all ANDs of a prefix are silent on the pair input, each true prefix wire is true on at least one singleton. This follows by induction on the fold: input bits split, each true OR has a true predecessor, and AND outputs on the pair are false by hypothesis. It also covers nonexistent indices. Applied to the complete fold if no AND fires, the output would be true on a singleton, contradicting correctness. first_exists picks the least firing AND.",
      "At that AND, every read therefore has a singleton witness. An empty AND would fire on a singleton by vacuous truth. A unary AND would fire on the singleton witnessing its sole operand. Cleanliness forbids both cases and also forbids the same singleton from witnessing both operands of a binary AND. Thus the two endpoints can be oriented into the two operand singleton acceptance sets.",
      "Monotonicity of the prefix lifts witnesses from opposite acceptance sets to the cross pair, where both operands are true. Cleanliness of the AND gives an edge on that pair. Graph looplessness removes any overlap of the two sets. With two distinct vertices on each side, the four cross edges form a forbidden 4-cycle. One side is consequently a singleton, and its vertex meets every pair first accepted by the gate.",
      "If the graph has an edge, choose a center for each AND used as a first gate and use any fixed edge endpoint for the vacuous center condition at unused indices. The image of I under the center map covers every edge and its cardinality is at most I.card. The edgeless case uses the empty cover."
    ],
    "verification_context": "The workspace had no lean/ project. The public archive at the pinned commit was extracted under test/scratch, and the Lean version and Mathlib revision were taken from its checked-in pins. The reported module path is its placement in that project. The complete file is in the source field.",
    "source_sha256": "8a2e3ac3370ec888542c6941d1a9e568d10d136eed5bdbe2b94650c93c0ed65b"
  },
  "checks": [
    {
      "command": "lake build PEqualNP.Defs",
      "outcome": "Exit 0 in the pinned Lean project."
    },
    {
      "command": "lake build +PEqualNP.Outside.L_meta_1406",
      "outcome": "Build completed successfully (18383 jobs)."
    },
    {
      "command": "lake env lean InspectLMeta1406.lean",
      "outcome": "PEqualNP.Outside.L_meta_1406 (n : ℕ) (G : SimpleGraph (Fin n)) [DecidableRel G.Adj] :\n  (∀ (a b c d : Fin n), a ≠ c → b ≠ d → ¬(G.Adj a b ∧ G.Adj b c ∧ G.Adj c d ∧ G.Adj d a)) →\n    ∀ (gates : List PEqualNP.CircuitLowerBounds.Gate) (out : ℕ),\n      (∀ g ∈ gates,\n          (g.op = PEqualNP.CircuitLowerBounds.GateOp.and ∨ g.op = PEqualNP.CircuitLowerBounds.GateOp.or) ∧\n            g.inputs.length ≤ 2) →\n        (∀ (x : Fin n → Bool),\n            { gates := gates, output := out }.eval (List.ofFn x) =\n              decide (∃ u v, G.Adj u v ∧ x u = true ∧ x v = true)) →\n          (∀ (i : Fin gates.length) (x : Fin n → Bool),\n              (gates.get i).op = PEqualNP.CircuitLowerBounds.GateOp.and →\n                ({ gates := gates, output := 0 }.wires (List.ofFn x)).getD (n + ↑i) false = true →\n                  ∃ u v, G.Adj u v ∧ x u = true ∧ x v = true) →\n            ∀ (I : Finset (Fin gates.length)),\n              (∀ (i : Fin gates.length), (gates.get i).op = PEqualNP.CircuitLowerBounds.GateOp.and → i ∈ I) →\n                ∃ T, (∀ (u v : Fin n), G.Adj u v → u ∈ T ∨ v ∈ T) ∧ T.card ≤ I.card\nPEqualNP.Outside.L_meta_1406.first_star {n : ℕ} {gs : List PEqualNP.CircuitLowerBounds.Gate} {G : SimpleGraph (Fin n)}\n  (hcycle : ∀ (a b c d : Fin n), a ≠ c → b ≠ d → ¬(G.Adj a b ∧ G.Adj b c ∧ G.Adj c d ∧ G.Adj d a))\n  (hg : PEqualNP.Outside.L_meta_1406.MonotoneGates gs) (hc : PEqualNP.Outside.L_meta_1406.Clean G gs)\n  {i : Fin gs.length} (hi : (gs.get i).inputs.length ≤ 2) (hused : ∃ a b, PEqualNP.Outside.L_meta_1406.First gs i a b) :\n  ∃ c, ∀ (a b : Fin n), PEqualNP.Outside.L_meta_1406.First gs i a b → c = a ∨ c = b\n'PEqualNP.Outside.L_meta_1406' depends on axioms: [propext, Classical.choice, Quot.sound]\n'PEqualNP.Outside.L_meta_1406.first_star' depends on axioms: [propext, Classical.choice, Quot.sound]",
      "scratch_source": "import PEqualNP.Outside.L_meta_1406\n\n#check PEqualNP.Outside.L_meta_1406\n#check PEqualNP.Outside.L_meta_1406.first_star\n#print axioms PEqualNP.Outside.L_meta_1406\n#print axioms PEqualNP.Outside.L_meta_1406.first_star\n\nexample : ∀ (n : ℕ) (G : SimpleGraph (Fin n)) [DecidableRel G.Adj], (∀ a b c d : Fin n, a ≠ c → b ≠ d → ¬ (G.Adj a b ∧ G.Adj b c ∧ G.Adj c d ∧ G.Adj d a)) → ∀ (gates : List PEqualNP.CircuitLowerBounds.Gate) (out : ℕ), (∀ g ∈ gates, (g.op = PEqualNP.CircuitLowerBounds.GateOp.and ∨ g.op = PEqualNP.CircuitLowerBounds.GateOp.or) ∧ g.inputs.length ≤ 2) → (∀ x : Fin n → Bool, PEqualNP.CircuitLowerBounds.Circuit.eval ⟨gates, out⟩ (List.ofFn x) = decide (∃ u v : Fin n, G.Adj u v ∧ x u = true ∧ x v = true)) → (∀ (i : Fin gates.length) (x : Fin n → Bool), (gates.get i).op = PEqualNP.CircuitLowerBounds.GateOp.and → (PEqualNP.CircuitLowerBounds.Circuit.wires ⟨gates, 0⟩ (List.ofFn x)).getD (n + (i : ℕ)) false = true → ∃ u v : Fin n, G.Adj u v ∧ x u = true ∧ x v = true) → ∀ I : Finset (Fin gates.length), (∀ i : Fin gates.length, (gates.get i).op = PEqualNP.CircuitLowerBounds.GateOp.and → i ∈ I) → ∃ T : Finset (Fin n), (∀ u v : Fin n, G.Adj u v → u ∈ T ∨ v ∈ T) ∧ T.card ≤ I.card :=\n  PEqualNP.Outside.L_meta_1406\n"
    },
    {
      "command": "lake build checklemma",
      "outcome": "Build completed successfully (5 jobs)."
    },
    {
      "command": "lake env .lake/build/bin/checklemma PEqualNP.Outside.L_meta_1406 ../posted.lean check",
      "outcome": "MODULES PEqualNP.Outside.L_meta_1406\nACCEPTED (check): PEqualNP.Outside.L_meta_1406; axioms [propext, Quot.sound, Classical.choice]; kernel re-checked 1257 constants of [PEqualNP.Defs.Base, PEqualNP.Defs.Classes, PEqualNP.Defs.CircuitLowerBounds, PEqualNP.Defs.MetaComplexity, PEqualNP.Defs.MetaComplexityLocal, PEqualNP.Defs.MetaComplexitySparse, PEqualNP.Defs.MetaComplexityMinimal, PEqualNP.Defs.MetaComplexityLgp, PEqualNP.Defs.MetaComplexityLgpMono, PEqualNP.Defs.BinaryCircuit, PEqualNP.Defs.MetaComplexityCoverCircuit, PEqualNP.Defs.ProofComplexity, PEqualNP.Defs.ProofComplexityLin, PEqualNP.Defs.ProofComplexityLinK, PEqualNP.Defs.ProofComplexityLift, PEqualNP.Defs.ProofComplexityResK, PEqualNP.Defs.ProofComplexityRestrict, PEqualNP.Defs.ProofComplexityBit, PEqualNP.Defs.ProofComplexityPC, PEqualNP.Defs.ProofComplexityMoment, PEqualNP.Defs.ProofComplexityChain, PEqualNP.Defs.ProofComplexityGeneral, PEqualNP.Defs.Search, PEqualNP.Defs.SearchQ, PEqualNP.Defs.SearchQTree, PEqualNP.Defs.SearchCP, PEqualNP.Defs.SearchRUP, PEqualNP.Defs.SearchQSyn, PEqualNP.Defs.SearchSoS, PEqualNP.Defs.Gct, PEqualNP.Defs.Oracle, PEqualNP.Defs.Algebraic, PEqualNP.Defs.Expanders, PEqualNP.Defs.RiffleRank, PEqualNP.Defs.TimeAlt, PEqualNP.Defs.CoverPromise, PEqualNP.Defs.SingleLevel, PEqualNP.Defs.DeMorganFormula, PEqualNP.Defs.MetaComplexityTypedRank, PEqualNP.Defs.Pebble, PEqualNP.Defs.Subdivision, PEqualNP.Defs.AndCountCircuit, PEqualNP.Defs.PebbleThreeWay, PEqualNP.Defs.CoLevel, PEqualNP.Defs.Peelable, PEqualNP.Defs.NestedCoverCircuit, PEqualNP.Defs.LiteralPartition, PEqualNP.Defs.MinimumComplex, PEqualNP.Defs.PendantBit, PEqualNP.Defs.BorrowedCoverCircuit, PEqualNP.Defs.LineDegree, PEqualNP.Defs.CircuitMoves, PEqualNP.Defs.LowMerge, PEqualNP.Defs.NewLowMerge, PEqualNP.Defs.AffinePlane, PEqualNP.Defs.EdgeOwnership, PEqualNP.Defs.PencilGate, PEqualNP.Defs.BlindGate, PEqualNP.Defs.BicliqueBlockCost, PEqualNP.Defs.SharingOrder, PEqualNP.Defs.NotPremium, PEqualNP.Defs.NotBracket, PEqualNP.Defs.PairShadow, PEqualNP.Defs.InvisibleWire, PEqualNP.Defs.SharedOr, PEqualNP.Defs, PEqualNP.Outside.L_meta_1406]"
    }
  ],
  "sources": [
    "https://data.pequalnp.com/data/desk/gaps.json",
    "https://raw.githubusercontent.com/brilliant-hq/pequalnp-proofs/605dc84be40929b8c04c6b206c363d69dc369d12/lean/PEqualNP/Defs/CircuitLowerBounds.lean",
    "https://raw.githubusercontent.com/brilliant-hq/pequalnp-proofs/605dc84be40929b8c04c6b206c363d69dc369d12/CONTRIBUTING.md",
    "https://raw.githubusercontent.com/brilliant-hq/pequalnp-proofs/605dc84be40929b8c04c6b206c363d69dc369d12/lean/CheckLemma.lean",
    "https://raw.githubusercontent.com/brilliant-hq/pequalnp-proofs/605dc84be40929b8c04c6b206c363d69dc369d12/lean/lean-toolchain",
    "https://raw.githubusercontent.com/brilliant-hq/pequalnp-proofs/605dc84be40929b8c04c6b206c363d69dc369d12/lean/lake-manifest.json"
  ],
  "remaining": []
}
