Section MacroMachine_secion.
Definition Word := list Σ.
Record RepeatWord := {
w: Word;
min_cnt: nat;
is_const: bool;
}.
Inductive RepW_match:RepeatWord->Word->Prop :=
| RepW_match_O w0:
RepW_match {| w:=w0; min_cnt:=0; is_const:=true |} nil
| RepW_match_S0 w0 w1 n:
RepW_match {| w:=w0; min_cnt:=n; is_const:=true |} w1 ->
RepW_match {| w:=w0; min_cnt:=S n; is_const:=true |} (w0++w1)
| RepW_match_S1 w0 w1 n n0:
n<=n0 ->
RepW_match {| w:=w0; min_cnt:=n0; is_const:=true |} w1 ->
RepW_match {| w:=w0; min_cnt:=n; is_const:=false |} w1
.
Inductive RepWL_match:(list RepeatWord)->(nat->Σ)->Prop :=
| RepWL_match_O:
RepWL_match nil half_tape_all0
| RepWL_match_S h t fh ft:
RepW_match h fh ->
RepWL_match t ft ->
RepWL_match (h::t) (app_halftape fh ft)
.
Record RepeatWordList_ES := {
l: list RepeatWord;
r: list RepeatWord;
s: St;
sgn: Dir;
}.
Fixpoint all0(x:Word):bool :=
match x with
| nil => true
| Σ0::t => all0 t
| _::t => false
end.
Fixpoint Word_eqb(x1 x2:Word):bool :=
match x1,x2 with
| nil,nil => true
| h1::t1,h2::t2 =>
if Σ_eqb h1 h2 then Word_eqb t1 t2 else false
| _,_ => false
end.
Hypothesis len:nat.
Definition pop(wl:list RepeatWord): option (Word*(list (list RepeatWord))) :=
match wl with
| nil => Some (repeat Σ0 len,(nil)::nil)
| v::wl0 =>
match min_cnt v with
| O => None
| S n0 => Some
(w v,(match n0 with
| S _ => ({| w:=w v; min_cnt:=n0; is_const:=true |}::wl0)
| O => (wl0)
end)::(if (is_const v) then nil else ((wl)::nil)))
end
end.
Ltac Word_eq_dec s1 s2 := eq_dec Word_eqb_spec Word_eqb s1 s2.

Lemma nat_lt_spec x1 x2:
if x1 <? x2 then x1<x2 else x2<=x1.