Newer
Older
Robbert Krebbers
committed
Global Instance set_infinite_subseteq :
Proper ((⊆) ==> impl) (@set_infinite A C _).
Proof. intros X Y HX ?. eapply pred_infinite_impl; set_solver. Qed.
Global Instance set_infinite_proper : Proper ((≡) ==> iff) (@set_infinite A C _).
Proof. intros X Y HX; apply forall_proper. by setoid_rewrite HX. Qed.
Lemma union_infinite_l X Y : set_infinite X → set_infinite (X ∪ Y).
Proof. intros Hinf xs. destruct (Hinf xs). set_solver. Qed.
Lemma union_infinite_r X Y : set_infinite Y → set_infinite (X ∪ Y).
Proof. intros Hinf xs. destruct (Hinf xs). set_solver. Qed.
End set_finite_infinite.
Implicit Types X Y : C.
Lemma intersection_finite_l X Y : set_finite X → set_finite (X ∩ Y).
Proof. intros [l ?]; exists l; intros x [??]%elem_of_intersection; auto. Qed.
Lemma intersection_finite_r X Y : set_finite Y → set_finite (X ∩ Y).
Proof. intros [l ?]; exists l; intros x [??]%elem_of_intersection; auto. Qed.
Lemma difference_finite X Y : set_finite X → set_finite (X ∖ Y).
Proof. intros [l ?]; exists l; intros x [??]%elem_of_difference; auto. Qed.
Lemma difference_finite_inv X Y `{∀ x, Decision (x ∈ Y)} :
set_finite Y → set_finite (X ∖ Y) → set_finite X.
Proof.
intros [l ?] [k ?]; exists (l ++ k).
intros x ?; destruct (decide (x ∈ Y)); rewrite elem_of_app; set_solver.
Robbert Krebbers
committed
Lemma difference_infinite X Y :
set_infinite X → set_finite Y → set_infinite (X ∖ Y).
Proof. intros Hinf [xs ?] xs'. destruct (Hinf (xs ++ xs')). set_solver. Qed.
(** Sets of sequences of natural numbers *)
(* The set [seq_seq start len] of natural numbers contains the sequence
[start, start + 1, ..., start + (len-1)]. *)
Fixpoint set_seq `{Singleton nat C, Union C, Empty C} (start len : nat) : C :=
| S len' => {[ start ]} ∪ set_seq (S start) len'
Section set_seq.
Context `{SemiSet nat C}.
Implicit Types start len x : nat.
Lemma elem_of_set_seq start len x :
x ∈ set_seq (C:=C) start len ↔ start ≤ x < start + len.
Proof.
revert start. induction len as [|len IH]; intros start; simpl.
- rewrite elem_of_empty. lia.
- rewrite elem_of_union, elem_of_singleton, IH. lia.
Global Instance set_unfold_seq start len :
Robbert Krebbers
committed
SetUnfoldElemOf x (set_seq (C:=C) start len) (start ≤ x < start + len).
Proof. constructor; apply elem_of_set_seq. Qed.
Lemma set_seq_plus_disjoint start len1 len2 :
set_seq (C:=C) start len1 ## set_seq (start + len1) len2.
Lemma set_seq_plus start len1 len2 :
set_seq (C:=C) start (len1 + len2)
≡ set_seq start len1 ∪ set_seq (start + len1) len2.
Lemma set_seq_plus_L `{!LeibnizEquiv C} start len1 len2 :
set_seq (C:=C) start (len1 + len2)
= set_seq start len1 ∪ set_seq (start + len1) len2.
Proof. unfold_leibniz. apply set_seq_plus. Qed.
Lemma set_seq_S_start_disjoint start len :
{[ start ]} ## set_seq (C:=C) (S start) len.
Lemma set_seq_S_start start len :
set_seq (C:=C) start (S len) ≡ {[ start ]} ∪ set_seq (S start) len.
Lemma set_seq_S_end_disjoint start len :
{[ start + len ]} ## set_seq (C:=C) start len.
Lemma set_seq_S_end_union start len :
set_seq start (S len) ≡@{C} {[ start + len ]} ∪ set_seq start len.
Lemma set_seq_S_end_union_L `{!LeibnizEquiv C} start len :
set_seq start (S len) =@{C} {[ start + len ]} ∪ set_seq start len.
Proof. unfold_leibniz. apply set_seq_S_end_union. Qed.
Lemma list_to_set_seq start len :
list_to_set (seq start len) =@{C} set_seq start len.
Proof. revert start; induction len; intros; f_equal/=; auto. Qed.
Lemma set_seq_finite start len : set_finite (set_seq (C:=C) start len).
Proof.
exists (seq start len); intros x. rewrite <-list_to_set_seq. set_solver.
Qed.
(** Mimimal elements *)
Definition minimal `{ElemOf A C} (R : relation A) (x : A) (X : C) : Prop :=
Robbert Krebbers
committed
∀ y, y ∈ X → R y x → R x y.
Context `{SemiSet A C} {R : relation A}.
Robbert Krebbers
committed
Global Instance minimal_proper x : Proper ((≡@{C}) ==> iff) (minimal R x).
Proof. intros X X' y; unfold minimal; set_solver. Qed.
Robbert Krebbers
committed
Lemma minimal_anti_symm_1 `{!AntiSymm (=) R} X x y :
minimal R x X → y ∈ X → R y x → x = y.
Proof. intros Hmin ??. apply (anti_symm _); auto. Qed.
Lemma minimal_anti_symm `{!AntiSymm (=) R} X x :
Robbert Krebbers
committed
minimal R x X ↔ ∀ y, y ∈ X → R y x → x = y.
Proof. unfold minimal; naive_solver eauto using minimal_anti_symm_1. Qed.
Lemma minimal_strict_1 `{!StrictOrder R} X x y :
minimal R x X → y ∈ X → ¬R y x.
Proof. intros Hmin ??. destruct (irreflexivity R x); trans y; auto. Qed.
Lemma minimal_strict `{!StrictOrder R} X x :
Robbert Krebbers
committed
minimal R x X ↔ ∀ y, y ∈ X → ¬R y x.
Proof. unfold minimal; split; [eauto using minimal_strict_1|naive_solver]. Qed.
Robbert Krebbers
committed
Lemma empty_minimal x : minimal R x (∅ : C).
Lemma singleton_minimal x : minimal R x ({[ x ]} : C).
Lemma singleton_minimal_not_above y x : ¬R y x → minimal R x ({[ y ]} : C).
Proof. unfold minimal; set_solver. Qed.
Lemma union_minimal X Y x :
minimal R x X → minimal R x Y → minimal R x (X ∪ Y).
Proof. unfold minimal; set_solver. Qed.
Lemma minimal_subseteq X Y x : minimal R x X → Y ⊆ X → minimal R x Y.
Proof. unfold minimal; set_solver. Qed.
Robbert Krebbers
committed
Lemma minimal_weaken `{!Transitive R} X x x' :
minimal R x X → R x' x → minimal R x' X.
Proof.
intros Hmin ? y ??. trans x; [done|]. by eapply (Hmin y), transitivity.