Section M.
Variable (sig : finType).
(* Hypothesis (defX: inhabitedC sigX). *)
(* We use the FinType instance of bool, as it has a Case-machine *)
Context `{retr__list : Retract (sigList bool) sig}
`{retr__Pro : Retract Alphabets.sigPro sig}.
Local Instance retr__nat : Retract sigNat sig := ComposeRetract retr__Pro _.
Local Instance retr__bool : Retract bool sig := ComposeRetract retr__list (Retract_sigList_X _).
(* Check _ : codable sig (list bool). *)
(* Check _ : codable sig bool. *)
(* Tapes: 0: compiled and encoded bs (input) 1: result 2: intern (constant for ConcatRepeat [0]) 3: intern (length of bs for concatReepat [1]) *)
(* für step (prepend the bs-dependent symbols) Tapes: 0: bs (input) 1: result 2: head of bs 3: intern (length of bs for concatReepat [1]) *)
Definition M__step : pTM sig^+ (option unit) 3 :=
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;Reset _ @ [|Fin2|];;
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;Reset _ @ [|Fin2|];;
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;
CaseCom ⇑ ComposeRetract retr__Pro _ @ [|Fin2|];;
If (CaseNat ⇑ _ @ [|Fin2|])
(Return (Reset _ @ [|Fin2|];;
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;Reset _ @ [|Fin2|];;
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;Reset _ @ [|Fin2|]
) (Some tt))
(Reset _ @ [|Fin2|];;
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;Reset _ @ [|Fin2|];;
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;Reset _ @ [|Fin2|];;
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;
CaseCom ⇑ ComposeRetract retr__Pro _ @ [|Fin2|];;
Switch (CaseNat ⇑ _ @ [|Fin2|])
(fun b => Cons_constant.M b ⇑ retr__list @[|Fin1|]);;
Reset _ @ [|Fin2|];;
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;Reset _ @ [|Fin2|];;
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;Reset _ @ [|Fin2|];;
CaseList _ ⇑ retr__Pro @ [|Fin0;Fin2|];;Reset _ @ [|Fin2|];;
Return Nop (None)
).
Arguments rcomp : simpl never.
Definition M__loop : pTM sig^+ unit 3 := While M__step.
Definition M : pTM sig^+ unit 3 :=
WriteValue ( (nil:list bool)) ⇑ _ @ [|Fin1|];;
M__loop.

Lemma SpecT :
{ f : UpToC (fun bs => length bs + 1) &
forall (bs :list bool),
TripleT
≃≃([],[|Contains _ (compile (Computable.enc bs));
Void;Void|])
(f bs)
M
(fun _ => ≃≃([],[| Contains _ (concat (repeat enc_bool_closing (length bs)));Contains _  (rev bs);Void |]))}.