open import 1Lab.HLevel.Retracts
open import 1Lab.HLevel.Universe
open import 1Lab.Path.Groupoid
open import 1Lab.Type.Sigma
open import 1Lab.Univalence
open import 1Lab.Type.Pi
open import 1Lab.HLevel
open import 1Lab.Equiv
open import 1Lab.Path
open import 1Lab.Type

module 1Lab.Equiv.Embedding where

EmbeddingsπŸ”—

One of the most important observations leading to the development of categorical set theory is that injective maps into a set SS correspond to maps from SS into a universe of propositions, normally denoted Ω\Omega. Classically, this object is Ω={0,1}\Omega = \{ 0 , 1 \}, but there are other settings in which this idea makes sense (elementary topoi) where the subobject classifier is not a coproduct 1∐11 \coprod 1.

To develop this correspondence, we note that, if a map is injective and its codomain is a [set], then all the fibres fβˆ—(x)f^*(x) of ff are propositions.

injective : (A β†’ B) β†’ Type _
injective f = βˆ€ {x y} β†’ f x ≑ f y β†’ x ≑ y

injective-between-sets→has-prop-fibres
  : is-set B β†’ (f : A β†’ B) β†’ injective f
  β†’ βˆ€ x β†’ is-prop (fibre f x)
injective-between-sets→has-prop-fibres bset f inj x (f*x , p) (f*x′ , q) =
  Ξ£-prop-path (Ξ» x β†’ bset _ _) (inj (p βˆ™ sym q))

In fact, this condition is not only necessary, it is also sufficient. Thus, we conclude that, for maps between sets, these notions are equivalent, and we could take either as the definition of β€œsubset inclusion.”

has-prop-fibres→injective
  : (f : A β†’ B) β†’ (βˆ€ x β†’ is-prop (fibre f x))
  β†’ injective f
has-prop-fibres→injective _ prop p = ap fst (prop _ (_ , p) (_ , refl))

between-sets-injective≃has-prop-fibres
  : is-set A β†’ is-set B β†’ (f : A β†’ B)
  β†’ injective f ≃ (βˆ€ x β†’ is-prop (fibre f x))
between-sets-injective≃has-prop-fibres aset bset f =
  prop-ext (Ξ» p q i x β†’ aset _ _ (p x) (q x) i)
           (Ξ -is-hlevel 1 Ξ» _ β†’ is-prop-is-prop)
           (injective-between-sets→has-prop-fibres bset f)
           (has-prop-fibres→injective f)

However, for more general types, like the circle, this fails: A function can have propositional fibres in at most one way, but a function can be injective in more than one. Consider the following two witnesses of injectivity for the identity map of the circle, i.e., two functions x=y→x=yx = y → x = y.

module _ where private
  open import 1Lab.HIT.S1

  circle-id : SΒΉ β†’ SΒΉ
  circle-id p = p

The first is the boring option: it just gives back the same path, unchanged. The second is more interesting: By doing circle induction, we can consider the cases separately, and in the case where y=basey = \id{base}, we add an extra twist onto the path:

  circle-id-inj₁ circle-id-injβ‚‚ : injective circle-id
  circle-id-inj₁ p = p
  circle-id-injβ‚‚ {x} =
    SΒΉ-elim {P = Ξ» y β†’ x ≑ y β†’ x ≑ y} (_βˆ™ loop)
      (funext-dep Ξ» p β†’ to-pathp (subst-path-right _ _ βˆ™ lemma p))
      _
    where
      lemma : βˆ€ {x} {p1 p2 : x ≑ base}
            β†’ PathP (Ξ» i β†’ x ≑ loop i) p1 p2
            β†’ (p1 βˆ™ loop) βˆ™ loop ≑ p2 βˆ™ loop
      lemma path = ap (_βˆ™ loop) (from-pathp path)

These functions are not the same! When given refl, circle-id-inj₁ will give refl (because it’s boring), but the exciting function will give loop. And that ain’t refl.

  circle-id-inj₁≠injβ‚‚ : circle-id-inj₁ ≑ circle-id-injβ‚‚ β†’ βŠ₯
  circle-id-inj₁≠injβ‚‚ p = reflβ‰ loop (happly p refl βˆ™ βˆ™-id-l _)

Since we want β€œis a subtype inclusion” to be a property β€” that is, we really want to not care about how a function is a subtype inclusion, only that it is, we define embeddings as those functions which have propositional fibres:

is-embedding : (A β†’ B) β†’ Type _
is-embedding f = βˆ€ x β†’ is-prop (fibre f x)

_β†ͺ_ : Type β„“ β†’ Type ℓ₁ β†’ Type _
A β†ͺ B = Ξ£[ f ∈ (A β†’ B) ] is-embedding f

Univalence β€” specifically, the existence of classifying objects for maps with PP-fibres β€” tells us that the embeddings into BB correspond to the families of propositional types over BB.

subtype-classifier
  : βˆ€ {β„“} {B : Type β„“}
  β†’ (Ξ£[ A ∈ Type β„“ ] (A β†ͺ B)) ≃ (B β†’ Ξ£[ T ∈ Type β„“ ] (is-prop T))
subtype-classifier {β„“} = Map-classifier {β„“ = β„“} is-prop

A canonical source of embedding, then, are the first projections from total spaces of propositional families. This is because, as Fibre-equiv tells us, the fibre of Ο€1\pi_1 over xx is equivalent to β€œthe space of possible second coordinates,” i.e., B(x)B(x). Since B(x)B(x) was assumed to be a prop., then so are the fibres of fst.

Subset-proj-embedding
  : βˆ€ {B : A β†’ Type β„“} β†’ (βˆ€ x β†’ is-prop (B x))
  β†’ is-embedding {A = Ξ£ B} fst
Subset-proj-embedding {B = B} Bprop x = is-hlevel≃ 1 (Fibre-equiv B x e⁻¹) (Bprop _)
!–
embedding→monic
  : βˆ€ {β„“ β„“β€² β„“β€²β€²} {A : Type β„“} {B : Type β„“β€²} {f : A β†’ B}
  β†’ is-embedding f
  β†’ βˆ€ {C : Type β„“β€²β€²} (g h : C β†’ A) β†’ f ∘ g ≑ f ∘ h β†’ g ≑ h
embedding→monic {f = f} emb g h p =
  funext Ξ» x β†’ ap fst (emb _ (g x , refl) (h x , happly (sym p) x))

monic-between-sets→is-embedding
  : βˆ€ {β„“ β„“β€² β„“β€²β€²} {A : Type β„“} {B : Type β„“β€²} {f : A β†’ B}
  β†’ is-set B
  β†’ (βˆ€ {C : Set β„“β€²β€²} (g h : ∣ C ∣ β†’ A) β†’ f ∘ g ≑ f ∘ h β†’ g ≑ h)
  β†’ is-embedding f
monic-between-sets→is-embedding {f = f} bset monic =
  injective-between-sets→has-prop-fibres bset _ λ {x} {y} p →
    happly (monic {C = Lift _ ⊀ , Ξ» _ _ _ _ i j β†’ lift tt} (Ξ» _ β†’ x) (Ξ» _ β†’ y) (funext (Ξ» _ β†’ p))) _

–