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.

Lemma TM_history_LRU_HF tm:
forall (s:St)(i:Σ_history),
match TM_history_LRU tm s i with
| Some tr =>
let (s',d,o) := tr in
tm s (fst i) = Some {| nxt:=s'; dir:=d; out:= fst o |}
| None => tm s (fst i) = None
end.