{
 "unit": "L-meta-25842",
 "statement": "∃ C : PEqualNP.CircuitLowerBounds.Circuit, PEqualNP.MetaComplexity.FanInTwo C ∧ C.size ≤ 5 ∧ PEqualNP.Represents.Represents (fun u v : Fin 4 => (31711 : ℕ).testBit (4 * u.val + v.val)) C",
 "verdict": "no_circuit",
 "search_complete": true,
 "min_gates": 6,
 "circuit": {
  "note": "no circuit of at most 5 gates exists; this is the 6-gate circuit the same program finds (wires 0-3 = left vertices u, 4-7 = right vertices v)",
  "gates": [
   [
    "and",
    [
     1,
     5
    ]
   ],
   [
    "and",
    [
     2,
     6
    ]
   ],
   [
    "and",
    [
     3,
     7
    ]
   ],
   [
    "or",
    [
     8,
     9
    ]
   ],
   [
    "or",
    [
     10,
     11
    ]
   ],
   [
    "not",
    [
     12
    ]
   ]
  ],
  "output": 13,
  "function": "A u v = not (u = v and u != 0); row masks 15, 13, 11, 7"
 },
 "coverage": "Each wire is its 16-bit table on the promised inputs oneEach u v (bit 4u+v); wire u = 0xF<<4u, wire 4+v = 0x1111<<v; target 31711. Every circuit the definitions allow reduces to one the program enumerates with no more gates: (1) an index at or past the current wire count (absent, including forward references) reads false = table 0, so and with it gives 0, or gives a copy, not gives all-ones; (2) and[]=all-ones, or[]=0, not[]=all-ones, one-input and/or are copies, not reads only its first input, repeated inputs (a,a) give copies; (3) a gate whose table is already available (an input, an earlier gate, or 0) can be deleted and its readers redirected, so a minimal circuit has pairwise distinct new tables; the target is neither 0 nor all-ones, and a constant all-ones wire only yields 0, copies or itself, so constant gates are never needed; (4) unused gates can be deleted, and the output can be taken as the last gate (any output index, including an input or absent index, is covered by checking the target against every available table, which also excludes 0 and 1 gate trivially). So every candidate gate is not a, a and b, or a or b over available wires (a<b). Symmetry pruning: among the topological orders of the gate DAG the lexicographically least by gate key has each gate either reading the previous gate or with key larger than it, which the DFS enforces. Results: max 1..5 gates visited 53 / 1895 / 63301 / 2254964 / 89514993 nodes, none reached 31711; with 6 gates the program finds the circuit above. Cross-check: target 279 (a known 5-gate unit, L_meta_19236) is found by the same program. Lean side independent of this argument: the theorem uses the generic refute lemma (proved in the file) which turns any FanInTwo circuit of at most 5 gates representing A into a live set of wire tables over 94 rows (16 promised rows + 39 true-cell copies + 39 false-cell copies, one per true/false pair), and decide +kernel checks that no subset of the 10 initial tables (8 inputs, 0, all-ones) is live for 5 gates.",
 "program": "/* Exhaustive search for FanInTwo circuits representing A u v = testBit(T, 4u+v), u,v in Fin 4.\n   Wire = 16-bit table on the 16 promised inputs oneEach u v (bit 4u+v).\n   Inputs: wire u (0..3) = 0xF<<4u, wire 4+v = 0x1111<<v.\n   Reduction (argued in result.json): a gate whose table is already available (input wire,\n   earlier gate, or 0 = an absent index) can be dropped; constant gates (and[]/not[] = all ones,\n   or[] = 0) never help a target that is neither 0 nor all ones except as output; one-input\n   and/or are copies; not with 2 inputs = not of first; inputs at absent indices read 0, giving\n   and = 0, or = copy, not = all-ones. So every minimal circuit is a list of distinct new tables\n   each = ~a, a&b or a|b of available wires, and the output is the last gate.\n   Canonical order: adjacent gates that do not depend on each other appear in increasing key. */\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\nstatic uint16_t T; static int maxg; static uint16_t w[32]; static int n;\nstatic int key[32], usesPrev[32]; static int op[32], ia[32], ib[32];\nstatic long long nodes=0; static int found=0;\nstatic int avail(uint16_t t){ if(t==0) return 1; for(int i=0;i<n;i++) if(w[i]==t) return 1; return 0; }\nstatic void report(void){\n  printf(\"FOUND %d gates:\", n-8);\n  for(int j=8;j<n;j++){ printf(\" w%d=%s(w%d%s\",j,op[j]==0?\"and\":op[j]==1?\"or\":\"not\",ia[j],op[j]==2?\")\":\"\"); if(op[j]!=2) printf(\",w%d)\",ib[j]); }\n  printf(\" out=w%d\\n\", n-1); fflush(stdout);\n}\nstatic void dfs(void){\n  nodes++;\n  int g = n-8; if(g>=maxg) return;\n  int last = n-1;\n  /* candidate gates */\n  for(int o=0;o<3;o++) for(int a=0;a<n;a++) for(int b=(o==2?a:a+1);b<(o==2?a+1:n);b++){\n    uint16_t t = o==0 ? (w[a]&w[b]) : o==1 ? (w[a]|w[b]) : (uint16_t)~w[a];\n    if(t==0xFFFF || avail(t)) continue;\n    int k = (o*32+a)*32+b;\n    int dep = (g>0) && (a==last || (o!=2 && b==last));\n    if(g>0 && !dep && k<=key[last]) continue;\n    w[n]=t; key[n]=k; op[n]=o; ia[n]=a; ib[n]=b; n++;\n    if(t==T){ found++; report(); n--; if(found>=1 && getenv(\"FIRST\")) exit(0); continue; }\n    dfs(); n--;\n  }\n}\nint main(int argc,char**argv){\n  T = (uint16_t)atoi(argv[1]); maxg = atoi(argv[2]);\n  for(int u=0;u<4;u++) w[u]=(uint16_t)(0xF<<(4*u));\n  for(int v=0;v<4;v++) w[4+v]=(uint16_t)(0x1111<<v);\n  n=8;\n  if(avail(T)||T==0xFFFF){ printf(\"trivial (0 or 1 gate)\\n\"); return 0; }\n  dfs();\n  printf(\"target=%u maxg=%d nodes=%lld found=%d\\n\", T, maxg, nodes, found);\n  return 0;\n}\n\n/* ---- gen.py: generates the Lean data (G0, MK0, I0, E0) and simulates the pruned LS search ---- */\n/*\nimport sys, itertools, functools\nsys.setrecursionlimit(10000)\nT=int(sys.argv[1]); K=int(sys.argv[2]); mode=sys.argv[3]  # sim | lean\nA=lambda u,v:(T>>(4*u+v))&1\ntrues=[(u,v) for u in range(4) for v in range(4) if A(u,v)]\nfalses=[(u,v) for u in range(4) for v in range(4) if not A(u,v)]\nprs=[(p,q) for p in trues for q in falses]\nJ=len(prs)\nex=[p for p,q in prs]+[q for p,q in prs]\nrows=[(u,v) for u in range(4) for v in range(4)]+ex\nNt=len(rows); Nb=16\ndef enc(bits): return sum(b<<i for i,b in enumerate(bits))\ngoal=enc([A(u,v) for u,v in rows]); mask=(1<<Nt)-1\ndef beh(i): return enc([ (u==i) if i<4 else (v==i-4) for u,v in rows])\ninit=[beh(i) for i in range(8)]+[0,mask]\nmaskJ=(1<<J)-1\ndef sepF(ws):\n  acc=0\n  for w in ws: acc|=(w>>Nb)^(w>>(Nb+J))\n  return acc&maskJ==maskJ\ndef monF(ws):\n  acc=0\n  for w in ws: acc|=(w>>Nb)&(maskJ^(w>>(Nb+J)))\n  return acc&maskJ==maskJ\ndef pairs(ws):\n  for i in range(len(ws)):\n    for j in range(i+1,len(ws)):\n      yield ws[i],ws[j],[x for k,x in enumerate(ws) if k!=i and k!=j]\ndef singles(ws):\n  for i in range(len(ws)): yield ws[i],[x for k,x in enumerate(ws) if k!=i]\ncnt=[0]\ndef LS(k,ws):\n  cnt[0]+=1\n  if ws==[goal]: return True\n  if k==0: return False\n  if not(len(ws)<=k+2 and sepF(ws) and (len(ws)!=k+2 or monF(ws))): return False\n  for a,b,r in pairs(ws):\n    for z in (a&b,a|b):\n      if z not in ws:\n        for kept in ([*r],[a,*r],[b,*r],[a,b,*r]):\n          if LS(k-1,[z]+kept): return True\n  for a,r in singles(ws):\n    z=mask^a\n    if z not in ws:\n      for kept in (r,[a]+r):\n        if LS(k-1,[z]+kept): return True\n  return False\nif mode=='sim':\n  bad=0\n  for n in range(len(init)+1):\n    for l in itertools.combinations(init,n):\n      if LS(K,list(l)): bad+=1\n  print('J',J,'Nt',Nt,'live subsets',bad,'LS calls',cnt[0])\nelse:\n  print(goal); print(mask); print(init); print(ex); print(J, Nt)\n*/\n",
 "mode": "refute",
 "complete": true,
 "lean": "import PEqualNP.Defs\n\nnamespace PEqualNP.Outside.L_meta_25842\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 : ℕ) : ℕ := enc (List.replicate N true)\n\ntheorem maskN_testBit (N r : ℕ) : (maskN N).testBit r = decide (r < N) := by\n  rw [maskN, testBit_enc]\n  simp only [List.getD_eq_getElem?_getD, List.getElem?_replicate]\n  by_cases h : r < N <;> simp [h]\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 : ℕ := 36028797018930143\ndef MK0 : ℕ := 19807040628566084398385987583\ndef I0 : List ℕ := [268369935, 2829577232647150937365807344, 5659154465294371831695806208, 11318308930624561629056004096, 493545161429265, 2829577232651099146454311458, 5659154465325826812843934788, 11318308930588664893926312072, 0, 19807040628566084398385987583]\ndef E0 : List (Fin 4 × Fin 4) := [(0, 0), (0, 0), (0, 0), (0, 1), (0, 1), (0, 1), (0, 2), (0, 2), (0, 2), (0, 3), (0, 3), (0, 3), (1, 0), (1, 0), (1, 0), (1, 2), (1, 2), (1, 2), (1, 3), (1, 3), (1, 3), (2, 0), (2, 0), (2, 0), (2, 1), (2, 1), (2, 1), (2, 3), (2, 3), (2, 3), (3, 0), (3, 0), (3, 0), (3, 1), (3, 1), (3, 1), (3, 2), (3, 2), (3, 2), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3), (1, 1), (2, 2), (3, 3)]\n\ntheorem C0_0 : ((I0.sublists.drop (256 * 0)).take 256).all (fun l => !LS G0 MK0 16 39 5 l) = true := by\n  decide +kernel\n\ntheorem C0_1 : ((I0.sublists.drop (256 * 1)).take 256).all (fun l => !LS G0 MK0 16 39 5 l) = true := by\n  decide +kernel\n\ntheorem C0_2 : ((I0.sublists.drop (256 * 2)).take 256).all (fun l => !LS G0 MK0 16 39 5 l) = true := by\n  decide +kernel\n\ntheorem C0_3 : ((I0.sublists.drop (256 * 3)).take 256).all (fun l => !LS G0 MK0 16 39 5 l) = true := by\n  decide +kernel\n\ntheorem S0 : I0.sublists.all (fun l => !LS G0 MK0 16 39 5 l) = true :=\n  all_of_chunks _ _ 256 4 (by decide +kernel) (fun i hi => match i, hi with\n    | 0, _ => C0_0\n    | 1, _ => C0_1\n    | 2, _ => C0_2\n    | 3, _ => C0_3\n    | _ + 4, hi => absurd hi (by omega))\n\nend PEqualNP.Outside.L_meta_25842\n\ntheorem PEqualNP.Outside.L_meta_25842 : ¬ (∃ C : PEqualNP.CircuitLowerBounds.Circuit, PEqualNP.MetaComplexity.FanInTwo C ∧ C.size ≤ 5 ∧ PEqualNP.Represents.Represents (fun u v : Fin 4 => (31711 : ℕ).testBit (4 * u.val + v.val)) C) :=\n  PEqualNP.Outside.L_meta_25842.refute (fun u v : Fin 4 => (31711 : ℕ).testBit (4 * u.val + v.val)) 5 16 39 94 PEqualNP.Outside.L_meta_25842.G0 PEqualNP.Outside.L_meta_25842.MK0 PEqualNP.Outside.L_meta_25842.I0 PEqualNP.Outside.L_meta_25842.E0\n      (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel)\n      (by decide +kernel) (by decide +kernel) PEqualNP.Outside.L_meta_25842.S0\n",
 "lean_bytes": 37608,
 "lean_sha256": "0e409a01702a7e0a9894b5997646d36414edbc619255d8146c33bf8e8bcf6132",
 "build": {
  "exit": 0,
  "seconds": 10.39,
  "peak_memory_gb": 3.09
 },
 "checker": {
  "exit": 0,
  "last_line": "ACCEPTED (refute): PEqualNP.Outside.L_meta_25842; axioms [propext, Quot.sound, Classical.choice]; kernel re-checked 1915 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. ...",
  "wall_seconds": 11.85,
  "peak_memory_gb": 13.45
 },
 "axioms": [
  "propext",
  "Quot.sound",
  "Classical.choice"
 ],
 "missing": [],
 "approach": "Fetched the row (gap still listed, pr_open 0) and took the statement from gaps[0]. Exhaustive C search over 16-bit wire tables: no circuit of at most 5 gates, a 6-gate one found. Lean file: the reusable refutation framework of the merged file lean/PEqualNP/Outside/L_meta_25814.lean in open-goat/pequalnp-proofs (commit e8dc2d83), renamed to this module, with new data for 31711 (J=39 pairs, Nt=94 rows) made by gen.py; the pruned backward search (separation and monotonicity pruning) does 15,508 LS calls in simulation at K=5 and finds a live set at K=6, as a sanity check. Search proof split into 4 chunks of 256 sublists. lake build exit 0 in 10.4 s; node tools/check-lean.mjs <file> <statement> refute printed ACCEPTED (refute). No lease taken, no pull request opened.",
 "skipped": false
}