(** * Arity  - [arity e] returns the arity (i.e., the number variables) of the expression [e] if it is well formed, or an error including the arity of the subterms. *)
Inductive Arity : Set :=
| error_Rec : Arity -> Arity -> Arity -> Arity -> Arity
| error_Comp : Arity -> list Arity -> Arity
| error_Proj : nat -> nat -> Arity
| ok_arity : nat -> Arity.
Definition arity_eq (a1 a2 : Arity) :=
match a1, a2 with
| ok_arity n1, ok_arity n2 => beq_nat n1 n2
| _, _ => false
end.

Lemma Cobham_ind_inf :
forall (P : nat -> Cobham -> Prop),
P 0 Zero ->
(forall n i, i < n  ->  P n (Proj n i)) ->
(forall b, P 1 (Succ b)) ->
(P 2 Smash) ->
(forall n g h0 h1 j,
arity g = ok_arity n ->
arity h0 = ok_arity (S (S n)) ->
arity h1 = ok_arity (S (S n)) ->
arity j = ok_arity (S n) ->
P n g ->
P (S (S n)) h0 ->
P (S (S n)) h1 ->
P (S n) j ->
P (S n) (Rec g h0 h1 j)) ->
(forall n h rl,
arity h = ok_arity (length rl)  ->
(forall e, In e rl -> arity e = ok_arity n) ->
P (length rl) h ->
(forall r, In r rl -> P n r) ->
P n (Comp n h rl)) ->
forall e n , arity e = ok_arity n -> P n e.