Inductive list_order {A : Type} (R : A -> A -> Prop) : list A -> list A -> Prop :=
| lo_cons:  forall l1 l2 h, Forall (fun x => R x h) l1 -> list_order R (l1 ++ l2) (h :: l2).Inductive list_order {A : Type} (R : A -> A -> Prop) : list A -> list A -> Prop :=
| lo_cons:  forall l1 l2 h, Forall (fun x => R x h) l1 -> list_order R (l1 ++ l2) (h :: l2).Definition W {A : Type} (R : A -> A -> Prop) (l : list A) : Prop :=
  Acc (list_order R) l.

Lemma max_arity_subst s t f lp : rule_vars_defined (rule_intro f lp t) -> let t' := fapply f (map (fun p => term_from_value variable function (@psubst variable constructor s p)) lp) in max_arity_term (subst s t) <= Nat.max (max_arity_rule (rule_intro f lp t)) (max_arity_term t').