(* Closure designed for qhmaps, but written on fmaps,
as usual: *)

Fixpoint clos(m:fmap):fmap:=
  match m with
    V => V
  | I m0 x0 =>
      i (clos m0) x0
  | L m0 k x0 y0 =>
      let mr:= clos m0 in
        if eq_dart_dec y0 (A mr k x0)
	then mr
        else l mr k x0 y0
  end.

(* Specifications: *)
Lemma exd_clos : forall (m:fmap)(x:dart), inv_qhmap m -> (exd m x <-> exd (clos m) x).
Lemma exd_clos_r : forall (m:fmap)(x:dart), inv_qhmap m -> exd m x -> exd (clos m) x.
Lemma exd_clos_qmap_l : forall (m:fmap)(x:dart), inv_qhmap m -> exd (clos m) x -> exd m x.
Theorem inv_hmap_clos : forall (m:fmap), inv_qhmap m -> inv_hmap (clos m).
Theorem A_clos_eq_cA : forall (m:fmap)(k:dim)(z:dart), inv_qhmap m -> exd m z -> A (clos m) k z = cA m k z /\ A_1 (clos m) k z = cA_1 m k z.