Section loopM.
Context (sig : finType).
Let reg_sig := @registered_finType sig.
Existing Instance reg_sig.
Let eqb_sig := eqbFinType_inst (X:=sig).
Existing Instance eqb_sig.
Variable n : nat.
Variable M : TM sig n.
Let reg_state := @registered_finType (state M).
Existing Instance reg_state.
Let eqb_state := eqbFinType_inst (X:=state M).
Existing Instance eqb_state.
Local Definition c__trans :=
(length ( elem (state M) ) * 4 + (n * (4 * length ( elem sig ) + 10) + 4) + 4) *
c__eqbComp (finType_CS (state M * VectorDef.t (option sig) n)).
Definition transTime := (| funTable (trans (m:=M)) |) * (c__trans + 24) + 4 + 9.
(* *** Computability of transition relation *)
Global Instance term_trans : computableTime' (trans (m:=M)) (fun _ _ => (transTime,tt)).
Definition step' (c :  mconfig sig (state M) n) : mconfig sig (state M) n :=
let (news, actions) := trans (cstate c, current_chars (ctapes c)) in
mk_mconfig news (doAct_multi (ctapes c) actions).
Global Instance term_doAct_multi: computableTime' (doAct_multi (n:=n) (sig:=sig)) (fun _ _ => (1,fun _ _ =>(n * 108 + 123,tt))).
Global Instance term_step' : computableTime' (step (M:=M)) (fun _ _ => (n* 130+ transTime + 172,tt)).
Local Definition cHalt := ((| elem (state M) |) * 4 * c__eqbComp (state M) + 24).
Definition haltTime := length (funTable (halt (m:=M))) * cHalt + 12.
Global Instance term_halt : computableTime' (halt (m:=M)) (fun _ _ => (haltTime,tt)).
Global Instance term_haltConf : computableTime' (haltConf (M:=M)) (fun _ _ => (haltTime+8,tt)).
(* *** Computability of step-ndexed interpreter *)
Global Instance term_loopM :
let c1 := (haltTime + n*130 + transTime + 85 + 108) in
let c2 := 15 + haltTime in
computableTime' (loopM (M:=M)) (fun _ _ => (5,fun k _ => (c1 * k + c2,tt))).
Instance term_test cfg :
computable (fun k => LOptions.isSome (loopM (M := M) cfg k)).

Lemma Halt_red cfg :
Halt' cfg <-> converges (mu (ext ((fun k => LOptions.isSome (loopM (M := M) cfg k))))).