PolyBounded f means f n ≤ c * (n + 1) ^ d. The bound polyBound c d is monotone in n, which composing time bounds relies on. Closure under addition, multiplication and composition is proved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diff
2 files changed +91 -0
| @@ -0,0 +1,90 @@ | ||
| 1 | +/-! | |
| 2 | +# Polynomial bounds | |
| 3 | + | |
| 4 | +A function `f : Nat → Nat` is *polynomially bounded* when `f n ≤ c * (n + 1) ^ d` for some constants. | |
| 5 | +Every polynomial with natural coefficients is dominated by a bound of this shape, and the shape is | |
| 6 | +monotone in `n`, which is what composing time bounds needs. | |
| 7 | + | |
| 8 | +The closure lemmas here (sums, products, composition) are all that the complexity theory uses. | |
| 9 | +-/ | |
| 10 | + | |
| 11 | +namespace PvsNP | |
| 12 | + | |
| 13 | +/-- The canonical monotone polynomial bound `n ↦ c * (n + 1) ^ d`. -/ | |
| 14 | +def polyBound (c d : Nat) (n : Nat) : Nat := c * (n + 1) ^ d | |
| 15 | + | |
| 16 | +/-- `f` is bounded by a polynomial. -/ | |
| 17 | +def PolyBounded (f : Nat → Nat) : Prop := | |
| 18 | + ∃ c d, ∀ n, f n ≤ polyBound c d n | |
| 19 | + | |
| 20 | +namespace polyBound | |
| 21 | + | |
| 22 | +theorem mono (c d : Nat) {m n : Nat} (h : m ≤ n) : polyBound c d m ≤ polyBound c d n := | |
| 23 | + Nat.mul_le_mul_left c (Nat.pow_le_pow_left (Nat.succ_le_succ h) d) | |
| 24 | + | |
| 25 | +theorem one_le_pow (n d : Nat) : 1 ≤ (n + 1) ^ d := | |
| 26 | + Nat.pow_pos (Nat.succ_pos n) | |
| 27 | + | |
| 28 | +theorem pow_mono (n : Nat) {d e : Nat} (h : d ≤ e) : (n + 1) ^ d ≤ (n + 1) ^ e := | |
| 29 | + Nat.pow_le_pow_right (Nat.succ_pos n) h | |
| 30 | + | |
| 31 | +end polyBound | |
| 32 | + | |
| 33 | +namespace PolyBounded | |
| 34 | + | |
| 35 | +theorem of_le {f g : Nat → Nat} (hg : PolyBounded g) (h : ∀ n, f n ≤ g n) : PolyBounded f := by | |
| 36 | + obtain ⟨c, d, hcd⟩ := hg | |
| 37 | + exact ⟨c, d, fun n => Nat.le_trans (h n) (hcd n)⟩ | |
| 38 | + | |
| 39 | +theorem polyBound (c d : Nat) : PolyBounded (polyBound c d) := | |
| 40 | + ⟨c, d, fun _ => Nat.le_refl _⟩ | |
| 41 | + | |
| 42 | +theorem const (c : Nat) : PolyBounded (fun _ => c) := | |
| 43 | + ⟨c, 0, fun n => by simp [PvsNP.polyBound]⟩ | |
| 44 | + | |
| 45 | +theorem id : PolyBounded (fun n => n) := | |
| 46 | + ⟨1, 1, fun n => by simp [PvsNP.polyBound]⟩ | |
| 47 | + | |
| 48 | +theorem add {f g : Nat → Nat} (hf : PolyBounded f) (hg : PolyBounded g) : | |
| 49 | + PolyBounded (fun n => f n + g n) := by | |
| 50 | + obtain ⟨c₁, d₁, h₁⟩ := hf | |
| 51 | + obtain ⟨c₂, d₂, h₂⟩ := hg | |
| 52 | + refine ⟨c₁ + c₂, d₁ + d₂, fun n => ?_⟩ | |
| 53 | + have e₁ := polyBound.pow_mono n (Nat.le_add_right d₁ d₂) | |
| 54 | + have e₂ := polyBound.pow_mono n (Nat.le_add_left d₂ d₁) | |
| 55 | + calc f n + g n ≤ c₁ * (n + 1) ^ d₁ + c₂ * (n + 1) ^ d₂ := Nat.add_le_add (h₁ n) (h₂ n) | |
| 56 | + _ ≤ c₁ * (n + 1) ^ (d₁ + d₂) + c₂ * (n + 1) ^ (d₁ + d₂) := | |
| 57 | + Nat.add_le_add (Nat.mul_le_mul_left c₁ e₁) (Nat.mul_le_mul_left c₂ e₂) | |
| 58 | + _ = PvsNP.polyBound (c₁ + c₂) (d₁ + d₂) n := by simp [PvsNP.polyBound, Nat.add_mul] | |
| 59 | + | |
| 60 | +theorem mul {f g : Nat → Nat} (hf : PolyBounded f) (hg : PolyBounded g) : | |
| 61 | + PolyBounded (fun n => f n * g n) := by | |
| 62 | + obtain ⟨c₁, d₁, h₁⟩ := hf | |
| 63 | + obtain ⟨c₂, d₂, h₂⟩ := hg | |
| 64 | + refine ⟨c₁ * c₂, d₁ + d₂, fun n => ?_⟩ | |
| 65 | + calc f n * g n ≤ (c₁ * (n + 1) ^ d₁) * (c₂ * (n + 1) ^ d₂) := Nat.mul_le_mul (h₁ n) (h₂ n) | |
| 66 | + _ = PvsNP.polyBound (c₁ * c₂) (d₁ + d₂) n := by | |
| 67 | + simp only [PvsNP.polyBound, Nat.pow_add] | |
| 68 | + rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_left_comm ((n + 1) ^ d₁)] | |
| 69 | + | |
| 70 | +/-- Polynomially bounded functions compose. No monotonicity of `f` is needed: its bound is. -/ | |
| 71 | +theorem comp {f g : Nat → Nat} (hf : PolyBounded f) (hg : PolyBounded g) : | |
| 72 | + PolyBounded (fun n => f (g n)) := by | |
| 73 | + obtain ⟨c₁, d₁, h₁⟩ := hf | |
| 74 | + obtain ⟨c₂, d₂, h₂⟩ := hg | |
| 75 | + refine ⟨c₁ * (c₂ + 1) ^ d₁, d₂ * d₁, fun n => ?_⟩ | |
| 76 | + have hgn : g n + 1 ≤ (c₂ + 1) * (n + 1) ^ d₂ := by | |
| 77 | + have := h₂ n | |
| 78 | + have := polyBound.one_le_pow n d₂ | |
| 79 | + simp only [PvsNP.polyBound] at * | |
| 80 | + rw [Nat.add_mul, Nat.one_mul] | |
| 81 | + omega | |
| 82 | + calc f (g n) ≤ c₁ * (g n + 1) ^ d₁ := h₁ (g n) | |
| 83 | + _ ≤ c₁ * ((c₂ + 1) * (n + 1) ^ d₂) ^ d₁ := | |
| 84 | + Nat.mul_le_mul_left c₁ (Nat.pow_le_pow_left hgn d₁) | |
| 85 | + _ = PvsNP.polyBound (c₁ * (c₂ + 1) ^ d₁) (d₂ * d₁) n := by | |
| 86 | + simp only [PvsNP.polyBound, Nat.mul_pow, Nat.pow_mul, Nat.mul_assoc] | |
| 87 | + | |
| 88 | +end PolyBounded | |
| 89 | + | |
| 90 | +end PvsNP | |