Section PartialFunctions.
Variable X Y : Set.
Hypothesis Xeq_dec : forall x1 x2 : X, {x1 = x2} + {x1 <> x2}.
Hypothesis Yeq_dec : forall x1 x2 : Y, {x1 = x2} + {x1 <> x2}.
Hypothesis XYeq_dec : forall x1 x2 : X * Y, {x1 = x2} + {x1 <> x2}.
(*Domain of a FPF*)
Fixpoint DOM (f : set (X * Y)) : set X :=
match f with
| nil => nil (A:=X)
| (x, y) :: g => set_add Xeq_dec x (DOM g)
end.
(*Range of a FPF*)
Fixpoint RAN (f : set (X * Y)) : set Y :=
match f with
| nil => nil (A:=Y)
| (x, y) :: g => set_add Yeq_dec y (RAN g)
end.
(*Application of a FPF*)
Fixpoint PARTFUNC (f : set (X * Y)) : X -> Exc Y :=
fun x : X =>
match f with
| nil => None (A:=Y)
| (x1, y) :: g =>
match Xeq_dec x x1 with
| left _ => Some y
| right _ => PARTFUNC g x
end
end.
(*Test to decide whether a set of pairs is a FPF or not*)
Fixpoint IsPARTFUNC (f : set (X * Y)) : Prop :=
match f with
| nil => True
| a :: l =>
match set_In_dec Xeq_dec (fst a) (DOM l) with
| left _ => False
| right _ => IsPARTFUNC l
end
end.
(*Some usefull lemmas about our implementation of FPF*)
intros.
induction  f as [| a0 f Hrecf].
simpl in |- *.
elim (Xeq_dec a b).
intros.
cut False.
intro.
elim H0.
unfold not in H; apply H.
auto.
auto.
simpl in |- *.
elim a0.
intros.
elim (Xeq_dec a a1).
elim (XYeq_dec (b, y) (a1, b0)).
intros.
cut False.
intro F.
elim F.
unfold not in H.
apply H.
rewrite a3.
injection a2.
auto.
simpl in |- *.
elim (Xeq_dec a a1).
auto.
intros.
cut False.
intro F.
elim F.
auto.
elim (XYeq_dec (b, y) (a1, b0)).
simpl in |- *.
elim (Xeq_dec a a1).
intros.
cut False.
intro F.
elim F.
auto.
auto.
simpl in |- *.
elim (Xeq_dec a a1).
intros.
cut False.
intro F.
elim F.
auto.
intros.
auto.
Qed.

Lemma AddEq1 :
forall (x : X) (y : Y) (f : set (X * Y)),
~ set_In x (DOM f) -> value y = PARTFUNC (set_add XYeq_dec (x, y) f) x.