(************************************************************************)
(*         *      The Rocq Prover / The Rocq Development Team           *)
(*  v      *         Copyright INRIA, CNRS and contributors             *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)
(** * Finite sets library *)
(** This functor derives additional facts from [FSetInterface.S]. These facts are mainly the specifications of [FSetInterface.S] written using different styles: equivalence and boolean equalities. Moreover, we prove that [E.Eq] and [Equal] are setoid equalities. *)
Require Export FSetInterface.
Set Implicit Arguments.
Unset Strict Implicit.
(** First, a functor for Weak Sets in functorial version. *)
Module WFacts_fun (Import E : DecidableType)(Import M : WSfun E).
Notation eq_dec := E.eq_dec.
Definition eqb x y := if eq_dec x y then true else false.
(** * Specifications written using equivalences *)
Section IffSpec.
Variable s s' s'' : t.
Variable x y z : elt.

(* Specifications: *)
Lemma In_eq_iff : E.eq x y -> (In x s <-> In y s).
Lemma mem_iff : In x s <-> mem x s = true.
Lemma not_mem_iff : ~In x s <-> mem x s = false.
Lemma equal_iff : s[=]s' <-> equal s s' = true.
Lemma subset_iff : s[<=]s' <-> subset s s' = true.
Lemma empty_iff : In x empty <-> False.
Lemma is_empty_iff : Empty s <-> is_empty s = true.
Lemma singleton_iff : In y (singleton x) <-> E.eq x y.
Lemma add_iff : In y (add x s) <-> E.eq x y \/ In y s.
Lemma add_neq_iff : ~ E.eq x y -> (In y (add x s)  <-> In y s).
Lemma remove_iff : In y (remove x s) <-> In y s /\ ~E.eq x y.
Lemma remove_neq_iff : ~ E.eq x y -> (In y (remove x s) <-> In y s).
Lemma union_iff : In x (union s s') <-> In x s \/ In x s'.
Lemma inter_iff : In x (inter s s') <-> In x s /\ In x s'.
Lemma diff_iff : In x (diff s s') <-> In x s /\ ~ In x s'.
Variable f : elt->bool.
Lemma filter_iff :  compat_bool E.eq f -> (In x (filter f s) <-> In x s /\ f x = true).
Lemma for_all_iff : compat_bool E.eq f ->
(For_all (fun x => f x = true) s <-> for_all f s = true).
Lemma exists_iff : compat_bool E.eq f ->
(Exists (fun x => f x = true) s <-> exists_ f s = true).
Lemma elements_iff : In x s <-> InA E.eq x (elements s).
End IffSpec.