bsets.v 1.58 KB
Newer Older
Robbert Krebbers's avatar
Robbert Krebbers committed
1 2 3
(* Copyright (c) 2012-2015, Robbert Krebbers. *)
(* This file is distributed under the terms of the BSD license. *)
(** This file implements bsets as functions into Prop. *)
4
From iris.prelude Require Export prelude.
Robbert Krebbers's avatar
Robbert Krebbers committed
5 6 7 8

Record bset (A : Type) : Type := mkBSet { bset_car : A  bool }.
Arguments mkBSet {_} _.
Arguments bset_car {_} _ _.
9
Instance bset_top {A} : Top (bset A) := mkBSet (λ _, true).
Robbert Krebbers's avatar
Robbert Krebbers committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23
Instance bset_empty {A} : Empty (bset A) := mkBSet (λ _, false).
Instance bset_singleton {A} `{ x y : A, Decision (x = y)} :
  Singleton A (bset A) := λ x, mkBSet (λ y, bool_decide (y = x)).
Instance bset_elem_of {A} : ElemOf A (bset A) := λ x X, bset_car X x.
Instance bset_union {A} : Union (bset A) := λ X1 X2,
  mkBSet (λ x, bset_car X1 x || bset_car X2 x).
Instance bset_intersection {A} : Intersection (bset A) := λ X1 X2,
  mkBSet (λ x, bset_car X1 x && bset_car X2 x).
Instance bset_difference {A} : Difference (bset A) := λ X1 X2,
  mkBSet (λ x, bset_car X1 x && negb (bset_car X2 x)).
Instance bset_collection {A} `{ x y : A, Decision (x = y)} :
  Collection A (bset A).
Proof.
  split; [split| |].
24 25 26 27 28
  - by intros x ?.
  - by intros x y; rewrite <-(bool_decide_spec (x = y)).
  - split. apply orb_prop_elim. apply orb_prop_intro.
  - split. apply andb_prop_elim. apply andb_prop_intro.
  - intros X Y x; unfold elem_of, bset_elem_of; simpl. 
Robbert Krebbers's avatar
Robbert Krebbers committed
29 30 31 32 33 34 35
    destruct (bset_car X x), (bset_car Y x); simpl; tauto.
Qed.
Instance bset_elem_of_dec {A} x (X : bset A) : Decision (x  X) := _.

Typeclasses Opaque bset_elem_of.
Global Opaque bset_empty bset_singleton bset_union
  bset_intersection bset_difference.