Definition mkEI (j j': meminj) (m1 m2 m1':mem)
(Ext12: Mem.extends m1 m2)
(Fwd1: mem_forward m1 m1') m3
(Inj23: Mem.inject j m2 m3)
m3' (Fwd3: mem_forward m3 m3')
(Inj13': Mem.inject j' m1' m3')
(UnchOn3: Mem.unchanged_on (loc_out_of_reach j m1) m3 m3')
(InjInc: inject_incr j j') (injSep: inject_separated j j' m1 m3)
(UnchOn1: Mem.unchanged_on (loc_unmapped j) m1 m1')
: Mem.mem'.
assert (VB: (Mem.nextblock m2 <= Mem.nextblock m1')%positive).
destruct Ext12. rewrite <- mext_next.
apply (forward_nextblock _ _ Fwd1).
destruct (mkAccessMap_EI_existsT j m1 m1' m2) as [AM [ADefault PAM]].
assumption.
destruct (ContentsMap_EI_existsT j m1 m1' m2) as [CM [CDefault PCM]].
eapply Mem.mkmem with (nextblock:=m1'.(Mem.nextblock))
(mem_access:=AM)
(mem_contents:=CM).
(*apply (mkContentsMap_EI_exists j m1 m1' m2).*)
(*  apply m1'.*)
(*access_max*)
intros. rewrite PAM. unfold AccessMap_EI_FUN.
destruct (plt b (Mem.nextblock m2)).
(*valid_block m2 b*)
destruct (j b).
destruct p0.
destruct (Mem.perm_dec m1 b ofs Max Nonempty).
apply m1'.
apply m2.
apply m2.
(*~ valid_block m2 b*)
destruct (Mem.perm_dec m1' b ofs Max Nonempty).
apply m1'.
reflexivity.
(*nextblock_noaccess*)
intros. rewrite PAM.
unfold AccessMap_EI_FUN.
destruct (plt b (Mem.nextblock m2)).
exfalso. apply H; clear - VB p. xomega.
destruct (Mem.perm_dec m1' b ofs Max Nonempty); trivial.
exfalso. apply H. apply (Mem.perm_valid_block _ _ _ _ _ p).
(*contents_default*)
intros. rewrite PCM.
unfold ContentsMap_EI_FUN.
destruct (plt b (Mem.nextblock m1')).
remember (CM_block_EI_existsT j m1 m1' m2 b).
destruct s. apply a.
reflexivity.
Defined.

Lemma interpolate_EI: forall (m1 m2 m1':mem)
(Ext12: Mem.extends m1 m2) (Fwd1: mem_forward m1 m1')
m3 j (Inj23: Mem.inject j m2 m3) m3'
(Fwd3: mem_forward m3 m3') j'
(Inj13': Mem.inject j' m1' m3')
(UnchOn3: Mem.unchanged_on (loc_out_of_reach j m1) m3 m3')
(InjInc: inject_incr j j')
(injSep: inject_separated j j' m1 m3)
(UnchOn1:  Mem.unchanged_on (loc_unmapped j) m1 m1'),
exists m2', mem_forward m2 m2' /\ Mem.extends m1' m2' /\
Mem.inject j' m2' m3' /\
Mem.unchanged_on (loc_out_of_bounds m1) m2 m2' /\
Mem.unchanged_on (loc_unmapped j) m2 m2'.