Debian Codegraph @

test-suite/bugs/bug_15048.v

raw
1
2
3 Reserved Notation "x = y :> T"
4 (at level 70, y at next level, no associativity).
5 Reserved Notation "x = y" (at level 70, no associativity).
6
7 Reserved Notation "x + y" (at level 50, left associativity).
8
9 Reserved Notation "n .+1" (at level 2, left associativity, format "n .+1").
10 Reserved Notation "n .+2" (at level 2, left associativity, format "n .+2").
11 Reserved Notation "g 'o' f" (at level 40, left associativity).
12 Reserved Notation "! x" (at level 3, format "'!' x").
13 Declare Scope path_scope.
14 Delimit Scope type_scope with type.
15 Delimit Scope trunc_scope with trunc.
16
17 Global Open Scope trunc_scope.
18 Global Open Scope path_scope.
19 Global Open Scope type_scope.
20
21 Global Set Universe Polymorphism.
22
23 Notation "A -> B" := (forall (_ : A), B) : type_scope.
24
25
26 Create HintDb typeclass_instances discriminated.
27
28 Definition Relation (A : Type) := A -> A -> Type.
29
30 Class Symmetric {A} (R : Relation A) :=
31 symmetry : forall x y, R x y -> R y x.
32
33 Notation Type0 := Set.
34
35 Cumulative Inductive paths {A : Type} (a : A) : A -> Type :=
36 idpath : paths a a.
37
38 Arguments idpath {A a} , [A] a.
39
40 Notation "x = y :> A" := (@paths A x y) : type_scope.
41 Notation "x = y" := (x = y :>_) : type_scope.
42
43 Definition inverse {A : Type} {x y : A} (p : x = y) : y = x
44 := match p with idpath => idpath end.
45
46 Global Instance symmetric_paths {A} : Symmetric (@paths A) | 0 := @inverse A.
47
48 Notation "1" := idpath : path_scope.
49
50 Class Contr_internal (A : Type) := Build_Contr {
51 center : A ;
52 contr : (forall y : A, center = y)
53 }.
54
55 Inductive trunc_index : Type :=
56 | minus_two : trunc_index
57 | trunc_S : trunc_index -> trunc_index.
58
59 Bind Scope trunc_scope with trunc_index.
60
61 Notation "n .+1" := (trunc_S n) : trunc_scope.
62 Notation "n .+2" := (n.+1.+1)%trunc : trunc_scope.
63
64 Fixpoint IsTrunc_internal (n : trunc_index) (A : Type) : Type :=
65 match n with
66 | minus_two => Contr_internal A
67 | n'.+1 => forall (x y : A), IsTrunc_internal n' (x = y)
68 end.
69
70 Class IsTrunc (n : trunc_index) (A : Type) : Type :=
71 Trunc_is_trunc : IsTrunc_internal n A.
72
73 Notation Contr := (IsTrunc minus_two).
74 Notation IsHSet := (IsTrunc minus_two.+2).
75
76 Inductive Empty : Type0 := .
77
78 Inductive Unit : Type0 := tt : Unit.
79 Module Export Core.
80 Set Implicit Arguments.
81
82 Delimit Scope morphism_scope with morphism.
83 Delimit Scope category_scope with category.
84 Delimit Scope object_scope with object.
85
86 Record PreCategory :=
87 Build_PreCategory' {
88 object :> Type;
89 morphism : object -> object -> Type;
90
91 identity : forall x, morphism x x;
92 compose : forall s d d',
93 morphism d d'
94 -> morphism s d
95 -> morphism s d'
96 where "f 'o' g" := (compose f g);
97
98 associativity : forall x1 x2 x3 x4
99 (m1 : morphism x1 x2)
100 (m2 : morphism x2 x3)
101 (m3 : morphism x3 x4),
102 (m3 o m2) o m1 = m3 o (m2 o m1);
103
104 associativity_sym : forall x1 x2 x3 x4
105 (m1 : morphism x1 x2)
106 (m2 : morphism x2 x3)
107 (m3 : morphism x3 x4),
108 m3 o (m2 o m1) = (m3 o m2) o m1;
109
110 left_identity : forall a b (f : morphism a b), identity b o f = f;
111 right_identity : forall a b (f : morphism a b), f o identity a = f;
112
113 identity_identity : forall x, identity x o identity x = identity x;
114
115 trunc_morphism : forall s d, IsHSet (morphism s d)
116 }.
117
118 Bind Scope category_scope with PreCategory.
119 Arguments identity {!C%_category} / x%_object : rename.
120 Arguments compose {!C%_category} / {s d d'}%_object (m1 m2)%_morphism : rename.
121
122 Infix "o" := compose : morphism_scope.
123
124 End Core.
125 Delimit Scope functor_scope with functor.
126
127 Local Open Scope morphism_scope.
128
129 Section Functor.
130 Variables C D : PreCategory.
131
132 Record Functor :=
133 {
134 object_of :> C -> D;
135 morphism_of : forall s d, morphism C s d
136 -> morphism D (object_of s) (object_of d);
137 composition_of : forall s d d'
138 (m1 : morphism C s d) (m2: morphism C d d'),
139 morphism_of _ _ (m2 o m1)
140 = (morphism_of _ _ m2) o (morphism_of _ _ m1);
141 identity_of : forall x, morphism_of _ _ (identity x)
142 = identity (object_of x)
143 }.
144 End Functor.
145
146 Generalizable Variables A B m n f.
147
148 Fixpoint trunc_index_inc (k : trunc_index) (n : nat)
149 : trunc_index
150 := match n with
151 | O => k
152 | S m => (trunc_index_inc k m).+1
153 end.
154
155 Definition nat_to_trunc_index (n : nat) : trunc_index
156 := (trunc_index_inc minus_two n).+2.
157
158 Definition int_to_trunc_index (v : Decimal.int) : option trunc_index
159 := match v with
160 | Decimal.Pos d => Some (nat_to_trunc_index (Nat.of_uint d))
161 | Decimal.Neg d => match Nat.of_uint d with
162 | 2%nat => Some minus_two
163 | 1%nat => Some (minus_two.+1)
164 | 0 => Some (minus_two.+2)
165 | _ => None
166 end
167 end.
168
169 Definition num_int_to_trunc_index v : option trunc_index :=
170 match Nat.of_num_int v with
171 | Some n => Some (nat_to_trunc_index n)
172 | None => None
173 end.
174
175 Fixpoint trunc_index_to_little_uint n acc :=
176 match n with
177 | minus_two => acc
178 | minus_two.+1 => acc
179 | minus_two.+2 => acc
180 | trunc_S n => trunc_index_to_little_uint n (Decimal.Little.succ acc)
181 end.
182
183 Definition trunc_index_to_int n :=
184 match n with
185 | minus_two => Decimal.Neg (Nat.to_uint 2)
186 | minus_two.+1 => Decimal.Neg (Nat.to_uint 1)
187 | n => Decimal.Pos (Decimal.rev (trunc_index_to_little_uint n Decimal.zero))
188 end.
189
190 Definition trunc_index_to_num_int n :=
191 Number.IntDecimal (trunc_index_to_int n).
192
193
194 Global Instance istrunc_succ `{IsTrunc n A}
195 : IsTrunc n.+1 A | 1000.
196 Admitted.
197
198 Global Instance contr_unit : Contr Unit | 0 := let x := {|
199 center := tt;
200 contr := fun t : Unit => match t with tt => 1 end
201 |} in x.
202
203 Definition groupoid_category X `{IsTrunc (trunc_S (trunc_S (trunc_S minus_two))) X} : PreCategory.
204 Admitted.
205 Definition discrete_category X `{IsHSet X} := groupoid_category X.
206 Section indiscrete_category.
207
208 Variable X : Type.
209
210 Definition indiscrete_category : PreCategory
211 := @Build_PreCategory' X
212 (fun _ _ => Unit)
213 (fun _ => tt)
214 (fun _ _ _ _ _ => tt)
215 (fun _ _ _ _ _ _ _ => idpath)
216 (fun _ _ _ _ _ _ _ => idpath)
217 (fun _ _ f => match f with tt => idpath end)
218 (fun _ _ f => match f with tt => idpath end)
219 (fun _ => idpath)
220 _.
221 End indiscrete_category.
222 Local Open Scope nat_scope.
223
224 Fixpoint CardinalityRepresentative (n : nat) : Type0 :=
225 match n with
226 | 0 => Empty
227 | 1 => Unit
228 | S n' => (CardinalityRepresentative n' + Unit)%type
229 end.
230
231 Coercion CardinalityRepresentative : nat >-> Sortclass.
232
233 Global Instance trunc_cardinality_representative (n : nat)
234 : IsHSet (CardinalityRepresentative n).
235 Admitted.
236
237 Definition nat_category (n : nat) :=
238 match n with
239 | 0 => indiscrete_category 0
240 | 1 => indiscrete_category 1
241 | S (S n') => discrete_category (S (S n'))
242 end.
243 Notation "1" := (nat_category 1) : category_scope.
244 Notation terminal_category := (nat_category 1) (only parsing).
245
246 Class IsTerminalCategory (C : PreCategory)
247 `{Contr (object C)}
248 `{forall s d, Contr (morphism C s d)} := {}.
249 Global Instance: IsTerminalCategory 1 | 0 := {}.
250 Generalizable All Variables.
251
252 Section functors.
253 Variable C : PreCategory.
254
255 Definition from_terminal `{@IsTerminalCategory one Hone Hone'} (c : C)
256 : Functor one C
257 := Build_Functor
258 one C
259 (fun _ => c)
260 (fun _ _ _ => identity c)
261 (fun _ _ _ _ _ => symmetry _ _ (@identity_identity _ _))
262 (fun _ => idpath).
263 End functors.
264
265 Local Notation "! x" := (@from_terminal _ terminal_category _ _ _ x) : functor_scope.
266
267 Definition CC_Functor' (C : PreCategory) (D : PreCategory) := Functor C D.
268
269 Coercion cc_functor_from_terminal' (C : PreCategory) (x : C) : CC_Functor' _ C
270 := (!x)%functor.