{"repo":"pvsnp","commit":{"oid":"c8e434ba058c72a281a2c0f4d9ac19451c2bdc33","tree":"f548f74fabaa47be0ebfd8f37d92ef7e0be1b569","parents":["bcc4f3dece3d264853eced6c9d44e5e47d2f6d63"],"author":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795944852000},"committer":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795944852000},"subject":"Define P and prove it closed under complement","message":"Define P and prove it closed under complement\n\nInP L: some machine decides L within a polynomial time bound. The full\nand empty languages are in P (a machine that halts at once), and P is\nclosed under complement by swapping accepting and rejecting states.\n\nCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>\n"},"diff":{"base":"bcc4f3dece3d264853eced6c9d44e5e47d2f6d63","head":"c8e434ba058c72a281a2c0f4d9ac19451c2bdc33","stat":{"files":2,"additions":65,"deletions":0},"files":[{"path":"PvsNP.lean","status":"modified","additions":1,"deletions":0,"binary":false,"patch":"--- a/PvsNP.lean\n+++ b/PvsNP.lean\n@@ -6,6 +6,7 @@\n import PvsNP.Machine.Lift\n import PvsNP.Machine.Compose\n import PvsNP.Complexity.Time\n+import PvsNP.Complexity.P\n \n /-! # P versus NP in Lean 4\n \n","truncated":false},{"path":"PvsNP/Complexity/P.lean","status":"added","additions":64,"deletions":0,"binary":false,"patch":"--- /dev/null\n+++ b/PvsNP/Complexity/P.lean\n@@ -0,0 +1,64 @@\n+import PvsNP.Basic.Poly\n+import PvsNP.Complexity.Time\n+\n+/-!\n+# The class P\n+\n+`InP L`: some multi-tape machine decides `L` within a polynomial number of steps.\n+\n+Proved here: the full and the empty language are in P, and P is closed under complement.\n+-/\n+\n+namespace PvsNP\n+\n+variable {α : Type}\n+\n+/-- `L ∈ P`: a machine decides `L` in polynomial time. -/\n+def InP (L : Language α) : Prop :=\n+  ∃ (k : Nat) (M : Machine α k) (T : Nat → Nat), PolyBounded T ∧ DecidesIn M L T\n+\n+/-- A machine that halts at once, accepting or not as `b` says, touching nothing. -/\n+def Machine.const (α : Type) (k : Nat) (b : Bool) : Machine α k where\n+  Q := Unit\n+  finite := inferInstance\n+  start := ()\n+  halted _ := true\n+  accepting _ := b\n+  δ q r := (q, r, fun _ => .stay)\n+\n+namespace InP\n+\n+/-- The time bound of a language in P can be taken of the form `c * (n + 1) ^ d`, hence monotone. -/\n+theorem polyBound {L : Language α} (h : InP L) :\n+    ∃ (k : Nat) (M : Machine α k) (c d : Nat), DecidesIn M L (PvsNP.polyBound c d) := by\n+  obtain ⟨k, M, T, ⟨c, d, hT⟩, hM⟩ := h\n+  exact ⟨k, M, c, d, hM.mono hT⟩\n+\n+theorem univ : InP (Language.univ : Language α) :=\n+  ⟨0, Machine.const α 0 true, fun _ => 0, PolyBounded.const 0, fun _ =>\n+    ⟨rfl, by simp [Machine.const, Language.univ, Machine.init]⟩⟩\n+\n+theorem empty : InP (Language.empty : Language α) :=\n+  ⟨0, Machine.const α 0 false, fun _ => 0, PolyBounded.const 0, fun _ =>\n+    ⟨rfl, by simp [Machine.const, Language.empty, Machine.init]⟩⟩\n+\n+/-- **P is closed under complement**: swap accepting and rejecting halted states. -/\n+theorem compl {L : Language α} (h : InP L) : InP L.compl := by\n+  obtain ⟨k, M, T, hT, hM⟩ := h\n+  refine ⟨k, M.withAccepting (fun q => !M.accepting q), T, hT, fun x => ?_⟩\n+  have e : (M.withAccepting (fun q => !M.accepting q)).init (inputTapes x) = M.init (inputTapes x) :=\n+    rfl\n+  rw [e, Machine.run_withAccepting]\n+  refine ⟨(hM x).1, ?_⟩\n+  simp only [Machine.withAccepting, Bool.not_eq_eq_eq_not, Bool.not_true, Language.compl_apply,\n+    ← (hM x).2, Bool.not_eq_true]\n+\n+theorem of_compl {L : Language α} (h : InP L.compl) : InP L := by\n+  obtain ⟨k, M, T, hT, hM⟩ := h.compl\n+  exact ⟨k, M, T, hT, fun x => ⟨(hM x).1, by rw [(hM x).2, Language.compl_compl]⟩⟩\n+\n+theorem compl_iff {L : Language α} : InP L.compl ↔ InP L := ⟨of_compl, compl⟩\n+\n+end InP\n+\n+end PvsNP\n","truncated":false}],"truncated":false},"jit":null,"api":"/v1/repos/pvsnp/commit?rev=c8e434ba058c72a281a2c0f4d9ac19451c2bdc33","api_url":"https://git.neoopensource.com/v1/repos/pvsnp/commit?rev=c8e434ba058c72a281a2c0f4d9ac19451c2bdc33"}