Definition minmaxN (n:block) (m:mem) (j:meminj) (b2:block) : option (Z * Z):=
Pos.peano_rect
(fun p => option(Z * Z))
(minmax_at m j b2 (1%positive))
(fun p Hp =>
match minmax_at m j b2 (Pos.succ p)
with Some(min1,max1) =>
match Hp with
Some(min2, max2) => Some (Zmin min1 min2, Zmax max1 max2)
| None => Some(min1,max1)
end
| None => Hp
end)
n.

Lemma minmaxN_sound: forall m j b2 n,
match minmaxN n m j b2
with Some(mn,mx) =>
forall b1 delta, (b1 <= n)%positive -> j b1 = Some(b2,delta) ->
forall z, z + delta < mn \/ z + delta > mx ->
ZMap.get z (Mem.mem_contents m)!!b1 = Undef
| None => forall b1 delta, (b1 <= n)%positive -> j b1 = Some(b2,delta) ->
forall z, ZMap.get z (Mem.mem_contents m)!!b1 = Undef
end.