Module RML := Rmaps_Lemmas(R).
Export RML.
Export R.
Definition mk_rshare: forall p: Share.t, pure_readable_share p -> rshare := exist pure_readable_share.
Definition rshare_sh (p: rshare) : Share.t := proj1_sig p.
(* Definition mk_pshare : forall p: Share.t, nonunit p -> pshare := exist nonunit. *)
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 _))).

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)).