annotate maybeCat.agda @ 403:375edfefbf6a

maybe CAT
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 20 Mar 2016 11:36:44 +0900
parents 9123f79c0642
children 07bea66e5ceb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
398
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 open import Category -- https://github.com/konn/category-agda
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 open import Level
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
402
9123f79c0642 on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 399
diff changeset
4 module maybeCat where
398
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import cat-utility
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import HomReasoning
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Relation.Binary
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Data.Maybe
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open Functor
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 record MaybeHom { c₁ c₂ ℓ : Level} ( A : Category c₁ c₂ ℓ ) (a : Obj A ) (b : Obj A ) : Set (ℓ ⊔ c₂) where
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 field
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 hom : Maybe ( Hom A a b )
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 open MaybeHom
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
20 _+_ : { c₁ c₂ ℓ : Level} -> { A : Category c₁ c₂ ℓ } -> {a b c : Obj A } → MaybeHom A b c → MaybeHom A a b → MaybeHom A a c
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
21 _+_ {x} {y} {z} {A} {a} {b} {c} f g with hom f | hom g
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
22 _+_ {_} {_} {_} {A} {a} {b} {c} f g | nothing | _ = record { hom = nothing }
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
23 _+_ {_} {_} {_} {A} {a} {b} {c} f g | _ | nothing = record { hom = nothing }
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
24 _+_ {_} {_} {_} {A} {a} {b} {c} _ _ | (just f) | (just g) = record { hom = just ( A [ f o g ] ) }
398
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
402
9123f79c0642 on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 399
diff changeset
26 MaybeHomId : { c₁ c₂ ℓ : Level} { A : Category c₁ c₂ ℓ } (a : Obj A ) -> MaybeHom A a a
9123f79c0642 on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 399
diff changeset
27 MaybeHomId {_} {_} {_} {A} a = record { hom = just ( id1 A a) }
398
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
29 _[_≡≡_] : { c₁ c₂ ℓ : Level} ( A : Category c₁ c₂ ℓ ) {a b : Obj A } -> Rel (Maybe (Hom A a b)) (c₂ ⊔ ℓ)
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
30 _[_≡≡_] A = Eq ( Category._≈_ A )
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
31
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
32
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
33 *refl : { c₁ c₂ ℓ : Level} -> { A : Category c₁ c₂ ℓ } -> {a b : Obj A } -> {x : Maybe ( Hom A a b ) } → A [ x ≡≡ x ]
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
34 *refl {_} {_} {_} {A} {_} {_} {just x} = just refl-hom where open ≈-Reasoning (A)
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
35 *refl {_} {_} {_} {A} {_} {_} {nothing} = nothing
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
36
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
37 *sym : { c₁ c₂ ℓ : Level} -> { A : Category c₁ c₂ ℓ } -> {a b : Obj A } -> {x y : Maybe ( Hom A a b ) } → A [ x ≡≡ y ] → A [ y ≡≡ x ]
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
38 *sym {_} {_} {_} {A} (just x≈y) = just (sym x≈y) where open ≈-Reasoning (A)
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
39 *sym {_} {_} {_} {A} nothing = nothing
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
40
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
41 *trans : { c₁ c₂ ℓ : Level} -> { A : Category c₁ c₂ ℓ } -> {a b : Obj A } -> {x y z : Maybe ( Hom A a b ) } → A [ x ≡≡ y ] → A [ y ≡≡ z ] → A [ x ≡≡ z ]
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
42 *trans {_} {_} {_} {A} (just x≈y) (just y≈z) = just (trans-hom x≈y y≈z) where open ≈-Reasoning (A)
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
43 *trans {_} {_} {_} {A} nothing nothing = nothing
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
44
398
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
402
9123f79c0642 on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 399
diff changeset
47 MaybeCat : { c₁ c₂ ℓ : Level} ( A : Category c₁ c₂ ℓ ) -> Category c₁ (ℓ ⊔ c₂) (ℓ ⊔ c₂)
9123f79c0642 on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 399
diff changeset
48 MaybeCat { c₁} {c₂} {ℓ} ( A ) = record {
398
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 Obj = Obj A ;
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 Hom = λ a b → MaybeHom A a b ;
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
51 _o_ = _+_ ;
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
52 _≈_ = λ a b → _[_≡≡_] { c₁} {c₂} {ℓ} A (hom a) (hom b) ;
398
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 Id = \{a} -> MaybeHomId a ;
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 isCategory = record {
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
55 isEquivalence = record {refl = *refl {_} {_} {_} {A}; trans = *trans {_} {_} {_} {A}; sym = *sym {_} {_} {_} {A}};
399
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
56 identityL = \{a b f} -> identityL {a} {b} {f} ;
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
57 identityR = \{a b f} -> identityR {a} {b} {f};
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
58 o-resp-≈ = \{a b c f g h i} -> o-resp-≈ {a} {b} {c} {f} {g} {h} {i} ;
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
59 associative = \{a b c d f g h } -> associative {a } { b } { c } { d } { f } { g } { h }
398
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 } where
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 open ≈-Reasoning (A)
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
63 identityL : { a b : Obj A } { f : MaybeHom A a b } -> A [ hom (MaybeHomId b + f) ≡≡ hom f ]
399
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
64 identityL {a} {b} {f} with hom f
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
65 identityL {a} {b} {_} | nothing = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
66 identityL {a} {b} {_} | just f = just ( IsCategory.identityL ( Category.isCategory A ) {a} {b} {f} )
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
67
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
68 identityR : { a b : Obj A } { f : MaybeHom A a b } -> A [ hom (f + MaybeHomId a ) ≡≡ hom f ]
399
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
69 identityR {a} {b} {f} with hom f
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
70 identityR {a} {b} {_} | nothing = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
71 identityR {a} {b} {_} | just f = just ( IsCategory.identityR ( Category.isCategory A ) {a} {b} {f} )
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
72
402
9123f79c0642 on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 399
diff changeset
73 o-resp-≈ : {a b c : Obj A} → {f g : MaybeHom A a b } → {h i : MaybeHom A b c } →
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
74 A [ hom f ≡≡ hom g ] → A [ hom h ≡≡ hom i ] → A [ hom (h + f) ≡≡ hom (i + g) ]
399
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
75 o-resp-≈ {a} {b} {c} {f} {g} {h} {i} eq-fg eq-hi with hom f | hom g | hom h | hom i
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
76 o-resp-≈ {a} {b} {c} {_} {_} {_} {_} (just eq-fg) (just eq-hi) | just f | just g | just h | just i =
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
77 just ( IsCategory.o-resp-≈ ( Category.isCategory A ) {a} {b} {c} {f} {g} {h} {i} eq-fg eq-hi )
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
78 o-resp-≈ {a} {b} {c} {f} {g} {h} {i} (just _) nothing | just _ | just _ | nothing | nothing = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
79 o-resp-≈ {a} {b} {c} {f} {g} {h} {i} nothing (just _) | nothing | nothing | just _ | just _ = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
80 o-resp-≈ {a} {b} {c} {f} {g} {h} {i} nothing nothing | nothing | nothing | nothing | nothing = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
81
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
82
402
9123f79c0642 on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 399
diff changeset
83 associative : {a b c d : Obj A} → {f : MaybeHom A c d } → {g : MaybeHom A b c } → {h : MaybeHom A a b } →
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
84 A [ hom (f + (g + h)) ≡≡ hom ((f + g) + h) ]
399
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
85 associative {_} {_} {_} {_} {f} {g} {h} with hom f | hom g | hom h
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
86 associative {_} {_} {_} {_} {f} {g} {h} | nothing | _ | _ = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
87 associative {_} {_} {_} {_} {f} {g} {h} | just _ | nothing | _ = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
88 associative {_} {_} {_} {_} {f} {g} {h} | just _ | just _ | nothing = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
89 associative {a} {b} {c} {d} {_} {_} {_} | just f | just g | just h =
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
90 just ( IsCategory.associative ( Category.isCategory A ) {a} {b} {c} {d} {f} {g} {h} )