Close Scope open_scope.
End MoreLemmas.
Section SubstFresh.
Context {A val : Type} {Heq : RelDec (@eq A)} {HeqOk : RelDec_Correct Heq}.
Context {R : ValNull val}.
Definition subst_fresh (vs: A -> val) (xs: list A) : subst :=
fun x' => if (List.anyb (rel_dec x')) xs then V_expr (vs x') else stack_get x'.
Fixpoint subst_fresh_l (vs: A -> val) (xs: list A) : list (@expr A val) :=
match xs with
| nil => nil
| cons x xs' => cons (V_expr (vs x)) (subst_fresh_l vs xs')
end.

(* Specifications: *)
(* TODO: switch the two alt. definitions. *)
Lemma subst_fresh_alt (vs: A -> val) (xs: list A) :
subst_fresh vs xs = substl (combine xs (subst_fresh_l vs xs)).