(*========================================================
                      HMAPS
  ========================================================*)

(* HYPOTHESIS: a hmap could be viewed as a qhmap with
the closed version of A. Hier, it is considered as a completely 
sewn qhmap, which is approximately the same... *)

(* Invariant of the hypermaps: inv_qhmap + completeness *)

Definition inv_hmap(m:fmap):Prop :=
   inv_qhmap m
  /\ forall (x:dart)(k:dim), exd m x ->
       succ m k x /\ pred m k x.(* Definition of the hypermaps: *)

Definition hmap:Set := {m:fmap | inv_hmap m}.(* Surjection, bijection on the fmap darts: *)

Definition surj_dart(Df:dart->Prop)(f:dart->dart):Prop:=
  forall y:dart, Df y ->
     exists x:dart, Df x /\ f x = y.Definition bij_dart(Df:dart->Prop)(f:dart->dart):Prop:=       
  inj_dart Df f /\ surj_dart Df f.

(* Specifications: *)
Lemma inj_A: forall (m:fmap)(k:dim), inv_hmap m -> inj_dart (exd m) (A m k).
Lemma inj_A_1: forall (m:fmap)(k:dim), inv_hmap m -> inj_dart (exd m) (A_1 m k).
Lemma surj_A_1_hmap: forall (m:fmap)(k:dim), inv_hmap m -> surj_dart (succ m k) (A_1 m k).
Lemma surj_A_1: forall (m:fmap)(k:dim), inv_hmap m -> surj_dart (exd m) (A_1 m k).
Lemma surj_A_hmap: forall (m:fmap)(k:dim), inv_hmap m -> surj_dart (succ m k) (A m k).
Lemma surj_A: forall (m:fmap)(k:dim), inv_hmap m -> surj_dart (exd m) (A m k).
Theorem bij_A: forall (m:fmap)(k:dim), inv_hmap m -> bij_dart (exd m) (A m k).
Theorem bij_A_1: forall (m:fmap)(k:dim), inv_hmap m -> bij_dart (exd m) (A_1 m k).
Lemma A_B_1_B_x0 : forall(m:fmap)(k:dim)(x0 y0:dart), inv_qhmap m -> A (B_1 (B m k x0) k y0) k x0 = nil.
Lemma A_B_1_B_y0 : forall(m:fmap)(k:dim)(x0 y0:dart), inv_qhmap m -> exd m x0 -> exd m y0 -> y0<>x0 -> y0<>A m k x0 -> A (B_1 (B m k x0) k y0) k y0 = if eq_dart_dec y0 (A m k y0) then nil else A m k y0.
Lemma A_B_1_B_xk : forall(m:fmap)(k:dim)(x0 y0:dart), inv_qhmap m -> exd m x0 -> exd m y0 -> let xk := A m k x0 in let yk := A_1 m k y0 in x0 <> xk -> y0 <> xk -> A (B_1 (B m k x0) k y0) k xk = if eq_dart_dec xk yk then nil else A m k xk.
Lemma A_B_1_B_yk : forall(m:fmap)(k:dim)(x0 y0:dart), inv_qhmap m -> exd m x0 -> exd m y0 -> y0 <> A m k x0 -> A (B_1 (B m k x0) k y0) k (A_1 m k y0) = nil.
Lemma A_1_B_1_B_y0 : forall(m:fmap)(k:dim)(x0 y0:dart), inv_qhmap m -> A_1 (B_1 (B m k x0) k y0) k y0 = nil.
Lemma A_1_B_1_B_x0 : forall(m:fmap)(k:dim)(x0 y0:dart), inv_qhmap m -> exd m x0 -> exd m y0 -> y0<>x0 -> y0<>A m k x0 -> A_1 (B_1 (B m k x0) k y0) k x0 = if eq_dart_dec x0 (A m k x0) then nil else A_1 m k x0.
Lemma A_1_B_1_B_yk : forall(m:fmap)(k:dim)(x0 y0:dart), inv_qhmap m -> exd m x0 -> exd m y0 -> let xk := A m k x0 in let yk := A_1 m k y0 in y0 <> yk -> y0 <> xk -> A_1 (B_1 (B m k x0) k y0) k yk = if eq_dart_dec xk yk then nil else A_1 m k yk.
Lemma A_1_B_1_B_xk : forall(m:fmap)(k:dim)(x0 y0:dart), inv_qhmap m -> exd m x0 -> exd m y0 -> y0<>A m k x0 -> A_1 (B_1 (B m k x0) k y0) k (A m k x0) = nil.