Section CopySymbols.
Variable sig : finType.
(* Termination check *)
Variable f : sig -> bool.
Definition CopySymbols_Step : pTM sig (option unit) 2 :=
Switch (ReadChar_at Fin0)
(fun b : option sig =>
match b with
| Some x =>
(* First write the read symbol to tape 1 *)
if f x
then (* found the symbol: write it to tape 1; break and return *)
Return (LiftTapes (Write x) [|Fin1|]) (Some tt)
else (* wrong symbol: write it to tape 1 and move both tapes right and continue *)
Return (LiftTapes (Write x) [|Fin1|];;
MovePar Rmove Rmove) (None)
| _ => Return Nop (Some tt) (* there is no such symbol, break and return *)
end).
Definition CopySymbols_Step_Rel : pRel sig (option unit) 2 :=
fun tin '(yout, tout) =>
match current tin[@Fin0] with
| Some x =>
if (f x)
then tout[@Fin0] = tin[@Fin0] /\
tout[@Fin1] = tape_write tin[@Fin1] (Some x) /\
yout = Some tt (* break *)
else tout[@Fin0] = tape_move_right tin[@Fin0] /\
tout[@Fin1] = doAct tin[@Fin1] (Some x, Rmove) /\
yout = None (* continue *)
| _ => tout = tin /\
yout = Some tt
end.

Lemma CopySymbols_Step_Sem :
CopySymbols_Step ⊨c(7) CopySymbols_Step_Rel.