(*===========================================================
                   top, bottom
 
============================================================*)

(* top AND bottom :*)

Fixpoint top
   (m:fmap)(k:dim)(z:dart){struct m}:dart:=
 match m with
     V => nil
  |  I m0 x _ _ =>
       if eq_dart_dec x z then z
       else top m0 k z
  |  L m0 k0 x y =>
       if eq_dim_dec k0 k
       then
         if eq_dart_dec x (top m0 k0 z) 
         then top m0 k0 y
	 else top m0 k0 z
       else top m0 k z
 end.Fixpoint bottom
   (m:fmap)(k:dim)(z:dart){struct m}:dart:=
 match m with
     V => nil
  |  I m0 x _ _ =>
       if eq_dart_dec x z then z
       else bottom m0 k z
  |  L m0 k0 x y =>
       if (eq_dim_dec k0 k)
       then
         if eq_dart_dec y (bottom m0 k0 z)
         then bottom m0 k0 x
	 else bottom m0 k0 z
       else bottom m0 k z
 end.

Lemma cA_B : forall (m:fmap)(k:dim)(x z:dart), inv_hmap m -> succ m k x -> cA (B m k x) k z = (if eq_dart_dec x z then bottom m k x else if eq_dart_dec (top m k x) z then A m k x else cA m k z).