Source file booleans.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
(** {1 boolean subterms} *)
open Logtk
open Libzipperposition
module T = Term
module Pos = Position
module US = Unif_subst
module L = Literal
module Ls = Literals
type reasoning_kind =
BoolReasoningDisabled
| BoolSimplificationsOnly
| BoolHoist
| BoolCasesPreprocess
let section = Util.Section.make ~parent:Const.section "booleans"
let k_bool_reasoning = Flex_state.create_key ()
let k_cased_term_selection = Flex_state.create_key ()
let k_quant_rename = Flex_state.create_key ()
let k_interpret_bool_funs = Flex_state.create_key ()
let k_cnf_non_simpl = Flex_state.create_key ()
let k_norm_bools = Flex_state.create_key ()
let k_filter_literals = Flex_state.create_key ()
let k_nnf = Flex_state.create_key ()
let k_simplify_bools = Flex_state.create_key ()
let k_trigger_bool_inst = Flex_state.create_key ()
let k_trigger_bool_ind = Flex_state.create_key ()
let k_include_quants = Flex_state.create_key ()
let k_bool_hoist_simpl = Flex_state.create_key ()
let k_rename_nested_bools = Flex_state.create_key ()
let k_bool_app_var_repl = Flex_state.create_key ()
let k_fluid_hoist = Flex_state.create_key ()
let k_fluid_log_hoist = Flex_state.create_key ()
let k_solve_formulas = Flex_state.create_key ()
let k_replace_unsupported_quants = Flex_state.create_key ()
let k_disable_ho_bool_unif = Flex_state.create_key ()
let k_generalize_trigger = Flex_state.create_key ()
let k_bool_triggers_only = Flex_state.create_key ()
module type S = sig
module Env : Env.S
module C : module type of Env.C
(** {5 Registration} *)
val setup : unit -> unit
(** Register rules in the environment *)
end
module Make(E : Env.S) : S with module Env = E = struct
module Env = E
module PS = E.ProofState
module C = Env.C
module Ctx = Env.Ctx
module Fool = Fool.Make(Env)
module Combs = Combinators.Make(Env)
module HO = Higher_order.Make(Env)
module LazyCNF = Lazy_cnf.Make(Env)
module FR = Env.FormRename
module Stm = Env.Stm
module StmQ = Env.StmQ
let (=~),(/~) = Literal.mk_eq, Literal.mk_neq
let (@:) = T.app_builtin ~ty:Type.prop
let no a = a =~ T.false_
let yes a = a =~ T.true_
let _trigger_bools = ref (Type.Map.empty)
let _cls_w_pred_vars = ref (Type.Map.empty)
let get_unif_alg () =
if Env.flex_get k_disable_ho_bool_unif
then (fun _ _ -> OSeq.empty)
else Env.flex_get Superposition.k_unif_alg
let get_unif_alg_l () =
if Env.flex_get k_disable_ho_bool_unif
then (fun _ _ -> OSeq.empty)
else (
let (module U) = Superposition.get_unif_module (module E) in
U.unify_scoped_l
)
let get_triggers c =
let ord = Ctx.ord () in
let trivial_trigger t =
let body = snd @@ T.open_fun t in
T.is_var body || T.is_true_or_false body in
let rec get_terms t k =
if T.DB.is_closed t then k t;
match T.view t with
| T.App(hd, args) -> List.iter (fun t -> get_terms t k) (args)
| T.AppBuiltin((And|Or|Not|Imply|Eq|Neq|Equiv|Xor), args) ->
List.iter (fun t -> get_terms t k) (args)
| T.AppBuiltin((ForallConst|ExistsConst), [_; body]) ->
if Env.flex_get k_include_quants then k body
| _ -> ()
in
Literals.fold_terms ~ord ~subterms:false ~eligible:C.Eligible.always
~which:`All (C.lits c) ~fun_bodies:false
|> Iter.flat_map (fun (t, p) -> get_terms t)
|> Iter.filter_map (fun t ->
let ty = Term.ty t and hd = Term.head_term t in
let cached_t = Subst.FO.canonize_all_vars t in
if not (Term.Set.mem cached_t !Higher_order.prim_enum_terms) &&
Type.is_fun ty && Type.returns_prop ty && not (Term.is_var hd) &&
not (trivial_trigger t) then (
Some t
) else None
)
let instantiate_w_bool ~clause ~var ~trigger =
assert(Type.equal (T.ty var) (T.ty trigger));
let cl_sc, trig_sc = 0, 1 in
let subst = Subst.FO.bind' Subst.empty (T.as_var_exn var, cl_sc) (trigger, trig_sc) in
let renaming = Subst.Renaming.create () in
let expand_quant = not @@ Env.flex_get Combinators.k_enable_combinators in
let lits = Literals.apply_subst renaming subst (C.lits clause, cl_sc) in
let lits = Literals.map (fun t -> Lambda.eta_reduce ~expand_quant @@ Lambda.snf t) lits in
let proof =
Proof.Step.inference
~rule:(Proof.Rule.mk "triggered_bool_instantiation")
~tags:[Proof.Tag.T_ho; Proof.Tag.T_cannot_orphan]
[C.proof_parent_subst renaming (clause, cl_sc) subst] in
let res = C.create_a lits proof ~penalty:(C.penalty clause) ~trail:(C.trail clause) in
res
let inst_clauses_w_trigger t =
let triggers = Type.Map.get_or ~default:[] (T.ty t) !_trigger_bools in
if not (CCList.mem ~eq:T.equal t triggers) &&
(not (Env.flex_get k_bool_triggers_only) || Type.returns_prop (T.ty t)) then (
_trigger_bools := Type.Map.update (T.ty t) (function
| None -> Some [t]
| Some res -> Some (t :: res)
) !_trigger_bools;
Type.Map.get_or ~default:[] (T.ty t) !_cls_w_pred_vars
|> CCList.map (fun (clause,var) -> instantiate_w_bool ~clause ~var ~trigger:t)
) else []
let insert_new_trigger t =
let do_insert t =
inst_clauses_w_trigger t
|> CCList.to_iter
|> Env.add_passive
in
do_insert t;
if (Type.returns_prop (T.ty t)) then (
let t = Lambda.eta_expand t in
match Env.flex_get k_generalize_trigger with
| `Neg ->
let vars, body = T.open_fun t in
if not (Type.is_prop (T.ty body)) then (
CCFormat.printf "%a:%a@." T.pp body Type.pp (T.ty body);
assert (false);
);
do_insert (T.fun_l vars (T.Form.not_ body))
| `Var ->
let vars, body = T.open_fun t in
assert(Type.is_prop (T.ty body));
let n = List.length vars in
let dbs = List.mapi (fun i ty -> T.bvar ~ty (n-i-1)) vars in
let var_ty = Type.(==>) (vars @ [Type.prop]) Type.prop in
let var = T.var (HVar.fresh ~ty:var_ty ()) in
do_insert (T.fun_l vars (T.app var (dbs@[body])))
| _ -> ()
)
let update_triggers cl =
if C.proof_depth cl < Env.flex_get k_trigger_bool_inst then (
let new_triggers = (get_triggers cl) in
if not (Iter.is_empty new_triggers) then (
Iter.iter insert_new_trigger new_triggers
));
Signal.ContinueListening
let handle_new_pred_var_clause (clause,var) =
assert(T.is_var var);
assert(Type.returns_prop (T.ty var));
let ty = T.ty var in
Type.Map.get_or ~default:[] ty !_trigger_bools
|> CCList.map (fun trigger -> instantiate_w_bool ~clause ~var ~trigger)
|> CCList.to_iter
|> Env.add_passive;
_cls_w_pred_vars := Type.Map.update ty (function
| None -> Some [(clause, var)]
| Some res -> Some ((clause, var) :: res)
) !_cls_w_pred_vars;
Signal.ContinueListening
let handle_new_skolem_sym (c,trigger) =
let trig_hd = T.head_term trigger in
assert(T.is_const trig_hd);
assert(ID.is_postcnf_skolem (T.as_const_exn trig_hd));
if C.proof_depth c < Env.flex_get k_trigger_bool_inst
then insert_new_trigger trigger;
Signal.ContinueListening
let trigger_induction cl =
let abstract ~subterm t =
assert(T.DB.is_closed subterm);
let rec aux ~depth t =
if T.equal subterm t then (
T.bvar ~ty:(T.ty subterm) depth
) else (
match T.view t with
| T.App(hd, args) ->
let hd' = aux ~depth hd in
let args' = List.map (aux ~depth) args in
if T.equal hd hd' && T.same_l args args' then t
else T.app hd' args'
| T.AppBuiltin(hd, args) ->
let args' = List.map (aux ~depth) args in
if T.same_l args args' then t
else T.app_builtin ~ty:(T.ty t) hd args'
| T.Fun _ ->
let pref, body = T.open_fun t in
let body' = aux ~depth:(depth+(List.length pref)) body in
if T.equal body body' then t else T.fun_l pref body'
| _ -> t
) in
let res = aux ~depth:0 t in
assert (Type.equal (T.ty res) (T.ty t));
if T.equal res t then None else (Some res) in
let make_triggers lhs rhs sign =
let lhs_body, rhs_body = snd (Term.open_fun lhs), snd (Term.open_fun rhs) in
let immediate_args =
if (T.is_const (T.head_term lhs_body)) &&
(T.is_const (T.head_term rhs_body)) then (
List.sort_uniq T.compare (T.args lhs_body @ T.args rhs_body)
) else [] in
CCList.filter_map (fun arg ->
if T.DB.is_closed arg && not (Type.is_tType (T.ty arg)) then (
match abstract ~subterm:arg lhs, abstract ~subterm:arg rhs with
| Some(lhs'), Some(rhs') ->
assert (Type.equal (T.ty lhs') (T.ty rhs'));
let build_body sign = if sign then T.Form.neq else T.Form.eq in
let res = T.fun_ (T.ty arg) (build_body sign lhs' rhs') in
assert (T.DB.is_closed res);
Some res
| _ -> None
) else None
) immediate_args in
if C.proof_depth cl < Env.flex_get k_trigger_bool_ind &&
CCOpt.is_some (C.distance_to_goal cl) then (
match C.lits cl with
| [| Literal.Equation(lhs, rhs, _) as lit |] ->
let res =
CCList.flat_map inst_clauses_w_trigger (make_triggers lhs rhs (Literal.is_positivoid lit))
in
res
| _ -> []
) else []
let () =
Signal.on PS.ActiveSet.on_add_clause (fun c ->
update_triggers c)
let mk_res ~proof ~old ~repl new_lit c =
C.create ~trail:(C.trail c) ~penalty:(C.penalty c)
(new_lit :: Array.to_list( C.lits c |> Literals.map (T.replace ~old ~by:repl)))
proof
let get_green_eligible c =
let ord = C.Ctx.ord () in
Ls.fold_terms ~vars:false ~var_args:false ~fun_bodies:false
~ty_args:false ~ord ~which:`Max ~subterms:true
~eligible:(C.Eligible.res c) (C.lits c)
let get_bool_eligible c =
Iter.append
(SClause.TPSet.to_iter (C.eligible_subterms_of_bool c))
(get_green_eligible c)
let get_bool_hoist_eligible c =
get_bool_eligible c
|> Iter.filter (fun (t,p) ->
let module P = Position in
match p with
| P.Arg(idx, P.Left P.Stop)
| P.Arg(idx, P.Right P.Stop) ->
(match (C.lits c).(idx) with
| L.Equation(_,_,false) -> true
| _ -> false)
| _ -> true
) |> Iter.filter (fun (t,_) ->
let ty = T.ty t in
(Type.is_prop ty || Type.is_var ty) &&
not (T.is_true_or_false t) &&
not (T.is_var t) &&
match T.view t with
| T.AppBuiltin(hd,_) ->
not (List.mem hd Builtin.([Eq; Neq; ForallConst; ExistsConst; Not]) ||
Builtin.is_logical_binop hd)
| T.App(hd, _) -> not @@ T.is_var hd
| _ -> true)
|> Iter.to_list
|> CCList.sort_uniq ~cmp:(fun (t1,_) (t2,_) -> T.compare t1 t2)
let handle_poly_bool_hoist t c =
let ty = T.ty t in
assert(Type.is_prop ty || Type.is_var ty);
if Type.is_prop ty then (
(t, c)
) else (
let sub =
Subst.Ty.bind Subst.empty
((Type.as_var_exn ty, 0) :> InnerTerm.t HVar.t Scoped.t)
(Type.prop, 0)
in
let renaming = Subst.Renaming.create () in
let t' = Subst.FO.apply renaming sub (t,0) in
let c' = C.apply_subst ~renaming (c,0) sub in
(t',c')
)
let bool_hoist (c:C.t) : C.t list =
let proof = Proof.Step.inference [C.proof_parent c]
~rule:(Proof.Rule.mk "bool_hoist") ~tags:[Proof.Tag.T_ho] in
List.map (fun (t, _) ->
let t,c = handle_poly_bool_hoist t c in
mk_res ~proof ~old:t ~repl:T.false_ (yes t) c)
(get_bool_hoist_eligible c)
|> CCFun.tap (fun res ->
Util.debugf ~section 3 "hoist(@[%a@])" (fun k -> k C.pp c);
if CCList.is_empty res then (
Util.debugf ~section 3 " = ∅ (%d)(%a)(%d)"
(fun k ->
k (Iter.length (get_green_eligible c))
(Iter.pp_seq Term.pp) (Iter.map fst (get_bool_eligible c))
(List.length (get_bool_hoist_eligible c)));
) else (Util.debugf ~section 3 " = @[%a@]" (fun k -> k (CCList.pp C.pp) res))
)
let bool_hoist_simpl (c:C.t) : C.t list option =
let proof = Proof.Step.simp [C.proof_parent c]
~rule:(Proof.Rule.mk "bool_hoist") ~tags:[Proof.Tag.T_ho] in
let bool_subterms = get_bool_hoist_eligible c in
CCOpt.return_if (not @@ CCList.is_empty bool_subterms) (
CCList.fold_left (fun acc (t,_) ->
let t,c = handle_poly_bool_hoist t c in
let neg_lit, repl_neg = no t, T.true_ in
let pos_lit, repl_pos = yes t, T.false_ in
(mk_res ~proof ~old:t ~repl:repl_neg neg_lit c) ::
(mk_res ~proof ~old:t ~repl:repl_pos pos_lit c) :: acc )
[] bool_subterms
)
|> CCFun.tap (function
| Some res ->
Util.debugf ~section 2 "bool_hoist_simpl(@[%a@])=@. @[%a@]@." (fun k -> k C.pp c (CCList.pp C.pp) res);
| None ->
Util.debugf ~section 2 "bool_hoist_simpl(@[%a@])= None@." (fun k -> k C.pp c)
)
let eq_hoist (c:C.t) : C.t list =
let proof ~prefix =
Proof.Step.inference [C.proof_parent c]
~rule:(Proof.Rule.mk (prefix^"_hoist")) ~tags:[Proof.Tag.T_ho] in
get_bool_eligible c
|> Iter.filter (fun (t,_) ->
match T.view t with
| T.AppBuiltin(hd,_) ->
List.mem hd [Builtin.Eq;Neq;Xor;Equiv;ForallConst;ExistsConst] &&
Type.is_prop (T.ty t)
| _ -> false)
|> Iter.to_list
|> CCList.sort_uniq ~cmp:(fun (t1,_) (t2,_) -> T.compare t1 t2)
|> List.map (fun (t, _) ->
match T.view t with
| T.AppBuiltin(Builtin.(Eq|Equiv), ([a;b]|[_;a;b])) ->
let new_lit = Literal.mk_eq a b in
mk_res ~proof:(proof ~prefix:"eq") ~old:t ~repl:T.false_ new_lit c
| T.AppBuiltin(Builtin.(Neq|Xor), ([a;b]|[_;a;b])) ->
let new_lit = Literal.mk_eq a b in
mk_res ~proof:(proof ~prefix:"neq") ~old:t ~repl:T.true_ new_lit c
| _ -> assert false
)
|> CCFun.tap (fun res ->
Util.debugf ~section 3 "eq-hoist(@[%a@])" (fun k -> k C.pp c);
if CCList.is_empty res then (
Util.debugf ~section 3 " = ∅ (%d)(%d)(%a)"
(fun k ->
k (Iter.length (get_green_eligible c))
(Iter.length (get_bool_eligible c))
(Iter.pp_seq Term. pp) (Iter.map fst (get_bool_eligible c)) );
) else (Util.debugf ~section 3 " = @[%a@]" (fun k -> k (CCList.pp C.pp) res))
)
let fluid_hoist (c:C.t) =
let tyvar = Type.var (HVar.fresh ~ty:Type.tType ()) in
let z = T.var (HVar.fresh ~ty:(Type.arrow [Type.prop] tyvar) ()) in
let x = T.var (HVar.fresh ~ty:Type.prop ()) in
let zx = T.app z [x] in
let z_false, z_true = T.app z [T.false_], T.app z [T.true_] in
let sc_zx, sc_cl = 0, 1 in
let mk_res sign renaming sub at =
let c' = C.apply_subst ~renaming (c, sc_cl) sub in
let still_at_eligible =
get_bool_eligible c'
|> Iter.exists (fun (_, p) -> Position.equal p at)
in
if still_at_eligible then (
let new_lit =
let x_sub = Subst.FO.apply renaming sub (x, sc_zx) in
Literal.mk_eq x_sub (if sign then T.true_ else T.false_) in
let by =
Subst.FO.apply renaming sub ((if sign then z_false else z_true), sc_zx) in
Literals.Pos.replace (C.lits c') ~at ~by;
let rule =
Proof.Rule.mk ("fluid_" ^ (if sign then "bool_" else "loob_") ^ "hoist") in
let proof = Proof.Step.inference ~rule [C.proof_parent_subst renaming (c,sc_cl) sub] in
let res =
C.create ~penalty:(C.penalty c +
(C.proof_depth c) +
(if Proof.Step.has_ho_step (C.proof_step c) then 3 else 1))
~trail:(C.trail c)
(new_lit :: CCArray.to_list (C.lits c')) proof in
Some res
) else None
in
get_bool_eligible c
|> (fun iter ->
Iter.fold (fun acc (u,p) ->
if T.is_app_var u || T.is_fun u && (not (T.is_ground u)) then (
let unif_seq =
get_unif_alg () (zx, sc_zx) (u, sc_cl)
|> OSeq.flat_map (fun us_opt ->
CCOpt.map_or ~default:OSeq.empty (fun us ->
assert(not @@ US.has_constr us);
let sub = US.subst us in
let renaming = Subst.Renaming.create () in
let z_false_sub =
Lambda.snf @@ Subst.FO.apply renaming sub (z_false, sc_zx) in
let z_true_sub =
Lambda.snf @@ Subst.FO.apply renaming sub (z_true, sc_zx) in
let x_sub =
Lambda.snf @@ Subst.FO.apply renaming sub (x, sc_zx) in
let zx_sub =
Lambda.snf @@ Subst.FO.apply renaming sub (zx, sc_zx) in
if T.is_true_or_false x_sub then OSeq.empty
else (
let bool_res =
if T.equal z_false_sub zx_sub then []
else [(mk_res true renaming sub p)] in
let loob_res =
if T.equal z_true_sub zx_sub then []
else [(mk_res false renaming sub p)] in
OSeq.of_list (bool_res @ loob_res)
)
) us_opt
)
in
if Env.should_force_stream_eval () then (
(Env.get_finite_infs [unif_seq]) @ acc
) else (
let stm_res = Env.Stm.make ~penalty:(C.penalty c + 2) ~parents:[c] (unif_seq) in
Env.StmQ.add (Env.get_stm_queue ()) stm_res;
acc)
) else acc
) [] iter)
type fluid_log_partner_info =
{
unif_partner : Term.t;
repl : Term.t;
new_lit : Literal.t option
}
let fluid_log_hoist (c:C.t) =
let a = Type.var (HVar.fresh ~ty:(Type.tType) ()) in
let x_a = T.var (HVar.fresh ~ty:a ()) in
let y_a = T.var (HVar.fresh ~ty:a ()) in
let y_quant =
Lambda.eta_expand @@
T.var (HVar.fresh ~ty:(Type.arrow [a] Type.prop) ()) in
let yx = Lambda.whnf @@ T.app y_quant [y_a] in
let module F = T.Form in
let module PB = Position.Build in
let partners =
[ {unif_partner=F.eq x_a y_a; repl= T.false_; new_lit=Some (L.mk_eq x_a y_a)};
{unif_partner=F.neq x_a y_a; repl= T.true_; new_lit=Some (L.mk_eq x_a y_a)};
{unif_partner=F.forall y_quant; repl= T.false_; new_lit=Some (L.mk_eq yx T.true_)};
{unif_partner=F.exists y_quant; repl= T.true_; new_lit=Some (L.mk_eq yx T.false_)};
{unif_partner=(F.not_ T.false_); repl= T.true_; new_lit=None};
{unif_partner=(F.not_ T.true_); repl= T.false_; new_lit=None};
{unif_partner=(F.eq x_a x_a); repl= T.true_; new_lit=None};
{unif_partner=(F.neq x_a x_a); repl= T.false_; new_lit=None};
{unif_partner=(F.and_ T.false_ T.false_); repl= T.false_; new_lit=None};
{unif_partner=(F.and_ T.true_ T.false_); repl= T.false_; new_lit=None};
{unif_partner=(F.and_ T.false_ T.true_); repl= T.false_; new_lit=None};
{unif_partner=(F.and_ T.true_ T.true_); repl= T.true_; new_lit=None};
{unif_partner=(F.or_ T.false_ T.false_); repl= T.false_; new_lit=None};
{unif_partner=(F.or_ T.true_ T.false_); repl= T.true_; new_lit=None};
{unif_partner=(F.or_ T.false_ T.true_); repl= T.true_; new_lit=None};
{unif_partner=(F.or_ T.true_ T.true_); repl= T.true_; new_lit=None};
{unif_partner=(F.imply T.false_ T.false_); repl= T.true_; new_lit=None};
{unif_partner=(F.imply T.true_ T.false_); repl= T.false_; new_lit=None};
{unif_partner=(F.imply T.false_ T.true_); repl= T.true_; new_lit=None};
{unif_partner=(F.imply T.true_ T.true_); repl= T.true_; new_lit=None};]
in
let sc_partner, sc_cl = 0, 1 in
let mk_res sub at partner=
let renaming = Subst.Renaming.create () in
let lits = Literals.apply_subst renaming sub ((C.lits c), sc_cl) in
Literals.Pos.replace lits ~at ~by:partner.repl;
let new_lits =
(CCOpt.map_or ~default:[] (fun x -> [L.apply_subst renaming sub (x,sc_partner)]) partner.new_lit)
@ (Array.to_list (lits))
in
let rule = Proof.Rule.mk "fluid_log_symbol_hoist" in
let step = Proof.Step.inference ~rule [C.proof_parent_subst renaming (c,sc_cl) sub] in
C.create ~penalty:(C.penalty c +
(C.proof_depth c) +
(if Proof.Step.has_ho_step (C.proof_step c) then 2 else 0)) ~trail:(C.trail c) new_lits step
in
let eligible = C.Eligible.res c in
Literals.fold_lits ~eligible (C.lits c)
|> Iter.fold (fun acc (lit, idx) ->
let lit_pos = PB.arg idx PB.empty in
match lit with
| Literal.Equation(u, v, true)
when (Type.is_prop (T.ty u) || Type.is_var (T.ty u))
&& T.is_app_var u ->
let app_vars =
if Literal.is_predicate_lit lit then [(u, PB.to_pos (PB.left lit_pos))]
else if Term.is_app_var v then [(u, PB.to_pos (PB.left lit_pos));
(v, PB.to_pos (PB.right lit_pos))]
else []
in
List.fold_left (fun acc (var, pos) ->
List.fold_left (fun acc p ->
let seq =
get_unif_alg () (p.unif_partner, sc_partner) (var, sc_cl)
|> OSeq.filter_map (
CCOpt.map (fun us ->
assert(not (Unif_subst.has_constr us));
let sub = Unif_subst.subst us in
let eligible' = C.eligible_res (c, sc_cl) sub in
if not (CCBV.get eligible' idx) then None
else (
Some (mk_res sub pos p)
)))
in
if Env.should_force_stream_eval () then (
Env.get_finite_infs [seq] @ acc
) else (
let stm_res = Env.Stm.make ~penalty:(C.penalty c + 2) ~parents:[c] (seq) in
Env.StmQ.add (Env.get_stm_queue ()) stm_res;
acc)
) acc partners;
) acc app_vars
| _ -> acc
) []
let fluid_quant_rw (c:C.t) =
let module PB = Position.Build in
let module F = T.Form in
let sc_partner, sc_cl = 0, 1 in
let a = Type.var (HVar.fresh ~ty:(Type.tType) ()) in
let y_quant =
Lambda.eta_expand @@
T.var (HVar.fresh ~ty:(Type.arrow [a] Type.prop) ()) in
let partners =
[ {unif_partner=F.forall y_quant;
repl= T.fun_ a (F.not_ (Lambda.whnf @@ T.app y_quant [T.bvar ~ty:a 0]));
new_lit=None};
{unif_partner=F.exists y_quant;
repl= y_quant ;
new_lit=None};]
in
let mk_res sub at partner=
let lits = Array.copy @@ C.lits c in
let renaming = Subst.Renaming.create () in
let expand_quant = not @@ Env.flex_get Combinators.k_enable_combinators in
let repl_sub =
Lambda.eta_reduce ~expand_quant @@ Lambda.snf @@
Subst.FO.apply renaming sub (partner.repl, sc_partner) in
let sk = FR.get_skolem ~parent:c ~mode:`SkolemRecycle repl_sub in
let y_sk =
T.app (Subst.FO.apply renaming sub (y_quant, sc_partner)) [sk]
in
let lits = Literals.apply_subst renaming sub (lits, sc_cl) in
Literals.Pos.replace lits ~at ~by:y_sk;
let rule = Proof.Rule.mk "fluid_quant_rw" in
let step = Proof.Step.inference ~rule [C.proof_parent_subst renaming (c,sc_cl) sub] in
let res = C.create_a ~penalty:(C.penalty c + 2) ~trail:(C.trail c) lits step in
Util.debugf ~section 5 "fluid_quant_rw:@.@[%a@] -> @.@[%a@]@."
(fun k -> k C.pp c C.pp res);
res
in
let eligible = C.Eligible.res c in
Literals.fold_lits ~eligible (C.lits c)
|> Iter.fold (fun acc (lit, idx) ->
let lit_pos = PB.arg idx PB.empty in
match lit with
| Literal.Equation(u, v, true)
when (Type.is_var (T.ty u) || Type.is_prop (T.ty u))
&& T.is_app_var u ->
let app_vars =
if Literal.is_predicate_lit lit then [(u, PB.to_pos (PB.left lit_pos))]
else if Term.is_app_var v then [(u, PB.to_pos (PB.left lit_pos));
(v, PB.to_pos (PB.right lit_pos))]
else []
in
List.fold_left (fun acc (var, pos) ->
List.fold_left (fun acc p ->
let seq =
get_unif_alg () (p.unif_partner, sc_partner) (var, sc_cl)
|> OSeq.filter_map (
CCOpt.map (fun us ->
assert(not (Unif_subst.has_constr us));
let sub = Unif_subst.subst us in
let eligible' = C.eligible_res (c, sc_cl) sub in
if not (CCBV.get eligible' idx) then None
else (
Some (mk_res sub pos p)
)))
in
if Env.should_force_stream_eval () then (
Env.get_finite_infs [seq] @ acc
) else (
let stm_res = Env.Stm.make ~penalty:(C.penalty c + 2) ~parents:[c] ( seq) in
Env.StmQ.add (Env.get_stm_queue ()) stm_res;
acc)
) acc partners;
) acc app_vars
| _ -> acc
) []
let false_elim c =
let module S = Subst.FO in
let p sub renaming =
Proof.Step.inference [C.proof_parent_subst renaming (c,0) sub]
~rule:(Proof.Rule.mk ("false_elim"))
~tags:[Proof.Tag.T_ho]
in
let add_immediate acc sub idx =
let renaming = Subst.Renaming.create () in
let res =
C.apply_subst ~renaming ~proof:(Some (p sub renaming)) (c,0) sub
in
res :: acc
in
let schedule app_var target idx =
assert(T.is_ground target);
let seq =
get_unif_alg () (app_var, 0) (target, 0)
|> OSeq.filter_map (
CCOpt.map (fun us ->
assert(not (Unif_subst.has_constr us));
let sub = Unif_subst.subst us in
let renaming = Subst.Renaming.create () in
let res =
C.apply_subst ~penalty_inc:(Some 1) ~renaming
~proof:(Some (p sub renaming)) (c,0) sub
in
if not @@ CCBV.get (C.eligible_res_no_subst res) idx then None
else (
Some (res)
)))
in
if Env.should_force_stream_eval () then (
Env.get_finite_infs [seq]
) else (
let stm_res = Env.Stm.make ~penalty:(C.penalty c) ~parents:[c] (seq) in
Env.StmQ.add (Env.get_stm_queue ()) stm_res;
[]
)
in
let eligible = C.eligible_res (c, 0) Subst.empty in
let get_var = T.as_var_exn in
Ls.fold_eqn_simple (C.lits c)
|> Iter.filter (fun (_,_,_,p) ->
let idx = Ls.Pos.idx p in
CCBV.get eligible idx )
|> Iter.fold (fun acc (lhs,rhs,sign,p) ->
let idx = Ls.Pos.idx p in
if T.equal T.true_ rhs then (
if T.is_var lhs then (
let sub =
S.bind' Subst.empty (get_var lhs, 0) (T.false_, 0) in
add_immediate acc sub idx
) else if T.is_app_var lhs then (
schedule lhs T.false_ idx @ acc
) else acc
) else if T.equal T.false_ rhs then (
if T.is_var lhs then (
let sub = S.bind' Subst.empty (get_var lhs, 0) (T.true_, 0) in
add_immediate acc sub idx
) else if T.is_app_var lhs then (
schedule lhs T.true_ idx @ acc
) else acc
) else if T.is_var (T.head_term lhs)
&& T.is_var (T.head_term rhs)
&& sign then (
if T.is_var lhs && T.is_var rhs && Type.is_prop (T.ty lhs) then (
let sub_t_f =
S.bind'
(S.bind' Subst.empty (get_var lhs, 0) (T.true_, 0))
(get_var rhs,0) (T.false_, 0)
in
let sub_f_t =
S.bind'
(S.bind' Subst.empty (get_var lhs, 0) (T.false_, 0))
(get_var rhs,0) (T.true_, 0)
in
add_immediate (add_immediate acc sub_t_f idx) sub_f_t idx
) else (
let l_eq_r = T.Form.eq lhs rhs in
let t_eq_f = T.Form.eq T.true_ T.false_ in
let f_eq_t = T.Form.eq T.false_ T.true_ in
schedule l_eq_r t_eq_f idx @ schedule l_eq_r f_eq_t idx @ acc
)
) else acc
) []
let replace_bool_vars (c:C.t) =
let p =
Proof.Step.simp [C.proof_parent c]
~rule:(Proof.Rule.mk ("replace_bool_vars"))
~tags:[Proof.Tag.T_ho] in
let all_bool_substs vars =
let sc = 0 in
assert (not (CCList.is_empty vars));
let rec aux = function
| [] -> assert false
| [v] ->
[Subst.FO.bind' Subst.empty (v,sc) (T.true_, sc);
Subst.FO.bind' Subst.empty (v,sc) (T.false_, sc)]
| v :: vs ->
CCList.flat_map (fun subst ->
[Subst.FO.bind' subst (v,sc) (T.true_, sc);
Subst.FO.bind' subst (v,sc) (T.false_, sc)]
) (aux vs)
in
aux vars
in
get_bool_eligible c
|> Iter.find_pred (fun (t,_) ->
Type.is_prop (T.ty t)
&&
(match T.view t with
| T.AppBuiltin(Builtin.(Eq|Neq), [_;a;b]) when Type.is_prop (T.ty a) ->
T.is_var a && T.is_var b
| T.AppBuiltin(hd, args) ->
(Builtin.is_logical_binop hd || hd = Builtin.Not)
&& List.for_all T.is_var args
| _ -> false))
|> CCOpt.map (fun (t,_) ->
let vars = T.VarSet.to_list (T.vars t) in
assert (List.for_all (fun t -> Type.is_prop (HVar.ty t)) vars);
all_bool_substs vars
|> List.map (C.apply_subst ~proof:(Some p) (c,0)))
let replace_bool_app_vars (c:C.t) =
let p sub renaming =
Proof.Step.simp [C.proof_parent_subst renaming (c,0) sub]
~rule:(Proof.Rule.mk ("replace_bool_app_vars"))
~tags:[Proof.Tag.T_ho]
in
let is_var_headed t = T.is_var (T.head_term t) in
let is_eligible xs =
CCOpt.return_if ((List.for_all is_var_headed xs) && (List.exists T.is_app_var xs)) xs
in
let create_targets n =
let rec aux = function
| 0 -> []
| 1 -> [[T.true_]; [T.false_]]
| n ->
let rest = aux (n-1) in
List.rev_append (List.rev_map (List.cons T.true_) rest)
(List.rev_map (List.cons T.false_) rest)
in
aux n
in
let stms =
get_bool_eligible c
|> Iter.filter_map (fun (t,_) ->
(
match T.view t with
| T.AppBuiltin((Eq|Neq), [_;a;b]) when Type.is_prop (T.ty a) ->
is_eligible [a;b]
| T.AppBuiltin(hd, args)
when (Builtin.is_logical_binop hd || hd = Builtin.Not) && Type.is_prop (T.ty t) ->
is_eligible args
| _ -> None))
|> Iter.flat_map_l (fun (args) ->
List.map (fun target ->
get_unif_alg_l () (args, 0) (target, 0)
|> OSeq.filter_map (
CCOpt.map (fun us ->
assert(not (Unif_subst.has_constr us));
let sub = Unif_subst.subst us in
let renaming = Subst.Renaming.create () in
let res =
C.apply_subst ~penalty_inc:(Some 1) ~renaming
~proof:(Some (p sub renaming)) (c,0) sub
in
Some (res)
))) (create_targets (List.length args)))
|> Iter.to_list
in
if Env.should_force_stream_eval () then (
Env.get_finite_infs stms
) else (
Env.StmQ.add_lst (Env.get_stm_queue ()) (
List.map (fun seq ->
Env.Stm.make ~penalty:(C.penalty c) ~parents:[c] (seq)) stms
);
[]
)
let quantifier_rw_and_hoist (c:C.t) =
let quant_rw ~at b body =
let quant_rw_unapplicable =
let module P = Pos in
match at with
| P.Arg(i, P.Left P.Stop)
| P.Arg(i, P.Right P.Stop) when L.is_predicate_lit (C.lits c).(i) ->
let sign = L.is_positivoid ((C.lits c).(i)) in
(Builtin.equal b Builtin.ForallConst && sign)
|| (Builtin.equal b Builtin.ExistsConst && not sign)
| _ -> false
in
if quant_rw_unapplicable then None
else (
let proof =
Proof.Step.simp [C.proof_parent c]
~rule:(Proof.Rule.mk ("quantifier_rw"))
~tags:[Proof.Tag.T_ho]
in
let body = Combs.expand body in
let form_for_skolem =
(if b = Builtin.ForallConst then T.Form.not_ else CCFun.id)
(snd @@ T.open_fun body) in
let sk =
FR.get_skolem ~parent:c ~mode:`SkolemRecycle
(T.fun_l (fst @@ T.open_fun body) form_for_skolem) in
let repl = T.app body [sk] in
let new_lits = CCArray.copy (C.lits c) in
Literals.Pos.replace ~at ~by:repl new_lits;
Some (C.create ~trail:(C.trail c) ~penalty:(C.penalty c)
(Array.to_list new_lits) proof)
)
in
let quant_hoist ~old b body =
let proof ~prefix =
Proof.Step.inference [C.proof_parent c]
~rule:(Proof.Rule.mk (prefix^"_hoist")) ~tags:[Proof.Tag.T_ho] in
let fresh_var ~body =
assert(Type.is_fun (T.ty body));
let pref,_ = Type.open_fun (T.ty body) in
assert(List.length pref == 1);
let var_ty = List.hd pref in
let fresh_var = HVar.fresh ~ty:var_ty () in
T.var fresh_var
in
let subst_t = fresh_var ~body in
match b with
| Builtin.ForallConst ->
let new_lit = yes (T.app body [subst_t]) in
let res = mk_res ~proof:(proof ~prefix:"forall") ~old ~repl:T.false_ new_lit c in
if Type.returns_prop (T.ty subst_t) then (
Signal.send Env.on_pred_var_elimination (res, subst_t));
res
| Builtin.ExistsConst ->
let new_lit = no (T.app body [subst_t]) in
let res = mk_res ~proof:(proof ~prefix:"exists") ~old ~repl:T.true_ new_lit c in
if Type.returns_prop (T.ty subst_t) then (
Signal.send Env.on_pred_var_elimination (res, subst_t));
res
| _ -> assert false
in
get_bool_eligible c
|> Iter.fold (fun acc (t,p) ->
match T.view t with
| T.AppBuiltin(Builtin.(ForallConst|ExistsConst) as b, [_;body]) ->
let hoisted = quant_hoist ~old:t b body in
let rest = if CCArray.exists Literal.is_trivial (C.lits hoisted) then acc else hoisted :: acc in
CCList.cons_maybe (quant_rw ~at:p b body) (rest)
| _ -> acc) []
|> (fun res -> CCOpt.return_if (not @@ CCList.is_empty res) res)
let nested_eq_rw c =
let sc = 0 in
let mk_sc t = (t,sc) in
let parents r s = [C.proof_parent_subst r (mk_sc c) s ] in
get_bool_eligible c
|> Iter.filter_map (fun (t,p) ->
match T.view t with
| T.AppBuiltin((Builtin.(Eq|Neq|Equiv|Xor) as hd), ([a;b]|[_;a;b])) ->
Some (
get_unif_alg () (mk_sc a) (mk_sc b)
|> OSeq.map (fun unif_subst_opt ->
CCOpt.map (fun unif_subst ->
assert (not @@ US.has_constr unif_subst);
let subst = US.subst unif_subst in
let repl =
if hd = Builtin.Eq || hd = Builtin.Equiv
then T.true_ else T.false_ in
let new_lits = Array.copy (C.lits c) in
Literals.Pos.replace ~at:p ~by:repl new_lits;
let renaming = Subst.Renaming.create () in
let new_lits =
Literals.apply_subst renaming subst (mk_sc new_lits)
|> CCArray.to_list
in
let rule = Proof.Rule.mk ((if T.equal repl T.true_ then "eq" else "neq") ^ "_rw") in
let proof = Proof.Step.inference ~tags:[Proof.Tag.T_ho] ~rule (parents renaming subst) in
C.create ~penalty:(C.penalty c) ~trail:(C.trail c) new_lits proof
) unif_subst_opt))
| _ -> None)
|> Iter.flat_map_l (fun clause_seq ->
if Env.should_force_stream_eval () then (
Env.get_finite_infs [clause_seq]
) else (
let stm_res = Env.Stm.make ~penalty:(C.penalty c) ~parents:[c] (clause_seq) in
Env.StmQ.add (Env.get_stm_queue ()) stm_res;
[]
))
|> Iter.to_rev_list
let rename_nested_booleans c =
let module L = Literal in
let rename_lit lit =
let sign = L.is_positivoid lit in
if L.is_predicate_lit lit then (
match lit with
| L.Equation(lhs,_,_) ->
CCOpt.get_exn (FR.rename_form ~polarity_aware:false ~c lhs sign)
| _ -> assert false
) else (
let mk_form =
(if sign then T.Form.eq else T.Form.neq)
in
match lit with
| L.Equation(lhs,rhs,_) ->
CCOpt.get_exn (FR.rename_form ~polarity_aware:false ~c (mk_form lhs rhs) sign)
| _ -> assert false
)
in
let threshold = 2 in
C.bool_selected c
|> List.map (fun (_, lit_pos) ->
Literals.Pos.idx lit_pos)
|> CCList.group_by ~hash:CCInt.hash ~eq:CCInt.equal
|> List.map (fun idx_list -> (List.hd idx_list, List.length idx_list))
|> List.filter (fun (_, cnt) -> cnt >= threshold)
|> (function
| x :: xs when not (CCList.is_empty xs) ->
let new_lits = CCArray.copy (C.lits c) in
let (new_defs, new_parents) =
CCList.fold_left (fun (defs, parents) (idx, _) ->
let lit = (C.lits c).(idx) in
let renamer, new_defs, new_parents = rename_lit lit in
let new_lit = Literal.mk_prop renamer (Literal.is_positivoid lit) in
new_lits.(idx) <- new_lit;
(new_defs @ defs, new_parents @ parents)
) ([], []) xs
in
let rule = Proof.Rule.mk "rename_nested_bools" in
let parents = List.map C.proof_parent (c :: new_parents) in
let proof = Proof.Step.simp ~rule parents in
let renamed =
C.create_a ~penalty:(C.penalty c) ~trail:(C.trail c) new_lits proof in
Util.debugf ~section 1 "renamed @[%a@] into@. @[%a@]"
(fun k -> k C.pp c C.pp renamed);
Util.debugf ~section 1 "new_defs @[%a@]" (fun k -> k (CCList.pp C.pp) new_defs);
Some (renamed :: new_defs)
| _ -> None)
let simplify_bools t =
let negate t =
match T.view t with
| T.AppBuiltin(((Builtin.Eq|Builtin.Neq) as b), l) ->
let hd = if b = Builtin.Eq then Builtin.Neq else Builtin.Eq in
T.app_builtin ~ty:(T.ty t) hd l
| T.AppBuiltin(Builtin.Not, [s]) -> s
| _ -> T.Form.not_ t in
let simplify_and_or t b l =
let open Term in
let compl_in_l l =
let pos, neg =
CCList.partition_map (fun t ->
match view t with
| AppBuiltin(Builtin.Not, [s]) -> `Right s
| _ -> `Left t) l
|> CCPair.map_same Set.of_list in
not (Set.is_empty (Set.inter pos neg)) in
let res =
assert(b = Builtin.And || b = Builtin.Or);
let netural_el, absorbing_el =
if b = Builtin.And then true_,false_ else (false_,true_) in
let l' = CCList.sort_uniq ~cmp:compare l in
if compl_in_l l || List.exists (equal absorbing_el) l then absorbing_el
else (
let l' = List.filter (fun s -> not (equal s netural_el)) l' in
if List.length l = List.length l' then t
else (
if CCList.is_empty l' then netural_el
else (if List.length l' = 1 then List.hd l'
else app_builtin ~ty:(Type.prop) b l')
))
in
res
in
let rec aux t =
let ty_is_prop t = Type.is_prop (T.ty t) in
match T.view t with
| DB _ | Const _ | Var _ -> t
| Fun(ty, body) ->
let body' = aux body in
assert(Type.equal (T.ty body) (T.ty body'));
if T.equal body body' then t
else T.fun_ ty body'
| App(hd, args) ->
let hd' = aux hd and args' = List.map aux args in
if T.equal hd hd' && T.same_l args args' then t
else T.app hd' args'
| AppBuiltin (Builtin.And, [x])
when T.is_true_or_false x
&& ty_is_prop t
&& List.length (Type.expected_args (T.ty t)) = 1 ->
if T.equal x T.true_ then (
T.fun_ Type.prop (T.bvar ~ty:Type.prop 0)
) else (
assert (T.equal x T.false_);
T.fun_ Type.prop T.false_
)
| AppBuiltin(Builtin.Or, [x])
when T.is_true_or_false x
&& ty_is_prop t
&& List.length (Type.expected_args (T.ty t)) = 1 ->
let prop = Type.prop in
if T.equal x T.true_ then (
T.fun_ prop T.true_
) else (
assert (T.equal x T.false_);
T.fun_ prop (T.bvar ~ty:prop 0)
)
| AppBuiltin(Builtin.And, l)
when ty_is_prop t &&
List.length l > 1 ->
let l' = List.map aux l in
let t =
if T.same_l l l' then t
else T.app_builtin ~ty:(Type.prop) Builtin.And l' in
simplify_and_or t Builtin.And l'
| AppBuiltin(Builtin.Or, l)
when ty_is_prop t &&
List.length l > 1 ->
let l' = List.map aux l in
let t =
if T.same_l l l' then t
else T.app_builtin ~ty:(Type.prop) Builtin.Or l' in
simplify_and_or t Builtin.Or l'
| AppBuiltin(Builtin.Not, [s]) ->
let s' = aux s in
begin match T.view s' with
| AppBuiltin(Builtin.Not, [s'']) -> s''
| _ ->
if T.equal s' T.true_ then T.false_
else if T.equal s' T.false_ then T.true_
else if T.equal s s' then t
else T.app_builtin ~ty:(Type.prop) Builtin.Not [s'] end
| AppBuiltin(Builtin.Imply, [p;c]) ->
let unroll_and p = match T.view p with
| AppBuiltin(And, l) -> T.Set.of_list l
| _ -> T.Set.singleton p in
let unroll_or p = match T.view p with
| AppBuiltin(Or, l) -> T.Set.of_list l
| _ -> T.Set.singleton p in
let is_impl p = match T.view p with
| AppBuiltin(Imply, [l;r]) -> true
| _ -> false in
let unroll_impl p =
assert(is_impl p);
let rec aux acc p =
match T.view p with
| AppBuiltin(Imply, [l;r]) ->
let unrolled_l = unroll_and l in
let acc' = Term.Set.union unrolled_l acc in
if is_impl r then aux acc' r
else (acc', unroll_or r)
| _ -> assert false in
aux Term.Set.empty p
in
let p' = aux p and c' = aux c in
let (premises,conclusions) = unroll_impl (T.Form.imply p' c') in
if not (T.Set.is_empty (T.Set.inter premises conclusions)) then (
T.true_
) else if T.equal p' c' then T.true_
else if T.equal c' (negate p') then c'
else if T.equal p' (negate c') then c'
else if T.equal p' T.true_ then c'
else if T.equal p' T.false_ then T.true_
else if T.equal c' T.false_ then aux (T.Form.not_ p')
else if T.equal c' T.true_ then T.true_
else (
if T.equal p p' && T.equal c c' then t
else T.app_builtin ~ty:(T.ty t) Builtin.Imply [p';c']
)
| AppBuiltin((Builtin.Eq | Builtin.Equiv) as hd, ([a;b]|[_;a;b])) when Type.is_prop (T.ty t)->
let cons = if hd = Builtin.Eq then T.Form.eq else T.Form.equiv in
let a',b' = aux a, aux b in
if T.equal a' b' then T.true_
else if T.equal a' T.true_ then b'
else if T.equal b' T.true_ then a'
else if T.equal a' T.false_ then aux (T.Form.not_ b')
else if T.equal b' T.false_ then aux (T.Form.not_ a')
else (
if T.equal a a' && T.equal b b' then t
else cons a' b'
)
| AppBuiltin((Builtin.Neq | Builtin.Xor) as hd, ([a;b]|[_;a;b])) when Type.is_prop (T.ty t) ->
let cons = if hd = Builtin.Neq then T.Form.neq else T.Form.xor in
let a',b' = aux a, aux b in
if T.equal a' b' then T.false_
else if T.equal a' T.true_ then aux (T.Form.not_ b')
else if T.equal b' T.true_ then aux (T.Form.not_ a')
else if T.equal a' T.false_ then b'
else if T.equal b' T.false_ then a'
else (
if T.equal a a' && T.equal b b' then t
else cons a' b'
)
| AppBuiltin((ExistsConst|ForallConst) as b, [tyarg;g]) ->
let g' = aux g in
let exp_g = Combs.expand g' in
let _, body = T.open_fun exp_g in
assert(Type.is_prop (T.ty body));
if (T.Seq.subterms ~include_builtin:true body
|> Iter.exists T.is_bvar) then (
if T.equal g g' then t
else T.app_builtin ~ty:(T.ty t) b [tyarg; g']
) else body
| AppBuiltin(hd, args) ->
let args' = List.map aux args in
if T.same_l args args' then t
else T.app_builtin ~ty:(T.ty t) hd args' in
let res = aux t in
assert (T.DB.is_closed res);
res
let fix_unsupported_quant t =
let quant_normal _ q_body =
let has_loosely_bound_0 t =
List.mem 0 (T.DB.unbound t)
in
let rec aux t =
match T.view t with
| Fun(_, body) -> not (has_loosely_bound_0 t)
| App(hd, args) ->
if T.is_const hd then List.for_all aux args
else (
not (List.exists has_loosely_bound_0 (hd::args))
)
| AppBuiltin(hd, args) -> List.for_all aux args
| _ -> true
in
let res = aux q_body in
res
in
let rec aux t =
match T.view t with
| Fun(ty,body) ->
let body' = aux body in
assert(Type.equal (T.ty body) (T.ty body'));
if T.equal body body' then t
else T.fun_ ty body'
| App(hd,args) ->
let hd' = aux hd in
let args' = List.map aux args in
if T.equal hd hd' && T.same_l args args' then t
else T.app hd' args'
| AppBuiltin((ExistsConst|ForallConst) as hd, [alpha]) ->
let alpha = Type.of_term_unsafe (alpha :> InnerTerm.t) in
let alpha2prop = Type.arrow [alpha] Type.prop in
let inner_quant =
let body =
if Builtin.equal hd ExistsConst then T.false_
else T.true_
in
T.fun_ alpha body
in
let var = T.bvar ~ty:alpha2prop 0 in
let body =
if Builtin.equal hd ExistsConst then T.Form.neq var inner_quant
else T.Form.eq var inner_quant
in
T.fun_ alpha2prop body
| AppBuiltin((ExistsConst|ForallConst), ([])) ->
invalid_arg "type argument must be present"
| AppBuiltin(hd,args) ->
let args' = List.map aux args in
if Builtin.is_quantifier hd && List.length args' == 2 then (
let q_pref, q_body = T.open_fun @@ List.nth args' 1 in
let var_ty = List.hd q_pref in
if not (quant_normal var_ty q_body) then (
if Builtin.equal hd Builtin.ExistsConst then (
T.Form.neq (List.nth args' 1) (T.fun_ var_ty T.false_)
) else (
T.Form.eq (List.nth args' 1) (T.fun_ var_ty T.true_)
)
) else T.app_builtin ~ty:(T.ty t) hd args'
) else (
if T.same_l args args' then t
else T.app_builtin ~ty:(T.ty t) hd args'
)
| DB _ | Const _ | Var _ -> t
in
if Env.flex_get Combinators.k_enable_combinators then t
else aux (Lambda.eta_reduce @@ Lambda.snf t)
let replace_unsupported_quants c =
let new_lits = Literals.map fix_unsupported_quant (C.lits c) in
if Literals.equal (C.lits c) new_lits then (
None
) else (
let proof = Proof.Step.simp [C.proof_parent c]
~rule:(Proof.Rule.mk "replace unsupported quants") in
let new_ = C.create ~trail:(C.trail c) ~penalty:(C.penalty c)
(Array.to_list new_lits) proof in
Some new_
)
let simpl_bool_subterms c =
try
let new_lits = Literals.map simplify_bools (C.lits c) in
if Literals.equal (C.lits c) new_lits then (
SimplM.return_same c
) else (
let proof = Proof.Step.simp [C.proof_parent c]
~rule:(Proof.Rule.mk "simplify boolean subterms") in
let new_ = C.create ~trail:(C.trail c) ~penalty:(C.penalty c)
(Array.to_list new_lits) proof in
SimplM.return_new new_
)
with Type.ApplyError err ->
CCFormat.printf "error(%s):@[%a@]@." err C.pp c;
CCFormat.printf "@[%a@]@." Proof.S.pp_tstp (C.proof c);
assert false
let nnf_bools t =
let module F = T.Form in
let expand_quant = not @@ Env.flex_get Combinators.k_enable_combinators in
let rec aux t =
match T.view t with
| Const _ | DB _ | Var _ -> t
| Fun _ ->
let tyargs, body = T.open_fun t in
let body' = aux body in
if T.equal body body' then t
else T.fun_l tyargs body'
| App(hd, l) ->
let hd' = aux hd and l' = List.map aux l in
if T.equal hd hd' && T.same_l l l' then t
else T.app hd' l'
| AppBuiltin (Builtin.Not, [f]) ->
begin match T.view f with
| AppBuiltin(Not, [g]) -> aux g
| AppBuiltin( ((And|Or) as b), l) when List.length l >= 2 ->
let flipped = if b = Builtin.And then F.or_l else F.and_l in
flipped (List.map (fun t -> aux (F.not_ t)) l)
| AppBuiltin( ((ForallConst|ExistsConst) as b), ([g]|[_;g]) ) ->
let flipped =
if b = Builtin.ForallConst then Builtin.ExistsConst
else Builtin.ForallConst in
let g_ty_args, g_body = T.open_fun (Combs.expand g) in
let g_body' = aux @@ F.not_ g_body in
let g' = Lambda.eta_reduce ~expand_quant (T.fun_l g_ty_args g_body') in
T.app_builtin ~ty:(T.ty t) flipped [g']
| AppBuiltin( Imply, [g;h] ) ->
F.and_ (aux g) (aux @@ F.not_ h)
| AppBuiltin( ((Equiv|Xor) as b), [g;h] ) ->
let flipped = if b = Equiv then Builtin.Xor else Builtin.Equiv in
aux (T.app_builtin ~ty:(T.ty t) flipped [g;h])
| AppBuiltin(((Eq|Neq) as b), ([_;s;t]|[s;t])) ->
let flipped = if b = Eq then F.neq else F.eq in
flipped (aux s) (aux t)
| _ -> F.not_ (aux f)
end
| AppBuiltin(Imply, [f;g]) -> aux (F.or_ (F.not_ f) g)
| AppBuiltin(Equiv, [f;g]) ->
aux (F.and_ (F.imply f g) (F.imply g f))
| AppBuiltin(Xor, [f;g]) ->
aux (F.and_ (F.or_ f g) (F.or_ (F.not_ f) (F.not_ g)))
| AppBuiltin(b, l) ->
let l' = List.map aux l in
if T.same_l l l' then t
else T.app_builtin ~ty:(T.ty t) b l' in
aux t
let nnf_bool_subters c =
let new_lits = Literals.map nnf_bools (C.lits c) in
if Literals.equal (C.lits c) new_lits then (
SimplM.return_same c
) else (
let proof = Proof.Step.simp [C.proof_parent c]
~rule:(Proof.Rule.mk "nnf boolean subterms") in
let new_ = C.create ~trail:(C.trail c) ~penalty:(C.penalty c)
(Array.to_list new_lits) proof in
SimplM.return_new new_
)
let normalize_bool_terms c =
let new_lits = Literals.map T.normalize_bools (C.lits c) in
if Literals.equal (C.lits c) new_lits then (
SimplM.return_same c
) else (
let proof = Proof.Step.simp [C.proof_parent c]
~rule:(Proof.Rule.mk "normalize subterms") in
let new_ = C.create ~trail:(C.trail c) ~penalty:(C.penalty c)
(Array.to_list new_lits) proof in
SimplM.return_new new_
)
let solve_bool_formulas ~which c =
let normalize_not t =
let rec aux t =
match T.view t with
| T.AppBuiltin(Not, [f]) ->
begin match T.view f with
| T.AppBuiltin(Not, [g]) -> aux g
| T.AppBuiltin( ((Eq|Equiv) as b), l ) ->
let flipped =
if b = Builtin.Eq then Builtin.Neq else Builtin.Xor in
T.app_builtin flipped l ~ty:(T.ty f)
| T.AppBuiltin( ((Neq|Xor) as b), l ) ->
let flipped =
if b = Builtin.Neq then Builtin.Eq else Builtin.Equiv in
T.app_builtin flipped l ~ty:(T.ty f)
| _ -> t end
| _ -> t in
aux t in
let find_resolvable_form lit =
let is_var_headed t = T.is_var (T.head_term t) in
let find_pos_var_headed_eq l r =
if is_var_headed l && not (is_var_headed r) then (Some(l, T.Form.not_ r))
else if is_var_headed r && not (is_var_headed l) then (Some(r, T.Form.not_ l))
else None in
match (Literal.View.as_eqn lit) with
| Some (l,r,sign) ->
if not (T.is_true_or_false r) && Type.is_prop (T.ty l) then (
if not sign && which = `All then Some (l,r)
else if sign then find_pos_var_headed_eq l r
else None)
else if T.is_true_or_false r then (
let apply_sign = if sign then CCFun.id else T.Form.not_ in
match T.view (normalize_not (apply_sign l)) with
| T.AppBuiltin((Neq|Xor), ([f;g]|[_;f;g]))
when Type.is_prop (T.ty f) && which == `All ->
assert(Type.equal (T.ty f) (T.ty g));
Some (f,g)
| T.AppBuiltin((Eq|Equiv), ([f;g]|[_;f;g])) when Type.is_prop (T.ty f) ->
assert(Type.equal (T.ty f) (T.ty g));
find_pos_var_headed_eq f g
| _ -> None
) else None
| None -> None in
let unif_alg l r =
if not (Env.flex_get Combinators.k_enable_combinators) then (
Env.flex_get Superposition.k_unif_alg (l,0) (r,0)
) else OSeq.return (Some (Unif.FO.unify_full (l,0) (r,0))) in
Util.debugf ~section 5 "bool solving @[%a@]@."(fun k -> k C.pp c);
C.lits c
|> CCArray.mapi (fun i lit ->
match find_resolvable_form lit with
| None ->
Util.debugf ~section 5 "for lit %d(@[%a@]) of @[%a@] no resolvable lits found@."
(fun k -> k i Literal.pp lit C.pp c);
None
| Some (l,r) ->
let module US = Unif_subst in
try
Util.debugf ~section 5 "trying lit @[%d:%a@]@."(fun k -> k i Literal.pp lit);
Util.debugf ~section 5 "unif problem: @[%a=?=%a@]@."(fun k -> k T.pp l T.pp r);
let stm =
unif_alg l r
|> OSeq.map (CCOpt.map (fun subst ->
let renaming = Subst.Renaming.create () in
let new_lits =
CCArray.except_idx (C.lits c) i
|> CCArray.of_list
|> (fun l ->
Literals.apply_subst renaming (US.subst subst) (l,0))
|> CCArray.to_list in
let proof =
Proof.Step.simp ~tags:[Proof.Tag.T_ho]
~rule:(Proof.Rule.mk "solve_formulas")
[C.proof_parent_subst renaming (c,0) (US.subst subst) ] in
let res = C.create ~penalty:(C.penalty c) ~trail:(C.trail c) new_lits proof in
Util.debugf ~section 5 "solved by @[%a@]@."(fun k -> k C.pp res);
res
))
in
match stm () with
| OSeq.Cons(hd, rest) ->
let stm = Stm.make ~penalty:(C.penalty c) ~parents:[c] rest in
StmQ.add (Env.get_stm_queue ()) stm;
hd
| OSeq.Nil -> None
with _ ->
Util.debugf ~section 5 "failed @." (fun k -> k);
None)
|> CCArray.filter_map CCFun.id
|> CCArray.to_list
|> (fun l -> if CCList.is_empty l then None else Some l)
let cnf_otf c : C.t list option =
let idx = CCArray.find_idx (fun l ->
let eq = Literal.View.as_eqn l in
match eq with
| Some (l,r,_) ->
Type.is_prop (T.ty l) &&
not (T.equal l r) &&
((not (T.equal r T.true_) && not (T.equal r T.false_))
|| T.is_formula l || T.is_formula r)
| None -> false
) (C.lits c) in
let renaming_weight = 40 in
let max_formula_weight =
C.Seq.terms c
|> Iter.filter T.is_formula
|> Iter.map T.size
|> Iter.max in
let opts =
match max_formula_weight with
| None -> [Cnf.DisableRenaming]
| Some m -> if m < renaming_weight then [Cnf.DisableRenaming] else [] in
match idx with
| Some _ ->
let f = Literals.Conv.to_tst (C.lits c) in
let proof = Proof.Step.simp ~rule:(Proof.Rule.mk "cnf_otf") ~tags:[Proof.Tag.T_ho] [C.proof_parent c] in
let trail = C.trail c and penalty = C.penalty c in
let stmt = Statement.assert_ ~proof f in
let cnf_vec = Cnf.convert @@ CCVector.to_iter @@ Cnf.cnf_of ~opts ~ctx:(Ctx.sk_ctx ()) stmt in
CCVector.iter (fun cl ->
Statement.Seq.ty_decls cl
|> Iter.iter (fun (id,ty) ->
Ctx.declare id ty;
ID.set_payload id (ID.Attr_skolem ID.K_after_cnf)
)) cnf_vec;
let solved =
if Env.flex_get k_solve_formulas then (
CCOpt.get_or ~default:[] (solve_bool_formulas ~which:`All c))
else [] in
let clauses = CCVector.map (C.of_statement ~convert_defs:true) cnf_vec
|> CCVector.to_list
|> CCList.flatten
|> List.map (fun c ->
C.create ~penalty ~trail (CCArray.to_list (C.lits c)) proof) in
Util.debugf ~section 5 "cl:@[%a@]@." (fun k-> k C.pp c);
Util.debugf ~section 5 " @[%a@]@." (fun k-> k (CCList.pp C.pp) clauses);
List.iteri (fun i new_c ->
assert((C.proof_depth c) <= C.proof_depth new_c);) clauses;
Some (solved @clauses)
| None -> None
let cnf_infer cl =
CCOpt.get_or ~default:[] (cnf_otf cl)
let interpret_boolean_functions c =
let collect_tl_bool_funs t k =
let rec aux t =
let ty_args, ret_ty = Type.open_fun (T.ty t) in
if not (CCList.is_empty ty_args)
&& Type.is_prop ret_ty
&& not (T.is_var t)
&& not (T.is_app_var t) then k t else(
match T.view t with
| App (f, l) ->
List.iter aux l
| AppBuiltin (b,l) when not (Builtin.is_quantifier b) ->
List.iter aux l
| _ -> ())
in
aux t in
let interpret t i =
let ty_args, body = T.open_fun t in
assert(Type.is_prop (Term.ty body));
T.fun_l ty_args i
in
let negate_bool_fun bool_fun =
let ty_args, body = T.open_fun bool_fun in
assert(Type.is_prop (Term.ty body));
T.fun_l ty_args (T.Form.not_ body)
in
let forall_close t =
let ty_args, body = T.open_fun t in
assert(Type.is_prop (T.ty body));
List.fold_right (fun ty acc ->
T.Form.forall (T.fun_ ty acc)
) ty_args body in
Iter.flat_map collect_tl_bool_funs
(C.Seq.terms c
|> Iter.filter (fun t -> not @@ Type.is_fun (T.ty t)))
|> Iter.filter (fun t ->
let cached_t = Subst.FO.canonize_all_vars t in
not (Term.Set.mem cached_t !Higher_order.prim_enum_terms))
|> Iter.sort_uniq ~cmp:Term.compare
|> Iter.fold (fun res t ->
assert(T.DB.is_closed t);
let proof = Proof.Step.inference [C.proof_parent c]
~rule:(Proof.Rule.mk"interpret boolean function") ~tags:[Proof.Tag.T_ho]
in
let t' = Combs.expand t in
let _,t'_body = T.open_fun t' in
if not (T.is_true_or_false t'_body) then (
let as_forall = Literal.mk_prop (forall_close t') false in
let as_neg_forall = Literal.mk_prop (forall_close (negate_bool_fun t')) false in
let forall_cl =
C.create ~trail:(C.trail c) ~penalty:(C.penalty c)
(as_forall :: Array.to_list(C.lits c |> Literals.map(T.replace ~old:t ~by:(interpret t' T.true_))))
proof in
let forall_neg_cl =
C.create ~trail:(C.trail c) ~penalty:(C.penalty c)
(as_neg_forall :: Array.to_list(C.lits c |> Literals.map(T.replace ~old:t ~by:(interpret t' T.false_))))
proof in
Util.debugf ~section 5 "interpret bool(@[%a@]):@.@[%a@] !!> @. @[%a@]@."
(fun k -> k T.pp t Literals.pp (C.lits c) Literals.pp (C.lits forall_cl));
Util.debugf ~section 5 "interpret bool(@[%a@]):@.@[%a@] !!> @. @[%a@]@."
(fun k -> k T.pp t Literals.pp (C.lits c) Literals.pp (C.lits forall_neg_cl));
forall_cl :: forall_neg_cl :: res
) else res)
[]
let setup () =
if Env.flex_get k_replace_unsupported_quants then (
Signal.once Env.on_start (fun () ->
Env.ProofState.PassiveSet.clauses ()
|> C.ClauseSet.iter (fun cl ->
match replace_unsupported_quants cl with
| None -> ()
| Some new_ ->
Env.remove_passive (Iter.singleton cl);
Env.add_passive (Iter.singleton new_);
)););
match Env.flex_get k_bool_reasoning with
| BoolReasoningDisabled -> ()
| BoolCasesPreprocess ->
Env.add_unary_inf "false_elim" false_elim;
| _ ->
if Env.flex_get k_solve_formulas then (
Env.add_unary_inf "solve formulas" (
fun c ->
CCOpt.get_or ~default:[] @@
solve_bool_formulas ~which:`OnlyPositive c
));
if Env.flex_get k_trigger_bool_inst > 0 || Env.flex_get k_trigger_bool_ind > 0 then (
Signal.on Env.on_pred_var_elimination handle_new_pred_var_clause;
Signal.on Env.FormRename.on_pred_skolem_introduction handle_new_skolem_sym;
);
if Env.flex_get k_trigger_bool_ind > 0 then (
Env.add_unary_inf "trigger bool ind" trigger_induction
);
if Env.flex_get k_simplify_bools then (
Env.add_basic_simplify simpl_bool_subterms
);
if Env.flex_get k_nnf then (
E.add_basic_simplify nnf_bool_subters;
);
if Env.flex_get k_norm_bools then (
Env.add_basic_simplify normalize_bool_terms
);
if not !Lazy_cnf.enabled then (
Env.add_multi_simpl_rule ~priority:2 Fool.rw_bool_lits;
if Env.flex_get k_cnf_non_simpl then (
Env.add_unary_inf "cnf otf inf" cnf_infer;
) else Env.add_multi_simpl_rule ~priority:2 cnf_otf);
if (Env.flex_get k_interpret_bool_funs) then (
Env.add_unary_inf "interpret boolean functions" interpret_boolean_functions;
);
Env.add_unary_inf "false_elim" false_elim;
if Env.flex_get k_bool_reasoning = BoolHoist then (
if Env.flex_get k_bool_hoist_simpl
then Env.add_multi_simpl_rule ~priority:1000 bool_hoist_simpl;
Env.add_unary_inf "bool_hoist" bool_hoist;
if Env.flex_get k_rename_nested_bools then (
Env.add_multi_simpl_rule ~priority:500 rename_nested_booleans
);
Env.add_unary_inf "formula_hoist" eq_hoist;
Env.add_multi_simpl_rule ~priority:100 replace_bool_vars;
Env.add_multi_simpl_rule ~priority:90 quantifier_rw_and_hoist;
Env.add_unary_inf "eq_rw" nested_eq_rw;
if Env.flex_get Superposition.k_ho_basic_rules then (
if Env.flex_get k_bool_app_var_repl then (
Env.add_unary_inf "replace_bool_app_vars" replace_bool_app_vars
);
if Env.flex_get k_fluid_hoist then (
Env.add_unary_inf "fluid_hoist" fluid_hoist
);
if Env.flex_get k_fluid_log_hoist then (
Env.add_unary_inf "fluid_log_hoist" fluid_log_hoist;
Env.add_unary_inf "fluid_quant_rw" fluid_quant_rw;
);
);
)
end
open CCFun
open Builtin
open Statement
open TypedSTerm
open CCList
let if_changed proof (mk: ?attrs:Logtk.Statement.attrs -> 'r) s f p =
let fp = f s p in
if fp == [p] then [s] else map(fun x -> mk ~proof:(proof s) x) fp
let map_propositions ~proof f =
CCVector.flat_map_list(fun s -> match Statement.view s with
| Assert p -> if_changed proof assert_ s f p
| Lemma ps -> if_changed proof lemma s (map%f) ps
| Goal p -> if_changed proof goal s f p
| NegatedGoal(ts, ps) -> if_changed proof (neg_goal ~skolems:ts) s (map%f) ps
| _ -> [s]
)
let is_bool t = CCOpt.equal Ty.equal (Some prop) (ty t)
let is_T_F t = match view t with AppBuiltin((True|False),[]) -> true | _ -> false
let rec replaceTST f top t =
let re = replaceTST f in
let ty = ty_exn t in
let transformer = if top then id else f in
transformer
(match view t with
| App(t,ts) ->
app_whnf ~ty (re false t) (map (re false) ts)
| Ite(c,x,y) ->
ite (re false c) (re false x) (re false y)
| Match(t, cases) ->
match_ (re false t) (map (fun (c,vs,e) -> (c,vs, re false e)) cases)
| Let(binds, expr) ->
let_ (map(CCPair.map_snd (re false)) binds) (re false expr)
| Bind(b,x,t) ->
let top = Binder.equal b Binder.Forall || Binder.equal b Binder.Exists in
bind ~ty b x (re top t)
| AppBuiltin(b,ts) ->
let logical = for_all is_bool ts in
app_builtin ~ty b (map (re(top && logical)) ts)
| Multiset ts ->
multiset ~ty (map (re false) ts)
| _ -> t)
let name_quantifiers stmts =
let proof s = Proof.Step.esa [Proof.Parent.from(Statement.as_proof_i s)]
~rule:(Proof.Rule.mk "Quantifier naming")
in
let new_stmts = CCVector.create() in
let changed = ref false in
let if_changed (mk: ?attrs:Logtk.Statement.attrs -> 'r) s r =
if !changed then (changed := false; mk ~proof:(proof s) r) else s in
let if_changed_list (mk: ?attrs:Logtk.Statement.attrs -> 'l) s r =
if !changed then (changed := false; mk ~proof:(proof s) r) else s in
let name_prop_Qs s = replaceTST(fun t -> match TypedSTerm.view t with
| Bind(Binder.Forall,_,_) | Bind(Binder.Exists, _, _) ->
changed := true;
let vars = Var.Set.of_iter (TypedSTerm.Seq.free_vars t) |> Var.Set.to_list in
let qid = ID.gensym() in
let ty = app_builtin ~ty:tType Arrow (prop :: map Var.ty vars) in
let q = const ~ty qid in
let q_vars = app ~ty:prop q (map var vars) in
let proof = Proof.Step.define_internal qid [Proof.Parent.from(Statement.as_proof_i s)] in
let q_typedecl = ty_decl ~proof qid ty in
let definition =
bind_list ~ty:prop Binder.Forall vars
(app_builtin ~ty:prop Builtin.Equiv [q_vars; t])
in
CCVector.push new_stmts q_typedecl;
CCVector.push new_stmts (assert_ ~proof definition);
q_vars
| _ -> t) true
in
stmts |> CCVector.map(fun s ->
match Statement.view s with
| TyDecl(id,t) -> s
| Data ts -> s
| Def defs -> s
| Rewrite _ -> s
| Assert p -> if_changed assert_ s (name_prop_Qs s p)
| Lemma ps -> if_changed_list lemma s (map (name_prop_Qs s) ps)
| Goal p -> if_changed goal s (name_prop_Qs s p)
| NegatedGoal(ts, ps) -> if_changed_list (neg_goal ~skolems:ts) s (map (name_prop_Qs s) ps)
) |> CCVector.append new_stmts;
CCVector.freeze new_stmts
let rec replace old by t =
let r = replace old by in
let ty = ty_exn t in
if TypedSTerm.equal t old then by
else match view t with
| App(f,ps) -> app_whnf ~ty (r f) (map r ps)
| AppBuiltin(f,ps) -> app_builtin ~ty f (map r ps)
| Ite(c,x,y) -> ite (r c) (r x) (r y)
| Let(bs,e) -> let_ (map (CCPair.map_snd r) bs) (r e)
| Bind(b,v,e) -> bind ~ty b v (r e)
| _ -> t
exception Return of TypedSTerm.t
let with_subterm_or_id t f = try
(Seq.subterms_with_bound t (fun(s, var_ctx) ->
match f var_ctx s with
| None -> ()
| Some r -> raise(Return r)));
t
with Return r -> r
let case_bool vs c p =
if is_bool p && not(is_T_F p) && not (TypedSTerm.equal p c) && Var.Set.is_empty(Var.Set.diff (free_vars_set p) vs) then
let ty = prop in
app_builtin ~ty And [
app_builtin ~ty Imply [p; replace p Form.true_ c];
app_builtin ~ty Or [p; replace p Form.false_ c];
]
else c
let rec case_bools_wrt vs t =
with_subterm_or_id t (fun _ s ->
match view s with
| App(f,ps) ->
let t' = fold_left (case_bool vs) t ps in
if TypedSTerm.equal t t' then None else Some(case_bools_wrt vs t')
| _ -> None
)
let eager_cases_far stms =
let proof s = Proof.Step.esa [Proof.Parent.from(Statement.as_proof_i s)]
~rule:(Proof.Rule.mk "eager_cases_far")
in
map_propositions ~proof (fun _ t ->
[with_subterm_or_id t (fun vs s ->
match view s with
| Bind((Forall|Exists) as q, v, b) ->
let b' = case_bools_wrt (Var.Set.add vs v) b in
if TypedSTerm.equal b b' then None else Some(replace s (bind ~ty:prop q v b') t)
| _ -> None)
|> case_bools_wrt Var.Set.empty]) stms
let eager_cases_near stms =
let proof s = Proof.Step.esa [Proof.Parent.from(Statement.as_proof_i s)]
~rule:(Proof.Rule.mk "eager_cases_near")
in
let module T = TypedSTerm in
let find_fool_subterm ?(free_vars=Var.Set.empty) p =
let rec aux ~top p =
let p_ty = T.ty_exn p in
let no_leaky_variables t =
Var.Set.intersection_empty (T.free_vars_set t) free_vars
in
let return p =
assert(T.Ty.is_prop (T.ty_exn p));
assert(no_leaky_variables p);
Some (T.Form.true_, T.Form.false_, p) in
match T.view p with
| AppBuiltin(hd, args)
when not top && no_leaky_variables p && T.Ty.is_prop (T.ty_exn p) &&
(Builtin.is_logical_op hd ||
Builtin.equal hd Builtin.Eq ||
Builtin.equal hd Builtin.Neq) ->
CCFormat.printf "found OK eq@.";
return p
| Bind((Binder.Exists | Binder.Forall), var, body)
when not top && no_leaky_variables p ->
return p
| Bind(Binder.Lambda, var, body) ->
CCOpt.map (fun (body_t, body_f, s) ->
assert(no_leaky_variables s);
(T.fun_l [var] body_t, T.fun_l [var] body_f, s)
) (aux ~top:false body)
| App(hd, args) when not top && T.Ty.is_prop p_ty && no_leaky_variables p ->
return p
| Const _ when not top && T.Ty.is_prop p_ty ->
return p
| AppBuiltin(b, args) ->
CCOpt.map (fun (args_t,args_f, s) ->
(T.app_builtin ~ty:p_ty b args_t, T.app_builtin ~ty:p_ty b args_f, s)
) (aux_l args)
| App(hd,args) ->
CCOpt.map (fun (args_t,args_f, s) ->
(T.app ~ty:p_ty hd args_t, T.app ~ty:p_ty hd args_f, s)
) (aux_l args)
| _ -> None
and aux_l = function
| [] -> None
| x :: xs ->
begin match aux ~top:false x with
| Some (x_t, x_f, s) -> Some(x_t::xs, x_f::xs, s)
| None ->
begin match aux_l xs with
| Some (xs_t, xs_f, s) -> Some (x::xs_t, x::xs_f, s)
| None -> None end
end in
let res = aux ~top:true p in
res in
let unroll_fool p =
let rec aux ~vars p =
let p_ty = T.ty_exn p in
match T.view p with
| AppBuiltin(((Builtin.Neq|Builtin.Eq) as hd), ([_;a;b]|[a;b])) when not (T.Ty.is_prop (T.ty_exn a)) ->
let cons = if hd = Neq then T.Form.neq else T.Form.eq in
begin match find_fool_subterm a with
| None ->
begin match find_fool_subterm b with
| None -> p
| Some(b_t, b_f, subterm) ->
let subterm' = aux ~vars subterm in
let if_true = T.Form.or_ [T.Form.not_ (subterm'); aux ~vars @@ cons a b_t] in
let if_false = T.Form.or_ [subterm'; aux ~vars @@ cons a b_f] in
T.Form.and_ [if_true; if_false]
end
| Some(a_t, a_f, subterm) ->
let subterm' = aux ~vars subterm in
let if_true = T.Form.or_ [T.Form.not_ (subterm'); aux ~vars @@ cons a_t b] in
let if_false = T.Form.or_ [subterm'; aux ~vars @@ cons a_f b] in
T.Form.and_ [if_true; if_false]
end
| AppBuiltin(hd, args) ->
T.app_builtin ~ty:p_ty hd (List.map (aux ~vars) args)
| App(hd, args) ->
begin match find_fool_subterm p with
| Some(p_t, p_f, subterm) ->
let subterm' = aux ~vars subterm in
let if_true = T.Form.or_ [T.Form.not_ (subterm'); aux ~vars p_t] in
let if_false = T.Form.or_ [subterm'; aux ~vars p_f] in
T.Form.and_ [if_true; if_false]
| None -> p end
| Bind((Binder.Exists | Binder.Forall) as b, var , body) ->
let body' = aux ~vars:(Var.Set.add vars var) body in
T.bind ~ty:p_ty b var body'
| _ -> p in
let res = aux ~vars:Var.Set.empty p in
res in
map_propositions ~proof (fun _ p -> [unroll_fool p]) stms
open Term
let post_eager_cases =
let proof s = Proof.Step.esa [Proof.Parent.from(Statement.as_proof_c s)]
~rule:(Proof.Rule.mk "post_eager_cases")
in
map_propositions ~proof (fun _ c ->
let cased = ref Set.empty in
fold_left(SLiteral.fold(fun res ->
Seq.subterms_depth %> Iter.fold(fun res (s,d) ->
if d = 0 || not(Type.is_prop(ty s)) || is_true_or_false s || is_var s || Set.mem s !cased
|| not (T.DB.is_closed s)
then
res
else(
cased := Set.add s !cased;
let replace_s_by by = map(SLiteral.map ~f:(replace ~old:s ~by)) in
flatten(map(fun c -> [
SLiteral.atom_true s :: replace_s_by false_ c;
SLiteral.atom_false s :: replace_s_by true_ c
]) res))
) res
)) [c] c)
let _bool_reasoning = ref BoolReasoningDisabled
let _quant_rename = ref false
let preprocess_booleans stmts = (match !_bool_reasoning with
| BoolCasesPreprocess -> eager_cases_near
| _ -> id
) (if !_quant_rename then name_quantifiers stmts else stmts)
let preprocess_cnf_booleans stmts = match !_bool_reasoning with
| BoolCasesPreprocess ->
let res = post_eager_cases stmts in
res
| _ -> stmts
let _interpret_bool_funs = ref false
let _cnf_non_simpl = ref false
let _norm_bools = ref false
let _filter_literals = ref `Max
let _nnf = ref false
let _simplify_bools = ref true
let _trigger_bool_inst = ref (-1)
let _trigger_bool_ind = ref (-1)
let _generalize_trigger = ref (`Off)
let _include_quants = ref true
let _bool_hoist_simpl = ref false
let _rename_nested_bools = ref false
let _fluid_hoist = ref false
let _bool_app_var_repl = ref false
let _fluid_log_hoist = ref false
let _solve_formulas = ref false
let _replace_quants = ref false
let _disable_ho_unif = ref false
let _bool_triggers_only = ref (false)
let extension =
let register env =
let module E = (val env : Env.S) in
let module ET = Make(E) in
E.flex_add k_bool_reasoning !_bool_reasoning;
E.flex_add k_quant_rename !_quant_rename;
E.flex_add k_interpret_bool_funs !_interpret_bool_funs;
E.flex_add k_cnf_non_simpl !_cnf_non_simpl;
E.flex_add k_norm_bools !_norm_bools;
E.flex_add k_filter_literals !_filter_literals;
E.flex_add k_nnf !_nnf;
E.flex_add k_simplify_bools !_simplify_bools;
E.flex_add k_trigger_bool_inst !_trigger_bool_inst;
E.flex_add k_trigger_bool_ind !_trigger_bool_ind;
E.flex_add k_include_quants !_include_quants;
E.flex_add k_bool_hoist_simpl !_bool_hoist_simpl;
E.flex_add k_rename_nested_bools !_rename_nested_bools;
E.flex_add k_fluid_hoist !_fluid_hoist;
E.flex_add k_bool_app_var_repl !_bool_app_var_repl;
E.flex_add k_fluid_log_hoist !_fluid_log_hoist;
E.flex_add k_solve_formulas !_solve_formulas;
E.flex_add k_replace_unsupported_quants !_replace_quants;
E.flex_add k_disable_ho_bool_unif !_disable_ho_unif;
E.flex_add k_generalize_trigger !_generalize_trigger;
E.flex_add k_bool_triggers_only !_bool_triggers_only;
ET.setup ()
in
{ Extensions.default with
Extensions.name = "bool";
env_actions=[register];
}
let () =
Options.add_opts
[ "--boolean-reasoning", Arg.Symbol (["off"; "simpl-only"; "bool-hoist"; "cases-preprocess"],
(fun s ->
_bool_reasoning :=
(match s with
| "off" -> BoolReasoningDisabled
| "simpl-only" -> BoolSimplificationsOnly
| "bool-hoist" -> BoolHoist
| "cases-preprocess" -> BoolCasesPreprocess
| _ -> assert false);
if !_bool_reasoning == BoolHoist then (
Params.bool_select := "smallest";
);)),
" enable/disable boolean axioms";
"--quantifier-renaming"
, Arg.Bool (fun v -> _quant_rename := v)
, " turn the quantifier renaming on or off";
"--replace-quants"
, Arg.Bool (fun v -> _replace_quants := v)
, " replace unsupported quantifiers";
"--replace-bool-app-vars"
, Arg.Bool (fun v -> _bool_app_var_repl := v)
, " unify applied variables with combinations of T and F";
"--rename-nested-bools"
, Arg.Bool (fun v -> _rename_nested_bools := v)
, " rename deeply nested bool subterms";
"--trigger-bool-ind", Arg.Set_int _trigger_bool_ind
, " abstract away constants from the goal and use them to trigger axioms of induction";
"--trigger-bool-inst", Arg.Set_int _trigger_bool_inst
, " instantiate predicate variables with boolean terms already in the proof state. Argument is the maximal proof depth of predicate variable";
"--trigger-bool-inst-prop-only", Arg.Bool ((:=) _bool_triggers_only)
, " make sure that lambdas are REALLY only of Boolean type";
"--trigger-bool-include-quants", Arg.Bool ((:=) _include_quants)
, " include lambdas directly under a quant in consdieration";
"--trigger-bool-generalize", Arg.Symbol (["off"; "neg"; "var" ], (fun s ->
_generalize_trigger := (match s with
| "off" -> `Off
| "neg" -> `Neg
| "var" -> `Var
| _ -> invalid_arg "off, neg or var are the only options")
)), " generalize the trigger: neg adds the negation before the trigger body, " ^
" and var applies the body to a fresh variable";
"--disable-simplifying-cnf",
Arg.Set _cnf_non_simpl,
" implement cnf on-the-fly as an inference rule";
"--interpret-bool-funs"
, Arg.Bool (fun v -> _interpret_bool_funs := v)
, " turn interpretation of boolean functions as forall or negation of forall on or off";
"--bool-hoist-simpl"
, Arg.Bool (fun v -> _bool_hoist_simpl := v; _rename_nested_bools := true)
, " use BoolHoistSimpl instead of BoolHoist; NOTE: Setting this option triggers nested booleans renaming";
"--normalize-bool-terms", Arg.Bool((fun v -> _norm_bools := v)),
" normalize boolean subterms using their weight.";
"--nnf-nested-formulas"
, Arg.Bool (fun v -> _nnf := v)
, " convert nested formulas into negation normal form";
"--simplify-bools"
, Arg.Bool (fun v -> _simplify_bools := v)
, " simplify boolean subterms";
"--fluid-hoist"
, Arg.Bool (fun v -> _fluid_hoist := v)
, " enable/disable Fluid(Bool|Loob)Hoist rules";
"--fluid-log-hoist"
, Arg.Bool (fun v -> _fluid_log_hoist := v)
, " enable/disable fluid version of BoolRW, (Forall|Exists)RW, (Eq|Neq|Forall|Exists)Hoist rules";
"--solve-formulas"
, Arg.Bool (fun v -> _solve_formulas := v)
, " solve phi = psi eagerly by unifying phi != ~psi, where phi and psi are formulas";
"--boolean-reasoning-filter-literals"
, Arg.Symbol(["all"; "max"], (fun v ->
match v with
| "all" -> _filter_literals:=`All
| "max" -> _filter_literals:= `Max
| _ -> assert false;))
, " select on which literals to apply bool reasoning rules"
];
Params.add_to_modes ["ho-pragmatic";
"lambda-free-intensional";
"lambda-free-purify-intensional";
"lambda-free-extensional";
"ho-comb-complete";
"lambda-free-purify-extensional";
"fo-complete-basic"] (fun () ->
_bool_reasoning := BoolReasoningDisabled
);
Params.add_to_mode "ho-complete-basic" (fun () ->
_bool_reasoning := BoolHoist;
_fluid_hoist := true;
_bool_app_var_repl := true;
_fluid_log_hoist := true;
_replace_quants := true);
Params.add_to_modes ["ho-pragmatic";
"lambda-free-intensional";
"lambda-free-purify-intensional";
"lambda-free-extensional";
"ho-comb-complete";
"ho-competititve";
"lambda-free-purify-extensional";
"fo-complete-basic"] (fun () ->
_replace_quants := false;
);
Params.add_to_modes ["lambda-free-intensional";
"lambda-free-purify-intensional";
"lambda-free-extensional";
"ho-comb-complete";
"lambda-free-purify-extensional"] (fun () ->
_disable_ho_unif := true
);
Extensions.register extension