Section Compare.
Variable sig : finType.
Variable stop : sig -> bool. (* stop symbol(s) *)
Definition Compare_Step : pTM sig (option bool) 2 :=
Switch
(CaseChar2 (fun c1 c2 =>
match c1, c2 with
| Some c1, Some c2 =>
if (stop c1) && (stop c2)
then Some true (* both stop symbols were reached at the same time ~> strings are equal *)
else if (stop c1) || (stop c2)
then Some false (* Only one stop symbol was reached ~> one string is longer *)
else if Dec (c1 = c2)
then None (* up to here, the strings are the same *)
else Some false (* symbols differ! *)
| _, _ => Some false (* At least one string not terminated *)
end))
(fun x : option bool => match x with
| Some b => Return Nop (Some b)
| None => Return (MovePar Rmove Rmove) None
end).
Definition Compare_Step_Rel : pRel sig (option bool) 2 :=
fun tin '(yout, tout) =>
match current tin[@Fin0], current tin[@Fin1] with
| Some c1, Some c2 =>
if (stop c1) && (stop c2)
then yout = Some true /\ tout = tin
else if (stop c1) || (stop c2)
then yout = Some false /\ tout = tin
else if Dec (c1 = c2)
then yout = None /\ tout[@Fin0] = tape_move_right tin[@Fin0] /\ tout[@Fin1] = tape_move_right tin[@Fin1]
else yout = Some false /\ tout = tin
| _, _ => yout = Some false /\ tout = tin
end.

Lemma Compare_Step_Sem : Compare_Step ⊨c(5) Compare_Step_Rel.