Section While.
Variable n : nat.
Variable sig : finType.
Variable F : finType.
(* Label [None] indicates continueing, [Some f] means breaking out of the loop and terminating in the label [f]. *)
Variable pM : pTM sig (option F) n.
Definition While_trans :
(TM.state (projT1 pM)) * Vector.t (option sig) n ->
(TM.state (projT1 pM)) * Vector.t (option sig * move) n :=
fun '(q,s) =>
if halt q
then (start (projT1 pM), nop_action)
else trans (q,s).
Definition WhileTM : TM sig n :=
Build_TM While_trans (start (projT1 pM))
(fun q => halt q && match projT2 pM q with
| Some _ => true
| None => false
end).
Hypothesis (defF : inhabitedC F).
Definition While_part : state (projT1 pM) -> F :=
fun q =>
match projT2 pM q with
| Some y => y
| None => default
end.
Definition While : pTM sig F n :=
(WhileTM; While_part).
Local Arguments loopM {_ _} _ _ _.
Local Arguments halt {_ _} _ _.
Local Arguments step {_ _} _ _.

Lemma While_split_term k (c1 c2 : mconfig sig (state WhileTM) n) (f : F) :
loopM WhileTM c1 k = Some c2 ->
haltConf (M := projT1 pM) c1 = true ->
projT2 pM (cstate c1) = Some f ->
c2 = c1.