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.

Lemma perm_multistep' : forall tm tm' f,
Perm tm tm' f -> forall n q t q' t',
f q;; t -[ tm' ]->> n / q';; t' ->
exists q'', q;; t -[ tm ]->> n / q'';; t' /\ f q'' = q'.