Definition synheap := seq elem.(*****************************************************************************)
(* Validity of indices:                                                      *)
(*   valid i t  iif all the indices in t are in bounds of the contexts lists *)
(*****************************************************************************)

Fixpoint valid_ptrs i t :=
  match t with
    Pts sx _ :: s => (sx < size (ptr_ctx i)) && valid_ptrs i s
  | Var _ :: s => valid_ptrs i s
  | _ => true
  end.Fixpoint valid_heaps i t :=
  match t with
    Pts _ _ :: s => valid_heaps i s
  | Var v :: s => (v < size (heap_ctx i)) && valid_heaps i s
  | _ => true
  end.Definition valid i t := valid_ptrs i t && valid_heaps i t.

Lemma valid_heaps_cat j t1 t2 : valid_heaps j (t1 ++ t2) = valid_heaps j t1 && valid_heaps j t2.