module Cat.Restriction.Reasoning
  {o β„“} {C : Precategory o β„“}
  (C-restrict : Restriction-category C)
  where

Reasoning in restriction categoriesπŸ”—

This module provides some useful lemmas about restriction categories. We begin by noting that for every is an idempotent.

↓-idem : βˆ€ {x y} (f : Hom x y) β†’ is-idempotent (f ↓)
↓-idem f =
  f ↓ ∘ f ↓   β‰‘Λ˜βŸ¨ ↓-smashr f f βŸ©β‰‘Λ˜
  (f ∘ f ↓) ↓ β‰‘βŸ¨ ap _↓ (↓-dom f) βŸ©β‰‘
  f ↓         ∎

Next, some useful lemmas about pre and postcomposition of a restriction map.

↓-cancelr : βˆ€ {x y z} (f : Hom y z) (g : Hom x y) β†’ (f ∘ g) ↓ ∘ g ↓ ≑ (f ∘ g) ↓
↓-cancelr f g =
  (f ∘ g) ↓ ∘ g ↓   β‰‘Λ˜βŸ¨ ↓-smashr g (f ∘ g) βŸ©β‰‘Λ˜
  ((f ∘ g) ∘ g ↓) ↓ β‰‘βŸ¨ ap _↓ (pullr (↓-dom g)) βŸ©β‰‘
  (f ∘ g) ↓         ∎


↓-cancell : βˆ€ {x y z} (f : Hom y z) (g : Hom x y) β†’ g ↓ ∘ (f ∘ g) ↓ ≑ (f ∘ g) ↓
↓-cancell f g =
  g ↓ ∘ (f ∘ g) ↓  β‰‘βŸ¨ ↓-comm g (f ∘ g) βŸ©β‰‘
  (f ∘ g) ↓ ∘ g ↓  β‰‘βŸ¨ ↓-cancelr f g βŸ©β‰‘
  (f ∘ g) ↓        ∎

We can use these to show that which is somewhat hard to motivate, but ends up being a useful algebraic manipulation.

↓-smashl : βˆ€ {x y z} (f : Hom y z) (g : Hom x y) β†’ (f ↓ ∘ g) ↓ ≑ (f ∘ g) ↓
↓-smashl f g =
  ((f ↓) ∘ g) ↓     β‰‘βŸ¨ ap _↓ (↓-swap f g) βŸ©β‰‘
  (g ∘ (f ∘ g) ↓) ↓ β‰‘βŸ¨ ↓-smashr (f ∘ g) g βŸ©β‰‘
  g ↓ ∘ (f ∘ g) ↓   β‰‘βŸ¨ ↓-cancell f g βŸ©β‰‘
  (f ∘ g) ↓ ∎

↓-smash : βˆ€ {x y z} (f : Hom x z) (g : Hom x y) β†’ (f ↓ ∘ g ↓) ↓ ≑ f ↓ ∘ g ↓
↓-smash f g =
  (f ↓ ∘ g ↓) ↓ β‰‘βŸ¨ ↓-smashl f (g ↓) βŸ©β‰‘
  (f ∘ g ↓) ↓   β‰‘βŸ¨ ↓-smashr g f βŸ©β‰‘
  f ↓ ∘ g ↓ ∎

Next, we note that iterating does nothing.

↓-join : βˆ€ {x y} (f : Hom x y) β†’ (f ↓) ↓ ≑ f ↓
↓-join f =
  (f ↓) ↓       β‰‘βŸ¨ ap _↓ (sym (↓-idem f)) βŸ©β‰‘
  (f ↓ ∘ f ↓) ↓ β‰‘βŸ¨ ↓-smashr f (f ↓) βŸ©β‰‘
  (f ↓) ↓ ∘ f ↓ β‰‘βŸ¨ ↓-comm (f ↓) f βŸ©β‰‘
  f ↓ ∘ (f ↓) ↓ β‰‘βŸ¨ ↓-dom (f ↓) βŸ©β‰‘
  f ↓ ∎

Total morphismsπŸ”—

We say that a morphism in a restriction category is total if its restriction is the identity morphism.

is-total : βˆ€ {x y} β†’ Hom x y β†’ Type _
is-total f = f ↓ ≑ id

record Total (x y : Ob) : Type β„“ where
  no-eta-equality
  field
    mor : Hom x y
    has-total : is-total mor

open Total public

Being total is a proposition, so the collection of total morphisms forms a set.

is-total-is-prop : βˆ€ {x y} β†’ (f : Hom x y) β†’ is-prop (is-total f)
is-total-is-prop f = Hom-set _ _ _ _

If is monic, then it is a total morphism.

monicβ†’total : βˆ€ {x y} {f : Hom x y} β†’ is-monic f β†’ is-total f
monicβ†’total {f = f} monic = monic (f ↓) id (↓-dom f βˆ™ sym (idr _))

As a corollary, every isomorphism is total.

invertibleβ†’total : βˆ€ {x y} {f : Hom x y} β†’ is-invertible f β†’ is-total f
invertible→total f-inv = monic→total (invertible→monic f-inv)

The identity morphism is total, as it is monic.

id-total : βˆ€ {x} β†’ is-total (id {x})
id-total = monic→total id-monic

Total morphisms are closed under composition.

total-∘
  : βˆ€ {x y z} {f : Hom y z} {g : Hom x y}
  β†’ is-total f β†’ is-total g β†’ is-total (f ∘ g)
total-∘ {f = f} {g = g} f-total g-total =
  (f ∘ g) ↓   β‰‘Λ˜βŸ¨ ↓-smashl f g βŸ©β‰‘Λ˜
  (f ↓ ∘ g) ↓ β‰‘βŸ¨ ap _↓ (eliml f-total) βŸ©β‰‘
  g ↓         β‰‘βŸ¨ g-total βŸ©β‰‘
  id          ∎

_∘Total_ : βˆ€ {x y z} β†’ Total y z β†’ Total x y β†’ Total x z
(f ∘Total g) .mor = f .mor ∘ g .mor
(f ∘Total g) .has-total = total-∘ (f .has-total) (g .has-total)

Furthermore, if is total, then must also be total.

total-cancell
  : βˆ€ {x y z} {f : Hom y z} {g : Hom x y}
  β†’ is-total (f ∘ g) β†’ is-total g
total-cancell {f = f} {g = g} fg-total =
  g ↓             β‰‘βŸ¨ intror fg-total βŸ©β‰‘
  g ↓ ∘ (f ∘ g) ↓ β‰‘βŸ¨ ↓-cancell f g βŸ©β‰‘
  (f ∘ g) ↓       β‰‘βŸ¨ fg-total βŸ©β‰‘
  id ∎

If is total, then

total-smashl
  : βˆ€ {x y z} {f : Hom y z} {g : Hom x y}
  β†’ is-total f β†’ (f ∘ g) ↓ ≑ g ↓
total-smashl {f = f} {g = g} f-total =
  (f ∘ g) ↓ β‰‘Λ˜βŸ¨ ↓-smashl f g βŸ©β‰‘Λ˜
  (f ↓ ∘ g) ↓ β‰‘βŸ¨ ap _↓ (eliml f-total) βŸ©β‰‘
  g ↓ ∎

Restriction idempotentsπŸ”—

We say that a morphism is a restriction idempotent if

is-restriction-idempotent : βˆ€ {x} β†’ (f : Hom x x) β†’ Type _
is-restriction-idempotent f = f ↓ ≑ f

As the name suggests, restriction idempotents are idempotents.

restriction-idempotent→idempotent
  : βˆ€ {x} {f : Hom x x}
  β†’ is-restriction-idempotent f β†’ is-idempotent f
restriction-idempotent→idempotent {f = f} f-dom =
  f ∘ f β‰‘βŸ¨ ap (f ∘_) (sym f-dom) βŸ©β‰‘
  f ∘ f ↓ β‰‘βŸ¨ ↓-dom f βŸ©β‰‘
  f ∎

Furthermore, every morphism is a restriction idempotent.

↓-restriction-idempotent : βˆ€ {x y} (f : Hom x y) β†’ is-restriction-idempotent (f ↓)
↓-restriction-idempotent f = ↓-join f

If and are restriction idempotents, then they commute.

restriction-idem-comm
  : βˆ€ {x} {f g : Hom x x}
  β†’ is-restriction-idempotent f β†’ is-restriction-idempotent g
  β†’ f ∘ g ≑ g ∘ f
restriction-idem-comm f-dom g-dom =
  apβ‚‚ _∘_ (sym f-dom) (sym g-dom)
  Β·Β· ↓-comm _ _
  Β·Β· apβ‚‚ _∘_ g-dom f-dom

Restricted monicsπŸ”—

A morphism is a restricted monic if for all implies that Intuitively, this is the correct notion of monic for a partial function; we cannot guarantee that and are equal if as may diverge on some inputs where and disagree.

is-restricted-monic : βˆ€ {x y} β†’ Hom x y β†’ Type _
is-restricted-monic {x} {y} f =
  βˆ€ {a} β†’ (g h : Hom a x) β†’ f ∘ g ≑ f ∘ h β†’ f ↓ ∘ g ≑ f ↓ ∘ h

If is a total restricted monic, then is monic.

restricted-monic+total→monic
  : βˆ€ {x y} {f : Hom x y}
  β†’ is-restricted-monic f β†’ is-total f
  β†’ is-monic f
restricted-monic+total→monic {f = f} f-rmonic f-total g1 g2 p =
  g1       β‰‘βŸ¨ introl f-total βŸ©β‰‘
  f ↓ ∘ g1 β‰‘βŸ¨ f-rmonic g1 g2 p βŸ©β‰‘
  f ↓ ∘ g2 β‰‘βŸ¨ eliml f-total βŸ©β‰‘
  g2 ∎

Restricted monics are closed under composition.

restricted-monic-∘
  : βˆ€ {x y z} {f : Hom y z} {g : Hom x y}
  β†’ is-restricted-monic f β†’ is-restricted-monic g
  β†’ is-restricted-monic (f ∘ g)
restricted-monic-∘ {f = f} {g = g} f-rmonic g-rmonic h1 h2 p =
  (f ∘ g) ↓ ∘ h1         β‰‘βŸ¨ pushl (sym (↓-cancell f g)) βŸ©β‰‘
  g ↓ ∘ (f ∘ g) ↓ ∘ h1   β‰‘βŸ¨ g-rmonic _ _ g-lemma βŸ©β‰‘
  (g ↓) ∘ (f ∘ g) ↓ ∘ h2 β‰‘βŸ¨ pulll (↓-cancell f g) βŸ©β‰‘
  (f ∘ g) ↓ ∘ h2 ∎
  where
    p-assoc : f ∘ g ∘ h1 ≑ f ∘ g ∘ h2
    p-assoc = assoc _ _ _ Β·Β· p Β·Β· sym (assoc _ _ _)

    g-lemma : g ∘ (f ∘ g) ↓ ∘ h1 ≑ g ∘ (f ∘ g) ↓ ∘ h2
    g-lemma =
      g ∘ (f ∘ g) ↓ ∘ h1 β‰‘βŸ¨ extendl (sym (↓-swap f g)) βŸ©β‰‘
      f ↓ ∘ g ∘ h1       β‰‘βŸ¨ f-rmonic _ _ p-assoc βŸ©β‰‘
      f ↓ ∘ g ∘ h2       β‰‘βŸ¨ extendl (↓-swap f g) βŸ©β‰‘
      g ∘ (f ∘ g) ↓ ∘ h2 ∎

Furthermore, if is a restricted monic and is total, then is a restricted monic.

restricted-monic-cancell
  : βˆ€ {x y z} {f : Hom y z} {g : Hom x y}
  β†’ is-restricted-monic (f ∘ g)
  β†’ is-total f
  β†’ is-restricted-monic g
restricted-monic-cancell {f = f} {g = g} fg-rmonic f-total h1 h2 p =
  g ↓ ∘ h1           β‰‘βŸ¨ ap (_∘ h1) (sym (total-smashl f-total)) βŸ©β‰‘
  (f ∘ g) ↓ ∘ h1     β‰‘βŸ¨ fg-rmonic h1 h2 (sym (assoc _ _ _) Β·Β· ap (f ∘_) p Β·Β· assoc _ _ _) βŸ©β‰‘
  (f ∘ g) ↓ ∘ h2     β‰‘βŸ¨ ap (_∘ h2) (total-smashl f-total) βŸ©β‰‘
  g ↓ ∘ h2           ∎

Restricted retractsπŸ”—

Let and be a pair of morphisms. The map is a restricted retract of when

_restricted-retract-of_ : βˆ€ {x y} (r : Hom x y) (s : Hom y x) β†’ Type _
r restricted-retract-of s = r ∘ s ≑ s ↓

record has-restricted-retract {x y} (s : Hom y x) : Type β„“ where
  no-eta-equality
  field
    ↓-retract : Hom x y
    is-restricted-retract : ↓-retract restricted-retract-of s

open has-restricted-retract public

If is total and has a restricted retract, then it has a retract.

has-restricted-retract+total→has-retract
  : βˆ€ {x y} {f : Hom x y}
  β†’ has-restricted-retract f β†’ is-total f β†’ has-retract f
has-restricted-retract+total→has-retract {f = f} f-sect f-total =
  make-retract (f-sect .↓-retract) $
    f-sect .↓-retract ∘ f β‰‘βŸ¨ f-sect .is-restricted-retract βŸ©β‰‘
    f ↓                   β‰‘βŸ¨ f-total βŸ©β‰‘
    id                    ∎

If has a restricted retract, then it is a restricted mono.

has-restricted-retract→restricted-monic
  : βˆ€ {x y} {f : Hom x y}
  β†’ has-restricted-retract f
  β†’ is-restricted-monic f
has-restricted-retract→restricted-monic {f = f} f-sect g1 g2 p =
  f ↓ ∘ g1 β‰‘βŸ¨ pushl (sym $ f-sect .is-restricted-retract) βŸ©β‰‘
  f-sect .↓-retract ∘ f ∘ g1 β‰‘βŸ¨ ap (f-sect .↓-retract ∘_) p βŸ©β‰‘
  f-sect .↓-retract ∘ f ∘ g2 β‰‘βŸ¨ pulll (f-sect .is-restricted-retract) βŸ©β‰‘
  f ↓ ∘ g2 ∎

If and have restricted retracts, then so does

restricted-retract-∘
  : βˆ€ {x y z} {f : Hom y z} {g : Hom x y}
  β†’ has-restricted-retract f β†’ has-restricted-retract g
  β†’ has-restricted-retract (f ∘ g)
restricted-retract-∘ {f = f} {g = g} f-sect g-sect .↓-retract =
  g-sect .↓-retract ∘ f-sect .↓-retract
restricted-retract-∘ {f = f} {g = g} f-sect g-sect .is-restricted-retract =
  (g-sect .↓-retract ∘ f-sect .↓-retract) ∘ f ∘ g β‰‘βŸ¨ pull-inner (f-sect .is-restricted-retract) βŸ©β‰‘
  g-sect .↓-retract ∘ f ↓ ∘ g                     β‰‘βŸ¨ ap (g-sect .↓-retract ∘_) (↓-swap f g) βŸ©β‰‘
  g-sect .↓-retract ∘ g ∘ (f ∘ g) ↓               β‰‘βŸ¨ pulll (g-sect .is-restricted-retract) βŸ©β‰‘
  g ↓ ∘ (f ∘ g) ↓                                 β‰‘βŸ¨ ↓-cancell f g βŸ©β‰‘
  (f ∘ g) ↓                                       ∎

If has a restricted retract and is total, then has a restricted retract.

has-restricted-retract-cancell
  : βˆ€ {x y z} {f : Hom y z} {g : Hom x y}
  β†’ has-restricted-retract (f ∘ g)
  β†’ is-total f
  β†’ has-restricted-retract g
has-restricted-retract-cancell {f = f} fg-sect f-total .↓-retract =
  fg-sect .↓-retract ∘ f
has-restricted-retract-cancell {f = f} {g = g} fg-sect f-total .is-restricted-retract =
  (fg-sect .↓-retract ∘ f) ∘ g β‰‘βŸ¨ sym (assoc _ _ _) βˆ™ fg-sect .is-restricted-retract βŸ©β‰‘
  (f ∘ g) ↓                    β‰‘βŸ¨ total-smashl f-total βŸ©β‰‘
  g ↓ ∎

Restricted isomorphismsπŸ”—

Let and be a pair of morphisms. and are restricted inverses if and

record restricted-inverses
  {x y} (f : Hom x y) (g : Hom y x)
  : Type β„“ where
  no-eta-equality
  field
    ↓-invl : f ∘ g ≑ g ↓
    ↓-invr : g ∘ f ≑ f ↓

open restricted-inverses

record is-restricted-invertible {x y} (f : Hom x y) : Type β„“ where
  no-eta-equality
  field
    ↓-inv : Hom y x
    ↓-inverses : restricted-inverses f ↓-inv

  open restricted-inverses ↓-inverses public

record _↓≅_ (x y : Ob) : Type β„“ where
  no-eta-equality
  field
    ↓-to : Hom x y
    ↓-from : Hom y x
    ↓-inverses : restricted-inverses ↓-to ↓-from

  open restricted-inverses ↓-inverses public

open _↓≅_ public

A given morphism is a has a unique restricted inverse.

restricted-inverses-is-prop
  : βˆ€ {x y} {f : Hom x y} {g : Hom y x}
  β†’ is-prop (restricted-inverses f g)
restricted-inverses-is-prop x y i .↓-invl =
  Hom-set _ _ _ _ (x .↓-invl) (y .↓-invl) i
restricted-inverses-is-prop x y i .↓-invr =
  Hom-set _ _ _ _ (x .↓-invr) (y .↓-invr) i

is-restricted-invertible-is-prop
   : βˆ€ {x y} {f : Hom x y}
   β†’ is-prop (is-restricted-invertible f)
is-restricted-invertible-is-prop {f = f} g h = p where
  module g = is-restricted-invertible g
  module h = is-restricted-invertible h

  g≑h : g.↓-inv ≑ h.↓-inv
  g≑h =
    g.↓-inv                                 β‰‘Λ˜βŸ¨ ↓-dom _ βŸ©β‰‘Λ˜
    g.↓-inv ∘ g.↓-inv ↓                     β‰‘βŸ¨ ap (g.↓-inv ∘_) (sym g.↓-invl) βŸ©β‰‘
    g.↓-inv ∘ f ∘ g.↓-inv                   β‰‘βŸ¨ extendl (g.↓-invr βˆ™ sym h.↓-invr) βŸ©β‰‘
    h.↓-inv ∘ ⌜ f ⌝ ∘ g.↓-inv               β‰‘βŸ¨ ap! (sym (↓-dom f) βˆ™ ap (f ∘_) (sym h.↓-invr)) βŸ©β‰‘
    h.↓-inv ∘ (f ∘ h.↓-inv ∘ f) ∘ g.↓-inv   β‰‘βŸ¨ ap (h.↓-inv ∘_) (pullr (pullr g.↓-invl) βˆ™ pulll h.↓-invl) βŸ©β‰‘
    h.↓-inv ∘ h.↓-inv ↓ ∘ g.↓-inv ↓         β‰‘βŸ¨ ap (h.↓-inv ∘_) (↓-comm _ _) βŸ©β‰‘
    h.↓-inv ∘ g.↓-inv ↓ ∘ h.↓-inv ↓         β‰‘βŸ¨ ap (h.↓-inv ∘_) (pushl (sym g.↓-invl) βˆ™ pushr (pushr (sym h.↓-invl))) βŸ©β‰‘
    h.↓-inv ∘ ⌜ f ∘ g.↓-inv ∘ f ⌝ ∘ h.↓-inv β‰‘βŸ¨ ap! (ap (f ∘_) g.↓-invr βˆ™ ↓-dom f) βŸ©β‰‘
    h.↓-inv ∘ f ∘ h.↓-inv                   β‰‘βŸ¨ ap (h.↓-inv ∘_) (h.↓-invl)  βŸ©β‰‘
    h.↓-inv ∘ h.↓-inv ↓                     β‰‘βŸ¨ ↓-dom _ βŸ©β‰‘
    h.↓-inv                                 ∎

  p : g ≑ h
  p i .is-restricted-invertible.↓-inv = g≑h i
  p i .is-restricted-invertible.↓-inverses =
    is-propβ†’pathp (Ξ» i β†’ restricted-inverses-is-prop {f = f} {g = g≑h i})
      g.↓-inverses h.↓-inverses i

If and are both total and restricted inverses, then they are inverses.

restricted-inverses+total→inverses
  : βˆ€ {x y} {f : Hom x y} {g : Hom y x}
  β†’ restricted-inverses f g
  β†’ is-total f
  β†’ is-total g
  β†’ Inverses f g
restricted-inverses+total→inverses {f = f} {g = g} fg-inv f-total g-total = record
    { invl = fg-inv .↓-invl βˆ™ g-total
    ; invr = fg-inv .↓-invr βˆ™ f-total
    }

Refining morphismsπŸ”—

Let be a restriction category, and We say that refines if agrees with when restricted to the domain of

_≀_ : βˆ€ {x y} β†’ Hom x y β†’ Hom x y β†’ Type β„“
f ≀ g = g ∘ f ↓ ≑ f

The refinement relation is reflexive, transitive, and anti-symmetric.

≀-refl : βˆ€ {x y} {f : Hom x y} β†’ f ≀ f
≀-refl {f = f} = ↓-dom f

≀-trans : βˆ€ {x y} {f g h : Hom x y} β†’ f ≀ g β†’ g ≀ h β†’ f ≀ h
≀-trans {f = f} {g = g} {h = h} p q =
  h ∘ ⌜ f ⌝ ↓       β‰‘βŸ¨ ap! (sym p) βŸ©β‰‘
  h ∘ (g ∘ (f ↓)) ↓ β‰‘βŸ¨ ap (h ∘_) (↓-smashr f g) βŸ©β‰‘
  h ∘ g ↓ ∘ f ↓     β‰‘βŸ¨ pulll q βŸ©β‰‘
  g ∘ f ↓           β‰‘βŸ¨ p βŸ©β‰‘
  f                 ∎

≀-antisym : βˆ€ {x y} {f g : Hom x y} β†’ f ≀ g β†’ g ≀ f β†’ f ≑ g
≀-antisym {f = f} {g = g} p q =
  f             β‰‘βŸ¨ sym p βŸ©β‰‘
  g ∘ f ↓       β‰‘βŸ¨ pushl (sym q) βŸ©β‰‘
  f ∘ g ↓ ∘ f ↓ β‰‘βŸ¨ ap (f ∘_) (↓-comm g f) βŸ©β‰‘
  f ∘ f ↓ ∘ g ↓ β‰‘βŸ¨ pulll (↓-dom f) βŸ©β‰‘
  f ∘ (g ↓)     β‰‘βŸ¨ q βŸ©β‰‘
  g ∎

Furthermore, composition preserves refinement.

∘-preserves-≀
  : βˆ€ {x y z} {f g : Hom y z} {h i : Hom x y}
  β†’ f ≀ g β†’ h ≀ i β†’ (f ∘ h) ≀ (g ∘ i)
∘-preserves-≀ {f = f} {g = g} {h = h} {i = i} p q =
  (g ∘ i) ∘ ⌜ f ∘ h ⌝ ↓          β‰‘βŸ¨ ap! (pushr (sym q)) βŸ©β‰‘
  (g ∘ i) ∘ ((f ∘ i) ∘ (h ↓)) ↓  β‰‘βŸ¨ ap ((g ∘ i) ∘_) (↓-smashr h (f ∘ i)) βŸ©β‰‘
  (g ∘ i) ∘ (f ∘ i) ↓ ∘ h ↓      β‰‘βŸ¨ extendr (extendl (sym (↓-swap f i))) βŸ©β‰‘
  (g ∘ f ↓) ∘ (i ∘ h ↓)          β‰‘βŸ¨ apβ‚‚ _∘_ p q βŸ©β‰‘
  f ∘ h                          ∎