(*======================================================== NUMBERING AND CHARACTERISTICS: =========================================================*)
Open Scope Z_scope.
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 zero x y => nv m0
| L m0 one x y => nv m0 - 1
end.
(* Number of edges: *)
Fixpoint ne(m:fmap):Z :=
match m with
V => 0
| I m0 x _ _ => ne m0 + 1
| L m0 zero x y => ne m0 - 1
| L m0 one 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 zero x y =>
let x_1:= cA_1 m0 one x in
nf m0 +
if expf_dec m0 x_1 y then 1 else -1
| L m0 one x y =>
let y0 := cA m0 zero y in
nf m0 +
if expf_dec m0 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 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.  *)

(* Specifications: *)
Theorem even_ec :
forall m:fmap, inv_hmap m -> Zeven (ec m).