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_1 :
forall (m:Map A) (pf:ad -> ad) (a:ad) (y:A),
MapSweep1 pf m = Some (a, y) -> {a' : ad | a = pf a'}.