Definition minmax m j (b2:block): option(Z * Z) :=
if plt 1%positive (Mem.nextblock m)
then minmaxN (Pos.pred (Mem.nextblock m)) m j b2
else None.

(* Specifications: *)
Lemma minmax_sound: forall m j b2,
match minmax m j b2
with Some(mn,mx) =>
forall b1 delta, (b1 < Mem.nextblock m)%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 < Mem.nextblock m)%positive ->
j b1 = Some(b2,delta) ->
forall z, ZMap.get z (Mem.mem_contents m)!!b1 = Undef
end.
Lemma minmax_sound: forall m j b2,
match minmax m j b2
with Some(mn,mx) =>
forall b1 delta, (b1 < Mem.nextblock m)%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 < Mem.nextblock m)%positive ->
j b1 = Some(b2,delta) ->
forall z, ZMap.get z (Mem.mem_contents m)!!b1 = Undef
end.