(************************************************************************)
(*         *      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 [MSetInterface.S]. These facts are mainly the specifications of [MSetInterface.S] written using different styles: equivalence and boolean equalities. Moreover, we prove that [E.Eq] and [Equal] are setoid equalities. *)
Require Export MSetInterface.
Set Implicit Arguments.
Unset Strict Implicit.
Local Ltac Tauto.intuition_solver ::= auto with relations.
(** First, a functor for Weak Sets in functorial version. *)
Module WFactsOn (Import E : DecidableType)(Import M : WSetsOn E).
Notation eq_dec := E.eq_dec.
Definition eqb x y := if eq_dec x y then true else false.
(** * Specifications written using implications : this used to be the default interface. *)
Section ImplSpec.
Variable s s' : t.
Variable x y : elt.

(* Specifications: *)
Lemma In_1 : E.eq x y -> In x s -> In y s.
Lemma mem_iff : In x s <-> mem x s = true.
Lemma equal_iff : s[=]s' <-> equal s s' = true.
Lemma empty_b : mem y empty = false.
Lemma add_b : mem y (add x s) = eqb x y || mem y s.
Lemma add_neq_b : ~ E.eq x y -> mem y (add x s) = mem y s.
Lemma remove_b : mem y (remove x s) = mem y s && negb (eqb x y).
Lemma remove_neq_b : ~ E.eq x y -> mem y (remove x s) = mem y s.
Lemma singleton_b : mem y (singleton x) = eqb x y.
Lemma union_b : mem x (union s s') = mem x s || mem x s'.
Lemma inter_b : mem x (inter s s') = mem x s && mem x s'.
Lemma diff_b : mem x (diff s s') = mem x s && negb (mem x s').
Lemma elements_b : mem x s = existsb (eqb x) (elements s).
Variable f : elt->bool.
Lemma filter_b : Proper (E.eq==>Logic.eq) f -> mem x (filter f s) = mem x s && f x.
Lemma for_all_b : Proper (E.eq==>Logic.eq) f ->
for_all f s = forallb f (elements s).
Lemma exists_b : Proper (E.eq==>Logic.eq) f ->
exists_ f s = existsb f (elements s).