Section TMwithExtraInfo.
Hypothesis Σ:Set.
Hypothesis Σ':Set.
Hypothesis Σ0':Σ'.
Hypothesis F:Σ'->Σ.
Hypothesis tm:TM Σ.
Hypothesis tm':TM Σ'.
Hypothesis HF:
forall (s:St)(i:Σ'),
match tm' s i with
| Some tr =>
let (s',d,o) := tr in
tm s (F i) = Some {| nxt:=s'; dir:=d; out:= F o |}
| None => tm s (F i) = None
end.
Definition F_ES: (ExecState Σ')->(ExecState Σ) :=
fun st =>
let (s,t):=st in
(s,fun x => F (t x)).
End TMwithExtraInfo.
Definition StΣ_neb(x1 x2:St*Σ) :=
let (s1,i1):=x1 in
let (s2,i2):=x2 in
if St_eqb s1 s2 then negb (Σ_eqb i1 i2) else true.
Definition Σ_history:Set :=
Σ*(list (St*Σ)).
Definition Σ_history_0:Σ_history := (Σ0,nil).
Definition TM_history(n:nat)(tm:TM Σ):TM Σ_history :=
fun s i =>
let (i0,i1):=i in
match tm s i0 with
| Some tr =>
let (s',d,o0):=tr in
Some {|
nxt := s';
dir := d;
out := (o0,firstn n ((s,i0)::i1));
|}
| None => None
end.
Definition TM_history_LRU(tm:TM Σ):TM Σ_history :=
fun s i =>
let (i0,i1):=i in
match tm s i0 with
| Some tr =>
let (s',d,o0):=tr in
Some {|
nxt := s';
dir := d;
out := (o0,((s,i0)::(filter (StΣ_neb (s,i0)) i1)));
|}
| None => None
end.
Fixpoint listStΣ_enc(x:list (St*Σ)):positive:=
match x with
| nil => xH
| (St0,Σ0)::t => (listStΣ_enc t)~0~0~0
| (St0,Σ1)::t => (listStΣ_enc t)~1~0~0
| (St0,Σ2)::t => (listStΣ_enc t)~0~1~0
| (St0,Σ3)::t => (listStΣ_enc t)~1~1~0
| (St1,Σ0)::t => (listStΣ_enc t)~0~0~1
| (St1,Σ1)::t => (listStΣ_enc t)~1~0~1
| (St1,Σ2)::t => (listStΣ_enc t)~0~1~1
| (St1,Σ3)::t => (listStΣ_enc t)~1~1~1
end.
Definition Σ_history_enc(x:Σ_history):positive:=
let (x0,x1):=x in
match x0 with
| Σ0 => (listStΣ_enc x1)~0~0
| Σ1 => (listStΣ_enc x1)~1~0
| Σ2 => (listStΣ_enc x1)~0~1
| Σ3 => (listStΣ_enc x1)~1~1
end.
Definition NGramCPS_decider_impl1_0 (len_h len_l len_r m:nat) tm :=
NGramCPS_decider Σ_history len_l len_r Σ_history_enc (listT_enc Σ_history_enc) Σ_history_0 m (TM_history len_h tm).
Definition NGramCPS_decider_impl2_0 (len_l len_r m:nat) tm :=
NGramCPS_decider Σ len_l len_r Σ_enc (listΣ_enc) Σ0 m tm.
Definition NGramCPS_LRU_decider_0 (len_l len_r m:nat) tm :=
NGramCPS_decider Σ_history len_l len_r Σ_history_enc (listT_enc Σ_history_enc) Σ_history_0 m (TM_history_LRU tm).
Definition NGramCPS_decider_impl1 (len_h len_l len_r m:nat):HaltDecider :=
fun tm =>
if NGramCPS_decider_impl1_0 len_h len_l len_r m tm then Result_NonHalt else Result_Unknown.
Definition NGramCPS_decider_impl2 (len_l len_r m:nat):HaltDecider :=
fun tm =>
if NGramCPS_decider_impl2_0 len_l len_r m tm then Result_NonHalt else Result_Unknown.
Definition NGramCPS_LRU_decider (len_l len_r m:nat):HaltDecider :=
fun tm =>
if NGramCPS_LRU_decider_0 len_l len_r m tm then Result_NonHalt else Result_Unknown.

Lemma NGramCPS_decider_impl1_spec len_h len_l len_r m BB:
HaltDecider_WF BB (NGramCPS_decider_impl1 len_h len_l len_r m).