(*========================================================== ============================================================ TOPOLOGICAL FMAPS, QHMAPS, HMAPS -  PROOFS OF THE GENUS THEOREM AND THE EULER RELATION  PART 3:  EQUIVALENCES, CHARACTERISTICS, GENUS, EULER_POINCARE, CONSTRUCTIVE CONDITION OF PLANARITY  (J.-F. Dufourd - June 2006 - FOR PUBLICATION completed in October 2007 / January 2008)  (* COMPLETE, APART FROM LEMMA expf_clos_symm, WHICH IS ADMITTED TO PROVE THE NECESSARY CONDITION OF PLANARITY *)
============================================================
==========================================================*)
(*========================================================== DART EQUIVALENCES IN QHMAPS ==========================================================*)
Require Export Euler2.
(* Face equivalence: *)
Definition eqf(m:fmap)(x y:dart):=
expf m x y \/ expf m y x.
(* Reflexivity of eqf: *)
(* Symmetry of eqf: *)
(* Transitivity of eqf: *)
(* Decidability of eqf: *)
(* Connectivity : Definition in Prop "a la" Warshall *)
Fixpoint eqc(m:fmap)(x y:dart){struct m}:Prop:=
match m with
V => False
|  I m0 x0 => x=x0 /\ y=x0 \/ eqc m0 x y
|  L m0 _ x0 y0 =>
eqc m0 x y
\/ eqc m0 x x0 /\ eqc m0 y0 y
\/ eqc m0 x y0 /\ eqc m0 x0 y
end.
(* Decidability of eqc: *)
(* Reflexivity of eqc: *)
(* Symmetry of eqc: *)
(* Transitivity of eqc: *)
(* LEMMAS, USED IN THE FOLLOWING: *)
(* Idem, for A_1: *)
(* OK: *)
(* INVERSES, Idem: *)
(* OK: *)
(* Face path implies equivalence: with the LEMMAS above: *)
(* OK: *)
(* IDEM : *)
(*======================================================== NUMBERING AND CHARACTERISTICS: =========================================================*)
Open Scope Z_scope.
(* Number of darts: *)
Fixpoint nd(m:fmap):Z :=
match m with
V => 0
| I m0 x => nd m0 + 1
| L m0 _ _ _ => nd m0
end.
(* Number of vertices: *)
Fixpoint nv(m:fmap):Z :=
match m with
V => 0
| I m0 x => nv m0 + 1
| L m0 di0 x y => nv m0
| L m0 di1 x y => nv m0 -
if eq_dart_dec (A (clos m0) di1 x) y
then 0 else 1
end.
(* Number of edges: *)
Fixpoint ne(m:fmap):Z :=
match m with
V => 0
| I m0 x => ne m0 + 1
| L m0 di0 x y => ne m0 -
if eq_dart_dec (A (clos m0) di0 x) y
then 0 else 1
| L m0 di1 x y => ne m0
end.
(* Number of faces: *)
Fixpoint nf(m:fmap):Z :=
match m with
V => 0
| I m0 x => nf m0 + 1
| L m0 di0 x y =>
let mc := clos m0 in
let x0 := A mc di0 x in
let x_1:= A_1 mc di1 x in
nf m0 +
if eq_dart_dec y x0 then 0
else if expf_dec mc x_1 y then 1
else -1
| L m0 di1 x y =>
let mc := clos m0 in
let x1 := A mc di1 x in
let y0 := A mc di0 y in
nf m0 +
if eq_dart_dec y x1 then 0
else if expf_dec mc x y0 then 1
else -1
end.
(* Number of connected components: *)
Fixpoint nc(m:fmap):Z :=
match m with
V => 0
| I m0 x => nc m0 + 1
| L m0 _ x y => nc m0 -
if eqc_dec (clos m0) x y then 0 else 1
end.
(* Euler-Poincare characteristic: *)
Definition ec(m:fmap): Z:=
nv m + ne m + nf m - nd m.
(* The Euler-Poincare characteristic is even: OK: *)
(* THEOREME OF THE GENUS: OK *)
Definition genus(m:fmap):= (nc m) - (ec m)/2.
(* COROLLARY, OK: *)
Definition planar(m:fmap):= genus m = 0.
(* EULER-POINCARE FORMULA: *)
(* REMARK: SYMMETRY OF expf in the closure NOT USED *)
(* ========================================================== PLANARITY CRITERIA (SUFFICIENT CONDITIONS) =============================================================*)
(* Sewing at dimension 0: *)
(* Sewing at dimension 1: *)
(* V is planar: *)
(* Inserting a dart preserves planarity: *)
(* Sewing two disconnected darts preserves planarity:*)
(* Sewing at dimension 0 and planarity preservation: *)
(* Sewing at dimension 1 and planarity preservation: *)
(* Definition of "Planar formation" of fmap: *)
Fixpoint plf(m:fmap):Prop:=
match m with
V => True
| I m0 x => plf m0
| L m0 di0 x y => plf m0 /\
(let mc := (clos m0) in
~eqc mc x y \/ expf mc (A_1 mc di1 x) y)
| L m0 di1 x y => plf m0 /\
(let mc := (clos m0) in
~eqc mc x y \/ expf mc x (A mc di0 y))
end.
(* Constructive Sufficient Condition of planarity: *)

Theorem plf_planar:forall (m:fmap),
inv_qhmap m -> plf m -> planar m.