Debian Codegraph @

plugins/micromega/micromega.ml

raw symbols SCIP
1 (* *** DO NOT EDIT *** *)
2 (* This file is extracted from test-suite/output/MExtraction.v in the stdlib *)
3 (* *** DO NOT EDIT *** *)
4
5 type __ = Obj.t
6
7 type unit0 =
8 | Tt
9
10 (** val negb : bool -> bool **)
11
12 let negb = function
13 | true -> false
14 | false -> true
15
16 type nat =
17 | O
18 | S of nat
19
20 type ('a, 'b) sum =
21 | Inl of 'a
22 | Inr of 'b
23
24 (** val fst : ('a1 * 'a2) -> 'a1 **)
25
26 let fst = function
27 | x,_ -> x
28
29 (** val snd : ('a1 * 'a2) -> 'a2 **)
30
31 let snd = function
32 | _,y -> y
33
34 (** val app : 'a1 list -> 'a1 list -> 'a1 list **)
35
36 let rec app l m =
37 match l with
38 | [] -> m
39 | a::l1 -> a::(app l1 m)
40
41 type comparison =
42 | Eq
43 | Lt
44 | Gt
45
46 (** val compOpp : comparison -> comparison **)
47
48 let compOpp = function
49 | Eq -> Eq
50 | Lt -> Gt
51 | Gt -> Lt
52
53 module Coq__1 = struct
54 (** val add : nat -> nat -> nat **)
55
56 let rec add n0 m =
57 match n0 with
58 | O -> m
59 | S p -> S (add p m)
60 end
61 include Coq__1
62
63 (** val nth : nat -> 'a1 list -> 'a1 -> 'a1 **)
64
65 let rec nth n0 l default =
66 match n0 with
67 | O -> (match l with
68 | [] -> default
69 | x::_ -> x)
70 | S m -> (match l with
71 | [] -> default
72 | _::l' -> nth m l' default)
73
74 (** val rev_append : 'a1 list -> 'a1 list -> 'a1 list **)
75
76 let rec rev_append l l' =
77 match l with
78 | [] -> l'
79 | a::l0 -> rev_append l0 (a::l')
80
81 (** val map : ('a1 -> 'a2) -> 'a1 list -> 'a2 list **)
82
83 let rec map f = function
84 | [] -> []
85 | a::l0 -> (f a)::(map f l0)
86
87 (** val fold_left : ('a1 -> 'a2 -> 'a1) -> 'a2 list -> 'a1 -> 'a1 **)
88
89 let rec fold_left f l a0 =
90 match l with
91 | [] -> a0
92 | b::l0 -> fold_left f l0 (f a0 b)
93
94 (** val fold_right : ('a2 -> 'a1 -> 'a1) -> 'a1 -> 'a2 list -> 'a1 **)
95
96 let rec fold_right f a0 = function
97 | [] -> a0
98 | b::l0 -> f b (fold_right f a0 l0)
99
100 type positive =
101 | XI of positive
102 | XO of positive
103 | XH
104
105 type n =
106 | N0
107 | Npos of positive
108
109 type z =
110 | Z0
111 | Zpos of positive
112 | Zneg of positive
113
114 module Pos =
115 struct
116 type mask =
117 | IsNul
118 | IsPos of positive
119 | IsNeg
120 end
121
122 module Coq_Pos =
123 struct
124 (** val succ : positive -> positive **)
125
126 let rec succ = function
127 | XI p -> XO (succ p)
128 | XO p -> XI p
129 | XH -> XO XH
130
131 (** val add : positive -> positive -> positive **)
132
133 let rec add x y =
134 match x with
135 | XI p ->
136 (match y with
137 | XI q0 -> XO (add_carry p q0)
138 | XO q0 -> XI (add p q0)
139 | XH -> XO (succ p))
140 | XO p ->
141 (match y with
142 | XI q0 -> XI (add p q0)
143 | XO q0 -> XO (add p q0)
144 | XH -> XI p)
145 | XH -> (match y with
146 | XI q0 -> XO (succ q0)
147 | XO q0 -> XI q0
148 | XH -> XO XH)
149
150 (** val add_carry : positive -> positive -> positive **)
151
152 and add_carry x y =
153 match x with
154 | XI p ->
155 (match y with
156 | XI q0 -> XI (add_carry p q0)
157 | XO q0 -> XO (add_carry p q0)
158 | XH -> XI (succ p))
159 | XO p ->
160 (match y with
161 | XI q0 -> XO (add_carry p q0)
162 | XO q0 -> XI (add p q0)
163 | XH -> XO (succ p))
164 | XH ->
165 (match y with
166 | XI q0 -> XI (succ q0)
167 | XO q0 -> XO (succ q0)
168 | XH -> XI XH)
169
170 (** val pred_double : positive -> positive **)
171
172 let rec pred_double = function
173 | XI p -> XI (XO p)
174 | XO p -> XI (pred_double p)
175 | XH -> XH
176
177 type mask = Pos.mask =
178 | IsNul
179 | IsPos of positive
180 | IsNeg
181
182 (** val succ_double_mask : mask -> mask **)
183
184 let succ_double_mask = function
185 | IsNul -> IsPos XH
186 | IsPos p -> IsPos (XI p)
187 | IsNeg -> IsNeg
188
189 (** val double_mask : mask -> mask **)
190
191 let double_mask = function
192 | IsPos p -> IsPos (XO p)
193 | x0 -> x0
194
195 (** val double_pred_mask : positive -> mask **)
196
197 let double_pred_mask = function
198 | XI p -> IsPos (XO (XO p))
199 | XO p -> IsPos (XO (pred_double p))
200 | XH -> IsNul
201
202 (** val sub_mask : positive -> positive -> mask **)
203
204 let rec sub_mask x y =
205 match x with
206 | XI p ->
207 (match y with
208 | XI q0 -> double_mask (sub_mask p q0)
209 | XO q0 -> succ_double_mask (sub_mask p q0)
210 | XH -> IsPos (XO p))
211 | XO p ->
212 (match y with
213 | XI q0 -> succ_double_mask (sub_mask_carry p q0)
214 | XO q0 -> double_mask (sub_mask p q0)
215 | XH -> IsPos (pred_double p))
216 | XH -> (match y with
217 | XH -> IsNul
218 | _ -> IsNeg)
219
220 (** val sub_mask_carry : positive -> positive -> mask **)
221
222 and sub_mask_carry x y =
223 match x with
224 | XI p ->
225 (match y with
226 | XI q0 -> succ_double_mask (sub_mask_carry p q0)
227 | XO q0 -> double_mask (sub_mask p q0)
228 | XH -> IsPos (pred_double p))
229 | XO p ->
230 (match y with
231 | XI q0 -> double_mask (sub_mask_carry p q0)
232 | XO q0 -> succ_double_mask (sub_mask_carry p q0)
233 | XH -> double_pred_mask p)
234 | XH -> IsNeg
235
236 (** val sub : positive -> positive -> positive **)
237
238 let sub x y =
239 match sub_mask x y with
240 | IsPos z0 -> z0
241 | _ -> XH
242
243 (** val mul : positive -> positive -> positive **)
244
245 let rec mul x y =
246 match x with
247 | XI p -> add y (XO (mul p y))
248 | XO p -> XO (mul p y)
249 | XH -> y
250
251 (** val iter : ('a1 -> 'a1) -> 'a1 -> positive -> 'a1 **)
252
253 let rec iter f x = function
254 | XI n' -> f (iter f (iter f x n') n')
255 | XO n' -> iter f (iter f x n') n'
256 | XH -> f x
257
258 (** val size_nat : positive -> nat **)
259
260 let rec size_nat = function
261 | XI p2 -> S (size_nat p2)
262 | XO p2 -> S (size_nat p2)
263 | XH -> S O
264
265 (** val compare_cont : comparison -> positive -> positive -> comparison **)
266
267 let rec compare_cont r x y =
268 match x with
269 | XI p ->
270 (match y with
271 | XI q0 -> compare_cont r p q0
272 | XO q0 -> compare_cont Gt p q0
273 | XH -> Gt)
274 | XO p ->
275 (match y with
276 | XI q0 -> compare_cont Lt p q0
277 | XO q0 -> compare_cont r p q0
278 | XH -> Gt)
279 | XH -> (match y with
280 | XH -> r
281 | _ -> Lt)
282
283 (** val compare : positive -> positive -> comparison **)
284
285 let compare =
286 compare_cont Eq
287
288 (** val max : positive -> positive -> positive **)
289
290 let max p p' =
291 match compare p p' with
292 | Gt -> p
293 | _ -> p'
294
295 (** val eqb : positive -> positive -> bool **)
296
297 let rec eqb p q0 =
298 match p with
299 | XI p2 -> (match q0 with
300 | XI q1 -> eqb p2 q1
301 | _ -> false)
302 | XO p2 -> (match q0 with
303 | XO q1 -> eqb p2 q1
304 | _ -> false)
305 | XH -> (match q0 with
306 | XH -> true
307 | _ -> false)
308
309 (** val leb : positive -> positive -> bool **)
310
311 let leb x y =
312 match compare x y with
313 | Gt -> false
314 | _ -> true
315
316 (** val gcdn : nat -> positive -> positive -> positive **)
317
318 let rec gcdn n0 a b =
319 match n0 with
320 | O -> XH
321 | S n1 ->
322 (match a with
323 | XI a' ->
324 (match b with
325 | XI b' ->
326 (match compare a' b' with
327 | Eq -> a
328 | Lt -> gcdn n1 (sub b' a') a
329 | Gt -> gcdn n1 (sub a' b') b)
330 | XO b0 -> gcdn n1 a b0
331 | XH -> XH)
332 | XO a0 ->
333 (match b with
334 | XI _ -> gcdn n1 a0 b
335 | XO b0 -> XO (gcdn n1 a0 b0)
336 | XH -> XH)
337 | XH -> XH)
338
339 (** val gcd : positive -> positive -> positive **)
340
341 let gcd a b =
342 gcdn (Coq__1.add (size_nat a) (size_nat b)) a b
343
344 (** val of_succ_nat : nat -> positive **)
345
346 let rec of_succ_nat = function
347 | O -> XH
348 | S x -> succ (of_succ_nat x)
349 end
350
351 module N =
352 struct
353 (** val of_nat : nat -> n **)
354
355 let of_nat = function
356 | O -> N0
357 | S n' -> Npos (Coq_Pos.of_succ_nat n')
358 end
359
360 (** val pow_pos : ('a1 -> 'a1 -> 'a1) -> 'a1 -> positive -> 'a1 **)
361
362 let rec pow_pos rmul x = function
363 | XI i0 -> let p = pow_pos rmul x i0 in rmul x (rmul p p)
364 | XO i0 -> let p = pow_pos rmul x i0 in rmul p p
365 | XH -> x
366
367 module Z =
368 struct
369 (** val double : z -> z **)
370
371 let double = function
372 | Z0 -> Z0
373 | Zpos p -> Zpos (XO p)
374 | Zneg p -> Zneg (XO p)
375
376 (** val succ_double : z -> z **)
377
378 let succ_double = function
379 | Z0 -> Zpos XH
380 | Zpos p -> Zpos (XI p)
381 | Zneg p -> Zneg (Coq_Pos.pred_double p)
382
383 (** val pred_double : z -> z **)
384
385 let pred_double = function
386 | Z0 -> Zneg XH
387 | Zpos p -> Zpos (Coq_Pos.pred_double p)
388 | Zneg p -> Zneg (XI p)
389
390 (** val pos_sub : positive -> positive -> z **)
391
392 let rec pos_sub x y =
393 match x with
394 | XI p ->
395 (match y with
396 | XI q0 -> double (pos_sub p q0)
397 | XO q0 -> succ_double (pos_sub p q0)
398 | XH -> Zpos (XO p))
399 | XO p ->
400 (match y with
401 | XI q0 -> pred_double (pos_sub p q0)
402 | XO q0 -> double (pos_sub p q0)
403 | XH -> Zpos (Coq_Pos.pred_double p))
404 | XH ->
405 (match y with
406 | XI q0 -> Zneg (XO q0)
407 | XO q0 -> Zneg (Coq_Pos.pred_double q0)
408 | XH -> Z0)
409
410 (** val add : z -> z -> z **)
411
412 let add x y =
413 match x with
414 | Z0 -> y
415 | Zpos x' ->
416 (match y with
417 | Z0 -> x
418 | Zpos y' -> Zpos (Coq_Pos.add x' y')
419 | Zneg y' -> pos_sub x' y')
420 | Zneg x' ->
421 (match y with
422 | Z0 -> x
423 | Zpos y' -> pos_sub y' x'
424 | Zneg y' -> Zneg (Coq_Pos.add x' y'))
425
426 (** val opp : z -> z **)
427
428 let opp = function
429 | Z0 -> Z0
430 | Zpos x0 -> Zneg x0
431 | Zneg x0 -> Zpos x0
432
433 (** val sub : z -> z -> z **)
434
435 let sub m n0 =
436 add m (opp n0)
437
438 (** val mul : z -> z -> z **)
439
440 let mul x y =
441 match x with
442 | Z0 -> Z0
443 | Zpos x' ->
444 (match y with
445 | Z0 -> Z0
446 | Zpos y' -> Zpos (Coq_Pos.mul x' y')
447 | Zneg y' -> Zneg (Coq_Pos.mul x' y'))
448 | Zneg x' ->
449 (match y with
450 | Z0 -> Z0
451 | Zpos y' -> Zneg (Coq_Pos.mul x' y')
452 | Zneg y' -> Zpos (Coq_Pos.mul x' y'))
453
454 (** val pow_pos : z -> positive -> z **)
455
456 let pow_pos z0 =
457 Coq_Pos.iter (mul z0) (Zpos XH)
458
459 (** val pow : z -> z -> z **)
460
461 let pow x = function
462 | Z0 -> Zpos XH
463 | Zpos p -> pow_pos x p
464 | Zneg _ -> Z0
465
466 (** val compare : z -> z -> comparison **)
467
468 let compare x y =
469 match x with
470 | Z0 -> (match y with
471 | Z0 -> Eq
472 | Zpos _ -> Lt
473 | Zneg _ -> Gt)
474 | Zpos x' -> (match y with
475 | Zpos y' -> Coq_Pos.compare x' y'
476 | _ -> Gt)
477 | Zneg x' ->
478 (match y with
479 | Zneg y' -> compOpp (Coq_Pos.compare x' y')
480 | _ -> Lt)
481
482 (** val leb : z -> z -> bool **)
483
484 let leb x y =
485 match compare x y with
486 | Gt -> false
487 | _ -> true
488
489 (** val ltb : z -> z -> bool **)
490
491 let ltb x y =
492 match compare x y with
493 | Lt -> true
494 | _ -> false
495
496 (** val gtb : z -> z -> bool **)
497
498 let gtb x y =
499 match compare x y with
500 | Gt -> true
501 | _ -> false
502
503 (** val eqb : z -> z -> bool **)
504
505 let eqb x y =
506 match x with
507 | Z0 -> (match y with
508 | Z0 -> true
509 | _ -> false)
510 | Zpos p -> (match y with
511 | Zpos q0 -> Coq_Pos.eqb p q0
512 | _ -> false)
513 | Zneg p -> (match y with
514 | Zneg q0 -> Coq_Pos.eqb p q0
515 | _ -> false)
516
517 (** val max : z -> z -> z **)
518
519 let max n0 m =
520 match compare n0 m with
521 | Lt -> m
522 | _ -> n0
523
524 (** val abs : z -> z **)
525
526 let abs = function
527 | Zneg p -> Zpos p
528 | x -> x
529
530 (** val to_N : z -> n **)
531
532 let to_N = function
533 | Zpos p -> Npos p
534 | _ -> N0
535
536 (** val of_nat : nat -> z **)
537
538 let of_nat = function
539 | O -> Z0
540 | S n1 -> Zpos (Coq_Pos.of_succ_nat n1)
541
542 (** val of_N : n -> z **)
543
544 let of_N = function
545 | N0 -> Z0
546 | Npos p -> Zpos p
547
548 (** val pos_div_eucl : positive -> z -> z * z **)
549
550 let rec pos_div_eucl a b =
551 match a with
552 | XI a' ->
553 let q0,r = pos_div_eucl a' b in
554 let r' = add (mul (Zpos (XO XH)) r) (Zpos XH) in
555 if ltb r' b
556 then (mul (Zpos (XO XH)) q0),r'
557 else (add (mul (Zpos (XO XH)) q0) (Zpos XH)),(sub r' b)
558 | XO a' ->
559 let q0,r = pos_div_eucl a' b in
560 let r' = mul (Zpos (XO XH)) r in
561 if ltb r' b
562 then (mul (Zpos (XO XH)) q0),r'
563 else (add (mul (Zpos (XO XH)) q0) (Zpos XH)),(sub r' b)
564 | XH -> if leb (Zpos (XO XH)) b then Z0,(Zpos XH) else (Zpos XH),Z0
565
566 (** val div_eucl : z -> z -> z * z **)
567
568 let div_eucl a b =
569 match a with
570 | Z0 -> Z0,Z0
571 | Zpos a' ->
572 (match b with
573 | Z0 -> Z0,a
574 | Zpos _ -> pos_div_eucl a' b
575 | Zneg b' ->
576 let q0,r = pos_div_eucl a' (Zpos b') in
577 (match r with
578 | Z0 -> (opp q0),Z0
579 | _ -> (opp (add q0 (Zpos XH))),(add b r)))
580 | Zneg a' ->
581 (match b with
582 | Z0 -> Z0,a
583 | Zpos _ ->
584 let q0,r = pos_div_eucl a' b in
585 (match r with
586 | Z0 -> (opp q0),Z0
587 | _ -> (opp (add q0 (Zpos XH))),(sub b r))
588 | Zneg b' -> let q0,r = pos_div_eucl a' (Zpos b') in q0,(opp r))
589
590 (** val div : z -> z -> z **)
591
592 let div a b =
593 let q0,_ = div_eucl a b in q0
594
595 (** val gcd : z -> z -> z **)
596
597 let gcd a b =
598 match a with
599 | Z0 -> abs b
600 | Zpos a0 ->
601 (match b with
602 | Z0 -> abs a
603 | Zpos b0 -> Zpos (Coq_Pos.gcd a0 b0)
604 | Zneg b0 -> Zpos (Coq_Pos.gcd a0 b0))
605 | Zneg a0 ->
606 (match b with
607 | Z0 -> abs a
608 | Zpos b0 -> Zpos (Coq_Pos.gcd a0 b0)
609 | Zneg b0 -> Zpos (Coq_Pos.gcd a0 b0))
610 end
611
612 type 'c pExpr =
613 | PEc of 'c
614 | PEX of positive
615 | PEadd of 'c pExpr * 'c pExpr
616 | PEsub of 'c pExpr * 'c pExpr
617 | PEmul of 'c pExpr * 'c pExpr
618 | PEopp of 'c pExpr
619 | PEpow of 'c pExpr * n
620
621 type 'c pol =
622 | Pc of 'c
623 | Pinj of positive * 'c pol
624 | PX of 'c pol * positive * 'c pol
625
626 (** val p0 : 'a1 -> 'a1 pol **)
627
628 let p0 cO =
629 Pc cO
630
631 (** val p1 : 'a1 -> 'a1 pol **)
632
633 let p1 cI =
634 Pc cI
635
636 (** val peq : ('a1 -> 'a1 -> bool) -> 'a1 pol -> 'a1 pol -> bool **)
637
638 let rec peq ceqb p p' =
639 match p with
640 | Pc c -> (match p' with
641 | Pc c' -> ceqb c c'
642 | _ -> false)
643 | Pinj (j, q0) ->
644 (match p' with
645 | Pinj (j', q') ->
646 (match Coq_Pos.compare j j' with
647 | Eq -> peq ceqb q0 q'
648 | _ -> false)
649 | _ -> false)
650 | PX (p2, i, q0) ->
651 (match p' with
652 | PX (p'0, i', q') ->
653 (match Coq_Pos.compare i i' with
654 | Eq -> if peq ceqb p2 p'0 then peq ceqb q0 q' else false
655 | _ -> false)
656 | _ -> false)
657
658 (** val mkPinj : positive -> 'a1 pol -> 'a1 pol **)
659
660 let mkPinj j p = match p with
661 | Pc _ -> p
662 | Pinj (j', q0) -> Pinj ((Coq_Pos.add j j'), q0)
663 | PX (_, _, _) -> Pinj (j, p)
664
665 (** val mkPinj_pred : positive -> 'a1 pol -> 'a1 pol **)
666
667 let mkPinj_pred j p =
668 match j with
669 | XI j0 -> Pinj ((XO j0), p)
670 | XO j0 -> Pinj ((Coq_Pos.pred_double j0), p)
671 | XH -> p
672
673 (** val mkPX :
674 'a1 -> ('a1 -> 'a1 -> bool) -> 'a1 pol -> positive -> 'a1 pol -> 'a1 pol **)
675
676 let mkPX cO ceqb p i q0 =
677 match p with
678 | Pc c -> if ceqb c cO then mkPinj XH q0 else PX (p, i, q0)
679 | Pinj (_, _) -> PX (p, i, q0)
680 | PX (p', i', q') ->
681 if peq ceqb q' (p0 cO)
682 then PX (p', (Coq_Pos.add i' i), q0)
683 else PX (p, i, q0)
684
685 (** val mkXi : 'a1 -> 'a1 -> positive -> 'a1 pol **)
686
687 let mkXi cO cI i =
688 PX ((p1 cI), i, (p0 cO))
689
690 (** val mkX : 'a1 -> 'a1 -> 'a1 pol **)
691
692 let mkX cO cI =
693 mkXi cO cI XH
694
695 (** val popp : ('a1 -> 'a1) -> 'a1 pol -> 'a1 pol **)
696
697 let rec popp copp = function
698 | Pc c -> Pc (copp c)
699 | Pinj (j, q0) -> Pinj (j, (popp copp q0))
700 | PX (p2, i, q0) -> PX ((popp copp p2), i, (popp copp q0))
701
702 (** val paddC : ('a1 -> 'a1 -> 'a1) -> 'a1 pol -> 'a1 -> 'a1 pol **)
703
704 let rec paddC cadd p c =
705 match p with
706 | Pc c1 -> Pc (cadd c1 c)
707 | Pinj (j, q0) -> Pinj (j, (paddC cadd q0 c))
708 | PX (p2, i, q0) -> PX (p2, i, (paddC cadd q0 c))
709
710 (** val psubC : ('a1 -> 'a1 -> 'a1) -> 'a1 pol -> 'a1 -> 'a1 pol **)
711
712 let rec psubC csub p c =
713 match p with
714 | Pc c1 -> Pc (csub c1 c)
715 | Pinj (j, q0) -> Pinj (j, (psubC csub q0 c))
716 | PX (p2, i, q0) -> PX (p2, i, (psubC csub q0 c))
717
718 (** val paddI :
719 ('a1 -> 'a1 -> 'a1) -> ('a1 pol -> 'a1 pol -> 'a1 pol) -> 'a1 pol ->
720 positive -> 'a1 pol -> 'a1 pol **)
721
722 let rec paddI cadd pop q0 j = function
723 | Pc c -> mkPinj j (paddC cadd q0 c)
724 | Pinj (j', q') ->
725 (match Z.pos_sub j' j with
726 | Z0 -> mkPinj j (pop q' q0)
727 | Zpos k -> mkPinj j (pop (Pinj (k, q')) q0)
728 | Zneg k -> mkPinj j' (paddI cadd pop q0 k q'))
729 | PX (p2, i, q') ->
730 (match j with
731 | XI j0 -> PX (p2, i, (paddI cadd pop q0 (XO j0) q'))
732 | XO j0 -> PX (p2, i, (paddI cadd pop q0 (Coq_Pos.pred_double j0) q'))
733 | XH -> PX (p2, i, (pop q' q0)))
734
735 (** val psubI :
736 ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1) -> ('a1 pol -> 'a1 pol -> 'a1 pol) ->
737 'a1 pol -> positive -> 'a1 pol -> 'a1 pol **)
738
739 let rec psubI cadd copp pop q0 j = function
740 | Pc c -> mkPinj j (paddC cadd (popp copp q0) c)
741 | Pinj (j', q') ->
742 (match Z.pos_sub j' j with
743 | Z0 -> mkPinj j (pop q' q0)
744 | Zpos k -> mkPinj j (pop (Pinj (k, q')) q0)
745 | Zneg k -> mkPinj j' (psubI cadd copp pop q0 k q'))
746 | PX (p2, i, q') ->
747 (match j with
748 | XI j0 -> PX (p2, i, (psubI cadd copp pop q0 (XO j0) q'))
749 | XO j0 -> PX (p2, i, (psubI cadd copp pop q0 (Coq_Pos.pred_double j0) q'))
750 | XH -> PX (p2, i, (pop q' q0)))
751
752 (** val paddX :
753 'a1 -> ('a1 -> 'a1 -> bool) -> ('a1 pol -> 'a1 pol -> 'a1 pol) -> 'a1 pol
754 -> positive -> 'a1 pol -> 'a1 pol **)
755
756 let rec paddX cO ceqb pop p' i' p = match p with
757 | Pc _ -> PX (p', i', p)
758 | Pinj (j, q') ->
759 (match j with
760 | XI j0 -> PX (p', i', (Pinj ((XO j0), q')))
761 | XO j0 -> PX (p', i', (Pinj ((Coq_Pos.pred_double j0), q')))
762 | XH -> PX (p', i', q'))
763 | PX (p2, i, q') ->
764 (match Z.pos_sub i i' with
765 | Z0 -> mkPX cO ceqb (pop p2 p') i q'
766 | Zpos k -> mkPX cO ceqb (pop (PX (p2, k, (p0 cO))) p') i' q'
767 | Zneg k -> mkPX cO ceqb (paddX cO ceqb pop p' k p2) i q')
768
769 (** val psubX :
770 'a1 -> ('a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> ('a1 pol -> 'a1 pol -> 'a1
771 pol) -> 'a1 pol -> positive -> 'a1 pol -> 'a1 pol **)
772
773 let rec psubX cO copp ceqb pop p' i' p = match p with
774 | Pc _ -> PX ((popp copp p'), i', p)
775 | Pinj (j, q') ->
776 (match j with
777 | XI j0 -> PX ((popp copp p'), i', (Pinj ((XO j0), q')))
778 | XO j0 -> PX ((popp copp p'), i', (Pinj ((Coq_Pos.pred_double j0), q')))
779 | XH -> PX ((popp copp p'), i', q'))
780 | PX (p2, i, q') ->
781 (match Z.pos_sub i i' with
782 | Z0 -> mkPX cO ceqb (pop p2 p') i q'
783 | Zpos k -> mkPX cO ceqb (pop (PX (p2, k, (p0 cO))) p') i' q'
784 | Zneg k -> mkPX cO ceqb (psubX cO copp ceqb pop p' k p2) i q')
785
786 (** val padd :
787 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 pol -> 'a1 pol
788 -> 'a1 pol **)
789
790 let rec padd cO cadd ceqb p = function
791 | Pc c' -> paddC cadd p c'
792 | Pinj (j', q') -> paddI cadd (padd cO cadd ceqb) q' j' p
793 | PX (p'0, i', q') ->
794 (match p with
795 | Pc c -> PX (p'0, i', (paddC cadd q' c))
796 | Pinj (j, q0) ->
797 (match j with
798 | XI j0 -> PX (p'0, i', (padd cO cadd ceqb (Pinj ((XO j0), q0)) q'))
799 | XO j0 ->
800 PX (p'0, i',
801 (padd cO cadd ceqb (Pinj ((Coq_Pos.pred_double j0), q0)) q'))
802 | XH -> PX (p'0, i', (padd cO cadd ceqb q0 q')))
803 | PX (p2, i, q0) ->
804 (match Z.pos_sub i i' with
805 | Z0 ->
806 mkPX cO ceqb (padd cO cadd ceqb p2 p'0) i (padd cO cadd ceqb q0 q')
807 | Zpos k ->
808 mkPX cO ceqb (padd cO cadd ceqb (PX (p2, k, (p0 cO))) p'0) i'
809 (padd cO cadd ceqb q0 q')
810 | Zneg k ->
811 mkPX cO ceqb (paddX cO ceqb (padd cO cadd ceqb) p'0 k p2) i
812 (padd cO cadd ceqb q0 q')))
813
814 (** val psub :
815 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1) -> ('a1
816 -> 'a1 -> bool) -> 'a1 pol -> 'a1 pol -> 'a1 pol **)
817
818 let rec psub cO cadd csub copp ceqb p = function
819 | Pc c' -> psubC csub p c'
820 | Pinj (j', q') -> psubI cadd copp (psub cO cadd csub copp ceqb) q' j' p
821 | PX (p'0, i', q') ->
822 (match p with
823 | Pc c -> PX ((popp copp p'0), i', (paddC cadd (popp copp q') c))
824 | Pinj (j, q0) ->
825 (match j with
826 | XI j0 ->
827 PX ((popp copp p'0), i',
828 (psub cO cadd csub copp ceqb (Pinj ((XO j0), q0)) q'))
829 | XO j0 ->
830 PX ((popp copp p'0), i',
831 (psub cO cadd csub copp ceqb (Pinj ((Coq_Pos.pred_double j0), q0))
832 q'))
833 | XH -> PX ((popp copp p'0), i', (psub cO cadd csub copp ceqb q0 q')))
834 | PX (p2, i, q0) ->
835 (match Z.pos_sub i i' with
836 | Z0 ->
837 mkPX cO ceqb (psub cO cadd csub copp ceqb p2 p'0) i
838 (psub cO cadd csub copp ceqb q0 q')
839 | Zpos k ->
840 mkPX cO ceqb (psub cO cadd csub copp ceqb (PX (p2, k, (p0 cO))) p'0)
841 i' (psub cO cadd csub copp ceqb q0 q')
842 | Zneg k ->
843 mkPX cO ceqb
844 (psubX cO copp ceqb (psub cO cadd csub copp ceqb) p'0 k p2) i
845 (psub cO cadd csub copp ceqb q0 q')))
846
847 (** val pmulC_aux :
848 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 pol -> 'a1 ->
849 'a1 pol **)
850
851 let rec pmulC_aux cO cmul ceqb p c =
852 match p with
853 | Pc c' -> Pc (cmul c' c)
854 | Pinj (j, q0) -> mkPinj j (pmulC_aux cO cmul ceqb q0 c)
855 | PX (p2, i, q0) ->
856 mkPX cO ceqb (pmulC_aux cO cmul ceqb p2 c) i (pmulC_aux cO cmul ceqb q0 c)
857
858 (** val pmulC :
859 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 pol ->
860 'a1 -> 'a1 pol **)
861
862 let pmulC cO cI cmul ceqb p c =
863 if ceqb c cO
864 then p0 cO
865 else if ceqb c cI then p else pmulC_aux cO cmul ceqb p c
866
867 (** val pmulI :
868 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> ('a1 pol ->
869 'a1 pol -> 'a1 pol) -> 'a1 pol -> positive -> 'a1 pol -> 'a1 pol **)
870
871 let rec pmulI cO cI cmul ceqb pmul0 q0 j = function
872 | Pc c -> mkPinj j (pmulC cO cI cmul ceqb q0 c)
873 | Pinj (j', q') ->
874 (match Z.pos_sub j' j with
875 | Z0 -> mkPinj j (pmul0 q' q0)
876 | Zpos k -> mkPinj j (pmul0 (Pinj (k, q')) q0)
877 | Zneg k -> mkPinj j' (pmulI cO cI cmul ceqb pmul0 q0 k q'))
878 | PX (p', i', q') ->
879 (match j with
880 | XI j' ->
881 mkPX cO ceqb (pmulI cO cI cmul ceqb pmul0 q0 j p') i'
882 (pmulI cO cI cmul ceqb pmul0 q0 (XO j') q')
883 | XO j' ->
884 mkPX cO ceqb (pmulI cO cI cmul ceqb pmul0 q0 j p') i'
885 (pmulI cO cI cmul ceqb pmul0 q0 (Coq_Pos.pred_double j') q')
886 | XH ->
887 mkPX cO ceqb (pmulI cO cI cmul ceqb pmul0 q0 XH p') i' (pmul0 q' q0))
888
889 (** val pmul :
890 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
891 -> bool) -> 'a1 pol -> 'a1 pol -> 'a1 pol **)
892
893 let rec pmul cO cI cadd cmul ceqb p p'' = match p'' with
894 | Pc c -> pmulC cO cI cmul ceqb p c
895 | Pinj (j', q') -> pmulI cO cI cmul ceqb (pmul cO cI cadd cmul ceqb) q' j' p
896 | PX (p', i', q') ->
897 (match p with
898 | Pc c -> pmulC cO cI cmul ceqb p'' c
899 | Pinj (j, q0) ->
900 let qQ' =
901 match j with
902 | XI j0 -> pmul cO cI cadd cmul ceqb (Pinj ((XO j0), q0)) q'
903 | XO j0 ->
904 pmul cO cI cadd cmul ceqb (Pinj ((Coq_Pos.pred_double j0), q0)) q'
905 | XH -> pmul cO cI cadd cmul ceqb q0 q'
906 in
907 mkPX cO ceqb (pmul cO cI cadd cmul ceqb p p') i' qQ'
908 | PX (p2, i, q0) ->
909 let qQ' = pmul cO cI cadd cmul ceqb q0 q' in
910 let pQ' = pmulI cO cI cmul ceqb (pmul cO cI cadd cmul ceqb) q' XH p2 in
911 let qP' = pmul cO cI cadd cmul ceqb (mkPinj XH q0) p' in
912 let pP' = pmul cO cI cadd cmul ceqb p2 p' in
913 padd cO cadd ceqb
914 (mkPX cO ceqb (padd cO cadd ceqb (mkPX cO ceqb pP' i (p0 cO)) qP') i'
915 (p0 cO))
916 (mkPX cO ceqb pQ' i qQ'))
917
918 (** val psquare :
919 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
920 -> bool) -> 'a1 pol -> 'a1 pol **)
921
922 let rec psquare cO cI cadd cmul ceqb = function
923 | Pc c -> Pc (cmul c c)
924 | Pinj (j, q0) -> Pinj (j, (psquare cO cI cadd cmul ceqb q0))
925 | PX (p2, i, q0) ->
926 let twoPQ =
927 pmul cO cI cadd cmul ceqb p2
928 (mkPinj XH (pmulC cO cI cmul ceqb q0 (cadd cI cI)))
929 in
930 let q2 = psquare cO cI cadd cmul ceqb q0 in
931 let p3 = psquare cO cI cadd cmul ceqb p2 in
932 mkPX cO ceqb (padd cO cadd ceqb (mkPX cO ceqb p3 i (p0 cO)) twoPQ) i q2
933
934 (** val mk_X : 'a1 -> 'a1 -> positive -> 'a1 pol **)
935
936 let mk_X cO cI j =
937 mkPinj_pred j (mkX cO cI)
938
939 (** val ppow_pos :
940 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
941 -> bool) -> ('a1 pol -> 'a1 pol) -> 'a1 pol -> 'a1 pol -> positive -> 'a1
942 pol **)
943
944 let rec ppow_pos cO cI cadd cmul ceqb subst_l res p = function
945 | XI p3 ->
946 subst_l
947 (pmul cO cI cadd cmul ceqb
948 (ppow_pos cO cI cadd cmul ceqb subst_l
949 (ppow_pos cO cI cadd cmul ceqb subst_l res p p3) p p3)
950 p)
951 | XO p3 ->
952 ppow_pos cO cI cadd cmul ceqb subst_l
953 (ppow_pos cO cI cadd cmul ceqb subst_l res p p3) p p3
954 | XH -> subst_l (pmul cO cI cadd cmul ceqb res p)
955
956 (** val ppow_N :
957 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
958 -> bool) -> ('a1 pol -> 'a1 pol) -> 'a1 pol -> n -> 'a1 pol **)
959
960 let ppow_N cO cI cadd cmul ceqb subst_l p = function
961 | N0 -> p1 cI
962 | Npos p2 -> ppow_pos cO cI cadd cmul ceqb subst_l (p1 cI) p p2
963
964 (** val norm_aux :
965 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
966 -> 'a1) -> ('a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 pExpr -> 'a1 pol **)
967
968 let rec norm_aux cO cI cadd cmul csub copp ceqb = function
969 | PEc c -> Pc c
970 | PEX j -> mk_X cO cI j
971 | PEadd (pe1, pe2) ->
972 (match pe1 with
973 | PEopp pe3 ->
974 psub cO cadd csub copp ceqb
975 (norm_aux cO cI cadd cmul csub copp ceqb pe2)
976 (norm_aux cO cI cadd cmul csub copp ceqb pe3)
977 | _ ->
978 (match pe2 with
979 | PEopp pe3 ->
980 psub cO cadd csub copp ceqb
981 (norm_aux cO cI cadd cmul csub copp ceqb pe1)
982 (norm_aux cO cI cadd cmul csub copp ceqb pe3)
983 | _ ->
984 padd cO cadd ceqb (norm_aux cO cI cadd cmul csub copp ceqb pe1)
985 (norm_aux cO cI cadd cmul csub copp ceqb pe2)))
986 | PEsub (pe1, pe2) ->
987 psub cO cadd csub copp ceqb (norm_aux cO cI cadd cmul csub copp ceqb pe1)
988 (norm_aux cO cI cadd cmul csub copp ceqb pe2)
989 | PEmul (pe1, pe2) ->
990 pmul cO cI cadd cmul ceqb (norm_aux cO cI cadd cmul csub copp ceqb pe1)
991 (norm_aux cO cI cadd cmul csub copp ceqb pe2)
992 | PEopp pe1 -> popp copp (norm_aux cO cI cadd cmul csub copp ceqb pe1)
993 | PEpow (pe1, n0) ->
994 ppow_N cO cI cadd cmul ceqb (fun p -> p)
995 (norm_aux cO cI cadd cmul csub copp ceqb pe1) n0
996
997 type kind =
998 | IsProp
999 | IsBool
1000
1001 type 'a trace =
1002 | Null
1003 | Push of 'a * 'a trace
1004 | Merge of 'a trace * 'a trace
1005
1006 type ('tA, 'tX, 'aA, 'aF) gFormula =
1007 | TT of kind
1008 | FF of kind
1009 | X of kind * 'tX
1010 | A of kind * 'tA * 'aA
1011 | AND of kind * ('tA, 'tX, 'aA, 'aF) gFormula * ('tA, 'tX, 'aA, 'aF) gFormula
1012 | OR of kind * ('tA, 'tX, 'aA, 'aF) gFormula * ('tA, 'tX, 'aA, 'aF) gFormula
1013 | NOT of kind * ('tA, 'tX, 'aA, 'aF) gFormula
1014 | IMPL of kind * ('tA, 'tX, 'aA, 'aF) gFormula * 'aF option
1015 * ('tA, 'tX, 'aA, 'aF) gFormula
1016 | IFF of kind * ('tA, 'tX, 'aA, 'aF) gFormula * ('tA, 'tX, 'aA, 'aF) gFormula
1017 | EQ of ('tA, 'tX, 'aA, 'aF) gFormula * ('tA, 'tX, 'aA, 'aF) gFormula
1018
1019 (** val mapX :
1020 (kind -> 'a2 -> 'a2) -> kind -> ('a1, 'a2, 'a3, 'a4) gFormula -> ('a1,
1021 'a2, 'a3, 'a4) gFormula **)
1022
1023 let rec mapX f _ = function
1024 | X (k0, x) -> X (k0, (f k0 x))
1025 | AND (k0, f1, f2) -> AND (k0, (mapX f k0 f1), (mapX f k0 f2))
1026 | OR (k0, f1, f2) -> OR (k0, (mapX f k0 f1), (mapX f k0 f2))
1027 | NOT (k0, f1) -> NOT (k0, (mapX f k0 f1))
1028 | IMPL (k0, f1, o, f2) -> IMPL (k0, (mapX f k0 f1), o, (mapX f k0 f2))
1029 | IFF (k0, f1, f2) -> IFF (k0, (mapX f k0 f1), (mapX f k0 f2))
1030 | EQ (f1, f2) -> EQ ((mapX f IsBool f1), (mapX f IsBool f2))
1031 | x -> x
1032
1033 (** val foldA :
1034 ('a5 -> 'a3 -> 'a5) -> kind -> ('a1, 'a2, 'a3, 'a4) gFormula -> 'a5 -> 'a5 **)
1035
1036 let rec foldA f _ f0 acc =
1037 match f0 with
1038 | A (_, _, an) -> f acc an
1039 | AND (k0, f1, f2) -> foldA f k0 f1 (foldA f k0 f2 acc)
1040 | OR (k0, f1, f2) -> foldA f k0 f1 (foldA f k0 f2 acc)
1041 | NOT (k0, f1) -> foldA f k0 f1 acc
1042 | IMPL (k0, f1, _, f2) -> foldA f k0 f1 (foldA f k0 f2 acc)
1043 | IFF (k0, f1, f2) -> foldA f k0 f1 (foldA f k0 f2 acc)
1044 | EQ (f1, f2) -> foldA f IsBool f1 (foldA f IsBool f2 acc)
1045 | _ -> acc
1046
1047 (** val cons_id : 'a1 option -> 'a1 list -> 'a1 list **)
1048
1049 let cons_id id l =
1050 match id with
1051 | Some id0 -> id0::l
1052 | None -> l
1053
1054 (** val ids_of_formula : kind -> ('a1, 'a2, 'a3, 'a4) gFormula -> 'a4 list **)
1055
1056 let rec ids_of_formula _ = function
1057 | IMPL (k0, _, id, f') -> cons_id id (ids_of_formula k0 f')
1058 | _ -> []
1059
1060 (** val collect_annot : kind -> ('a1, 'a2, 'a3, 'a4) gFormula -> 'a3 list **)
1061
1062 let rec collect_annot _ = function
1063 | A (_, _, a) -> a::[]
1064 | AND (k0, f1, f2) -> app (collect_annot k0 f1) (collect_annot k0 f2)
1065 | OR (k0, f1, f2) -> app (collect_annot k0 f1) (collect_annot k0 f2)
1066 | NOT (k0, f0) -> collect_annot k0 f0
1067 | IMPL (k0, f1, _, f2) -> app (collect_annot k0 f1) (collect_annot k0 f2)
1068 | IFF (k0, f1, f2) -> app (collect_annot k0 f1) (collect_annot k0 f2)
1069 | EQ (f1, f2) -> app (collect_annot IsBool f1) (collect_annot IsBool f2)
1070 | _ -> []
1071
1072 type rtyp = __
1073
1074 type eKind = __
1075
1076 type 'a bFormula = ('a, eKind, unit0, unit0) gFormula
1077
1078 (** val map_bformula :
1079 kind -> ('a1 -> 'a2) -> ('a1, 'a3, 'a4, 'a5) gFormula -> ('a2, 'a3, 'a4,
1080 'a5) gFormula **)
1081
1082 let rec map_bformula _ fct = function
1083 | TT k -> TT k
1084 | FF k -> FF k
1085 | X (k, p) -> X (k, p)
1086 | A (k, a, t0) -> A (k, (fct a), t0)
1087 | AND (k0, f1, f2) ->
1088 AND (k0, (map_bformula k0 fct f1), (map_bformula k0 fct f2))
1089 | OR (k0, f1, f2) ->
1090 OR (k0, (map_bformula k0 fct f1), (map_bformula k0 fct f2))
1091 | NOT (k0, f0) -> NOT (k0, (map_bformula k0 fct f0))
1092 | IMPL (k0, f1, a, f2) ->
1093 IMPL (k0, (map_bformula k0 fct f1), a, (map_bformula k0 fct f2))
1094 | IFF (k0, f1, f2) ->
1095 IFF (k0, (map_bformula k0 fct f1), (map_bformula k0 fct f2))
1096 | EQ (f1, f2) ->
1097 EQ ((map_bformula IsBool fct f1), (map_bformula IsBool fct f2))
1098
1099 type ('x, 'annot) clause = ('x * 'annot) list
1100
1101 type ('x, 'annot) cnf = ('x, 'annot) clause list
1102
1103 (** val cnf_tt : ('a1, 'a2) cnf **)
1104
1105 let cnf_tt =
1106 []
1107
1108 (** val cnf_ff : ('a1, 'a2) cnf **)
1109
1110 let cnf_ff =
1111 []::[]
1112
1113 (** val add_term :
1114 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1 * 'a2) -> ('a1, 'a2)
1115 clause -> ('a1, 'a2) clause option **)
1116
1117 let rec add_term unsat deduce t0 = function
1118 | [] ->
1119 (match deduce (fst t0) (fst t0) with
1120 | Some u -> if unsat u then None else Some (t0::[])
1121 | None -> Some (t0::[]))
1122 | t'::cl0 ->
1123 (match deduce (fst t0) (fst t') with
1124 | Some u ->
1125 if unsat u
1126 then None
1127 else (match add_term unsat deduce t0 cl0 with
1128 | Some cl' -> Some (t'::cl')
1129 | None -> None)
1130 | None ->
1131 (match add_term unsat deduce t0 cl0 with
1132 | Some cl' -> Some (t'::cl')
1133 | None -> None))
1134
1135 (** val or_clause :
1136 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1, 'a2) clause -> ('a1,
1137 'a2) clause -> ('a1, 'a2) clause option **)
1138
1139 let rec or_clause unsat deduce cl1 cl2 =
1140 match cl1 with
1141 | [] -> Some cl2
1142 | t0::cl ->
1143 (match add_term unsat deduce t0 cl2 with
1144 | Some cl' -> or_clause unsat deduce cl cl'
1145 | None -> None)
1146
1147 (** val xor_clause_cnf :
1148 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1, 'a2) clause -> ('a1,
1149 'a2) cnf -> ('a1, 'a2) cnf **)
1150
1151 let xor_clause_cnf unsat deduce t0 f =
1152 fold_left (fun acc e ->
1153 match or_clause unsat deduce t0 e with
1154 | Some cl -> cl::acc
1155 | None -> acc) f []
1156
1157 (** val or_clause_cnf :
1158 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1, 'a2) clause -> ('a1,
1159 'a2) cnf -> ('a1, 'a2) cnf **)
1160
1161 let or_clause_cnf unsat deduce t0 f =
1162 match t0 with
1163 | [] -> f
1164 | _::_ -> xor_clause_cnf unsat deduce t0 f
1165
1166 (** val or_cnf :
1167 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1, 'a2) cnf -> ('a1,
1168 'a2) cnf -> ('a1, 'a2) cnf **)
1169
1170 let rec or_cnf unsat deduce f f' =
1171 match f with
1172 | [] -> cnf_tt
1173 | e::rst ->
1174 rev_append (or_cnf unsat deduce rst f') (or_clause_cnf unsat deduce e f')
1175
1176 (** val and_cnf : ('a1, 'a2) cnf -> ('a1, 'a2) cnf -> ('a1, 'a2) cnf **)
1177
1178 let and_cnf =
1179 rev_append
1180
1181 type ('term, 'annot, 'tX, 'aF) tFormula = ('term, 'tX, 'annot, 'aF) gFormula
1182
1183 (** val is_cnf_tt : ('a1, 'a2) cnf -> bool **)
1184
1185 let is_cnf_tt = function
1186 | [] -> true
1187 | _::_ -> false
1188
1189 (** val is_cnf_ff : ('a1, 'a2) cnf -> bool **)
1190
1191 let is_cnf_ff = function
1192 | [] -> false
1193 | c0::l ->
1194 (match c0 with
1195 | [] -> (match l with
1196 | [] -> true
1197 | _::_ -> false)
1198 | _::_ -> false)
1199
1200 (** val and_cnf_opt : ('a1, 'a2) cnf -> ('a1, 'a2) cnf -> ('a1, 'a2) cnf **)
1201
1202 let and_cnf_opt f1 f2 =
1203 if if is_cnf_ff f1 then true else is_cnf_ff f2
1204 then cnf_ff
1205 else if is_cnf_tt f2 then f1 else and_cnf f1 f2
1206
1207 (** val or_cnf_opt :
1208 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1, 'a2) cnf -> ('a1,
1209 'a2) cnf -> ('a1, 'a2) cnf **)
1210
1211 let or_cnf_opt unsat deduce f1 f2 =
1212 if if is_cnf_tt f1 then true else is_cnf_tt f2
1213 then cnf_tt
1214 else if is_cnf_ff f2 then f1 else or_cnf unsat deduce f1 f2
1215
1216 (** val mk_and :
1217 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> (bool -> kind -> ('a1,
1218 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf) -> kind -> bool -> ('a1, 'a3,
1219 'a4, 'a5) tFormula -> ('a1, 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf **)
1220
1221 let mk_and unsat deduce rEC k pol0 f1 f2 =
1222 if pol0
1223 then and_cnf_opt (rEC pol0 k f1) (rEC pol0 k f2)
1224 else or_cnf_opt unsat deduce (rEC pol0 k f1) (rEC pol0 k f2)
1225
1226 (** val mk_or :
1227 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> (bool -> kind -> ('a1,
1228 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf) -> kind -> bool -> ('a1, 'a3,
1229 'a4, 'a5) tFormula -> ('a1, 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf **)
1230
1231 let mk_or unsat deduce rEC k pol0 f1 f2 =
1232 if pol0
1233 then or_cnf_opt unsat deduce (rEC pol0 k f1) (rEC pol0 k f2)
1234 else and_cnf_opt (rEC pol0 k f1) (rEC pol0 k f2)
1235
1236 (** val mk_impl :
1237 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> (bool -> kind -> ('a1,
1238 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf) -> kind -> bool -> ('a1, 'a3,
1239 'a4, 'a5) tFormula -> ('a1, 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf **)
1240
1241 let mk_impl unsat deduce rEC k pol0 f1 f2 =
1242 if pol0
1243 then or_cnf_opt unsat deduce (rEC (negb pol0) k f1) (rEC pol0 k f2)
1244 else and_cnf_opt (rEC (negb pol0) k f1) (rEC pol0 k f2)
1245
1246 (** val mk_iff :
1247 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> (bool -> kind -> ('a1,
1248 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf) -> kind -> bool -> ('a1, 'a3,
1249 'a4, 'a5) tFormula -> ('a1, 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf **)
1250
1251 let mk_iff unsat deduce rEC k pol0 f1 f2 =
1252 or_cnf_opt unsat deduce
1253 (and_cnf_opt (rEC (negb pol0) k f1) (rEC false k f2))
1254 (and_cnf_opt (rEC pol0 k f1) (rEC true k f2))
1255
1256 (** val is_bool : kind -> ('a1, 'a2, 'a3, 'a4) tFormula -> bool option **)
1257
1258 let is_bool _ = function
1259 | TT _ -> Some true
1260 | FF _ -> Some false
1261 | _ -> None
1262
1263 (** val xcnf :
1264 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> ('a1 -> 'a3 -> ('a2, 'a3)
1265 cnf) -> ('a1 -> 'a3 -> ('a2, 'a3) cnf) -> bool -> kind -> ('a1, 'a3, 'a4,
1266 'a5) tFormula -> ('a2, 'a3) cnf **)
1267
1268 let rec xcnf unsat deduce normalise1 negate0 pol0 _ = function
1269 | TT _ -> if pol0 then cnf_tt else cnf_ff
1270 | FF _ -> if pol0 then cnf_ff else cnf_tt
1271 | X (_, _) -> cnf_ff
1272 | A (_, x, t0) -> if pol0 then normalise1 x t0 else negate0 x t0
1273 | AND (k0, e1, e2) ->
1274 mk_and unsat deduce (fun x x0 x1 ->
1275 xcnf unsat deduce normalise1 negate0 x x0 x1) k0 pol0 e1 e2
1276 | OR (k0, e1, e2) ->
1277 mk_or unsat deduce (fun x x0 x1 ->
1278 xcnf unsat deduce normalise1 negate0 x x0 x1) k0 pol0 e1 e2
1279 | NOT (k0, e) -> xcnf unsat deduce normalise1 negate0 (negb pol0) k0 e
1280 | IMPL (k0, e1, _, e2) ->
1281 mk_impl unsat deduce (fun x x0 x1 ->
1282 xcnf unsat deduce normalise1 negate0 x x0 x1) k0 pol0 e1 e2
1283 | IFF (k0, e1, e2) ->
1284 (match is_bool k0 e2 with
1285 | Some isb ->
1286 xcnf unsat deduce normalise1 negate0 (if isb then pol0 else negb pol0)
1287 k0 e1
1288 | None ->
1289 mk_iff unsat deduce (fun x x0 x1 ->
1290 xcnf unsat deduce normalise1 negate0 x x0 x1) k0 pol0 e1 e2)
1291 | EQ (e1, e2) ->
1292 (match is_bool IsBool e2 with
1293 | Some isb ->
1294 xcnf unsat deduce normalise1 negate0 (if isb then pol0 else negb pol0)
1295 IsBool e1
1296 | None ->
1297 mk_iff unsat deduce (fun x x0 x1 ->
1298 xcnf unsat deduce normalise1 negate0 x x0 x1) IsBool pol0 e1 e2)
1299
1300 (** val radd_term :
1301 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1 * 'a2) -> ('a1, 'a2)
1302 clause -> (('a1, 'a2) clause, 'a2 trace) sum **)
1303
1304 let rec radd_term unsat deduce t0 = function
1305 | [] ->
1306 (match deduce (fst t0) (fst t0) with
1307 | Some u -> if unsat u then Inr (Push ((snd t0), Null)) else Inl (t0::[])
1308 | None -> Inl (t0::[]))
1309 | t'::cl0 ->
1310 (match deduce (fst t0) (fst t') with
1311 | Some u ->
1312 if unsat u
1313 then Inr (Push ((snd t0), (Push ((snd t'), Null))))
1314 else (match radd_term unsat deduce t0 cl0 with
1315 | Inl cl' -> Inl (t'::cl')
1316 | Inr l -> Inr l)
1317 | None ->
1318 (match radd_term unsat deduce t0 cl0 with
1319 | Inl cl' -> Inl (t'::cl')
1320 | Inr l -> Inr l))
1321
1322 (** val ror_clause :
1323 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1 * 'a2) list -> ('a1,
1324 'a2) clause -> (('a1, 'a2) clause, 'a2 trace) sum **)
1325
1326 let rec ror_clause unsat deduce cl1 cl2 =
1327 match cl1 with
1328 | [] -> Inl cl2
1329 | t0::cl ->
1330 (match radd_term unsat deduce t0 cl2 with
1331 | Inl cl' -> ror_clause unsat deduce cl cl'
1332 | Inr l -> Inr l)
1333
1334 (** val xror_clause_cnf :
1335 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1 * 'a2) list -> ('a1,
1336 'a2) clause list -> ('a1, 'a2) clause list * 'a2 trace **)
1337
1338 let xror_clause_cnf unsat deduce t0 f =
1339 fold_left (fun pat e ->
1340 let acc,tg = pat in
1341 (match ror_clause unsat deduce t0 e with
1342 | Inl cl -> (cl::acc),tg
1343 | Inr l -> acc,(Merge (tg, l))))
1344 f ([],Null)
1345
1346 (** val ror_clause_cnf :
1347 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1 * 'a2) list -> ('a1,
1348 'a2) clause list -> ('a1, 'a2) clause list * 'a2 trace **)
1349
1350 let ror_clause_cnf unsat deduce t0 f =
1351 match t0 with
1352 | [] -> f,Null
1353 | _::_ -> xror_clause_cnf unsat deduce t0 f
1354
1355 (** val ror_cnf :
1356 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1, 'a2) clause list ->
1357 ('a1, 'a2) clause list -> ('a1, 'a2) cnf * 'a2 trace **)
1358
1359 let rec ror_cnf unsat deduce f f' =
1360 match f with
1361 | [] -> cnf_tt,Null
1362 | e::rst ->
1363 let rst_f',t0 = ror_cnf unsat deduce rst f' in
1364 let e_f',t' = ror_clause_cnf unsat deduce e f' in
1365 (rev_append rst_f' e_f'),(Merge (t0, t'))
1366
1367 (** val ror_cnf_opt :
1368 ('a1 -> bool) -> ('a1 -> 'a1 -> 'a1 option) -> ('a1, 'a2) cnf -> ('a1,
1369 'a2) cnf -> ('a1, 'a2) cnf * 'a2 trace **)
1370
1371 let ror_cnf_opt unsat deduce f1 f2 =
1372 if is_cnf_tt f1
1373 then cnf_tt,Null
1374 else if is_cnf_tt f2
1375 then cnf_tt,Null
1376 else if is_cnf_ff f2 then f1,Null else ror_cnf unsat deduce f1 f2
1377
1378 (** val ratom : ('a1, 'a2) cnf -> 'a2 -> ('a1, 'a2) cnf * 'a2 trace **)
1379
1380 let ratom c a =
1381 if if is_cnf_ff c then true else is_cnf_tt c
1382 then c,(Push (a, Null))
1383 else c,Null
1384
1385 (** val rxcnf_and :
1386 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> (bool -> kind -> ('a1,
1387 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf * 'a3 trace) -> bool -> kind ->
1388 ('a1, 'a3, 'a4, 'a5) tFormula -> ('a1, 'a3, 'a4, 'a5) tFormula -> ('a2,
1389 'a3) cnf * 'a3 trace **)
1390
1391 let rxcnf_and unsat deduce rXCNF polarity k e1 e2 =
1392 let e3,t1 = rXCNF polarity k e1 in
1393 let e4,t2 = rXCNF polarity k e2 in
1394 if polarity
1395 then (and_cnf_opt e3 e4),(Merge (t1, t2))
1396 else let f',t' = ror_cnf_opt unsat deduce e3 e4 in
1397 f',(Merge (t1, (Merge (t2, t'))))
1398
1399 (** val rxcnf_or :
1400 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> (bool -> kind -> ('a1,
1401 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf * 'a3 trace) -> bool -> kind ->
1402 ('a1, 'a3, 'a4, 'a5) tFormula -> ('a1, 'a3, 'a4, 'a5) tFormula -> ('a2,
1403 'a3) cnf * 'a3 trace **)
1404
1405 let rxcnf_or unsat deduce rXCNF polarity k e1 e2 =
1406 let e3,t1 = rXCNF polarity k e1 in
1407 let e4,t2 = rXCNF polarity k e2 in
1408 if polarity
1409 then let f',t' = ror_cnf_opt unsat deduce e3 e4 in
1410 f',(Merge (t1, (Merge (t2, t'))))
1411 else (and_cnf_opt e3 e4),(Merge (t1, t2))
1412
1413 (** val rxcnf_impl :
1414 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> (bool -> kind -> ('a1,
1415 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf * 'a3 trace) -> bool -> kind ->
1416 ('a1, 'a3, 'a4, 'a5) tFormula -> ('a1, 'a3, 'a4, 'a5) tFormula -> ('a2,
1417 'a3) cnf * 'a3 trace **)
1418
1419 let rxcnf_impl unsat deduce rXCNF polarity k e1 e2 =
1420 let e3,t1 = rXCNF (negb polarity) k e1 in
1421 if polarity
1422 then if is_cnf_tt e3
1423 then e3,t1
1424 else if is_cnf_ff e3
1425 then rXCNF polarity k e2
1426 else let e4,t2 = rXCNF polarity k e2 in
1427 let f',t' = ror_cnf_opt unsat deduce e3 e4 in
1428 f',(Merge (t1, (Merge (t2, t'))))
1429 else let e4,t2 = rXCNF polarity k e2 in (and_cnf_opt e3 e4),(Merge (t1, t2))
1430
1431 (** val rxcnf_iff :
1432 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> (bool -> kind -> ('a1,
1433 'a3, 'a4, 'a5) tFormula -> ('a2, 'a3) cnf * 'a3 trace) -> bool -> kind ->
1434 ('a1, 'a3, 'a4, 'a5) tFormula -> ('a1, 'a3, 'a4, 'a5) tFormula -> ('a2,
1435 'a3) cnf * 'a3 trace **)
1436
1437 let rxcnf_iff unsat deduce rXCNF polarity k e1 e2 =
1438 let c1,t1 = rXCNF (negb polarity) k e1 in
1439 let c2,t2 = rXCNF false k e2 in
1440 let c3,t3 = rXCNF polarity k e1 in
1441 let c4,t4 = rXCNF true k e2 in
1442 let f',t' = ror_cnf_opt unsat deduce (and_cnf_opt c1 c2) (and_cnf_opt c3 c4)
1443 in
1444 f',(Merge (t1, (Merge (t2, (Merge (t3, (Merge (t4, t'))))))))
1445
1446 (** val rxcnf :
1447 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> ('a1 -> 'a3 -> ('a2, 'a3)
1448 cnf) -> ('a1 -> 'a3 -> ('a2, 'a3) cnf) -> bool -> kind -> ('a1, 'a3, 'a4,
1449 'a5) tFormula -> ('a2, 'a3) cnf * 'a3 trace **)
1450
1451 let rec rxcnf unsat deduce normalise1 negate0 polarity _ = function
1452 | TT _ -> if polarity then cnf_tt,Null else cnf_ff,Null
1453 | FF _ -> if polarity then cnf_ff,Null else cnf_tt,Null
1454 | X (_, _) -> cnf_ff,Null
1455 | A (_, x, t0) ->
1456 ratom (if polarity then normalise1 x t0 else negate0 x t0) t0
1457 | AND (k0, e1, e2) ->
1458 rxcnf_and unsat deduce (fun x x0 x1 ->
1459 rxcnf unsat deduce normalise1 negate0 x x0 x1) polarity k0 e1 e2
1460 | OR (k0, e1, e2) ->
1461 rxcnf_or unsat deduce (fun x x0 x1 ->
1462 rxcnf unsat deduce normalise1 negate0 x x0 x1) polarity k0 e1 e2
1463 | NOT (k0, e) -> rxcnf unsat deduce normalise1 negate0 (negb polarity) k0 e
1464 | IMPL (k0, e1, _, e2) ->
1465 rxcnf_impl unsat deduce (fun x x0 x1 ->
1466 rxcnf unsat deduce normalise1 negate0 x x0 x1) polarity k0 e1 e2
1467 | IFF (k0, e1, e2) ->
1468 rxcnf_iff unsat deduce (fun x x0 x1 ->
1469 rxcnf unsat deduce normalise1 negate0 x x0 x1) polarity k0 e1 e2
1470 | EQ (e1, e2) ->
1471 rxcnf_iff unsat deduce (fun x x0 x1 ->
1472 rxcnf unsat deduce normalise1 negate0 x x0 x1) polarity IsBool e1 e2
1473
1474 type ('term, 'annot, 'tX) to_constrT = { mkTT : (kind -> 'tX);
1475 mkFF : (kind -> 'tX);
1476 mkA : (kind -> 'term -> 'annot ->
1477 'tX);
1478 mkAND : (kind -> 'tX -> 'tX -> 'tX);
1479 mkOR : (kind -> 'tX -> 'tX -> 'tX);
1480 mkIMPL : (kind -> 'tX -> 'tX -> 'tX);
1481 mkIFF : (kind -> 'tX -> 'tX -> 'tX);
1482 mkNOT : (kind -> 'tX -> 'tX);
1483 mkEQ : ('tX -> 'tX -> 'tX) }
1484
1485 (** val aformula :
1486 ('a1, 'a2, 'a3) to_constrT -> kind -> ('a1, 'a2, 'a3, 'a4) tFormula -> 'a3 **)
1487
1488 let rec aformula to_constr _ = function
1489 | TT b -> to_constr.mkTT b
1490 | FF b -> to_constr.mkFF b
1491 | X (_, p) -> p
1492 | A (b, x, t0) -> to_constr.mkA b x t0
1493 | AND (k0, f1, f2) ->
1494 to_constr.mkAND k0 (aformula to_constr k0 f1) (aformula to_constr k0 f2)
1495 | OR (k0, f1, f2) ->
1496 to_constr.mkOR k0 (aformula to_constr k0 f1) (aformula to_constr k0 f2)
1497 | NOT (k0, f0) -> to_constr.mkNOT k0 (aformula to_constr k0 f0)
1498 | IMPL (k0, f1, _, f2) ->
1499 to_constr.mkIMPL k0 (aformula to_constr k0 f1) (aformula to_constr k0 f2)
1500 | IFF (k0, f1, f2) ->
1501 to_constr.mkIFF k0 (aformula to_constr k0 f1) (aformula to_constr k0 f2)
1502 | EQ (f1, f2) ->
1503 to_constr.mkEQ (aformula to_constr IsBool f1) (aformula to_constr IsBool f2)
1504
1505 (** val is_X : kind -> ('a1, 'a2, 'a3, 'a4) tFormula -> 'a3 option **)
1506
1507 let is_X _ = function
1508 | X (_, p) -> Some p
1509 | _ -> None
1510
1511 (** val abs_and :
1512 ('a1, 'a2, 'a3) to_constrT -> kind -> ('a1, 'a2, 'a3, 'a4) tFormula ->
1513 ('a1, 'a2, 'a3, 'a4) tFormula -> (kind -> ('a1, 'a2, 'a3, 'a4) tFormula
1514 -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula) ->
1515 ('a1, 'a3, 'a2, 'a4) gFormula **)
1516
1517 let abs_and to_constr k f1 f2 c =
1518 match is_X k f1 with
1519 | Some _ -> X (k, (aformula to_constr k (c k f1 f2)))
1520 | None ->
1521 (match is_X k f2 with
1522 | Some _ -> X (k, (aformula to_constr k (c k f1 f2)))
1523 | None -> c k f1 f2)
1524
1525 (** val abs_or :
1526 ('a1, 'a2, 'a3) to_constrT -> kind -> ('a1, 'a2, 'a3, 'a4) tFormula ->
1527 ('a1, 'a2, 'a3, 'a4) tFormula -> (kind -> ('a1, 'a2, 'a3, 'a4) tFormula
1528 -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula) ->
1529 ('a1, 'a3, 'a2, 'a4) gFormula **)
1530
1531 let abs_or to_constr k f1 f2 c =
1532 match is_X k f1 with
1533 | Some _ ->
1534 (match is_X k f2 with
1535 | Some _ -> X (k, (aformula to_constr k (c k f1 f2)))
1536 | None -> c k f1 f2)
1537 | None -> c k f1 f2
1538
1539 (** val abs_not :
1540 ('a1, 'a2, 'a3) to_constrT -> kind -> ('a1, 'a2, 'a3, 'a4) tFormula ->
1541 (kind -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula)
1542 -> ('a1, 'a3, 'a2, 'a4) gFormula **)
1543
1544 let abs_not to_constr k f1 c =
1545 match is_X k f1 with
1546 | Some _ -> X (k, (aformula to_constr k (c k f1)))
1547 | None -> c k f1
1548
1549 (** val mk_arrow :
1550 'a4 option -> kind -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3,
1551 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula **)
1552
1553 let mk_arrow o k f1 f2 =
1554 match o with
1555 | Some _ ->
1556 (match is_X k f1 with
1557 | Some _ -> f2
1558 | None -> IMPL (k, f1, o, f2))
1559 | None -> IMPL (k, f1, None, f2)
1560
1561 (** val abst_simpl :
1562 ('a1, 'a2, 'a3) to_constrT -> ('a2 -> bool) -> kind -> ('a1, 'a2, 'a3,
1563 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula **)
1564
1565 let rec abst_simpl to_constr needA _ = function
1566 | A (k, x, t0) ->
1567 if needA t0 then A (k, x, t0) else X (k, (to_constr.mkA k x t0))
1568 | AND (k0, f1, f2) ->
1569 AND (k0, (abst_simpl to_constr needA k0 f1),
1570 (abst_simpl to_constr needA k0 f2))
1571 | OR (k0, f1, f2) ->
1572 OR (k0, (abst_simpl to_constr needA k0 f1),
1573 (abst_simpl to_constr needA k0 f2))
1574 | NOT (k0, f0) -> NOT (k0, (abst_simpl to_constr needA k0 f0))
1575 | IMPL (k0, f1, o, f2) ->
1576 IMPL (k0, (abst_simpl to_constr needA k0 f1), o,
1577 (abst_simpl to_constr needA k0 f2))
1578 | IFF (k0, f1, f2) ->
1579 IFF (k0, (abst_simpl to_constr needA k0 f1),
1580 (abst_simpl to_constr needA k0 f2))
1581 | EQ (f1, f2) ->
1582 EQ ((abst_simpl to_constr needA IsBool f1),
1583 (abst_simpl to_constr needA IsBool f2))
1584 | x -> x
1585
1586 (** val abst_and :
1587 ('a1, 'a2, 'a3) to_constrT -> (bool -> kind -> ('a1, 'a2, 'a3, 'a4)
1588 tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula) -> bool -> kind -> ('a1, 'a2,
1589 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3,
1590 'a4) tFormula **)
1591
1592 let abst_and to_constr rEC pol0 k f1 f2 =
1593 if pol0
1594 then abs_and to_constr k (rEC pol0 k f1) (rEC pol0 k f2) (fun x x0 x1 ->
1595 AND (x, x0, x1))
1596 else abs_or to_constr k (rEC pol0 k f1) (rEC pol0 k f2) (fun x x0 x1 -> AND
1597 (x, x0, x1))
1598
1599 (** val abst_or :
1600 ('a1, 'a2, 'a3) to_constrT -> (bool -> kind -> ('a1, 'a2, 'a3, 'a4)
1601 tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula) -> bool -> kind -> ('a1, 'a2,
1602 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3,
1603 'a4) tFormula **)
1604
1605 let abst_or to_constr rEC pol0 k f1 f2 =
1606 if pol0
1607 then abs_or to_constr k (rEC pol0 k f1) (rEC pol0 k f2) (fun x x0 x1 -> OR
1608 (x, x0, x1))
1609 else abs_and to_constr k (rEC pol0 k f1) (rEC pol0 k f2) (fun x x0 x1 -> OR
1610 (x, x0, x1))
1611
1612 (** val abst_impl :
1613 ('a1, 'a2, 'a3) to_constrT -> (bool -> kind -> ('a1, 'a2, 'a3, 'a4)
1614 tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula) -> bool -> 'a4 option -> kind
1615 -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula ->
1616 ('a1, 'a2, 'a3, 'a4) tFormula **)
1617
1618 let abst_impl to_constr rEC pol0 o k f1 f2 =
1619 if pol0
1620 then abs_or to_constr k (rEC (negb pol0) k f1) (rEC pol0 k f2) (mk_arrow o)
1621 else abs_and to_constr k (rEC (negb pol0) k f1) (rEC pol0 k f2) (mk_arrow o)
1622
1623 (** val or_is_X :
1624 kind -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula ->
1625 bool **)
1626
1627 let or_is_X k f1 f2 =
1628 match is_X k f1 with
1629 | Some _ -> true
1630 | None -> (match is_X k f2 with
1631 | Some _ -> true
1632 | None -> false)
1633
1634 (** val abs_iff :
1635 ('a1, 'a2, 'a3) to_constrT -> kind -> ('a1, 'a2, 'a3, 'a4) tFormula ->
1636 ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1,
1637 'a2, 'a3, 'a4) tFormula -> kind -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1,
1638 'a2, 'a3, 'a4) tFormula **)
1639
1640 let abs_iff to_constr k nf1 ff2 f1 tf2 r def =
1641 if (&&) (or_is_X k nf1 ff2) (or_is_X k f1 tf2)
1642 then X (r, (aformula to_constr r def))
1643 else def
1644
1645 (** val abst_iff :
1646 ('a1, 'a2, 'a3) to_constrT -> ('a2 -> bool) -> (bool -> kind -> ('a1,
1647 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula) -> bool -> kind
1648 -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula ->
1649 ('a1, 'a2, 'a3, 'a4) tFormula **)
1650
1651 let abst_iff to_constr needA rEC pol0 k f1 f2 =
1652 abs_iff to_constr k (rEC (negb pol0) k f1) (rEC false k f2) (rEC pol0 k f1)
1653 (rEC true k f2) k (IFF (k, (abst_simpl to_constr needA k f1),
1654 (abst_simpl to_constr needA k f2)))
1655
1656 (** val abst_eq :
1657 ('a1, 'a2, 'a3) to_constrT -> ('a2 -> bool) -> (bool -> kind -> ('a1,
1658 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula) -> bool ->
1659 ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula -> ('a1,
1660 'a2, 'a3, 'a4) tFormula **)
1661
1662 let abst_eq to_constr needA rEC pol0 f1 f2 =
1663 abs_iff to_constr IsBool (rEC (negb pol0) IsBool f1) (rEC false IsBool f2)
1664 (rEC pol0 IsBool f1) (rEC true IsBool f2) IsProp (EQ
1665 ((abst_simpl to_constr needA IsBool f1),
1666 (abst_simpl to_constr needA IsBool f2)))
1667
1668 (** val abst_form :
1669 ('a1, 'a2, 'a3) to_constrT -> ('a2 -> bool) -> bool -> kind -> ('a1, 'a2,
1670 'a3, 'a4) tFormula -> ('a1, 'a2, 'a3, 'a4) tFormula **)
1671
1672 let rec abst_form to_constr needA pol0 _ = function
1673 | TT k -> if pol0 then TT k else X (k, (to_constr.mkTT k))
1674 | FF k -> if pol0 then X (k, (to_constr.mkFF k)) else FF k
1675 | X (k, p) -> X (k, p)
1676 | A (k, x, t0) ->
1677 if needA t0 then A (k, x, t0) else X (k, (to_constr.mkA k x t0))
1678 | AND (k0, f1, f2) ->
1679 abst_and to_constr (abst_form to_constr needA) pol0 k0 f1 f2
1680 | OR (k0, f1, f2) ->
1681 abst_or to_constr (abst_form to_constr needA) pol0 k0 f1 f2
1682 | NOT (k0, f0) ->
1683 abs_not to_constr k0 (abst_form to_constr needA (negb pol0) k0 f0)
1684 (fun x x0 -> NOT (x, x0))
1685 | IMPL (k0, f1, o, f2) ->
1686 abst_impl to_constr (abst_form to_constr needA) pol0 o k0 f1 f2
1687 | IFF (k0, f1, f2) ->
1688 abst_iff to_constr needA (abst_form to_constr needA) pol0 k0 f1 f2
1689 | EQ (f1, f2) ->
1690 abst_eq to_constr needA (abst_form to_constr needA) pol0 f1 f2
1691
1692 (** val cnf_checker :
1693 (('a1 * 'a2) list -> 'a3 -> bool) -> ('a1, 'a2) cnf -> 'a3 list -> bool **)
1694
1695 let rec cnf_checker checker f l =
1696 match f with
1697 | [] -> true
1698 | e::f0 ->
1699 (match l with
1700 | [] -> false
1701 | c::l0 -> if checker e c then cnf_checker checker f0 l0 else false)
1702
1703 (** val tauto_checker :
1704 ('a2 -> bool) -> ('a2 -> 'a2 -> 'a2 option) -> ('a1 -> 'a3 -> ('a2, 'a3)
1705 cnf) -> ('a1 -> 'a3 -> ('a2, 'a3) cnf) -> (('a2 * 'a3) list -> 'a4 ->
1706 bool) -> ('a1, rtyp, 'a3, unit0) gFormula -> 'a4 list -> bool **)
1707
1708 let tauto_checker unsat deduce normalise1 negate0 checker f w =
1709 cnf_checker checker (xcnf unsat deduce normalise1 negate0 true IsProp f) w
1710
1711 (** val cneqb : ('a1 -> 'a1 -> bool) -> 'a1 -> 'a1 -> bool **)
1712
1713 let cneqb ceqb x y =
1714 negb (ceqb x y)
1715
1716 (** val cltb :
1717 ('a1 -> 'a1 -> bool) -> ('a1 -> 'a1 -> bool) -> 'a1 -> 'a1 -> bool **)
1718
1719 let cltb ceqb cleb x y =
1720 (&&) (cleb x y) (cneqb ceqb x y)
1721
1722 type 'c polC = 'c pol
1723
1724 type op1 =
1725 | Equal
1726 | NonEqual
1727 | Strict
1728 | NonStrict
1729
1730 type 'c nFormula = 'c polC * op1
1731
1732 (** val opMult : op1 -> op1 -> op1 option **)
1733
1734 let opMult o o' =
1735 match o with
1736 | Equal -> Some Equal
1737 | NonEqual ->
1738 (match o' with
1739 | Equal -> Some Equal
1740 | NonEqual -> Some NonEqual
1741 | _ -> None)
1742 | Strict -> (match o' with
1743 | NonEqual -> None
1744 | _ -> Some o')
1745 | NonStrict ->
1746 (match o' with
1747 | Equal -> Some Equal
1748 | NonEqual -> None
1749 | _ -> Some NonStrict)
1750
1751 (** val opAdd : op1 -> op1 -> op1 option **)
1752
1753 let opAdd o o' =
1754 match o with
1755 | Equal -> Some o'
1756 | NonEqual -> (match o' with
1757 | Equal -> Some NonEqual
1758 | _ -> None)
1759 | Strict -> (match o' with
1760 | NonEqual -> None
1761 | _ -> Some Strict)
1762 | NonStrict ->
1763 (match o' with
1764 | Equal -> Some NonStrict
1765 | NonEqual -> None
1766 | x -> Some x)
1767
1768 type 'c psatz =
1769 | PsatzLet of 'c psatz * 'c psatz
1770 | PsatzIn of nat
1771 | PsatzSquare of 'c polC
1772 | PsatzMulC of 'c polC * 'c psatz
1773 | PsatzMulE of 'c psatz * 'c psatz
1774 | PsatzAdd of 'c psatz * 'c psatz
1775 | PsatzC of 'c
1776 | PsatzZ
1777
1778 (** val map_option : ('a1 -> 'a2 option) -> 'a1 option -> 'a2 option **)
1779
1780 let map_option f = function
1781 | Some x -> f x
1782 | None -> None
1783
1784 (** val map_option2 :
1785 ('a1 -> 'a2 -> 'a3 option) -> 'a1 option -> 'a2 option -> 'a3 option **)
1786
1787 let map_option2 f o o' =
1788 match o with
1789 | Some x -> (match o' with
1790 | Some x' -> f x x'
1791 | None -> None)
1792 | None -> None
1793
1794 (** val pexpr_times_nformula :
1795 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
1796 -> bool) -> 'a1 polC -> 'a1 nFormula -> 'a1 nFormula option **)
1797
1798 let pexpr_times_nformula cO cI cplus ctimes ceqb e = function
1799 | ef,o ->
1800 (match o with
1801 | Equal -> Some ((pmul cO cI cplus ctimes ceqb e ef),Equal)
1802 | _ -> None)
1803
1804 (** val nformula_times_nformula :
1805 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
1806 -> bool) -> 'a1 nFormula -> 'a1 nFormula -> 'a1 nFormula option **)
1807
1808 let nformula_times_nformula cO cI cplus ctimes ceqb f1 f2 =
1809 let e1,o1 = f1 in
1810 let e2,o2 = f2 in
1811 map_option (fun x -> Some ((pmul cO cI cplus ctimes ceqb e1 e2),x))
1812 (opMult o1 o2)
1813
1814 (** val nformula_plus_nformula :
1815 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 nFormula -> 'a1
1816 nFormula -> 'a1 nFormula option **)
1817
1818 let nformula_plus_nformula cO cplus ceqb f1 f2 =
1819 let e1,o1 = f1 in
1820 let e2,o2 = f2 in
1821 map_option (fun x -> Some ((padd cO cplus ceqb e1 e2),x)) (opAdd o1 o2)
1822
1823 (** val eval_Psatz :
1824 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
1825 -> bool) -> ('a1 -> 'a1 -> bool) -> 'a1 nFormula list -> 'a1 psatz -> 'a1
1826 nFormula option **)
1827
1828 let rec eval_Psatz cO cI cplus ctimes ceqb cleb l = function
1829 | PsatzLet (p2, p3) ->
1830 (match eval_Psatz cO cI cplus ctimes ceqb cleb l p2 with
1831 | Some f -> eval_Psatz cO cI cplus ctimes ceqb cleb (f::l) p3
1832 | None -> None)
1833 | PsatzIn n0 -> Some (nth n0 l ((Pc cO),Equal))
1834 | PsatzSquare e0 -> Some ((psquare cO cI cplus ctimes ceqb e0),NonStrict)
1835 | PsatzMulC (re, e0) ->
1836 map_option (pexpr_times_nformula cO cI cplus ctimes ceqb re)
1837 (eval_Psatz cO cI cplus ctimes ceqb cleb l e0)
1838 | PsatzMulE (f1, f2) ->
1839 map_option2 (nformula_times_nformula cO cI cplus ctimes ceqb)
1840 (eval_Psatz cO cI cplus ctimes ceqb cleb l f1)
1841 (eval_Psatz cO cI cplus ctimes ceqb cleb l f2)
1842 | PsatzAdd (f1, f2) ->
1843 map_option2 (nformula_plus_nformula cO cplus ceqb)
1844 (eval_Psatz cO cI cplus ctimes ceqb cleb l f1)
1845 (eval_Psatz cO cI cplus ctimes ceqb cleb l f2)
1846 | PsatzC c -> if cltb ceqb cleb cO c then Some ((Pc c),Strict) else None
1847 | PsatzZ -> Some ((Pc cO),Equal)
1848
1849 (** val check_inconsistent :
1850 'a1 -> ('a1 -> 'a1 -> bool) -> ('a1 -> 'a1 -> bool) -> 'a1 nFormula ->
1851 bool **)
1852
1853 let check_inconsistent cO ceqb cleb = function
1854 | e,op ->
1855 (match e with
1856 | Pc c ->
1857 (match op with
1858 | Equal -> cneqb ceqb c cO
1859 | NonEqual -> ceqb c cO
1860 | Strict -> cleb c cO
1861 | NonStrict -> cltb ceqb cleb c cO)
1862 | _ -> false)
1863
1864 (** val check_normalised_formulas :
1865 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
1866 -> bool) -> ('a1 -> 'a1 -> bool) -> 'a1 nFormula list -> 'a1 psatz -> bool **)
1867
1868 let check_normalised_formulas cO cI cplus ctimes ceqb cleb l cm =
1869 match eval_Psatz cO cI cplus ctimes ceqb cleb l cm with
1870 | Some f -> check_inconsistent cO ceqb cleb f
1871 | None -> false
1872
1873 type op2 =
1874 | OpEq
1875 | OpNEq
1876 | OpLe
1877 | OpGe
1878 | OpLt
1879 | OpGt
1880
1881 type 't formula = { flhs : 't pExpr; fop : op2; frhs : 't pExpr }
1882
1883 (** val norm :
1884 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
1885 -> 'a1) -> ('a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 pExpr -> 'a1 pol **)
1886
1887 let norm =
1888 norm_aux
1889
1890 (** val psub0 :
1891 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1) -> ('a1
1892 -> 'a1 -> bool) -> 'a1 pol -> 'a1 pol -> 'a1 pol **)
1893
1894 let psub0 =
1895 psub
1896
1897 (** val padd0 :
1898 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 pol -> 'a1 pol
1899 -> 'a1 pol **)
1900
1901 let padd0 =
1902 padd
1903
1904 (** val popp0 : ('a1 -> 'a1) -> 'a1 pol -> 'a1 pol **)
1905
1906 let popp0 =
1907 popp
1908
1909 (** val normalise :
1910 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
1911 -> 'a1) -> ('a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 formula -> 'a1
1912 nFormula **)
1913
1914 let normalise cO cI cplus ctimes cminus copp ceqb f =
1915 let { flhs = lhs; fop = op; frhs = rhs } = f in
1916 let lhs0 = norm cO cI cplus ctimes cminus copp ceqb lhs in
1917 let rhs0 = norm cO cI cplus ctimes cminus copp ceqb rhs in
1918 (match op with
1919 | OpEq -> (psub0 cO cplus cminus copp ceqb lhs0 rhs0),Equal
1920 | OpNEq -> (psub0 cO cplus cminus copp ceqb lhs0 rhs0),NonEqual
1921 | OpLe -> (psub0 cO cplus cminus copp ceqb rhs0 lhs0),NonStrict
1922 | OpGe -> (psub0 cO cplus cminus copp ceqb lhs0 rhs0),NonStrict
1923 | OpLt -> (psub0 cO cplus cminus copp ceqb rhs0 lhs0),Strict
1924 | OpGt -> (psub0 cO cplus cminus copp ceqb lhs0 rhs0),Strict)
1925
1926 (** val xnormalise : ('a1 -> 'a1) -> 'a1 nFormula -> 'a1 nFormula list **)
1927
1928 let xnormalise copp = function
1929 | e,o ->
1930 (match o with
1931 | Equal -> (e,Strict)::(((popp0 copp e),Strict)::[])
1932 | NonEqual -> (e,Equal)::[]
1933 | Strict -> ((popp0 copp e),NonStrict)::[]
1934 | NonStrict -> ((popp0 copp e),Strict)::[])
1935
1936 (** val xnegate : ('a1 -> 'a1) -> 'a1 nFormula -> 'a1 nFormula list **)
1937
1938 let xnegate copp = function
1939 | e,o ->
1940 (match o with
1941 | NonEqual -> (e,Strict)::(((popp0 copp e),Strict)::[])
1942 | x -> (e,x)::[])
1943
1944 (** val cnf_of_list :
1945 'a1 -> ('a1 -> 'a1 -> bool) -> ('a1 -> 'a1 -> bool) -> 'a1 nFormula list
1946 -> 'a2 -> ('a1 nFormula, 'a2) cnf **)
1947
1948 let cnf_of_list cO ceqb cleb l tg =
1949 fold_right (fun x acc ->
1950 if check_inconsistent cO ceqb cleb x then acc else ((x,tg)::[])::acc)
1951 cnf_tt l
1952
1953 (** val cnf_normalise :
1954 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
1955 -> 'a1) -> ('a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> ('a1 -> 'a1 -> bool)
1956 -> 'a1 formula -> 'a2 -> ('a1 nFormula, 'a2) cnf **)
1957
1958 let cnf_normalise cO cI cplus ctimes cminus copp ceqb cleb t0 tg =
1959 let f = normalise cO cI cplus ctimes cminus copp ceqb t0 in
1960 if check_inconsistent cO ceqb cleb f
1961 then cnf_ff
1962 else cnf_of_list cO ceqb cleb (xnormalise copp f) tg
1963
1964 (** val cnf_negate :
1965 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1
1966 -> 'a1) -> ('a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> ('a1 -> 'a1 -> bool)
1967 -> 'a1 formula -> 'a2 -> ('a1 nFormula, 'a2) cnf **)
1968
1969 let cnf_negate cO cI cplus ctimes cminus copp ceqb cleb t0 tg =
1970 let f = normalise cO cI cplus ctimes cminus copp ceqb t0 in
1971 if check_inconsistent cO ceqb cleb f
1972 then cnf_tt
1973 else cnf_of_list cO ceqb cleb (xnegate copp f) tg
1974
1975 (** val xdenorm : positive -> 'a1 pol -> 'a1 pExpr **)
1976
1977 let rec xdenorm jmp = function
1978 | Pc c -> PEc c
1979 | Pinj (j, p2) -> xdenorm (Coq_Pos.add j jmp) p2
1980 | PX (p2, j, q0) ->
1981 PEadd ((PEmul ((xdenorm jmp p2), (PEpow ((PEX jmp), (Npos j))))),
1982 (xdenorm (Coq_Pos.succ jmp) q0))
1983
1984 (** val denorm : 'a1 pol -> 'a1 pExpr **)
1985
1986 let denorm p =
1987 xdenorm XH p
1988
1989 (** val map_PExpr : ('a2 -> 'a1) -> 'a2 pExpr -> 'a1 pExpr **)
1990
1991 let rec map_PExpr c_of_S = function
1992 | PEc c -> PEc (c_of_S c)
1993 | PEX p -> PEX p
1994 | PEadd (e1, e2) -> PEadd ((map_PExpr c_of_S e1), (map_PExpr c_of_S e2))
1995 | PEsub (e1, e2) -> PEsub ((map_PExpr c_of_S e1), (map_PExpr c_of_S e2))
1996 | PEmul (e1, e2) -> PEmul ((map_PExpr c_of_S e1), (map_PExpr c_of_S e2))
1997 | PEopp e0 -> PEopp (map_PExpr c_of_S e0)
1998 | PEpow (e0, n0) -> PEpow ((map_PExpr c_of_S e0), n0)
1999
2000 (** val map_Formula : ('a2 -> 'a1) -> 'a2 formula -> 'a1 formula **)
2001
2002 let map_Formula c_of_S f =
2003 let { flhs = l; fop = o; frhs = r } = f in
2004 { flhs = (map_PExpr c_of_S l); fop = o; frhs = (map_PExpr c_of_S r) }
2005
2006 (** val simpl_cone :
2007 'a1 -> 'a1 -> ('a1 -> 'a1 -> 'a1) -> ('a1 -> 'a1 -> bool) -> 'a1 psatz ->
2008 'a1 psatz **)
2009
2010 let simpl_cone cO cI ctimes ceqb e = match e with
2011 | PsatzSquare t0 ->
2012 (match t0 with
2013 | Pc c -> if ceqb cO c then PsatzZ else PsatzC (ctimes c c)
2014 | _ -> PsatzSquare t0)
2015 | PsatzMulE (t1, t2) ->
2016 (match t1 with
2017 | PsatzMulE (x, x0) ->
2018 (match x with
2019 | PsatzC p2 ->
2020 (match t2 with
2021 | PsatzC c -> PsatzMulE ((PsatzC (ctimes c p2)), x0)
2022 | PsatzZ -> PsatzZ
2023 | _ -> e)
2024 | _ ->
2025 (match x0 with
2026 | PsatzC p2 ->
2027 (match t2 with
2028 | PsatzC c -> PsatzMulE ((PsatzC (ctimes c p2)), x)
2029 | PsatzZ -> PsatzZ
2030 | _ -> e)
2031 | _ ->
2032 (match t2 with
2033 | PsatzC c -> if ceqb cI c then t1 else PsatzMulE (t1, t2)
2034 | PsatzZ -> PsatzZ
2035 | _ -> e)))
2036 | PsatzC c ->
2037 (match t2 with
2038 | PsatzMulE (x, x0) ->
2039 (match x with
2040 | PsatzC p2 -> PsatzMulE ((PsatzC (ctimes c p2)), x0)
2041 | _ ->
2042 (match x0 with
2043 | PsatzC p2 -> PsatzMulE ((PsatzC (ctimes c p2)), x)
2044 | _ -> if ceqb cI c then t2 else PsatzMulE (t1, t2)))
2045 | PsatzAdd (y, z0) ->
2046 PsatzAdd ((PsatzMulE ((PsatzC c), y)), (PsatzMulE ((PsatzC c), z0)))
2047 | PsatzC c0 -> PsatzC (ctimes c c0)
2048 | PsatzZ -> PsatzZ
2049 | _ -> if ceqb cI c then t2 else PsatzMulE (t1, t2))
2050 | PsatzZ -> PsatzZ
2051 | _ ->
2052 (match t2 with
2053 | PsatzC c -> if ceqb cI c then t1 else PsatzMulE (t1, t2)
2054 | PsatzZ -> PsatzZ
2055 | _ -> e))
2056 | PsatzAdd (t1, t2) ->
2057 (match t1 with
2058 | PsatzZ -> t2
2059 | _ -> (match t2 with
2060 | PsatzZ -> t1
2061 | _ -> PsatzAdd (t1, t2)))
2062 | _ -> e
2063
2064 type q = { qnum : z; qden : positive }
2065
2066 (** val qeq_bool : q -> q -> bool **)
2067
2068 let qeq_bool x y =
2069 Z.eqb (Z.mul x.qnum (Zpos y.qden)) (Z.mul y.qnum (Zpos x.qden))
2070
2071 (** val qle_bool : q -> q -> bool **)
2072
2073 let qle_bool x y =
2074 Z.leb (Z.mul x.qnum (Zpos y.qden)) (Z.mul y.qnum (Zpos x.qden))
2075
2076 (** val qplus : q -> q -> q **)
2077
2078 let qplus x y =
2079 { qnum = (Z.add (Z.mul x.qnum (Zpos y.qden)) (Z.mul y.qnum (Zpos x.qden)));
2080 qden = (Coq_Pos.mul x.qden y.qden) }
2081
2082 (** val qmult : q -> q -> q **)
2083
2084 let qmult x y =
2085 { qnum = (Z.mul x.qnum y.qnum); qden = (Coq_Pos.mul x.qden y.qden) }
2086
2087 (** val qopp : q -> q **)
2088
2089 let qopp x =
2090 { qnum = (Z.opp x.qnum); qden = x.qden }
2091
2092 (** val qminus : q -> q -> q **)
2093
2094 let qminus x y =
2095 qplus x (qopp y)
2096
2097 (** val qinv : q -> q **)
2098
2099 let qinv x =
2100 match x.qnum with
2101 | Z0 -> { qnum = Z0; qden = XH }
2102 | Zpos p -> { qnum = (Zpos x.qden); qden = p }
2103 | Zneg p -> { qnum = (Zneg x.qden); qden = p }
2104
2105 (** val qpower_positive : q -> positive -> q **)
2106
2107 let qpower_positive =
2108 pow_pos qmult
2109
2110 (** val qpower : q -> z -> q **)
2111
2112 let qpower q0 = function
2113 | Z0 -> { qnum = (Zpos XH); qden = XH }
2114 | Zpos p -> qpower_positive q0 p
2115 | Zneg p -> qinv (qpower_positive q0 p)
2116
2117 type 'a t =
2118 | Empty
2119 | Elt of 'a
2120 | Branch of 'a t * 'a * 'a t
2121
2122 (** val find : 'a1 -> 'a1 t -> positive -> 'a1 **)
2123
2124 let rec find default vm p =
2125 match vm with
2126 | Empty -> default
2127 | Elt i -> i
2128 | Branch (l, e, r) ->
2129 (match p with
2130 | XI p2 -> find default r p2
2131 | XO p2 -> find default l p2
2132 | XH -> e)
2133
2134 (** val singleton : 'a1 -> positive -> 'a1 -> 'a1 t **)
2135
2136 let rec singleton default x v =
2137 match x with
2138 | XI p -> Branch (Empty, default, (singleton default p v))
2139 | XO p -> Branch ((singleton default p v), default, Empty)
2140 | XH -> Elt v
2141
2142 (** val vm_add : 'a1 -> positive -> 'a1 -> 'a1 t -> 'a1 t **)
2143
2144 let rec vm_add default x v = function
2145 | Empty -> singleton default x v
2146 | Elt vl ->
2147 (match x with
2148 | XI p -> Branch (Empty, vl, (singleton default p v))
2149 | XO p -> Branch ((singleton default p v), vl, Empty)
2150 | XH -> Elt v)
2151 | Branch (l, o, r) ->
2152 (match x with
2153 | XI p -> Branch (l, o, (vm_add default p v r))
2154 | XO p -> Branch ((vm_add default p v l), o, r)
2155 | XH -> Branch (l, v, r))
2156
2157 (** val zeval_const : z pExpr -> z option **)
2158
2159 let rec zeval_const = function
2160 | PEc c -> Some c
2161 | PEX _ -> None
2162 | PEadd (e1, e2) ->
2163 map_option2 (fun x y -> Some (Z.add x y)) (zeval_const e1) (zeval_const e2)
2164 | PEsub (e1, e2) ->
2165 map_option2 (fun x y -> Some (Z.sub x y)) (zeval_const e1) (zeval_const e2)
2166 | PEmul (e1, e2) ->
2167 map_option2 (fun x y -> Some (Z.mul x y)) (zeval_const e1) (zeval_const e2)
2168 | PEopp e0 -> map_option (fun x -> Some (Z.opp x)) (zeval_const e0)
2169 | PEpow (e1, n0) ->
2170 map_option (fun x -> Some (Z.pow x (Z.of_N n0))) (zeval_const e1)
2171
2172 type zWitness = z psatz
2173
2174 (** val zWeakChecker : z nFormula list -> z psatz -> bool **)
2175
2176 let zWeakChecker =
2177 check_normalised_formulas Z0 (Zpos XH) Z.add Z.mul Z.eqb Z.leb
2178
2179 (** val psub1 : z pol -> z pol -> z pol **)
2180
2181 let psub1 =
2182 psub0 Z0 Z.add Z.sub Z.opp Z.eqb
2183
2184 (** val popp1 : z pol -> z pol **)
2185
2186 let popp1 =
2187 popp0 Z.opp
2188
2189 (** val padd1 : z pol -> z pol -> z pol **)
2190
2191 let padd1 =
2192 padd0 Z0 Z.add Z.eqb
2193
2194 (** val normZ : z pExpr -> z pol **)
2195
2196 let normZ =
2197 norm Z0 (Zpos XH) Z.add Z.mul Z.sub Z.opp Z.eqb
2198
2199 (** val zunsat : z nFormula -> bool **)
2200
2201 let zunsat =
2202 check_inconsistent Z0 Z.eqb Z.leb
2203
2204 (** val zdeduce : z nFormula -> z nFormula -> z nFormula option **)
2205
2206 let zdeduce =
2207 nformula_plus_nformula Z0 Z.add Z.eqb
2208
2209 (** val xnnormalise : z formula -> z nFormula **)
2210
2211 let xnnormalise t0 =
2212 let { flhs = lhs; fop = o; frhs = rhs } = t0 in
2213 let lhs0 = normZ lhs in
2214 let rhs0 = normZ rhs in
2215 (match o with
2216 | OpEq -> (psub1 rhs0 lhs0),Equal
2217 | OpNEq -> (psub1 rhs0 lhs0),NonEqual
2218 | OpLe -> (psub1 rhs0 lhs0),NonStrict
2219 | OpGe -> (psub1 lhs0 rhs0),NonStrict
2220 | OpLt -> (psub1 rhs0 lhs0),Strict
2221 | OpGt -> (psub1 lhs0 rhs0),Strict)
2222
2223 (** val xnormalise0 : z nFormula -> z nFormula list **)
2224
2225 let xnormalise0 = function
2226 | e,o ->
2227 (match o with
2228 | Equal ->
2229 ((psub1 e (Pc (Zpos XH))),NonStrict)::(((psub1 (Pc (Zneg XH)) e),NonStrict)::[])
2230 | NonEqual -> (e,Equal)::[]
2231 | Strict -> ((psub1 (Pc Z0) e),NonStrict)::[]
2232 | NonStrict -> ((psub1 (Pc (Zneg XH)) e),NonStrict)::[])
2233
2234 (** val cnf_of_list0 :
2235 'a1 -> z nFormula list -> (z nFormula * 'a1) list list **)
2236
2237 let cnf_of_list0 tg l =
2238 fold_right (fun x acc -> if zunsat x then acc else ((x,tg)::[])::acc)
2239 cnf_tt l
2240
2241 (** val normalise0 : z formula -> 'a1 -> (z nFormula, 'a1) cnf **)
2242
2243 let normalise0 t0 tg =
2244 let f = xnnormalise t0 in
2245 if zunsat f then cnf_ff else cnf_of_list0 tg (xnormalise0 f)
2246
2247 (** val xnegate0 : z nFormula -> z nFormula list **)
2248
2249 let xnegate0 = function
2250 | e,o ->
2251 (match o with
2252 | NonEqual ->
2253 ((psub1 e (Pc (Zpos XH))),NonStrict)::(((psub1 (Pc (Zneg XH)) e),NonStrict)::[])
2254 | Strict -> ((psub1 e (Pc (Zpos XH))),NonStrict)::[]
2255 | x -> (e,x)::[])
2256
2257 (** val negate : z formula -> 'a1 -> (z nFormula, 'a1) cnf **)
2258
2259 let negate t0 tg =
2260 let f = xnnormalise t0 in
2261 if zunsat f then cnf_tt else cnf_of_list0 tg (xnegate0 f)
2262
2263 (** val cnfZ :
2264 kind -> (z formula, 'a1, 'a2, 'a3) tFormula -> (z nFormula, 'a1)
2265 cnf * 'a1 trace **)
2266
2267 let cnfZ k f =
2268 rxcnf zunsat zdeduce normalise0 negate true k f
2269
2270 (** val ceiling : z -> z -> z **)
2271
2272 let ceiling a b =
2273 let q0,r = Z.div_eucl a b in
2274 (match r with
2275 | Z0 -> q0
2276 | _ -> Z.add q0 (Zpos XH))
2277
2278 type zArithProof =
2279 | DoneProof
2280 | RatProof of zWitness * zArithProof
2281 | CutProof of zWitness * zArithProof
2282 | SplitProof of z polC * zArithProof * zArithProof
2283 | EnumProof of zWitness * zWitness * zArithProof list
2284 | ExProof of positive * zArithProof
2285
2286 (** val zgcdM : z -> z -> z **)
2287
2288 let zgcdM x y =
2289 Z.max (Z.gcd x y) (Zpos XH)
2290
2291 (** val zgcd_pol : z polC -> z * z **)
2292
2293 let rec zgcd_pol = function
2294 | Pc c -> Z0,c
2295 | Pinj (_, p2) -> zgcd_pol p2
2296 | PX (p2, _, q0) ->
2297 let g1,c1 = zgcd_pol p2 in
2298 let g2,c2 = zgcd_pol q0 in (zgcdM (zgcdM g1 c1) g2),c2
2299
2300 (** val zdiv_pol : z polC -> z -> z polC **)
2301
2302 let rec zdiv_pol p x =
2303 match p with
2304 | Pc c -> Pc (Z.div c x)
2305 | Pinj (j, p2) -> Pinj (j, (zdiv_pol p2 x))
2306 | PX (p2, j, q0) -> PX ((zdiv_pol p2 x), j, (zdiv_pol q0 x))
2307
2308 (** val makeCuttingPlane : z polC -> z polC * z **)
2309
2310 let makeCuttingPlane p =
2311 let g,c = zgcd_pol p in
2312 if Z.gtb g Z0
2313 then (zdiv_pol (psubC Z.sub p c) g),(Z.opp (ceiling (Z.opp c) g))
2314 else p,Z0
2315
2316 (** val genCuttingPlane : z nFormula -> ((z polC * z) * op1) option **)
2317
2318 let genCuttingPlane = function
2319 | e,op ->
2320 (match op with
2321 | Equal ->
2322 let g,c = zgcd_pol e in
2323 if (&&) (Z.gtb g Z0)
2324 ((&&) (negb (Z.eqb c Z0)) (negb (Z.eqb (Z.gcd g c) g)))
2325 then None
2326 else Some ((makeCuttingPlane e),Equal)
2327 | NonEqual -> Some ((e,Z0),op)
2328 | Strict -> Some ((makeCuttingPlane (psubC Z.sub e (Zpos XH))),NonStrict)
2329 | NonStrict -> Some ((makeCuttingPlane e),NonStrict))
2330
2331 (** val nformula_of_cutting_plane : ((z polC * z) * op1) -> z nFormula **)
2332
2333 let nformula_of_cutting_plane = function
2334 | e_z,o -> let e,z0 = e_z in (padd1 e (Pc z0)),o
2335
2336 (** val is_pol_Z0 : z polC -> bool **)
2337
2338 let is_pol_Z0 = function
2339 | Pc z0 -> (match z0 with
2340 | Z0 -> true
2341 | _ -> false)
2342 | _ -> false
2343
2344 (** val eval_Psatz0 : z nFormula list -> zWitness -> z nFormula option **)
2345
2346 let eval_Psatz0 =
2347 eval_Psatz Z0 (Zpos XH) Z.add Z.mul Z.eqb Z.leb
2348
2349 (** val valid_cut_sign : op1 -> bool **)
2350
2351 let valid_cut_sign = function
2352 | Equal -> true
2353 | NonStrict -> true
2354 | _ -> false
2355
2356 (** val bound_var : positive -> z formula **)
2357
2358 let bound_var v =
2359 { flhs = (PEX v); fop = OpGe; frhs = (PEc Z0) }
2360
2361 (** val mk_eq_pos : positive -> positive -> positive -> z formula **)
2362
2363 let mk_eq_pos x y t0 =
2364 { flhs = (PEX x); fop = OpEq; frhs = (PEsub ((PEX y), (PEX t0))) }
2365
2366 (** val max_var : positive -> z pol -> positive **)
2367
2368 let rec max_var jmp = function
2369 | Pc _ -> jmp
2370 | Pinj (j, p2) -> max_var (Coq_Pos.add j jmp) p2
2371 | PX (p2, _, q0) ->
2372 Coq_Pos.max (max_var jmp p2) (max_var (Coq_Pos.succ jmp) q0)
2373
2374 (** val max_var_nformulae : z nFormula list -> positive **)
2375
2376 let max_var_nformulae l =
2377 fold_left (fun acc f -> Coq_Pos.max acc (max_var XH (fst f))) l XH
2378
2379 (** val zChecker : z nFormula list -> zArithProof -> bool **)
2380
2381 let rec zChecker l = function
2382 | DoneProof -> false
2383 | RatProof (w, pf0) ->
2384 (match eval_Psatz0 l w with
2385 | Some f -> if zunsat f then true else zChecker (f::l) pf0
2386 | None -> false)
2387 | CutProof (w, pf0) ->
2388 (match eval_Psatz0 l w with
2389 | Some f ->
2390 (match genCuttingPlane f with
2391 | Some cp -> zChecker ((nformula_of_cutting_plane cp)::l) pf0
2392 | None -> true)
2393 | None -> false)
2394 | SplitProof (p, pf1, pf2) ->
2395 (match genCuttingPlane (p,NonStrict) with
2396 | Some cp1 ->
2397 (match genCuttingPlane ((popp1 p),NonStrict) with
2398 | Some cp2 ->
2399 (&&) (zChecker ((nformula_of_cutting_plane cp1)::l) pf1)
2400 (zChecker ((nformula_of_cutting_plane cp2)::l) pf2)
2401 | None -> false)
2402 | None -> false)
2403 | EnumProof (w1, w2, pf0) ->
2404 (match eval_Psatz0 l w1 with
2405 | Some f1 ->
2406 (match eval_Psatz0 l w2 with
2407 | Some f2 ->
2408 (match genCuttingPlane f1 with
2409 | Some p ->
2410 let p2,op3 = p in
2411 let e1,z1 = p2 in
2412 (match genCuttingPlane f2 with
2413 | Some p3 ->
2414 let p4,op4 = p3 in
2415 let e2,z2 = p4 in
2416 if (&&) ((&&) (valid_cut_sign op3) (valid_cut_sign op4))
2417 (is_pol_Z0 (padd1 e1 e2))
2418 then let rec label pfs lb ub =
2419 match pfs with
2420 | [] -> Z.gtb lb ub
2421 | pf1::rsr ->
2422 (&&) (zChecker (((psub1 e1 (Pc lb)),Equal)::l) pf1)
2423 (label rsr (Z.add lb (Zpos XH)) ub)
2424 in label pf0 (Z.opp z1) z2
2425 else false
2426 | None -> true)
2427 | None -> true)
2428 | None -> false)
2429 | None -> false)
2430 | ExProof (x, prf) ->
2431 let fr = max_var_nformulae l in
2432 if Coq_Pos.leb x fr
2433 then let z0 = Coq_Pos.succ fr in
2434 let t0 = Coq_Pos.succ z0 in
2435 let nfx = xnnormalise (mk_eq_pos x z0 t0) in
2436 let posz = xnnormalise (bound_var z0) in
2437 let post = xnnormalise (bound_var t0) in
2438 zChecker (nfx::(posz::(post::l))) prf
2439 else false
2440
2441 (** val zTautoChecker : z formula bFormula -> zArithProof list -> bool **)
2442
2443 let zTautoChecker f w =
2444 tauto_checker zunsat zdeduce normalise0 negate (fun cl ->
2445 zChecker (map fst cl)) f w
2446
2447 type qWitness = q psatz
2448
2449 (** val qWeakChecker : q nFormula list -> q psatz -> bool **)
2450
2451 let qWeakChecker =
2452 check_normalised_formulas { qnum = Z0; qden = XH } { qnum = (Zpos XH);
2453 qden = XH } qplus qmult qeq_bool qle_bool
2454
2455 (** val qnormalise : q formula -> 'a1 -> (q nFormula, 'a1) cnf **)
2456
2457 let qnormalise t0 tg =
2458 cnf_normalise { qnum = Z0; qden = XH } { qnum = (Zpos XH); qden = XH }
2459 qplus qmult qminus qopp qeq_bool qle_bool t0 tg
2460
2461 (** val qnegate : q formula -> 'a1 -> (q nFormula, 'a1) cnf **)
2462
2463 let qnegate t0 tg =
2464 cnf_negate { qnum = Z0; qden = XH } { qnum = (Zpos XH); qden = XH } qplus
2465 qmult qminus qopp qeq_bool qle_bool t0 tg
2466
2467 (** val qunsat : q nFormula -> bool **)
2468
2469 let qunsat =
2470 check_inconsistent { qnum = Z0; qden = XH } qeq_bool qle_bool
2471
2472 (** val qdeduce : q nFormula -> q nFormula -> q nFormula option **)
2473
2474 let qdeduce =
2475 nformula_plus_nformula { qnum = Z0; qden = XH } qplus qeq_bool
2476
2477 (** val normQ : q pExpr -> q pol **)
2478
2479 let normQ =
2480 norm { qnum = Z0; qden = XH } { qnum = (Zpos XH); qden = XH } qplus qmult
2481 qminus qopp qeq_bool
2482
2483 (** val cnfQ :
2484 kind -> (q formula, 'a1, 'a2, 'a3) tFormula -> (q nFormula, 'a1)
2485 cnf * 'a1 trace **)
2486
2487 let cnfQ k f =
2488 rxcnf qunsat qdeduce qnormalise qnegate true k f
2489
2490 (** val qTautoChecker : q formula bFormula -> qWitness list -> bool **)
2491
2492 let qTautoChecker f w =
2493 tauto_checker qunsat qdeduce qnormalise qnegate (fun cl ->
2494 qWeakChecker (map fst cl)) f w
2495
2496 type rcst =
2497 | C0
2498 | C1
2499 | CQ of q
2500 | CZ of z
2501 | CPlus of rcst * rcst
2502 | CMinus of rcst * rcst
2503 | CMult of rcst * rcst
2504 | CPow of rcst * (z, nat) sum
2505 | CInv of rcst
2506 | COpp of rcst
2507
2508 (** val z_of_exp : (z, nat) sum -> z **)
2509
2510 let z_of_exp = function
2511 | Inl z1 -> z1
2512 | Inr n0 -> Z.of_nat n0
2513
2514 (** val q_of_Rcst : rcst -> q **)
2515
2516 let rec q_of_Rcst = function
2517 | C0 -> { qnum = Z0; qden = XH }
2518 | C1 -> { qnum = (Zpos XH); qden = XH }
2519 | CQ q0 -> q0
2520 | CZ z0 -> { qnum = z0; qden = XH }
2521 | CPlus (r1, r2) -> qplus (q_of_Rcst r1) (q_of_Rcst r2)
2522 | CMinus (r1, r2) -> qminus (q_of_Rcst r1) (q_of_Rcst r2)
2523 | CMult (r1, r2) -> qmult (q_of_Rcst r1) (q_of_Rcst r2)
2524 | CPow (r1, z0) -> qpower (q_of_Rcst r1) (z_of_exp z0)
2525 | CInv r0 -> qinv (q_of_Rcst r0)
2526 | COpp r0 -> qopp (q_of_Rcst r0)
2527
2528 type rWitness = q psatz
2529
2530 (** val rWeakChecker : q nFormula list -> q psatz -> bool **)
2531
2532 let rWeakChecker =
2533 check_normalised_formulas { qnum = Z0; qden = XH } { qnum = (Zpos XH);
2534 qden = XH } qplus qmult qeq_bool qle_bool
2535
2536 (** val rnormalise : q formula -> 'a1 -> (q nFormula, 'a1) cnf **)
2537
2538 let rnormalise t0 tg =
2539 cnf_normalise { qnum = Z0; qden = XH } { qnum = (Zpos XH); qden = XH }
2540 qplus qmult qminus qopp qeq_bool qle_bool t0 tg
2541
2542 (** val rnegate : q formula -> 'a1 -> (q nFormula, 'a1) cnf **)
2543
2544 let rnegate t0 tg =
2545 cnf_negate { qnum = Z0; qden = XH } { qnum = (Zpos XH); qden = XH } qplus
2546 qmult qminus qopp qeq_bool qle_bool t0 tg
2547
2548 (** val runsat : q nFormula -> bool **)
2549
2550 let runsat =
2551 check_inconsistent { qnum = Z0; qden = XH } qeq_bool qle_bool
2552
2553 (** val rdeduce : q nFormula -> q nFormula -> q nFormula option **)
2554
2555 let rdeduce =
2556 nformula_plus_nformula { qnum = Z0; qden = XH } qplus qeq_bool
2557
2558 (** val rTautoChecker : rcst formula bFormula -> rWitness list -> bool **)
2559
2560 let rTautoChecker f w =
2561 tauto_checker runsat rdeduce rnormalise rnegate (fun cl ->
2562 rWeakChecker (map fst cl))
2563 (map_bformula IsProp (map_Formula q_of_Rcst) f) w