(*==========================================================
           CLOSURES of A AND A_1 IN qhmap
==========================================================*)

(* Closures of A and A_1, together designed for qhmaps,
mutually recursive: *)

Fixpoint cA
   (m:fmap)(k:dim)(x:dart){struct m}:dart:=
 match m with
     V => nil
  |  I m0 x0 =>
        if eq_dart_dec x x0 then x
	else cA m0 k x
  |  L m0 k0 x0 y0 =>
      if (eq_dim_dec k k0)
      then
         if (eq_dart_dec x x0) then y0
	 else
	   if (eq_dart_dec x (cA_1 m0 k y0))
	   then cA m0 k x0
	   else cA m0 k x
      else cA m0 k x
 end
with cA_1
   (m:fmap)(k:dim)(x:dart){struct m}:dart:=
 match m with
     V => nil
  |  I m0 x0 =>
        if eq_dart_dec x x0 then x
	else cA_1 m0 k x
  |  L m0 k0 x0 y0 =>
      if (eq_dim_dec k k0)
      then
         if (eq_dart_dec x y0) then x0
	 else
	   if (eq_dart_dec x (cA m0 k x0))
	   then cA_1 m0 k y0
	   else cA_1 m0 k x
      else cA_1 m0 k x
 end.

Lemma A_B_ter : forall (m:fmap)(k j:dim)(x y:dart), k<>j -> A (B m k x) j y = A m j y.