import Problems.PVersusNP.Millennium import Problems.PVersusNP.Machines.CertificateBound /-! # Polynomial time and computable enumerability Cook's polynomial-time reductions and checking relations can be used as computable ones. For NP, the computable checker also enforces the original certificate bound. -/ namespace Millennium open Computability Turing /-- A polynomial-time many-one reduction is a computable many-one reduction. -/ theorem PolynomialTimeReducible.toManyOneReducible {α β : Type} {ea : FinEncoding α} {eb : FinEncoding β} {L₁ : Language α} {L₂ : Language β} (h : PolynomialTimeReducible ea eb L₁ L₂) : ManyOneReducible ea eb L₁ L₂ := by obtain ⟨f, machine, correct⟩ := h exact ⟨f, machine.toTM2ComputableInTime.toTM2Computable, correct⟩ /-- A polynomial-time checking relation is a computable checking relation. -/ theorem PolynomialTimeCheckingRelation.toComputableCheckingRelation {α β : Type} {ea : FinEncoding α} {eb : FinEncoding β} {R : α → β → Prop} (h : PolynomialTimeCheckingRelation ea eb R) : ComputableCheckingRelation ea eb R := by obtain ⟨verifier, machine, correct⟩ := h exact ⟨verifier, machine.toTM2ComputableInTime.toTM2Computable, fun a b => correct (a, b)⟩ /-- Every NP language is computably enumerable, using a computable checker that also rejects certificates longer than the original NP bound. -/ theorem InNondeterministicPolynomialTime.toComputablyEnumerable {α : Type} {ea : FinEncoding α} {L : Language α} (h : InNondeterministicPolynomialTime ea L) : ComputablyEnumerable ea L := by obtain ⟨Γ, hΓ, R, k, hR, correct⟩ := h letI : Fintype Γ := hΓ obtain ⟨verifier, machine, verifies⟩ := hR.toComputableCheckingRelation refine ⟨Γ, hΓ, fun a y => y.length ≤ (ea.encode a).length ^ k ∧ R a y, ?_, correct⟩ exact ⟨_, Machines.CertificateBound.checked machine k, fun a y => by by_cases bound : y.length ≤ (ea.encode a).length ^ k · simpa [bound, Machines.CertificateBound.check] using verifies a y · simp [bound, Machines.CertificateBound.check]⟩ end Millennium