-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdiscreteness.t
461 lines (332 loc) · 11 KB
/
discreteness.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
$ cat >jd.ny <<EOF
> def Jd (X:Type) (x:X) : X → Type ≔ data [ rfl. : Jd X x x ]
> EOF
Arbitrary types are not discrete:
$ cat >arb.ny <<EOF
> axiom A : Type
> axiom a : A
> def T ≔ A⁽ᵈ⁾ a
> EOF
$ narya -source-only -arity 1 -direction d arb.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ error[E1003]
■ command-line exec string
1 | def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.
^ index
t1
of constructor application doesn't match the corresponding index
t2
of datatype instance
[1]
They remain so even when discreteness is on:
$ narya -source-only -arity 1 -direction d -discreteness arb.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ error[E1003]
■ command-line exec string
1 | def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.
^ index
t1
of constructor application doesn't match the corresponding index
t2
of datatype instance
[1]
There are no discrete datatypes if discreteness is off:
$ cat >natd.ny <<EOF
> def ℕ : Type ≔ data [ zero. | suc. (_:ℕ) ]
> axiom n : ℕ
> def T ≔ ℕ⁽ᵈ⁾ n
> EOF
$ narya -source-only -v -arity 1 -direction d natd.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ constant ℕ defined
→ info[I0001]
○ axiom n assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ error[E1003]
■ command-line exec string
1 | def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.
^ index
t1
of constructor application doesn't match the corresponding index
t2
of datatype instance
[1]
Discrete datatypes are not themselves propositions:
$ cat >nat.ny <<EOF
> def T : Type ≔ data [ zero. | suc. (_:T) ]
> EOF
$ narya -source-only -v -arity 1 -direction d -discreteness nat.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ discrete constant T defined
→ info[I0000]
○ constant Jd defined
→ error[E1003]
■ command-line exec string
1 | def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.
^ index
t1
of constructor application doesn't match the corresponding index
t2
of datatype instance
[1]
But their degenerate versions are:
$ cat >natd.ny <<EOF
> def ℕ : Type ≔ data [ zero. | suc. (_:ℕ) ]
> axiom n : ℕ
> def T ≔ ℕ⁽ᵈ⁾ n
> EOF
$ narya -source-only -v -arity 1 -direction d -discreteness natd.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ discrete constant ℕ defined
→ info[I0001]
○ axiom n assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ info[I0000]
○ constant test defined
Datatypes with nondiscrete parameters are not discrete:
$ cat >param.ny <<EOF
> def List (A:Type) : Type ≔ data [ nil. | cons. (_:A) (_:List A) ]
> axiom A : Type
> axiom l : List A
> def T ≔ (List A)⁽ᵈ⁾ l
$ narya -source-only -v -arity 1 -direction d -discreteness param.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ constant List defined
→ info[I0001]
○ axiom A assumed
→ info[I0001]
○ axiom l assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ error[E1003]
■ command-line exec string
1 | def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.
^ index
t1
of constructor application doesn't match the corresponding index
t2
of datatype instance
[1]
Even trivial parameters:
$ cat >param2.ny <<EOF
> def param_empty (A:Type) : Type ≔ data [ ]
> axiom A : Type
> axiom l : param_empty A
> def T ≔ (param_empty A)⁽ᵈ⁾ l
$ narya -source-only -v -arity 1 -direction d -discreteness param2.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ constant param_empty defined
→ info[I0001]
○ axiom A assumed
→ info[I0001]
○ axiom l assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ error[E1003]
■ command-line exec string
1 | def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.
^ index
t1
of constructor application doesn't match the corresponding index
t2
of datatype instance
[1]
But datatypes with discrete parameters are discrete:
$ cat >param3.ny <<EOF
> def ℕ : Type ≔ data [ zero. | suc. (_:ℕ) ]
> def param_empty (n:ℕ) : Type ≔ data [ ]
> axiom l : param_empty zero.
> def T ≔ (param_empty zero.)⁽ᵈ⁾ l
$ narya -source-only -v -arity 1 -direction d -discreteness param3.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ discrete constant ℕ defined
→ info[I0000]
○ discrete constant param_empty defined
→ info[I0001]
○ axiom l assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ info[I0000]
○ constant test defined
Datatypes with discrete indices are discrete:
$ cat >index.ny <<EOF
> def ℕ : Type ≔ data [ zero. | suc. (_:ℕ) ]
> def iszero : ℕ → Type ≔ data [ iszero. : iszero zero. ]
> axiom n : ℕ
> axiom z : iszero n
> def T ≔ (iszero n)⁽ᵈ⁾ z
$ narya -source-only -v -arity 1 -direction d -discreteness index.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ discrete constant ℕ defined
→ info[I0000]
○ discrete constant iszero defined
→ info[I0001]
○ axiom n assumed
→ info[I0001]
○ axiom z assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ info[I0000]
○ constant test defined
But datatypes with nondiscrete indices, even trivial ones, are not discrete:
$ cat >index2.ny <<EOF
> axiom N : Type
> axiom n : N
> def index_unit : N → Type ≔ data [ foo. : index_unit n ]
> axiom z : index_unit n
> def T ≔ (index_unit n)⁽ᵈ⁾ z
$ narya -source-only -v -arity 1 -direction d -discreteness index2.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0001]
○ axiom N assumed
→ info[I0001]
○ axiom n assumed
→ info[I0000]
○ constant index_unit defined
→ info[I0001]
○ axiom z assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ error[E1003]
■ command-line exec string
1 | def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.
^ index
t1
of constructor application doesn't match the corresponding index
t2
of datatype instance
[1]
Datatypes with constructors having non-discrete arguments are not discrete:
$ cat >constr.ny <<EOF
> def foo : Type ≔ data [ foo. (_:Type) ]
> axiom f : foo
> def T ≔ foo⁽ᵈ⁾ f
$ narya -source-only -v -arity 1 -direction d -discreteness constr.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ constant foo defined
→ info[I0001]
○ axiom f assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ error[E1003]
■ command-line exec string
1 | def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.
^ index
t1
of constructor application doesn't match the corresponding index
t2
of datatype instance
[1]
Trivially mutually datatypes are discrete:
$ cat >mutual2.ny <<EOF
> def empty : Type ≔ data [ ]
> and unit : Type ≔ data [ ]
> axiom e : unit
> def T ≔ unit⁽ᵈ⁾ e
> EOF
$ narya -source-only -v -arity 1 -direction d -discreteness mutual2.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ discrete constants defined mutually:
empty
unit
→ info[I0001]
○ axiom e assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ info[I0000]
○ constant test defined
Nontrivially mutual datatypes can also be discrete, if treating them all as discrete validates all of their discreteness:
$ cat >mutual3.ny <<EOF
> def even : Type ≔ data [ zero. | suc. (_ : odd) ]
> and odd : Type ≔ data [ suc. (_:even) ]
> axiom e : even
> def T ≔ even⁽ᵈ⁾ e
> EOF
$ narya -source-only -v -arity 1 -direction d -discreteness mutual3.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ discrete constants defined mutually:
even
odd
→ info[I0001]
○ axiom e assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ info[I0000]
○ constant test defined
Including if they have discrete indices:
$ cat >mutual4.ny <<EOF
> def ℕ : Type ≔ data [ zero. | suc. (_:ℕ) ]
> def even : ℕ → Type ≔ data [ zero. : even zero. | suc. (n : ℕ) (_ : odd n) : even (suc. n) ]
> and odd : ℕ → Type ≔ data [ suc. (n:ℕ) (_ : even n) : odd (suc. n) ]
> axiom e : even 2
> def T ≔ even⁽ᵈ⁾ 2 2 e
> EOF
$ narya -source-only -v -arity 1 -direction d -discreteness mutual4.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ discrete constant ℕ defined
→ info[I0000]
○ discrete constants defined mutually:
even
odd
→ info[I0001]
○ axiom e assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ info[I0000]
○ constant test defined
But nondiscreteness of any of them throws the others off:
$ cat >mutual5.ny <<EOF
> def empty1 (A : Type) : Type ≔ data []
> and empty2 : Type ≔ data [ ]
> axiom e : empty2
> def T ≔ empty2⁽ᵈ⁾ e
> EOF
$ narya -source-only -v -arity 1 -direction d -discreteness mutual5.ny jd.ny -e 'def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.'
→ info[I0000]
○ constants defined mutually:
empty1
empty2
→ info[I0001]
○ axiom e assumed
→ info[I0000]
○ constant T defined
→ info[I0000]
○ constant Jd defined
→ error[E1003]
■ command-line exec string
1 | def test (t1 : T) (t2 : T) : Jd T t1 t2 ≔ rfl.
^ index
t1
of constructor application doesn't match the corresponding index
t2
of datatype instance
[1]
Some other discrete types:
$ narya -source-only -v -arity 1 -direction d -discreteness -e 'def ℕ : Type ≔ data [ zero. | suc. (_:ℕ) ]' -e 'def ℤ : Type ≔ data [ zero. | suc. (_:ℕ) | negsuc. (_:ℕ) ]' -e 'def btree : Type ≔ data [ leaf. | node. (_:btree) (_:btree) ]'
→ info[I0000]
○ discrete constant ℕ defined
→ info[I0000]
○ discrete constant ℤ defined
→ info[I0000]
○ discrete constant btree defined