(* * Pointer bookkeeping for machines using (positive) binary numbers *)
Local Open Scope positive_scope.
Definition atBit (t : tape sigPos^+) (lp : positive) (mb : bool) (rs : list bool) :=
exists (ls : list sigPos^+),
t = midtape (map inr (rev (encode lp)) ++ inl START :: ls) (bitToSigPos' mb) (map bitToSigPos' rs ++ [inl STOP]).
Definition atLSB (t : tape sigPos^+) (lp : positive) (mb : bool) := atBit t lp mb nil.
Definition atHSB (t : tape sigPos^+) (p : positive) :=
exists (ls : list sigPos^+),
t = midtape (inl START :: ls) (inr sigPos_xH) (map inr (tl (encode p)) ++ [inl STOP]).
(* *** Extensionality lemma and tactics *)

Lemma atBit_ext (t : tape sigPos^+) (p0 : positive) (b0 : bool) (bits0 : list bool) (p1 : positive) (b1 : bool) (bits1 : list bool) :
atBit t p0 b0 bits0 ->
p0 = p1 ->
b0 = b1 ->
bits0 = bits1 ->
atBit t p1 b1 bits1.