(** [map] and [mapi] *)
Variable B : Type.
Section Mapi.
Variable f : key -> A -> B.
Fixpoint xmapi (m : t A) (i : key) : t B :=
match m with
| Leaf => @Leaf B
| Node l o r => Node (xmapi l (append i (xO xH)))
(option_map (f i) o)
(xmapi r (append i (xI xH)))
end.
Definition mapi m := xmapi m xH.
End Mapi.
Definition map (f : A -> B) m := mapi (fun _ => f) m.
End A.

Lemma mapi_1 :
forall (elt elt':Type)(m: t elt)(x:key)(e:elt)(f:key->elt->elt'),
MapsTo x e m ->
exists y, E.eq y x /\ MapsTo x (f y e) (mapi f m).