-
Notifications
You must be signed in to change notification settings - Fork 63
/
Prelude.sawcore
2345 lines (1900 loc) · 93 KB
/
Prelude.sawcore
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Copyright : Galois, Inc. 2012-2014
-- License : BSD3
-- Maintainer : jhendrix@galois.com
module Prelude where
-- Grammar for the core prelude types.
--
-- We use single colons ":" to represent the type constraint on the core symbols.
-- e.g., "Bool : sort 0" indicates "Bool" has type "sort 0".
-- Functions use "->" to separate arguments from result.
-- e.g., "f : Bool -> Bool -> Bool" indicates "f" is a binary operation on Booleans.
id : (a : sort 0) -> a -> a;
id _ x = x;
-- FIXME: We eventually need to remove this, as it violates soundness...
primitive fix : (a : sort 1) -> (a -> a) -> a;
-- FIXME: below are some defined data-types that could be used in place of
-- the SAW primitive types
--------------------------------------------------------------------------------
-- The Unit type
data UnitType : sort 0 where {
Unit : UnitType;
}
-- The recursor for the Unit type at sort 0
-- UnitType__rec : (p : UnitType -> sort 0) -> p Unit -> (u : UnitType) -> p u;
-- UnitType__rec p f1 u = UnitType#rec p f1 u;
UnitType__rec (p : UnitType -> sort 0) (f1 : p Unit) (u : UnitType) : p u
= UnitType#rec p f1 u;
--------------------------------------------------------------------------------
-- Pair types
data PairType (a b : sort 0) : sort 0 where {
PairValue : a -> b -> PairType a b;
}
pair_example : (a b : sort 0) -> a -> b -> PairType a b;
pair_example a b x y = PairValue a b x y;
-- The recursor for primitive pair types at sort 1
Pair__rec
(a b : sort 0)
(p : PairType a b -> sort 0)
(f : (x:a) -> (y:b) -> p (PairValue a b x y))
(pair : PairType a b)
: p pair
= PairType#rec a b p f pair;
Pair_fst : (a b : sort 0) -> PairType a b -> a;
Pair_fst a b = Pair__rec a b (\ (p:PairType a b) -> a)
(\ (x:a) -> \ (y: b) -> x);
Pair_snd : (a b : sort 0) -> PairType a b -> b;
Pair_snd a b = Pair__rec a b (\ (p:PairType a b) -> b)
(\ (x:a) -> \ (y:b) -> y);
fst : (a b : sort 0) -> a * b -> a;
fst a b tup = tup.(1);
snd : (a b : sort 0) -> a * b -> b;
snd a b tup = tup.(2);
uncurry (a b c : sort 0) (f : a -> b -> c) : a * b -> c
= (\ (x : a * b) -> f x.(1) x.(2));
--------------------------------------------------------------------------------
-- String values
primitive String : sort 0;
primitive error : (a : isort 1) -> String -> a;
--------------------------------------------------------------------------------
-- Record types
-- The empty record
data EmptyType : sort 0 where {
Empty : EmptyType;
}
-- The recursor for the empty type at sort 0
EmptyType__rec : (p : EmptyType -> sort 0) -> p Empty ->
(emp : EmptyType) -> p emp;
EmptyType__rec p f1 emp = EmptyType#rec p f1 emp;
-- Add a named field to a record type
data RecordType (s:String) (a b :sort 0) : sort 0 where {
RecordValue : a -> b -> RecordType s a b;
}
-- The recursor for record types at sort 0
RecordType__rec
(s : String)
(a b :sort 0)
(p : RecordType s a b -> sort 1)
(f1 : (x:a) -> (y:b) -> p (RecordValue s a b x y))
(r : RecordType s a b)
: p r
= RecordType#rec s a b p f1 r;
--------------------------------------------------------------------------------
-- Equality proofs.
data Eq (t : sort 1) (x : t) : t -> Prop where {
Refl : Eq t x x;
}
-- The eliminator for the Eq type at sort 1, assuming the usual parameter-index
-- structure of the Eq type
Eq__rec : (t : sort 1) -> (x : t) -> (p : (y : t) -> Eq t x y -> sort 1) ->
p x (Refl t x) -> (y : t) -> (pf : Eq t x y) -> p y pf;
Eq__rec t x p f1 y pf = Eq#rec t x p f1 y pf;
-- Congruence closure for equality
eq_cong : (t : sort 1) -> (x : t) -> (y : t) -> Eq t x y ->
(u : sort 1) -> (f : t -> u) -> Eq u (f x) (f y);
eq_cong t x y eq u f =
Eq__rec t x (\ (y':t) -> \ (eq':Eq t x y') -> Eq u (f x) (f y'))
(Refl u (f x)) y eq;
sym : (a : sort 1) -> (x y : a) -> Eq a x y -> Eq a y x;
sym a x y eq =
Eq__rec a x (\ (y':a) -> \ (eq':Eq a x y') -> Eq a y' x) (Refl a x) y eq;
trans : (a : sort 1) -> (x y z : a) -> Eq a x y -> Eq a y z -> Eq a x z;
trans a x y z eq1 eq2 =
Eq__rec a y (\ (y':a) -> \ (eq':Eq a y y') -> Eq a x y') eq1 z eq2;
trans2 : (a : sort 1) -> (x y z : a) -> Eq a x z -> Eq a y z -> Eq a x y;
trans2 a x y z eq1 eq2 = trans a x z y eq1 (sym a y z eq2);
trans4 : (a : sort 1) -> (w x y z : a) ->
Eq a w x -> Eq a x y -> Eq a y z -> Eq a w z;
trans4 a w x y z eq1 eq2 eq3 =
trans a w x z eq1 (trans a x y z eq2 eq3);
eq_inv_map : (a b : sort 1) -> (a1 a2 : a) -> Eq a a1 a2 ->
(f1 f2 : a -> b) -> Eq b (f1 a2) (f2 a2) ->
Eq b (f1 a1) (f2 a1);
eq_inv_map a b a1 a2 eq_a f1 f2 eq_f =
trans
b (f1 a1) (f1 a2) (f2 a1)
(eq_cong a a1 a2 eq_a b f1)
(trans b (f1 a2) (f2 a2) (f2 a1) eq_f
(eq_cong a a2 a1 (sym a a1 a2 eq_a) b f2));
-- Unchecked assertion that two types are equal.
axiom unsafeAssert : (a : sort 1) -> (x : a) -> (y : a) -> Eq a x y;
primitive coerce : (a b : sort 0) -> Eq (sort 0) a b -> a -> b;
coerce__def : (a b : sort 0) -> Eq (sort 0) a b -> a -> b;
coerce__def a b eq x =
Eq__rec (sort 0) a (\ (b':sort 0) -> \ (eq':Eq (sort 0) a b') -> b') x b eq;
axiom coerce__eq :
Eq ((a b : sort 0) -> Eq (sort 0) a b -> a -> b) coerce coerce__def;
-- NOTE: this is equivalent to UIP / Axiom K
{-
coerce_same : (a : sort 0) -> (q : Eq (sort 0) a a) -> (x : a) -> Eq a (coerce a a q x) x;
coerce_same a (Refl _ _) x = Refl a x;
-}
rcoerce : (a b : sort 0) -> Eq (sort 0) a b -> b -> a;
rcoerce a b q = coerce b a (sym (sort 0) a b q);
-- NOTE: this is equivalent to UIP / Axiom K
{-
rcoerce_same : (a : sort 0) -> (q : Eq (sort 0) a a) -> (x : a) -> Eq a (rcoerce a a q x) x;
rcoerce_same a q x = coerce_same a (sym (sort 0) a a q) x;
-}
unsafeCoerce : (a b : sort 0) -> a -> b;
unsafeCoerce a b = coerce a b (unsafeAssert (sort 0) a b);
axiom unsafeCoerce_same : (a : sort 0) -> (x : a) ->
Eq a (unsafeCoerce a a x) x;
-- NOTE: We could prove unsafeCoerce_same if we were willing to allow UIP...
{-
unsafeCoerce_same : (a : sort 0) -> (x : a) -> Eq a (unsafeCoerce a a x) x;
unsafeCoerce_same a x = coerce_same a (unsafeAssert (sort 0) a a) x;
-}
piCong0 : (r x y : sort 0) -> Eq (sort 0) x y -> (Eq (sort 0) (x -> r) (y -> r));
piCong0 r x y eq =
Eq__rec
(sort 0) x
(\ (y': sort 0) -> \ (eq': Eq (sort 0) x y') ->
Eq (sort 0) (x -> r) (y' -> r))
(Refl (sort 0) (x -> r)) y eq;
piCong1 : (r x y : sort 0) -> Eq (sort 0) x y -> (Eq (sort 0) (r -> x) (r -> y));
piCong1 r x y eq =
Eq__rec
(sort 0) x
(\ (y': sort 0) -> \ (eq': Eq (sort 0) x y') ->
Eq (sort 0) (r -> x) (r -> y'))
(Refl (sort 0) (r -> x)) y eq;
--------------------------------------------------------------------------------
-- Bits
data Bit : sort 0 where {
Bit1 : Bit;
Bit0 : Bit;
}
Bit__rec : (p : Bit -> sort 1) -> (p Bit1) -> (p Bit0) -> (b:Bit) -> p b;
Bit__rec p f1 f2 b = Bit#rec p f1 f2 b;
--------------------------------------------------------------------------------
-- Booleans
-- Boolean is a primitive type, because it is handled specially by some of the
-- back-ends (e.g., the SAT/SMT solvers)
primitive Bool : sort 0;
primitive True : Bool;
primitive False : Bool;
-- Elimination form for Bool is dependent if-then-else. This is exactly the same
-- as the recursor for Bit, but it is declared as a primitive because Bool is.
-- It also rearranges the arguments to look more like normal if-then-else.
primitive iteDep : (p : Bool -> sort 1) -> (b:Bool) ->
p True -> p False -> p b;
-- Reduction rules for iteDep
axiom iteDep_True : (p : Bool -> sort 1) -> (f1:p True) -> (f2:p False) ->
Eq (p True) (iteDep p True f1 f2) f1;
axiom iteDep_False : (p : Bool -> sort 1) -> (f1:p True) -> (f2:p False) ->
Eq (p False) (iteDep p False f1 f2) f2;
-- Non-dependent if-then-else; this is a primitive because it is handled
-- specially by some of the back-ends (e.g., the SAT/SMT solvers)
primitive ite : (a : sort 1) -> Bool -> a -> a -> a;
-- ite should be the same as iteDep
axiom ite_eq_iteDep : (a:sort 1) -> (b:Bool) -> (x y:a) ->
Eq a (ite a b x y) (iteDep (\ (_:Bool) -> a) b x y);
ite_true (a : sort 1) (x y : a) : Eq a (ite a True x y) x =
trans a (ite a True x y) (iteDep (\ (b:Bool) -> a) True x y) x
(ite_eq_iteDep a True x y) (iteDep_True (\ (_:Bool) -> a) x y);
ite_false (a : sort 1) (x y : a) : Eq a (ite a False x y) y =
trans a (ite a False x y) (iteDep (\ (b:Bool) -> a) False x y) y
(ite_eq_iteDep a False x y) (iteDep_False (\ (_:Bool) -> a) x y);
--
-- Converting between Bools and Bits (cause why not?)
--
bool2bit : Bool -> Bit;
bool2bit b = iteDep (\ (_:Bool) -> Bit) b Bit1 Bit0;
bool2bit_True : Eq Bit (bool2bit True) Bit1;
bool2bit_True = iteDep_True (\ (_:Bool) -> Bit) Bit1 Bit0;
bool2bit_False : Eq Bit (bool2bit False) Bit0;
bool2bit_False = iteDep_False (\ (_:Bool) -> Bit) Bit1 Bit0;
bit2bool : Bit -> Bool;
bit2bool = Bit__rec (\ (_:Bit) -> Bool) True False;
bit2bool_Bit1 : Eq Bool (bit2bool Bit1) True;
bit2bool_Bit1 = Refl Bool True;
bit2bool_Bit0 : Eq Bool (bit2bool Bit0) False;
bit2bool_Bit0 = Refl Bool False;
--
-- The Boolean operations
--
primitive not : Bool -> Bool;
axiom not__eq : (b:Bool) -> Eq Bool (not b) (ite Bool b False True);
primitive and : Bool -> Bool -> Bool;
axiom and__eq : (b1 b2:Bool) -> Eq Bool (and b1 b2) (ite Bool b1 b2 False);
primitive or : Bool -> Bool -> Bool;
axiom or__eq : (b1 b2:Bool) -> Eq Bool (or b1 b2) (ite Bool b1 True b2);
primitive xor : Bool -> Bool -> Bool;
axiom xor__eq : (b1 b2:Bool) ->
Eq Bool (xor b1 b2) (ite Bool b1 (not b2) b2);
-- Decidable Boolean equality, also known as iff
primitive boolEq : Bool -> Bool -> Bool;
axiom boolEq__eq : (b1 b2:Bool) ->
Eq Bool (boolEq b1 b2) (ite Bool b1 b2 (not b2));
-- Implies is not a primitive, as it is not mapped by any of the simulator
-- back-ends; instead, it is just defined in terms of or and not
implies : Bool -> Bool -> Bool;
implies = \ (a:Bool) (b:Bool) -> or (not a) b;
-- FIXME: this rule should be derived by scDefRewriteRules
implies__eq : (a b:Bool) -> Eq Bool (implies a b) (or (not a) b);
implies__eq a b = Refl Bool (implies a b);
unitEq : UnitType -> UnitType -> Bool;
unitEq _ _ = True;
pairEq : (a b : sort 0) -> (a -> a -> Bool) -> (b -> b -> Bool) -> a * b -> a * b -> Bool;
pairEq a b f g x y = and ( f x.(1) y.(1) ) ( g x.(2) y.(2) );
--
-- Rewrite rules for booleans
--
not_True : Eq Bool (not True) False;
not_True =
trans Bool (not True) (ite Bool True False True) False
(not__eq True) (ite_true Bool False True);
not_False : Eq Bool (not False) True;
not_False =
trans Bool (not False) (ite Bool False False True) True
(not__eq False) (ite_false Bool False True);
not_not (x : Bool) : Eq Bool (not (not x)) x =
iteDep (\ (b:Bool) -> Eq Bool (not (not b)) b) x
(trans Bool (not (not True)) (not False) True
(eq_cong Bool (not True) False not_True Bool not)
not_False)
(trans Bool (not (not False)) (not True) False
(eq_cong Bool (not False) True not_False Bool not)
not_True);
and_True1 (x : Bool) : Eq Bool (and True x) x =
trans Bool (and True x) (ite Bool True x False) x
(and__eq True x) (ite_true Bool x False);
and_False1 (x : Bool) : Eq Bool (and False x) False =
trans Bool (and False x) (ite Bool False x False) False
(and__eq False x) (ite_false Bool x False);
and_True2 (x : Bool) : Eq Bool (and x True) x =
iteDep (\ (b:Bool) -> Eq Bool (and b True) b) x
(and_True1 True) (and_False1 True);
and_False2 (x : Bool) : Eq Bool (and x False) False =
iteDep (\ (b:Bool) -> Eq Bool (and b False) False) x
(and_True1 False) (and_False1 False);
and_assoc (x y z : Bool) : Eq Bool (and x (and y z)) (and (and x y) z) =
iteDep (\ (b:Bool) -> Eq Bool (and x (and y b)) (and (and x y) b)) z
(trans2 Bool (and x (and y True)) (and (and x y) True) (and x y)
(eq_cong Bool (and y True) y (and_True2 y) Bool (and x))
(and_True2 (and x y)))
(trans2 Bool (and x (and y False)) (and (and x y) False) False
(trans Bool (and x (and y False)) (and x False) False
(eq_cong Bool (and y False) False (and_False2 y) Bool (and x))
(and_False2 x))
(and_False2 (and x y)));
and_idem (x : Bool) : Eq Bool (and x x) x =
iteDep (\ (b:Bool) -> Eq Bool (and b b) b) x
(and_True1 True) (and_False1 False);
or_True1 (x : Bool) : Eq Bool (or True x) True =
trans Bool (or True x) (ite Bool True True x) True
(or__eq True x) (ite_true Bool True x);
or_False1 (x : Bool) : Eq Bool (or False x) x =
trans Bool (or False x) (ite Bool False True x) x
(or__eq False x) (ite_false Bool True x);
or_True2 (x : Bool) : Eq Bool (or x True) True =
iteDep (\ (b:Bool) -> Eq Bool (or b True) True) x
(or_True1 True) (or_False1 True);
or_False2 (x : Bool) : Eq Bool (or x False) x =
iteDep (\ (b:Bool) -> Eq Bool (or b False) b) x
(or_True1 False) (or_False1 False);
or_assoc (x y z : Bool) : Eq Bool (or x (or y z)) (or (or x y) z) =
iteDep (\ (b:Bool) -> Eq Bool (or x (or y b)) (or (or x y) b)) z
(trans2 Bool (or x (or y True)) (or (or x y) True) True
(trans Bool (or x (or y True)) (or x True) True
(eq_cong Bool (or y True) True (or_True2 y) Bool (or x))
(or_True2 x))
(or_True2 (or x y)))
(trans2 Bool (or x (or y False)) (or (or x y) False) (or x y)
(eq_cong Bool (or y False) y (or_False2 y) Bool (or x))
(or_False2 (or x y)));
or_idem (x : Bool) : Eq Bool (or x x) x =
iteDep (\ (b:Bool) -> Eq Bool (or b b) b) x
(or_True1 True) (or_False1 False);
implies_True1 (x : Bool) : Eq Bool (implies True x) x =
trans
Bool (or (not True) x) (or False x) x
(eq_cong Bool (not True) False not_True
Bool (\ (y:Bool) -> or y x))
(or_False1 x);
implies_False1 (x : Bool) : Eq Bool (implies False x) True =
trans
Bool (or (not False) x) (or True x) True
(eq_cong Bool (not False) True not_False
Bool (\ (y:Bool) -> or y x))
(or_True1 x);
-- Legacy name
true_implies (x : Bool) : Eq Bool (implies True x) x = implies_True1 x;
xor_True1 (x : Bool) : Eq Bool (xor True x) (not x) =
trans Bool (xor True x) (ite Bool True (not x) x) (not x)
(xor__eq True x) (ite_true Bool (not x) x);
xor_False1 (x : Bool) : Eq Bool (xor False x) x =
trans Bool (xor False x) (ite Bool False (not x) x) x
(xor__eq False x) (ite_false Bool (not x) x);
xor_False2 (x : Bool) : Eq Bool (xor x False) x =
iteDep (\ (b:Bool) -> Eq Bool (xor b False) b) x
(trans Bool (xor True False) (not False) True (xor_True1 False) not_False)
(xor_False1 False);
xor_True2 (x : Bool) : Eq Bool (xor x True) (not x) =
iteDep (\ (b:Bool) -> Eq Bool (xor b True) (not b)) x
(xor_True1 True)
(trans2 Bool (xor False True) (not False) True (xor_False1 True) not_False);
xor_same (x : Bool) : Eq Bool (xor x x) False =
iteDep (\ (b:Bool) -> Eq Bool (xor b b) False) x
(trans Bool (xor True True) (not True) False (xor_True1 True) not_True)
(xor_False1 False);
boolEq_True1 (x : Bool) : Eq Bool (boolEq True x) x =
trans Bool (boolEq True x) (ite Bool True x (not x)) x
(boolEq__eq True x) (ite_true Bool x (not x));
boolEq_False1 (x : Bool) : Eq Bool (boolEq False x) (not x) =
trans Bool (boolEq False x) (ite Bool False x (not x)) (not x)
(boolEq__eq False x) (ite_false Bool x (not x));
boolEq_True2 (x : Bool) : Eq Bool (boolEq x True) x =
iteDep (\ (b:Bool) -> Eq Bool (boolEq b True) b) x
(boolEq_True1 True)
(trans Bool (boolEq False True) (not True) False (boolEq_False1 True) not_True);
boolEq_False2 (x : Bool) : Eq Bool (boolEq x False) (not x) =
iteDep (\ (b:Bool) -> Eq Bool (boolEq b False) (not b)) x
(trans2 Bool (boolEq True False) (not True) False (boolEq_True1 False) not_True)
(boolEq_False1 False);
boolEq_same (x : Bool) : Eq Bool (boolEq x x) True =
iteDep (\ (b:Bool) -> Eq Bool (boolEq b b) True) x
(boolEq_True1 True)
(trans Bool (boolEq False False) (not False) True (boolEq_False1 False) not_False);
not_or (x y : Bool) : Eq Bool (not (or x y)) (and (not x) (not y)) =
iteDep (\ (b:Bool) -> Eq Bool (not (or b y)) (and (not b) (not y)))
x
(trans Bool (not (or True y)) False (and (not True) (not y))
(trans Bool (not (or True y)) (not True) False
(eq_cong Bool (or True y) True (or_True1 y)
Bool not)
not_True)
(trans Bool False (and False (not y)) (and (not True) (not y))
(sym Bool (and False (not y)) False (and_False1 (not y)))
(eq_cong Bool False (not True)
(sym Bool (not True) False not_True)
Bool (\ (z:Bool) -> (and z (not y))))))
(trans Bool (not (or False y)) (not y) (and (not False) (not y))
(eq_cong Bool (or False y) y (or_False1 y) Bool not)
(sym Bool (and (not False) (not y)) (not y)
(trans Bool (and (not False) (not y)) (and True (not y))
(not y)
(eq_cong Bool (not False) True not_False Bool
(\ (z:Bool) -> (and z (not y))))
(and_True1 (not y)))));
not_and (x y : Bool)
: Eq Bool (not (and x y)) (or (not x) (not y)) =
iteDep (\ (b:Bool) -> Eq Bool (not (and b y)) (or (not b) (not y)))
x
(trans Bool (not (and True y)) (not y) (or (not True) (not y))
(eq_cong Bool (and True y) y (and_True1 y) Bool not)
(sym Bool (or (not True) (not y)) (not y)
(trans Bool (or (not True) (not y)) (or False (not y))
(not y)
(eq_cong Bool (not True) False not_True Bool
(\ (z:Bool) -> (or z (not y))))
(or_False1 (not y)))))
(trans Bool (not (and False y)) True (or (not False) (not y))
(trans Bool (not (and False y)) (not False) True
(eq_cong Bool (and False y) False (and_False1 y)
Bool not)
not_False)
(trans Bool True (or True (not y)) (or (not False) (not y))
(sym Bool (or True (not y)) True (or_True1 (not y)))
(eq_cong Bool True (not False)
(sym Bool (not False) True not_False)
Bool (\ (z:Bool) -> (or z (not y))))));
ite_not (a : sort 1) (b : Bool) (x y : a)
: Eq a (ite a (not b) x y) (ite a b y x) =
iteDep (\ (b':Bool) -> Eq a (ite a (not b') x y) (ite a b' y x))
b
(trans a (ite a (not True) x y) y (ite a True y x)
(trans a (ite a (not True) x y) (ite a False x y) y
(eq_cong Bool (not True) False not_True a
(\ (z:Bool) -> ite a z x y))
(ite_false a x y))
(sym a (ite a True y x) y (ite_true a y x)))
(trans a (ite a (not False) x y) x (ite a False y x)
(trans a (ite a (not False) x y) (ite a True x y) x
(eq_cong Bool (not False) True not_False a
(\ (z:Bool) -> ite a z x y))
(ite_true a x y))
(sym a (ite a False y x) x (ite_false a y x)));
ite_nest1 (a : sort 1) (b : Bool) (x y z : a)
: Eq a (ite a b (ite a b x y) z) (ite a b x z) =
iteDep (\ (b':Bool) -> Eq a (ite a b' (ite a b' x y) z) (ite a b' x z))
b
(trans a (ite a True (ite a True x y) z) x (ite a True x z)
(trans a (ite a True (ite a True x y) z) (ite a True x y) x
(ite_true a (ite a True x y) z)
(ite_true a x y))
(sym a (ite a True x z) x (ite_true a x z)))
(trans a (ite a False (ite a False x y) z) z (ite a False x z)
(ite_false a (ite a False x y) z)
(sym a (ite a False x z) z (ite_false a x z)));
ite_nest2 (a : sort 1) (b : Bool) (x y z : a)
: Eq a (ite a b x (ite a b y z)) (ite a b x z) =
iteDep (\ (b':Bool) -> Eq a (ite a b' x (ite a b' y z)) (ite a b' x z))
b
(trans a (ite a True x (ite a True y z)) x (ite a True x z)
(ite_true a x (ite a True y z))
(sym a (ite a True x z) x (ite_true a x z)))
(trans a (ite a False x (ite a False y z)) z (ite a False x z)
(trans a (ite a False x (ite a False y z)) (ite a False y z) z
(ite_false a x (ite a False y z))
(ite_false a y z))
(sym a (ite a False x z) z (ite_false a x z)));
-- This is provable with iteDep on b, but yuck!
axiom ite_bit : (b : Bool) -> (c : Bool) -> (d : Bool) ->
Eq Bool (ite Bool b c d) (and (or (not b) c) (or b d));
ite_bit_false_1 (b c : Bool)
: Eq Bool (ite Bool b False c) (and (not b) c) =
iteDep (\ (b':Bool) -> Eq Bool (ite Bool b' False c) (and (not b') c)) b
(trans Bool (ite Bool True False c) False (and (not True) c)
(ite_true Bool False c)
(sym Bool (and (not True) c) False
(trans Bool (and (not True) c) (and False c) False
(eq_cong Bool (not True) False not_True
Bool (\ (z:Bool) -> (and z c)))
(and_False1 c))))
(trans Bool (ite Bool False False c) c (and (not False) c)
(ite_false Bool False c)
(sym Bool (and (not False) c) c
(trans Bool (and (not False) c) (and True c) c
(eq_cong Bool (not False) True not_False
Bool (\ (z:Bool) -> (and z c)))
(and_True1 c))));
ite_bit_true_1 (b c : Bool) : Eq Bool (ite Bool b True c) (or b c) =
iteDep (\ (b':Bool) -> Eq Bool (ite Bool b' True c) (or b' c))
b
(trans Bool (ite Bool True True c) True (or True c)
(ite_true Bool True c)
(sym Bool (or True c) True (or_True1 c)))
(trans Bool (ite Bool False True c) c (or False c)
(ite_false Bool True c)
(sym Bool (or False c) c (or_False1 c)));
ite_fold_not (b : Bool) : Eq Bool (ite Bool b False True) (not b) =
iteDep (\ (b':Bool) -> Eq Bool (ite Bool b' False True) (not b'))
b
(trans Bool (ite Bool True False True) False (not True)
(ite_true Bool False True)
(sym Bool (not True) False not_True))
(trans Bool (ite Bool False False True) True (not False)
(ite_false Bool False True)
(sym Bool (not False) True not_False));
ite_eq (a : sort 1) (b : Bool) (x : a) : Eq a (ite a b x x) x =
iteDep (\ (b':Bool) -> Eq a (ite a b' x x) x)
b (ite_true a x x) (ite_false a x x);
or_triv1 (x : Bool) : Eq Bool (or x (not x)) True =
iteDep (\ (b:Bool) -> Eq Bool (or b (not b)) True)
x
(or_True1 (not True))
(trans Bool (or False (not False)) (not False) True
(or_False1 (not False)) not_False);
or_triv2 (x : Bool) : Eq Bool (or (not x) x) True =
iteDep (\ (b:Bool) -> Eq Bool (or (not b) b) True)
x
(or_True2 (not True))
(trans Bool (or (not False) False) (not False) True
(or_False2 (not False)) not_False);
and_triv1 (x : Bool) : Eq Bool (and x (not x)) False =
iteDep (\ (b:Bool) -> Eq Bool (and b (not b)) False)
x
(trans Bool (and True (not True)) (not True) False
(and_True1 (not True)) not_True)
(and_False1 (not False));
and_triv2 (x : Bool) : Eq Bool (and (not x) x) False =
iteDep (\ (b:Bool) -> Eq Bool (and (not b) b) False)
x
(trans Bool (and (not True) True) (not True) False
(and_True2 (not True)) not_True)
(and_False2 (not False));
--------------------------------------------------------------------------------
-- Converting Booleans to Propositions
EqTrue : Bool -> Prop;
EqTrue x = Eq Bool x True;
TrueI : EqTrue True;
TrueI = Refl Bool True;
andI : (x y : Bool) -> EqTrue x -> EqTrue y -> EqTrue (and x y);
andI x y p q =
trans4 Bool (and x y) (and x True) x True
(eq_cong Bool y True q Bool (and x)) (and_True2 x) p;
impliesI (x y : Bool) : (EqTrue x -> EqTrue y) -> EqTrue (implies x y) =
iteDep (\ (x : Bool) -> (EqTrue x -> EqTrue y) -> EqTrue (implies x y)) x
(\ (H : EqTrue True -> EqTrue y) ->
trans Bool (implies True y) y True (implies_True1 y) (H TrueI))
(\ (_ : EqTrue False -> EqTrue y) -> implies_False1 y);
--------------------------------------------------------------------------------
-- Either
data Either (s t : sort 0) : sort 0 where {
Left : s -> Either s t;
Right : t -> Either s t;
}
Either__rec : (s t : sort 0) -> (p : Either s t -> sort 0) ->
((l : s) -> p (Left s t l)) ->
((r : t) -> p (Right s t r)) ->
(e : Either s t) -> p e;
Either__rec s t p f1 f2 e = Either#rec s t p f1 f2 e;
either : (a b c : sort 0) -> (a -> c) -> (b -> c) -> Either a b -> c;
either a b c f g e =
Either__rec a b (\ (p: Either a b) -> c) f g e;
eitherCong0 : (t x y : sort 0) -> Eq (sort 0) x y ->
Eq (sort 0) (Either x t) (Either y t);
eitherCong0 t x y eq =
eq_cong (sort 0) x y eq (sort 0) (\ (y':sort 0) -> Either y' t);
eitherCong1 : (t x y : sort 0) -> Eq (sort 0) x y ->
Eq (sort 0) (Either t x) (Either t y);
eitherCong1 t x y eq =
eq_cong (sort 0) x y eq (sort 0) (\ (y':sort 0) -> Either t y');
boolToEither : Bool -> Either #() #();
boolToEither b = ite (Either #() #()) b (Left #() #() ()) (Right #() #() ());
--------------------------------------------------------------------------------
-- Maybe
data Maybe (a : sort 0) : sort 0 where {
Nothing : Maybe a;
Just : a -> Maybe a;
}
Maybe__rec : (a : sort 0) -> (p : (Maybe a) -> sort 0) ->
p (Nothing a) -> ((x:a) -> p (Just a x)) -> (m : Maybe a) -> p m;
Maybe__rec a p f1 f2 m = Maybe#rec a p f1 f2 m;
maybe : (a b : sort 0) -> b -> (a -> b) -> Maybe a -> b;
maybe a b f1 f2 m = Maybe__rec a (\ (m':Maybe a) -> b) f1 f2 m;
--------------------------------------------------------------------------------
-- Nat
data Nat : sort 0 where {
Zero : Nat;
Succ : Nat -> Nat;
}
Nat__rec : (p : Nat -> sort 1) -> p Zero -> ((n:Nat) -> p n -> p (Succ n)) ->
(n:Nat) -> p n;
Nat__rec p f1 f2 n = Nat#rec p f1 f2 n;
Nat_cases : (a:sort 1) -> a -> (Nat -> a -> a) -> Nat -> a;
Nat_cases a f1 f2 n = Nat__rec (\ (n:Nat) -> a) f1 f2 n;
-- Build a binary function for Nats that satisfies:
-- Nat_cases2 a f1 f2 f3 Zero y = f1 y
-- Nat_cases2 a f1 f2 f3 (Succ x) Zero = f2 x
-- Nat_cases2 a f1 f2 f3 (Succ x) (Succ y) = f3 x y (Nat_cases2 ... x y)
Nat_cases2 : (a:sort 1) -> (Nat -> a) -> (Nat -> a) ->
(Nat -> Nat -> a -> a) -> Nat -> Nat -> a;
Nat_cases2 a f1 f2 f3 n m =
Nat__rec (\ (n:Nat) -> Nat -> a) f1
(\ (n:Nat) -> \ (f_rec : Nat -> a) -> \ (m:Nat) ->
Nat__rec (\ (m':Nat) -> a) (f2 n)
(\ (m':Nat) -> \ (frec':a) -> f3 n m' (f_rec m')) m) n m;
eqNat : Nat -> Nat -> sort 1;
eqNat x y = Eq Nat x y;
eqNatSucc : (x y : Nat) -> eqNat x y -> eqNat (Succ x) (Succ y);
eqNatSucc x y eq = eq_cong Nat x y eq Nat (\ (n:Nat) -> Succ n);
-- Predecessor
pred : Nat -> Nat;
pred x = Nat_cases Nat Zero (\ (n:Nat) -> \ (m:Nat) -> n) x;
eqNatPrec : (x y : Nat) -> eqNat (Succ x) (Succ y) -> eqNat x y;
eqNatPrec x y eq' =
eq_cong Nat (Succ x) (Succ y) eq' Nat pred;
-- | Propositional less than or equal to; defined the same way as in Coq
data IsLeNat (n:Nat) : Nat -> Prop where {
IsLeNat_base : IsLeNat n n;
IsLeNat_succ : (m:Nat) -> IsLeNat n m -> IsLeNat n (Succ m);
}
-- | m < n is defined as m+1 <= n (as in Coq)
IsLtNat : Nat -> Nat -> Prop;
IsLtNat m n = IsLeNat (Succ m) n;
-- | Test if m < n or n <= m
-- FIXME: implement this!
primitive natCompareLe : (m n : Nat) -> Either (IsLtNat m n) (IsLeNat n m);
-- | Test if m = n
-- FIXME: implement this!
primitive proveEqNat : (m n : Nat) -> Maybe (Eq Nat m n);
-- | Try to prove x <= y (FIXME: implement this from natCompareLe!)
primitive proveLeNat : (x y : Nat) -> Maybe (IsLeNat x y);
-- | Try to prove x < y
proveLtNat : (x y : Nat) -> Maybe (IsLtNat x y);
proveLtNat x y = proveLeNat (Succ x) y;
-- | Addition
addNat : Nat -> Nat -> Nat;
addNat x y =
Nat_cases Nat y (\ (_:Nat) -> \ (prev_sum:Nat) -> Succ prev_sum) x;
eqNatAdd0 (x : Nat) : eqNat (addNat x 0) x =
Nat__rec (\ (n:Nat) -> eqNat (addNat n 0) n)
(Refl Nat 0)
(\ (n:Nat) -> eqNatSucc (addNat n 0) n)
x;
eqNatAddS (x y : Nat) : eqNat (addNat x (Succ y)) (Succ (addNat x y)) =
Nat__rec (\ (x':Nat) -> (y':Nat) ->
eqNat (addNat x' (Succ y')) (Succ (addNat x' y')))
(\ (y':Nat) -> Refl Nat (Succ y'))
(\ (x':Nat) ->
\ (eqF : (y':Nat) ->
eqNat (addNat x' (Succ y')) (Succ (addNat x' y'))) ->
\ (y':Nat) ->
eqNatSucc (addNat x' (Succ y')) (Succ (addNat x' y')) (eqF y'))
x y;
eqNatAddComm (x y : Nat) : eqNat (addNat x y) (addNat y x) =
Nat__rec (\ (y':Nat) -> (x':Nat) -> eqNat (addNat x' y') (addNat y' x'))
(\ (x':Nat) -> eqNatAdd0 x')
(\ (y':Nat) ->
\ (eqF : (x':Nat) -> eqNat (addNat x' y') (addNat y' x')) ->
\ (x':Nat) ->
trans Nat
(addNat x' (Succ y'))
(Succ (addNat x' y'))
(Succ (addNat y' x'))
(eqNatAddS x' y')
(eqNatSucc (addNat x' y') (addNat y' x') (eqF x')))
y x;
addNat_assoc (x y z : Nat) : eqNat (addNat x (addNat y z)) (addNat (addNat x y) z) =
Nat__rec (\ (x':Nat) -> eqNat (addNat x' (addNat y z)) (addNat (addNat x' y) z))
(Refl Nat (addNat y z))
(\ (x':Nat) ->
\ (eq : eqNat (addNat x' (addNat y z)) (addNat (addNat x' y) z)) ->
eqNatSucc (addNat x' (addNat y z)) (addNat (addNat x' y) z) eq)
x;
-- | Multiplication
mulNat : Nat -> Nat -> Nat;
mulNat x y =
Nat__rec (\ (x':Nat) -> Nat) 0
(\ (x':Nat) -> \ (prod:Nat) -> addNat y prod) x;
equal0Nat : Nat -> Bool;
equal0Nat n =
Nat_cases Bool True (\ (n:Nat) -> \ (b:Bool) -> False) n;
equalNat : Nat -> Nat -> Bool;
equalNat x y =
Nat_cases (Nat -> Bool) equal0Nat
(\ (n':Nat) -> \ (eqN : Nat -> Bool) -> \ (m:Nat) ->
Nat_cases Bool False
(\ (m':Nat) -> \ (b:Bool) -> eqN m') m) x y;
ltNat : Nat -> Nat -> Bool;
ltNat x y =
Nat_cases2 Bool (\ (x':Nat) -> False)
(\ (y':Nat) -> True)
(\ (y':Nat) -> \ (x':Nat) -> \ (lt_mn:Bool) -> lt_mn) y x;
-- | Subtraction
subNat : Nat -> Nat -> Nat;
subNat x y =
Nat_cases2 Nat (\ (x':Nat) -> x')
(\ (y':Nat) -> Zero)
(\ (y':Nat) -> \ (x':Nat) -> \ (sub_xy:Nat) -> sub_xy) y x;
-- | Minimum
minNat : Nat -> Nat -> Nat;
minNat x y =
Nat_cases2 Nat (\ (y':Nat) -> Zero)
(\ (x':Nat) -> Zero)
(\ (x':Nat) -> \ (y':Nat) -> \ (min_xy:Nat) -> Succ min_xy) x y;
-- | Maximum
maxNat : Nat -> Nat -> Nat;
maxNat x y =
Nat_cases2 Nat (\ (x':Nat) -> x')
(\ (y':Nat) -> Succ y')
(\ (y':Nat) -> \ (x':Nat) -> \ (sub_xy:Nat) -> sub_xy) y x;
-- | Width(n) = 1 + floor(log_2(n))
primitive widthNat : Nat -> Nat;
-- | Natural exponentiation
expNat : Nat -> Nat -> Nat;
expNat b e =
Nat_cases Nat 1 (\ (e':Nat) -> \ (exp_b_e:Nat) -> mulNat b exp_b_e) e;
-- | Natural division and modulus
primitive divModNat : Nat -> Nat -> Nat * Nat;
divNat : Nat -> Nat -> Nat;
divNat x y = (divModNat x y).(1);
modNat : Nat -> Nat -> Nat;
modNat x y = (divModNat x y).(2);
-- There are implicit constructors from integer literals.
-- Dependent, non-recursive pattern matching combinator for natural numbers
natCase : (p : Nat -> sort 0) -> p Zero -> ((n : Nat) -> p (Succ n)) ->
(n : Nat) -> p n;
natCase p z s = Nat__rec p z (\ (n:Nat) -> \ (r:p n) -> s n);
-- An if-then-else for whether a Nat = 0
if0Nat : (a : sort 0) -> Nat -> a -> a -> a;
if0Nat a n x y = natCase (\ (_:Nat) -> a) x (\ (_:Nat) -> y) n;
-- An exponentation operation on arbitrary types.
--
-- The arguments are: the 1 value for a;
-- the multiplication operation, the base of the exponent
-- and the number of times to multiply.
primitive expByNat : (a:sort 0) -> a -> (a -> a -> a) -> a -> Nat -> a;
--------------------------------------------------------------------------------
-- Operations on string values
primitive equalString : String -> String -> Bool;
--------------------------------------------------------------------------------
-- "Vec n a" is an array of n elements, each with type "a".
primitive Vec : Nat -> sort 0 -> sort 0;
-- Primitive function for generating an array.
primitive gen : (n : Nat) -> (a : sort 0) -> (Nat -> a) -> Vec n a;
-- Primitive eliminators for arrays
primitive head : (n : Nat) -> (a : sort 0) -> Vec (Succ n) a -> a;
primitive tail : (n : Nat) -> (a : sort 0) -> Vec (Succ n) a -> Vec n a;
primitive atWithDefault : (n : Nat) -> (a : sort 0) -> a -> Vec n a -> Nat -> a;
at : (n : Nat) -> (a : isort 0) -> Vec n a -> Nat -> a;
at n a v i = atWithDefault n a (error a "at: index out of bounds") v i;
-- `at n a v i` has the precondition `ltNat i n`
primitive EmptyVec : (a : sort 0) -> Vec 0 a;
ConsVec : (a : isort 0) -> a -> (n : Nat) -> Vec n a -> Vec (Succ n) a;
ConsVec a x n v =
gen (Succ n) a (Nat_cases a x (\ (i:Nat) -> \ (a':a) -> at n a v i));
upd : (n : Nat) -> (a : isort 0) -> Vec n a -> Nat -> a -> Vec n a;
upd n a v j x = gen n a (\ (i : Nat) -> ite a (equalNat i j) x (at n a v i));
-- TODO: assertion that j < n
-- | Defines a function that maps array elements from one range to another.
map : (a : isort 0) -> (b : sort 0) -> (a -> b) -> (n : Nat) -> Vec n a -> Vec n b;
map a b f n v = gen n b (\ (i : Nat) -> f (at n a v i));
-- | Defines a function that maps array elements from one range to another.
zipWith : (a b : isort 0) -> (c : sort 0)
-> (a -> b -> c)
-> (n : Nat) -> Vec n a -> Vec n b -> Vec n c;
zipWith a b c f n x y = gen n c (\ (i : Nat) -> f (at n a x i) (at n b y i));
-- replicate n x returns an array with n copies of x.
replicate : (n : Nat) -> (a : sort 0) -> a -> Vec n a;
replicate n a x = gen n a (\ (_ : Nat) -> x);
-- | Create a vector of length 1.
single : (a : sort 0) -> a -> Vec 1 a;
single = replicate 1;
axiom at_single : (a : sort 0) -> (x : a) -> (i : Nat) -> Eq a (at 1 a (single a x) i) x;
-- Zip together two lists (truncating the longer of the two).
primitive zip : (a b : sort 0) -> (m n : Nat) -> Vec m a -> Vec n b -> Vec (minNat m n) (a * b);
primitive foldr : (a b : sort 0) -> (n : Nat) -> (a -> b -> b) -> b -> Vec n a -> b;
primitive foldl : (a b : sort 0) -> (n : Nat) -> (b -> a -> b) -> b -> Vec n a -> b;
reverse : (n : Nat) -> (a : isort 0) -> Vec n a -> Vec n a;
reverse n a xs = gen n a (\ (i : Nat) -> at n a xs (subNat (subNat n 1) i));
transpose : (m n : Nat) -> (a : isort 0) -> Vec m (Vec n a) -> Vec n (Vec m a);
transpose m n a xss =
gen n (Vec m a) (\ (j : Nat) ->
gen m a (\ (i : Nat) -> at n a (at m (Vec n a) xss i) j));
-- | Return true if two vectors are equal, given a comparison function
-- for elements.
vecEq : (n : Nat) -> (a : isort 0) -> (a -> a -> Bool)
-> Vec n a -> Vec n a -> Bool;
vecEq n a eqFn x y =
foldr Bool Bool n and True (zipWith a a Bool eqFn n x y);
-- | Take a prefix of a vector.
take : (a : isort 0) -> (m n : Nat) -> Vec (addNat m n) a -> Vec m a;
take a m n v = gen m a (\ (i : Nat) -> at (addNat m n) a v i);
vecCong : (a : sort 0) -> (m n : Nat) -> Eq Nat m n ->
Eq (sort 0) (Vec m a) (Vec n a);
vecCong a m n eq = eq_cong Nat m n eq (sort 0) (\ (i:Nat) -> Vec i a);
coerceVec : (a : sort 0) -> (m n : Nat) -> Eq Nat m n -> Vec m a -> Vec n a;
coerceVec a m n q = coerce (Vec m a) (Vec n a) (vecCong a m n q);
-- | Simplify take all elements from a vector.
axiom take0 : (a : sort 0)
-> (m : Nat)
-> (v : Vec (addNat m 0) a)
-> Eq (Vec m a)
(take a m 0 v)
(coerceVec a (addNat m 0) m (eqNatAdd0 m) v);
-- | Returns a suffix of a vector after a given number of elements.
drop : (a : isort 0) -> (m n : Nat) -> Vec (addNat m n) a -> Vec n a;
drop a m n v = gen n a (\ (i : Nat) -> at (addNat m n) a v (addNat m i));
-- | Simplify drop 0-elements from a vector.
axiom drop0 : (a : sort 0)
-> (n : Nat)