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.

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