annotate maybeCat.agda @ 411:33958fdfc77e

add reasoning
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 23 Mar 2016 11:29:45 +0900
parents 07bea66e5ceb
children b5519e954b57
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
411
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
33 module ≡≡-Reasoning { c₁ c₂ ℓ : Level} ( A : Category c₁ c₂ ℓ ) where
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
34
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
35 infixr 2 _∎
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
36 infixr 2 _≡≡⟨_⟩_ _≡≡⟨⟩_
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
37 infix 1 begin_
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
38
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
39 ≡≡-refl : {a b : Obj A } -> {x : Maybe ( Hom A a b ) } → A [ x ≡≡ x ]
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
40 ≡≡-refl {_} {_} {just x} = just refl-hom where open ≈-Reasoning (A)
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
41 ≡≡-refl {_} {_} {nothing} = nothing
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
42
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
43 ≡≡-sym : {a b : Obj A } -> {x y : Maybe ( Hom A a b ) } → A [ x ≡≡ y ] → A [ y ≡≡ x ]
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
44 ≡≡-sym (just x≈y) = just (sym x≈y) where open ≈-Reasoning (A)
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
45 ≡≡-sym nothing = nothing
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
46
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
47 ≡≡-trans : {a b : Obj A } -> {x y z : Maybe ( Hom A a b ) } → A [ x ≡≡ y ] → A [ y ≡≡ z ] → A [ x ≡≡ z ]
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
48 ≡≡-trans (just x≈y) (just y≈z) = just (trans-hom x≈y y≈z) where open ≈-Reasoning (A)
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
49 ≡≡-trans nothing nothing = nothing
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
50
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
51
411
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
52 data _IsRelatedTo_ {a b : Obj A} (x y : (Maybe (Hom A a b ))) :
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
53 Set (ℓ ⊔ c₂) where
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
54 relTo : (x≈y : A [ x ≡≡ y ] ) → x IsRelatedTo y
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
55
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
56 begin_ : {a b : Obj A} {x : Maybe (Hom A a b ) } {y : Maybe (Hom A a b )} →
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
57 x IsRelatedTo y → A [ x ≡≡ y ]
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
58 begin relTo x≈y = x≈y
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
59
411
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
60 _≡≡⟨_⟩_ : {a b : Obj A} (x : Maybe (Hom A a b )) {y z : Maybe (Hom A a b ) } →
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
61 A [ x ≡≡ y ] → y IsRelatedTo z → x IsRelatedTo z
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
62 _ ≡≡⟨ x≈y ⟩ relTo y≈z = relTo (≡≡-trans x≈y y≈z)
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
63
411
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
64 _≡≡⟨⟩_ : {a b : Obj A} (x : Maybe (Hom A a b )) {y : Maybe (Hom A a b )}
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
65 → x IsRelatedTo y → x IsRelatedTo y
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
66 _ ≡≡⟨⟩ x≈y = x≈y
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
67
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
68 _∎ : {a b : Obj A} (x : Maybe (Hom A a b )) → x IsRelatedTo x
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
69 _∎ _ = relTo ≡≡-refl
398
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
402
9123f79c0642 on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 399
diff changeset
72 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
73 MaybeCat { c₁} {c₂} {ℓ} ( A ) = record {
398
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 Obj = Obj A ;
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 Hom = λ a b → MaybeHom A a b ;
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
76 _o_ = _+_ ;
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
77 _≈_ = λ 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
78 Id = \{a} -> MaybeHomId a ;
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 isCategory = record {
411
33958fdfc77e add reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 404
diff changeset
80 isEquivalence = let open ≡≡-Reasoning (A) in record {refl = ≡≡-refl ; trans = ≡≡-trans ; sym = ≡≡-sym } ;
399
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
81 identityL = \{a b f} -> identityL {a} {b} {f} ;
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
82 identityR = \{a b f} -> identityR {a} {b} {f};
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
83 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
84 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
85 }
64aa49a18469 add Maybe Category
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 } where
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
87 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
88 identityL {a} {b} {f} with hom f
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
89 identityL {a} {b} {_} | nothing = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
90 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
91
403
375edfefbf6a maybe CAT
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 402
diff changeset
92 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
93 identityR {a} {b} {f} with hom f
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
94 identityR {a} {b} {_} | nothing = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
95 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
96
402
9123f79c0642 on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 399
diff changeset
97 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
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
106
402
9123f79c0642 on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 399
diff changeset
107 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
108 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
109 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
110 associative {_} {_} {_} {_} {f} {g} {h} | nothing | _ | _ = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
111 associative {_} {_} {_} {_} {f} {g} {h} | just _ | nothing | _ = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
112 associative {_} {_} {_} {_} {f} {g} {h} | just _ | just _ | nothing = nothing
8304007dc2f8 maybe category done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
113 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
114 just ( IsCategory.associative ( Category.isCategory A ) {a} {b} {c} {d} {f} {g} {h} )