(* ** Helper Machines for positive numbers *)
Local Open Scope positive_scope.
(* ** Read the current symbol *)
Definition ReadPosSym : pTM sigPos^+ (option bool) 1 :=
CaseChar (fun (s : option sigPos^+) =>
match s with
| Some (inr sigPos_xH) => None
| Some (inr sigPos_xO) => Some false
| Some (inr sigPos_xI) => Some true
| _ => default
end).
Definition ReadPosSym_Rel : pRel sigPos^+ (option bool) 1 :=
fun tin '(yout, tout) =>
(forall (p : positive) (b : bool) (bits : list bool),
atBit tin[@Fin0] p b bits ->
match yout, b with
| Some false, false => tout = tin
| Some true,  true => tout = tin
| _, _ => False
end) /\
(forall (p : positive), atHSB tin[@Fin0] p -> tout = tin /\ yout = None).
(* ** Read the two current symbols *)
Definition ReadPosSym2 : pTM sigPos^+ (option bool * option bool) 2 :=
CaseChar2 (fun (s1 s2 : option sigPos^+) =>
(match s1 with
| Some (inr sigPos_xH) => None
| Some (inr sigPos_xO) => Some false
| Some (inr sigPos_xI) => Some true
| _ => default
end,
match s2 with
| Some (inr sigPos_xH) => None
| Some (inr sigPos_xO) => Some false
| Some (inr sigPos_xI) => Some true
| _ => default
end)).
Definition ReadPosSym2_Rel : pRel sigPos^+ (option bool * option bool) 2 :=
fun tin '(yout, tout) =>
(forall (p1 : positive) (b1 : bool) (bits1 : list bool) (p2 : positive) (b2 : bool) (bits2 : list bool),
atBit tin[@Fin0] p1 b1 bits1 ->
atBit tin[@Fin1] p2 b2 bits2 ->
match yout, b1, b2 with
| (Some false, Some false), false, false => tout = tin
| (Some false, Some  true), false,  true => tout = tin
| (Some  true, Some false),  true, false => tout = tin
| (Some  true, Some  true),  true,  true => tout = tin
| _, _, _ => False
end) /\
(forall (p1 : positive) (b1 : bool) (bits1 : list bool) (p2 : positive),
atBit tin[@Fin0] p1 b1 bits1 ->
atHSB tin[@Fin1] p2 ->
match yout, b1 with
| (Some false, None), false => tout = tin
| (Some  true, None),  true => tout = tin
| _, _ => False
end) /\
(forall (p1 : positive) (p2 : positive) (b2 : bool) (bits2 : list bool),
atHSB tin[@Fin0] p1 ->
atBit tin[@Fin1] p2 b2 bits2 ->
match yout, b2 with
| (None, Some false), false => tout = tin
| (None, Some  true),  true => tout = tin
| _, _ => False
end) /\
(forall (p1 p2 : positive),
atHSB tin[@Fin0] p1 ->
atHSB tin[@Fin1] p2 ->
tout = tin /\ yout = (None, None)).

Lemma ReadPosSym2_Sem : ReadPosSym2 ⊨c(1) ReadPosSym2_Rel.