Safety of a deterministic worker replayed to its first halt
ProvedReplayVerification.no_mismatch_after_deterministic_restartdiscrete-dynamical-systemsformal-verification
A controller initializes a deterministic worker for the current input and runs it until the first state where its halting test is true. It records that state's reported value, resets the worker to the same initialized state, and replays it until its first halt. A mismatch enters a distinguished failure state. A match starts the same process on a specified successor input. For any worker, any initial input, any input successor function, and any finite number of controller steps, the failure state is unreachable. Worker running times may vary and a worker may never halt.
Preamble
import Mathlib
Formal statement
theorem ReplayVerification.no_mismatch_after_deterministic_restart {Input Work Result : Type*} [DecidableEq Result]
(init : Input → Work) (next : Work → Work) (halt : Work → Bool)
(report : Work → Result) (successor : Input → Input)
(first : Input) (T : ℕ) :
let Control := (Input × Work) ⊕ ((Input × Result × Work) ⊕ Unit)
let step : Control → Control := fun
| .inl (i, w) =>
if halt w then .inr (.inl (i, report w, init i)) else .inl (i, next w)
| .inr (.inl (i, claim, w)) =>
if halt w then
if report w = claim then .inl (successor i, init (successor i)) else .inr (.inr ())
else .inr (.inl (i, claim, next w))
| .inr (.inr ()) => .inr (.inr ())
step^[T] (.inl (first, init first)) ≠ .inr (.inr ()) := by sorrySource
Direct first-halt uniqueness and inductive safety proof for a deterministic replay controller.