Section TM.
Hypothesis Σ:Set.
Hypothesis Σ0:Σ.
Definition HaltsAt(tm:TM Σ)(n:nat)(st:ExecState Σ): Prop :=
exists st', Steps Σ tm n st st' /\ step Σ tm st' = None.
Definition Halts(tm:TM Σ)(st:ExecState Σ): Prop :=
exists n, HaltsAt tm n st.
Definition HaltsFromInit(tm:TM Σ): Prop :=
Halts tm (InitES Σ Σ0).
Definition NonHalt tm st :=
forall n, exists st', Steps Σ tm n st st'.
Definition LE(tm tm':TM Σ): Prop :=
forall (s:St)(i:Σ),
tm s i = tm' s i \/
tm s i = None.
Hypothesis BB:nat.
Definition HaltTimeUpperBound(st:ExecState Σ)(P:TM Σ->Prop):Prop :=
forall (tm:TM Σ)(n0:nat), P tm -> HaltsAt tm n0 st -> n0<=BB.
Hypothesis Σ_eqb:Σ->Σ->bool.
Hypothesis Σ_eqb_spec: forall i1 i2, if Σ_eqb i1 i2 then i1=i2 else i1<>i2.
Definition TM_upd tm s i t: TM Σ :=
fun s0 i0 =>
if (andb (St_eqb s0 s) (Σ_eqb i0 i)) then t else tm s0 i0.
Ltac Σ_eq_dec s1 s2 :=
eq_dec Σ_eqb_spec Σ_eqb s1 s2.

Lemma HaltTimeUpperBound_LE_Halt st tm n s t:
HaltsAt tm n st ->
Steps Σ tm n st (s,t) ->
n<=BB ->
(forall tr, HaltTimeUpperBound st (LE (TM_upd tm s (t Z0) (Some tr)))) ->
HaltTimeUpperBound st (LE tm).