{-# OPTIONS --without-K #-}
open import elementary-number-theory.natural-numbers
open import foundation.action-on-identifications-functions
open import foundation.booleans
open import foundation.cartesian-product-types
open import foundation.coproduct-types
open import foundation.dependent-pair-types
open import foundation.embeddings
open import foundation.empty-types
open import foundation.equality-cartesian-product-types
open import foundation.equality-coproduct-types
open import foundation.equivalences
open import foundation.equivalence-extensionality
open import foundation.existential-quantification
open import foundation.function-types
open import foundation.function-extensionality
open import foundation.functoriality-cartesian-product-types
open import foundation.functoriality-coproduct-types
open import foundation.functoriality-dependent-function-types
open import foundation.functoriality-dependent-pair-types
open import foundation.functoriality-truncation
open import foundation.identity-types
open import foundation.negation
open import foundation.propositional-truncations
open import foundation.propositions
open import foundation.raising-universe-levels
open import foundation.sets
open import foundation.transport-along-identifications
open import foundation.truncated-types
open import foundation.truncations
open import foundation.truncation-levels
renaming (truncation-level-minus-one-â to minus-one;
truncation-level-minus-two-â to minus-two;
truncation-level-â to to-đ)
open import foundation.type-arithmetic-booleans
open import foundation.type-arithmetic-cartesian-product-types
open import foundation.type-arithmetic-empty-type
open import foundation.type-arithmetic-unit-type
open import foundation.type-theoretic-principle-of-choice
open import foundation.unit-type
open import foundation.universe-levels
open import order-theory.accessible-elements-relations
open import order-theory.well-founded-orders
open import e-structure.core
open import notation as N
module e-structure.property.unordered-tupling
{i j} (((M , _â_) , p) : â-structure i j) where
[_]-UnorderedTupling : â â {k : Level} â UU k â UU (i â (j â k))
[ n ]-UnorderedTupling I = (v : I â M)
â ÎŖ M Îģ īŊvīŊ â (z : M) â (z â īŊvīŊ) â type-trunc (minus-one n ) (ÎŖ I Îģ i â v i == z)
0-UnorderedTupling : â {k} â UU k â UU (i â (j â k))
0-UnorderedTupling = [ zero-â ]-UnorderedTupling
â-UnorderedTupling : â {k} â UU k â UU (i â (j â k))
â-UnorderedTupling I = (v : I â M)
â ÎŖ M Îģ [v] â (z : M) â (z â [v]) â ÎŖ I Îģ i â v i == z
open e-structure.core.extensionality ((M , _â_) , p)
open e-structure.core.mere-sets ((M , _â_) , p)
EmptySet : UU (i â j)
EmptySet = ÎŖ M (Îģ â
â (x : M) â (x â â
) â empty)
module empty-set where
module notation (empty-set : EmptySet) where
â
: M
â
= pr1 empty-set
module properties (empty-set : EmptySet) where
open notation empty-set
mere-set-empty-set : mere-set â
mere-set-empty-set x = is-prop-equiv (pr2 empty-set x) is-prop-empty
accessible-empty-set : is-accessible-element-Relation _â_ â
accessible-empty-set = access (Îģ {y} yââ
â ex-falso (map-equiv (pr2 empty-set y) yââ
))
0-Singletons : UU (i â j)
0-Singletons = (x : M) â
ÎŖ M Îģ īŊxīŊ â (z : M) â (z â īŊxīŊ) â type-trunc-Prop (x == z)
module 0-singletons where
module notation (0-singletons : 0-Singletons) where
īŊ_īŊ : M â M
īŊ x īŊ = pr1 (0-singletons x)
[_]-Singletons : â â UU (i â j)
[ n ]-Singletons = (x : M) â
ÎŖ M Îģ īŊxīŊ â (z : M) â (z â īŊxīŊ) â type-trunc (minus-one n) (x == z)
module singletons where
module notation {n : â} (singletons : [ n ]-Singletons) where
īŊ_īŊ : M â M
īŊ x īŊ = pr1 (singletons x)
â-Singletons : UU (i â j)
â-Singletons = (x : M) â
ÎŖ M Îģ [x] â (z : M) â (z â [x]) â (x == z)
module â-singletons where
module notation (â-singletons : â-Singletons) where
[_] : M â M
[ x ] = pr1 (â-singletons x)
UnorderedPairs' : UU (i â j)
UnorderedPairs' = (x y : M) â
ÎŖ M Îģ [x,y] â ÂŦ (x == y) â (z : M) â (z â [x,y]) â ((x == z) + (y == z))
module unordered-pairs' where
module notation (unordered-pairs' : UnorderedPairs') where
[_,,_]' : M â M â M
[ x ,, y ]' = pr1 (unordered-pairs' x y)
[_]-UnorderedPairs : â â UU (i â j)
[ n ]-UnorderedPairs = (x y : M) â
ÎŖ M (Îģ īŊx,yīŊ â (z : M) â (z â īŊx,yīŊ) â type-trunc (minus-one n) ((x == z) + (y == z)))
module unordered-pairs where
module notation {n : â} (unordered-pairs : [ n ]-UnorderedPairs) where
īŊ_,,_īŊ : M â M â M
īŊ x ,, y īŊ = pr1 (unordered-pairs x y)
â-UnorderedPairs : UU (i â j)
â-UnorderedPairs = (x y : M) â
ÎŖ M (Îģ [x,y] â (z : M) â (z â [x,y]) â ((x == z) + (y == z)))
module â-unordered-pairs where
module notation (â-unordered-pairs : â-UnorderedPairs) where
[_,,_] : M â M â M
[ x ,, y ] = pr1 (â-unordered-pairs x y)
equiv-coprod-equiv-pair-eq : {x x' y y' : M}
â ÂŦ (x == y')
â ÂŦ (x' == y)
â ((z : M) â ((x == z) + (y == z)) â ((x' == z) + (y' == z)))
â ((x == x') Ã (y == y'))
equiv-coprod-equiv-pair-eq {x} {x'} {y} {y'} xâ y' x'â y =
equivalence-reasoning
((z : M) â ((x == z) + (y == z)) â ((x' == z) + (y' == z)))
â ((z : M) â ((x == z) â (x' == z)) Ã ((y == z) â (y' == z))) by equiv-Î -equiv-family (Îģ z â
equiv-mutually-exclusive-coprod
(Îģ x=z y'=z â xâ y' (x=z â inv y'=z))
(Îģ x'=z y=z â x'â y (x'=z â inv y=z)))
â ((z : M) â (x == z) â (x' == z)) Ã
((z : M) â (y == z) â (y' == z)) by distributive-Î -ÎŖ
â (x == x') Ã (y == y') by equiv-prod
(equiv-inv x' x âe equiv-concat-equiv)
(equiv-inv y' y âe equiv-concat-equiv)
module unordered-pair'-eq
(unordered-pairs' : UnorderedPairs') where
open unordered-pairs'.notation unordered-pairs'
equiv-unordered-pair-eq : {x x' y y' : M}
â ÂŦ (x == y)
â ÂŦ (x' == y')
â ÂŦ (x == y')
â ÂŦ (x' == y)
â ([ x ,, y ]' == [ x' ,, y' ]')
â ((x == x') Ã (y == y'))
equiv-unordered-pair-eq {x} {x'} {y} {y'} xâ y x'â y' xâ y' x'â y =
equivalence-reasoning
[ x ,, y ]' == [ x' ,, y' ]'
â ((z : M) â (z â [ x ,, y ]') â (z â [ x' ,, y' ]')) by equiv-extensionality
â ((z : M) â ((x == z) + (y == z)) â ((x' == z) + (y' == z))) by equiv-Î -equiv-family (Îģ z â
equiv-postcomp-equiv
(pr2 (unordered-pairs' x' y') x'â y' z)
_ âe
equiv-precomp-equiv
(inv-equiv (pr2 (unordered-pairs' x y) xâ y z))
_)
â (x == x') Ã (y == y') by equiv-coprod-equiv-pair-eq xâ y' x'â y
compute-equiv-unordered-pair-eq : {x y : M}
â (xâ y : ÂŦ (x == y))
â map-equiv (equiv-unordered-pair-eq xâ y xâ y xâ y xâ y) refl
== (refl , refl)
compute-equiv-unordered-pair-eq {x} {y} xâ y =
ap (map-equiv
(equiv-coprod-equiv-pair-eq xâ y xâ y))
(eq-htpy (Îģ z â
eq-htpy-equiv
{e = pr2 (unordered-pairs' x y) xâ y z âe inv-equiv (pr2 (unordered-pairs' x y) xâ y z)}
{e' = id-equiv}
(is-section-map-inv-equiv
(pr2 (unordered-pairs' x y) xâ y z))))
module emb-singleton
(â-singletons : â-Singletons) where
open â-singletons.notation â-singletons
equiv-singleton-eq : (x x' : M)
â ([ x ] == [ x' ])
â (x == x')
equiv-singleton-eq x x' =
equivalence-reasoning
[ x ] == [ x' ]
â ((y : M) â (y â [ x ]) â (y â [ x' ])) by equiv-extensionality
â ((y : M) â (x == y) â (x' == y)) by equiv-Î -equiv-family (Îģ y â
equiv-postcomp-equiv (pr2 (â-singletons x') y) _ âe
equiv-precomp-equiv (inv-equiv (pr2 (â-singletons x) y)) _)
â x' == x by equiv-concat-equiv
â x == x' by equiv-inv x' x
compute-equiv-singleton-eq : (x : M)
â map-equiv (equiv-singleton-eq x x) refl
== refl
compute-equiv-singleton-eq x =
ap (inv â map-equiv equiv-concat-equiv)
(eq-htpy Îģ y â
eq-htpy-equiv
{e = pr2 (â-singletons x) y âe inv-equiv (pr2 (â-singletons x) y)}
{e' = id-equiv}
(is-section-map-inv-equiv (pr2 (â-singletons x) y)))
is-emb-singleton : is-emb [_]
is-emb-singleton =
is-emb-equiv-refl-to-refl
[_]
equiv-singleton-eq
compute-equiv-singleton-eq
emb-singleton : M âĒ M
pr1 emb-singleton = [_]
pr2 emb-singleton = is-emb-singleton
module emb-unordered-pair-singleton-empty
(empty-set : EmptySet)
(â-singletons : â-Singletons)
(unordered-pairs' : UnorderedPairs') where
open empty-set.properties empty-set
open empty-set.notation empty-set
open â-singletons.notation â-singletons
open unordered-pairs'.notation unordered-pairs'
open unordered-pair'-eq unordered-pairs'
open emb-singleton â-singletons
[_]â â
: (x : M) â ÂŦ ([ x ] == â
)
[ x ]â â
[x]=â
=
map-equiv
(pr2 empty-set x)
(tr (x â_) [x]=â
(map-inv-equiv (pr2 (â-singletons x) x) refl))
equiv-unordered-pair-singleton-empty-eq : (x x' : M)
â ([ [ x ] ,, â
]' == [ [ x' ] ,, â
]')
â (x == x')
equiv-unordered-pair-singleton-empty-eq x x' =
equivalence-reasoning
[ [ x ] ,, â
]' == [ [ x' ] ,, â
]'
â ([ x ] == [ x' ]) Ã (â
== â
) by equiv-unordered-pair-eq [ x ]â â
[ x' ]â â
[ x ]â â
[ x' ]â â
â ([ x ] == [ x' ]) by right-unit-law-prod-is-contr
(is-proof-irrelevant-is-prop
(is-prop-eq-mere-set
mere-set-empty-set)
refl)
â x == x' by inv-equiv (equiv-ap-emb emb-singleton)
compute-equiv-unordered-pair-singleton-empty-eq : (x : M)
â map-equiv (equiv-unordered-pair-singleton-empty-eq x x) refl
== refl
compute-equiv-unordered-pair-singleton-empty-eq x =
equational-reasoning
map-equiv (equiv-unordered-pair-singleton-empty-eq x x) refl
īŧ map-inv-equiv (equiv-ap-emb emb-singleton) refl by ap (map-inv-equiv (equiv-ap-emb emb-singleton) â pr1)
(compute-equiv-unordered-pair-eq [ x ]â â
)
īŧ refl by is-retraction-map-inv-equiv
(equiv-ap-emb emb-singleton)
refl
is-emb-unordered-pair-singleton-empty : is-emb (Îģ x â [ [ x ] ,, â
]')
is-emb-unordered-pair-singleton-empty =
is-emb-equiv-refl-to-refl
(Îģ x â [ [ x ] ,, â
]')
equiv-unordered-pair-singleton-empty-eq
compute-equiv-unordered-pair-singleton-empty-eq
emb-unordered-pair-singleton-empty : M âĒ M
pr1 emb-unordered-pair-singleton-empty = (Îģ x â [ [ x ] ,, â
]')
pr2 emb-unordered-pair-singleton-empty = is-emb-unordered-pair-singleton-empty
[[_],,â
]â [[_]] : (x y : M) â ÂŦ ([ [ x ] ,, â
]' == [ [ y ] ])
[[ x ],,â
]â [[ y ]] [[x],,â
]=[[y]] = [ y ]â â
[y]=â
where
â
â[[y]] : â
â [ [ y ] ]
â
â[[y]] =
tr (â
â_) [[x],,â
]=[[y]]
(map-inv-equiv
(pr2 (unordered-pairs' [ x ] â
) [ x ]â â
â
)
(inr refl))
[y]=â
: [ y ] == â
[y]=â
= map-equiv (pr2 (â-singletons [ y ]) â
) â
â[[y]]
module ordered-pairs where
open e-structure.core.ordered-pairing-structure M
module from-distinct-embeddings
(f : M âĒ M) (g : M âĒ M)
(fâ g : (x y : M) â ÂŦ (f ⊠x âĒ == g ⊠y âĒ))
(unordered-pairs' : UnorderedPairs') where
open unordered-pair'-eq unordered-pairs'
ordered-pair : M â M â M
ordered-pair x y = pr1 (unordered-pairs' (f ⊠x âĒ) (g ⊠y âĒ))
equiv-ordered-pair-eq : (x x' y y' : M)
â (ordered-pair x y == ordered-pair x' y')
â ((x , y) == (x' , y'))
equiv-ordered-pair-eq x x' y y' =
equivalence-reasoning
ordered-pair x y == ordered-pair x' y'
â (f ⊠x âĒ == f ⊠x' âĒ) à (g ⊠y âĒ == g ⊠y' âĒ) by equiv-unordered-pair-eq
(fâ g x y)
(fâ g x' y')
(fâ g x y')
(fâ g x' y)
â (x == x') Ã (y == y') by equiv-prod
(inv-equiv (equiv-ap-emb f))
(inv-equiv (equiv-ap-emb g))
â (x , y) == (x' , y') by equiv-eq-pair (x , y) (x' , y')
compute-equiv-ordered-pair-eq : (x y : M)
â map-equiv (equiv-ordered-pair-eq x x y y) refl
== refl
compute-equiv-ordered-pair-eq x y =
equational-reasoning
map-equiv (equiv-ordered-pair-eq x x y y) refl
īŧ eq-pair'
(map-inv-equiv (equiv-ap-emb f) refl ,
map-inv-equiv (equiv-ap-emb g) refl) by ap (map-equiv
(equiv-eq-pair (x , y) (x , y) âe
equiv-prod
(inv-equiv (equiv-ap-emb f))
(inv-equiv (equiv-ap-emb g))))
(compute-equiv-unordered-pair-eq (fâ g x y))
īŧ refl by ap eq-pair'
(eq-pair'
(is-retraction-map-inv-equiv (equiv-ap-emb f) refl ,
is-retraction-map-inv-equiv (equiv-ap-emb g) refl))
is-emb-ordered-pair : is-emb {A = M Ã M} (Îģ (x , y) â ordered-pair x y)
is-emb-ordered-pair =
is-emb-equiv-refl-to-refl
(Îģ (x , y) â ordered-pair x y)
(Îģ (x , y) (x' , y') â equiv-ordered-pair-eq x x' y y')
(Îģ (x , y) â compute-equiv-ordered-pair-eq x y)
ordered-pairs : OrderedPairs
pr1 ordered-pairs (x , y) = ordered-pair x y
pr2 ordered-pairs = is-emb-ordered-pair
module from-unordered-pairs'
(empty-set : EmptySet)
(â-singletons : â-Singletons)
(unordered-pairs' : UnorderedPairs') where
open emb-singleton â-singletons
open emb-unordered-pair-singleton-empty empty-set â-singletons unordered-pairs'
open from-distinct-embeddings
emb-unordered-pair-singleton-empty
(comp-emb emb-singleton emb-singleton)
[[_],,â
]â [[_]]
unordered-pairs'
using (ordered-pairs) public
module from-â-unordered-pairs
(empty-set : EmptySet)
(â-singletons : â-Singletons)
(â-unordered-pairs : â-UnorderedPairs) where
private
unordered-pairs' : UnorderedPairs'
pr1 (unordered-pairs' x y) = pr1 (â-unordered-pairs x y)
pr2 (unordered-pairs' x y) _ = pr2 (â-unordered-pairs x y)
open emb-singleton â-singletons
open emb-unordered-pair-singleton-empty empty-set â-singletons unordered-pairs'
open from-distinct-embeddings
emb-unordered-pair-singleton-empty
(comp-emb emb-singleton emb-singleton)
[[_],,â
]â [[_]]
unordered-pairs'
using (ordered-pairs) public
open e-structure.core.trunc-sets ((M , _â_) , p)
ordered-pairs-from-level : (n : â)
â â-str-has-level n
â EmptySet
â [ n ]-Singletons
â [ n ]-UnorderedPairs
â OrderedPairs
ordered-pairs-from-level zero-â H empty-set n-singletons n-unordered-pairs
= ordered-pairs where
M-Set : Set i
pr1 M-Set = M
pr2 M-Set = is-trunc-â-str-carrier zero-â H
â-singletons : â-Singletons
pr1 (â-singletons x) = pr1 (n-singletons x)
pr2 (â-singletons x) z =
inv-equiv (equiv-unit-trunc (Id-Prop M-Set x z))
âe pr2 (n-singletons x) z
unordered-pairs' : UnorderedPairs'
pr1 (unordered-pairs' x y) = pr1 (n-unordered-pairs x y)
pr2 (unordered-pairs' x y) xâ y z =
inv-equiv (equiv-unit-trunc
(coprod-Prop
(Id-Prop M-Set x z)
(Id-Prop M-Set y z)
(Îģ x=z y=z â xâ y (x=z â inv y=z))))
âe pr2 (n-unordered-pairs x y) z
open from-unordered-pairs'
empty-set
â-singletons
unordered-pairs'
ordered-pairs-from-level (succ-â n) H empty-set n-singletons n-unordered-pairs
= ordered-pairs where
M-Truncated-Type : Truncated-Type i (to-đ (succ-â n))
pr1 M-Truncated-Type = M
pr2 M-Truncated-Type = is-trunc-â-str-carrier (succ-â n) H
â-singletons : â-Singletons
pr1 (â-singletons x) = pr1 (n-singletons x)
pr2 (â-singletons x) z =
inv-equiv (equiv-unit-trunc (Id-Truncated-Type M-Truncated-Type x z))
âe pr2 (n-singletons x) z
â-unordered-pairs : â-UnorderedPairs
pr1 (â-unordered-pairs x y) = pr1 (n-unordered-pairs x y)
pr2 (â-unordered-pairs x y) z =
inv-equiv (equiv-unit-trunc
((x == z) + (y == z) ,
is-trunc-coprod (minus-two n)
(pr2 M-Truncated-Type x z)
(pr2 M-Truncated-Type y z)))
âe pr2 (n-unordered-pairs x y) z
open from-â-unordered-pairs
empty-set
â-singletons
â-unordered-pairs