(* 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                                                     *)
(** %\subsection*{ support :  finite\_subsets.v }%*)
Set Implicit Arguments.
Unset Strict Implicit.
From Algebra Require Export Diff.
From Algebra Require Export Singleton.
Require Export cast_between_subsets.
Require Export empty.
Require Export Classical_Prop.
(** - A set is finite if we can list its elements (possibly with duplicates in the list)  %\label{isfiniteset}% *)
Definition is_finite_set (A : Setoid) :=
exists n : Nat, (exists v : seq n A, full A =' seq_set v in _).
(** - For subsets, the following notion is more useful as it removes one one layer of taking subsets: *)
Definition is_finite_subset (A : Setoid) (B : part_set A) :=
exists n : Nat, (exists v : seq n A, B =' seq_set v in _).
red in |- *.
intros.
red in H0.
inversion H0.
inversion H1.
exists x.
exists x0.
apply Trans with B; auto with algebra.
Qed.
(** - There is no corresponding is_finite_set_comp, for there is no 'master' setoid wherein two Setoids can be compared. *)
Hint Resolve is_finite_subset_comp: algebra.
intros.
red in |- *; red in H.
inversion_clear H; inversion_clear H0.
exists x.
assert (forall i : fin x, in_part (x0 i) B).
simpl in H; red in H; simpl in H.
intros.
elim (H (x0 i)).
intros p q; (apply q; auto with algebra).
exists i; auto with algebra.
exists (cast_map_to_subset H0).
simpl in |- *; red in |- *; simpl in |- *; split; intro; auto.
unfold subtype_image_equal in |- *.
simpl in H; red in H; simpl in H.
elim (H (subtype_elt x1)).
intros.
assert (in_part (subtype_elt x1) B).
auto with algebra.
elim (H2 H4).
intros.
exists x2.
apply Trans with (x0 x2); auto with algebra.
Qed.

Lemma is_finite_set_then_is_finite_subset :
forall (A : Setoid) (B : part_set A), is_finite_set B -> is_finite_subset B.