(*START THE MEASUREMENT FOR BLACK NODES*)

Fixpoint countBLeafST (n : nat) (s : ShareTree) : nat :=
 match (n,s) with
 | (0,Leaf true) => 1
 | (0,Leaf false) => 0
 | (0, Node s1 s2) => 0
 | (S n', Leaf true) => (countBLeafST n' (Leaf true)) + (countBLeafST n' (Leaf true))
 | (S n', Leaf false) => 0
 | (S n', Node s1 s2) => (countBLeafST n' s1) + (countBLeafST n' s2)
 end.Definition countBLeafCT (n : nat) (s : canonTree) : nat :=
  countBLeafST n (proj1_sig s).

(* Specifications: *)
Lemma decompose_height_le : forall n s s1 s2, decompose s = (s1,s2) -> height s <= S n -> height s1 <= n /\ height s2 <= n.
Lemma decompose_le: forall s1 s2 s11 s12 s21 s22, (s1 <= s2)%ba -> decompose s1 = (s11,s12) -> decompose s2 = (s21,s22) -> (s11 <= s21)%ba /\ (s12 <= s22)%ba.
Lemma decompose_diff: forall s1 s2 s11 s12 s21 s22, s1 <> s2 -> decompose s1 = (s11,s12) -> decompose s2 = (s21,s22) -> s11 <> s21 \/ s12 <> s22.
Lemma countBLeafCT_decompose : forall n s s1 s2, decompose s = (s1,s2) -> countBLeafCT (S n) s = countBLeafCT n s1 + countBLeafCT n s2.
Lemma countBLeafCT_le : forall n s1 s2, (s1 <= s2)%ba -> countBLeafCT n s1 <= countBLeafCT n s2.
Lemma countBLeafCT_lt : forall n s1 s2, (s1 <= s2)%ba -> s1 <> s2 -> height s2 <= n -> countBLeafCT n s1 < countBLeafCT n s2.