End Cat.
Module Import FmapE.
Definition fmapE := (fndSome, getfE, setfK, fnd_set, getf_set,
setfNK, fnd_reducef, get_reducef, fnd_filterf, get_filterf,
fnd_restrict, getf_restrict, fnd_rem, fnd_rem1,
restrictfT, restrictf0, restrictf_id, remf_id, remf1_id,
fnd_cat).
End FmapE.
Arguments catf : simpl never.
Notation "f + g" := (catf f g) : fset_scope.
Section FinMapKeyType.
Variables (K V : choiceType).
Implicit Types (f g : {fmap K -> V}).
Definition codomf f : {fset V} := [fset f k | k : domf f].

(* Specifications: *)
Lemma mem_codomf f v : (v \in codomf f) = [exists x : domf f, f x == v].
Lemma codomfP f v : reflect (exists x, f.[? x] = Some v) (v \in codomf f).
Lemma codomfPn f v : reflect (forall x, f.[? x] != Some v) (v \notin codomf f).
Lemma codomf0 : codomf [fmap] = fset0.
Lemma in_codomf f (k : domf f) : f k \in codomf f.
Lemma codomf_restrict f (A : {fset K})  :
codomf f.[& A] = [fset f k | k : domf f & val k \in A].
Lemma codomf_restrict_exists f (A : {fset K})  :
codomf f.[& A] = [fset v in codomf f
| [exists k : domf f, (val k \in A) && (f k == v)]].
Lemma codomf_rem f (A : {fset K})  :
codomf f.[\ A] = [fset f k | k : domf f & val k \notin A].
Lemma codomf_rem_exists f (A : {fset K})  :
codomf f.[\ A] = [fset v in codomf f
| [exists k : domf f, (val k \notin A) && (f k == v)]].
Lemma in_codomf_rem1 f (k : K) (kf : k \in domf f)  :
codomf f.[~ k] =
if [exists k' : domf f, (val k' != k) && (f k' == f.[kf])] then codomf f
else codomf f `\ f.[kf].
Lemma codomf_set f (k : K) (v : V) (kf : k \in domf f) :
codomf f.[k <- v] = v |` codomf f.[~ k].