# PvsNP/Complexity/NP.lean @ 346abe536d053a5c1b61722fd9b9ea5144e9a85c

````
import PvsNP.Complexity.Reduction

/-!
# The class NP

`InNP L`: some machine verifies `L` in polynomial time. The input `x` is on tape `0` and a certificate
`w` on tape `1`; the verifier halts within `T |x|` steps whatever the certificate, and `x ∈ L` exactly
when some certificate makes it accept. Because the time bound depends on `|x|` alone, only the first
`T |x|` symbols of a certificate can matter, so certificates are polynomially short in effect
(Sipser, *Introduction to the Theory of Computation*, Definition 7.18).

Proved here:
- `InP.inNP`: **P ⊆ NP**. A decider, run with tape `1` left alone, is a verifier that ignores its
  certificate.
-/

namespace PvsNP

variable {α : Type}

/-- `L ∈ NP`: a machine verifies `L` in polynomial time. -/
def InNP (L : Language α) : Prop :=
  ∃ (k : Nat) (M : Machine α k) (T : Nat → Nat), PolyBounded T ∧ VerifiesIn M L T

namespace InNP

/-- The time bound of a verifier can be taken of the form `c * (n + 1) ^ d`, hence monotone. -/
theorem polyBound {L : Language α} (h : InNP L) :
    ∃ (k : Nat) (M : Machine α k) (c d : Nat), VerifiesIn M L (PvsNP.polyBound c d) := by
  obtain ⟨k, M, T, ⟨c, d, hT⟩, hM⟩ := h
  exact ⟨k, M, c, d, hM.mono hT⟩

end InNP

/-- **P ⊆ NP.** -/
theorem InP.inNP {L : Language α} (h : InP L) : InNP L := by
  obtain ⟨k, M, T, hT, hM⟩ := h
  let E := Embedding.skipOne (Nat.le_refl (k + 1))
  have e : ∀ x w, (M.lift E).init (verifierTapes x w) =
      M.liftCfg E (verifierTapes x w) (M.init (inputTapes x)) := by
    intro x w
    simp only [Machine.init, Machine.liftCfg, E, liftTapes_skipOne_inputTapes]; rfl
  refine ⟨k + 1, M.lift E, T, hT, fun x w => ?_, fun x => ?_⟩
  · rw [e, Machine.run_lift]; exact (hM x).1
  · simp only [e, Machine.run_lift]
    exact ⟨fun hx => ⟨[], (hM x).2.mpr hx⟩, fun ⟨_, hw⟩ => (hM x).2.mp hw⟩

end PvsNP

````

API: `https://git.neoopensource.com/v1/repos/pvsnp/blob?rev=346abe536d053a5c1b61722fd9b9ea5144e9a85c&path=PvsNP%2FComplexity%2FNP.lean`
