-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicromega.ml
2530 lines (2052 loc) · 73.2 KB
/
micromega.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
type __ = Obj.t
type unit0 =
| Tt
(** val negb : bool -> bool **)
let negb = function
| true -> false
| false -> true
type nat =
| O
| S of nat
type ('a, 'b) sum =
| Inl of 'a
| Inr of 'b
(** val fst : ('a1 * 'a2) -> 'a1 **)
let fst = function
| x,_ -> x
(** val snd : ('a1 * 'a2) -> 'a2 **)
let snd = function
| _,y -> y
(** val app : 'a1 list -> 'a1 list -> 'a1 list **)
let rec app l m =
match l with
| [] -> m
| a::l1 -> a::(app l1 m)
type comparison =
| Eq
| Lt
| Gt
(** val compOpp : comparison -> comparison **)
let compOpp = function
| Eq -> Eq
| Lt -> Gt
| Gt -> Lt
module Coq__1 = struct
(** val add : nat -> nat -> nat **)
let rec add n0 m =
match n0 with
| O -> m
| S p -> S (add p m)
end
include Coq__1
(** val nth : nat -> 'a1 list -> 'a1 -> 'a1 **)
let rec nth n0 l default =
match n0 with
| O -> (match l with
| [] -> default
| x::_ -> x)
| S m -> (match l with
| [] -> default
| _::t0 -> nth m t0 default)
(** val rev_append : 'a1 list -> 'a1 list -> 'a1 list **)
let rec rev_append l l' =
match l with
| [] -> l'
| a::l0 -> rev_append l0 (a::l')
(** val map : ('a1 -> 'a2) -> 'a1 list -> 'a2 list **)
let rec map f = function
| [] -> []
| a::t0 -> (f a)::(map f t0)
(** val fold_left : ('a1 -> 'a2 -> 'a1) -> 'a2 list -> 'a1 -> 'a1 **)
let rec fold_left f l a0 =
match l with
| [] -> a0
| b::t0 -> fold_left f t0 (f a0 b)
(** val fold_right : ('a2 -> 'a1 -> 'a1) -> 'a1 -> 'a2 list -> 'a1 **)
let rec fold_right f a0 = function
| [] -> a0
| b::t0 -> f b (fold_right f a0 t0)
type positive =
| XI of positive
| XO of positive
| XH
type n =
| N0
| Npos of positive
type z =
| Z0
| Zpos of positive
| Zneg of positive
module Pos =
struct
type mask =
| IsNul
| IsPos of positive
| IsNeg
end
module Coq_Pos =
struct
(** val succ : positive -> positive **)
let rec succ = function
| XI p -> XO (succ p)
| XO p -> XI p
| XH -> XO XH
(** val add : positive -> positive -> positive **)
let rec add x y =
match x with
| XI p ->
(match y with
| XI q0 -> XO (add_carry p q0)
| XO q0 -> XI (add p q0)
| XH -> XO (succ p))
| XO p ->
(match y with
| XI q0 -> XI (add p q0)
| XO q0 -> XO (add p q0)
| XH -> XI p)
| XH -> (match y with
| XI q0 -> XO (succ q0)
| XO q0 -> XI q0
| XH -> XO XH)
(** val add_carry : positive -> positive -> positive **)
and add_carry x y =
match x with
| XI p ->
(match y with
| XI q0 -> XI (add_carry p q0)
| XO q0 -> XO (add_carry p q0)
| XH -> XI (succ p))
| XO p ->
(match y with
| XI q0 -> XO (add_carry p q0)
| XO q0 -> XI (add p q0)
| XH -> XO (succ p))
| XH ->
(match y with
| XI q0 -> XI (succ q0)
| XO q0 -> XO (succ q0)
| XH -> XI XH)
(** val pred_double : positive -> positive **)
let rec pred_double = function
| XI p -> XI (XO p)
| XO p -> XI (pred_double p)
| XH -> XH
type mask = Pos.mask =
| IsNul
| IsPos of positive
| IsNeg
(** val succ_double_mask : mask -> mask **)
let succ_double_mask = function
| IsNul -> IsPos XH
| IsPos p -> IsPos (XI p)
| IsNeg -> IsNeg
(** val double_mask : mask -> mask **)
let double_mask = function
| IsPos p -> IsPos (XO p)
| x0 -> x0
(** val double_pred_mask : positive -> mask **)
let double_pred_mask = function
| XI p -> IsPos (XO (XO p))
| XO p -> IsPos (XO (pred_double p))
| XH -> IsNul
(** val sub_mask : positive -> positive -> mask **)
let rec sub_mask x y =
match x with
| XI p ->
(match y with
| XI q0 -> double_mask (sub_mask p q0)
| XO q0 -> succ_double_mask (sub_mask p q0)
| XH -> IsPos (XO p))
| XO p ->
(match y with
| XI q0 -> succ_double_mask (sub_mask_carry p q0)
| XO q0 -> double_mask (sub_mask p q0)
| XH -> IsPos (pred_double p))
| XH -> (match y with
| XH -> IsNul
| _ -> IsNeg)
(** val sub_mask_carry : positive -> positive -> mask **)
and sub_mask_carry x y =
match x with
| XI p ->
(match y with
| XI q0 -> succ_double_mask (sub_mask_carry p q0)
| XO q0 -> double_mask (sub_mask p q0)
| XH -> IsPos (pred_double p))
| XO p ->
(match y with
| XI q0 -> double_mask (sub_mask_carry p q0)
| XO q0 -> succ_double_mask (sub_mask_carry p q0)
| XH -> double_pred_mask p)
| XH -> IsNeg
(** val sub : positive -> positive -> positive **)
let sub x y =
match sub_mask x y with
| IsPos z0 -> z0
| _ -> XH
(** val mul : positive -> positive -> positive **)
let rec mul x y =
match x with
| XI p -> add y (XO (mul p y))
| XO p -> XO (mul p y)
| XH -> y
(** val iter : ('a1 -> 'a1) -> 'a1 -> positive -> 'a1 **)
let rec iter f x = function
| XI n' -> f (iter f (iter f x n') n')
| XO n' -> iter f (iter f x n') n'
| XH -> f x
(** val size_nat : positive -> nat **)
let rec size_nat = function
| XI p2 -> S (size_nat p2)
| XO p2 -> S (size_nat p2)
| XH -> S O
(** val compare_cont : comparison -> positive -> positive -> comparison **)
let rec compare_cont r x y =
match x with
| XI p ->
(match y with
| XI q0 -> compare_cont r p q0
| XO q0 -> compare_cont Gt p q0
| XH -> Gt)
| XO p ->
(match y with
| XI q0 -> compare_cont Lt p q0
| XO q0 -> compare_cont r p q0
| XH -> Gt)
| XH -> (match y with
| XH -> r
| _ -> Lt)
(** val compare : positive -> positive -> comparison **)
let compare =
compare_cont Eq
(** val max : positive -> positive -> positive **)
let max p p' =
match compare p p' with
| Gt -> p
| _ -> p'
(** val leb : positive -> positive -> bool **)
let leb x y =
match compare x y with
| Gt -> false
| _ -> true
(** val gcdn : nat -> positive -> positive -> positive **)
let rec gcdn n0 a b =
match n0 with
| O -> XH
| S n1 ->
(match a with
| XI a' ->
(match b with
| XI b' ->
(match compare a' b' with
| Eq -> a
| Lt -> gcdn n1 (sub b' a') a
| Gt -> gcdn n1 (sub a' b') b)
| XO b0 -> gcdn n1 a b0
| XH -> XH)
| XO a0 ->
(match b with
| XI _ -> gcdn n1 a0 b
| XO b0 -> XO (gcdn n1 a0 b0)
| XH -> XH)
| XH -> XH)
(** val gcd : positive -> positive -> positive **)
let gcd a b =
gcdn (Coq__1.add (size_nat a) (size_nat b)) a b
(** val of_succ_nat : nat -> positive **)
let rec of_succ_nat = function
| O -> XH
| S x -> succ (of_succ_nat x)
end
module N =
struct
(** val of_nat : nat -> n **)
let of_nat = function
| O -> N0
| S n' -> Npos (Coq_Pos.of_succ_nat n')
end
(** val pow_pos : ('a1 -> 'a1 -> 'a1) -> 'a1 -> positive -> 'a1 **)
let rec pow_pos rmul x = function
| XI i0 -> let p = pow_pos rmul x i0 in rmul x (rmul p p)
| XO i0 -> let p = pow_pos rmul x i0 in rmul p p
| XH -> x
module Z =
struct
(** val double : z -> z **)
let double = function
| Z0 -> Z0
| Zpos p -> Zpos (XO p)
| Zneg p -> Zneg (XO p)
(** val succ_double : z -> z **)
let succ_double = function
| Z0 -> Zpos XH
| Zpos p -> Zpos (XI p)
| Zneg p -> Zneg (Coq_Pos.pred_double p)
(** val pred_double : z -> z **)
let pred_double = function
| Z0 -> Zneg XH
| Zpos p -> Zpos (Coq_Pos.pred_double p)
| Zneg p -> Zneg (XI p)
(** val pos_sub : positive -> positive -> z **)
let rec pos_sub x y =
match x with
| XI p ->
(match y with
| XI q0 -> double (pos_sub p q0)
| XO q0 -> succ_double (pos_sub p q0)
| XH -> Zpos (XO p))
| XO p ->
(match y with
| XI q0 -> pred_double (pos_sub p q0)
| XO q0 -> double (pos_sub p q0)
| XH -> Zpos (Coq_Pos.pred_double p))
| XH ->
(match y with
| XI q0 -> Zneg (XO q0)
| XO q0 -> Zneg (Coq_Pos.pred_double q0)
| XH -> Z0)
(** val add : z -> z -> z **)
let add x y =
match x with
| Z0 -> y
| Zpos x' ->
(match y with
| Z0 -> x
| Zpos y' -> Zpos (Coq_Pos.add x' y')
| Zneg y' -> pos_sub x' y')
| Zneg x' ->
(match y with
| Z0 -> x
| Zpos y' -> pos_sub y' x'
| Zneg y' -> Zneg (Coq_Pos.add x' y'))
(** val opp : z -> z **)
let opp = function
| Z0 -> Z0
| Zpos x0 -> Zneg x0
| Zneg x0 -> Zpos x0
(** val sub : z -> z -> z **)
let sub m n0 =
add m (opp n0)
(** val mul : z -> z -> z **)
let mul x y =
match x with
| Z0 -> Z0
| Zpos x' ->
(match y with
| Z0 -> Z0
| Zpos y' -> Zpos (Coq_Pos.mul x' y')
| Zneg y' -> Zneg (Coq_Pos.mul x' y'))
| Zneg x' ->
(match y with
| Z0 -> Z0
| Zpos y' -> Zneg (Coq_Pos.mul x' y')
| Zneg y' -> Zpos (Coq_Pos.mul x' y'))
(** val pow_pos : z -> positive -> z **)
let pow_pos z0 =
Coq_Pos.iter (mul z0) (Zpos XH)
(** val pow : z -> z -> z **)
let pow x = function
| Z0 -> Zpos XH
| Zpos p -> pow_pos x p
| Zneg _ -> Z0
(** val compare : z -> z -> comparison **)
let compare x y =
match x with
| Z0 -> (match y with
| Z0 -> Eq
| Zpos _ -> Lt
| Zneg _ -> Gt)
| Zpos x' -> (match y with
| Zpos y' -> Coq_Pos.compare x' y'
| _ -> Gt)
| Zneg x' ->
(match y with
| Zneg y' -> compOpp (Coq_Pos.compare x' y')
| _ -> Lt)
(** val leb : z -> z -> bool **)
let leb x y =
match compare x y with
| Gt -> false
| _ -> true
(** val ltb : z -> z -> bool **)
let ltb x y =
match compare x y with
| Lt -> true
| _ -> false
(** val gtb : z -> z -> bool **)
let gtb x y =
match compare x y with
| Gt -> true
| _ -> false
(** val max : z -> z -> z **)
let max n0 m =
match compare n0 m with
| Lt -> m
| _ -> n0
(** val abs : z -> z **)
let abs = function
| Zneg p -> Zpos p
| x -> x
(** val to_N : z -> n **)
let to_N = function
| Zpos p -> Npos p
| _ -> N0
(** val of_nat : nat -> z **)
let of_nat = function
| O -> Z0
| S n1 -> Zpos (Coq_Pos.of_succ_nat n1)
(** val of_N : n -> z **)
let of_N = function
| N0 -> Z0
| Npos p -> Zpos p
(** val pos_div_eucl : positive -> z -> z * z **)
let rec pos_div_eucl a b =
match a with
| XI a' ->
let q0,r = pos_div_eucl a' b in
let r' = add (mul (Zpos (XO XH)) r) (Zpos XH) in
if ltb r' b
then (mul (Zpos (XO XH)) q0),r'
else (add (mul (Zpos (XO XH)) q0) (Zpos XH)),(sub r' b)
| XO a' ->
let q0,r = pos_div_eucl a' b in
let r' = mul (Zpos (XO XH)) r in
if ltb r' b
then (mul (Zpos (XO XH)) q0),r'
else (add (mul (Zpos (XO XH)) q0) (Zpos XH)),(sub r' b)
| XH -> if leb (Zpos (XO XH)) b then Z0,(Zpos XH) else (Zpos XH),Z0
(** val div_eucl : z -> z -> z * z **)
let div_eucl a b =
match a with
| Z0 -> Z0,Z0
| Zpos a' ->
(match b with
| Z0 -> Z0,a
| Zpos _ -> pos_div_eucl a' b
| Zneg b' ->
let q0,r = pos_div_eucl a' (Zpos b') in
(match r with
| Z0 -> (opp q0),Z0
| _ -> (opp (add q0 (Zpos XH))),(add b r)))
| Zneg a' ->
(match b with
| Z0 -> Z0,a
| Zpos _ ->
let q0,r = pos_div_eucl a' b in
(match r with
| Z0 -> (opp q0),Z0
| _ -> (opp (add q0 (Zpos XH))),(sub b r))
| Zneg b' -> let q0,r = pos_div_eucl a' (Zpos b') in q0,(opp r))
(** val div : z -> z -> z **)
let div a b =
let q0,_ = div_eucl a b in q0
(** val gcd : z -> z -> z **)
let gcd a b =
match a with
| Z0 -> abs b
| Zpos a0 ->
(match b with
| Z0 -> abs a
| Zpos b0 -> Zpos (Coq_Pos.gcd a0 b0)
| Zneg b0 -> Zpos (Coq_Pos.gcd a0 b0))
| Zneg a0 ->
(match b with
| Z0 -> abs a
| Zpos b0 -> Zpos (Coq_Pos.gcd a0 b0)
| Zneg b0 -> Zpos (Coq_Pos.gcd a0 b0))
end
(** val zeq_bool : z -> z -> bool **)
let zeq_bool x y =
match Z.compare x y with
| Eq -> true
| _ -> false
type 'c pExpr =
| PEc of 'c
| PEX of positive
| PEadd of 'c pExpr * 'c pExpr
| PEsub of 'c pExpr * 'c pExpr
| PEmul of 'c pExpr * 'c pExpr
| PEopp of 'c pExpr
| PEpow of 'c pExpr * n
type 'c pol =
| Pc of 'c
| Pinj of positive * 'c pol
| PX of 'c pol * positive * 'c pol
(** val p0 : 'a1 -> 'a1 pol **)
let p0 cO =
Pc cO
(** val p1 : 'a1 -> 'a1 pol **)
let p1 cI =
Pc cI
(** val peq : ('a1 -> 'a1 -> bool) -> 'a1 pol -> 'a1 pol -> bool **)
let rec peq ceqb p p' =
match p with
| Pc c -> (match p' with
| Pc c' -> ceqb c c'
| _ -> false)
| Pinj (j, q0) ->
(match p' with
| Pinj (j', q') ->
(match Coq_Pos.compare j j' with
| Eq -> peq ceqb q0 q'
| _ -> false)
| _ -> false)
| PX (p2, i, q0) ->
(match p' with
| PX (p'0, i', q') ->
(match Coq_Pos.compare i i' with
| Eq -> if peq ceqb p2 p'0 then peq ceqb q0 q' else false
| _ -> false)
| _ -> false)
(** val mkPinj : positive -> 'a1 pol -> 'a1 pol **)
let mkPinj j p = match p with
| Pc _ -> p
| Pinj (j', q0) -> Pinj ((Coq_Pos.add j j'), q0)
| PX (_, _, _) -> Pinj (j, p)
(** val mkPinj_pred : positive -> 'a1 pol -> 'a1 pol **)
let mkPinj_pred j p =
match j with
| XI j0 -> Pinj ((XO j0), p)
| XO j0 -> Pinj ((Coq_Pos.pred_double j0), p)
| XH -> p
(** val mkPX :
'a1 -> ('a1 -> 'a1 -> bool) -> 'a1 pol -> positive -> 'a1 pol -> 'a1 pol **)
let mkPX cO ceqb p i q0 =
match p with
| Pc c -> if ceqb c cO then mkPinj XH q0 else PX (p, i, q0)
| Pinj (_, _) -> PX (p, i, q0)
| PX (p', i', q') ->
if peq ceqb q' (p0 cO)
then PX (p', (Coq_Pos.add i' i), q0)
else PX (p, i, q0)
(** val mkXi : 'a1 -> 'a1 -> positive -> 'a1 pol **)
let mkXi cO cI i =
PX ((p1 cI), i, (p0 cO))
(** val mkX : 'a1 -> 'a1 -> 'a1 pol **)
let mkX cO cI =
mkXi cO cI XH
(** val popp : ('a1 -> 'a1) -> 'a1 pol -> 'a1 pol **)
let rec popp copp = function
| Pc c -> Pc (copp c)
| Pinj (j, q0) -> Pinj (j, (popp copp q0))
| PX (p2, i, q0) -> PX ((popp copp p2), i, (popp copp q0))
(** val paddC : ('a1 -> 'a1 -> 'a1) -> 'a1 pol -> 'a1 -> 'a1 pol **)
let rec paddC cadd p c =
match p with
| Pc c1 -> Pc (cadd c1 c)
| Pinj (j, q0) -> Pinj (j, (paddC cadd q0 c))
| PX (p2, i, q0) -> PX (p2, i, (paddC cadd q0 c))
(** val psubC : ('a1 -> 'a1 -> 'a1) -> 'a1 pol -> 'a1 -> 'a1 pol **)
let rec psubC csub p c =
match p with
| Pc c1 -> Pc (csub c1 c)
| Pinj (j, q0) -> Pinj (j, (psubC csub q0 c))
| PX (p2, i, q0) -> PX (p2, i, (psubC csub q0 c))
(** val paddI :
('a1 -> 'a1 -> 'a1) -> ('a1 pol -> 'a1 pol -> 'a1 pol) -> 'a1 pol ->
positive -> 'a1 pol -> 'a1 pol **)
let rec paddI cadd pop q0 j = function
| Pc c -> mkPinj j (paddC cadd q0 c)
| Pinj (j', q') ->
(match Z.pos_sub j' j with
| Z0 -> mkPinj j (pop q' q0)
| Zpos k -> mkPinj j (pop (Pinj (k, q')) q0)
| Zneg k -> mkPinj j' (paddI cadd pop q0 k q'))
| PX (p2, i, q') ->
(match j with
| XI j0 -> PX (p2, i, (paddI cadd pop q0 (XO j0) q'))
| XO j0 -> PX (p2, i, (paddI cadd pop q0 (Coq_Pos.pred_double j0) q'))
| XH -> PX (p2, i, (pop q' q0)))
(** val psubI :
('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1) -> ('a1 pol -> 'a1 pol -> 'a1 pol) ->
'a1 pol -> positive -> 'a1 pol -> 'a1 pol **)
let rec psubI cadd copp pop q0 j = function
| Pc c -> mkPinj j (paddC cadd (popp copp q0) c)
| Pinj (j', q') ->
(match Z.pos_sub j' j with
| Z0 -> mkPinj j (pop q' q0)
| Zpos k -> mkPinj j (pop (Pinj (k, q')) q0)
| Zneg k -> mkPinj j' (psubI cadd copp pop q0 k q'))
| PX (p2, i, q') ->
(match j with
| XI j0 -> PX (p2, i, (psubI cadd copp pop q0 (XO j0) q'))
| XO j0 -> PX (p2, i, (psubI cadd copp pop q0 (Coq_Pos.pred_double j0) q'))
| XH -> PX (p2, i, (pop q' q0)))
(** val paddX :
'a1 -> ('a1 -> 'a1 -> bool) -> ('a1 pol -> 'a1 pol -> 'a1 pol) -> 'a1 pol
-> positive -> 'a1 pol -> 'a1 pol **)
let rec paddX cO ceqb pop p' i' p = match p with
| Pc _ -> PX (p', i', p)
| Pinj (j, q') ->
(match j with
| XI j0 -> PX (p', i', (Pinj ((XO j0), q')))
| XO j0 -> PX (p', i', (Pinj ((Coq_Pos.pred_double j0), q')))
| XH -> PX (p', i', q'))
| PX (p2, i, q') ->
(match Z.pos_sub i i' with
| Z0 -> mkPX cO ceqb (pop p2 p') i q'
| Zpos k -> mkPX cO ceqb (pop (PX (p2, k, (p0 cO))) p') i' q'
| Zneg k -> mkPX cO ceqb (paddX cO ceqb pop p' k p2) i q')
(** val psubX :
'a1 -> ('a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> ('a1 pol -> 'a1 pol -> 'a1
pol) -> 'a1 pol -> positive -> 'a1 pol -> 'a1 pol **)
let rec psubX cO copp ceqb pop p' i' p = match p with
| Pc _ -> PX ((popp copp p'), i', p)
| Pinj (j, q') ->
(match j with
| XI j0 -> PX ((popp copp p'), i', (Pinj ((XO j0), q')))
| XO j0 -> PX ((popp copp p'), i', (Pinj ((Coq_Pos.pred_double j0), q')))
| XH -> PX ((popp copp p'), i', q'))
| PX (p2, i, q') ->
(match Z.pos_sub i i' with
| Z0 -> mkPX cO ceqb (pop p2 p') i q'
| Zpos k -> mkPX cO ceqb (pop (PX (p2, k, (p0 cO))) p') i' q'
| Zneg k -> mkPX cO ceqb (psubX cO copp ceqb pop p' k p2) i q')
(** val padd :
'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 pol -> 'a1 pol
-> 'a1 pol **)
let rec padd cO cadd ceqb p = function
| Pc c' -> paddC cadd p c'
| Pinj (j', q') -> paddI cadd (padd cO cadd ceqb) q' j' p
| PX (p'0, i', q') ->
(match p with
| Pc c -> PX (p'0, i', (paddC cadd q' c))
| Pinj (j, q0) ->
(match j with
| XI j0 -> PX (p'0, i', (padd cO cadd ceqb (Pinj ((XO j0), q0)) q'))
| XO j0 ->
PX (p'0, i',
(padd cO cadd ceqb (Pinj ((Coq_Pos.pred_double j0), q0)) q'))
| XH -> PX (p'0, i', (padd cO cadd ceqb q0 q')))
| PX (p2, i, q0) ->
(match Z.pos_sub i i' with
| Z0 ->
mkPX cO ceqb (padd cO cadd ceqb p2 p'0) i (padd cO cadd ceqb q0 q')
| Zpos k ->
mkPX cO ceqb (padd cO cadd ceqb (PX (p2, k, (p0 cO))) p'0) i'
(padd cO cadd ceqb q0 q')
| Zneg k ->
mkPX cO ceqb (paddX cO ceqb (padd cO cadd ceqb) p'0 k p2) i
(padd cO cadd ceqb q0 q')))
(** val psub :
'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1) -> ('a1
-> 'a1 -> bool) -> 'a1 pol -> 'a1 pol -> 'a1 pol **)
let rec psub cO cadd csub copp ceqb p = function
| Pc c' -> psubC csub p c'
| Pinj (j', q') -> psubI cadd copp (psub cO cadd csub copp ceqb) q' j' p
| PX (p'0, i', q') ->
(match p with
| Pc c -> PX ((popp copp p'0), i', (paddC cadd (popp copp q') c))
| Pinj (j, q0) ->
(match j with
| XI j0 ->
PX ((popp copp p'0), i',
(psub cO cadd csub copp ceqb (Pinj ((XO j0), q0)) q'))
| XO j0 ->
PX ((popp copp p'0), i',
(psub cO cadd csub copp ceqb (Pinj ((Coq_Pos.pred_double j0), q0))
q'))
| XH -> PX ((popp copp p'0), i', (psub cO cadd csub copp ceqb q0 q')))
| PX (p2, i, q0) ->
(match Z.pos_sub i i' with
| Z0 ->
mkPX cO ceqb (psub cO cadd csub copp ceqb p2 p'0) i
(psub cO cadd csub copp ceqb q0 q')
| Zpos k ->
mkPX cO ceqb (psub cO cadd csub copp ceqb (PX (p2, k, (p0 cO))) p'0)
i' (psub cO cadd csub copp ceqb q0 q')
| Zneg k ->
mkPX cO ceqb
(psubX cO copp ceqb (psub cO cadd csub copp ceqb) p'0 k p2) i
(psub cO cadd csub copp ceqb q0 q')))
(** val pmulC_aux :
'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 pol -> 'a1 ->
'a1 pol **)
let rec pmulC_aux cO cmul ceqb p c =
match p with
| Pc c' -> Pc (cmul c' c)
| Pinj (j, q0) -> mkPinj j (pmulC_aux cO cmul ceqb q0 c)
| PX (p2, i, q0) ->
mkPX cO ceqb (pmulC_aux cO cmul ceqb p2 c) i (pmulC_aux cO cmul ceqb q0 c)
(** val pmulC :
'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 pol ->
'a1 -> 'a1 pol **)
let pmulC cO cI cmul ceqb p c =
if ceqb c cO
then p0 cO
else if ceqb c cI then p else pmulC_aux cO cmul ceqb p c
(** val pmulI :
'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> ('a1 pol ->
'a1 pol -> 'a1 pol) -> 'a1 pol -> positive -> 'a1 pol -> 'a1 pol **)
let rec pmulI cO cI cmul ceqb pmul0 q0 j = function
| Pc c -> mkPinj j (pmulC cO cI cmul ceqb q0 c)
| Pinj (j', q') ->
(match Z.pos_sub j' j with
| Z0 -> mkPinj j (pmul0 q' q0)
| Zpos k -> mkPinj j (pmul0 (Pinj (k, q')) q0)
| Zneg k -> mkPinj j' (pmulI cO cI cmul ceqb pmul0 q0 k q'))
| PX (p', i', q') ->
(match j with
| XI j' ->
mkPX cO ceqb (pmulI cO cI cmul ceqb pmul0 q0 j p') i'
(pmulI cO cI cmul ceqb pmul0 q0 (XO j') q')
| XO j' ->
mkPX cO ceqb (pmulI cO cI cmul ceqb pmul0 q0 j p') i'
(pmulI cO cI cmul ceqb pmul0 q0 (Coq_Pos.pred_double j') q')
| XH ->
mkPX cO ceqb (pmulI cO cI cmul ceqb pmul0 q0 XH p') i' (pmul0 q' q0))
(** val pmul :
'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
-> bool) -> 'a1 pol -> 'a1 pol -> 'a1 pol **)
let rec pmul cO cI cadd cmul ceqb p p'' = match p'' with
| Pc c -> pmulC cO cI cmul ceqb p c
| Pinj (j', q') -> pmulI cO cI cmul ceqb (pmul cO cI cadd cmul ceqb) q' j' p
| PX (p', i', q') ->
(match p with
| Pc c -> pmulC cO cI cmul ceqb p'' c
| Pinj (j, q0) ->
let qQ' =
match j with
| XI j0 -> pmul cO cI cadd cmul ceqb (Pinj ((XO j0), q0)) q'
| XO j0 ->
pmul cO cI cadd cmul ceqb (Pinj ((Coq_Pos.pred_double j0), q0)) q'
| XH -> pmul cO cI cadd cmul ceqb q0 q'
in
mkPX cO ceqb (pmul cO cI cadd cmul ceqb p p') i' qQ'
| PX (p2, i, q0) ->
let qQ' = pmul cO cI cadd cmul ceqb q0 q' in
let pQ' = pmulI cO cI cmul ceqb (pmul cO cI cadd cmul ceqb) q' XH p2 in
let qP' = pmul cO cI cadd cmul ceqb (mkPinj XH q0) p' in
let pP' = pmul cO cI cadd cmul ceqb p2 p' in
padd cO cadd ceqb
(mkPX cO ceqb (padd cO cadd ceqb (mkPX cO ceqb pP' i (p0 cO)) qP') i'
(p0 cO)) (mkPX cO ceqb pQ' i qQ'))
(** val psquare :
'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
-> bool) -> 'a1 pol -> 'a1 pol **)
let rec psquare cO cI cadd cmul ceqb = function
| Pc c -> Pc (cmul c c)
| Pinj (j, q0) -> Pinj (j, (psquare cO cI cadd cmul ceqb q0))
| PX (p2, i, q0) ->
let twoPQ =
pmul cO cI cadd cmul ceqb p2
(mkPinj XH (pmulC cO cI cmul ceqb q0 (cadd cI cI)))
in
let q2 = psquare cO cI cadd cmul ceqb q0 in
let p3 = psquare cO cI cadd cmul ceqb p2 in
mkPX cO ceqb (padd cO cadd ceqb (mkPX cO ceqb p3 i (p0 cO)) twoPQ) i q2
(** val mk_X : 'a1 -> 'a1 -> positive -> 'a1 pol **)
let mk_X cO cI j =
mkPinj_pred j (mkX cO cI)
(** val ppow_pos :
'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
-> bool) -> ('a1 pol -> 'a1 pol) -> 'a1 pol -> 'a1 pol -> positive -> 'a1
pol **)
let rec ppow_pos cO cI cadd cmul ceqb subst_l res p = function
| XI p3 ->
subst_l
(pmul cO cI cadd cmul ceqb
(ppow_pos cO cI cadd cmul ceqb subst_l
(ppow_pos cO cI cadd cmul ceqb subst_l res p p3) p p3) p)
| XO p3 ->
ppow_pos cO cI cadd cmul ceqb subst_l
(ppow_pos cO cI cadd cmul ceqb subst_l res p p3) p p3
| XH -> subst_l (pmul cO cI cadd cmul ceqb res p)
(** val ppow_N :
'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
-> bool) -> ('a1 pol -> 'a1 pol) -> 'a1 pol -> n -> 'a1 pol **)
let ppow_N cO cI cadd cmul ceqb subst_l p = function
| N0 -> p1 cI
| Npos p2 -> ppow_pos cO cI cadd cmul ceqb subst_l (p1 cI) p p2
(** val norm_aux :
'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
-> 'a1) -> ('a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 pExpr -> 'a1 pol **)
let rec norm_aux cO cI cadd cmul csub copp ceqb = function
| PEc c -> Pc c
| PEX j -> mk_X cO cI j
| PEadd (pe1, pe2) ->
(match pe1 with
| PEopp pe3 ->
psub cO cadd csub copp ceqb
(norm_aux cO cI cadd cmul csub copp ceqb pe2)
(norm_aux cO cI cadd cmul csub copp ceqb pe3)
| _ ->
(match pe2 with
| PEopp pe3 ->
psub cO cadd csub copp ceqb
(norm_aux cO cI cadd cmul csub copp ceqb pe1)
(norm_aux cO cI cadd cmul csub copp ceqb pe3)
| _ ->
padd cO cadd ceqb (norm_aux cO cI cadd cmul csub copp ceqb pe1)
(norm_aux cO cI cadd cmul csub copp ceqb pe2)))
| PEsub (pe1, pe2) ->
psub cO cadd csub copp ceqb (norm_aux cO cI cadd cmul csub copp ceqb pe1)
(norm_aux cO cI cadd cmul csub copp ceqb pe2)
| PEmul (pe1, pe2) ->
pmul cO cI cadd cmul ceqb (norm_aux cO cI cadd cmul csub copp ceqb pe1)
(norm_aux cO cI cadd cmul csub copp ceqb pe2)
| PEopp pe1 -> popp copp (norm_aux cO cI cadd cmul csub copp ceqb pe1)
| PEpow (pe1, n0) ->
ppow_N cO cI cadd cmul ceqb (fun p -> p)
(norm_aux cO cI cadd cmul csub copp ceqb pe1) n0
type kind =
| IsProp
| IsBool
type 'a trace =
| Null
| Push of 'a * 'a trace
| Merge of 'a trace * 'a trace
type ('tA, 'tX, 'aA, 'aF) gFormula =
| TT of kind
| FF of kind
| X of kind * 'tX
| A of kind * 'tA * 'aA
| AND of kind * ('tA, 'tX, 'aA, 'aF) gFormula * ('tA, 'tX, 'aA, 'aF) gFormula
| OR of kind * ('tA, 'tX, 'aA, 'aF) gFormula * ('tA, 'tX, 'aA, 'aF) gFormula
| NOT of kind * ('tA, 'tX, 'aA, 'aF) gFormula
| IMPL of kind * ('tA, 'tX, 'aA, 'aF) gFormula * 'aF option
* ('tA, 'tX, 'aA, 'aF) gFormula
| IFF of kind * ('tA, 'tX, 'aA, 'aF) gFormula * ('tA, 'tX, 'aA, 'aF) gFormula
| EQ of ('tA, 'tX, 'aA, 'aF) gFormula * ('tA, 'tX, 'aA, 'aF) gFormula
(** val mapX :
(kind -> 'a2 -> 'a2) -> kind -> ('a1, 'a2, 'a3, 'a4) gFormula -> ('a1,
'a2, 'a3, 'a4) gFormula **)
let rec mapX f _ = function
| X (k0, x) -> X (k0, (f k0 x))
| AND (k0, f1, f2) -> AND (k0, (mapX f k0 f1), (mapX f k0 f2))
| OR (k0, f1, f2) -> OR (k0, (mapX f k0 f1), (mapX f k0 f2))
| NOT (k0, f1) -> NOT (k0, (mapX f k0 f1))