Definition replace_locals (mu:SM_Injection) pSrc' pTgt': SM_Injection :=
match mu with
Build_SM_Injection locBSrc locBTgt pSrc pTgt local extBSrc extBTgt fSrc fTgt extern =>
Build_SM_Injection locBSrc locBTgt pSrc' pTgt' local extBSrc extBTgt fSrc fTgt extern
end.
(*typically, we have forall b, pSrc b -> pSrc' b and forall b, pTgt b -> pTgt' b, i.e. only reclassify private entries as public*)

(* Specifications: *)
Lemma replace_locals_wd: forall mu (WD: SM_wd mu) pSrc' pTgt'
(SRC: forall b1, pSrc' b1 = true ->
exists b2 d, local_of mu b1 = Some(b2,d) /\ pTgt' b2=true)
(TGT: forall b, pTgt' b = true -> locBlocksTgt mu b = true),
SM_wd (replace_locals mu pSrc' pTgt').
Lemma replace_locals_extern: forall mu pubSrc' pubTgt',
extern_of (replace_locals mu pubSrc' pubTgt') = extern_of mu.
Lemma replace_locals_local: forall mu pubSrc' pubTgt',
local_of (replace_locals mu pubSrc' pubTgt') = local_of mu.
Lemma replace_locals_unknown: forall mu pubSrc' pubTgt',
unknown_of (replace_locals mu pubSrc' pubTgt') = unknown_of mu.
Lemma replace_locals_foreign: forall mu pubSrc' pubTgt',
foreign_of (replace_locals mu pubSrc' pubTgt') = foreign_of mu.
Lemma replace_locals_pub: forall mu pubSrc' pubTgt',
pub_of (replace_locals mu pubSrc' pubTgt') =
(fun b => if pubSrc' b then local_of mu b else None).
Lemma replace_locals_pub': forall mu pubSrc' pubTgt'
(P: forall b, pubBlocksSrc mu b = true -> pubSrc' b = true)
b (B: pubBlocksSrc mu b = true),
pub_of (replace_locals mu pubSrc' pubTgt') b = pub_of mu b.
Lemma replace_locals_as_inj: forall mu pubSrc' pubTgt',
as_inj (replace_locals mu pubSrc' pubTgt') = as_inj mu.
Lemma replace_locals_shared: forall mu pubSrc' pubTgt',
shared_of (replace_locals mu pubSrc' pubTgt') =
join (foreign_of mu) (fun b => if pubSrc' b then local_of mu b else None).
Lemma replace_locals_DOM: forall mu pubSrc' pubTgt',
DOM (replace_locals mu pubSrc' pubTgt') = DOM mu.
Lemma replace_locals_RNG: forall mu pubSrc' pubTgt',
RNG (replace_locals mu pubSrc' pubTgt') = RNG mu.
Lemma replace_locals_DomSrc: forall mu pubSrc' pubTgt',
DomSrc (replace_locals mu pubSrc' pubTgt') = DomSrc mu.
Lemma replace_locals_DomTgt: forall mu pubSrc' pubTgt',
DomTgt (replace_locals mu pubSrc' pubTgt') = DomTgt mu.
Lemma replace_locals_locBlocksSrc: forall mu pubSrc' pubTgt',
locBlocksSrc (replace_locals mu pubSrc' pubTgt') = locBlocksSrc mu.
Lemma replace_locals_extBlocksTgt: forall mu pubSrc' pubTgt',
extBlocksTgt (replace_locals mu pubSrc' pubTgt') = extBlocksTgt mu.
Lemma replace_locals_extBlocksSrc: forall mu pubSrc' pubTgt',
extBlocksSrc (replace_locals mu pubSrc' pubTgt') = extBlocksSrc mu.
Lemma replace_locals_locBlocksTgt: forall mu pubSrc' pubTgt',
locBlocksTgt (replace_locals mu pubSrc' pubTgt') = locBlocksTgt mu.
Lemma replace_locals_frgnBlocksSrc: forall mu pubSrc' pubTgt',
frgnBlocksSrc (replace_locals mu pubSrc' pubTgt') = frgnBlocksSrc mu.
Lemma replace_locals_frgnBlocksTgt: forall mu pubSrc' pubTgt',
frgnBlocksTgt (replace_locals mu pubSrc' pubTgt') = frgnBlocksTgt mu.
Lemma replace_locals_pubBlocksSrc: forall mu pubSrc' pubTgt',
pubBlocksSrc (replace_locals mu pubSrc' pubTgt') = pubSrc'.
Lemma replace_locals_pubBlocksTgt: forall mu pubSrc' pubTgt',
pubBlocksTgt (replace_locals mu pubSrc' pubTgt') = pubTgt'.
Lemma replace_locals_sharedTgt:
forall (mu : SM_Injection) (pubSrc' pubTgt' : block -> bool),
sharedTgt (replace_locals mu pubSrc' pubTgt') =
(fun b : block => frgnBlocksTgt mu b || pubTgt' b).
Lemma replace_locals_visTgt:
forall (mu : SM_Injection) (pubSrc' pubTgt' : block -> bool),
visTgt (replace_locals mu pubSrc' pubTgt') = visTgt mu.
Lemma replace_locals_wd: forall mu (WD: SM_wd mu) pSrc' pTgt'
(SRC: forall b1, pSrc' b1 = true ->
exists b2 d, local_of mu b1 = Some(b2,d) /\ pTgt' b2=true)
(TGT: forall b, pTgt' b = true -> locBlocksTgt mu b = true),
SM_wd (replace_locals mu pSrc' pTgt').
Lemma replace_locals_extern: forall mu pubSrc' pubTgt',
extern_of (replace_locals mu pubSrc' pubTgt') = extern_of mu.
Lemma replace_locals_local: forall mu pubSrc' pubTgt',
local_of (replace_locals mu pubSrc' pubTgt') = local_of mu.
Lemma replace_locals_unknown: forall mu pubSrc' pubTgt',
unknown_of (replace_locals mu pubSrc' pubTgt') = unknown_of mu.
Lemma replace_locals_foreign: forall mu pubSrc' pubTgt',
foreign_of (replace_locals mu pubSrc' pubTgt') = foreign_of mu.
Lemma replace_locals_pub: forall mu pubSrc' pubTgt',
pub_of (replace_locals mu pubSrc' pubTgt') =
(fun b => if pubSrc' b then local_of mu b else None).
Lemma replace_locals_pub': forall mu pubSrc' pubTgt'
(P: forall b, pubBlocksSrc mu b = true -> pubSrc' b = true)
b (B: pubBlocksSrc mu b = true),
pub_of (replace_locals mu pubSrc' pubTgt') b = pub_of mu b.
Lemma replace_locals_as_inj: forall mu pubSrc' pubTgt',
as_inj (replace_locals mu pubSrc' pubTgt') = as_inj mu.
Lemma replace_locals_shared: forall mu pubSrc' pubTgt',
shared_of (replace_locals mu pubSrc' pubTgt') =
join (foreign_of mu) (fun b => if pubSrc' b then local_of mu b else None).
Lemma replace_locals_DOM: forall mu pubSrc' pubTgt',
DOM (replace_locals mu pubSrc' pubTgt') = DOM mu.
Lemma replace_locals_RNG: forall mu pubSrc' pubTgt',
RNG (replace_locals mu pubSrc' pubTgt') = RNG mu.
Lemma replace_locals_DomSrc: forall mu pubSrc' pubTgt',
DomSrc (replace_locals mu pubSrc' pubTgt') = DomSrc mu.
Lemma replace_locals_DomTgt: forall mu pubSrc' pubTgt',
DomTgt (replace_locals mu pubSrc' pubTgt') = DomTgt mu.
Lemma replace_locals_locBlocksSrc: forall mu pubSrc' pubTgt',
locBlocksSrc (replace_locals mu pubSrc' pubTgt') = locBlocksSrc mu.
Lemma replace_locals_extBlocksTgt: forall mu pubSrc' pubTgt',
extBlocksTgt (replace_locals mu pubSrc' pubTgt') = extBlocksTgt mu.
Lemma replace_locals_extBlocksSrc: forall mu pubSrc' pubTgt',
extBlocksSrc (replace_locals mu pubSrc' pubTgt') = extBlocksSrc mu.
Lemma replace_locals_locBlocksTgt: forall mu pubSrc' pubTgt',
locBlocksTgt (replace_locals mu pubSrc' pubTgt') = locBlocksTgt mu.
Lemma replace_locals_frgnBlocksSrc: forall mu pubSrc' pubTgt',
frgnBlocksSrc (replace_locals mu pubSrc' pubTgt') = frgnBlocksSrc mu.
Lemma replace_locals_frgnBlocksTgt: forall mu pubSrc' pubTgt',
frgnBlocksTgt (replace_locals mu pubSrc' pubTgt') = frgnBlocksTgt mu.
Lemma replace_locals_pubBlocksSrc: forall mu pubSrc' pubTgt',
pubBlocksSrc (replace_locals mu pubSrc' pubTgt') = pubSrc'.
Lemma replace_locals_pubBlocksTgt: forall mu pubSrc' pubTgt',
pubBlocksTgt (replace_locals mu pubSrc' pubTgt') = pubTgt'.