Section MapSweepDef.
Variable f : ad -> A -> bool.
Definition MapSweep2 (a0:ad) (y:A) :=
if f a0 y then Some (a0, y) else None.
Fixpoint MapSweep1 (pf:ad -> ad) (m:Map A) {struct m} :
option (ad * A) :=
match m with
| M0 => None
| M1 a y => MapSweep2 (pf a) y
| M2 m m' =>
match MapSweep1 (fun a:ad => pf (N.double a)) m with
| Some r => Some r
| None => MapSweep1 (fun a:ad => pf (Ndouble_plus_one a)) m'
end
end.
Definition MapSweep (m:Map A) := MapSweep1 (fun a:ad => a) m.

Lemma MapSweep_semantics_2 :
forall (m:Map A) (a:ad) (y:A),
MapSweep m = Some (a, y) -> MapGet A m a = Some y.