Definition term_from_active_term (t: active_term) : term :=
let (f, lv) := t in
fapply f (map (@term_from_value _ _ _) lv).
Definition value_list_order (lv lv' : list value) : Prop :=
suml (map (@value_size _) lv) < suml (map (@value_size _) lv').

Lemma psubst_app p v (s s' : list (variable * value)) :
(forall x : variable, assoc (variable_beq variable_eq_dec) x s <> None -> assoc (variable_beq variable_eq_dec) x s' = None) ->
(forall x, In x (vars_of_pattern p) -> assoc (variable_beq variable_eq_dec) x s <> None) ->
psubst (assoc_default (variable_beq variable_eq_dec) value_default s        ) p = v ->
psubst (assoc_default (variable_beq variable_eq_dec) value_default (s' ++ s)) p = v.