Ltac Inversion_typ T :=
    let INVTYP := fresh "INVTYP" in
    (generalize T; intro INVTYP; inversion INVTYP using inversion_lemma;
      unfold inv_typ in |- *; clear INVTYP; intros).

(* Specifications: *)
Lemma typ_free_db : forall (e : env) (t T : term), typ e t T -> free_db (length e) t.
Lemma wft_free_db : forall (e : env) (t : term), wf_type e t -> free_db (length e) t.
Theorem typ_weak : forall (g : env) (d : decl) (e : env) (t T : term), typ e t T -> forall (n : nat) (f : env), ins_in_env g d n e f -> wf f -> typ f (lift_rec 1 t n) (lift_rec 1 T n).
Theorem thinning : forall (e : env) (t T : term) (d : decl), typ e t T -> wf (d :: e) -> typ (d :: e) (lift 1 t) (lift 1 T).
Theorem thinning_n : forall (n : nat) (e f : env), trunc n e f -> forall t T : term, typ f t T -> wf e -> typ e (lift n t) (lift n T).
Theorem wf_sort_lift : forall (n : nat) (e : env) (t : term), wf e -> item_lift t e n -> exists s : sort, typ e t (Srt s).
Theorem definition_lift : forall (e : env) (n : nat) (t T : term), item (Def t T) e n -> wf e -> typ e (lift (S n) t) (lift (S n) T).
Theorem typ_sub : forall (g : env) (x : term) (d : decl), typ g x (typ_of_decl d) -> forall (e : env) (u U : term), typ e u U -> forall (f : env) (n : nat), sub_in_env g d x n e f -> wf f -> typ f (subst_rec x u n) (subst_rec x U n).
Theorem substitution : forall (e : env) (d t u U : term), typ (Ax t :: e) u U -> typ e d t -> typ e (subst d u) (subst d U).
Theorem subtype_in_env : forall (e : env) (t T : term), typ e t T -> forall f : env, R_in_env ge_type e f -> wf f -> typ f t T.
Theorem typ_conv_wf : forall (e : env) (t T U : term), typ e t T -> wf_type e U -> le_type e T U -> typ e t U.
Theorem wf_type_prod_l : forall (e : env) (A B : term), wf_type e (Prod A B) -> wf_type e A.
Theorem wf_type_prod_r : forall (e : env) (A B : term), wf_type e (Prod A B) -> wf_type (Ax A :: e) B.
Theorem wf_type_subst : forall (e : env) (v V T : term), wf_type (Ax V :: e) T -> typ e v V -> wf_type e (subst v T).
Theorem type_correctness : forall (e : env) (t T : term), typ e t T -> wf_type e T.
Lemma typ_free_db : forall (e : env) (t T : term), typ e t T -> free_db (length e) t.
Lemma wft_free_db : forall (e : env) (t : term), wf_type e t -> free_db (length e) t.
Theorem typ_weak : forall (g : env) (d : decl) (e : env) (t T : term), typ e t T -> forall (n : nat) (f : env), ins_in_env g d n e f -> wf f -> typ f (lift_rec 1 t n) (lift_rec 1 T n).
Theorem thinning : forall (e : env) (t T : term) (d : decl), typ e t T -> wf (d :: e) -> typ (d :: e) (lift 1 t) (lift 1 T).
Theorem thinning_n : forall (n : nat) (e f : env), trunc n e f -> forall t T : term, typ f t T -> wf e -> typ e (lift n t) (lift n T).
Theorem wf_sort_lift : forall (n : nat) (e : env) (t : term), wf e -> item_lift t e n -> exists s : sort, typ e t (Srt s).
Theorem definition_lift : forall (e : env) (n : nat) (t T : term), item (Def t T) e n -> wf e -> typ e (lift (S n) t) (lift (S n) T).
Theorem typ_sub : forall (g : env) (x : term) (d : decl), typ g x (typ_of_decl d) -> forall (e : env) (u U : term), typ e u U -> forall (f : env) (n : nat), sub_in_env g d x n e f -> wf f -> typ f (subst_rec x u n) (subst_rec x U n).
Theorem substitution : forall (e : env) (d t u U : term), typ (Ax t :: e) u U -> typ e d t -> typ e (subst d u) (subst d U).
Theorem subtype_in_env : forall (e : env) (t T : term), typ e t T -> forall f : env, R_in_env ge_type e f -> wf f -> typ f t T.
Theorem typ_conv_wf : forall (e : env) (t T U : term), typ e t T -> wf_type e U -> le_type e T U -> typ e t U.
Theorem wf_type_prod_l : forall (e : env) (A B : term), wf_type e (Prod A B) -> wf_type e A.
Theorem wf_type_prod_r : forall (e : env) (A B : term), wf_type e (Prod A B) -> wf_type (Ax A :: e) B.
Theorem wf_type_subst : forall (e : env) (v V T : term), wf_type (Ax V :: e) T -> typ e v V -> wf_type e (subst v T).
Theorem type_correctness : forall (e : env) (t T : term), typ e t T -> wf_type e T.