{"repo":"pvsnp","commit":{"oid":"6e7066ddddafbadd01b90cd05e7abb76c82a1bba","tree":"2ffd9b4bb15c834edff42356734a67154b43bc98","parents":["ca0840598349a33fc20adf79395534b6d8376a04"],"author":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795944787000},"committer":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795944787000},"subject":"Compose machines sequentially","message":"Compose machines sequentially\n\nM₁.seq M₂ runs M₁, switches to M₂ in one step without touching a tape,\nthen runs M₂ on the tapes M₁ left. run_seq: if M₁ halts within t₁ steps\nand M₂ then halts within t₂, the composite halts within t₁ + 1 + t₂ in\nthe configuration M₂ reaches.\n\nCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>\n"},"diff":{"base":"ca0840598349a33fc20adf79395534b6d8376a04","head":"6e7066ddddafbadd01b90cd05e7abb76c82a1bba","stat":{"files":2,"additions":98,"deletions":0},"files":[{"path":"PvsNP.lean","status":"modified","additions":1,"deletions":0,"binary":false,"patch":"--- a/PvsNP.lean\n+++ b/PvsNP.lean\n@@ -4,6 +4,7 @@\n import PvsNP.Machine.Tape\n import PvsNP.Machine.Defs\n import PvsNP.Machine.Lift\n+import PvsNP.Machine.Compose\n \n /-! # P versus NP in Lean 4\n \n","truncated":false},{"path":"PvsNP/Machine/Compose.lean","status":"added","additions":97,"deletions":0,"binary":false,"patch":"--- /dev/null\n+++ b/PvsNP/Machine/Compose.lean\n@@ -0,0 +1,97 @@\n+import PvsNP.Machine.Defs\n+\n+/-!\n+# Running one machine after another\n+\n+`M₁.seq M₂` runs `M₁`; when `M₁` halts it spends one step switching to `M₂`'s start state, touching no\n+tape, and then runs `M₂` on the tapes `M₁` left behind. Its states are `M₁.Q ⊕ M₂.Q`, still finite.\n+\n+`Machine.run_seq` is the composition theorem: if `M₁` halts within `t₁` steps and `M₂`, started on what\n+`M₁` left, halts within `t₂` steps, then the composite halts within `t₁ + 1 + t₂` steps in the\n+configuration `M₂` reaches.\n+-/\n+\n+namespace PvsNP\n+\n+namespace Machine\n+\n+variable {α : Type} {k : Nat}\n+\n+/-- Run `M₁`, then `M₂` on the tapes `M₁` halts with. -/\n+def seq (M₁ M₂ : Machine α k) : Machine α k where\n+  Q := M₁.Q ⊕ M₂.Q\n+  finite := @IsFinite.instSum _ _ M₁.finite M₂.finite\n+  start := .inl M₁.start\n+  halted\n+    | .inl _ => false\n+    | .inr q => M₂.halted q\n+  accepting\n+    | .inl _ => false\n+    | .inr q => M₂.accepting q\n+  δ\n+    | .inl q, r =>\n+      if M₁.halted q then (.inr M₂.start, r, fun _ => .stay)\n+      else let o := M₁.δ q r; (.inl o.1, o.2.1, o.2.2)\n+    | .inr q, r => let o := M₂.δ q r; (.inr o.1, o.2.1, o.2.2)\n+\n+variable (M₁ M₂ : Machine α k)\n+\n+/-- The composite's configuration while it is running `M₁`. -/\n+def inlCfg (c : Cfg α k M₁.Q) : Cfg α k (M₁.seq M₂).Q := ⟨.inl c.state, c.tapes⟩\n+\n+/-- The composite's configuration once it is running `M₂`. -/\n+def inrCfg (c : Cfg α k M₂.Q) : Cfg α k (M₁.seq M₂).Q := ⟨.inr c.state, c.tapes⟩\n+\n+theorem apply_stay (T : Fin (k + 1) → Tape α) : apply T (reads T) (fun _ => .stay) = T := by\n+  funext i; simp [apply, reads]\n+\n+theorem step_seq_inl_running (c : Cfg α k M₁.Q) (h : M₁.halted c.state = false) :\n+    (M₁.seq M₂).step (inlCfg M₁ M₂ c) = inlCfg M₁ M₂ (M₁.step c) := by\n+  simp [step, seq, inlCfg, h]\n+\n+theorem step_seq_inl_halted (c : Cfg α k M₁.Q) (h : M₁.halted c.state = true) :\n+    (M₁.seq M₂).step (inlCfg M₁ M₂ c) = inrCfg M₁ M₂ (M₂.init c.tapes) := by\n+  simp [step, seq, inlCfg, inrCfg, init, h, apply_stay]\n+\n+theorem step_seq_inr (c : Cfg α k M₂.Q) :\n+    (M₁.seq M₂).step (inrCfg M₁ M₂ c) = inrCfg M₁ M₂ (M₂.step c) := by\n+  by_cases h : M₂.halted c.state = true\n+  · simp [step, seq, inrCfg, h]\n+  · simp [step, seq, inrCfg, h]\n+\n+theorem run_seq_inr (c : Cfg α k M₂.Q) (t : Nat) :\n+    (M₁.seq M₂).run (inrCfg M₁ M₂ c) t = inrCfg M₁ M₂ (M₂.run c t) := by\n+  induction t generalizing c with\n+  | zero => rfl\n+  | succ t ih => rw [run_succ, step_seq_inr, ih, run_succ]\n+\n+/-- If `M₁` has halted by step `t`, the composite has switched to `M₂` by step `t + 1`. -/\n+theorem run_seq_switch (c : Cfg α k M₁.Q) (t : Nat) (h : M₁.halted (M₁.run c t).state = true) :\n+    ∃ s, s ≤ t + 1 ∧\n+      (M₁.seq M₂).run (inlCfg M₁ M₂ c) s = inrCfg M₁ M₂ (M₂.init (M₁.run c t).tapes) := by\n+  induction t generalizing c with\n+  | zero => exact ⟨1, Nat.le_refl 1, by rw [run_succ, step_seq_inl_halted M₁ M₂ c h]; rfl⟩\n+  | succ t ih =>\n+    cases hc : M₁.halted c.state\n+    · rw [run_succ] at h\n+      obtain ⟨s, hs, hrun⟩ := ih (M₁.step c) h\n+      refine ⟨s + 1, by omega, ?_⟩\n+      rw [run_succ, step_seq_inl_running M₁ M₂ c hc, hrun, run_succ]\n+    · refine ⟨1, by omega, ?_⟩\n+      rw [run_succ, step_seq_inl_halted M₁ M₂ c hc, run_zero, run_of_halted M₁ hc]\n+\n+/-- **Composition.** `M₁` halts within `t₁` steps; `M₂`, started on the tapes `M₁` leaves, halts within\n+`t₂`. Then the composite halts within `t₁ + 1 + t₂` steps, where `M₂` does. -/\n+theorem run_seq (c : Cfg α k M₁.Q) (t₁ t₂ : Nat) (h₁ : M₁.halted (M₁.run c t₁).state = true)\n+    (h₂ : M₂.halted (M₂.run (M₂.init (M₁.run c t₁).tapes) t₂).state = true) :\n+    (M₁.seq M₂).run (inlCfg M₁ M₂ c) (t₁ + 1 + t₂) =\n+      inrCfg M₁ M₂ (M₂.run (M₂.init (M₁.run c t₁).tapes) t₂) := by\n+  obtain ⟨s, hs, hrun⟩ := run_seq_switch M₁ M₂ c t₁ h₁\n+  have hmid : (M₁.seq M₂).run (inlCfg M₁ M₂ c) (s + t₂) =\n+      inrCfg M₁ M₂ (M₂.run (M₂.init (M₁.run c t₁).tapes) t₂) := by\n+    rw [run_add, hrun, run_seq_inr]\n+  rw [run_stable (M₁.seq M₂) (s := s + t₂) (by rw [hmid]; exact h₂) (by omega), hmid]\n+\n+end Machine\n+\n+end PvsNP\n","truncated":false}],"truncated":false},"jit":null,"api":"/v1/repos/pvsnp/commit?rev=6e7066ddddafbadd01b90cd05e7abb76c82a1bba","api_url":"https://git.neoopensource.com/v1/repos/pvsnp/commit?rev=6e7066ddddafbadd01b90cd05e7abb76c82a1bba"}