{"unit":"L-meta-25851","statement":"∃ C : PEqualNP.CircuitLowerBounds.Circuit, PEqualNP.MetaComplexity.FanInTwo C ∧ C.size ≤ 6 ∧ PEqualNP.Represents.Represents (fun u v : Fin 4 => (15855 : ℕ).testBit (4 * u.val + v.val)) C","verdict":"no_circuit","search_complete":true,"min_gates":7,"circuit":{"gates":[{"op":"and","inputs":[5,2],"mask":512},{"op":"or","inputs":[7,1],"mask":35064},{"op":"or","inputs":[9,6],"mask":52476},{"op":"or","inputs":[4,3],"mask":61713},{"op":"and","inputs":[11,10],"mask":49168},{"op":"or","inputs":[12,8],"mask":49680},{"op":"not","inputs":[13],"mask":15855}],"output":14,"size":7,"wire_masks":[15,240,3840,61440,4369,8738,17476,34952,512,35064,52476,61713,49168,49680,15855]},"coverage":["Bit 4*u+v of each 16-bit table is the wire value on the two one-hot inputs u and v. The first eight wire indices are the four row bits followed by the four column bits.","An out-of-range operand or output is constant false at the time of evaluation. An empty AND yields true, an empty OR yields false, and an empty NOT yields true. NOT ignores a second operand. Unary AND/OR and repeated binary operands are copies. Propagating constant operands through AND/OR/NOT and identifying duplicate tables introduces no gates. The target is neither constant nor a primary wire.","For a minimum realization modulo the promised inputs, delete gates outside the output cone, merge equal tables and drop constant tables by constant propagation. The output then has a producing gate, which is last. Every other gate is a complement of a prior wire or an AND/OR of two distinct prior wires. Commutativity permits choosing the larger operand index first.","Fix the operand edges of that realization and pick the lexicographically least topological ordering by output table. A non-output gate must have a higher table than every earlier gate after its latest gate dependency. Otherwise it could have been inserted before an earlier larger table while respecting all dependencies. The prefix loop enforces exactly this necessary inequality. The direct final-step test enumerates all unary and unordered binary target-producing operations, with the subset/superset tests required by OR/AND.","The search checks every smaller bound before proceeding and stops on the first witness. The target cannot be an unused or missing output in a minimum circuit, and arbitrary output indices in the original representation are covered by deleting gates outside its cone."],"program":"#include <array>\n#include <cstdint>\n#include <cstdlib>\n#include <iostream>\nusing Mask = uint16_t;\nconstexpr Mask target = 15855;\nconstexpr Mask all = 65535;\nstruct Gate { char op; int a, b; };\nstd::array<Mask, 16> wire{};\nstd::array<Gate, 16> gates{};\nstd::array<bool, 65536> present{};\nstd::array<uint64_t, 16> states{};\nint limit;\nvoid witness(int depth) {\n    std::cout << \"witness \" << depth+1 << '\\n';\n    for (int i=0; i<=depth; ++i) {\n        auto [op,a,b] = gates[i];\n        std::cout << op << ' ' << a << ' ' << b << ' ' << wire[i+8] << '\\n';\n    }\n}\nbool dfs(int depth) {\n    ++states[depth];\n    int n = 8+depth;\n    // Only a new output-producing gate is needed after this prefix.\n    for (int i=0; i<n; ++i) {\n        Mask a = wire[i];\n        if (Mask(~a) == target) {\n            gates[depth] = {'!', i, -1}; wire[n] = target; witness(depth); return true;\n        }\n        if ((a & target) == target)\n            for (int j=0; j<i; ++j) if ((a & wire[j]) == target) {\n                gates[depth] = {'&', i,j}; wire[n] = target; witness(depth); return true;\n            }\n        if ((a | target) == target)\n            for (int j=0; j<i; ++j) if ((a | wire[j]) == target) {\n                gates[depth] = {'|', i,j}; wire[n] = target; witness(depth); return true;\n            }\n    }\n    if (depth+1 == limit) return false;\n    Mask highest = 0;\n    for (int i=n-1; i>=0; --i) {\n        Mask a = wire[i];\n        auto tryGate = [&](Mask value, char op, int j) {\n            if (value <= highest || present[value]) return false;\n            present[value] = true;\n            wire[n] = value;\n            gates[depth] = {op,i,j};\n            bool found = dfs(depth+1);\n            present[value] = false;\n            return found;\n        };\n        if (tryGate(Mask(~a),'!',-1)) return true;\n        for (int j=0; j<i; ++j) {\n            if (tryGate(a & wire[j],'&',j) || tryGate(a | wire[j],'|',j)) return true;\n        }\n        if (i>=8 && a>highest) highest=a;\n    }\n    return false;\n}\nint main(int argc, char **argv) {\n    for (int u=0; u<4; ++u)\n        for (int v=0; v<4; ++v) {\n            wire[u] |= 1u<<(4*u+v);\n            wire[4+v] |= 1u<<(4*u+v);\n        }\n    present[0] = present[all] = true;\n    for (int i=0; i<8; ++i) {\n        if (wire[i]==target) return 0;\n        present[wire[i]] = true;\n    }\n    if (target==0 || target==all) return 0;\n    for (int bound=1; bound<=std::atoi(argv[1]); ++bound) {\n        limit=bound;\n        states.fill(0);\n        bool found=dfs(0);\n        std::cout << \"bound \" << bound << \" found \" << found << \" prefixes\";\n        for (int j=0;j<bound;++j) std::cout << ' ' << states[j];\n        std::cout << std::endl;\n        if (found) return 0;\n    }\n}\n","mode":"refute","complete":true,"lean":"import PEqualNP.Defs\n\n/- Adapted from PEqualNP Outside L_meta_25814, Apache-2.0.\n   The instance, search bound, pair encoding and kernel check are specialized to L-meta-25851. -/\n\nnamespace PEqualNP.Outside.L_meta_25851_aux\n\nopen PEqualNP.CircuitLowerBounds PEqualNP.MetaComplexity PEqualNP.Represents\n\nsection Live\n\nvariable {α : Type} [DecidableEq α] (bop : α → α → Finset α) (uop : α → Finset α) (goal : α)\n\ndef build : ℕ → Finset α → Prop\n  | 0, av => goal ∈ av\n  | k + 1, av => build k av ∨\n      (∃ a ∈ av, ∃ b ∈ av, a ≠ b ∧ ∃ z ∈ bop a b, build k (insert z av)) ∨\n      (∃ a ∈ av, ∃ z ∈ uop a, build k (insert z av))\n\ndef live : ℕ → Finset α → Prop\n  | 0, s => s = {goal}\n  | k + 1, s => live k s ∨\n      (∃ a ∈ s, ∃ b ∈ s, a ≠ b ∧ ∃ z ∈ bop a b, z ∉ s ∧\n        ∃ rest : Finset α, s = insert a (insert b rest) ∧ live k (insert z rest)) ∨\n      (∃ a ∈ s, ∃ z ∈ uop a, z ∉ s ∧\n        ∃ rest : Finset α, s = insert a rest ∧ live k (insert z rest))\n\nvariable {bop uop goal}\n\ntheorem compress {k : ℕ} {av : Finset α} (h : build bop uop goal k av) :\n    ∃ s ⊆ av, live bop uop goal k s := by\n  induction k generalizing av with\n  | zero => exact ⟨{goal}, Finset.singleton_subset_iff.mpr h, rfl⟩\n  | succ k ih =>\n    rcases h with skip | ⟨a, ha, b, hb, hab, z, hz, tail⟩ | ⟨a, ha, z, hz, tail⟩\n    · obtain ⟨s, hs, hrun⟩ := ih skip\n      exact ⟨s, hs, Or.inl hrun⟩\n    · obtain ⟨t, ht, hrun⟩ := ih tail\n      by_cases sub : t ⊆ av\n      · exact ⟨t, sub, Or.inl hrun⟩\n      · have hzmem : z ∈ t := by\n          by_contra hn\n          apply sub\n          intro u hu\n          rcases Finset.mem_insert.mp (ht hu) with rfl | ok\n          · exact False.elim (hn hu)\n          · exact ok\n        have hzout : z ∉ av := by\n          intro hh\n          exact sub ((Finset.insert_eq_of_mem hh) ▸ ht)\n        let rest := t.erase z\n        have hrest : rest ⊆ av := by\n          intro u hu\n          have hu' := Finset.mem_erase.mp hu\n          exact (Finset.mem_insert.mp (ht hu'.2)).resolve_left hu'.1\n        let s := insert a (insert b rest)\n        have hs : s ⊆ av := Finset.insert_subset ha (Finset.insert_subset hb hrest)\n        refine ⟨s, hs, Or.inr (Or.inl ⟨a, by simp [s], b, by simp [s], hab, z, hz,\n          fun h => hzout (hs h), rest, rfl, ?_⟩)⟩\n        simpa [rest, Finset.insert_erase hzmem] using hrun\n    · obtain ⟨t, ht, hrun⟩ := ih tail\n      by_cases sub : t ⊆ av\n      · exact ⟨t, sub, Or.inl hrun⟩\n      · have hzmem : z ∈ t := by\n          by_contra hn\n          apply sub\n          intro u hu\n          rcases Finset.mem_insert.mp (ht hu) with rfl | ok\n          · exact False.elim (hn hu)\n          · exact ok\n        have hzout : z ∉ av := by\n          intro hh\n          exact sub ((Finset.insert_eq_of_mem hh) ▸ ht)\n        let rest := t.erase z\n        have hrest : rest ⊆ av := by\n          intro u hu\n          have hu' := Finset.mem_erase.mp hu\n          exact (Finset.mem_insert.mp (ht hu'.2)).resolve_left hu'.1\n        let s := insert a rest\n        have hs : s ⊆ av := Finset.insert_subset ha hrest\n        refine ⟨s, hs, Or.inr (Or.inr ⟨a, by simp [s], z, hz,\n          fun h => hzout (hs h), rest, rfl, ?_⟩)⟩\n        simpa [rest, Finset.insert_erase hzmem] using hrun\n\ntheorem live_card {k : ℕ} {s : Finset α} (h : live bop uop goal k s) : s.card ≤ k + 1 := by\n  induction k generalizing s with\n  | zero => change s = {goal} at h; simp [h]\n  | succ k ih =>\n    rcases h with skip | ⟨a, ha, b, hb, hab, z, hz, hout, rest, rfl, tail⟩ |\n        ⟨a, ha, z, hz, hout, rest, rfl, tail⟩\n    · exact (ih skip).trans (by omega)\n    · have hzrest : z ∉ rest := fun hm => hout (by simp [hm])\n      have htail := ih tail\n      rw [Finset.card_insert_of_notMem hzrest] at htail\n      have h₁ := Finset.card_insert_le a (insert b rest)\n      have h₂ := Finset.card_insert_le b rest\n      omega\n    · have hzrest : z ∉ rest := fun hm => hout (by simp [hm])\n      have htail := ih tail\n      rw [Finset.card_insert_of_notMem hzrest] at htail\n      have h₁ := Finset.card_insert_le a rest\n      omega\n\ntheorem live_separates (D : α → Prop) (hd : D goal)\n    (hops : ∀ a b, ∀ z ∈ bop a b, D z → D a ∨ D b) (hun : ∀ a, ∀ z ∈ uop a, D z → D a)\n    {k : ℕ} {s : Finset α} (h : live bop uop goal k s) : ∃ w ∈ s, D w := by\n  induction k generalizing s with\n  | zero => change s = {goal} at h; exact ⟨goal, by simp [h], hd⟩\n  | succ k ih =>\n    rcases h with skip | ⟨a, ha, b, hb, hab, z, hz, hout, rest, rfl, tail⟩ |\n        ⟨a, ha, z, hz, hout, rest, rfl, tail⟩\n    · exact ih skip\n    · obtain ⟨w, hw, hD⟩ := ih tail\n      rcases Finset.mem_insert.mp hw with rfl | hw\n      · rcases hops a b w hz hD with h | h\n        · exact ⟨a, ha, h⟩\n        · exact ⟨b, hb, h⟩\n      · exact ⟨w, by simp [hw], hD⟩\n    · obtain ⟨w, hw, hD⟩ := ih tail\n      rcases Finset.mem_insert.mp hw with rfl | hw\n      · exact ⟨a, ha, hun a w hz hD⟩\n      · exact ⟨w, by simp [hw], hD⟩\n\ntheorem live_tight (D : α → Prop) (hd : D goal)\n    (hops : ∀ a b, ∀ z ∈ bop a b, D z → D a ∨ D b)\n    {k : ℕ} {s : Finset α} (h : live bop uop goal k s) (hc : s.card = k + 1) : ∃ w ∈ s, D w := by\n  induction k generalizing s with\n  | zero => change s = {goal} at h; exact ⟨goal, by simp [h], hd⟩\n  | succ k ih =>\n    rcases h with skip | ⟨a, ha, b, hb, hab, z, hz, hout, rest, rfl, tail⟩ |\n        ⟨a, ha, z, hz, hout, rest, rfl, tail⟩\n    · have := live_card skip\n      omega\n    · have hzrest : z ∉ rest := fun hm => hout (by simp [hm])\n      have htail := live_card tail\n      rw [Finset.card_insert_of_notMem hzrest] at htail\n      have h₁ := Finset.card_insert_le a (insert b rest)\n      have h₂ := Finset.card_insert_le b rest\n      have hc' : (insert z rest).card = k + 1 := by\n        rw [Finset.card_insert_of_notMem hzrest]; omega\n      obtain ⟨w, hw, hD⟩ := ih tail hc'\n      rcases Finset.mem_insert.mp hw with rfl | hw\n      · rcases hops a b w hz hD with h | h\n        · exact ⟨a, ha, h⟩\n        · exact ⟨b, hb, h⟩\n      · exact ⟨w, by simp [hw], hD⟩\n    · have hzrest : z ∉ rest := fun hm => hout (by simp [hm])\n      have htail := live_card tail\n      rw [Finset.card_insert_of_notMem hzrest] at htail\n      have h₁ := Finset.card_insert_le a rest\n      omega\n\ntheorem build_mono {k : ℕ} {av : Finset α} (h : build bop uop goal k av) :\n    ∀ j, k ≤ j → build bop uop goal j av := by\n  intro j hj\n  induction hj with\n  | refl => exact h\n  | step _ ih => exact Or.inl ih\n\nend Live\n\nsection Lists\n\ndef singles {α : Type} : List α → List (α × List α)\n  | [] => []\n  | a :: rest => (a, rest) :: (singles rest).map (fun (b, bs) => (b, a :: bs))\n\ndef pairs {α : Type} : List α → List (α × α × List α)\n  | [] => []\n  | a :: rest => (singles rest).map (fun (b, bs) => (a, b, bs)) ++\n      (pairs rest).map (fun (b, c, bs) => (b, c, a :: bs))\n\ntheorem pick_one {α : Type} {a : α} {ws : List α} (h : a ∈ ws) :\n    ∃ rest, (a, rest) ∈ singles ws ∧ ws.Perm (a :: rest) := by\n  induction ws with\n  | nil => simp at h\n  | cons x xs ih =>\n    rcases List.mem_cons.mp h with e | h\n    · subst x; exact ⟨xs, by simp [singles], .refl _⟩\n    · obtain ⟨rest, hm, hp⟩ := ih h\n      refine ⟨x :: rest, List.mem_cons_of_mem _ (List.mem_map.mpr ⟨(a, rest), hm, rfl⟩), ?_⟩\n      exact (hp.cons x).trans (.swap _ _ _)\n\ntheorem pick_two {α : Type} {a b : α} {ws : List α} (ha : a ∈ ws) (hb : b ∈ ws) (hne : a ≠ b) :\n    ∃ rest, ((a, b, rest) ∈ pairs ws ∨ (b, a, rest) ∈ pairs ws) ∧\n      ws.Perm (a :: b :: rest) := by\n  induction ws with\n  | nil => simp at ha\n  | cons x xs ih =>\n    rcases List.mem_cons.mp ha with h | ha\n    · subst x\n      obtain ⟨r, hm, hp⟩ := pick_one ((List.mem_cons.mp hb).resolve_left (Ne.symm hne))\n      exact ⟨r, .inl (List.mem_append_left _ (List.mem_map.mpr ⟨(b, r), hm, rfl⟩)), hp.cons a⟩\n    · rcases List.mem_cons.mp hb with h | hb\n      · subst x\n        obtain ⟨r, hm, hp⟩ := pick_one (ws := xs) (a := a) (by assumption)\n        exact ⟨r, .inr (List.mem_append_left _ (List.mem_map.mpr ⟨(a, r), hm, rfl⟩)),\n          (hp.cons b).trans (.swap _ _ _)⟩\n      · obtain ⟨r, hm, hp⟩ := ih ha hb\n        refine ⟨x :: r, ?_,\n          (hp.cons x).trans ((List.Perm.swap _ _ _).trans ((List.Perm.swap _ _ _).cons a))⟩\n        rcases hm with hm | hm\n        · exact .inl (List.mem_append_right _ (List.mem_map.mpr ⟨(a, b, r), hm, rfl⟩))\n        · exact .inr (List.mem_append_right _ (List.mem_map.mpr ⟨(b, a, r), hm, rfl⟩))\n\ndef keepChoices (a b : ℕ) (r : List ℕ) : List (List ℕ) := [r, a :: r, b :: r, a :: b :: r]\n\ntheorem recover_kept {ws r : List ℕ} {a b : ℕ} {needed : Finset ℕ}\n    (hp : ws.Perm (a :: b :: r)) (hn : ws.Nodup)\n    (hs : ws.toFinset = insert a (insert b needed)) :\n    ∃ kept ∈ keepChoices a b r, kept.Nodup ∧ kept.toFinset = needed := by\n  have habr := hp.nodup_iff.mp hn\n  have hbase : ws.toFinset = insert a (insert b r.toFinset) := by\n    ext v\n    simp [hp.mem_iff]\n  have henne : ∀ v, v ∈ r ↔ v ∈ needed ∧ v ≠ a ∧ v ≠ b := by\n    intro v\n    have he : (v ∈ insert a (insert b r.toFinset)) ↔ v ∈ insert a (insert b needed) := by\n      rw [← hbase, ← hs]\n    simp only [Finset.mem_insert, List.mem_toFinset] at he\n    simp only [List.nodup_cons, List.mem_cons, not_or] at habr\n    grind\n  by_cases ha : a ∈ needed <;> by_cases hb : b ∈ needed\n  · refine ⟨a :: b :: r, by simp [keepChoices], habr, ?_⟩\n    ext v; simp [henne]; grind\n  · refine ⟨a :: r, by simp [keepChoices], ?_, ?_⟩\n    · simp_all [List.nodup_cons]\n    · ext v; simp [henne]; grind\n  · refine ⟨b :: r, by simp [keepChoices], (List.nodup_cons.mp habr).2, ?_⟩\n    ext v; simp [henne]; grind\n  · refine ⟨r, by simp [keepChoices], (List.nodup_cons.mp (List.nodup_cons.mp habr).2).2, ?_⟩\n    ext v; simp [henne]; grind\n\ntheorem recover_kept1 {ws r : List ℕ} {a : ℕ} {needed : Finset ℕ}\n    (hp : ws.Perm (a :: r)) (hn : ws.Nodup)\n    (hs : ws.toFinset = insert a needed) :\n    ∃ kept ∈ [r, a :: r], kept.Nodup ∧ kept.toFinset = needed := by\n  have har := hp.nodup_iff.mp hn\n  have hbase : ws.toFinset = insert a r.toFinset := by\n    ext v\n    simp [hp.mem_iff]\n  have henne : ∀ v, v ∈ r ↔ v ∈ needed ∧ v ≠ a := by\n    intro v\n    have he : (v ∈ insert a r.toFinset) ↔ v ∈ insert a needed := by\n      rw [← hbase, ← hs]\n    simp only [Finset.mem_insert, List.mem_toFinset] at he\n    simp only [List.nodup_cons] at har\n    grind\n  by_cases ha : a ∈ needed\n  · refine ⟨a :: r, by simp, har, ?_⟩\n    ext v; simp [henne]; grind\n  · refine ⟨r, by simp, (List.nodup_cons.mp har).2, ?_⟩\n    ext v; simp [henne]; grind\n\ntheorem singleton_list {ws : List ℕ} {goal : ℕ} (hn : ws.Nodup) (hs : ws.toFinset = {goal}) :\n    ws = [goal] := by\n  have hc := List.toFinset_card_of_nodup hn\n  rw [hs] at hc\n  cases ws with\n  | nil => simp at hc\n  | cons w ws =>\n    cases ws with\n    | nil => simpa using hs\n    | cons => simp at hc\n\ntheorem all_of_chunks {β : Type} (L : List β) (f : β → Bool) (B n : ℕ) (hlen : L.length ≤ B * n)\n    (h : ∀ i < n, ((L.drop (B * i)).take B).all f = true) : L.all f = true := by\n  rw [List.all_eq_true]\n  intro x hx\n  obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem hx\n  have hB : 0 < B := by\n    rcases Nat.eq_zero_or_pos B with h0 | h0\n    · subst h0; rw [Nat.zero_mul] at hlen; omega\n    · exact h0\n  have hi : j / B < n := by\n    rw [Nat.div_lt_iff_lt_mul hB]; rw [Nat.mul_comm] at hlen; omega\n  have hmod := Nat.mod_lt j hB\n  have hdm := Nat.div_add_mod j B\n  have hc := List.all_eq_true.mp (h (j / B) hi)\n  apply hc\n  rw [List.mem_iff_getElem]\n  refine ⟨j % B, ?_, ?_⟩\n  · simp only [List.length_take, List.length_drop]\n    omega\n  · simp only [List.getElem_take, List.getElem_drop]\n    congr 1\n    all_goals omega\n\nend Lists\n\nsection Search\n\ndef enc : List Bool → ℕ\n  | [] => 0\n  | b :: l => b.toNat + 2 * enc l\n\ntheorem testBit_enc (l : List Bool) (i : ℕ) : (enc l).testBit i = l.getD i false := by\n  induction l generalizing i with\n  | nil => simp [enc]\n  | cons b l ih =>\n    cases i with\n    | zero =>\n      simp only [enc, Nat.testBit_zero, List.getD_cons_zero]\n      cases b <;> simp <;> omega\n    | succ i =>\n      rw [Nat.testBit_add_one, List.getD_cons_succ, ← ih i]\n      congr 1\n      simp only [enc]\n      cases b <;> simp <;> omega\n\ndef maskN (N : ℕ) : ℕ := 2 ^ N - 1\n\ntheorem maskN_testBit (N r : ℕ) : (maskN N).testBit r = decide (r < N) := by\n  exact Nat.testBit_two_pow_sub_one N r\n\nvariable (goal mask : ℕ) (prs : List (ℕ × ℕ)) (N J : ℕ)\n\ndef prsOf : List (ℕ × ℕ) := (List.range J).map (fun j => (N + j, N + J + j))\n\ndef sepF (ws : List ℕ) : Bool :=\n  (ws.foldr (fun w acc => acc ||| ((w >>> N) ^^^ (w >>> (N + J)))) 0 &&& maskN J) == maskN J\n\ndef monF (ws : List ℕ) : Bool :=\n  (ws.foldr (fun w acc => acc ||| ((w >>> N) &&& (maskN J ^^^ (w >>> (N + J))))) 0 &&& maskN J)\n    == maskN J\n\ntheorem foldr_or_testBit (f : ℕ → ℕ) (ws : List ℕ) (i : ℕ) :\n    (ws.foldr (fun w acc => acc ||| f w) 0).testBit i = ws.any (fun w => (f w).testBit i) := by\n  induction ws with\n  | nil => simp\n  | cons w ws ih =>\n    simp only [List.foldr_cons, Nat.testBit_or, ih, List.any_cons]\n    exact Bool.or_comm _ _\n\ndef bop (a b : ℕ) : Finset ℕ := {a &&& b, a ||| b}\ndef uop (a : ℕ) : Finset ℕ := {mask ^^^ a}\n\ndef sepOK (ws : List ℕ) : Bool :=\n  prs.all (fun pq => ws.any (fun w => w.testBit pq.1 != w.testBit pq.2))\n\ndef monOK (ws : List ℕ) : Bool :=\n  prs.all (fun pq => ws.any (fun w => w.testBit pq.1 && !w.testBit pq.2))\n\ntheorem sepF_of {ws : List ℕ} (h : sepOK (prsOf N J) ws = true) : sepF N J ws = true := by\n  simp only [sepOK, prsOf, List.all_map, List.all_eq_true, List.mem_range, Function.comp_def,\n    List.any_eq_true, bne_iff_ne] at h\n  simp only [sepF, beq_iff_eq]\n  apply Nat.eq_of_testBit_eq\n  intro i\n  rw [Nat.testBit_and, maskN_testBit, foldr_or_testBit]\n  by_cases hi : i < J\n  · obtain ⟨w, hw, hd⟩ := h i hi\n    simp only [hi, decide_true, Bool.and_true, List.any_eq_true]\n    refine ⟨w, hw, ?_⟩\n    rw [Nat.testBit_xor, Nat.testBit_shiftRight, Nat.testBit_shiftRight]\n    revert hd\n    cases w.testBit (N + i) <;> cases w.testBit (N + J + i) <;> simp\n  · simp [hi]\n\ntheorem monF_of {ws : List ℕ} (h : monOK (prsOf N J) ws = true) : monF N J ws = true := by\n  simp only [monOK, prsOf, List.all_map, List.all_eq_true, List.mem_range, Function.comp_def,\n    List.any_eq_true, Bool.and_eq_true, Bool.not_eq_true'] at h\n  simp only [monF, beq_iff_eq]\n  apply Nat.eq_of_testBit_eq\n  intro i\n  rw [Nat.testBit_and, maskN_testBit, foldr_or_testBit]\n  by_cases hi : i < J\n  · obtain ⟨w, hw, hd1, hd2⟩ := h i hi\n    simp only [hi, decide_true, Bool.and_true, List.any_eq_true]\n    refine ⟨w, hw, ?_⟩\n    rw [Nat.testBit_and, Nat.testBit_xor, Nat.testBit_shiftRight, Nat.testBit_shiftRight,\n      maskN_testBit, hd1, hd2]\n    simp [hi]\n  · simp [hi]\n\ndef LS : ℕ → List ℕ → Bool\n  | 0, ws => ws == [goal]\n  | k + 1, ws => ws == [goal] ||\n      (decide (ws.length ≤ k + 2) && sepF N J ws && (ws.length != k + 2 || monF N J ws) &&\n        ((pairs ws).any (fun t => [t.1 &&& t.2.1, t.1 ||| t.2.1].any (fun z =>\n            !ws.contains z && (keepChoices t.1 t.2.1 t.2.2).any (fun kept => LS k (z :: kept)))) ||\n         (singles ws).any (fun t => !ws.contains (mask ^^^ t.1) &&\n            [t.2, t.1 :: t.2].any (fun kept => LS k ((mask ^^^ t.1) :: kept)))))\n\ntheorem LS_mono : ∀ k ws, LS goal mask N J k ws = true → LS goal mask N J (k + 1) ws = true := by\n  intro k\n  induction k with\n  | zero =>\n    intro ws h\n    simp only [LS] at h ⊢\n    simp [h]\n  | succ k ih =>\n    intro ws h\n    rw [LS] at h\n    rw [LS]\n    simp only [Bool.or_eq_true, Bool.and_eq_true, decide_eq_true_eq, List.any_eq_true,\n      bne_iff_ne] at h ⊢\n    rcases h with h | ⟨⟨⟨hl, hs⟩, _⟩, h⟩\n    · exact Or.inl h\n    · refine Or.inr ⟨⟨⟨by omega, hs⟩, Or.inl (by omega)⟩, ?_⟩\n      rcases h with ⟨t, ht, z, hz, hc, kept, hk, hr⟩ | ⟨t, ht, hc, kept, hk, hr⟩\n      · exact Or.inl ⟨t, ht, z, hz, hc, kept, hk, ih _ hr⟩\n      · exact Or.inr ⟨t, ht, hc, kept, hk, ih _ hr⟩\n\ntheorem bop_comm (a b : ℕ) : bop a b = bop b a := by\n  simp [bop, Nat.land_comm, Nat.lor_comm, Finset.pair_comm]\n\ndef Dpq (pq : ℕ × ℕ) (w : ℕ) : Prop := w.testBit pq.1 ≠ w.testBit pq.2\n\ntheorem sep_of_live (hD : ∀ pq ∈ prs, Dpq pq goal)\n    (hM : ∀ pq ∈ prs, mask.testBit pq.1 = mask.testBit pq.2)\n    {k : ℕ} {ws : List ℕ} (h : live bop (uop mask) goal k ws.toFinset) :\n    sepOK prs ws = true := by\n  simp only [sepOK, List.all_eq_true, List.any_eq_true, bne_iff_ne]\n  intro pq hpq\n  obtain ⟨w, hw, hd⟩ := live_separates (Dpq pq) (hD pq hpq)\n    (by\n      intro a b z hz hdz\n      simp only [bop, Finset.mem_insert, Finset.mem_singleton] at hz\n      unfold Dpq at hdz ⊢\n      rcases hz with rfl | rfl <;> revert hdz <;>\n        simp only [Nat.testBit_and, Nat.testBit_or] <;>\n        cases a.testBit pq.1 <;> cases a.testBit pq.2 <;>\n        cases b.testBit pq.1 <;> cases b.testBit pq.2 <;> simp)\n    (by\n      intro a z hz hdz\n      simp only [uop, Finset.mem_singleton] at hz\n      subst hz\n      unfold Dpq at hdz ⊢\n      have hm := hM pq hpq\n      revert hdz\n      simp only [Nat.testBit_xor, hm]\n      cases mask.testBit pq.2 <;> cases a.testBit pq.1 <;> cases a.testBit pq.2 <;> simp) h\n  exact ⟨w, List.mem_toFinset.mp hw, hd⟩\n\ntheorem mon_of_live (hO : ∀ pq ∈ prs, goal.testBit pq.1 = true ∧ goal.testBit pq.2 = false)\n    {k : ℕ} {ws : List ℕ} (hn : ws.Nodup) (h : live bop (uop mask) goal k ws.toFinset)\n    (hc : ws.length = k + 1) : monOK prs ws = true := by\n  simp only [monOK, List.all_eq_true, List.any_eq_true, Bool.and_eq_true, Bool.not_eq_true']\n  intro pq hpq\n  obtain ⟨w, hw, hd⟩ := live_tight (fun w => w.testBit pq.1 = true ∧ w.testBit pq.2 = false)\n    (hO pq hpq)\n    (by\n      intro a b z hz hdz\n      simp only [bop, Finset.mem_insert, Finset.mem_singleton] at hz\n      rcases hz with rfl | rfl <;> revert hdz <;>\n        simp only [Nat.testBit_and, Nat.testBit_or] <;>\n        cases a.testBit pq.1 <;> cases a.testBit pq.2 <;>\n        cases b.testBit pq.1 <;> cases b.testBit pq.2 <;> simp) h\n    (by rw [List.toFinset_card_of_nodup hn, hc])\n  exact ⟨w, List.mem_toFinset.mp hw, hd⟩\n\ntheorem LS_complete (hD : ∀ pq ∈ prsOf N J, Dpq pq goal)\n    (hM : ∀ pq ∈ prsOf N J, mask.testBit pq.1 = mask.testBit pq.2)\n    (hO : ∀ pq ∈ prsOf N J, goal.testBit pq.1 = true ∧ goal.testBit pq.2 = false) :\n    ∀ k (ws : List ℕ), ws.Nodup → live bop (uop mask) goal k ws.toFinset →\n      LS goal mask N J k ws = true := by\n  intro k\n  induction k with\n  | zero =>\n    intro ws hn h\n    simp [LS, singleton_list hn h]\n  | succ k ih =>\n    intro ws hn h\n    have hcard := live_card h\n    rw [List.toFinset_card_of_nodup hn] at hcard\n    have hsep := sepF_of N J (sep_of_live goal mask (prsOf N J) hD hM h)\n    have hmon : (ws.length != k + 2) = true ∨ monF N J ws = true := by\n      by_cases hl : ws.length = k + 2\n      · exact Or.inr (monF_of N J (mon_of_live goal mask (prsOf N J) hO hn h hl))\n      · exact Or.inl (by simp [hl])\n    rcases h with skip | ⟨a, ha, b, hb, hab, z, hz, hout, needed, hs, tail⟩ |\n        ⟨a, ha, z, hz, hout, needed, hs, tail⟩\n    · exact LS_mono goal mask N J k ws (ih ws hn skip)\n    · obtain ⟨r, hm, hp⟩ := pick_two (List.mem_toFinset.mp ha) (List.mem_toFinset.mp hb) hab\n      have hzc : ws.contains z = false := by\n        simpa using fun hh => hout (List.mem_toFinset.mpr hh)\n      have go {a b : ℕ} (perm : ws.Perm (a :: b :: r))\n          (hset : ws.toFinset = insert a (insert b needed)) (hop : z ∈ bop a b) :\n          [a &&& b, a ||| b].any (fun z =>\n            !ws.contains z && (keepChoices a b r).any (fun kept => LS goal mask N J k (z :: kept)))\n            = true := by\n        obtain ⟨kept, hk, hnk, hfin⟩ := recover_kept perm hn hset\n        have hznew : z ∉ kept := by\n          intro hu\n          apply hout\n          rw [hset]\n          exact Finset.mem_insert_of_mem (Finset.mem_insert_of_mem\n            (hfin ▸ (List.mem_toFinset.mpr hu)))\n        have hnd : (z :: kept).Nodup := List.nodup_cons.mpr ⟨hznew, hnk⟩\n        have hl : live bop (uop mask) goal k (z :: kept).toFinset := by\n          simpa [hfin] using tail\n        have hrec := ih _ hnd hl\n        simp only [List.any_eq_true, Bool.and_eq_true, Bool.not_eq_true']\n        refine ⟨z, ?_, hzc, kept, hk, hrec⟩\n        simp only [bop, Finset.mem_insert, Finset.mem_singleton] at hop\n        rcases hop with rfl | rfl <;> simp\n      simp only [LS, Bool.or_eq_true, Bool.and_eq_true, decide_eq_true_eq]\n      right\n      refine ⟨⟨⟨by omega, hsep⟩, hmon⟩, Or.inl ?_⟩\n      simp only [List.any_eq_true]\n      rcases hm with direct | swap\n      · exact ⟨(a, b, r), direct, by simpa using go hp hs hz⟩\n      · exact ⟨(b, a, r), swap, by\n          simpa using go (hp.trans (.swap _ _ _)) (by rw [hs, Finset.insert_comm])\n            (bop_comm a b ▸ hz)⟩\n    · obtain ⟨r, hm, hp⟩ := pick_one (List.mem_toFinset.mp ha)\n      simp only [uop, Finset.mem_singleton] at hz\n      subst hz\n      have hzc : ws.contains (mask ^^^ a) = false := by\n        simpa using fun hh => hout (List.mem_toFinset.mpr hh)\n      obtain ⟨kept, hk, hnk, hfin⟩ := recover_kept1 hp hn hs\n      have hznew : (mask ^^^ a) ∉ kept := by\n        intro hu\n        apply hout\n        rw [hs]\n        exact Finset.mem_insert_of_mem (hfin ▸ (List.mem_toFinset.mpr hu))\n      have hnd : ((mask ^^^ a) :: kept).Nodup := List.nodup_cons.mpr ⟨hznew, hnk⟩\n      have hl : live bop (uop mask) goal k ((mask ^^^ a) :: kept).toFinset := by\n        simpa [hfin] using tail\n      have hrec := ih _ hnd hl\n      simp only [LS, Bool.or_eq_true, Bool.and_eq_true, decide_eq_true_eq]\n      right\n      refine ⟨⟨⟨by omega, hsep⟩, hmon⟩, Or.inr ?_⟩\n      simp only [List.any_eq_true, Bool.and_eq_true, Bool.not_eq_true']\n      exact ⟨(a, r), hm, hzc, kept, hk, hrec⟩\n\nend Search\n\nsection Circ\n\ndef step (w : List Bool) (g : Gate) : List Bool :=\n  w ++ [g.op.eval (g.inputs.map fun i => w.getD i false)]\n\ndef beh (W : List (List Bool)) (i : ℕ) : ℕ := enc (W.map fun w => w.getD i false)\n\ntheorem getD_map_row (W : List (List Bool)) (i r : ℕ) :\n    (W.map fun w => w.getD i false).getD r false = (W.getD r []).getD i false := by\n  simp only [List.getD_eq_getElem?_getD, List.getElem?_map]\n  cases W[r]? <;> simp\n\ntheorem beh_testBit (W : List (List Bool)) (i r : ℕ) :\n    (beh W i).testBit r = (W.getD r []).getD i false := by\n  rw [beh, testBit_enc, getD_map_row]\n\ntheorem row_of_lt {W : List (List Bool)} {r : ℕ} (h : r < W.length) :\n    W.getD r [] ∈ W := by\n  simp only [List.getD_eq_getElem?_getD, List.getElem?_eq_getElem h, Option.getD_some]\n  exact List.getElem_mem h\n\ntheorem row_of_ge {W : List (List Bool)} {r : ℕ} (h : W.length ≤ r) : W.getD r [] = [] := by\n  simp [List.getD_eq_getElem?_getD, List.getElem?_eq_none h]\n\ntheorem getD_step_ne {w : List Bool} {g : Gate} {i : ℕ} (hi : i ≠ w.length) :\n    (step w g).getD i false = w.getD i false := by\n  simp only [step, List.getD_eq_getElem?_getD]\n  rcases Nat.lt_or_gt_of_ne hi with h | h\n  · rw [List.getElem?_append_left h]\n  · rw [List.getElem?_eq_none (by simp; omega), List.getElem?_eq_none (by omega)]\n\ntheorem getD_step_eq {w : List Bool} {g : Gate} :\n    (step w g).getD w.length false = g.op.eval (g.inputs.map fun i => w.getD i false) := by\n  simp [step, List.getD_eq_getElem?_getD]\n\ntheorem mapstep_row (W : List (List Bool)) (g : Gate) (r : ℕ) :\n    (W.map (fun w => step w g)).getD r [] =\n      if r < W.length then step (W.getD r []) g else [] := by\n  simp only [List.getD_eq_getElem?_getD, List.getElem?_map]\n  by_cases h : r < W.length\n  · simp [h, List.getElem?_eq_getElem h]\n  · simp [h, List.getElem?_eq_none (Nat.le_of_not_lt h)]\n\ntheorem beh_old {W : List (List Bool)} {L : ℕ} (hl : ∀ w ∈ W, w.length = L) (g : Gate) {i : ℕ}\n    (hi : i ≠ L) : beh (W.map (fun w => step w g)) i = beh W i := by\n  apply Nat.eq_of_testBit_eq\n  intro r\n  rw [beh_testBit, beh_testBit, mapstep_row]\n  by_cases h : r < W.length\n  · simp only [h, ↓reduceIte]\n    rw [getD_step_ne (by rw [hl _ (row_of_lt h)]; exact hi)]\n  · simp only [h, ↓reduceIte]\n    rw [row_of_ge (Nat.le_of_not_lt h)]\n\ntheorem beh_beyond {W : List (List Bool)} {L : ℕ} (hl : ∀ w ∈ W, w.length = L) {i : ℕ}\n    (hi : L ≤ i) : beh W i = 0 := by\n  apply Nat.eq_of_testBit_eq\n  intro r\n  rw [beh_testBit, Nat.zero_testBit]\n  by_cases h : r < W.length\n  · have h2 : (W.getD r []).length ≤ i := by rw [hl _ (row_of_lt h)]; exact hi\n    exact List.getD_eq_default _ _ h2\n  · rw [row_of_ge (Nat.le_of_not_lt h)]\n    rfl\n\ndef okGate (g : Gate) : Prop :=\n  g.op ∈ ({GateOp.and, GateOp.or, GateOp.not} : Set GateOp) ∧ g.inputs.length ≤ 2\n\ntheorem beh_new {W : List (List Bool)} {L N : ℕ} (hl : ∀ w ∈ W, w.length = L)\n    (hN : W.length = N) (g : Gate) (z : ℕ)\n    (hz : ∀ r, (r < N → z.testBit r =\n        g.op.eval (g.inputs.map fun i => (W.getD r []).getD i false)) ∧\n      (N ≤ r → z.testBit r = false)) :\n    beh (W.map (fun w => step w g)) L = z := by\n  apply Nat.eq_of_testBit_eq\n  intro r\n  rw [beh_testBit, mapstep_row]\n  by_cases h : r < W.length\n  · simp only [h, ↓reduceIte]\n    have hm := row_of_lt h\n    have := getD_step_eq (w := W.getD r []) (g := g)\n    rw [hl _ hm] at this\n    rw [this, (hz r).1 (hN ▸ h)]\n  · simp only [h, ↓reduceIte]\n    rw [(hz r).2 (by omega)]\n    rfl\n\ntheorem gate_step {W : List (List Bool)} {L N : ℕ} (hl : ∀ w ∈ W, w.length = L)\n    (hN : W.length = N) (av : Finset ℕ) (hmask : maskN N ∈ av) (hinv : ∀ i, beh W i ∈ av)\n    (g : Gate) (hg : okGate g) :\n    ∃ z, (z ∈ av ∨ (∃ a ∈ av, ∃ b ∈ av, a ≠ b ∧ z ∈ bop a b) ∨\n        (∃ a ∈ av, z ∈ uop (maskN N) a)) ∧\n      beh (W.map (fun w => step w g)) L = z := by\n  obtain ⟨op, inputs⟩ := g\n  obtain ⟨hop, hlen⟩ := hg\n  simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hop\n  simp only at hlen\n  have hbeyond := beh_beyond hl (le_refl L)\n  have hi : ∀ i r, N ≤ r → (beh W i).testBit r = false := by\n    intro i r hr\n    rw [beh_testBit, row_of_ge (by omega)]\n    rfl\n  have hmk : ∀ r, N ≤ r → (maskN N).testBit r = false := by\n    intro r hr\n    rw [maskN_testBit]\n    simp; omega\n  have hmk' : ∀ r, r < N → (maskN N).testBit r = true := by\n    intro r hr\n    rw [maskN_testBit]\n    simp; omega\n  match inputs, hlen with\n  | [], _ =>\n    rcases hop with rfl | rfl | rfl\n    · refine ⟨maskN N, Or.inl hmask, beh_new hl hN _ _ ?_⟩\n      intro r\n      exact ⟨fun hr => by simp [hmk' r hr, GateOp.eval], fun hr => hmk r hr⟩\n    · refine ⟨0, Or.inl (hbeyond ▸ hinv L), beh_new hl hN _ _ ?_⟩\n      intro r\n      exact ⟨fun _ => by simp [GateOp.eval], fun _ => by simp⟩\n    · refine ⟨maskN N, Or.inl hmask, beh_new hl hN _ _ ?_⟩\n      intro r\n      exact ⟨fun hr => by simp [hmk' r hr, GateOp.eval], fun hr => hmk r hr⟩\n  | [i], _ =>\n    rcases hop with rfl | rfl | rfl\n    · refine ⟨beh W i, Or.inl (hinv i), beh_new hl hN _ _ ?_⟩\n      intro r\n      exact ⟨fun _ => by simp [beh_testBit, GateOp.eval], fun hr => hi i r hr⟩\n    · refine ⟨beh W i, Or.inl (hinv i), beh_new hl hN _ _ ?_⟩\n      intro r\n      exact ⟨fun _ => by simp [beh_testBit, GateOp.eval], fun hr => hi i r hr⟩\n    · refine ⟨maskN N ^^^ beh W i, Or.inr (Or.inr ⟨beh W i, hinv i, by simp [uop]⟩),\n        beh_new hl hN _ _ ?_⟩\n      intro r\n      exact ⟨fun hr => by simp [Nat.testBit_xor, hmk' r hr, beh_testBit, GateOp.eval],\n        fun hr => by simp [Nat.testBit_xor, hmk r hr, hi i r hr]⟩\n  | [i, j], _ =>\n    rcases hop with rfl | rfl | rfl\n    · refine ⟨beh W i &&& beh W j, ?_, beh_new hl hN _ _ ?_⟩\n      · by_cases e : beh W i = beh W j\n        · left; rw [e, Nat.and_self]; exact hinv j\n        · right; left; exact ⟨_, hinv i, _, hinv j, e, by simp [bop]⟩\n      · intro r\n        exact ⟨fun _ => by simp [Nat.testBit_and, beh_testBit, GateOp.eval],\n          fun hr => by simp [Nat.testBit_and, hi i r hr]⟩\n    · refine ⟨beh W i ||| beh W j, ?_, beh_new hl hN _ _ ?_⟩\n      · by_cases e : beh W i = beh W j\n        · left; rw [e, Nat.or_self]; exact hinv j\n        · right; left; exact ⟨_, hinv i, _, hinv j, e, by simp [bop]⟩\n      · intro r\n        exact ⟨fun _ => by simp [Nat.testBit_or, beh_testBit, GateOp.eval],\n          fun hr => by simp [Nat.testBit_or, hi i r hr, hi j r hr]⟩\n    · refine ⟨maskN N ^^^ beh W i, Or.inr (Or.inr ⟨beh W i, hinv i, by simp [uop]⟩),\n        beh_new hl hN _ _ ?_⟩\n      intro r\n      exact ⟨fun hr => by simp [Nat.testBit_xor, hmk' r hr, beh_testBit, GateOp.eval],\n        fun hr => by simp [Nat.testBit_xor, hmk r hr, hi i r hr]⟩\n  | _ :: _ :: _ :: _, h => simp at h\n\ndef stepAll (gs : List Gate) (W : List (List Bool)) : List (List Bool) :=\n  gs.foldl (fun W g => W.map (fun w => step w g)) W\n\ntheorem to_build (N goal : ℕ) (gs : List Gate) (hg : ∀ g ∈ gs, okGate g) :\n    ∀ (L : ℕ) (W : List (List Bool)) (av : Finset ℕ), (∀ w ∈ W, w.length = L) → W.length = N →\n      maskN N ∈ av → (∀ i, beh W i ∈ av) → ∀ o, beh (stepAll gs W) o = goal →\n      build bop (uop (maskN N)) goal gs.length av := by\n  induction gs with\n  | nil =>\n    intro L W av _ _ _ hinv o ho\n    exact ho ▸ hinv o\n  | cons g gs ih =>\n    intro L W av hl hN hm hinv o ho\n    obtain ⟨z, hz, hbz⟩ := gate_step hl hN av hm hinv g (hg g (by simp))\n    have hl' : ∀ w ∈ W.map (fun w => step w g), w.length = L + 1 := by\n      intro w hw\n      obtain ⟨w0, hw0, rfl⟩ := List.mem_map.mp hw\n      simp [step, hl w0 hw0]\n    have hN' : (W.map (fun w => step w g)).length = N := by simp [hN]\n    have hinv' : ∀ i, beh (W.map (fun w => step w g)) i ∈ insert z av := by\n      intro i\n      by_cases hi : i = L\n      · subst hi; rw [hbz]; exact Finset.mem_insert_self _ _\n      · rw [beh_old hl g hi]; exact Finset.mem_insert_of_mem (hinv i)\n    have hrec := ih (fun g hg' => hg g (List.mem_cons_of_mem _ hg')) (L + 1) _ (insert z av)\n      hl' hN' (Finset.mem_insert_of_mem hm) hinv' o ho\n    rw [List.length_cons]\n    rcases hz with hz | ⟨a, ha, b, hb, hab, hz⟩ | ⟨a, ha, hz⟩\n    · rw [Finset.insert_eq_of_mem hz] at hrec; exact Or.inl hrec\n    · exact Or.inr (Or.inl ⟨a, ha, b, hb, hab, z, hz, hrec⟩)\n    · exact Or.inr (Or.inr ⟨a, ha, z, hz, hrec⟩)\n\ntheorem stepAll_eq (gs : List Gate) :\n    ∀ W, stepAll gs W = W.map (fun w => gs.foldl step w) := by\n  induction gs with\n  | nil => intro W; simp [stepAll]\n  | cons g gs ih =>\n    intro W\n    show stepAll gs (W.map (fun w => step w g)) = _\n    rw [ih, List.map_map]\n    rfl\n\ndef rowsOf (n m : ℕ) (ex : List (Fin n × Fin m)) : List (List Bool) :=\n  ((List.finRange n).flatMap fun u => (List.finRange m).map fun v => oneEach u v) ++\n    ex.map (fun p => oneEach p.1 p.2)\n\ndef goalOf {n m : ℕ} (A : Fin n → Fin m → Bool) (ex : List (Fin n × Fin m)) : List Bool :=\n  ((List.finRange n).flatMap fun u => (List.finRange m).map fun v => A u v) ++\n    ex.map (fun p => A p.1 p.2)\n\ntheorem rows_len (n m : ℕ) (ex : List (Fin n × Fin m)) :\n    ∀ w ∈ rowsOf n m ex, w.length = n + m := by\n  intro w hw\n  simp only [rowsOf, List.mem_append, List.mem_flatMap, List.mem_map, List.mem_finRange,\n    true_and] at hw\n  rcases hw with ⟨u, v, rfl⟩ | ⟨p, _, rfl⟩ <;> simp [oneEach]\n\ntheorem final_beh {n m : ℕ} (A : Fin n → Fin m → Bool) (ex : List (Fin n × Fin m)) (C : Circuit)\n    (hr : Represents A C) :\n    beh (stepAll C.gates (rowsOf n m ex)) C.output = enc (goalOf A ex) := by\n  rw [beh, stepAll_eq, List.map_map]\n  congr 1\n  have : (rowsOf n m ex).map (fun x => C.eval x) = goalOf A ex := by\n    simp only [rowsOf, goalOf, List.map_append, List.map_flatMap, List.map_map]\n    congr 1\n    · congr 1\n      funext u\n      apply List.map_congr_left\n      intro v _\n      exact hr u v\n    · apply List.map_congr_left\n      intro p _\n      exact hr p.1 p.2\n  rw [← this]\n  rfl\n\ntheorem refute {n m : ℕ} (A : Fin n → Fin m → Bool) (K Nb J Nt goal mask : ℕ) (init : List ℕ)\n    (ex : List (Fin n × Fin m))\n    (hN : (rowsOf n m ex).length = Nt) (hgoal : enc (goalOf A ex) = goal) (hmask : maskN Nt = mask)\n    (hinit : ((List.range (n + m)).all (fun i => init.contains (beh (rowsOf n m ex) i)) &&\n      init.contains 0 && init.contains mask) = true)\n    (hnd : init.Nodup)\n    (hprs : (List.range J).all (fun j => (goal.testBit (Nb + j) && !goal.testBit (Nb + J + j)) &&\n      (mask.testBit (Nb + j) == mask.testBit (Nb + J + j))) = true)\n    (hsearch : init.sublists.all (fun l => !LS goal mask Nb J K l) = true) :\n    ¬ ∃ C : Circuit, FanInTwo C ∧ C.size ≤ K ∧ Represents A C := by\n  rintro ⟨C, hF, hs, hr⟩\n  simp only [Bool.and_eq_true, List.all_eq_true, List.contains_iff_mem, List.mem_range] at hinit\n  obtain ⟨⟨hinp, h0⟩, hm⟩ := hinit\n  have hinv : ∀ i, beh (rowsOf n m ex) i ∈ init.toFinset := by\n    intro i\n    rw [List.mem_toFinset]\n    by_cases h : i < n + m\n    · exact hinp i h\n    · rw [beh_beyond (rows_len n m ex) (Nat.le_of_not_lt h)]; exact h0\n  have hb := to_build Nt goal C.gates hF (n + m) (rowsOf n m ex) init.toFinset (rows_len n m ex) hN\n    (by rw [hmask]; exact List.mem_toFinset.mpr hm) hinv C.output\n    (by rw [final_beh A ex C hr, hgoal])\n  rw [hmask] at hb\n  have hb' := build_mono hb K hs\n  obtain ⟨S, hS, hlive⟩ := compress hb'\n  have hall : ∀ pq ∈ prsOf Nb J, (goal.testBit pq.1 = true ∧ goal.testBit pq.2 = false) ∧\n      mask.testBit pq.1 = mask.testBit pq.2 := by\n    intro pq hpq\n    obtain ⟨j, hj, rfl⟩ := List.mem_map.mp hpq\n    have := List.all_eq_true.mp hprs j hj\n    simp only [Bool.and_eq_true, Bool.not_eq_true', beq_iff_eq] at this\n    exact this\n  have hO : ∀ pq ∈ prsOf Nb J, goal.testBit pq.1 = true ∧ goal.testBit pq.2 = false :=\n    fun pq hpq => (hall pq hpq).1\n  have hD : ∀ pq ∈ prsOf Nb J, Dpq pq goal := by\n    intro pq hpq\n    have := hO pq hpq\n    unfold Dpq\n    rw [this.1, this.2]\n    simp\n  have hM : ∀ pq ∈ prsOf Nb J, mask.testBit pq.1 = mask.testBit pq.2 :=\n    fun pq hpq => (hall pq hpq).2\n  let l := init.filter (fun x => decide (x ∈ S))\n  have hl_sub : l ∈ init.sublists := List.mem_sublists.mpr List.filter_sublist\n  have hl_nd : l.Nodup := hnd.filter _\n  have hl_fs : l.toFinset = S := by\n    ext x\n    simp only [l, List.mem_toFinset, List.mem_filter, decide_eq_true_eq]\n    exact ⟨fun h => h.2, fun h => ⟨List.mem_toFinset.mp (hS h), h⟩⟩\n  have hc := LS_complete goal mask Nb J hD hM hO K l hl_nd (hl_fs ▸ hlive)\n  have hf := List.all_eq_true.mp hsearch l hl_sub\n  rw [hc] at hf\n  exact Bool.noConfusion hf\n\nend Circ\n\ndef G0 : ℕ := 18446744073709501935\ndef MK0 : ℕ := 5192296858534827628530496329220095\ndef I0 : List ℕ := [4294901775, 346153123902320612136682732388592, 692306247804641296278191534509824, 4153837486827865720115617767419904, 346153123902321693246888201883921, 692306247804658518060823225573922, 1384612495609282452699535059731524, 2769224991218564964523249842030728, 0, 5192296858534827628530496329220095]\ndef E0 : List (Fin 4 × Fin 4) := [(0, 0), (0, 0), (0, 0), (0, 0), (0, 1), (0, 1), (0, 1), (0, 1), (0, 2), (0, 2), (0, 2), (0, 2), (0, 3), (0, 3), (0, 3), (0, 3), (1, 1), (1, 1), (1, 1), (1, 1), (1, 2), (1, 2), (1, 2), (1, 2), (1, 3), (1, 3), (1, 3), (1, 3), (2, 0), (2, 0), (2, 0), (2, 0), (2, 2), (2, 2), (2, 2), (2, 2), (2, 3), (2, 3), (2, 3), (2, 3), (3, 0), (3, 0), (3, 0), (3, 0), (3, 1), (3, 1), (3, 1), (3, 1), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3), (1, 0), (2, 1), (3, 2), (3, 3)]\n\ndef S0test (l : List ℕ) : Bool := !LS G0 MK0 16 48 6 l\n\nset_option maxRecDepth 20000 in\nset_option maxHeartbeats 0 in\ntheorem S0_0 : ((I0.sublists.drop (128 * 0)).take 128).all S0test = true := by\n  decide +kernel\n\nset_option maxRecDepth 20000 in\nset_option maxHeartbeats 0 in\ntheorem S0_1 : ((I0.sublists.drop (128 * 1)).take 128).all S0test = true := by\n  decide +kernel\n\nset_option maxRecDepth 20000 in\nset_option maxHeartbeats 0 in\ntheorem S0_2 : ((I0.sublists.drop (128 * 2)).take 128).all S0test = true := by\n  decide +kernel\n\nset_option maxRecDepth 20000 in\nset_option maxHeartbeats 0 in\ntheorem S0_3 : ((I0.sublists.drop (128 * 3)).take 128).all S0test = true := by\n  decide +kernel\n\nset_option maxRecDepth 20000 in\nset_option maxHeartbeats 0 in\ntheorem S0_4 : ((I0.sublists.drop (128 * 4)).take 128).all S0test = true := by\n  decide +kernel\n\nset_option maxRecDepth 20000 in\nset_option maxHeartbeats 0 in\ntheorem S0_5 : ((I0.sublists.drop (128 * 5)).take 128).all S0test = true := by\n  decide +kernel\n\nset_option maxRecDepth 20000 in\nset_option maxHeartbeats 0 in\ntheorem S0_6 : ((I0.sublists.drop (128 * 6)).take 128).all S0test = true := by\n  decide +kernel\n\nset_option maxRecDepth 20000 in\nset_option maxHeartbeats 0 in\ntheorem S0_7 : ((I0.sublists.drop (128 * 7)).take 128).all S0test = true := by\n  decide +kernel\n\ntheorem S0 : I0.sublists.all S0test = true :=\n  all_of_chunks _ _ 128 8 (by decide +kernel) (fun i hi => match i, hi with\n    | 0, _ => S0_0\n    | 1, _ => S0_1\n    | 2, _ => S0_2\n    | 3, _ => S0_3\n    | 4, _ => S0_4\n    | 5, _ => S0_5\n    | 6, _ => S0_6\n    | 7, _ => S0_7\n    | _ + 8, hi => absurd hi (by omega))\n\nend PEqualNP.Outside.L_meta_25851_aux\n\nopen PEqualNP.Outside.L_meta_25851_aux in\ntheorem PEqualNP.Outside.L_meta_25851 : Not (∃ C : PEqualNP.CircuitLowerBounds.Circuit, PEqualNP.MetaComplexity.FanInTwo C ∧ C.size ≤ 6 ∧ PEqualNP.Represents.Represents (fun u v : Fin 4 => (15855 : ℕ).testBit (4 * u.val + v.val)) C) :=\n  refute (fun u v : Fin 4 => (15855 : ℕ).testBit (4 * u.val + v.val)) 6 16 48 112 G0 MK0 I0 E0\n    (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel)\n    (by decide +kernel) (by decide +kernel) S0\n","lean_bytes":38630,"lean_sha256":"fdcc5fddff8ade7290cc9fdd616477850ca39422e3999bb8e8c47f27829c614b","build":{"exit":0,"seconds":88.78,"peak_memory_gb":5.7507},"checker":{"exit":0,"last_line":"ACCEPTED (refute): PEqualNP.Outside.L_meta_25851; axioms [propext, Quot.sound, Classical.choice]; kernel re-checked 1923 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.SplitCount, PEqualNP.Defs.InvisibleWire, PEqualNP.Defs.SharedOr, PEqualNP.Defs.CleanedNonEdge, PEqualNP.Defs.MergeCost, PEqualNP.Defs.CarriedProduct, PEqualNP.Defs.TopForm, PEqualNP.Defs.SyntacticMultilinear, PEqualNP.Defs.TopFormNames, PEqualNP.Defs.HeptadCover, PEqualNP.Defs.ReadK, PEqualNP.Defs.GenericRejection, PEqualNP.Defs.CrossAnd, PEqualNP.Defs.ReadKJoin, PEqualNP.Defs.SharedBlockCost, PEqualNP.Defs.ReadTwo, PEqualNP.Defs.LratEncoding, PEqualNP.Defs.Core, PEqualNP.Defs.PointTypes, PEqualNP.Defs.FactorSubst, PEqualNP.Defs.TwoColour, PEqualNP.Defs.Represents, PEqualNP.Defs.BranchingProgram, PEqualNP.Defs, PEqualNP.Outside.L_meta_25851]"},"axioms":["propext","Quot.sound","Classical.choice"],"missing":[],"approach":{"run":"g++ -O3 -std=c++17 search.cpp -o search && ./search 7","search_log":["bound 1 found 0 prefixes 1","bound 2 found 0 prefixes 1 52","bound 3 found 0 prefixes 1 52 1842","bound 4 found 0 prefixes 1 52 1842 57244","bound 5 found 0 prefixes 1 52 1842 57244 1710229","bound 6 found 0 prefixes 1 52 1842 57244 1710229 51265464","witness 7","& 5 2 512","| 7 1 35064","| 9 6 52476","| 4 3 61713","& 11 10 49168","| 12 8 49680","! 13 -1 15855","bound 7 found 1 prefixes 1 29 1012 30863 906727 26790708 813623639"],"proof_repo_commit":"e8dc2d83cc1f03dc3fcf24af495304f2dc5e0d36","row_pr_open":0,"lean_path":"lean/PEqualNP/Outside/L_meta_25851.lean","lean_module":"PEqualNP.Outside.L_meta_25851","lean_search":"The circuit trace is transposed to table masks and compressed to its live frontier. A frontier must distinguish every target-one/target-zero pair, contain at most one more wire than the remaining gate budget, and separate the pairs in the positive direction when at that width limit. The kernel computes the result over all subsets of the initial wires and constants.","adapted_from":"PEqualNP.Outside.L_meta_25814 at the pinned commit, with a new target, gate budget, separation pairs, and mask computation.","license":"\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","release":"leanprover/lean4:v4.36.0","mathlib_commit":"fc4f59e577feb1a4956671bc04ac18aaaf8cd842","checker_seconds":229.31,"lean_witness_check_exit":0},"skipped":false}
