phanerozoic/Coq-Stdpp huggingface dataset:
(* stdpp/relations.v *)
Lemma diamond_confluent :
    diamond R → confluent R.
Proof.
    intros Hdiam. assert (∀ x y1 y2,
      rtc R x y1 → R x y2 → ∃ z, rtc R y1 z ∧ rtc R y2 z) as Hstrip.
    { intros x y1 y2 Hy1; revert y2.
      induction Hy1 as [x|x y1 y1' Hy1 Hy1' IH]; [by eauto|]; intros y2 Hy2.
      destruct (Hdiam x y1 y2) as (z&Hy1z&Hy2z); auto.
      destruct (IH z) as (z'&?&?); eauto. }
    intros x y1 y2 Hy1; revert y2.
    induction Hy1 as [x|x y1 y1' Hy1 Hy1' IH]; [by eauto|]; intros y2 Hy2.
    destruct (Hstrip x y2 y1) as (z&?&?); eauto.
    destruct (IH z) as (z'&?&?); eauto using rtc_trans.
  Qed.
(* stdpp/relations.v *)
Lemma confluent_locally_confluent :
    confluent R → locally_confluent R.
Proof. unfold confluent, locally_confluent; eauto. Qed.
(* stdpp/relations.v *)
(* The following is also known as Newman's lemma *)
Lemma locally_confluent_confluent :
    (∀ x, sn R x) → locally_confluent R → confluent R.
Proof.
    intros Hsn Hcr x. induction (Hsn x) as [x _ IH].
    intros y1 y2 Hy1 Hy2. destruct Hy1 as [x|x y1 y1' Hy1 Hy1']; [by eauto|].
    destruct Hy2 as [x|x y2 y2' Hy2 Hy2']; [by eauto|].
    destruct (Hcr x y1 y2) as (z&Hy1z&Hy2z); auto.
    destruct (IH _ Hy1 y1' z) as (z1&?&?); auto.
    destruct (IH _ Hy2 y2' z1) as (z2&?&?); eauto using rtc_trans.
  Qed.
(* stdpp/relations.v *)
Notation subrel
:= (∀ x y, R1 x y → R2 x y).
(* stdpp/relations.v *)
Lemma red_subrel x : subrel → red R1 x → red R2 x.
Proof. intros ? [y ?]; eauto. Qed.
(* stdpp/relations.v *)
Lemma nf_subrel x : subrel → nf R2 x → nf R1 x.
Proof. intros ? H1 H2; destruct H1; by apply red_subrel. Qed.
(* stdpp/relations.v *)
Lemma rtc_subrel x y : subrel → rtc R1 x y → rtc R2 x y.
Proof. induction 2; [by apply rtc_refl|]. eapply rtc_l; eauto. Qed.
(* stdpp/sets.v *)
(* Higher precedence to make sure these instances are not used for other types
with an [ElemOf] instance, such as lists. *)
Instance set_equiv_instance `{ElemOf A C} : Equiv C | 20
:= λ X Y,
  ∀ x, x ∈ X ↔ x ∈ Y.
(* stdpp/sets.v *)
Instance set_subseteq_instance `{ElemOf A C} : SubsetEq C | 20
:= λ X Y,
  ∀ x, x ∈ X → x ∈ Y.
(* stdpp/sets.v *)
Instance set_disjoint_instance `{ElemOf A C} : Disjoint C | 20
:= λ X Y,
  ∀ x, x ∈ X → x ∈ Y → False.
(* stdpp/sets.v *)
Instance set_equiv_equivalence : Equivalence (≡@{C}).
Proof.
    split.
    - done.
    - intros X Y ? x. by symmetry.
    - intros X Y Z ?? x; by trans (x ∈ Y).
  Qed.
(* stdpp/sets.v *)
Instance singleton_proper : Proper ((=) ==> (≡@{C})) singleton.
Proof. apply _. Qed.
(* stdpp/sets.v *)
Instance elem_of_proper : Proper ((=) ==> (≡) ==> iff) (∈@{C}) | 5.
Proof. by intros x ? <- X Y. Qed.
(* stdpp/sets.v *)
Instance disjoint_proper: Proper ((≡) ==> (≡) ==> iff) (##@{C}).
Proof.
    intros X1 X2 HX Y1 Y2 HY; apply forall_proper; intros x. by rewrite HX, HY.
  Qed.
(* stdpp/sets.v *)
Instance union_proper : Proper ((≡) ==> (≡) ==> (≡@{C})) union.
Proof. intros X1 X2 HX Y1 Y2 HY x. rewrite !elem_of_union. f_equiv; auto. Qed.
(* stdpp/sets.v *)
Instance union_list_proper: Proper ((≡) ==> (≡@{C})) union_list.
Proof. by induction 1; simpl; try apply union_proper. Qed.
(* stdpp/sets.v *)
Instance subseteq_proper : Proper ((≡@{C}) ==> (≡@{C}) ==> iff) (⊆).
Proof.
    intros X1 X2 HX Y1 Y2 HY. apply forall_proper; intros x. by rewrite HX, HY.
  Qed.
(* stdpp/sets.v *)
Instance subset_proper : Proper ((≡@{C}) ==> (≡@{C}) ==> iff) (⊂).
Proof. solve_proper. Qed.
(* stdpp/sets.v *)
(* * Setoids *)
Instance intersection_proper :
    Proper ((≡) ==> (≡) ==> (≡@{C})) intersection.
Proof.
    intros X1 X2 HX Y1 Y2 HY x. by rewrite !elem_of_intersection, HX, HY.
  Qed.
(* stdpp/sets.v *)
Instance difference_proper :
     Proper ((≡) ==> (≡) ==> (≡@{C})) difference.
Proof.
    intros X1 X2 HX Y1 Y2 HY x. by rewrite !elem_of_difference, HX, HY.
  Qed.
(* stdpp/sets.v *)
Instance set_fmap_proper {A B} :
    Proper (pointwise_relation _ (=) ==> (≡) ==> (≡)) (@fmap M _ A B).
Proof.
    intros f1 f2 Hf X1 X2 HX x. rewrite !elem_of_fmap. f_equiv; intros z.
    by rewrite HX, Hf.
  Qed.
(* stdpp/sets.v *)
Instance set_bind_proper {A B} :
    Proper (pointwise_relation _ (≡) ==> (≡) ==> (≡)) (@mbind M _ A B).
Proof.
    intros f1 f2 Hf X1 X2 HX x. rewrite !elem_of_bind. f_equiv; intros z.
    by rewrite HX, (Hf z).
  Qed.
(* stdpp/sets.v *)
Instance set_join_proper {A} :
    Proper ((≡) ==> (≡)) (@mjoin M _ A).
Proof.
    intros X1 X2 HX x. rewrite !elem_of_join. f_equiv; intros z. by rewrite HX.
  Qed.
(* stdpp/sets.v *)
(* The tactic [set_unfold] transforms all occurrences of [(∪)], [(∩)], [(∖)],
[(<$>)], [∅], [{[_]}], [(≡)], and [(⊆)] into logically equivalent propositions
involving just [∈]. For example, [A → x ∈ X ∪ ∅] becomes [A → x ∈ X ∨ False].

This transformation is implemented using type classes instead of setoid
rewriting to ensure that we traverse each term at most once and to be able to
deal with occurrences of the set operations under binders. *)
Class SetUnfold (P Q : Prop)
:= { set_unfold : P ↔ Q }.
(* stdpp/sets.v *)
(* The class [SetUnfoldElemOf] is a more specialized version of [SetUnfold]
for propositions of the shape [x ∈ X] to improve performance. *)
Class SetUnfoldElemOf `{ElemOf A C} (x : A) (X : C) (Q : Prop)
:=
  { set_unfold_elem_of : x ∈ X ↔ Q }.
(* stdpp/sets.v *)
Instance set_unfold_elem_of_default `{ElemOf A C} (x : A) (X : C) :
  SetUnfoldElemOf x X (x ∈ X) | 1000.
Proof. done. Qed.
(* stdpp/sets.v *)
Instance set_unfold_elem_of_set_unfold `{ElemOf A C} (x : A) (X : C) Q :
  SetUnfoldElemOf x X Q → SetUnfold (x ∈ X) Q.
Proof. by destruct 1; constructor. Qed.
(* stdpp/sets.v *)
Class SetUnfoldSimpl (P Q : Prop)
:= { set_unfold_simpl : SetUnfold P Q }.
(* stdpp/sets.v *)
Instance set_unfold_default P : SetUnfold P P | 1000.
done. Qed.
(* stdpp/sets.v *)
Definition set_unfold_1 `{SetUnfold P Q} : P → Q
:= proj1 (set_unfold P Q).
(* stdpp/sets.v *)
Definition set_unfold_2 `{SetUnfold P Q} : Q → P
:= proj2 (set_unfold P Q).
(* stdpp/sets.v *)
Lemma set_unfold_impl P Q P' Q' :
  SetUnfold P P' → SetUnfold Q Q' → SetUnfold (P → Q) (P' → Q').
Proof. constructor. by rewrite (set_unfold P P'), (set_unfold Q Q'). Qed.
(* stdpp/sets.v *)
Lemma set_unfold_and P Q P' Q' :
  SetUnfold P P' → SetUnfold Q Q' → SetUnfold (P ∧ Q) (P' ∧ Q').
Proof. constructor. by rewrite (set_unfold P P'), (set_unfold Q Q'). Qed.
(* stdpp/sets.v *)
Lemma set_unfold_or P Q P' Q' :
  SetUnfold P P' → SetUnfold Q Q' → SetUnfold (P ∨ Q) (P' ∨ Q').
Proof. constructor. by rewrite (set_unfold P P'), (set_unfold Q Q'). Qed.
(* stdpp/sets.v *)
Lemma set_unfold_iff P Q P' Q' :
  SetUnfold P P' → SetUnfold Q Q' → SetUnfold (P ↔ Q) (P' ↔ Q').
Proof. constructor. by rewrite (set_unfold P P'), (set_unfold Q Q'). Qed.
(* stdpp/sets.v *)
Lemma set_unfold_not P P' : SetUnfold P P' → SetUnfold (¬P) (¬P').
Proof. constructor. by rewrite (set_unfold P P'). Qed.
(* stdpp/sets.v *)
Lemma set_unfold_forall {A} (P P' : A → Prop) :
  (∀ x, SetUnfold (P x) (P' x)) → SetUnfold (∀ x, P x) (∀ x, P' x).
Proof. constructor. naive_solver. Qed.
(* stdpp/sets.v *)
Lemma set_unfold_exist {A} (P P' : A → Prop) :
  (∀ x, SetUnfold (P x) (P' x)) → SetUnfold (∃ x, P x) (∃ x, P' x).
Proof. constructor. naive_solver. Qed.
(* stdpp/sets.v *)
Instance set_unfold_empty x : SetUnfoldElemOf x (∅ : C) False.
Proof. constructor. split; [|done]. apply not_elem_of_empty. Qed.
(* stdpp/sets.v *)
Instance set_unfold_singleton x y : SetUnfoldElemOf x ({[ y ]} : C) (x = y).
Proof. constructor; apply elem_of_singleton. Qed.
(* stdpp/sets.v *)
Instance set_unfold_union x X Y P Q :
    SetUnfoldElemOf x X P → SetUnfoldElemOf x Y Q →
    SetUnfoldElemOf x (X ∪ Y) (P ∨ Q).
Proof.
    intros ??; constructor.
    by rewrite elem_of_union,
      (set_unfold_elem_of x X P), (set_unfold_elem_of x Y Q).
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_equiv_same X : SetUnfold (X ≡ X) True | 1.
Proof. done. Qed.
(* stdpp/sets.v *)
Instance set_unfold_equiv_empty_l X (P : A → Prop) :
    (∀ x, SetUnfoldElemOf x X (P x)) → SetUnfold (∅ ≡ X) (∀ x, ¬P x) | 5.
Proof.
    intros ?; constructor. unfold equiv, set_equiv_instance.
    pose proof (not_elem_of_empty (C:=C)); naive_solver.
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_equiv_empty_r (P : A → Prop) X :
    (∀ x, SetUnfoldElemOf x X (P x)) → SetUnfold (X ≡ ∅) (∀ x, ¬P x) | 5.
Proof.
    intros ?; constructor. unfold equiv, set_equiv_instance.
    pose proof (not_elem_of_empty (C:=C)); naive_solver.
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_equiv (P Q : A → Prop) X Y :
    (∀ x, SetUnfoldElemOf x X (P x)) → (∀ x, SetUnfoldElemOf x Y (Q x)) →
    SetUnfold (X ≡ Y) (∀ x, P x ↔ Q x) | 10.
Proof. constructor. apply forall_proper; naive_solver. Qed.
(* stdpp/sets.v *)
Instance set_unfold_subseteq (P Q : A → Prop) X Y :
    (∀ x, SetUnfoldElemOf x X (P x)) → (∀ x, SetUnfoldElemOf x Y (Q x)) →
    SetUnfold (X ⊆ Y) (∀ x, P x → Q x).
Proof. constructor. apply forall_proper; naive_solver. Qed.
(* stdpp/sets.v *)
Instance set_unfold_subset (P Q : A → Prop) X Y :
    (∀ x, SetUnfoldElemOf x X (P x)) → (∀ x, SetUnfoldElemOf x Y (Q x)) →
    SetUnfold (X ⊂ Y) ((∀ x, P x → Q x) ∧ ¬∀ x, Q x → P x).
Proof.
    constructor. unfold strict.
    repeat f_equiv; apply forall_proper; naive_solver.
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_disjoint (P Q : A → Prop) X Y :
    (∀ x, SetUnfoldElemOf x X (P x)) → (∀ x, SetUnfoldElemOf x Y (Q x)) →
    SetUnfold (X ## Y) (∀ x, P x → Q x → False).
Proof. constructor. unfold disjoint, set_disjoint_instance. naive_solver. Qed.
(* stdpp/sets.v *)
Instance set_unfold_equiv_same_L X : SetUnfold (X = X) True | 1.
Proof. done. Qed.
(* stdpp/sets.v *)
Instance set_unfold_equiv_empty_l_L X (P : A → Prop) :
    (∀ x, SetUnfoldElemOf x X (P x)) → SetUnfold (∅ = X) (∀ x, ¬P x) | 5.
Proof. constructor. unfold_leibniz. by apply set_unfold_equiv_empty_l. Qed.
(* stdpp/sets.v *)
Instance set_unfold_equiv_empty_r_L (P : A → Prop) X :
    (∀ x, SetUnfoldElemOf x X (P x)) → SetUnfold (X = ∅) (∀ x, ¬P x) | 5.
Proof. constructor. unfold_leibniz. by apply set_unfold_equiv_empty_r. Qed.
(* stdpp/sets.v *)
Instance set_unfold_equiv_L (P Q : A → Prop) X Y :
    (∀ x, SetUnfoldElemOf x X (P x)) → (∀ x, SetUnfoldElemOf x Y (Q x)) →
    SetUnfold (X = Y) (∀ x, P x ↔ Q x) | 10.
Proof. constructor. unfold_leibniz. by apply set_unfold_equiv. Qed.
(* stdpp/sets.v *)
Instance set_unfold_intersection x X Y P Q :
    SetUnfoldElemOf x X P → SetUnfoldElemOf x Y Q →
    SetUnfoldElemOf x (X ∩ Y) (P ∧ Q).
Proof.
    intros ??; constructor. rewrite elem_of_intersection.
    by rewrite (set_unfold_elem_of x X P), (set_unfold_elem_of x Y Q).
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_difference x X Y P Q :
    SetUnfoldElemOf x X P → SetUnfoldElemOf x Y Q →
    SetUnfoldElemOf x (X ∖ Y) (P ∧ ¬Q).
Proof.
    intros ??; constructor. rewrite elem_of_difference.
    by rewrite (set_unfold_elem_of x X P), (set_unfold_elem_of x Y Q).
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_top `{TopSet A C} (x : A) :
  SetUnfoldElemOf x (⊤ : C) True.
Proof. constructor. split; [done|intros; apply elem_of_top']. Qed.
(* stdpp/sets.v *)
Instance set_unfold_ret {A} (x y : A) :
    SetUnfoldElemOf x (mret (M:=M) y) (x = y).
Proof. constructor; apply elem_of_ret. Qed.
(* stdpp/sets.v *)
Instance set_unfold_bind {A B} (f : A → M B) X (P Q : A → Prop) x :
    (∀ y, SetUnfoldElemOf y X (P y)) → (∀ y, SetUnfoldElemOf x (f y) (Q y)) →
    SetUnfoldElemOf x (X ≫= f) (∃ y, Q y ∧ P y).
Proof. constructor. rewrite elem_of_bind; naive_solver. Qed.
(* stdpp/sets.v *)
Instance set_unfold_fmap {A B} (f : A → B) (X : M A) (P : A → Prop) x :
    (∀ y, SetUnfoldElemOf y X (P y)) →
    SetUnfoldElemOf x (f <$> X) (∃ y, x = f y ∧ P y).
Proof. constructor. rewrite elem_of_fmap; naive_solver. Qed.
(* stdpp/sets.v *)
Instance set_unfold_join {A} (X : M (M A)) (P : M A → Prop) x :
    (∀ Y, SetUnfoldElemOf Y X (P Y)) →
    SetUnfoldElemOf x (mjoin X) (∃ Y, x ∈ Y ∧ P Y).
Proof. constructor. rewrite elem_of_join; naive_solver. Qed.
(* stdpp/sets.v *)
Instance set_unfold_nil x : SetUnfoldElemOf x [] False.
Proof. constructor; apply elem_of_nil. Qed.
(* stdpp/sets.v *)
Instance set_unfold_cons x y l P :
    SetUnfoldElemOf x l P → SetUnfoldElemOf x (y :: l) (x = y ∨ P).
Proof. constructor. by rewrite elem_of_cons, (set_unfold_elem_of x l P). Qed.
(* stdpp/sets.v *)
Instance set_unfold_app x l k P Q :
    SetUnfoldElemOf x l P → SetUnfoldElemOf x k Q →
    SetUnfoldElemOf x (l ++ k) (P ∨ Q).
Proof.
    intros ??; constructor.
    by rewrite elem_of_app, (set_unfold_elem_of x l P), (set_unfold_elem_of x k Q).
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_list_cprod {B} (x : A * B) l (k : list B) P Q :
    SetUnfoldElemOf x.1 l P → SetUnfoldElemOf x.2 k Q →
    SetUnfoldElemOf x (cprod l k) (P ∧ Q).
Proof.
    intros ??; constructor.
    by rewrite list_elem_of_cprod, (set_unfold_elem_of x.1 l P),
      (set_unfold_elem_of x.2 k Q).
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_included l k (P Q : A → Prop) :
    (∀ x, SetUnfoldElemOf x l (P x)) → (∀ x, SetUnfoldElemOf x k (Q x)) →
    SetUnfold (l ⊆ k) (∀ x, P x → Q x).
Proof.
    constructor; unfold subseteq, list_subseteq.
    apply forall_proper; naive_solver.
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_reverse x l P :
    SetUnfoldElemOf x l P → SetUnfoldElemOf x (reverse l) P.
Proof. constructor. by rewrite elem_of_reverse, (set_unfold_elem_of x l P). Qed.
(* stdpp/sets.v *)
Instance set_unfold_list_fmap {B} (f : A → B) l P y :
    (∀ x, SetUnfoldElemOf x l (P x)) →
    SetUnfoldElemOf y (f <$> l) (∃ x, y = f x ∧ P x).
Proof.
    constructor. rewrite list_elem_of_fmap. f_equiv; intros x.
    by rewrite (set_unfold_elem_of x l (P x)).
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_list_omap {B} (f : A → option B) (y : B) l P :
    (∀ x, SetUnfoldElemOf x l (P x)) →
    SetUnfoldElemOf y (omap f l) (∃ x, P x ∧ f x = Some y).
Proof.
    constructor. rewrite list_elem_of_omap. f_equiv; intros x.
    by rewrite (set_unfold_elem_of x l (P x)).
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_list_filter x l P Q `{!∀ x, Decision (P x)} :
    SetUnfoldElemOf x l Q →
    SetUnfoldElemOf x (filter P l) (P x ∧ Q).
Proof.
    constructor. rewrite list_elem_of_filter.
    by rewrite (set_unfold_elem_of x l Q).
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_rotate x l P n:
    SetUnfoldElemOf x l P → SetUnfoldElemOf x (rotate n l) P.
Proof. constructor. by rewrite elem_of_rotate, (set_unfold_elem_of x l P). Qed.
(* stdpp/sets.v *)
Instance set_unfold_replicate x y n :
    SetUnfoldElemOf x (replicate n y) (x = y ∧ n ≠ 0).
Proof. constructor. by rewrite elem_of_replicate. Qed.
(* stdpp/sets.v *)
Instance set_unfold_list_bind {B} (f : A → list B) l P Q y :
    (∀ x, SetUnfoldElemOf x l (P x)) → (∀ x, SetUnfoldElemOf y (f x) (Q x)) →
    SetUnfoldElemOf y (l ≫= f) (∃ x, Q x ∧ P x).
Proof. constructor. rewrite list_elem_of_bind. naive_solver. Qed.
(* stdpp/sets.v *)
Instance set_unfold_list_ret (x y : A) : 
    SetUnfoldElemOf x (@mret list _ _ y) (x = y).
Proof. constructor. by rewrite list_elem_of_ret. Qed.
(* stdpp/sets.v *)
(* No [SetUnfoldElemOf] premise for [x ∈ l], as [l] is existential. *)
Instance set_unfold_list_join (x : A) (ls : list (list A)) P :
    (∀ l, SetUnfoldElemOf l ls (P l)) →
    SetUnfoldElemOf x (mjoin ls) (∃ l, x ∈ l ∧ P l).
Proof.
    constructor. rewrite list_elem_of_join. f_equiv; intros l.
    by rewrite (set_unfold_elem_of l ls (P l)).
  Qed.
(* stdpp/sets.v *)
Instance set_unfold_list_seq (x n m : nat) :
    SetUnfoldElemOf x (seq n m) (n ≤ x < n + m)%nat.
Proof. constructor. by rewrite elem_of_seq. Qed.
(* stdpp/sets.v *)
Instance set_unfold_list_seqZ (x n m : Z) :
    SetUnfoldElemOf x (seqZ n m) (n ≤ x < n + m)%Z.
Proof. constructor. by rewrite elem_of_seqZ. Qed.
(* stdpp/sets.v *)
Instance set_unfold_enum `{Finite A} x :
    SetUnfoldElemOf x (enum A) True.
Proof. constructor. split; [done|intros; apply elem_of_enum]. Qed.
(* stdpp/sets.v *)
(* Equality *)
Lemma set_equiv X Y : X ≡ Y ↔ ∀ x, x ∈ X ↔ x ∈ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma set_equiv_subseteq X Y : X ≡ Y ↔ X ⊆ Y ∧ Y ⊆ X.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Instance singleton_equiv_inj : Inj (=) (≡@{C}) singleton.
Proof. unfold Inj. set_solver. Qed.
(* stdpp/sets.v *)
Instance singleton_inj `{!LeibnizEquiv C} : Inj (=) (=@{C}) singleton.
Proof. unfold Inj. set_solver. Qed.
(* stdpp/sets.v *)
(* Subset relation *)
Instance set_subseteq_antisymm: AntiSymm (≡) (⊆@{C}).
Proof. intros ??. set_solver. Qed.
(* stdpp/sets.v *)
Instance set_subseteq_preorder: PreOrder (⊆@{C}).
Proof. split; [by intros ??|]. intros ???; set_solver. Qed.
(* stdpp/sets.v *)
Lemma subseteq_union X Y : X ⊆ Y ↔ X ∪ Y ≡ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma subseteq_union_1 X Y : X ⊆ Y → X ∪ Y ≡ Y.
Proof. by rewrite subseteq_union. Qed.
(* stdpp/sets.v *)
Lemma subseteq_union_2 X Y : X ∪ Y ≡ Y → X ⊆ Y.
Proof. by rewrite subseteq_union. Qed.
(* stdpp/sets.v *)
Lemma union_subseteq_l X Y : X ⊆ X ∪ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_subseteq_l' X X' Y : X ⊆ X' → X ⊆ X' ∪ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_subseteq_r X Y : Y ⊆ X ∪ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_subseteq_r' X Y Y' : Y ⊆ Y' → Y ⊆ X ∪ Y'.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_least X Y Z : X ⊆ Z → Y ⊆ Z → X ∪ Y ⊆ Z.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma elem_of_subseteq X Y : X ⊆ Y ↔ ∀ x, x ∈ X → x ∈ Y.
Proof. done. Qed.
(* stdpp/sets.v *)
Lemma elem_of_subset X Y : X ⊂ Y ↔ (∀ x, x ∈ X → x ∈ Y) ∧ ¬(∀ x, x ∈ Y → x ∈ X).
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma elem_of_weaken x X Y : x ∈ X → X ⊆ Y → x ∈ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma not_elem_of_weaken x X Y : x ∉ Y → X ⊆ Y → x ∉ X.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
(* Union *)
Lemma union_subseteq X Y Z : X ∪ Y ⊆ Z ↔ X ⊆ Z ∧ Y ⊆ Z.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma not_elem_of_union x X Y : x ∉ X ∪ Y ↔ x ∉ X ∧ x ∉ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma elem_of_union_l x X Y : x ∈ X → x ∈ X ∪ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma elem_of_union_r x X Y : x ∈ Y → x ∈ X ∪ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_mono_l X Y1 Y2 : Y1 ⊆ Y2 → X ∪ Y1 ⊆ X ∪ Y2.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_mono_r X1 X2 Y : X1 ⊆ X2 → X1 ∪ Y ⊆ X2 ∪ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_mono X1 X2 Y1 Y2 : X1 ⊆ X2 → Y1 ⊆ Y2 → X1 ∪ Y1 ⊆ X2 ∪ Y2.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Instance union_idemp : IdemP (≡@{C}) (∪).
Proof. intros X. set_solver. Qed.
(* stdpp/sets.v *)
Instance union_empty_l : LeftId (≡@{C}) ∅ (∪).
Proof. intros X. set_solver. Qed.
(* stdpp/sets.v *)
Instance union_empty_r : RightId (≡@{C}) ∅ (∪).
Proof. intros X. set_solver. Qed.
(* stdpp/sets.v *)
Instance union_comm : Comm (≡@{C}) (∪).
Proof. intros X Y. set_solver. Qed.
(* stdpp/sets.v *)
Instance union_assoc : Assoc (≡@{C}) (∪).
Proof. intros X Y Z. set_solver. Qed.
(* stdpp/sets.v *)
Lemma empty_union X Y : X ∪ Y ≡ ∅ ↔ X ≡ ∅ ∧ Y ≡ ∅.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_cancel_l X Y Z : Z ## X → Z ## Y → Z ∪ X ≡ Z ∪ Y → X ≡ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_cancel_r X Y Z : X ## Z → Y ## Z → X ∪ Z ≡ Y ∪ Z → X ≡ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
(* Empty *)
Lemma empty_subseteq X : ∅ ⊆ X.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma elem_of_equiv_empty X : X ≡ ∅ ↔ ∀ x, x ∉ X.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma elem_of_empty x : x ∈@{C} ∅ ↔ False.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma equiv_empty X : X ⊆ ∅ → X ≡ ∅.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_positive_l X Y : X ∪ Y ≡ ∅ → X ≡ ∅.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma union_positive_l_alt X Y : X ≢ ∅ → X ∪ Y ≢ ∅.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma non_empty_inhabited x X : x ∈ X → X ≢ ∅.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
(* Singleton *)
Lemma elem_of_singleton_1 x y : x ∈@{C} {[y]} → x = y.
Proof. by rewrite elem_of_singleton. Qed.
(* stdpp/sets.v *)
Lemma elem_of_singleton_2 x y : x = y → x ∈@{C} {[y]}.
Proof. by rewrite elem_of_singleton. Qed.
(* stdpp/sets.v *)
Lemma elem_of_subseteq_singleton x X : x ∈ X ↔ {[ x ]} ⊆ X.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma non_empty_singleton x : {[ x ]} ≢@{C} ∅.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma not_elem_of_singleton x y : x ∉@{C} {[ y ]} ↔ x ≠ y.
Proof. by rewrite elem_of_singleton. Qed.
(* stdpp/sets.v *)
Lemma not_elem_of_singleton_1 x y : x ∉@{C} {[ y ]} → x ≠ y.
Proof. apply not_elem_of_singleton. Qed.
(* stdpp/sets.v *)
Lemma not_elem_of_singleton_2 x y : x ≠ y → x ∉@{C} {[ y ]}.
Proof. apply not_elem_of_singleton. Qed.
(* stdpp/sets.v *)
Lemma singleton_subseteq_l x X : {[ x ]} ⊆ X ↔ x ∈ X.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma singleton_subseteq x y : {[ x ]} ⊆@{C} {[ y ]} ↔ x = y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
(* Disjointness *)
Lemma elem_of_disjoint X Y : X ## Y ↔ ∀ x, x ∈ X → x ∈ Y → False.
Proof. done. Qed.
(* stdpp/sets.v *)
Instance disjoint_sym : Symmetric (##@{C}).
Proof. intros X Y. set_solver. Qed.
(* stdpp/sets.v *)
Lemma disjoint_empty_l Y : ∅ ## Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma disjoint_empty_r X : X ## ∅.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma disjoint_singleton_l x Y : {[ x ]} ## Y ↔ x ∉ Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma disjoint_singleton_r y X : X ## {[ y ]} ↔ y ∉ X.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma disjoint_union_l X1 X2 Y : X1 ∪ X2 ## Y ↔ X1 ## Y ∧ X2 ## Y.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma disjoint_union_r X Y1 Y2 : X ## Y1 ∪ Y2 ↔ X ## Y1 ∧ X ## Y2.
Proof. set_solver. Qed.
(* stdpp/sets.v *)
Lemma disjoint_top_l `{!Top C, !TopSet A C} X : ⊤ ## X ↔ X ≡ ∅.
Proof.
    split; [|intros ->; apply disjoint_empty_r].
    intros Hdisj. apply elem_of_equiv_empty; intros x Hx.
    eapply Hdisj, Hx. by apply elem_of_top'.
  Qed.
(* stdpp/sets.v *)
Lemma disjoint_top_r `{!Top C, !TopSet A C} X : X ## ⊤ ↔ X ≡ ∅.
Proof. rewrite (symmetry_iff disjoint). apply disjoint_top_l. Qed.
(* stdpp/sets.v *)
(* Big unions *)
Lemma elem_of_union_list Xs x : x ∈ ⋃ Xs ↔ ∃ X, X ∈ Xs ∧ x ∈ X.
Proof.
    split.
    - induction Xs; simpl; intros HXs; [by apply elem_of_empty in HXs|].
      setoid_rewrite elem_of_cons. apply elem_of_union in HXs. naive_solver.
    - intros [X [Hx]]. induction Hx; simpl; [by apply elem_of_union_l |].
      intros. apply elem_of_union_r; auto.
  Qed.
(* stdpp/sets.v *)
Lemma union_list_nil : ⋃ @nil C = ∅.
Proof. done. Qed.
(* stdpp/sets.v *)
Lemma union_list_cons X Xs : ⋃ (X :: Xs) = X ∪ ⋃ Xs.
Proof. done. Qed.
(* stdpp/sets.v *)
Lemma union_list_singleton X : ⋃ [X] ≡ X.
Proof. simpl. by rewrite (right_id ∅ _). Qed.
(* stdpp/sets.v *)
Lemma union_list_app Xs1 Xs2 : ⋃ (Xs1 ++ Xs2) ≡ ⋃ Xs1 ∪ ⋃ Xs2.
Proof.
    induction Xs1 as [|X Xs1 IH]; simpl; [by rewrite (left_id ∅ _)|].
    by rewrite IH, (assoc _).
  Qed.
(* stdpp/sets.v *)
Lemma union_list_reverse Xs : ⋃ (reverse Xs) ≡ ⋃ Xs.
Proof.
    induction Xs as [|X Xs IH]; simpl; [done |].
    by rewrite reverse_cons, union_list_app,
      union_list_singleton, (comm _), IH.
  Qed.
(* stdpp/sets.v *)
Lemma union_list_mono Xs Ys : Xs ⊆* Ys → ⋃ Xs ⊆ ⋃ Ys.
Proof. induction 1; simpl; auto using union_mono. Qed.
(* stdpp/sets.v *)
Lemma empty_union_list Xs : ⋃ Xs ≡ ∅ ↔ Forall (.≡ ∅) Xs.
Proof.
    split.
    - induction Xs; simpl; rewrite ?empty_union; intuition.
    - induction 1 as [|?? E1 ? E2]; simpl; [done|]. by apply empty_union.
  Qed.
(* stdpp/sets.v *)
Instance union_list_permutation_proper :
    Proper ((≡ₚ) ==> (≡)) (union_list (A:=C)).
Proof. apply (foldr_permutation_proper' _); apply _. Qed.
(* stdpp/sets.v *)
Lemma set_eq X Y : X = Y ↔ ∀ x, x ∈ X ↔ x ∈ Y.
Proof. unfold_leibniz. apply set_equiv. Qed.
(* stdpp/sets.v *)
Lemma set_eq_subseteq X Y : X = Y ↔ X ⊆ Y ∧ Y ⊆ X.
Proof. unfold_leibniz. apply set_equiv_subseteq. Qed.
(* stdpp/sets.v *)
(* Subset relation *)
Instance set_subseteq_partialorder : PartialOrder (⊆@{C}).
Proof. split; [apply _|]. intros ??. unfold_leibniz. apply (anti_symm _). Qed.
(* stdpp/sets.v *)
Lemma subseteq_union_L X Y : X ⊆ Y ↔ X ∪ Y = Y.
Proof. unfold_leibniz. apply subseteq_union. Qed.
(* stdpp/sets.v *)
Lemma subseteq_union_1_L X Y : X ⊆ Y → X ∪ Y = Y.
Proof. unfold_leibniz. apply subseteq_union_1. Qed.