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
| (St1,Σ0)::t => (listStΣ_enc t)~0~1~0
| (St1,Σ1)::t => (listStΣ_enc t)~1~1~0
| (St2,Σ0)::t => (listStΣ_enc t)~0~0~1
| (St2,Σ1)::t => (listStΣ_enc t)~1~0~1
| (St3,Σ0)::t => (listStΣ_enc t)~0~1~1
| (St3,Σ1)::t => (listStΣ_enc t)~1~1~1
end.

Lemma listStΣ_enc_inj: is_inj listStΣ_enc.