Module Flip := Flip Ctx. Export Flip.
(* [f q = q'], where [q] is a state in [tm] and [q'] is the equivalent state in [tm']. *)
(* Note that this definition also admits mapping two equivalent states in [tm] to the same state in [tm']. This is intentional, though the name isn't perfect. *)
Definition Perm (tm tm' : TM) (f : Q -> Q) :=
(forall q s,
tm (q, s) = None ->
tm' (f q, s) = None) /\
(forall q s s' d q',
tm (q, s) = Some (s', d, q') ->
tm' (f q, s) = Some (s', d, f q')).
Local Hint Resolve perm_halted perm_halted' : core.
Local Hint Resolve perm_step : core.
Local Hint Resolve perm_multistep : core.
#[export] Hint Resolve perm_halts_in perm_halts_in' : core.

Lemma perm_nonhalt : forall tm tm' f q t,
Perm tm tm' f ->
~ halts tm' (f q;; t) ->
~ halts tm (q;; t).