Section Dom.
Variables A B : Type.
Fixpoint MapDomRestrTo (m:Map A) : Map B -> Map A :=
match m with
| M0 => fun _:Map B => M0 A
| M1 a y =>
fun m':Map B => match MapGet B m' a with
| None => M0 A
| _ => m
end
| M2 m1 m2 =>
fun m':Map B =>
match m' with
| M0 => M0 A
| M1 a' y' =>
match MapGet A m a' with
| None => M0 A
| Some y => M1 A a' y
end
| M2 m'1 m'2 =>
makeM2 A (MapDomRestrTo m1 m'1) (MapDomRestrTo m2 m'2)
end
end.
Fixpoint MapDomRestrBy (m:Map A) : Map B -> Map A :=
match m with
| M0 => fun _:Map B => M0 A
| M1 a y =>
fun m':Map B => match MapGet B m' a with
| None => m
| _ => M0 A
end
| M2 m1 m2 =>
fun m':Map B =>
match m' with
| M0 => m
| M1 a' y' => MapRemove A m a'
| M2 m'1 m'2 =>
makeM2 A (MapDomRestrBy m1 m'1) (MapDomRestrBy m2 m'2)
end
end.
Definition in_dom (a:ad) (m:Map A) :=
match MapGet A m a with
| None => false
| _ => true
end.

Lemma in_dom_remove :
forall (m:Map A) (a0 a:ad),
in_dom a (MapRemove A m a0) = andb (negb (N.eqb a a0)) (in_dom a m).