(** * Skelet #33 *)
Set Default Goal Selector "!".
Definition tm : TM := fun '(q, s) =>
match q, s with
| A, 0 => Some (1, R, B)  | A, 1 => Some (1, L, C)
| B, 0 => Some (0, R, C)  | B, 1 => Some (0, R, B)
| C, 0 => Some (1, L, D)  | C, 1 => Some (0, L, A)
| D, 0 => Some (1, L, E)  | D, 1 => None
| E, 0 => Some (1, L, A)  | E, 1 => Some (1, R, E)
end.
Notation "c --> c'" := (c -[ tm ]-> c')   (at level 40).
Notation "c -->* c'" := (c -[ tm ]->* c') (at level 40).
Notation "c -->+ c'" := (c -[ tm ]->+ c') (at level 40).
Notation P := Pos.succ.
Definition D n m : Q * tape :=
L n <{{C}} [1; 0; 1; 0; 1; 0] *> R m.
Definition E n m : Q * tape :=
K' n <{{C}} [1; 0; 1; 0] *> R m.
Fixpoint Lk {k} (n : bin k) :=
match n with
| bb => <[]
| b0 n => Lk n <+ <[0; 0; 0; 0]
| b1 n => Lk n <+ <[1; 0; 0; 0]
end.
Definition f (m : positive) (k : nat) : positive :=
(2 * (pow2 k - 1) :+ m)~0.
(* n = 1, or n starts with 11 in binary *)
Inductive leads' : positive -> Prop :=
| leads_1 : leads' 1
| leads_xI n : leads' n -> leads' n~1
| leads_xO n : leads' n -> (n <> 1)%positive -> leads' n~0.
Definition leads (n : N) : Prop :=
match n with
| 0%N => False
| N.pos n => leads' n
end.
Local Hint Constructors leads' : core.
Local Hint Resolve leads_add0_rev : core.
Local Hint Resolve reset_invariant_leads_b_m : core.

Theorem nonhalt : ~ halts tm c0.