{"repo":"pvsnp","commit":{"oid":"ca0840598349a33fc20adf79395534b6d8376a04","tree":"89e25f0aeaad100f391b11a9eddd72d0441721e6","parents":["cd5376bbfcbe7c47ca864981700de9c4af3334aa"],"author":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795944756000},"committer":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795944756000},"subject":"Run a machine on more tapes, with a simulation proof","message":"Run a machine on more tapes, with a simulation proof\n\nAn Embedding places the k + 1 tapes of a machine among k' + 1 tapes.\nMachine.lift runs the machine on those tapes and leaves the others\nuntouched; run_lift proves the lifted run is the original run, step by\nstep.\n\ncastLE keeps every tape where it is. skipOne leaves tape 1 free, so a\ncertificate there survives a decider's or a reduction's run.\n\nCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>\n"},"diff":{"base":"cd5376bbfcbe7c47ca864981700de9c4af3334aa","head":"ca0840598349a33fc20adf79395534b6d8376a04","stat":{"files":2,"additions":190,"deletions":0},"files":[{"path":"PvsNP.lean","status":"modified","additions":1,"deletions":0,"binary":false,"patch":"--- a/PvsNP.lean\n+++ b/PvsNP.lean\n@@ -3,6 +3,7 @@\n import PvsNP.Language\n import PvsNP.Machine.Tape\n import PvsNP.Machine.Defs\n+import PvsNP.Machine.Lift\n \n /-! # P versus NP in Lean 4\n \n","truncated":false},{"path":"PvsNP/Machine/Lift.lean","status":"added","additions":189,"deletions":0,"binary":false,"patch":"--- /dev/null\n+++ b/PvsNP/Machine/Lift.lean\n@@ -0,0 +1,189 @@\n+import PvsNP.Machine.Defs\n+\n+/-!\n+# Running a machine on more tapes\n+\n+A machine with `k + 1` tapes can run inside a machine with `k' + 1` tapes: an `Embedding` says which\n+of the larger machine's tapes stand for which of the smaller one's. The lifted machine does exactly\n+what the original does on those tapes and leaves every other tape untouched.\n+\n+Two embeddings are used:\n+- `Embedding.castLE`: tape `i` goes to tape `i`; the new tapes come last.\n+- `Embedding.skipOne`: tape `0` stays, tape `i + 1` goes to tape `i + 2`. Tape `1` is left alone, so a\n+  certificate written there survives the run (used for P ⊆ NP and for reductions into NP).\n+\n+The main result, `Machine.run_lift`, is a step-by-step simulation.\n+-/\n+\n+namespace PvsNP\n+\n+/-- How the tapes of a `k + 1`-tape machine sit among `k' + 1` tapes: `emb` places each small tape,\n+and `back` recognises the places (`none` for a tape the small machine does not use). -/\n+structure Embedding (k k' : Nat) where\n+  emb : Fin (k + 1) → Fin (k' + 1)\n+  back : Fin (k' + 1) → Option (Fin (k + 1))\n+  back_emb : ∀ i, back (emb i) = some i\n+\n+namespace Embedding\n+\n+/-- Tape `i` stays tape `i`. -/\n+def castLE {k k' : Nat} (h : k ≤ k') : Embedding k k' where\n+  emb i := ⟨i.val, by omega⟩\n+  back j := if hj : j.val < k + 1 then some ⟨j.val, hj⟩ else none\n+  back_emb i := by simp [i.isLt]\n+\n+/-- Tape `0` stays; tape `i + 1` becomes tape `i + 2`. Tape `1` is not used. -/\n+def skipOne {k k' : Nat} (h : k + 1 ≤ k') : Embedding k k' where\n+  emb i := if i.val = 0 then ⟨0, by omega⟩ else ⟨i.val + 1, by omega⟩\n+  back j :=\n+    if j.val = 0 then some ⟨0, by omega⟩\n+    else if j.val = 1 then none\n+    else if hj : j.val - 1 < k + 1 then some ⟨j.val - 1, hj⟩ else none\n+  back_emb i := by\n+    by_cases hi : i.val = 0\n+    · simp only [hi, ↓reduceIte, Option.some.injEq]\n+      exact Fin.ext hi.symm\n+    · have h1 : i.val + 1 ≠ 0 := by omega\n+      have h2 : i.val + 1 ≠ 1 := by omega\n+      have h3 : i.val + 1 - 1 < k + 1 := by omega\n+      simp only [hi, h1, h2, h3, ↓reduceIte, ↓reduceDIte, Option.some.injEq]\n+      exact Fin.ext (by simp)\n+\n+end Embedding\n+\n+variable {α : Type} {k k' : Nat}\n+\n+/-- The tapes of the large machine: the small machine's tapes where `E` places them, `rest` elsewhere. -/\n+def liftTapes (E : Embedding k k') (T : Fin (k + 1) → Tape α) (rest : Fin (k' + 1) → Tape α) :\n+    Fin (k' + 1) → Tape α :=\n+  fun j => match E.back j with\n+    | some i => T i\n+    | none => rest j\n+\n+theorem liftTapes_emb (E : Embedding k k') (T : Fin (k + 1) → Tape α) (rest : Fin (k' + 1) → Tape α)\n+    (i : Fin (k + 1)) : liftTapes E T rest (E.emb i) = T i := by\n+  simp [liftTapes, E.back_emb]\n+\n+/-- To identify lifted tapes, compare them where `E` places a small tape and elsewhere. -/\n+theorem liftTapes_eq (E : Embedding k k') {T : Fin (k + 1) → Tape α}\n+    {rest T' : Fin (k' + 1) → Tape α}\n+    (h₁ : ∀ j i, E.back j = some i → T' j = T i) (h₂ : ∀ j, E.back j = none → T' j = rest j) :\n+    liftTapes E T rest = T' := by\n+  funext j\n+  unfold liftTapes\n+  split\n+  · next i hi => exact (h₁ j i hi).symm\n+  · next hj => exact (h₂ j hj).symm\n+\n+namespace Machine\n+\n+/-- `M` running on the tapes `E` picks out; every other tape is read, written back, and not moved. -/\n+def lift (M : Machine α k) (E : Embedding k k') : Machine α k' where\n+  Q := M.Q\n+  finite := M.finite\n+  start := M.start\n+  halted := M.halted\n+  accepting := M.accepting\n+  δ q r :=\n+    let o := M.δ q (fun i => r (E.emb i))\n+    (o.1,\n+     fun j => match E.back j with\n+       | some i => o.2.1 i\n+       | none => r j,\n+     fun j => match E.back j with\n+       | some i => o.2.2 i\n+       | none => .stay)\n+\n+/-- The lifted machine's configuration standing for `c`, with `rest` on the other tapes. -/\n+def liftCfg (M : Machine α k) (E : Embedding k k') (rest : Fin (k' + 1) → Tape α) (c : Cfg α k M.Q) :\n+    Cfg α k' (M.lift E).Q :=\n+  ⟨c.state, liftTapes E c.tapes rest⟩\n+\n+theorem step_lift (M : Machine α k) (E : Embedding k k') (rest : Fin (k' + 1) → Tape α)\n+    (c : Cfg α k M.Q) : (M.lift E).step (M.liftCfg E rest c) = M.liftCfg E rest (M.step c) := by\n+  unfold step\n+  by_cases h : M.halted c.state = true\n+  · have h' : (M.lift E).halted (M.liftCfg E rest c).state = true := h\n+    simp only [h, h', ↓reduceIte]\n+  · have h' : ¬ (M.lift E).halted (M.liftCfg E rest c).state = true := h\n+    simp only [h, h', ↓reduceIte, Bool.false_eq_true]\n+    have hr : (fun i => reads (liftTapes E c.tapes rest) (E.emb i)) = reads c.tapes := by\n+      funext i\n+      simp [reads, liftTapes_emb]\n+    simp only [lift, liftCfg, Cfg.mk.injEq]\n+    refine ⟨by rw [hr], ?_⟩\n+    funext j\n+    simp only [apply, liftTapes]\n+    split\n+    · next i hi => simp only [hr]\n+    · next hj => simp [hj, reads, liftTapes]\n+\n+/-- **Simulation.** The lifted machine runs exactly like the original on its tapes. -/\n+theorem run_lift (M : Machine α k) (E : Embedding k k') (rest : Fin (k' + 1) → Tape α)\n+    (c : Cfg α k M.Q) (t : Nat) :\n+    (M.lift E).run (M.liftCfg E rest c) t = M.liftCfg E rest (M.run c t) := by\n+  induction t generalizing c with\n+  | zero => rfl\n+  | succ t ih => rw [run_succ, step_lift, ih, run_succ]\n+\n+end Machine\n+\n+/-! ## How the embeddings act on start tapes -/\n+\n+theorem liftTapes_castLE_inputTapes (h : k ≤ k') (y x : List α) :\n+    liftTapes (Embedding.castLE h) (inputTapes y) (inputTapes x : Fin (k' + 1) → Tape α) =\n+      inputTapes y := by\n+  apply liftTapes_eq\n+  · intro j i hi\n+    simp only [Embedding.castLE] at hi\n+    split at hi\n+    · cases hi; simp [inputTapes]\n+    · cases hi\n+  · intro j hj\n+    simp only [Embedding.castLE] at hj\n+    split at hj\n+    · cases hj\n+    · have : j.val ≠ 0 := by omega\n+      simp [inputTapes, this]\n+\n+theorem liftTapes_castLE_verifierTapes (h : k ≤ k') (x w : List α) :\n+    liftTapes (Embedding.castLE h) (verifierTapes x w)\n+        (verifierTapes x w : Fin (k' + 1) → Tape α) = verifierTapes x w := by\n+  apply liftTapes_eq\n+  · intro j i hi\n+    simp only [Embedding.castLE] at hi\n+    split at hi\n+    · cases hi; simp [verifierTapes]\n+    · cases hi\n+  · intro j _; rfl\n+\n+theorem liftTapes_skipOne_inputTapes (h : k + 1 ≤ k') (y x w : List α) :\n+    liftTapes (Embedding.skipOne h) (inputTapes y) (verifierTapes x w : Fin (k' + 1) → Tape α) =\n+      verifierTapes y w := by\n+  apply liftTapes_eq\n+  · intro j i hi\n+    simp only [Embedding.skipOne] at hi\n+    by_cases h0 : j.val = 0\n+    · simp only [h0, ↓reduceIte, Option.some.injEq] at hi\n+      subst hi\n+      simp [verifierTapes, inputTapes, h0]\n+    · by_cases h1 : j.val = 1\n+      · simp [h1] at hi\n+      · simp only [h0, h1, ↓reduceIte] at hi\n+        split at hi\n+        · cases hi\n+          have : j.val - 1 ≠ 0 := by omega\n+          simp [verifierTapes, inputTapes, h0, h1, this]\n+        · cases hi\n+  · intro j hj\n+    simp only [Embedding.skipOne] at hj\n+    by_cases h0 : j.val = 0\n+    · simp [h0] at hj\n+    · by_cases h1 : j.val = 1\n+      · simp [verifierTapes, h1]\n+      · simp only [h0, h1, ↓reduceIte] at hj\n+        split at hj\n+        · cases hj\n+        · simp [verifierTapes, h0, h1]\n+\n+end PvsNP\n","truncated":false}],"truncated":false},"jit":null,"api":"/v1/repos/pvsnp/commit?rev=ca0840598349a33fc20adf79395534b6d8376a04","api_url":"https://git.neoopensource.com/v1/repos/pvsnp/commit?rev=ca0840598349a33fc20adf79395534b6d8376a04"}