Module Type SHARE_MODEL.
Include BA_FACTS.
Parameter EqDec_share: EqDec t.
Existing Instance EqDec_share.
(* Splittability *)
Parameter split : t -> t * t.
(* Token factories *)
Parameter isTokenFactory : t -> nat -> Prop.
Parameter isToken : t -> nat -> Prop.
Parameter create_token : nat -> t -> (t*t).
Parameter split_token : nat -> t -> t*t.
(* relativization *)
Parameter rel : t -> t -> t.
Parameter unrel: t -> t -> t.
Definition Lsh  : t := fst (split top).
Definition Rsh  : t := snd (split top).
Definition splice (a b: t) : t := lub (rel Lsh a) (rel Rsh b).
(* BEGIN NEW MATERIAL *)
(*D1*)
Parameter tree_height : t -> nat.
Parameter tree_height_zero : forall t, {tree_height t = 0} + {tree_height t <> 0}.
Instance tree_heightable : heightable t :=
Heightable tree_height tree_height_zero.
(*D2*)
Parameter tree_round_left : nat -> t -> option t.
Instance  roundableL_tree : roundableLeft t :=
RoundableLeft tree_round_left.
(*D3*)
Parameter tree_round_right : nat -> t -> option t.
Instance  roundableR_tree : roundableRight t :=
RoundableRight tree_round_right.
(*D4*)
Parameter tree_avg : nat -> t -> t -> option t.
Instance avgable_tree : avgable t :=
Avgable tree_avg.
(*D5*)
Parameter countBLeafCT : nat -> t -> nat.
(*D6*)
Parameter share_metric : nat -> t -> nat.
(*D7*)
Parameter tree_decompose : t -> (t * t).
Instance decompose_tree : decomposible t :=
Decomposible tree_decompose.
(*D8*)
Parameter recompose : (t * t) -> t.
(*D9*)
Parameter power : nat -> nat -> nat.
(*D10*)
Parameter add : t -> t -> option t.
(*D11*)
Parameter sub : t -> t -> option t.

Axiom Lsh_recompose: Lsh = recompose (top, bot).
Axiom Rsh_recompose: Rsh = recompose (bot,top).
Axiom decompose_Rsh: forall sh, unrel Rsh sh = snd (decompose sh).
Axiom decompose_Lsh: forall sh, unrel Lsh sh = fst (decompose sh).
Axiom rel_Lsh: forall sh, rel Lsh sh = recompose (sh,bot).
Axiom rel_Rsh: forall sh, rel Rsh sh = recompose (bot,sh).
Axiom lub_rel_recompose: forall sh1 sh2,
lub (rel Lsh sh1) (rel Rsh sh2) = recompose (sh1,sh2).