(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
Set Implicit Arguments.
Unset Strict Implicit.
Require Export Tiroirs.
Require Export Parts2.
Require Export Classical_Pred_Type.
Require Export Compare_dec.
unfold injective in |- *.
intros A B f H'; try assumption.
cut
(ex
(fun x : A =>
~ (forall y : A, ~ (~ Equal x y /\ Equal (Ap f x) (Ap f y))))).
intros H'0; try assumption.
elim H'0; intros x E; try exact E; clear H'0.
exists x; try assumption.
cut (ex (fun y : A => ~ ~ (~ Equal x y /\ Equal (Ap f x) (Ap f y)))).
intros H'0; try assumption.
elim H'0; intros y E0; try exact E0; clear H'0.
exists y; try assumption.
apply NNPP; auto with *.
apply
not_all_ex_not
with (P := fun y : A => ~ (~ Equal x y /\ Equal (Ap f x) (Ap f y)));
auto with *.
apply
not_all_ex_not
with
(P := fun x : A =>
forall y : A, ~ (~ Equal x y /\ Equal (Ap f x) (Ap f y)));
auto with *.
red in |- *.
intros H'0; try assumption.
apply H'.
intros x y H'1; try assumption.
specialize  H'0 with (n := x) (y := y); rename H'0 into H'3; try exact H'3.
apply NNPP; tauto.
Qed.
intros A B f H'; try assumption.
apply not_all_ex_not with (P := fun y : B => in_part y (image_map f)).
red in |- *.
red in H'.
intros H'0; try assumption.
lapply H'; [ intros H'1; try exact H'1; clear H' | clear H' ].
red in |- *.
simpl in H'0.
intros y; try assumption.
elim (H'0 y); intros x E; elim E; intros H'1 H'2; try exact H'2; clear E.
exists x; try assumption.
Qed.
Parameter
image_empty :
forall (E F : Setoid) (f : MAP E F) (A : part_set E),
Equal A (empty E) -> Equal (image f A) (empty F).
Hint Resolve image_empty: algebra.
Parameter
image_union :
forall (E F : Setoid) (f : MAP E F) (A B : part_set E),
Equal (image f (union A B)) (union (image f A) (image f B)).
Hint Resolve image_union: algebra.
Parameter
image_single :
forall (E F : Setoid) (f : MAP E F) (A : part_set E) (x : E),
Equal (image f (single x)) (single (f x)).
Hint Resolve image_single: algebra.
Parameter
union_single_in :
forall (E : Setoid) (A : part_set E) (x : E),
in_part x A -> Equal (union A (single x)) A.
Hint Resolve union_single_in: algebra.
intros E F f A n H'; try assumption.
apply
cardinal_ind2
with
(P := fun (n : nat) (A : part_set E) (c : cardinal A n) =>
ex (fun m : nat => cardinal (image f A) m /\ m <= n)).
intros A0 H'0; try assumption.
exists 0; split; [ idtac | auto with * ].
apply cardinal_empty; auto with *.
intros n0 H'0 A0 B x H'1 H'2 H'3; try assumption.
case (classic (in_part (f x) (image f B))).
intros H'4; try assumption.
elim (H'0 B);
[ intros m E0; elim E0; intros H'7 H'8; try exact H'7; clear E0 | idtac ].
exists m; split; [ idtac | try assumption ].
apply cardinal_comp with (image f B) m; auto with *.
apply Sym.
apply Trans with (image f (add_part B x)); auto with *.
unfold add_part in |- *.
apply Trans with (union (image f B) (image f (single x))); auto with *.
apply Trans with (union (image f B) (single (Ap f x))); auto with *.
auto with *.
apply cardinal_S with A0 x; auto with *.
intros H'4; try assumption.
elim (H'0 B);
[ intros m E0; elim E0; intros H'7 H'8; try exact H'7; clear E0 | idtac ].
exists (S m); split; [ try assumption | idtac ].
apply cardinal_add with (image f B) (Ap f x); auto with *.
unfold add_part in |- *.
unfold add_part in H'2.
apply Trans with (image f (union B (single x))); auto with *.
apply Trans with (union (image f B) (image f (single x))); auto with *.
auto with *.
apply cardinal_S with A0 x; auto with *.
auto with *.
Qed.

Lemma cardinal_image_injective :
forall (E F : Setoid) (f : MAP E F) (A : part_set E) (n : nat),
cardinal A n -> injective f -> cardinal (image f A) n.