|
| 1 | +{-# OPTIONS --safe --without-K #-} |
| 2 | + |
| 3 | +module EchoCategorical where |
| 4 | + |
| 5 | +open import Echo |
| 6 | +open import EchoRelational using (EchoStep; RelMap; map-rel; map-rel-id; map-rel-comp) |
| 7 | + |
| 8 | +open import Level using (Level; _⊔_) |
| 9 | +open import Function.Base using (id; _∘_) |
| 10 | +open import Data.Product.Base using (Σ; _,_; proj₁) |
| 11 | +open import Relation.Binary.PropositionalEquality using (_≡_; refl; trans; subst) |
| 12 | + |
| 13 | +-- Phase D (part 1): slice-style packaging for deterministic maps. |
| 14 | +record SliceHom |
| 15 | + {a a' b} {A : Set a} {A' : Set a'} {B : Set b} |
| 16 | + (f : A → B) (f' : A' → B) : Set (a ⊔ a' ⊔ b) where |
| 17 | + field |
| 18 | + arrow : A → A' |
| 19 | + commute : ∀ x → f' (arrow x) ≡ f x |
| 20 | + |
| 21 | +open SliceHom public |
| 22 | + |
| 23 | +slice-to-mapover : |
| 24 | + ∀ {a a' b} {A : Set a} {A' : Set a'} {B : Set b} |
| 25 | + {f : A → B} {f' : A' → B} → |
| 26 | + SliceHom f f' → MapOver f f' |
| 27 | +slice-to-mapover h = arrow h , commute h |
| 28 | + |
| 29 | +mapover-to-slice : |
| 30 | + ∀ {a a' b} {A : Set a} {A' : Set a'} {B : Set b} |
| 31 | + {f : A → B} {f' : A' → B} → |
| 32 | + MapOver f f' → SliceHom f f' |
| 33 | +mapover-to-slice (u , c) = record { arrow = u ; commute = c } |
| 34 | + |
| 35 | +slice-id : |
| 36 | + ∀ {a b} {A : Set a} {B : Set b} (f : A → B) → |
| 37 | + SliceHom f f |
| 38 | +slice-id f = record |
| 39 | + { arrow = id |
| 40 | + ; commute = λ _ → refl |
| 41 | + } |
| 42 | + |
| 43 | +slice-comp : |
| 44 | + ∀ {a a' a'' b} |
| 45 | + {A : Set a} {A' : Set a'} {A'' : Set a''} {B : Set b} |
| 46 | + {f : A → B} {f' : A' → B} {f'' : A'' → B} → |
| 47 | + SliceHom f f' → SliceHom f' f'' → SliceHom f f'' |
| 48 | +slice-comp h₁ h₂ = record |
| 49 | + { arrow = arrow h₂ ∘ arrow h₁ |
| 50 | + ; commute = λ x → trans (commute h₂ (arrow h₁ x)) (commute h₁ x) |
| 51 | + } |
| 52 | + |
| 53 | +slice-act : |
| 54 | + ∀ {a a' b} {A : Set a} {A' : Set a'} {B : Set b} |
| 55 | + {f : A → B} {f' : A' → B} → |
| 56 | + SliceHom f f' → ∀ {y : B} → Echo f y → Echo f' y |
| 57 | +slice-act h = map-over (slice-to-mapover h) |
| 58 | + |
| 59 | +slice-act-id : |
| 60 | + ∀ {a b} {A : Set a} {B : Set b} |
| 61 | + {f : A → B} {y : B} (e : Echo f y) → |
| 62 | + slice-act (slice-id f) e ≡ e |
| 63 | +slice-act-id = map-over-id |
| 64 | + |
| 65 | +slice-act-comp : |
| 66 | + ∀ {a a' a'' b} |
| 67 | + {A : Set a} {A' : Set a'} {A'' : Set a''} {B : Set b} |
| 68 | + {f : A → B} {f' : A' → B} {f'' : A'' → B} |
| 69 | + (h₁ : SliceHom f f') (h₂ : SliceHom f' f'') |
| 70 | + {y : B} (e : Echo f y) → |
| 71 | + slice-act (slice-comp h₁ h₂) e ≡ |
| 72 | + slice-act h₂ (slice-act h₁ e) |
| 73 | +slice-act-comp h₁ h₂ = map-over-comp (arrow h₁) (commute h₁) (arrow h₂) (commute h₂) |
| 74 | + |
| 75 | +-- Phase D (part 2): fibration-style packaging for relational semantics. |
| 76 | +module Fibration {s o r} {S : Set s} {O : Set o} (Step : S → O → Set r) where |
| 77 | + |
| 78 | + Fiber : O → Set (s ⊔ r) |
| 79 | + Fiber = EchoStep Step |
| 80 | + |
| 81 | + Total : Set (s ⊔ o ⊔ r) |
| 82 | + Total = Σ O Fiber |
| 83 | + |
| 84 | + π : Total → O |
| 85 | + π = proj₁ |
| 86 | + |
| 87 | + fiber-to-echo : |
| 88 | + ∀ {out : O} → Fiber out → Echo π out |
| 89 | + fiber-to-echo {out} e = (out , e) , refl |
| 90 | + |
| 91 | + echo-to-fiber : |
| 92 | + ∀ {out : O} → Echo π out → Fiber out |
| 93 | + echo-to-fiber ((out' , e) , p) = subst Fiber p e |
| 94 | + |
| 95 | + echo-to-fiber∘fiber-to-echo : |
| 96 | + ∀ {out : O} (e : Fiber out) → |
| 97 | + echo-to-fiber (fiber-to-echo e) ≡ e |
| 98 | + echo-to-fiber∘fiber-to-echo e = refl |
| 99 | + |
| 100 | + fiber-map : |
| 101 | + ∀ {s' r'} {S' : Set s'} {Step' : S' → O → Set r'} → |
| 102 | + RelMap Step Step' → ∀ {out : O} → Fiber out → EchoStep Step' out |
| 103 | + fiber-map = map-rel |
| 104 | + |
| 105 | + fiber-map-id : |
| 106 | + ∀ {out : O} (e : Fiber out) → |
| 107 | + fiber-map (id , (λ {st} {out} p → p)) e ≡ e |
| 108 | + fiber-map-id e = map-rel-id {Step = Step} e |
| 109 | + |
| 110 | + rel-fiber-map-comp : |
| 111 | + ∀ {s' s'' r' r''} |
| 112 | + {S' : Set s'} {S'' : Set s''} |
| 113 | + {Step' : S' → O → Set r'} |
| 114 | + {Step'' : S'' → O → Set r''} |
| 115 | + (u₁ : S → S') (pres₁ : ∀ {st out} → Step st out → Step' (u₁ st) out) |
| 116 | + (u₂ : S' → S'') (pres₂ : ∀ {st out} → Step' st out → Step'' (u₂ st) out) |
| 117 | + {out : O} (e : Fiber out) → |
| 118 | + map-rel {Step = Step} {Step' = Step''} |
| 119 | + (u₂ ∘ u₁ , λ p → pres₂ (pres₁ p)) e |
| 120 | + ≡ map-rel {Step = Step'} {Step' = Step''} (u₂ , pres₂) |
| 121 | + (map-rel {Step = Step} {Step' = Step'} (u₁ , pres₁) e) |
| 122 | + rel-fiber-map-comp {Step' = Step'} {Step'' = Step''} u₁ pres₁ u₂ pres₂ e = |
| 123 | + map-rel-comp {Step = Step} {Step' = Step'} {Step'' = Step''} |
| 124 | + u₁ pres₁ u₂ pres₂ e |
0 commit comments