Source file Verify.ml

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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
open Interface

(** Provides functors to verify that instances are lawful. *)
module Compare = struct
  module Medial_Magma (M : MEDIAL_MAGMA) (E : EQ with type t = M.t) = struct
    module I = Infix.Magma (M)

    let bicommutativity =
      (fun a b c d ->
         let open I in
         E.eq (a <:> b <:> (c <:> d)) (a <:> c <:> (b <:> d))
        : M.t -> M.t -> M.t -> M.t -> bool)
  end

  module Semigroup (S : SEMIGROUP) (E : EQ with type t = S.t) = struct
    module I = Infix.Magma (S)

    let associativity =
      (fun a b c ->
         let open I in
         E.eq (a <:> (b <:> c)) (a <:> (b <:> c))
        : S.t -> S.t -> S.t -> bool)
  end

  module Semigroup_Any (S : SEMIGROUP_ANY) (E : EQ1 with type 'a t = 'a S.t) = struct
    module I = Infix.Magma_Any (S)

    let associativity =
      (fun a b c ->
         let open I in
         E.eq (a <:> (b <:> c)) (a <:> (b <:> c))
        : 'a S.t -> 'a S.t -> 'a S.t -> bool)
  end

  module Monoid (M : MONOID) (E : EQ with type t = M.t) = struct
    module I = Infix.Magma (M)

    let identity =
      (fun a ->
         let open I in
         E.eq (a <:> M.empty) a && E.eq (M.empty <:> a) a
        : M.t -> bool)
  end

  module Monoid_Any (M : MONOID_ANY) (E : EQ1 with type 'a t = 'a M.t) = struct
    module I = Infix.Magma_Any (M)

    let identity =
      (fun a ->
         let open I in
         E.eq (a <:> M.empty) a && E.eq (M.empty <:> a) a
        : 'a M.t -> bool)
  end

  module Quasigroup (Q : QUASIGROUP) (E : EQ with type t = Q.t) = struct
    module I = Infix.Magma (Q)

    let cancellative =
      (fun a b c ->
         (let open I in
         (not (E.eq (a <:> b) (a <:> c))) || E.eq b c)
         &&
         let open I in
         (not (E.eq (b <:> a) (c <:> a))) || E.eq b c
        : Q.t -> Q.t -> Q.t -> bool)
  end

  module Quasigroup_Any (Q : QUASIGROUP_ANY) (E : EQ1 with type 'a t = 'a Q.t) = struct
    module I = Infix.Magma_Any (Q)

    let cancellative =
      (fun a b c ->
         (let open I in
         (not (E.eq (a <:> b) (a <:> c))) || E.eq b c)
         &&
         let open I in
         (not (E.eq (b <:> a) (c <:> a))) || E.eq b c
        : 'a Q.t -> 'a Q.t -> 'a Q.t -> bool)
  end

  module Medial_Quasigroup (Q : MEDIAL_QUASIGROUP) (E : EQ with type t = Q.t) = struct
    include Quasigroup (Q) (E)
  end

  module Loop (L : LOOP) (E : EQ with type t = L.t) = struct
    module I = Infix.Magma (L)

    let identity =
      (fun a ->
         let open I in
         E.eq (a <:> L.empty) a && E.eq (L.empty <:> a) a
        : L.t -> bool)
  end

  module Loop_Any (L : LOOP_ANY) (E : EQ1 with type 'a t = 'a L.t) = struct
    module I = Infix.Magma_Any (L)

    let identity =
      (fun a ->
         let open I in
         E.eq (a <:> L.empty) a && E.eq (L.empty <:> a) a
        : 'a L.t -> bool)
  end

  module Group (G : GROUP) (E : EQ with type t = G.t) = struct
    module I = Infix.Magma (G)

    (** via {!Interface.MONOID} *)
    let invertibility =
      (fun a ->
         let open I in
         E.eq (G.inverse a <:> a) G.empty && E.eq (a <:> G.inverse a) G.empty
        : G.t -> bool)

    (** via {!Interface.LOOP} *)
    let associativity =
      (fun a b c ->
         let open I in
         E.eq (a <:> (b <:> c)) (a <:> (b <:> c))
        : G.t -> G.t -> G.t -> bool)
  end

  module Group_Any (G : GROUP_ANY) (E : EQ1 with type 'a t = 'a G.t) = struct
    module I = Infix.Magma_Any (G)

    (** via {!Interface.MONOID} *)
    let invertibility =
      (fun a ->
         let open I in
         E.eq (G.inverse a <:> a) G.empty && E.eq (a <:> G.inverse a) G.empty
        : 'a G.t -> bool)

    (** via {!Interface.LOOP} *)
    let associativity =
      (fun a b c ->
         let open I in
         E.eq (a <:> (b <:> c)) (a <:> (b <:> c))
        : 'a G.t -> 'a G.t -> 'a G.t -> bool)
  end

  module Abelian_Group (A : ABELIAN_GROUP) (E : EQ with type t = A.t) = struct
    let commutativity = (fun a b -> E.eq (A.append a b) (A.append b a) : A.t -> A.t -> bool)
  end

  module Abelian_Group_Any (A : ABELIAN_GROUP_ANY) (E : EQ1 with type 'a t = 'a A.t) = struct
    let commutativity = (fun a b -> E.eq (A.append a b) (A.append b a) : 'a A.t -> 'a A.t -> bool)
  end

  module Functor (F : FUNCTOR) (E : EQ1 with type 'a t = 'a F.t) = struct
    let ( <. ) = Function.Infix.( <. )

    let identity = (fun a -> E.eq (F.map Function.Category.id a) a : 'a F.t -> bool)

    let composition =
      (fun f g a -> E.eq (F.map (f <. g) a) ((F.map f <. F.map g) a)
        : ('b -> 'c) -> ('a -> 'b) -> 'a F.t -> bool)
  end

  module Apply (A : APPLY) (E : EQ1 with type 'a t = 'a A.t) = struct
    module I = Infix.Apply (A)

    let associative_composition =
      (fun f g h ->
         let open I in
         E.eq (A.map Function.Semigroupoid.compose f <*> g <*> h) (f <*> (g <*> h))
        : ('b -> 'c) A.t -> ('a -> 'b) A.t -> 'a A.t -> bool)
  end

  module Applicative (A : APPLICATIVE) (E : EQ1 with type 'a t = 'a A.t) = struct
    module I = Infix.Apply (A)

    let identity =
      (fun a ->
         let open I in
         E.eq (A.pure Function.Category.id <*> a) a
        : 'a A.t -> bool)

    let homomorphism =
      (fun f x ->
         let open I in
         E.eq (A.pure f <*> A.pure x) (A.pure (f x))
        : ('a -> 'b) -> 'a -> bool)

    let interchange =
      (fun f x ->
         let open I in
         E.eq (f <*> A.pure x) (A.pure (fun f' -> f' x) <*> f)
        : ('a -> 'b) A.t -> 'a -> bool)
  end

  module Monad (M : MONAD) (E : EQ1 with type 'a t = 'a M.t) = struct
    module I = Infix.Monad (M)

    let associativity =
      (fun f g x ->
         let open I in
         E.eq (x >>= f >>= g) (x >>= fun k -> f k >>= g)
        : ('a -> 'b M.t) -> ('b -> 'c M.t) -> 'a M.t -> bool)

    let identity =
      (fun f x ->
         let open I in
         E.eq (M.pure x >>= f) (f x) && E.eq (M.pure x >>= M.pure) (M.pure x)
        : ('a -> 'b M.t) -> 'a -> bool)
  end

  module Alt (A : ALT) (E : EQ1 with type 'a t = 'a A.t) = struct
    module I = Infix.Alt (A)

    let associativity =
      (fun a b c ->
         let open I in
         E.eq (a <|> (b <|> c)) (a <|> (b <|> c))
        : 'a A.t -> 'a A.t -> 'a A.t -> bool)

    let distributivity =
      (fun f a b ->
         let open I in
         E.eq (A.map f (a <|> b)) (A.map f a <|> A.map f b)
        : ('a -> 'b) -> 'a A.t -> 'a A.t -> bool)
  end

  module Plus (P : PLUS) (E : EQ1 with type 'a t = 'a P.t) = struct
    module I = Infix.Alt (P)

    let annihalation = (fun f -> E.eq (P.map f P.empty) P.empty : ('a -> 'b) -> bool)

    let identity =
      (fun a ->
         let open I in
         E.eq (P.empty <|> a) a && E.eq (a <|> P.empty) a
        : 'a P.t -> bool)
  end

  module Alternative (A : ALTERNATIVE) (E : EQ1 with type 'a t = 'a A.t) = struct
    module I = Infix.Alternative (A)

    let distributivity =
      (fun f g x ->
         let open I in
         E.eq (f <|> g <*> x) (f <*> x <|> (g <*> x))
        : ('a -> 'b) A.t -> ('a -> 'b) A.t -> 'a A.t -> bool)

    let annihalation =
      (fun f ->
         let open I in
         E.eq (A.empty <*> f) A.empty
        : ('a -> 'b) A.t -> bool)
  end

  module Semigroupoid (S : SEMIGROUPOID) (E : EQ2 with type ('a, 'b) t = ('a, 'b) S.t) = struct
    module I = Infix.Semigroupoid (S)

    let associativity =
      (fun a b c ->
         let open I in
         E.eq (a <. b <. c) (a <. (b <. c))
        : ('c, 'd) S.t -> ('b, 'c) S.t -> ('a, 'b) S.t -> bool)
  end

  module Category (C : CATEGORY) (E : EQ2 with type ('a, 'b) t = ('a, 'b) C.t) = struct
    module I = Infix.Semigroupoid (C)

    let identity =
      (fun a ->
         let open I in
         E.eq (C.id <. a) a && E.eq (a <. C.id) a
        : ('a, 'b) C.t -> bool)
  end

  module Eq (E : EQ) = struct
    module I = Infix.Eq (E)

    let reflexivity =
      (fun a ->
         let open I in
         a =|= a
        : E.t -> bool)

    let symmetry =
      (fun a b ->
         let open I in
         a =|= b = (b =|= a)
        : E.t -> E.t -> bool)

    let transitivity =
      (fun a b c ->
         let open I in
         (not (a =|= b && b =|= c)) || a =|= c
        : E.t -> E.t -> E.t -> bool)
  end

  module Quasireflexive_Eq (E : QUASIREFLEXIVE_EQ) = struct
    module I = Infix.Eq (E)

    let quasireflexivity =
      (fun a b ->
         let open I in
         (not (a =|= b)) || (a =|= a && b =|= b)
        : E.t -> E.t -> bool)

    let symmetry =
      (fun a b ->
         let open I in
         a =|= b = (b =|= a)
        : E.t -> E.t -> bool)

    let transitivity =
      (fun a b c ->
         let open I in
         (not (a =|= b && b =|= c)) || a =|= c
        : E.t -> E.t -> E.t -> bool)
  end

  module Ord (E : ORD) = struct
    module Ordering_Functions = Infix.Ord (E)

    let ( <|= ), ( >|= ) =
      let open Ordering_Functions in
      ( <|= ), ( >|= )

    let reflexivity = (fun a -> a <|= a : E.t -> bool)

    let antisymmetry = (fun a b -> (not (a <|= b && b <|= a)) || a = b : E.t -> E.t -> bool)

    let transitivity =
      (fun a b c -> (not (a <|= b && b <|= c)) || a <|= c : E.t -> E.t -> E.t -> bool)
  end

  module Bounded (B : BOUNDED) = struct
    module Ordering_Functions = Infix.Ord (B)

    let ( <|= ) =
      let open Ordering_Functions in
      ( <|= )

    let bounded = (fun a -> B.bottom <|= a && a <|= B.top : B.t -> bool)
  end

  module Join_Semilattice (J : JOIN_SEMILATTICE) (E : EQ with type t = J.t) = struct
    let associativity =
      (fun a b c -> E.eq (J.join a (J.join b c)) (J.join (J.join a b) c)
        : J.t -> J.t -> J.t -> bool)

    let commutativity = (fun a b -> E.eq (J.join a b) (J.join b a) : J.t -> J.t -> bool)

    let idempotency = (fun a -> E.eq (J.join a a) a : J.t -> bool)
  end

  module Meet_Semilattice (M : MEET_SEMILATTICE) (E : EQ with type t = M.t) = struct
    let associativity =
      (fun a b c -> E.eq (M.meet a (M.meet b c)) (M.meet (M.meet a b) c)
        : M.t -> M.t -> M.t -> bool)

    let commutativity = (fun a b -> E.eq (M.meet a b) (M.meet b a) : M.t -> M.t -> bool)

    let idempotency = (fun a -> E.eq (M.meet a a) a : M.t -> bool)
  end

  module Bounded_Join_Semilattice (B : BOUNDED_JOIN_SEMILATTICE) (E : EQ with type t = B.t) = struct
    let identity = (fun a -> B.join a B.bottom = a : B.t -> bool)
  end

  module Bounded_Meet_Semilattice (B : BOUNDED_MEET_SEMILATTICE) (E : EQ with type t = B.t) = struct
    let identity = (fun a -> B.meet a B.top = a : B.t -> bool)
  end

  module Lattice (L : LATTICE) (E : EQ with type t = L.t) = struct
    let absorption =
      (fun a b -> E.eq (L.meet a (L.join a b)) a && E.eq (L.join a (L.meet a b)) a
        : L.t -> L.t -> bool)
  end

  module Bounded_Lattice (L : BOUNDED_LATTICE) (E : EQ with type t = L.t) = struct
    let absorption =
      (fun a b -> L.meet a (L.join a b) = a && E.eq (L.join a (L.meet a b)) a : L.t -> L.t -> bool)
  end

  module Distributive_Lattice (L : DISTRIBUTIVE_LATTICE) (E : EQ with type t = L.t) = struct
    let distributivity =
      (fun a b c -> E.eq (L.meet a (L.join b c)) (L.join (L.meet a b) (L.meet a c))
        : L.t -> L.t -> L.t -> bool)
  end

  module Bounded_Distributive_Lattice (L : BOUNDED_DISTRIBUTIVE_LATTICE) (E : EQ with type t = L.t) =
  struct
    let distributivity =
      (fun a b c -> E.eq (L.meet a (L.join b c)) (L.join (L.meet a b) (L.meet a c))
        : L.t -> L.t -> L.t -> bool)
  end

  module Heyting_Algebra (H : HEYTING_ALGEBRA) (E : EQ with type t = H.t) = struct
    module O = Infix.Ord (H)

    let ( <|= ) = O.( <|= )

    let pseudocomplement = (fun a -> E.eq (H.not a) (H.implies a H.bottom) : H.t -> bool)

    let relative_pseudocomplement =
      (fun a b c -> H.meet c a <|= b = (c <|= H.implies a b) : H.t -> H.t -> H.t -> bool)
  end

  module Involutive_Heyting_Algebra (H : HEYTING_ALGEBRA) (E : EQ with type t = H.t) = struct
    let involution = (fun a -> E.eq (H.not (H.not a)) a : H.t -> bool)
  end

  module Boolean_Algebra (B : BOOLEAN_ALGEBRA) (E : EQ with type t = B.t) = struct
    let excluded_middle = (fun a -> E.eq (B.join a (B.not a)) B.top : B.t -> bool)
  end

  module Semiring (S : SEMIRING) (E : EQ with type t = S.t) = struct
    module I = Infix.Semiring (S)
    open I

    let additive_associativity =
      (fun a b c -> E.eq (a |+| b |+| c) (a |+| (b |+| c)) : S.t -> S.t -> S.t -> bool)

    let additive_identity = (fun a -> E.eq (S.zero |+| a) a : S.t -> bool)

    let commutativity = (fun a b -> E.eq (a |+| b) (b |+| a) : S.t -> S.t -> bool)

    let multiplicative_associativity =
      (fun a b c -> E.eq (a |*| b |*| c) (a |*| (b |*| c)) : S.t -> S.t -> S.t -> bool)

    let multiplicative_identity = (fun a -> E.eq (S.one |*| a) a : S.t -> bool)

    let distributivity =
      (fun a b c ->
         E.eq (a |*| (b |+| c)) (a |*| b |+| (a |*| c))
         && E.eq (a |+| b |*| c) (a |*| c |+| (b |*| c))
        : S.t -> S.t -> S.t -> bool)
  end

  module Ring (R : RING) (E : EQ with type t = R.t) = struct
    module I = Infix.Ring (R)

    let additive_inverse =
      (fun a ->
         let open I in
         E.eq (R.zero |-| a |+| a) R.zero
        : R.t -> bool)
  end

  module Commutative_Ring (R : COMMUTATIVE_RING) (E : EQ with type t = R.t) = struct
    module I = Infix.Ring (R)

    let multiplicative_commutativity =
      (fun a b ->
         let open I in
         E.eq (a |*| b) (b |*| a)
        : R.t -> R.t -> bool)
  end

  module Division_Ring (R : DIVISION_RING) (E : EQ with type t = R.t) = struct
    module I = Infix.Ring (R)

    let non_zero_ring = (not (E.eq R.zero R.one) : bool)

    let multiplicative_inverse =
      (fun a ->
         let open I in
         E.eq (R.reciprocal a |*| a) R.one
        : R.t -> bool)
  end

  module Euclidean_Ring (R : EUCLIDEAN_RING) (E : EQ with type t = R.t) = struct
    module I = Infix.Euclidean_Ring (R)

    let non_zero_ring = (not (E.eq R.zero R.one) : bool)

    let integral_domain =
      (fun a b ->
         let open I in
         (not ((not (E.eq a R.zero)) && b <> R.zero)) || not (E.eq (a |*| b) R.zero)
        : R.t -> R.t -> bool)

    let non_negative_degree = (fun a -> E.eq a R.zero || R.degree a >= 0 : R.t -> bool)

    let remainder =
      (fun a b ->
         let open I in
         if b <> R.zero
         then
           let q = a |/| b in
           let r = a |%| b in
           E.eq a (q |*| b |+| r) && (E.eq r R.zero || R.degree r < R.degree b)
         else true
        : R.t -> R.t -> bool)

    let submultiplicative =
      (fun a b ->
         let open I in
         R.degree a <= R.degree (a |*| b)
        : R.t -> R.t -> bool)
  end

  module Field (F : FIELD) (E : EQ with type t = F.t) = struct
    let non_zero_multiplicative_inverse =
      (fun a b -> E.eq (F.modulo a b) F.zero : F.t -> F.t -> bool)
  end

  module Invariant (I : INVARIANT) (E : EQ1 with type 'a t = 'a I.t) = struct
    let id = Function.Category.id

    let ( <. ) = Function.Infix.( <. )

    let identity = (fun a -> E.eq (I.imap id id a) a : 'a I.t -> bool)

    let composition =
      (fun f1 f2 g1 g2 a -> E.eq ((I.imap g1 g2 <. I.imap f1 f2) a) (I.imap (g1 <. f1) (f2 <. g2) a)
        : ('a -> 'b) -> ('b -> 'a) -> ('b -> 'a) -> ('a -> 'b) -> 'a I.t -> bool)
  end

  module Contravariant (C : CONTRAVARIANT) (E : EQ1 with type 'a t = 'a C.t) = struct
    let id = Function.Category.id

    let ( <. ) = Function.Infix.( <. )

    let identity = (fun a -> E.eq (C.cmap id a) a : 'a C.t -> bool)

    let composition =
      (fun f g a -> E.eq ((C.cmap f <. C.cmap g) a) (C.cmap (g <. f) a)
        : ('c -> 'b) -> ('b -> 'a) -> 'a C.t -> bool)
  end

  module Profunctor (P : PROFUNCTOR) (E : EQ2 with type ('a, 'b) t = ('a, 'b) P.t) = struct
    let id = Function.Category.id

    let ( <. ), ( >. ) =
      let open Function.Infix in
      ( <. ), ( >. )

    let identity = (fun a -> E.eq (P.dimap id id a) a : ('a, 'b) P.t -> bool)

    let composition =
      (fun f1 g1 f2 g2 a ->
         E.eq ((P.dimap f2 g2 <. P.dimap f1 g1) a) (P.dimap (f2 >. f1) (g2 <. g1) a)
        : ('a -> 'b) -> ('c -> 'd) -> ('e -> 'a) -> ('d -> 'f) -> ('b, 'c) P.t -> bool)
  end

  module Monad_Zero (M : MONAD_ZERO) (E : EQ1 with type 'a t = 'a M.t) = struct
    let annihalation = (fun f -> E.eq (M.flat_map M.empty f) M.empty : ('a -> 'b M.t) -> bool)
  end

  module Monad_Plus (M : MONAD_PLUS) (E : EQ1 with type 'a t = 'a M.t) = struct
    let distributivity =
      (fun f a b -> E.eq (M.flat_map (M.alt a b) f) (M.alt (M.flat_map a f) (M.flat_map b f))
        : ('a -> 'b M.t) -> 'a M.t -> 'a M.t -> bool)
  end

  module Extend (X : EXTEND) (E : EQ1 with type 'a t = 'a X.t) = struct
    let ( <. ) = Function.Infix.( <. )

    let associativity =
      (fun f g a -> E.eq ((X.extend f <. X.extend g) a) (X.extend (f <. X.extend g) a)
        : ('b E.t -> 'c) -> ('a E.t -> 'b) -> 'a E.t -> bool)
  end

  module Comonad (C : COMONAD) (E : EQ1 with type 'a t = 'a C.t) = struct
    let identity =
      (fun f a -> E.eq (C.extend C.extract a) a && E.eq (C.extract (C.extend f a)) (f a)
        : ('a C.t -> 'a) -> 'a C.t -> bool)
  end

  module Bifunctor (B : BIFUNCTOR) (E : EQ2 with type ('a, 'b) t = ('a, 'b) B.t) = struct
    let id = Function.Category.id

    let ( <. ) = Function.Infix.( <. )

    let identity = (fun a -> E.eq (B.bimap id id a) a : ('a, 'b) B.t -> bool)

    let composition =
      (fun f1 g1 f2 g2 a ->
         E.eq ((B.bimap f1 g1 <. B.bimap f2 g2) a) (B.bimap (f1 <. f2) (g1 <. g2) a)
        : ('b -> 'e) -> ('d -> 'f) -> ('a -> 'b) -> ('c -> 'd) -> ('a, 'c) B.t -> bool)
  end

  module Bicontravariant (B : BICONTRAVARIANT) (E : EQ2 with type ('a, 'b) t = ('a, 'b) B.t) =
  struct
    let id = Function.Category.id

    let ( <. ) = Function.Infix.( <. )

    let identity = (fun a -> E.eq (B.bicmap id id a) a : ('a, 'b) B.t -> bool)

    let composition =
      (fun f1 g1 f2 g2 a ->
         E.eq ((B.bicmap f1 g1 <. B.bicmap f2 g2) a) (B.bicmap (f2 <. f1) (g2 <. g1) a)
        : ('e -> 'b) -> ('f -> 'd) -> ('b -> 'a) -> ('d -> 'c) -> ('a, 'c) B.t -> bool)
  end
end

(** Default {!Verify} functors. Uses {!Pervasives.( == )} for comparison. *)
module Medial_Magma (M : MEDIAL_MAGMA) = struct
  include
    Compare.Medial_Magma
      (M)
      (struct
        type t = M.t

        let eq = ( = )
      end)
end

module Semigroup (S : SEMIGROUP) = struct
  include
    Compare.Semigroup
      (S)
      (struct
        type t = S.t

        let eq = ( = )
      end)
end

module Semigroup_Any (S : SEMIGROUP_ANY) = struct
  include
    Compare.Semigroup_Any
      (S)
      (struct
        type 'a t = 'a S.t

        let eq = ( = )
      end)
end

module Monoid (M : MONOID) = struct
  include
    Compare.Monoid
      (M)
      (struct
        type t = M.t

        let eq = ( = )
      end)
end

module Monoid_Any (M : MONOID_ANY) = struct
  include
    Compare.Monoid_Any
      (M)
      (struct
        type 'a t = 'a M.t

        let eq = ( = )
      end)
end

module Quasigroup (Q : QUASIGROUP) = struct
  include
    Compare.Quasigroup
      (Q)
      (struct
        type t = Q.t

        let eq = ( = )
      end)
end

module Quasigroup_Any (Q : QUASIGROUP_ANY) = struct
  include
    Compare.Quasigroup_Any
      (Q)
      (struct
        type 'a t = 'a Q.t

        let eq = ( = )
      end)
end

module Medial_Quasigroup (Q : MEDIAL_QUASIGROUP) = struct
  include
    Compare.Medial_Quasigroup
      (Q)
      (struct
        type t = Q.t

        let eq = ( = )
      end)
end

module Loop (L : LOOP) = struct
  include
    Compare.Loop
      (L)
      (struct
        type t = L.t

        let eq = ( = )
      end)
end

module Loop_Any (L : LOOP_ANY) = struct
  include
    Compare.Loop_Any
      (L)
      (struct
        type 'a t = 'a L.t

        let eq = ( = )
      end)
end

module Group (G : GROUP) = struct
  include
    Compare.Group
      (G)
      (struct
        type t = G.t

        let eq = ( = )
      end)
end

module Group_Any (G : GROUP_ANY) = struct
  include
    Compare.Group_Any
      (G)
      (struct
        type 'a t = 'a G.t

        let eq = ( = )
      end)
end

module Abelian_Group (A : ABELIAN_GROUP) = struct
  include
    Compare.Abelian_Group
      (A)
      (struct
        type t = A.t

        let eq = ( = )
      end)
end

module Abelian_Group_Any (A : ABELIAN_GROUP_ANY) = struct
  include
    Compare.Abelian_Group_Any
      (A)
      (struct
        type 'a t = 'a A.t

        let eq = ( = )
      end)
end

module Functor (F : FUNCTOR) = struct
  include
    Compare.Functor
      (F)
      (struct
        type 'a t = 'a F.t

        let eq = ( = )
      end)
end

module Apply (A : APPLY) = struct
  include
    Compare.Apply
      (A)
      (struct
        type 'a t = 'a A.t

        let eq = ( = )
      end)
end

module Applicative (A : APPLICATIVE) = struct
  include
    Compare.Applicative
      (A)
      (struct
        type 'a t = 'a A.t

        let eq = ( = )
      end)
end

module Monad (M : MONAD) = struct
  include
    Compare.Monad
      (M)
      (struct
        type 'a t = 'a M.t

        let eq = ( = )
      end)
end

module Alt (A : ALT) = struct
  include
    Compare.Alt
      (A)
      (struct
        type 'a t = 'a A.t

        let eq = ( = )
      end)
end

module Plus (P : PLUS) = struct
  include
    Compare.Plus
      (P)
      (struct
        type 'a t = 'a P.t

        let eq = ( = )
      end)
end

module Alternative (A : ALTERNATIVE) = struct
  include
    Compare.Alternative
      (A)
      (struct
        type 'a t = 'a A.t

        let eq = ( = )
      end)
end

module Semigroupoid (S : SEMIGROUPOID) = struct
  include
    Compare.Semigroupoid
      (S)
      (struct
        type ('a, 'b) t = ('a, 'b) S.t

        let eq = ( = )
      end)
end

module Category (C : CATEGORY) = struct
  include
    Compare.Category
      (C)
      (struct
        type ('a, 'b) t = ('a, 'b) C.t

        let eq = ( = )
      end)
end

module Eq (E : EQ) = struct
  include Compare.Eq (E)
end

module Ord (E : ORD) = struct
  include Compare.Ord (E)
end

module Bounded (B : BOUNDED) = struct
  include Compare.Bounded (B)
end

module Join_Semilattice (J : JOIN_SEMILATTICE) = struct
  include
    Compare.Join_Semilattice
      (J)
      (struct
        type t = J.t

        let eq = ( = )
      end)
end

module Meet_Semilattice (M : MEET_SEMILATTICE) = struct
  include
    Compare.Meet_Semilattice
      (M)
      (struct
        type t = M.t

        let eq = ( = )
      end)
end

module Bounded_Join_Semilattice (J : BOUNDED_JOIN_SEMILATTICE) = struct
  include
    Compare.Bounded_Join_Semilattice
      (J)
      (struct
        type t = J.t

        let eq = ( = )
      end)
end

module Bounded_Meet_Semilattice (M : BOUNDED_MEET_SEMILATTICE) = struct
  include
    Compare.Bounded_Meet_Semilattice
      (M)
      (struct
        type t = M.t

        let eq = ( = )
      end)
end

module Lattice (L : LATTICE) = struct
  include
    Compare.Lattice
      (L)
      (struct
        type t = L.t

        let eq = ( = )
      end)
end

module Bounded_Lattice (L : BOUNDED_LATTICE) = struct
  include
    Compare.Bounded_Lattice
      (L)
      (struct
        type t = L.t

        let eq = ( = )
      end)
end

module Distributive_Lattice (L : DISTRIBUTIVE_LATTICE) = struct
  include
    Compare.Distributive_Lattice
      (L)
      (struct
        type t = L.t

        let eq = ( = )
      end)
end

module Bounded_Distributive_Lattice (L : BOUNDED_DISTRIBUTIVE_LATTICE) = struct
  include
    Compare.Bounded_Distributive_Lattice
      (L)
      (struct
        type t = L.t

        let eq = ( = )
      end)
end

module Heyting_Algebra (H : HEYTING_ALGEBRA) = struct
  include
    Compare.Heyting_Algebra
      (H)
      (struct
        type t = H.t

        let eq = ( = )
      end)
end

module Involutive_Heyting_Algebra (H : INVOLUTIVE_HEYTING_ALGEBRA) = struct
  include
    Compare.Involutive_Heyting_Algebra
      (H)
      (struct
        type t = H.t

        let eq = ( = )
      end)
end

module Boolean_Algebra (B : BOOLEAN_ALGEBRA) = struct
  include
    Compare.Boolean_Algebra
      (B)
      (struct
        type t = B.t

        let eq = ( = )
      end)
end

module Semiring (S : SEMIRING) = struct
  include
    Compare.Semiring
      (S)
      (struct
        type t = S.t

        let eq = ( = )
      end)
end

module Ring (R : RING) = struct
  include
    Compare.Ring
      (R)
      (struct
        type t = R.t

        let eq = ( = )
      end)
end

module Commutative_Ring (R : COMMUTATIVE_RING) = struct
  include
    Compare.Commutative_Ring
      (R)
      (struct
        type t = R.t

        let eq = ( = )
      end)
end

module Division_Ring (R : DIVISION_RING) = struct
  include
    Compare.Division_Ring
      (R)
      (struct
        type t = R.t

        let eq = ( = )
      end)
end

module Euclidean_Ring (R : EUCLIDEAN_RING) = struct
  include
    Compare.Euclidean_Ring
      (R)
      (struct
        type t = R.t

        let eq = ( = )
      end)
end

module Field (F : FIELD) = struct
  include
    Compare.Field
      (F)
      (struct
        type t = F.t

        let eq = ( = )
      end)
end

module Invariant (I : INVARIANT) = struct
  include
    Compare.Invariant
      (I)
      (struct
        type 'a t = 'a I.t

        let eq = ( = )
      end)
end

module Contravariant (C : CONTRAVARIANT) = struct
  include
    Compare.Contravariant
      (C)
      (struct
        type 'a t = 'a C.t

        let eq = ( = )
      end)
end

module Profunctor (P : PROFUNCTOR) = struct
  include
    Compare.Profunctor
      (P)
      (struct
        type ('a, 'b) t = ('a, 'b) P.t

        let eq = ( = )
      end)
end

module Monad_Zero (M : MONAD_ZERO) = struct
  include
    Compare.Monad_Zero
      (M)
      (struct
        type 'a t = 'a M.t

        let eq = ( = )
      end)
end

module Monad_Plus (M : MONAD_PLUS) = struct
  include
    Compare.Monad_Plus
      (M)
      (struct
        type 'a t = 'a M.t

        let eq = ( = )
      end)
end

module Extend (E : EXTEND) = struct
  include
    Compare.Extend
      (E)
      (struct
        type 'a t = 'a E.t

        let eq = ( = )
      end)
end

module Comonad (C : COMONAD) = struct
  include
    Compare.Comonad
      (C)
      (struct
        type 'a t = 'a C.t

        let eq = ( = )
      end)
end

module Bifunctor (B : BIFUNCTOR) = struct
  include
    Compare.Bifunctor
      (B)
      (struct
        type ('a, 'b) t = ('a, 'b) B.t

        let eq = ( = )
      end)
end

module Bicontravariant (B : BICONTRAVARIANT) = struct
  include
    Compare.Bicontravariant
      (B)
      (struct
        type ('a, 'b) t = ('a, 'b) B.t

        let eq = ( = )
      end)
end