Section MoveToSymbol.
Variable sig : finType.
(* Halt function *)
Variable f : sig -> bool.
(* Rewrite function *)
Variable g : sig -> sig.
(* * One Step: * Read one symbol. If there was no symbol, return [Some tt] (break out of the loop). * If the symbol [s] fulfills [f], write [g s] and return [Some tt]. * Else, write [g s] and move right, return [None] (continue the loop). *)
Definition MoveToSymbol_Step : pTM sig (option unit) 1 :=
Switch (ReadChar)
(fun b : option sig =>
match b with
| Some x => if f x
(* then Return (Nop) (Some tt) (* found the symbol, break *) *)
then Return (Write (g x)) (Some tt) (* found the symbol, break *)
else Return (WriteMove (g x) Rmove) (None) (* wrong symbol, move right and continue *)
| _ => Return (Nop) (Some tt) (* there is no such symbol, break *)
end).
Definition MoveToSymbol_Step_Fun : tape sig -> tape sig :=
fun t1 =>
match current t1 with
| Some s => if (f s)
then tape_write t1 (Some (g s))
else doAct t1 (Some (g s), Rmove)
| _ => t1
end.
Definition MoveToSymbol_Step_Rel : Rel (tapes sig 1) (option unit * tapes sig 1) :=
Mk_R_p (fun tin '(yout, tout) =>
tout = MoveToSymbol_Step_Fun tin /\
yout = match current tin with
| Some m =>
if f m
then Some tt (* break *)
else None (* continue *)
| _ => (Some tt) (* break *)
end
).

Lemma MoveToSymbol_Step_Sem :
MoveToSymbol_Step ⊨c(3) MoveToSymbol_Step_Rel.