{"repo":"pvsnp","commit":{"oid":"5bdcd988ce31c5e20bc679e5aca17f88eaa6ccc7","tree":"d6bd765fbd5c18e2affe3b57483625399cb3f760","parents":["396d8a0df99015623a282b9dc207b52b6834db14"],"author":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795945433000},"committer":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795945433000},"subject":"Require a finite alphabet in P, NP and polynomial-time functions","message":"Require a finite alphabet in P, NP and polynomial-time functions\n\nReview finding: Machine requires finite states but nothing required a\nfinite alphabet. Over α := Nat a machine reading one symbol can test\nmembership in the halting set, so firstSymbol_inP put an undecidable\nlanguage in P.\n\nInP, InNP and PolyTimeComputable now start with IsFinite α, so every\nclass is empty over an infinite alphabet. The P ≠ NP statement (over\nBool) is unchanged. Theorems that build a machine from nothing (univ,\nempty, the identity, refl, firstSymbol_inP) take [IsFinite α].\n\nCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>\n"},"diff":{"base":"396d8a0df99015623a282b9dc207b52b6834db14","head":"5bdcd988ce31c5e20bc679e5aca17f88eaa6ccc7","stat":{"files":4,"additions":36,"deletions":29},"files":[{"path":"PvsNP/Complexity/NP.lean","status":"modified","additions":6,"deletions":6,"binary":false,"patch":"--- a/PvsNP/Complexity/NP.lean\n+++ b/PvsNP/Complexity/NP.lean\n@@ -3,7 +3,7 @@\n /-!\n # The class NP\n \n-`InNP L`: some machine verifies `L` in polynomial time. The input `x` is on tape `0` and a certificate\n+`InNP L`: the alphabet is finite and some machine verifies `L` in polynomial time. The input `x` is on tape `0` and a certificate\n `w` on tape `1`; the verifier halts within `T |x|` steps whatever the certificate, and `x ∈ L` exactly\n when some certificate makes it accept. Because the time bound depends on `|x|` alone, only the first\n `T |x|` symbols of a certificate can matter, so certificates are polynomially short in effect\n@@ -22,27 +22,27 @@\n \n /-- `L ∈ NP`: a machine verifies `L` in polynomial time. -/\n def InNP (L : Language α) : Prop :=\n-  ∃ (k : Nat) (M : Machine α k) (T : Nat → Nat), PolyBounded T ∧ VerifiesIn M L T\n+  IsFinite α ∧ ∃ (k : Nat) (M : Machine α k) (T : Nat → Nat), PolyBounded T ∧ VerifiesIn M L T\n \n namespace InNP\n \n /-- The time bound of a verifier can be taken of the form `c * (n + 1) ^ d`, hence monotone. -/\n theorem polyBound {L : Language α} (h : InNP L) :\n     ∃ (k : Nat) (M : Machine α k) (c d : Nat), VerifiesIn M L (PvsNP.polyBound c d) := by\n-  obtain ⟨k, M, T, ⟨c, d, hT⟩, hM⟩ := h\n+  obtain ⟨_, k, M, T, ⟨c, d, hT⟩, hM⟩ := h\n   exact ⟨k, M, c, d, hM.mono hT⟩\n \n end InNP\n \n /-- **P ⊆ NP.** -/\n theorem InP.inNP {L : Language α} (h : InP L) : InNP L := by\n-  obtain ⟨k, M, T, hT, hM⟩ := h\n+  obtain ⟨hα, k, M, T, hT, hM⟩ := h\n   let E := Embedding.skipOne (Nat.le_refl (k + 1))\n   have e : ∀ x w, (M.lift E).init (verifierTapes x w) =\n       M.liftCfg E (verifierTapes x w) (M.init (inputTapes x)) := by\n     intro x w\n     simp only [Machine.init, Machine.liftCfg, E, liftTapes_skipOne_inputTapes]; rfl\n-  refine ⟨k + 1, M.lift E, T, hT, fun x w => ?_, fun x => ?_⟩\n+  refine ⟨hα, k + 1, M.lift E, T, hT, fun x w => ?_, fun x => ?_⟩\n   · rw [e, Machine.run_lift]; exact (hM x).1\n   · simp only [e, Machine.run_lift]\n     exact ⟨fun hx => ⟨[], (hM x).2.mpr hx⟩, fun ⟨_, hw⟩ => (hM x).2.mp hw⟩\n@@ -93,7 +93,7 @@\n         (PvsNP.polyBound c₂ d₂ (f x).length)) := fun x w =>\n     Machine.run_seq_verifier M₁ hk₁ V' hM₁ x w _ _ (hV'.1 (f x) w)\n       (Nat.add_le_add_left (polyBound.mono c₂ d₂ (hB x)) _)\n-  refine ⟨k₁ + k₂ + 1, (M₁.lift (Embedding.skipOne hk₁)).seq V', T, ?_, fun x w => ?_, fun x => ?_⟩\n+  refine ⟨hf.1, k₁ + k₂ + 1, (M₁.lift (Embedding.skipOne hk₁)).seq V', T, ?_, fun x w => ?_, fun x => ?_⟩\n   · exact ((PolyBounded.polyBound c₁ d₁).add (PolyBounded.const 1)).add\n       ((PolyBounded.polyBound c₂ d₂).comp (PolyBounded.polyBound b e))\n   · rw [key]; exact hV'.1 (f x) w\n","truncated":false},{"path":"PvsNP/Complexity/P.lean","status":"modified","additions":18,"deletions":12,"binary":false,"patch":"--- a/PvsNP/Complexity/P.lean\n+++ b/PvsNP/Complexity/P.lean\n@@ -4,7 +4,10 @@\n /-!\n # The class P\n \n-`InP L`: some multi-tape machine decides `L` within a polynomial number of steps.\n+`InP L`: the alphabet is finite and some multi-tape machine decides `L` within a polynomial number\n+of steps. Finiteness of the alphabet is part of the definition: over an infinite alphabet a single\n+symbol carries unbounded information (a machine reading one `Nat` could test membership in the\n+halting set), so P is empty there by definition rather than meaningless.\n \n Proved here: the full and the empty language are in P, and P is closed under complement.\n -/\n@@ -13,9 +16,9 @@\n \n variable {α : Type}\n \n-/-- `L ∈ P`: a machine decides `L` in polynomial time. -/\n+/-- `L ∈ P`: over a finite alphabet, 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+  IsFinite α ∧ ∃ (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@@ -31,21 +34,24 @@\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+  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+/-- Only languages over finite alphabets are in P. -/\n+theorem isFinite {L : Language α} (h : InP L) : IsFinite α := h.1\n+\n+theorem univ [IsFinite α] : InP (Language.univ : Language α) :=\n+  ⟨inferInstance, 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+theorem empty [IsFinite α] : InP (Language.empty : Language α) :=\n+  ⟨inferInstance, 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+  obtain ⟨hα, k, M, T, hT, hM⟩ := h\n+  refine ⟨hα, 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@@ -54,8 +60,8 @@\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+  obtain ⟨hα, k, M, T, hT, hM⟩ := h.compl\n+  exact ⟨hα, 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","truncated":false},{"path":"PvsNP/Complexity/Reduction.lean","status":"modified","additions":8,"deletions":8,"binary":false,"patch":"--- a/PvsNP/Complexity/Reduction.lean\n+++ b/PvsNP/Complexity/Reduction.lean\n@@ -3,7 +3,7 @@\n /-!\n # Polynomial-time reductions\n \n-`PolyTimeComputable f`: a machine computes `f` in polynomial time, and `|f x|` is polynomially bounded\n+`PolyTimeComputable f`: the alphabet is finite and a machine computes `f` in polynomial time, and `|f x|` is polynomially bounded\n in `|x|`. (The output bound follows from the time bound in any reasonable model; we state it rather\n than derive it. Deriving it is on the roadmap.)\n \n@@ -19,7 +19,7 @@\n \n /-- `f` is computable in polynomial time, with polynomially bounded output. -/\n def PolyTimeComputable (f : List α → List α) : Prop :=\n-  ∃ (k : Nat) (M : Machine α k) (T B : Nat → Nat), PolyBounded T ∧ PolyBounded B ∧\n+  IsFinite α ∧ ∃ (k : Nat) (M : Machine α k) (T B : Nat → Nat), PolyBounded T ∧ PolyBounded B ∧\n     ComputesIn M f T ∧ ∀ x, (f x).length ≤ B x.length\n \n /-- `L` many-one reduces to `L'` in polynomial time. -/\n@@ -83,12 +83,12 @@\n theorem normalize {f : List α → List α} (h : PolyTimeComputable f) :\n     ∃ (k : Nat) (M : Machine α k) (c d b e : Nat), ComputesIn M f (polyBound c d) ∧\n       ∀ x, (f x).length ≤ polyBound b e x.length := by\n-  obtain ⟨k, M, T, B, ⟨c, d, hT⟩, ⟨b, e, hB⟩, hM, hfB⟩ := h\n+  obtain ⟨_, k, M, T, B, ⟨c, d, hT⟩, ⟨b, e, hB⟩, hM, hfB⟩ := h\n   exact ⟨k, M, c, d, b, e, hM.mono hT, fun x => Nat.le_trans (hfB x) (hB _)⟩\n \n /-- The identity: the machine that halts at once. -/\n-theorem id : PolyTimeComputable (fun x : List α => x) :=\n-  ⟨0, Machine.const α 0 true, fun _ => 0, fun n => n, PolyBounded.const 0, PolyBounded.id,\n+theorem id [IsFinite α] : PolyTimeComputable (fun x : List α => x) :=\n+  ⟨inferInstance, 0, Machine.const α 0 true, fun _ => 0, fun n => n, PolyBounded.const 0, PolyBounded.id,\n     fun _ => ⟨rfl, rfl⟩, fun _ => Nat.le_refl _⟩\n \n /-- **Polynomial-time functions compose.** -/\n@@ -98,7 +98,7 @@\n   obtain ⟨k₂, M₂, c₂, d₂, b₂, e₂, hM₂, hB₂⟩ := hg.normalize\n   have hl₁ := hM₁.lift (Nat.le_add_right k₁ k₂)\n   have hl₂ := hM₂.lift (Nat.le_add_left k₂ k₁)\n-  refine ⟨k₁ + k₂, _, _, fun n => polyBound b₂ e₂ (polyBound b₁ e₁ n),\n+  refine ⟨hf.1, k₁ + k₂, _, _, fun n => polyBound b₂ e₂ (polyBound b₁ e₁ n),\n     ?_, ?_, hl₁.seq hB₁ hl₂, fun x => ?_⟩\n   · exact ((PolyBounded.polyBound c₁ d₁).add (PolyBounded.const 1)).add\n       ((PolyBounded.polyBound c₂ d₂).comp (PolyBounded.polyBound b₁ e₁))\n@@ -110,7 +110,7 @@\n namespace Reduces\n \n /-- `≤ₚ` is reflexive. -/\n-theorem refl (L : Language α) : L ≤ₚ L := ⟨_, PolyTimeComputable.id, fun _ => Iff.rfl⟩\n+theorem refl [IsFinite α] (L : Language α) : L ≤ₚ L := ⟨_, PolyTimeComputable.id, fun _ => Iff.rfl⟩\n \n /-- **Reductions compose**: `≤ₚ` is transitive. -/\n theorem trans {L₁ L₂ L₃ : Language α} (h₁₂ : L₁ ≤ₚ L₂) (h₂₃ : L₂ ≤ₚ L₃) : L₁ ≤ₚ L₃ := by\n@@ -131,7 +131,7 @@\n   obtain ⟨k₁, M₁, c₁, d₁, b, e, hM₁, hB⟩ := hf.normalize\n   obtain ⟨k₂, M₂, c₂, d₂, hM₂⟩ := hL'.polyBound\n   have hd := DecidesIn.seq (hM₁.lift (Nat.le_add_right k₁ k₂)) hB (hM₂.lift (Nat.le_add_left k₂ k₁))\n-  refine ⟨k₁ + k₂,\n+  refine ⟨hL'.1, k₁ + k₂,\n     (M₁.lift (Embedding.castLE (Nat.le_add_right k₁ k₂))).seq\n       (M₂.lift (Embedding.castLE (Nat.le_add_left k₂ k₁))),\n     fun n => PvsNP.polyBound c₁ d₁ n + 1 + PvsNP.polyBound c₂ d₂ (PvsNP.polyBound b e n), ?_, ?_⟩\n","truncated":false},{"path":"PvsNP/Examples/FirstSymbol.lean","status":"modified","additions":4,"deletions":3,"binary":false,"patch":"--- a/PvsNP/Examples/FirstSymbol.lean\n+++ b/PvsNP/Examples/FirstSymbol.lean\n@@ -7,7 +7,8 @@\n `0` once and halts, accepting when a test `p` on that symbol passes. It decides\n `{x | p x.head? = true}` in one step, so each such language is in P.\n \n-Two instances over `Bool`: the words that start with `true`, and the empty word.\n+It needs a finite alphabet, like every class here: over `Nat`, a test on one symbol could be the\n+halting problem. Two instances over `Bool`: the words that start with `true`, and the empty word.\n -/\n \n namespace PvsNP.Examples\n@@ -48,8 +49,8 @@\n     Tape.read_ofWord]\n \n /-- Every language decided by the first symbol is in P, within one step. -/\n-theorem firstSymbol_inP (p : Option α → Bool) : InP (FirstSymbol p) := by\n-  refine ⟨0, firstSymbolMachine p, fun _ => 1, PolyBounded.const 1, fun x => ?_⟩\n+theorem firstSymbol_inP [IsFinite α] (p : Option α → Bool) : InP (FirstSymbol p) := by\n+  refine ⟨inferInstance, 0, firstSymbolMachine p, fun _ => 1, PolyBounded.const 1, fun x => ?_⟩\n   rw [firstSymbolMachine_run]\n   cases h : p x.head? <;> simp [firstSymbolMachine, FirstSymbol, h]\n \n","truncated":false}],"truncated":false},"jit":null,"api":"/v1/repos/pvsnp/commit?rev=5bdcd988ce31c5e20bc679e5aca17f88eaa6ccc7","api_url":"https://git.neoopensource.com/v1/repos/pvsnp/commit?rev=5bdcd988ce31c5e20bc679e5aca17f88eaa6ccc7"}