Define deciding, computing and verifying within a time bound
DecidesIn, ComputesIn and VerifiesIn, each with its time measured in the input length. ComputesIn asks for a clean output (f x on tape 0, all else blank, heads at 0) so a second machine can start where the first stopped. A verifier's time bound ignores the certificate, as in Sipser. All three are monotone in the time bound and survive adding tapes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diff
2 files changed +95 -0
| @@ -0,0 +1,94 @@ | ||
| 1 | +import PvsNP.Language | |
| 2 | +import PvsNP.Machine.Lift | |
| 3 | +import PvsNP.Machine.Compose | |
| 4 | + | |
| 5 | +/-! | |
| 6 | +# Time-bounded computation | |
| 7 | + | |
| 8 | +Three things a machine can do within a time bound `T : Nat → Nat`, always measured in the length of the | |
| 9 | +input `x`: | |
| 10 | + | |
| 11 | +- `DecidesIn M L T`: on input `x`, `M` has halted after `T |x|` steps, accepting exactly when `x ∈ L`. | |
| 12 | +- `ComputesIn M f T`: on input `x`, `M` has halted after `T |x|` steps, leaving `f x` on tape `0` with | |
| 13 | + every other tape blank and every head back at `0`. This *clean* output convention is what lets a | |
| 14 | + second machine start right where the first one stopped. | |
| 15 | +- `VerifiesIn M L T`: on input `x` with any certificate `w` on tape `1`, `M` has halted after `T |x|` | |
| 16 | + steps; and `x ∈ L` exactly when some certificate makes it accept. The time bound depends on `|x|` | |
| 17 | + only, so a verifier can read at most `T |x|` symbols of any certificate (Sipser's definition). | |
| 18 | + | |
| 19 | +Halting is absorbing, so each of these is monotone in `T`. | |
| 20 | +-/ | |
| 21 | + | |
| 22 | +namespace PvsNP | |
| 23 | + | |
| 24 | +variable {α : Type} {k : Nat} | |
| 25 | + | |
| 26 | +/-- `M` decides `L` within `T |x|` steps. -/ | |
| 27 | +def DecidesIn (M : Machine α k) (L : Language α) (T : Nat → Nat) : Prop := | |
| 28 | + ∀ x, M.halted (M.run (M.init (inputTapes x)) (T x.length)).state = true ∧ | |
| 29 | + (M.accepting (M.run (M.init (inputTapes x)) (T x.length)).state = true ↔ L x) | |
| 30 | + | |
| 31 | +/-- `M` computes `f` within `T |x|` steps, leaving its output in the start position. -/ | |
| 32 | +def ComputesIn (M : Machine α k) (f : List α → List α) (T : Nat → Nat) : Prop := | |
| 33 | + ∀ x, M.halted (M.run (M.init (inputTapes x)) (T x.length)).state = true ∧ | |
| 34 | + (M.run (M.init (inputTapes x)) (T x.length)).tapes = inputTapes (f x) | |
| 35 | + | |
| 36 | +/-- `M` verifies `L` within `T |x|` steps, the certificate on tape `1`. -/ | |
| 37 | +def VerifiesIn (M : Machine α k) (L : Language α) (T : Nat → Nat) : Prop := | |
| 38 | + (∀ x w, M.halted (M.run (M.init (verifierTapes x w)) (T x.length)).state = true) ∧ | |
| 39 | + ∀ x, L x ↔ ∃ w, M.accepting (M.run (M.init (verifierTapes x w)) (T x.length)).state = true | |
| 40 | + | |
| 41 | +/-! ## More time never hurts -/ | |
| 42 | + | |
| 43 | +theorem DecidesIn.mono {M : Machine α k} {L : Language α} {T T' : Nat → Nat} (h : DecidesIn M L T) | |
| 44 | + (hT : ∀ n, T n ≤ T' n) : DecidesIn M L T' := by | |
| 45 | + intro x | |
| 46 | + rw [M.run_stable (h x).1 (hT x.length)] | |
| 47 | + exact h x | |
| 48 | + | |
| 49 | +theorem ComputesIn.mono {M : Machine α k} {f : List α → List α} {T T' : Nat → Nat} | |
| 50 | + (h : ComputesIn M f T) (hT : ∀ n, T n ≤ T' n) : ComputesIn M f T' := by | |
| 51 | + intro x | |
| 52 | + rw [M.run_stable (h x).1 (hT x.length)] | |
| 53 | + exact h x | |
| 54 | + | |
| 55 | +theorem VerifiesIn.mono {M : Machine α k} {L : Language α} {T T' : Nat → Nat} (h : VerifiesIn M L T) | |
| 56 | + (hT : ∀ n, T n ≤ T' n) : VerifiesIn M L T' := by | |
| 57 | + refine ⟨fun x w => ?_, fun x => ?_⟩ | |
| 58 | + · rw [M.run_stable (h.1 x w) (hT x.length)]; exact h.1 x w | |
| 59 | + · rw [h.2 x] | |
| 60 | + exact exists_congr fun w => by rw [M.run_stable (h.1 x w) (hT x.length)] | |
| 61 | + | |
| 62 | +/-! ## More tapes never hurt -/ | |
| 63 | + | |
| 64 | +theorem DecidesIn.lift {M : Machine α k} {L : Language α} {T : Nat → Nat} {k' : Nat} (hk : k ≤ k') | |
| 65 | + (h : DecidesIn M L T) : DecidesIn (M.lift (Embedding.castLE hk)) L T := by | |
| 66 | + intro x | |
| 67 | + have e : (M.lift (Embedding.castLE hk)).init (inputTapes x) = | |
| 68 | + M.liftCfg (Embedding.castLE hk) (inputTapes x) (M.init (inputTapes x)) := by | |
| 69 | + simp only [Machine.init, Machine.liftCfg, liftTapes_castLE_inputTapes]; rfl | |
| 70 | + rw [e, Machine.run_lift] | |
| 71 | + exact h x | |
| 72 | + | |
| 73 | +theorem ComputesIn.lift {M : Machine α k} {f : List α → List α} {T : Nat → Nat} {k' : Nat} | |
| 74 | + (hk : k ≤ k') (h : ComputesIn M f T) : ComputesIn (M.lift (Embedding.castLE hk)) f T := by | |
| 75 | + intro x | |
| 76 | + have e : (M.lift (Embedding.castLE hk)).init (inputTapes x) = | |
| 77 | + M.liftCfg (Embedding.castLE hk) (inputTapes x) (M.init (inputTapes x)) := by | |
| 78 | + simp only [Machine.init, Machine.liftCfg, liftTapes_castLE_inputTapes]; rfl | |
| 79 | + rw [e, Machine.run_lift] | |
| 80 | + refine ⟨(h x).1, ?_⟩ | |
| 81 | + simp only [Machine.liftCfg, (h x).2, liftTapes_castLE_inputTapes] | |
| 82 | + | |
| 83 | +theorem VerifiesIn.lift {M : Machine α k} {L : Language α} {T : Nat → Nat} {k' : Nat} (hk : k ≤ k') | |
| 84 | + (h : VerifiesIn M L T) : VerifiesIn (M.lift (Embedding.castLE hk)) L T := by | |
| 85 | + have e : ∀ x w, (M.lift (Embedding.castLE hk)).init (verifierTapes x w) = | |
| 86 | + M.liftCfg (Embedding.castLE hk) (verifierTapes x w) (M.init (verifierTapes x w)) := by | |
| 87 | + intro x w | |
| 88 | + simp only [Machine.init, Machine.liftCfg, liftTapes_castLE_verifierTapes]; rfl | |
| 89 | + refine ⟨fun x w => ?_, fun x => ?_⟩ | |
| 90 | + · rw [e, Machine.run_lift]; exact h.1 x w | |
| 91 | + · rw [h.2 x] | |
| 92 | + exact exists_congr fun w => by rw [e, Machine.run_lift]; rfl | |
| 93 | + | |
| 94 | +end PvsNP | |