set.v 2.36 KB
Newer Older
1
(* Copyright (c) 2012-2017, Coq-std++ developers. *)
Robbert Krebbers's avatar
Robbert Krebbers committed
2 3
(* This file is distributed under the terms of the BSD license. *)
(** This file implements sets as functions into Prop. *)
4
From stdpp Require Export collections.
5
Set Default Proof Using "Type".
Robbert Krebbers's avatar
Robbert Krebbers committed
6 7

Record set (A : Type) : Type := mkSet { set_car : A  Prop }.
Robbert Krebbers's avatar
Robbert Krebbers committed
8
Add Printing Constructor set.
9 10
Arguments mkSet {_} _ : assert.
Arguments set_car {_} _ _ : assert.
Robbert Krebbers's avatar
Robbert Krebbers committed
11
Notation "{[ x | P ]}" := (mkSet (λ x, P))
12
  (at level 1, format "{[  x  |  P  ]}") : stdpp_scope.
Robbert Krebbers's avatar
Robbert Krebbers committed
13

Robbert Krebbers's avatar
Robbert Krebbers committed
14
Instance set_elem_of {A} : ElemOf A (set A) := λ x X, set_car X x.
Robbert Krebbers's avatar
Robbert Krebbers committed
15

16
Instance set_top {A} : Top (set A) := {[ _ | True ]}.
Robbert Krebbers's avatar
Robbert Krebbers committed
17 18 19
Instance set_empty {A} : Empty (set A) := {[ _ | False ]}.
Instance set_singleton {A} : Singleton A (set A) := λ y, {[ x | y = x ]}.
Instance set_union {A} : Union (set A) := λ X1 X2, {[ x | x  X1  x  X2 ]}.
Robbert Krebbers's avatar
Robbert Krebbers committed
20
Instance set_intersection {A} : Intersection (set A) := λ X1 X2,
Robbert Krebbers's avatar
Robbert Krebbers committed
21
  {[ x | x  X1  x  X2 ]}.
Robbert Krebbers's avatar
Robbert Krebbers committed
22
Instance set_difference {A} : Difference (set A) := λ X1 X2,
Robbert Krebbers's avatar
Robbert Krebbers committed
23
  {[ x | x  X1  x  X2 ]}.
Robbert Krebbers's avatar
Robbert Krebbers committed
24
Instance set_collection : Collection A (set A).
Robbert Krebbers's avatar
Robbert Krebbers committed
25
Proof. split; [split | |]; by repeat intro. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
26

27
Lemma elem_of_top {A} (x : A) : x  ( : set A)  True.
28
Proof. done. Qed.
29 30 31
Lemma elem_of_mkSet {A} (P : A  Prop) x : x  {[ x | P x ]}  P x.
Proof. done. Qed.
Lemma not_elem_of_mkSet {A} (P : A  Prop) x : x  {[ x | P x ]}  ¬P x.
32
Proof. done. Qed.
33 34 35
Lemma top_subseteq {A} (X : set A) : X  .
Proof. done. Qed.
Hint Resolve top_subseteq.
36

Robbert Krebbers's avatar
Robbert Krebbers committed
37 38 39 40
Instance set_ret : MRet set := λ A (x : A), {[ x ]}.
Instance set_bind : MBind set := λ A B (f : A  set B) (X : set A),
  mkSet (λ b,  a, b  f a  a  X).
Instance set_fmap : FMap set := λ A B (f : A  B) (X : set A),
Robbert Krebbers's avatar
Robbert Krebbers committed
41
  {[ b |  a, b = f a  a  X ]}.
Robbert Krebbers's avatar
Robbert Krebbers committed
42
Instance set_join : MJoin set := λ A (XX : set (set A)),
43
  {[ a |  X : set A, a  X  X  XX ]}.
Robbert Krebbers's avatar
Robbert Krebbers committed
44 45 46
Instance set_collection_monad : CollectionMonad set.
Proof. by split; try apply _. Qed.

47 48 49 50 51 52
Instance set_unfold_set_all {A} (x : A) : SetUnfold (x  ( : set A)) True.
Proof. by constructor. Qed.
Instance set_unfold_mkSet {A} (P : A  Prop) x Q :
  SetUnfoldSimpl (P x) Q  SetUnfold (x  mkSet P) Q.
Proof. intros HPQ. constructor. apply HPQ. Qed.

53
Global Opaque set_elem_of set_top set_empty set_singleton.
54
Global Opaque set_union set_intersection set_difference.
55
Global Opaque set_ret set_bind set_fmap set_join.