{"repo":"pvsnp","commit":{"oid":"cd5376bbfcbe7c47ca864981700de9c4af3334aa","tree":"9a04097f71bb8f6c3a27bbd45b358c97d50acd14","parents":["138ab8077e37aa95e182800617d096901bc6fbcf"],"author":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795944694000},"committer":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795944694000},"subject":"Define multi-tape Turing machines and their runs","message":"Define multi-tape Turing machines and their runs\n\nMachine α k has k + 1 tapes over Option α and a finite type of states\n(finiteness is a field, so a state cannot hide unbounded data). step,\nrun and init, with run_add and the fact that halting is absorbing:\nrunning a halted configuration longer changes nothing.\n\ninputTapes and verifierTapes give the start tapes of deciders and of\nverifiers (certificate on tape 1).\n\nCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>\n"},"diff":{"base":"138ab8077e37aa95e182800617d096901bc6fbcf","head":"cd5376bbfcbe7c47ca864981700de9c4af3334aa","stat":{"files":2,"additions":132,"deletions":0},"files":[{"path":"PvsNP.lean","status":"modified","additions":1,"deletions":0,"binary":false,"patch":"--- a/PvsNP.lean\n+++ b/PvsNP.lean\n@@ -2,6 +2,7 @@\n import PvsNP.Basic.Poly\n import PvsNP.Language\n import PvsNP.Machine.Tape\n+import PvsNP.Machine.Defs\n \n /-! # P versus NP in Lean 4\n \n","truncated":false},{"path":"PvsNP/Machine/Defs.lean","status":"added","additions":131,"deletions":0,"binary":false,"patch":"--- /dev/null\n+++ b/PvsNP/Machine/Defs.lean\n@@ -0,0 +1,131 @@\n+import PvsNP.Basic.Finite\n+import PvsNP.Machine.Tape\n+\n+/-!\n+# Multi-tape Turing machines\n+\n+A `Machine α k` is a deterministic Turing machine with `k + 1` tapes over the tape alphabet `Option α`\n+(the input symbols and the blank). Tape `0` holds the input. Its control is a *finite* type of states\n+`Q`; in each step it reads the symbol under every head, and the transition function `δ` gives the next\n+state, a symbol to write on every tape and a move for every head.\n+\n+A machine stops in the states marked `halted`; `accepting` says which of those accept. Running a halted\n+configuration leaves it unchanged, so \"halted after `t` steps\" means \"halted within `t` steps\".\n+\n+Design notes:\n+- The tape alphabet is `Option α`: machines have no extra work symbols. For `|α| ≥ 2` this changes\n+  running times only polynomially; it keeps machines over one alphabet composable without re-encoding\n+  tapes.\n+- Finiteness of `Q` is part of the structure (`finite`). Without it a state could store the whole input\n+  and the model would decide anything in one step.\n+-/\n+\n+namespace PvsNP\n+\n+/-- A deterministic Turing machine with `k + 1` tapes over the tape alphabet `Option α`. -/\n+structure Machine (α : Type) (k : Nat) where\n+  /-- The states. -/\n+  Q : Type\n+  /-- There are finitely many states. -/\n+  finite : IsFinite Q\n+  /-- The start state. -/\n+  start : Q\n+  /-- The states in which the machine stops. -/\n+  halted : Q → Bool\n+  /-- The halted states that accept. -/\n+  accepting : Q → Bool\n+  /-- The transition: from a state and the symbols under the heads, the next state, the symbols to\n+  write and the head moves. -/\n+  δ : Q → (Fin (k + 1) → Option α) → Q × (Fin (k + 1) → Option α) × (Fin (k + 1) → Dir)\n+\n+/-- A configuration: a state and the contents of every tape. -/\n+structure Cfg (α : Type) (k : Nat) (Q : Type) where\n+  state : Q\n+  tapes : Fin (k + 1) → Tape α\n+\n+namespace Machine\n+\n+variable {α : Type} {k : Nat}\n+\n+/-- Apply one transition to every tape at once: write, then move. -/\n+def apply (tapes : Fin (k + 1) → Tape α) (w : Fin (k + 1) → Option α) (d : Fin (k + 1) → Dir) :\n+    Fin (k + 1) → Tape α :=\n+  fun i => ((tapes i).write (w i)).move (d i)\n+\n+/-- The symbols under the heads. -/\n+def reads (tapes : Fin (k + 1) → Tape α) : Fin (k + 1) → Option α :=\n+  fun i => (tapes i).read\n+\n+/-- One step. A halted configuration does not move. -/\n+def step (M : Machine α k) (c : Cfg α k M.Q) : Cfg α k M.Q :=\n+  if M.halted c.state then c\n+  else\n+    let o := M.δ c.state (reads c.tapes)\n+    ⟨o.1, apply c.tapes o.2.1 o.2.2⟩\n+\n+/-- `t` steps. -/\n+def run (M : Machine α k) (c : Cfg α k M.Q) : Nat → Cfg α k M.Q\n+  | 0 => c\n+  | t + 1 => M.run (M.step c) t\n+\n+/-- The configuration in which a machine starts, given its tapes. -/\n+def init (M : Machine α k) (tapes : Fin (k + 1) → Tape α) : Cfg α k M.Q := ⟨M.start, tapes⟩\n+\n+variable (M : Machine α k)\n+\n+@[simp] theorem run_zero (c : Cfg α k M.Q) : M.run c 0 = c := rfl\n+\n+theorem run_succ (c : Cfg α k M.Q) (t : Nat) : M.run c (t + 1) = M.run (M.step c) t := rfl\n+\n+theorem run_succ' (c : Cfg α k M.Q) (t : Nat) : M.run c (t + 1) = M.step (M.run c t) := by\n+  induction t generalizing c with\n+  | zero => rfl\n+  | succ t ih => rw [run_succ, ih, ← run_succ]\n+\n+theorem run_add (c : Cfg α k M.Q) (s t : Nat) : M.run c (s + t) = M.run (M.run c s) t := by\n+  induction s generalizing c with\n+  | zero => simp\n+  | succ s ih => rw [Nat.succ_add, run_succ, ih, run_succ]\n+\n+theorem step_of_halted {c : Cfg α k M.Q} (h : M.halted c.state = true) : M.step c = c := by\n+  simp [step, h]\n+\n+theorem run_of_halted {c : Cfg α k M.Q} (h : M.halted c.state = true) (t : Nat) : M.run c t = c := by\n+  induction t with\n+  | zero => rfl\n+  | succ t ih => rw [run_succ', ih, step_of_halted M h]\n+\n+/-- Once halted, a machine stays put: running longer changes nothing. -/\n+theorem run_stable {c : Cfg α k M.Q} {s t : Nat} (h : M.halted (M.run c s).state = true)\n+    (hst : s ≤ t) : M.run c t = M.run c s := by\n+  obtain ⟨u, rfl⟩ := Nat.exists_eq_add_of_le hst\n+  rw [run_add, run_of_halted M h]\n+\n+/-- The same machine with other accepting states. -/\n+def withAccepting (a : M.Q → Bool) : Machine α k := { M with accepting := a }\n+\n+/-- Acceptance plays no part in running. -/\n+theorem run_withAccepting (a : M.Q → Bool) (c : Cfg α k M.Q) (t : Nat) :\n+    (M.withAccepting a).run c t = M.run c t := by\n+  induction t generalizing c with\n+  | zero => rfl\n+  | succ t ih => exact ih (M.step c)\n+\n+end Machine\n+\n+/-! ## Initial tapes -/\n+\n+/-- Input `x` on tape `0`, every other tape blank, every head at `0`. -/\n+def inputTapes {α : Type} {k : Nat} (x : List α) : Fin (k + 1) → Tape α :=\n+  fun i => if i.val = 0 then Tape.ofWord x else Tape.blank\n+\n+/-- Input `x` on tape `0`, certificate `w` on tape `1` (when there is one), the rest blank. -/\n+def verifierTapes {α : Type} {k : Nat} (x w : List α) : Fin (k + 1) → Tape α :=\n+  fun i => if i.val = 0 then Tape.ofWord x else if i.val = 1 then Tape.ofWord w else Tape.blank\n+\n+theorem verifierTapes_nil {α : Type} {k : Nat} (x : List α) :\n+    (verifierTapes x [] : Fin (k + 1) → Tape α) = inputTapes x := by\n+  funext i\n+  simp only [verifierTapes, inputTapes, Tape.ofWord_nil, ite_self]\n+\n+end PvsNP\n","truncated":false}],"truncated":false},"jit":null,"api":"/v1/repos/pvsnp/commit?rev=cd5376bbfcbe7c47ca864981700de9c4af3334aa","api_url":"https://git.neoopensource.com/v1/repos/pvsnp/commit?rev=cd5376bbfcbe7c47ca864981700de9c4af3334aa"}