{"repo":"pvsnp","commit":{"oid":"b2e6a61649b541c914352afc8e21f4edd8d866c4","tree":"0364ccb37b11f96015924d68de348a12deecf1a3","parents":["6d229cb522a543cb046a2a6bb5748cd8466cfbb8"],"author":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795944623000},"committer":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795944623000},"subject":"Add polynomial bounds with sum, product and composition","message":"Add polynomial bounds with sum, product and composition\n\nPolyBounded f means f n ≤ c * (n + 1) ^ d. The bound polyBound c d is\nmonotone in n, which composing time bounds relies on. Closure under\naddition, multiplication and composition is proved.\n\nCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>\n"},"diff":{"base":"6d229cb522a543cb046a2a6bb5748cd8466cfbb8","head":"b2e6a61649b541c914352afc8e21f4edd8d866c4","stat":{"files":2,"additions":91,"deletions":0},"files":[{"path":"PvsNP.lean","status":"modified","additions":1,"deletions":0,"binary":false,"patch":"--- a/PvsNP.lean\n+++ b/PvsNP.lean\n@@ -1,4 +1,5 @@\n import PvsNP.Basic.Finite\n+import PvsNP.Basic.Poly\n \n /-! # P versus NP in Lean 4\n \n","truncated":false},{"path":"PvsNP/Basic/Poly.lean","status":"added","additions":90,"deletions":0,"binary":false,"patch":"--- /dev/null\n+++ b/PvsNP/Basic/Poly.lean\n@@ -0,0 +1,90 @@\n+/-!\n+# Polynomial bounds\n+\n+A function `f : Nat → Nat` is *polynomially bounded* when `f n ≤ c * (n + 1) ^ d` for some constants.\n+Every polynomial with natural coefficients is dominated by a bound of this shape, and the shape is\n+monotone in `n`, which is what composing time bounds needs.\n+\n+The closure lemmas here (sums, products, composition) are all that the complexity theory uses.\n+-/\n+\n+namespace PvsNP\n+\n+/-- The canonical monotone polynomial bound `n ↦ c * (n + 1) ^ d`. -/\n+def polyBound (c d : Nat) (n : Nat) : Nat := c * (n + 1) ^ d\n+\n+/-- `f` is bounded by a polynomial. -/\n+def PolyBounded (f : Nat → Nat) : Prop :=\n+  ∃ c d, ∀ n, f n ≤ polyBound c d n\n+\n+namespace polyBound\n+\n+theorem mono (c d : Nat) {m n : Nat} (h : m ≤ n) : polyBound c d m ≤ polyBound c d n :=\n+  Nat.mul_le_mul_left c (Nat.pow_le_pow_left (Nat.succ_le_succ h) d)\n+\n+theorem one_le_pow (n d : Nat) : 1 ≤ (n + 1) ^ d :=\n+  Nat.pow_pos (Nat.succ_pos n)\n+\n+theorem pow_mono (n : Nat) {d e : Nat} (h : d ≤ e) : (n + 1) ^ d ≤ (n + 1) ^ e :=\n+  Nat.pow_le_pow_right (Nat.succ_pos n) h\n+\n+end polyBound\n+\n+namespace PolyBounded\n+\n+theorem of_le {f g : Nat → Nat} (hg : PolyBounded g) (h : ∀ n, f n ≤ g n) : PolyBounded f := by\n+  obtain ⟨c, d, hcd⟩ := hg\n+  exact ⟨c, d, fun n => Nat.le_trans (h n) (hcd n)⟩\n+\n+theorem polyBound (c d : Nat) : PolyBounded (polyBound c d) :=\n+  ⟨c, d, fun _ => Nat.le_refl _⟩\n+\n+theorem const (c : Nat) : PolyBounded (fun _ => c) :=\n+  ⟨c, 0, fun n => by simp [PvsNP.polyBound]⟩\n+\n+theorem id : PolyBounded (fun n => n) :=\n+  ⟨1, 1, fun n => by simp [PvsNP.polyBound]⟩\n+\n+theorem add {f g : Nat → Nat} (hf : PolyBounded f) (hg : PolyBounded g) :\n+    PolyBounded (fun n => f n + g n) := by\n+  obtain ⟨c₁, d₁, h₁⟩ := hf\n+  obtain ⟨c₂, d₂, h₂⟩ := hg\n+  refine ⟨c₁ + c₂, d₁ + d₂, fun n => ?_⟩\n+  have e₁ := polyBound.pow_mono n (Nat.le_add_right d₁ d₂)\n+  have e₂ := polyBound.pow_mono n (Nat.le_add_left d₂ d₁)\n+  calc f n + g n ≤ c₁ * (n + 1) ^ d₁ + c₂ * (n + 1) ^ d₂ := Nat.add_le_add (h₁ n) (h₂ n)\n+    _ ≤ c₁ * (n + 1) ^ (d₁ + d₂) + c₂ * (n + 1) ^ (d₁ + d₂) :=\n+        Nat.add_le_add (Nat.mul_le_mul_left c₁ e₁) (Nat.mul_le_mul_left c₂ e₂)\n+    _ = PvsNP.polyBound (c₁ + c₂) (d₁ + d₂) n := by simp [PvsNP.polyBound, Nat.add_mul]\n+\n+theorem mul {f g : Nat → Nat} (hf : PolyBounded f) (hg : PolyBounded g) :\n+    PolyBounded (fun n => f n * g n) := by\n+  obtain ⟨c₁, d₁, h₁⟩ := hf\n+  obtain ⟨c₂, d₂, h₂⟩ := hg\n+  refine ⟨c₁ * c₂, d₁ + d₂, fun n => ?_⟩\n+  calc f n * g n ≤ (c₁ * (n + 1) ^ d₁) * (c₂ * (n + 1) ^ d₂) := Nat.mul_le_mul (h₁ n) (h₂ n)\n+    _ = PvsNP.polyBound (c₁ * c₂) (d₁ + d₂) n := by\n+        simp only [PvsNP.polyBound, Nat.pow_add]\n+        rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_left_comm ((n + 1) ^ d₁)]\n+\n+/-- Polynomially bounded functions compose. No monotonicity of `f` is needed: its bound is. -/\n+theorem comp {f g : Nat → Nat} (hf : PolyBounded f) (hg : PolyBounded g) :\n+    PolyBounded (fun n => f (g n)) := by\n+  obtain ⟨c₁, d₁, h₁⟩ := hf\n+  obtain ⟨c₂, d₂, h₂⟩ := hg\n+  refine ⟨c₁ * (c₂ + 1) ^ d₁, d₂ * d₁, fun n => ?_⟩\n+  have hgn : g n + 1 ≤ (c₂ + 1) * (n + 1) ^ d₂ := by\n+    have := h₂ n\n+    have := polyBound.one_le_pow n d₂\n+    simp only [PvsNP.polyBound] at *\n+    rw [Nat.add_mul, Nat.one_mul]\n+    omega\n+  calc f (g n) ≤ c₁ * (g n + 1) ^ d₁ := h₁ (g n)\n+    _ ≤ c₁ * ((c₂ + 1) * (n + 1) ^ d₂) ^ d₁ :=\n+        Nat.mul_le_mul_left c₁ (Nat.pow_le_pow_left hgn d₁)\n+    _ = PvsNP.polyBound (c₁ * (c₂ + 1) ^ d₁) (d₂ * d₁) n := by\n+        simp only [PvsNP.polyBound, Nat.mul_pow, Nat.pow_mul, Nat.mul_assoc]\n+\n+end PolyBounded\n+\n+end PvsNP\n","truncated":false}],"truncated":false},"jit":null,"api":"/v1/repos/pvsnp/commit?rev=b2e6a61649b541c914352afc8e21f4edd8d866c4","api_url":"https://git.neoopensource.com/v1/repos/pvsnp/commit?rev=b2e6a61649b541c914352afc8e21f4edd8d866c4"}