Definition fixup_splitting
(a:address -> Share.t) (z: address -> option (rshare * kind)) : address -> option (rshare * kind) :=
fun l =>
match z l with
| Some (sh, k) =>
match dec_readable (a l) with
| left p => Some (readable_part p,  k)
| right _ => None
end
| None => None
end.
Definition share_of (x: option (rshare * kind)) : Share.t :=
match x with Some (p,_) => proj1_sig p | None => Share.bot end.
Definition Join_pk := (Join_lower (Join_prod rshare _ kind (Join_equiv _))).

(* Specifications: *)
Lemma share_of_Some: forall p: rshare * AV.kind, readable_share (share_of (Some p)).
Lemma join_sub_same_k:
forall {a a' : rshare} {k k': AV.kind},
@join_sub _ Join_pk (Some (a,k)) (Some (a',k')) -> k=k'.
Lemma pure_readable_glb_Rsh:
forall sh, pure_readable_share sh -> Share.glb Share.Rsh sh = sh.
Lemma join_glb_Rsh:
forall a b c : Share.t,
join a b c ->
join (Share.glb Share.Rsh a) (Share.glb Share.Rsh b) (Share.glb Share.Rsh c).
Lemma pure_readable_share_glb:
forall a, pure_readable_share a -> Share.glb Share.Rsh a = a.
Lemma glb_Rsh_bot_unreadable:
forall a, Share.glb Share.Rsh a = Share.bot -> ~readable_share a.
Lemma fixup_join : forall a (ac ad: address -> Share.t)  z,
(forall x, @join_sub _ Join_pk (a x) (z x)) ->
(forall x, join (ac x) (ad x) (share_of (a x))) ->
(forall x,
@join _ Join_pk
(fixup_splitting ac z x)
(fixup_splitting ad z x)
(a x)).
Lemma join_share_of: forall a b c,
@join _ Join_pk a b c -> join (share_of a) (share_of b) (share_of c).