Inductive pre_ad : Set :=
| pre_ad_empty : pre_ad
| pre_ad_O : pre_ad -> pre_ad
| pre_ad_I : pre_ad -> pre_ad.
Fixpoint pre_ad_concat (pa : pre_ad) : ad -> ad :=
fun a : ad =>
match pa with
| pre_ad_empty => a
| pre_ad_O pa' => pre_ad_concat pa' (Ndouble a)
| pre_ad_I pa' => pre_ad_concat pa' (Ndouble_plus_one a)
end.
Fixpoint st_compat_check_0 (pa : pre_ad) (sigma : signature)
(s : state) {struct s} : bool :=
match s with
| M0 => true
| M1 a p =>
match pl_compat_check p, MapGet nat sigma (pre_ad_concat pa a) with
| None, _ => false
| _, None => false
| Some n, Some m => beq_nat n m
end
| M2 x y =>
st_compat_check_0 (pre_ad_O pa) sigma x &&
st_compat_check_0 (pre_ad_I pa) sigma y
end.
Definition st_compat_check (s : state) (sigma : signature) : bool :=
st_compat_check_0 pre_ad_empty sigma s.
Fixpoint predta_compat_check (d : preDTA) : signature -> bool :=
fun sigma : signature =>
match d with
| M0 => true
| M1 a s => st_compat_check s sigma
| M2 x y => predta_compat_check x sigma && predta_compat_check y sigma
end.
Definition dta_compat_check (d : DTA) (sigma : signature) : bool :=
match d with
| dta p a => predta_compat_check p sigma
end.
Definition state_correct_wrt_sign_with_offset (s : state)
(sigma : signature) (pa : pre_ad) : Prop :=
forall (a : ad) (p : prec_list),
MapGet prec_list s a = Some p ->
exists n : nat,
MapGet nat sigma (pre_ad_concat pa a) = Some n /\ pl_tl_length p n.

Lemma st_compat_check_correct :
forall (s : state) (sigma : signature),
state_correct_wrt_sign s sigma -> st_compat_check s sigma = true.