(*******************freezing a list of mpreds ******************************)

Fixpoint freezelist_nth (l: list nat) (al: list mpred): (list mpred) * (list mpred) :=
 match l with
 | nil => (nil,al)
 | (n::l') => let (xs, ys) := freezelist_nth l' al
              in (nth n ys emp::xs, delete_nth n ys)
 end.

(* Specifications: *)
Lemma FRZL_ax ps: FRZL ps = fold_right_sepcon ps.
Lemma fold_right_sepcon_deletenth: forall n (l: list mpred), fold_right_sepcon l = nth n l emp * fold_right_sepcon (delete_nth n l).
Lemma fold_right_sepcon_deletenth': forall n (l:list (LiftEnviron mpred)), @fold_right (environ -> mpred) (environ -> mpred) sepcon emp l = nth n l emp * fold_right sepcon emp (delete_nth n l).
Lemma freeze_SEP': forall l Espec {cs: compspecs} Delta P Q R c Post xs ys, (xs, ys) = freezelist_nth l R -> @semax cs Espec Delta (PROPx P (LOCALx Q (SEPx (FRZL xs:: ys)))) c Post -> @semax cs Espec Delta (PROPx P (LOCALx Q (SEPx R))) c Post.
Lemma map_delete_nth {A B} (f:A->B): forall n l, delete_nth n (map f l) = map f (delete_nth n l).