Benedikt Ahrens and RΓ©gis Spadotti— Terminal semantics for codata types in intensional Martin-Löf type theory
Table of contents
Index
Require Import Category.RComonad.
Require Import Theory.Category.
Require Import Theory.Isomorphism.
Require Import Theory.Functor.
Require Import Theory.RelativeComonad.
Require Import Theory.Comodule.
Require Import Theory.Product.
Require Import Theory.CartesianStrongMonoidal.

Generalizable All Variables.

Relative comonad with cut

Definition

Section Defs.

  Context `{BinaryProduct π’ž} `{BinaryProduct π’Ÿ}
          (F : Functor π’ž π’Ÿ) (E : π’ž) `{!CartesianStrongMonoidal F}.

  Section ExtendConstruction.

    Context {T : RelativeComonad F}
            (cut : βˆ€ A, T (E Γ— A) β‡’ T A).

    Program Definition Extend {A B} : [ T A β‡’ F B ⟢ T (E Γ— A) β‡’ F (E Γ— B) ] ≔
      Ξ» f ↦ φ⁻¹ ∘ ⟨ F β‹… π₁ ∘ Tβ‹…counit , f ∘ cut A ⟩.
    Show proof.
      intros f g eq_fg. now rewrite eq_fg.

  End ExtendConstruction.

  Structure RelativeComonadWithCut ≔ mkRelativeComonadWithCut
  { T:>RelativeComonad F
  ; cut:βˆ€ {A}, T (E Γ— A) β‡’ T A
  ; cut_counit:βˆ€ {A}, Tβ‹…counit[A] ∘ cut β‰ˆ F β‹… Ο€β‚‚ ∘ Tβ‹…counit
  ; cut_cobind:βˆ€ {A B} {f : T A β‡’ F B}, Tβ‹…cobind(f) ∘ cut β‰ˆ cut ∘ Tβ‹…cobind (Extend (@cut) f) }.

  Definition extend {T : RelativeComonadWithCut} {A B} : [ T A β‡’ F B ⟢ T (E Γ— A) β‡’ F (E Γ— B) ] ≔
    Extend (@cut T).

End Defs.

Arguments RelativeComonadWithCut{_ _ _ _} _ _ {_}.
Arguments mkRelativeComonadWithCut{_ _ _ _ _ _ _ _ _} _ _.
Arguments T{_ _ _ _ _ _ _} _.
Arguments cut{_ _ _ _ _ _ _} _ {_}.
Arguments cut_counit{_ _ _ _ _ _ _} _ {_}.
Arguments cut_cobind{_ _ _ _ _ _ _} _ {_ _ _}.
Arguments extend{_ _ _ _ _ _ _} _ {_ _}.

Notation "'cut[' X ]"≔ (cut _ (A ≔ X)) (only parsing).
Notation "T 'β‹…cut'"≔ (cut T) (at level 0).
Notation "T 'β‹…cut[' X ]"≔ (cut T (A ≔ X)) (at level 0, only parsing).
Notation "T 'β‹…extend'"≔ (extend T) (at level 0).

Notation "'RelativeComonadWithCut.make' ⦃ 'RelativeComonad' ≔ RelativeComonad ; 'cut' ≔ cut ⦄" ≔
  (@mkRelativeComonadWithCut _ _ _ _ _ _ _ RelativeComonad cut _ _) (only parsing).
Notation "'RelativeComonadWithCut.make' ⦃ 'T' ≔ T ; 'counit' ≔ counit ; 'cobind' ≔ cobind ; 'cut' ≔ cut ⦄" ≔
  (@mkRelativeComonadWithCut _ _ _ _ _ _ _
      (RelativeComonad.make ⦃ T ≔ T ;counit ≔ counit ; cobind ≔ cobind ⦄ ) cut _ _) (only parsing).

Morphism

Section MDefs.

  Context `{BinaryProduct π’ž} `{BinaryProduct π’Ÿ}
          {F : Functor π’ž π’Ÿ} {E : π’ž} `{!CartesianStrongMonoidal F}.

  Local Notation "[ R ]" ≔ (T R) (only parsing).

  Structure Morphism (T S : RelativeComonadWithCut F E) : Type ≔ mkMorphism
  { Ο„:>[T] β‡’ [S]
  ; Ο„_cut:βˆ€ {A}, Sβ‹…cut ∘ Ο„(E Γ— A) β‰ˆ Ο„(A) ∘ Tβ‹…cut }.

End MDefs.

Arguments mkMorphism{_ _ _ _ _ _ _ _ _ _} _.
Arguments Ο„{_ _ _ _ _ _ _ _ _} _.
Arguments Ο„_cut{_ _ _ _ _ _ _ _ _} _ {_}.

Notation "'RelativeComonadWithCut.make' ⦃ 'RelativeComonad-Ο„' ≔ Ο„ ⦄" ≔
  (@mkMorphism _ _ _ _ _ _ _ _ _ Ο„ _) (only parsing).
Notation "'RelativeComonadWithCut.make' ⦃ 'Ο„' ≔ Ο„ ⦄" ≔
  (@mkMorphism _ _ _ _ _ _ _ _ _ (RelativeComonad.make ⦃ Ο„ ≔ Ο„ ⦄) _) (only parsing).

Module Morphism.

  Section id_composition.

    Context `{BinaryProduct π’ž} `{BinaryProduct π’Ÿ}
            {F : Functor π’ž π’Ÿ} {E : π’ž} `{!CartesianStrongMonoidal F}.

    Implicit Types (T S U : RelativeComonadWithCut F E).

    Program Definition Hom T S : Setoid ≔
      Setoid.make⦃ Carrier≔ Morphism T S
      ; Equiv≔ _β‰ˆ_ ⦄.
    Show proof.
      constructor.
      - intros f x; reflexivity.
      - intros f g eq_fg x. symmetry. apply eq_fg.
      - intros f g h eq_fg eq_gh; etransitivity; eauto.

    Local Infix "β‡’" ≔ Hom.

    Program Definition id {S} : S β‡’ S ≔
      RelativeComonadWithCut.make ⦃ RelativeComonad-Ο„ ≔ id ⦄.
    Show proof.
      now rewrite left_id, right_id.

    Program Definition compose {S T U} : [ T β‡’ U ⟢ S β‡’ T ⟢ S β‡’ U ] ≔
      Ξ» g f ↦₂ RelativeComonadWithCut.make ⦃ RelativeComonad-Ο„ ≔ g ∘ f ⦄.
    Show proof.
      rewrite compose_assoc. rewrite <- Ο„_cut. repeat rewrite <- compose_assoc.
      now rewrite Ο„_cut.
    Show proof.
      intros f₁ fβ‚‚ eq_f₁fβ‚‚ g₁ gβ‚‚ eq_g₁gβ‚‚ x.
      apply Ξ β‚‚.cong; [ apply eq_f₁fβ‚‚ | apply eq_g₁gβ‚‚ ].

  End id_composition.

End Morphism.

Section CanonicalCut.

  Context `{BinaryProduct π’ž} `{BinaryProduct π’Ÿ}
          {F : Functor π’ž π’Ÿ} (E : π’ž) `{!CartesianStrongMonoidal F}.

  Program Definition ccut (R : RelativeComonad F) : RelativeComonadWithCut F E ≔
    RelativeComonadWithCut.make ⦃ RelativeComonad ≔ R ; cut ≔ Ξ» A βˆ™ lift R Ο€β‚‚[E,A] ⦄.
  Show proof.
    rewrite counit_cobind. reflexivity.
  Show proof.
    do 2 rewrite cobind_cobind. apply Ξ .cong.
    rewrite compose_assoc. rewrite counit_cobind.
    rewrite <- compose_assoc. rewrite FΟ€β‚‚_Ο†_inv. rewrite Ο€β‚‚_compose. reflexivity.

End CanonicalCut.

Notation "↑[ R ]" ≔ (ccut _ R).
Notation "↑[ R ; E ]" ≔ (ccut E R).
Benedikt Ahrens and RΓ©gis Spadotti— Terminal semantics for codata types in intensional Martin-Löf type theory
Table of contents
Index