(* fetching rhs functions names *)
Definition rhs_funcs ru :=  (* => Syntax.v ? *)
  match ru with
  | rule_intro _ _ t => functions_of_term t
  end.Definition all_rhs_funcs prg := flat_map rhs_funcs prg.

(* Specifications: *)
Lemma rhs_funcs_eq prg: (* pour pouvoir faire des fold et pas que des unfold *) flat_map rhs_funcs prg = all_rhs_funcs prg.
Lemma get_info_main_eq trs: match assoc Nat.eqb trs.(main) trs.(infos) with | Some inf => inf | None => Err_info end = get_info trs trs.(main).
Lemma get_info_l_eq trsl f: match assoc Nat.eqb f (concat (map infos trsl)) with | Some inf => inf | None => Err_info end = get_info_l trsl f.
Lemma get_rank_eq f trs inf: assoc Nat.eqb f (infos trs) = Some inf → rank inf = get_rank trs f.
Lemma asg_main_eq trs: asg (get_info trs trs.(main)) = asg_main trs.
Lemma qif_eq trs: (λ f l, let inf := get_info trs f in let q := inf.(asg) in let norm := inf.(norm) in let l1 := firstn norm l in let l2 := skipn norm l in (q l1) + (maxl l2)) = qif trs.
Lemma qif_eq_eta trs f l: let inf := get_info trs f in let q := inf.(asg) in let norm := inf.(norm) in let l1 := firstn norm l in let l2 := skipn norm l in (q l1) + (maxl l2) = qif trs f l.
Lemma rvd_make_rec n s g h0 h1 f: (* we can't really make a generic Lemma (ie, have 'rvd' as a parameter) because the hard part is proving it on the rules, and that depends on the property. The recursive parts on g, h0 and h1 is very easy. *) Forall rule_vars_defined g.(rules) → Forall rule_vars_defined h0.(rules) → Forall rule_vars_defined h1.(rules) → Forall rule_vars_defined (make_rec (S n) s g h0 h1 f).(rules).
Lemma rvd_make_comp n s h gN gS f: (* similar remark apply here… *) Forall rule_vars_defined h.(rules) → Forall rule_vars_defined (flat_map rules gN) → Forall rule_vars_defined (flat_map rules gS) → Forall rule_vars_defined (make_comp n s h gN gS f).(rules).