Prove NP closed under polynomial-time reductions

9a243160Claude · 6d agoparent 346abe53files
If L ≤ₚ L' and L' ∈ NP then L ∈ NP. The reduction runs first, lifted
with skipOne so the certificate on tape 1 survives; the verifier for L'
then runs on f x and the same certificate. run_seq_verifier is the
simulation lemma for that composite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Diff

1 files changed +55 -0
@@ -12,6 +12,8 @@
1212 Proved here:
1313 - `InP.inNP`: **P ⊆ NP**. A decider, run with tape `1` left alone, is a verifier that ignores its
1414 certificate.
15+- `InNP.of_reduces`: NP is closed downward under `≤ₚ`. The reduction runs first, leaving the
16+ certificate on tape `1` untouched; then the verifier runs on `f x` and the same certificate.
1517 -/
1618
1719 namespace PvsNP
@@ -45,4 +47,57 @@
4547 · simp only [e, Machine.run_lift]
4648 exact ⟨fun hx => ⟨[], (hM x).2.mpr hx⟩, fun ⟨_, hw⟩ => (hM x).2.mp hw⟩
4749
50+/-! ## Reductions into NP -/
51+
52+namespace Machine
53+
54+/-- Run `M₁` (computing `f`) on `x` with tape `1` left alone, then `V` on `f x` and the certificate. -/
55+theorem run_seq_verifier {k₁ K : Nat} (M₁ : Machine α k₁) (h : k₁ + 1 ≤ K) (V : Machine α K)
56+ {f : List α → List α} {T₁ : Nat → Nat} (h₁ : ComputesIn M₁ f T₁) (x w : List α) (t₂ t : Nat)
57+ (h₂ : V.halted (V.run (V.init (verifierTapes (f x) w)) t₂).state = true)
58+ (ht : T₁ x.length + 1 + t₂ ≤ t) :
59+ ((M₁.lift (Embedding.skipOne h)).seq V).run
60+ (((M₁.lift (Embedding.skipOne h)).seq V).init (verifierTapes x w)) t =
61+ inrCfg _ V (V.run (V.init (verifierTapes (f x) w)) t₂) := by
62+ let E := Embedding.skipOne h
63+ have e : ((M₁.lift E).seq V).init (verifierTapes x w) =
64+ inlCfg (M₁.lift E) V (M₁.liftCfg E (verifierTapes x w) (M₁.init (inputTapes x))) := by
65+ simp only [init, inlCfg, liftCfg, E, liftTapes_skipOne_inputTapes]; rfl
66+ have hrun := M₁.run_lift E (verifierTapes x w) (M₁.init (inputTapes x)) (T₁ x.length)
67+ have htapes : ((M₁.lift E).run (M₁.liftCfg E (verifierTapes x w) (M₁.init (inputTapes x)))
68+ (T₁ x.length)).tapes = verifierTapes (f x) w := by
69+ rw [hrun]; simp only [liftCfg, (h₁ x).2, E, liftTapes_skipOne_inputTapes]
70+ have hhalt : (M₁.lift E).halted ((M₁.lift E).run
71+ (M₁.liftCfg E (verifierTapes x w) (M₁.init (inputTapes x))) (T₁ x.length)).state = true := by
72+ rw [hrun]; exact (h₁ x).1
73+ have key := run_seq (M₁.lift E) V _ (T₁ x.length) t₂ hhalt (by rw [htapes]; exact h₂)
74+ rw [htapes] at key
75+ show ((M₁.lift E).seq V).run (((M₁.lift E).seq V).init (verifierTapes x w)) t = _
76+ rw [e, run_stable _ (by rw [key]; exact h₂) ht, key]
77+
78+end Machine
79+
80+/-- **NP is closed under reductions**: if `L ≤ₚ L'` and `L' ∈ NP`, then `L ∈ NP`. -/
81+theorem InNP.of_reduces {L L' : Language α} (h : L ≤ₚ L') (hL' : InNP L') : InNP L := by
82+ obtain ⟨f, hf, hfL⟩ := h
83+ obtain ⟨k₁, M₁, c₁, d₁, b, e, hM₁, hB⟩ := hf.normalize
84+ obtain ⟨k₂, V, c₂, d₂, hV⟩ := hL'.polyBound
85+ have hk₁ : k₁ + 1 ≤ k₁ + k₂ + 1 := by omega
86+ have hk₂ : k₂ ≤ k₁ + k₂ + 1 := by omega
87+ have hV' := hV.lift hk₂
88+ let V' := V.lift (Embedding.castLE hk₂)
89+ let T := fun n => PvsNP.polyBound c₁ d₁ n + 1 + PvsNP.polyBound c₂ d₂ (PvsNP.polyBound b e n)
90+ have key : ∀ x w, ((M₁.lift (Embedding.skipOne hk₁)).seq V').run
91+ (((M₁.lift (Embedding.skipOne hk₁)).seq V').init (verifierTapes x w)) (T x.length) =
92+ Machine.inrCfg _ V' (V'.run (V'.init (verifierTapes (f x) w))
93+ (PvsNP.polyBound c₂ d₂ (f x).length)) := fun x w =>
94+ Machine.run_seq_verifier M₁ hk₁ V' hM₁ x w _ _ (hV'.1 (f x) w)
95+ (Nat.add_le_add_left (polyBound.mono c₂ d₂ (hB x)) _)
96+ refine ⟨k₁ + k₂ + 1, (M₁.lift (Embedding.skipOne hk₁)).seq V', T, ?_, fun x w => ?_, fun x => ?_⟩
97+ · exact ((PolyBounded.polyBound c₁ d₁).add (PolyBounded.const 1)).add
98+ ((PolyBounded.polyBound c₂ d₂).comp (PolyBounded.polyBound b e))
99+ · rw [key]; exact hV'.1 (f x) w
100+ · rw [hfL x, hV'.2 (f x)]
101+ exact exists_congr fun w => by rw [key]; rfl
102+
48103 end PvsNP