Library UniMath.MoreFoundations.Subtypes
Require Export UniMath.MoreFoundations.Notations.
Require Export UniMath.MoreFoundations.Propositions.
Declare Scope subtype.
Delimit Scope subtype with subtype.
Local Open Scope subtype.
Local Open Scope logic.
Local Open Scope type.
Require Export UniMath.MoreFoundations.Propositions.
Declare Scope subtype.
Delimit Scope subtype with subtype.
Local Open Scope subtype.
Local Open Scope logic.
Local Open Scope type.
The powerset, or set of all subsets, of a set.
Definition subtype_set X : hSet := make_hSet (hsubtype X) (isasethsubtype X).
Definition subtype_isIn {X:UU} {S:hsubtype X} (s:S) (T:hsubtype X) : hProp := T (pr1 s).
Notation " s ∈ T " := (subtype_isIn s T) (at level 70) : subtype.
Notation " s ∉ T " := (¬ (subtype_isIn s T) : hProp) (at level 70) : subtype.
Definition subtype_containedIn {X:UU} : hrel (subtype_set X) := λ S T, ∀ x:X, S x ⇒ T x.
Notation " S ⊆ T " := (subtype_containedIn S T) (at level 70) : subtype.
Definition subtype_notContainedIn {X:UU} (S T : hsubtype X) : hProp := ∃ x:X, S x ∧ ¬ (T x).
Definition subtype_inc {X:UU} {S T : hsubtype X} : S ⊆ T -> S -> T.
Proof.
intros le s. exact (pr1 s,, le (pr1 s) (pr2 s)).
Definition subtype_isIn {X:UU} {S:hsubtype X} (s:S) (T:hsubtype X) : hProp := T (pr1 s).
Notation " s ∈ T " := (subtype_isIn s T) (at level 70) : subtype.
Notation " s ∉ T " := (¬ (subtype_isIn s T) : hProp) (at level 70) : subtype.
Definition subtype_containedIn {X:UU} : hrel (subtype_set X) := λ S T, ∀ x:X, S x ⇒ T x.
Notation " S ⊆ T " := (subtype_containedIn S T) (at level 70) : subtype.
Definition subtype_notContainedIn {X:UU} (S T : hsubtype X) : hProp := ∃ x:X, S x ∧ ¬ (T x).
Definition subtype_inc {X:UU} {S T : hsubtype X} : S ⊆ T -> S -> T.
Proof.
intros le s. exact (pr1 s,, le (pr1 s) (pr2 s)).
Notation " S ⊈ T " := (subtype_notContainedIn S T) (at level 70) : subtype.
Definition subtype_smallerThan {X:UU} (S T : hsubtype X) : hProp := (S ⊆ T) ∧ (T ⊈ S).
Notation " S ⊊ T " := (subtype_smallerThan S T) (at level 70) : subtype.
Definition subtype_equal {X:UU} (S T : hsubtype X) : hProp := ∀ x, S x ⇔ T x.
Notation " S ≡ T " := (subtype_equal S T) (at level 70) : subtype.
Definition subtype_notEqual {X:UU} (S T : hsubtype X) : hProp := (S ⊈ T) ∨ (T ⊈ S).
Notation " S ≢ T " := (subtype_notEqual S T) (at level 70) : subtype.
Lemma subtype_notEqual_containedIn {X:UU} (S T : hsubtype X) : S ⊆ T -> S ≢ T -> T ⊈ S.
Show proof.
intros ci ne. apply (squash_to_hProp ne); clear ne; intros [n|n].
- apply (squash_to_hProp n); clear n; intros [x [p q]]. apply fromempty.
change (neg (T x)) in q. apply q; clear q. apply (ci x). exact p.
- exact n.
- apply (squash_to_hProp n); clear n; intros [x [p q]]. apply fromempty.
change (neg (T x)) in q. apply q; clear q. apply (ci x). exact p.
- exact n.
Lemma subtype_notEqual_to_negEqual {X:UU} (S T : hsubtype X) : S ≢ T -> ¬ (S ≡ T).
Show proof.
intros n. apply (squash_to_prop n).
+ apply isapropneg. + intros [c|c].
* apply (squash_to_prop c).
** apply isapropneg. ** intros [x [Sx nTx]] e. use nTx; clear nTx. exact (pr1 (e x) Sx).
* apply (squash_to_prop c).
** apply isapropneg. ** intros [x [Tx nSx]] e. use nSx; clear nSx. exact (pr2 (e x) Tx).
+ apply isapropneg. + intros [c|c].
* apply (squash_to_prop c).
** apply isapropneg. ** intros [x [Sx nTx]] e. use nTx; clear nTx. exact (pr1 (e x) Sx).
* apply (squash_to_prop c).
** apply isapropneg. ** intros [x [Tx nSx]] e. use nSx; clear nSx. exact (pr2 (e x) Tx).
Lemma subtype_notEqual_from_negEqual {X:UU} (S T : hsubtype X) : LEM -> (S ≢ T <- ¬ (S ≡ T)).
Show proof.
intros lem ne. unfold subtype_equal in ne.
assert (q := negforall_to_existsneg _ lem ne); clear ne.
apply (squash_to_hProp q); clear q; intros [x n].
unfold subtype_notEqual.
assert (r := weak_fromnegdirprod _ _ n); clear n. unfold dneg in r.
assert (s := proof_by_contradiction lem r); clear r.
apply (squash_to_hProp s); clear s. intros s. apply hinhpr. induction s as [s|s].
+ apply ii1, hinhpr. exists x. now apply negimpl_to_conj.
+ apply ii2, hinhpr. exists x. now apply negimpl_to_conj.
assert (q := negforall_to_existsneg _ lem ne); clear ne.
apply (squash_to_hProp q); clear q; intros [x n].
unfold subtype_notEqual.
assert (r := weak_fromnegdirprod _ _ n); clear n. unfold dneg in r.
assert (s := proof_by_contradiction lem r); clear r.
apply (squash_to_hProp s); clear s. intros s. apply hinhpr. induction s as [s|s].
+ apply ii1, hinhpr. exists x. now apply negimpl_to_conj.
+ apply ii2, hinhpr. exists x. now apply negimpl_to_conj.
Definition emptysubtype (X : UU) : hsubtype X
:= λ x, hfalse.
Definition subtype_difference {X:UU} (S T : hsubtype X) : hsubtype X := λ x, S x ∧ ¬ (T x).
Notation " S - T " := (subtype_difference S T) : subtype.
Definition subtype_difference_containedIn {X:UU} (S T : hsubtype X) : (S - T) ⊆ S.
Show proof.
Lemma subtype_equal_cond {X:UU} (S T : hsubtype X) : S ⊆ T ∧ T ⊆ S ⇔ S ≡ T.
Show proof.
split.
- intros c x. induction c as [st ts].
split.
+ intro s. exact (st x s).
+ intro t. exact (ts x t).
- intro e. split.
+ intros x s. exact (pr1 (e x) s).
+ intros x t. exact (pr2 (e x) t).
- intros c x. induction c as [st ts].
split.
+ intro s. exact (st x s).
+ intro t. exact (ts x t).
- intro e. split.
+ intros x s. exact (pr1 (e x) s).
+ intros x t. exact (pr2 (e x) t).
Definition subtype_union {X I:UU} (S : I -> hsubtype X) : hsubtype X := λ x, ∃ i, S i x.
Notation "⋃ S" := (subtype_union S) (at level 100, no associativity) : subtype.
Definition subtype_binaryunion {X} (A B : hsubtype X) : hsubtype X
:= fun x => A x ∨ B x.
Notation "A ∪ B" := (subtype_binaryunion A B)
(at level 40, left associativity) : subtype.
Definition subtype_binaryunion_leq1 {X} (A B : hsubtype X) : A ⊆ (A ∪ B)
:= fun x => hdisj_in1.
Definition subtype_binaryunion_leq2 {X} (A B : hsubtype X) : B ⊆ (A ∪ B)
:= fun x => hdisj_in2.
Definition subtype_union_containedIn {X:hSet} {I:UU} (S : I -> hsubtype X) i : S i ⊆ ⋃ S
:= λ x s, hinhpr (i,,s).