Source file equality.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
module CVars = Vars
open Pp
open CErrors
open Util
open Names
open Nameops
open Term
open Constr
open Context
open Termops
open EConstr
open Vars
open Namegen
open Inductive
open Inductiveops
open Libnames
open Globnames
open Reductionops
open Typing
open Retyping
open Tacmach
open Logic
open Hipattern
open Tacticals
open Tactics
open Tacred
open Coqlib
open Declarations
open Indrec
open Ind_tables
open Eqschemes
open Locus
open Locusops
open Tactypes
open Proofview.Notations
open Unification
open Context.Named.Declaration
module NamedDecl = Context.Named.Declaration
type inj_flags = {
keep_proof_equalities : bool;
injection_pattern_l2r_order : bool;
}
open Goptions
let use_injection_pattern_l2r_order = function
| None -> true
| Some flags -> flags.injection_pattern_l2r_order
let { Goptions.get = injection_in_context_flag } =
declare_bool_option_and_ref
~key:["Structural";"Injection"]
~value:false
()
type dep_proof_flag = bool
type freeze_evars_flag = bool
type orientation = bool
type conditions =
| Naive
| FirstSolved
| AllMatches
let rewrite_core_unif_flags = {
modulo_conv_on_closed_terms = None;
use_metas_eagerly_in_conv_on_closed_terms = true;
use_evars_eagerly_in_conv_on_closed_terms = false;
modulo_delta = TransparentState.empty;
modulo_delta_types = TransparentState.empty;
check_applied_meta_types = true;
use_pattern_unification = true;
use_meta_bound_pattern_unification = true;
allowed_evars = Evarsolve.AllowedEvars.all;
restrict_conv_on_strict_subterms = false;
modulo_betaiota = false;
modulo_eta = true;
}
let rewrite_unif_flags = {
core_unify_flags = rewrite_core_unif_flags;
merge_unify_flags = rewrite_core_unif_flags;
subterm_unify_flags = rewrite_core_unif_flags;
allow_K_in_toplevel_higher_order_unification = false;
resolve_evars = true
}
let freeze_initial_evars sigma flags newevars =
let initial = Evd.undefined_map sigma in
let allowed evk =
if Evar.Map.mem evk initial then false
else Evar.Set.mem evk (Lazy.force newevars)
in
let allowed_evars = Evarsolve.AllowedEvars.from_pred allowed in
{flags with
core_unify_flags = {flags.core_unify_flags with allowed_evars};
merge_unify_flags = {flags.merge_unify_flags with allowed_evars};
subterm_unify_flags = {flags.subterm_unify_flags with allowed_evars}}
let make_flags frzevars sigma flags newevars =
if frzevars then freeze_initial_evars sigma flags newevars else flags
let side_tac tac sidetac =
match sidetac with
| None -> tac
| Some sidetac -> tclTHENSFIRSTn tac [|Proofview.tclUNIT ()|] sidetac
let instantiate_lemma_all env flags eqclause l2r concl =
let (_, args) = decompose_app (Clenv.clenv_evd eqclause) (Clenv.clenv_type eqclause) in
let arglen = Array.length args in
let () = if arglen < 2 then user_err Pp.(str "The term provided is not an applied relation.") in
let c1 = args.(arglen - 2) in
let c2 = args.(arglen - 1) in
w_unify_to_subterm_all ~flags env (Clenv.clenv_evd eqclause)
((if l2r then c1 else c2),concl)
let rewrite_conv_closed_core_unif_flags = {
modulo_conv_on_closed_terms = Some TransparentState.full;
use_metas_eagerly_in_conv_on_closed_terms = true;
use_evars_eagerly_in_conv_on_closed_terms = false;
modulo_delta = TransparentState.empty;
modulo_delta_types = TransparentState.full;
check_applied_meta_types = true;
use_pattern_unification = true;
use_meta_bound_pattern_unification = true;
allowed_evars = Evarsolve.AllowedEvars.all;
restrict_conv_on_strict_subterms = false;
modulo_betaiota = false;
modulo_eta = true;
}
let rewrite_conv_closed_unif_flags = {
core_unify_flags = rewrite_conv_closed_core_unif_flags;
merge_unify_flags = rewrite_conv_closed_core_unif_flags;
subterm_unify_flags = rewrite_conv_closed_core_unif_flags;
allow_K_in_toplevel_higher_order_unification = false;
resolve_evars = false
}
let rewrite_keyed_core_unif_flags = {
modulo_conv_on_closed_terms = Some TransparentState.full;
use_metas_eagerly_in_conv_on_closed_terms = true;
use_evars_eagerly_in_conv_on_closed_terms = false;
modulo_delta = TransparentState.full;
modulo_delta_types = TransparentState.full;
check_applied_meta_types = true;
use_pattern_unification = true;
use_meta_bound_pattern_unification = true;
allowed_evars = Evarsolve.AllowedEvars.all;
restrict_conv_on_strict_subterms = false;
modulo_betaiota = true;
modulo_eta = true;
}
let rewrite_keyed_unif_flags = {
core_unify_flags = rewrite_keyed_core_unif_flags;
merge_unify_flags = rewrite_keyed_core_unif_flags;
subterm_unify_flags = rewrite_keyed_core_unif_flags;
allow_K_in_toplevel_higher_order_unification = false;
resolve_evars = false
}
let tclNOTSAMEGOAL tac =
let goal gl = Proofview.Goal.goal gl in
Proofview.Goal.enter begin fun gl ->
let sigma = project gl in
let ev = goal gl in
tac >>= fun () ->
Proofview.Goal.goals >>= fun gls ->
let check accu gl' =
gl' >>= fun gl' ->
let accu = accu || Proofview.Progress.goal_equal
~evd:sigma ~extended_evd:(project gl') ev (goal gl')
in
Proofview.tclUNIT accu
in
Proofview.Monad.List.fold_left check false gls >>= fun has_same ->
if has_same then
tclZEROMSG (str"Tactic generated a subgoal identical to the original goal.")
else
Proofview.tclUNIT ()
end
let elim_wrapper cls rwtac =
let open Pretype_errors in
Proofview.tclORELSE
begin match cls with
| None ->
tclNOTSAMEGOAL rwtac
| Some _ -> rwtac
end
begin function (e, info) -> match e with
| PretypeError (env, evd, NoOccurrenceFound (c', _)) ->
Proofview.tclZERO ~info (PretypeError (env, evd, NoOccurrenceFound (c', cls)))
| e ->
Proofview.tclZERO ~info e
end
let general_elim_clause with_evars frzevars tac cls c (ctx, eqn, args) l l2r elim =
let general_elim_clause0 rew =
let rewrite_elim =
Proofview.Goal.enter begin fun gl ->
let sigma = Proofview.Goal.sigma gl in
let flags = if Unification.is_keyed_unification ()
then rewrite_keyed_unif_flags else rewrite_conv_closed_unif_flags in
let newevars = lazy (Evarutil.undefined_evars_of_term sigma (Clenv.clenv_type rew)) in
let flags = make_flags frzevars sigma flags newevars in
let metas = Evd.meta_list (Clenv.clenv_evd rew) in
let submetas = List.map (fun mv -> mv, Evd.Metamap.find mv metas) (Clenv.clenv_arguments rew) in
general_elim_clause with_evars flags cls (submetas, c, Clenv.clenv_type rew) elim
end
in
Proofview.Unsafe.tclEVARS (Evd.clear_metas (Clenv.clenv_evd rew)) <*>
elim_wrapper cls rewrite_elim
in
let strat, tac =
match tac with
| None -> Naive, None
| Some (tac, Naive) -> Naive, Some tac
| Some (tac, FirstSolved) -> FirstSolved, Some (tclCOMPLETE tac)
| Some (tac, AllMatches) -> AllMatches, Some (tclCOMPLETE tac)
in
Proofview.Goal.enter begin fun gl ->
let env = Proofview.Goal.env gl in
let sigma = Proofview.Goal.sigma gl in
let typ = match cls with
| None -> pf_concl gl
| Some id -> pf_get_hyp_typ id gl
in
let ty = it_mkProd_or_LetIn (applist (eqn, args)) ctx in
let eqclause = Clenv.make_clenv_binding env sigma (c, ty) l in
let try_clause evd' =
let clenv = Clenv.update_clenv_evd eqclause evd' in
let clenv = Clenv.clenv_pose_dependent_evars ~with_evars:true clenv in
side_tac (general_elim_clause0 clenv) tac
in
match strat with
| Naive ->
side_tac (general_elim_clause0 eqclause) tac
| FirstSolved ->
let flags = make_flags frzevars sigma rewrite_unif_flags (lazy Evar.Set.empty) in
let cs = instantiate_lemma_all env flags eqclause l2r typ in
tclFIRST (List.map try_clause cs)
| AllMatches ->
let flags = make_flags frzevars sigma rewrite_unif_flags (lazy Evar.Set.empty) in
let cs = instantiate_lemma_all env flags eqclause l2r typ in
tclMAP try_clause cs
end
let (forward_general_setoid_rewrite_clause, general_setoid_rewrite_clause) = Hook.make ()
let jmeq_same_dom env sigma (rels, eq, args) =
let env = push_rel_context rels env in
match args with
| [dom1; _; dom2;_] -> is_conv env sigma dom1 dom2
| _ -> false
let eq_elimination_ref l2r sort =
let name =
if l2r then
match sort with
| InProp -> "core.eq.ind_r"
| InSProp -> "core.eq.sind_r"
| InSet | InType | InQSort -> "core.eq.rect_r"
else
match sort with
| InProp -> "core.eq.ind"
| InSProp -> "core.eq.sind"
| InSet | InType | InQSort -> "core.eq.rect"
in
Coqlib.lib_ref_opt name
let find_elim lft2rgt dep cls ((_, hdcncl, _) as t) =
Proofview.Goal.enter_one begin fun gl ->
let env = Proofview.Goal.env gl in
let sigma = project gl in
let is_global_exists gr c = match Coqlib.lib_ref_opt gr with
| Some gr -> isRefX env sigma gr c
| None -> false
in
let inccl = Option.is_empty cls in
let is_eq = is_global_exists "core.eq.type" hdcncl in
let is_jmeq = is_global_exists "core.JMeq.type" hdcncl && jmeq_same_dom env sigma t in
if (is_eq || is_jmeq) && not dep
then
let sort = elimination_sort_of_clause cls gl in
let c =
match EConstr.kind sigma hdcncl with
| Ind (ind_sp,u) ->
begin match lft2rgt, cls with
| Some true, None
| Some false, Some _ ->
begin match if is_eq then eq_elimination_ref true sort else None with
| Some r -> destConstRef r
| None ->
let c1 = destConstRef (lookup_eliminator env ind_sp sort) in
let mp,l = KerName.repr (Constant.canonical c1) in
let l' = Label.of_id (add_suffix (Label.to_id l) "_r") in
let c1' = Global.constant_of_delta_kn (KerName.make mp l') in
if not (Environ.mem_constant c1' (Global.env ())) then
user_err
(str "Cannot find rewrite principle " ++ Label.print l' ++ str ".");
c1'
end
| _ ->
begin match if is_eq then eq_elimination_ref false sort else None with
| Some r -> destConstRef r
| None -> destConstRef (lookup_eliminator env ind_sp sort)
end
end
| _ ->
assert false
in
Proofview.tclUNIT c
else
let scheme_name = match dep, lft2rgt, inccl with
| false, Some true, true -> rew_l2r_scheme_kind
| false, Some true, false -> rew_r2l_scheme_kind
| false, _, false -> rew_l2r_scheme_kind
| false, _, true -> rew_r2l_scheme_kind
| true, Some true, true -> rew_l2r_dep_scheme_kind
| true, Some true, false -> rew_l2r_forward_dep_scheme_kind
| true, _, true -> rew_r2l_dep_scheme_kind
| true, _, false -> rew_r2l_forward_dep_scheme_kind
in
match EConstr.kind sigma hdcncl with
| Ind (ind,u) -> find_scheme scheme_name ind
| _ -> assert false
end
let type_of_clause cls gl = match cls with
| None -> Proofview.Goal.concl gl
| Some id -> pf_get_hyp_typ id gl
let leibniz_rewrite_ebindings_clause cls lft2rgt tac c ((_, hdcncl, _) as t) l with_evars frzevars dep_proof_ok =
Proofview.Goal.enter begin fun gl ->
let evd = Proofview.Goal.sigma gl in
let type_of_cls = type_of_clause cls gl in
let dep = dep_proof_ok && dependent_no_evar evd c type_of_cls in
find_elim lft2rgt dep cls t >>= fun elim ->
general_elim_clause with_evars frzevars tac cls c t l
(match lft2rgt with None -> false | Some b -> b) elim
end
let adjust_rewriting_direction args lft2rgt =
match args with
| [_] ->
if not lft2rgt then
user_err Pp.(str "Rewriting non-symmetric equality not allowed from right-to-left.");
None
| _ ->
Some lft2rgt
let rewrite_side_tac tac sidetac = side_tac tac (Option.map fst sidetac)
let general_rewrite ~where:cls ~l2r:lft2rgt occs ~freeze:frzevars ~dep:dep_proof_ok ~with_evars ?tac
((c,l) : constr with_bindings) =
if not (Locusops.is_all_occurrences occs) then (
rewrite_side_tac (Hook.get forward_general_setoid_rewrite_clause cls lft2rgt occs (c,l) ~new_goals:[]) tac)
else
Proofview.Goal.enter begin fun gl ->
let sigma = Tacmach.project gl in
let env = Proofview.Goal.env gl in
let ctype = get_type_of env sigma c in
let rels, t = decompose_prod_decls sigma (whd_betaiotazeta env sigma ctype) in
match match_with_equality_type env sigma t with
| Some (hdcncl,args) ->
let lft2rgt = adjust_rewriting_direction args lft2rgt in
leibniz_rewrite_ebindings_clause cls lft2rgt tac c (rels, hdcncl, args)
l with_evars frzevars dep_proof_ok
| None ->
Proofview.tclORELSE
begin
rewrite_side_tac (Hook.get forward_general_setoid_rewrite_clause cls
lft2rgt occs (c,l) ~new_goals:[]) tac
end
begin function
| (e, info) ->
Proofview.tclEVARMAP >>= fun sigma ->
let env' = push_rel_context rels env in
let rels',t' = whd_decompose_prod_decls env' sigma t in
match match_with_equality_type env' sigma t' with
| Some (hdcncl,args) ->
let lft2rgt = adjust_rewriting_direction args lft2rgt in
leibniz_rewrite_ebindings_clause cls lft2rgt tac c
(rels' @ rels, hdcncl, args) l with_evars frzevars dep_proof_ok
| None -> Proofview.tclZERO ~info e
end
end
let clear_for_rewrite_in_hyps ids c =
let ids = Id.Set.of_list ids in
Proofview.Goal.enter begin fun gl ->
let env = Proofview.Goal.env gl in
let sigma = Proofview.Goal.sigma gl in
let err = (Evarutil.OccurHypInSimpleClause None) in
let sigma =
try Evarutil.check_and_clear_in_constr env sigma err ids c
with Evarutil.ClearDependencyError (id,err,inglobal) ->
CErrors.user_err Pp.(str "Cannot rewrite due to dependency on " ++ Id.print id ++ str ".")
in
Proofview.Unsafe.tclEVARS sigma
end
let general_rewrite_clause l2r with_evars ?tac c cl =
let occs_of = occurrences_map (List.fold_left
(fun acc ->
function ArgArg x -> x :: acc | ArgVar _ -> acc)
[])
in
match cl.onhyps with
| Some l ->
let rec do_hyps = function
| [] -> Proofview.tclUNIT ()
| ((occs,id),_) :: l ->
tclTHENFIRST
(general_rewrite ~where:(Some id) ~l2r (occs_of occs) ~freeze:false ~dep:true ~with_evars ?tac c)
(do_hyps l)
in
let tac =
if cl.concl_occs == NoOccurrences then do_hyps l
else
tclTHENFIRST
(general_rewrite ~where:None ~l2r (occs_of cl.concl_occs) ~freeze:false ~dep:true ~with_evars ?tac c)
(do_hyps l)
in
begin match l with
| [] | [_] ->
tac
| _ ->
tclTHEN (clear_for_rewrite_in_hyps (List.map (fun ((_,id),_) -> id) l) (fst c)) tac
end
| None ->
let rec do_hyps_atleastonce = function
| [] -> tclZEROMSG (Pp.str"Nothing to rewrite.")
| id :: l ->
tclIFTHENFIRSTTRYELSEMUST
(tclTHEN (clear_for_rewrite_in_hyps [id] (fst c))
(general_rewrite ~where:(Some id) ~l2r AllOccurrences ~freeze:false ~dep:true ~with_evars ?tac c))
(do_hyps_atleastonce l)
in
let do_hyps =
Proofview.Goal.enter begin fun gl ->
do_hyps_atleastonce (pf_ids_of_hyps gl)
end
in
if cl.concl_occs == NoOccurrences then do_hyps else
tclIFTHENFIRSTTRYELSEMUST
(general_rewrite ~where:None ~l2r (occs_of cl.concl_occs) ~freeze:false ~dep:true ~with_evars ?tac c)
do_hyps
let apply_special_clear_request clear_flag f =
Proofview.Goal.enter begin fun gl ->
let sigma = Tacmach.project gl in
let env = Proofview.Goal.env gl in
try
let (sigma, (c, bl)) = f env sigma in
let c = try Some (destVar sigma c) with DestKO -> None in
apply_clear_request clear_flag (use_clear_hyp_by_default ()) c
with
e when noncritical e -> tclIDTAC
end
type multi =
| Precisely of int
| UpTo of int
| RepeatStar
| RepeatPlus
let general_multi_rewrite with_evars l cl tac =
let do1 l2r f =
Proofview.Goal.enter begin fun gl ->
let sigma = Tacmach.project gl in
let env = Proofview.Goal.env gl in
let (sigma, c) = f env sigma in
tclWITHHOLES with_evars
(general_rewrite_clause l2r with_evars ?tac c cl) sigma
end
in
let rec doN l2r c = function
| Precisely n when n <= 0 -> Proofview.tclUNIT ()
| Precisely 1 -> do1 l2r c
| Precisely n -> tclTHENFIRST (do1 l2r c) (doN l2r c (Precisely (n-1)))
| RepeatStar -> tclREPEAT_MAIN (do1 l2r c)
| RepeatPlus -> tclTHENFIRST (do1 l2r c) (doN l2r c RepeatStar)
| UpTo n when n<=0 -> Proofview.tclUNIT ()
| UpTo n -> tclTHENFIRST (tclTRY (do1 l2r c)) (doN l2r c (UpTo (n-1)))
in
let rec loop = function
| [] -> Proofview.tclUNIT ()
| (l2r,m,clear_flag,c)::l ->
tclTHENFIRST
(tclTHEN (doN l2r c m) (apply_special_clear_request clear_flag c)) (loop l)
in loop l
let rewriteLR c =
general_rewrite ~where:None ~l2r:true AllOccurrences ~freeze:true ~dep:true ~with_evars:false (c, NoBindings)
let rewriteRL c =
general_rewrite ~where:None ~l2r:false AllOccurrences ~freeze:true ~dep:true ~with_evars:false (c, NoBindings)
let classes_dirpath =
DirPath.make (List.map Id.of_string ["Classes";"Coq"])
let init_setoid () =
if is_dirpath_prefix_of classes_dirpath (Lib.cwd ()) then ()
else check_required_library ["Coq";"Setoids";"Setoid"]
let check_setoid cl =
let concloccs = Locusops.occurrences_map (fun x -> x) cl.concl_occs in
Option.fold_left
(List.fold_left
(fun b ((occ,_),_) ->
b||(not (Locusops.is_all_occurrences (Locusops.occurrences_map (fun x -> x) occ)))
)
)
(not (Locusops.is_all_occurrences concloccs) &&
(concloccs <> NoOccurrences))
cl.onhyps
let replace_core clause l2r eq =
if check_setoid clause
then init_setoid ();
tclTHENFIRST
(assert_after Anonymous eq)
(onLastHypId (fun id ->
tclTHEN
(tclTRY (general_rewrite_clause l2r false (mkVar id,NoBindings) clause))
(clear [id])))
let replace_using_leibniz clause c1 c2 l2r unsafe try_prove_eq_opt =
Proofview.Goal.enter begin fun gl ->
let get_type_of = pf_apply get_type_of gl in
let t1 = get_type_of c1
and t2 = get_type_of c2 in
let evd =
if unsafe then Some (Tacmach.project gl)
else
try Some (Evarconv.unify_delay (Proofview.Goal.env gl) (Tacmach.project gl) t1 t2)
with Evarconv.UnableToUnify _ -> None
in
match evd with
| None ->
tclFAIL (str"Terms do not have convertible types")
| Some evd ->
let e,sym =
try lib_ref "core.eq.type", lib_ref "core.eq.sym"
with NotFoundRef _ ->
try lib_ref "core.identity.type", lib_ref "core.identity.sym"
with NotFoundRef _ ->
user_err (strbrk "Need a registration for either core.eq.type and core.eq.sym or core.identity.type and core.identity.sym.") in
Tacticals.pf_constr_of_global sym >>= fun sym ->
Tacticals.pf_constr_of_global e >>= fun e ->
let eq = applist (e, [t1;c1;c2]) in
let solve_tac = match try_prove_eq_opt with
| None ->
tclFIRST
[ assumption;
tclTHEN (apply sym) assumption;
Proofview.tclUNIT () ]
| Some tac -> tclCOMPLETE tac
in
tclTHENLAST
(replace_core clause l2r eq)
solve_tac
end
let replace c1 c2 =
replace_using_leibniz onConcl c2 c1 false false None
let replace_by c1 c2 tac =
replace_using_leibniz onConcl c2 c1 false false (Some tac)
let replace_in_clause_maybe_by c1 c2 cl tac_opt =
replace_using_leibniz cl c2 c1 false false tac_opt
exception DiscrFound of
(constructor * int) list * constructor * constructor
let keep_proof_equalities_for_injection = ref false
let () =
declare_bool_option
{ optstage = Summary.Stage.Interp;
optdepr = None;
optkey = ["Keep";"Proof";"Equalities"];
optread = (fun () -> !keep_proof_equalities_for_injection) ;
optwrite = (fun b -> keep_proof_equalities_for_injection := b) }
let keep_proof_equalities = function
| None -> !keep_proof_equalities_for_injection
| Some flags -> flags.keep_proof_equalities
module KeepEqualities =
struct
type t = inductive
module Set = Indset_env
let encode _env r = Nametab.global_inductive r
let subst subst obj = Mod_subst.subst_ind subst obj
let printer ind = Nametab.pr_global_env Id.Set.empty (GlobRef.IndRef ind)
let key = ["Keep"; "Equalities"]
let title = "Prop-valued inductive types for which injection keeps equality proofs"
let member_message ind b =
let b = if b then mt () else str "not " in
str "Equality proofs over " ++ (printer ind) ++
str " are " ++ b ++ str "kept by injection"
end
module KeepEqualitiesTable = Goptions.MakeRefTable(KeepEqualities)
let set_keep_equality = KeepEqualitiesTable.set
let keep_head_inductive sigma c =
let _, hd = EConstr.decompose_prod sigma c in
let hd, _ = EConstr.decompose_app sigma hd in
match EConstr.kind sigma hd with
| Ind (ind, _) -> KeepEqualitiesTable.active ind
| _ -> false
let find_positions env sigma ~keep_proofs ~no_discr t1 t2 =
let project env sorts posn t1 t2 =
let ty1 = get_type_of env sigma t1 in
let keep =
if keep_head_inductive sigma ty1 then true
else
let s = get_sort_family_of env sigma ty1 in
List.mem_f Sorts.family_equal s sorts
in
if keep then [(List.rev posn,t1,t2)] else []
in
let rec findrec sorts posn t1 t2 =
let hd1,args1 = whd_all_stack env sigma t1 in
let hd2,args2 = whd_all_stack env sigma t2 in
match (EConstr.kind sigma hd1, EConstr.kind sigma hd2) with
| Construct ((ind1,i1 as sp1),u1), Construct (sp2,_)
when Int.equal (List.length args1) (constructor_nallargs env sp1)
->
let sorts' =
CList.intersect Sorts.family_equal sorts (sorts_below (top_allowed_sort env (fst sp1)))
in
if Environ.QConstruct.equal env sp1 sp2 then
let nparams = inductive_nparams env ind1 in
let params1,rargs1 = List.chop nparams args1 in
let _,rargs2 = List.chop nparams args2 in
let (mib,mip) = lookup_mind_specif env ind1 in
let params1 = List.map EConstr.Unsafe.to_constr params1 in
let u1 = EInstance.kind sigma u1 in
let ctxt = (get_constructor ((ind1,u1),mib,mip,params1) i1).cs_args in
let adjust i = CVars.adjust_rel_to_rel_context ctxt (i+1) - 1 in
List.flatten
(List.map2_i (fun i -> findrec sorts' ((sp1,adjust i)::posn))
0 rargs1 rargs2)
else if List.mem_f Sorts.family_equal InType sorts' && not no_discr
then
raise (DiscrFound (List.rev posn,sp1,sp2))
else
project env sorts posn (applist (hd1,args1)) (applist (hd2,args2))
| _ ->
let t1_0 = applist (hd1,args1)
and t2_0 = applist (hd2,args2) in
if is_conv env sigma t1_0 t2_0 then
[]
else
project env sorts posn t1_0 t2_0
in
try
let sorts = if keep_proofs then [InSet;InType;InProp] else [InSet;InType] in
Inr (findrec sorts [] t1 t2)
with DiscrFound (path,c1,c2) ->
Inl (path,c1,c2)
let use_keep_proofs = function
| None -> !keep_proof_equalities_for_injection
| Some b -> b
let descend_then env sigma head dirn =
let IndType (indf,_) as indt =
try find_rectype env sigma (get_type_of env sigma head)
with Not_found ->
user_err Pp.(str "Cannot project on an inductive type derived from a dependency.")
in
let (ind, _),_ = (dest_ind_family indf) in
let () = check_privacy env ind in
let (mib,mip) = lookup_mind_specif env ind in
let cstr = get_constructors env indf in
let dirn_nlams = cstr.(dirn-1).cs_nargs in
let dirn_env = Environ.push_rel_context cstr.(dirn-1).cs_args env in
(dirn_nlams,
dirn_env,
(fun sigma dirnval (dfltval,resty) ->
let deparsign = make_arity_signature env sigma true indf in
let p =
it_mkLambda_or_LetIn (lift (mip.mind_nrealargs+1) resty) deparsign in
let build_branch i =
let result = if Int.equal i dirn then dirnval else dfltval in
let cs_args = List.map (fun d -> map_rel_decl EConstr.of_constr d) cstr.(i-1).cs_args in
let args = name_context env sigma cs_args in
it_mkLambda_or_LetIn result args in
let brl =
List.map build_branch
(List.interval 1 (Array.length mip.mind_consnames)) in
let rci = Sorts.Relevant in
let ci = make_case_info env ind RegularStyle in
Inductiveops.make_case_or_project env sigma indt ci (p, rci) head (Array.of_list brl)))
let build_selector env sigma dirn c ind special default =
let IndType(indf,_) as indt =
try find_rectype env sigma ind
with Not_found ->
user_err
(str "Cannot discriminate on inductive constructors with \
dependent types.") in
let (ind, _),_ = dest_ind_family indf in
let () = check_privacy env ind in
let typ = Retyping.get_type_of env sigma default in
let (mib,mip) = lookup_mind_specif env ind in
let deparsign = make_arity_signature env sigma true indf in
let p = it_mkLambda_or_LetIn typ deparsign in
let cstrs = get_constructors env indf in
let build_branch i =
let endpt = if Int.equal i dirn then special else default in
let args = List.map (fun d -> map_rel_decl EConstr.of_constr d) cstrs.(i-1).cs_args in
it_mkLambda_or_LetIn endpt args in
let brl =
List.map build_branch(List.interval 1 (Array.length mip.mind_consnames)) in
let rci = Sorts.Relevant in
let ci = make_case_info env ind RegularStyle in
let ans = Inductiveops.make_case_or_project env sigma indt ci (p, rci) c (Array.of_list brl) in
ans
let build_coq_False () = pf_constr_of_global (lib_ref "core.False.type")
let build_coq_True () = pf_constr_of_global (lib_ref "core.True.type")
let build_coq_I () = pf_constr_of_global (lib_ref "core.True.I")
let rec build_discriminator env sigma true_0 false_0 dirn c = function
| [] ->
let ind = get_type_of env sigma c in
build_selector env sigma dirn c ind true_0 (fst false_0)
| ((sp,cnum),argnum)::l ->
let (cnum_nlams,cnum_env,kont) = descend_then env sigma c cnum in
let newc = mkRel(cnum_nlams-argnum) in
let subval = build_discriminator cnum_env sigma true_0 false_0 dirn newc l in
kont sigma subval false_0
let gen_absurdity id =
Proofview.Goal.enter begin fun gl ->
let env = pf_env gl in
let sigma = project gl in
let hyp_typ = pf_get_hyp_typ id gl in
if is_empty_type env sigma hyp_typ
then
simplest_elim (mkVar id)
else
tclZEROMSG (str "Not the negation of an equality.")
end
let ind_scheme_of_eq lbeq to_kind =
Proofview.tclENV >>= fun env ->
let (mib,mip) = Inductive.lookup_mind_specif env (destIndRef lbeq.eq) in
let from_kind = inductive_sort_family mip in
let kind = Elimschemes.nondep_elim_scheme from_kind to_kind in
find_scheme kind (destIndRef lbeq.eq) >>= fun c ->
Proofview.tclUNIT (GlobRef.ConstRef c)
let discrimination_pf e (t,t1,t2) discriminator lbeq to_kind =
build_coq_I () >>= fun i ->
ind_scheme_of_eq lbeq to_kind >>= fun eq_elim ->
pf_constr_of_global eq_elim >>= fun eq_elim ->
Proofview.tclEVARMAP >>= fun sigma ->
Proofview.tclUNIT
(applist (eq_elim, [t;t1;mkNamedLambda sigma (make_annot e Sorts.Relevant) t discriminator;i;t2]))
type equality = {
eq_data : (coq_eq_data * (EConstr.t * EConstr.t * EConstr.t));
eq_term : EConstr.t;
eq_evar : Proofview_monad.goal_with_state list;
}
let eq_baseid = Id.of_string "e"
let discr_positions env sigma { eq_data = (lbeq,(t,t1,t2)); eq_term = v; eq_evar = evs } cpath dirn =
build_coq_True () >>= fun true_0 ->
build_coq_False () >>= fun false_0 ->
let false_ty = Retyping.get_type_of env sigma false_0 in
let false_kind = Retyping.get_sort_family_of env sigma false_0 in
let e = next_ident_away eq_baseid (vars_of_env env) in
let e_env = push_named (Context.Named.Declaration.LocalAssum (make_annot e Sorts.Relevant,t)) env in
let discriminator =
try
Proofview.tclUNIT
(build_discriminator e_env sigma true_0 (false_0,false_ty) dirn (mkVar e) cpath)
with
UserError _ as ex ->
let _, info = Exninfo.capture ex in
Proofview.tclZERO ~info ex
in
discriminator >>= fun discriminator ->
discrimination_pf e (t,t1,t2) discriminator lbeq false_kind >>= fun pf ->
let pf = EConstr.mkApp (pf, [|v|]) in
tclTHENS (assert_after Anonymous false_0)
[onLastHypId gen_absurdity; Tactics.exact_check pf <*> Proofview.Unsafe.tclNEWGOALS evs]
let discrEq eq =
let { eq_data = (_, (_, t1, t2)) } = eq in
Proofview.Goal.enter begin fun gl ->
let env = Proofview.Goal.env gl in
let sigma = Proofview.Goal.sigma gl in
match find_positions env sigma ~keep_proofs:false ~no_discr:false t1 t2 with
| Inr _ ->
let info = Exninfo.reify () in
tclZEROMSG ~info (str"Not a discriminable equality.")
| Inl (cpath, (_,dirn), _) ->
discr_positions env sigma eq cpath dirn
end
let onEquality with_evars tac (c,lbindc) =
Proofview.Goal.enter begin fun gl ->
let env = Proofview.Goal.env gl in
let sigma = Proofview.Goal.sigma gl in
let state = Proofview.Goal.state gl in
let t = Retyping.get_type_of env sigma c in
let t' = try snd (Tacred.reduce_to_quantified_ind env sigma t) with UserError _ -> t in
let sigma, eq_clause = EClause.make_evar_clause env sigma t' in
let sigma = EClause.solve_evar_clause env sigma false eq_clause lbindc in
if not with_evars && List.exists (fun h -> h.EClause.hole_deps) eq_clause.EClause.cl_holes then
let filter h = if h.EClause.hole_deps then Some h.EClause.hole_name else None in
let bindings = List.map_filter filter eq_clause.EClause.cl_holes in
Proofview.tclZERO (RefinerError (env, sigma, UnresolvedBindings bindings))
else
let filter h =
if h.EClause.hole_deps then None
else
try Some (Proofview_monad.goal_with_state (fst @@ destEvar sigma h.EClause.hole_evar) state)
with DestKO -> None
in
let goals = List.map_filter filter eq_clause.EClause.cl_holes in
let cl_args = Array.map_of_list (fun h -> h.EClause.hole_evar) eq_clause.EClause.cl_holes in
let (eq,u,eq_args) = find_this_eq_data_decompose env sigma eq_clause.cl_concl in
let eq = { eq_data = (eq, eq_args); eq_term = mkApp (c, cl_args); eq_evar = goals } in
Proofview.Unsafe.tclEVARS sigma <*> tac eq
end
let onNegatedEquality with_evars tac =
Proofview.Goal.enter begin fun gl ->
let sigma = Tacmach.project gl in
let ccl = Proofview.Goal.concl gl in
let env = Proofview.Goal.env gl in
match EConstr.kind sigma (hnf_constr0 env sigma ccl) with
| Prod (na,t,u) ->
let u = nf_betaiota (push_rel_assum (na, t) env) sigma u in
if is_empty_type env sigma u then
tclTHEN introf
(onLastHypId (fun id ->
onEquality with_evars tac (mkVar id,NoBindings)))
else tclZEROMSG (str "Not a negated primitive equality.")
| _ ->
let info = Exninfo.reify () in
tclZEROMSG ~info (str "Not a negated primitive equality.")
end
let discrSimpleClause with_evars = function
| None -> onNegatedEquality with_evars discrEq
| Some id -> onEquality with_evars discrEq (mkVar id,NoBindings)
let discr with_evars = onEquality with_evars discrEq
let discrClause with_evars = onClause (discrSimpleClause with_evars)
let discrEverywhere with_evars =
tclTHEN (Proofview.tclUNIT ())
(tclTHEN
(tclREPEAT introf)
(tryAllHyps
(fun id -> tclCOMPLETE (discr with_evars (mkVar id,NoBindings)))))
let discr_tac with_evars = function
| None -> discrEverywhere with_evars
| Some c -> onInductionArg (fun clear_flag -> discr with_evars) c
let discrConcl = discrClause false onConcl
let discrHyp id = discrClause false (onHyp id)
let find_sigma_data env s = build_sigma_type ()
let make_tuple env sigma (rterm,rty) lind =
assert (not (noccurn sigma lind rty));
let sigdata = find_sigma_data env (get_sort_of env sigma rty) in
let sigma, a = type_of ~refresh:true env sigma (mkRel lind) in
let a = simpl env sigma a in
let na = Context.Rel.Declaration.get_annot (lookup_rel lind env) in
let rty = lift (1-lind) (liftn lind (lind+1) rty) in
let p = mkLambda (na, a, rty) in
let sigma, exist_term = Evd.fresh_global env sigma sigdata.intro in
let sigma, sig_term = Evd.fresh_global env sigma sigdata.typ in
sigma,
(applist(exist_term,[a;p;(mkRel lind);rterm]),
applist(sig_term,[a;p]))
let minimal_free_rels env sigma (c,cty) =
let cty_rels = free_rels sigma cty in
let cty' = simpl env sigma cty in
let rels' = free_rels sigma cty' in
if Int.Set.subset cty_rels rels' then
(cty,cty_rels)
else
(cty',rels')
let minimal_free_rels_rec env sigma =
let rec minimalrec_free_rels_rec prev_rels (c,cty) =
let (cty,direct_rels) = minimal_free_rels env sigma (c,cty) in
let combined_rels = Int.Set.union prev_rels direct_rels in
let folder rels i = snd (minimalrec_free_rels_rec rels (c, get_type_of env sigma (mkRel i)))
in (cty, List.fold_left folder combined_rels (Int.Set.elements (Int.Set.diff direct_rels prev_rels)))
in minimalrec_free_rels_rec Int.Set.empty
let sig_clausal_form env sigma sort_of_ty siglen ty dflt =
let sigdata = find_sigma_data env sort_of_ty in
let rec sigrec_clausal_form sigma siglen p_i =
if Int.equal siglen 0 then
let dflt_typ = Retyping.get_type_of env sigma dflt in
try
let sigma = Evarconv.unify_leq_delay env sigma dflt_typ p_i in
let sigma = Evarconv.solve_unif_constraints_with_heuristics env sigma in
sigma, dflt
with Evarconv.UnableToUnify _ ->
user_err Pp.(str "Cannot solve a unification problem.")
else
let (a,p_i_minus_1) = match whd_beta_stack env sigma p_i with
| (_sigS,[a;p]) -> (a, p)
| _ -> anomaly ~label:"sig_clausal_form" (Pp.str "should be a sigma type.") in
let sigma, ev = Evarutil.new_evar env sigma a in
let rty = beta_applist sigma (p_i_minus_1,[ev]) in
let sigma, tuple_tail = sigrec_clausal_form sigma (siglen-1) rty in
if EConstr.isEvar sigma ev then
user_err Pp.(str "Cannot solve a unification problem.")
else
let sigma, exist_term = Evd.fresh_global env sigma sigdata.intro in
sigma, applist(exist_term,[a;p_i_minus_1;ev;tuple_tail])
in
let sigma, scf = sigrec_clausal_form sigma siglen ty in
sigma, Evarutil.nf_evar sigma scf
let make_iterated_tuple env sigma dflt (z,zty) =
let (zty,rels) = minimal_free_rels_rec env sigma (z,zty) in
let sort_of_zty = get_sort_of env sigma zty in
let sorted_rels = Int.Set.elements rels in
let sigma, (tuple,tuplety) =
List.fold_left (fun (sigma, t) -> make_tuple env sigma t) (sigma, (z,zty)) sorted_rels
in
assert (closed0 sigma tuplety);
let n = List.length sorted_rels in
let sigma, dfltval = sig_clausal_form env sigma sort_of_zty n tuplety dflt in
sigma, (tuple,tuplety,dfltval)
let rec build_injrec env sigma dflt c = function
| [] -> make_iterated_tuple env sigma dflt (c,get_type_of env sigma c)
| ((sp,cnum),argnum)::l ->
try
let (cnum_nlams,cnum_env,kont) = descend_then env sigma c cnum in
let newc = mkRel(cnum_nlams-argnum) in
let sigma, (subval,tuplety,dfltval) = build_injrec cnum_env sigma dflt newc l in
let res = kont sigma subval (dfltval,tuplety) in
sigma, (res, tuplety,dfltval)
with
UserError _ -> failwith "caught"
let build_injector env sigma dflt c cpath =
let sigma, (injcode,resty,_) = build_injrec env sigma dflt c cpath in
sigma, (injcode,resty)
let eq_dec_scheme_kind_name = ref (fun _ -> failwith "eq_dec_scheme undefined")
let set_eq_dec_scheme_kind k = eq_dec_scheme_kind_name := (fun _ -> k)
let warn_inject_no_eqdep_dec =
CWarnings.create ~name:"injection-missing-eqdep-dec" ~category:CWarnings.CoreCategories.tactics
Pp.(fun (env,ind) ->
str "The equality scheme for" ++ spc() ++ Printer.pr_inductive env ind ++ spc() ++
str "could not be used as Coq.Logic.Eqdep_dec has not been required.")
let inject_if_homogenous_dependent_pair ty =
Proofview.Goal.enter begin fun gl ->
try
let env = Proofview.Goal.env gl in
let sigma = Tacmach.project gl in
let eq,u,(t,t1,t2) = pf_apply find_this_eq_data_decompose gl ty in
let sigTconstr = Coqlib.(lib_ref "core.sigT.type") in
let existTconstr = Coqlib.lib_ref "core.sigT.intro" in
let eqTypeDest = fst (decompose_app sigma t) in
if not (isRefX env sigma sigTconstr eqTypeDest) then raise_notrace Exit;
let hd1,ar1 = decompose_app sigma t1 and
hd2,ar2 = decompose_app sigma t2 in
if not (isRefX env sigma existTconstr hd1) then raise_notrace Exit;
if not (isRefX env sigma existTconstr hd2) then raise_notrace Exit;
let (ind, _), _ = try pf_apply find_mrectype gl ar1.(0) with Not_found -> raise_notrace Exit in
if not (Option.has_some (Ind_tables.lookup_scheme (!eq_dec_scheme_kind_name()) ind) &&
pf_apply is_conv gl ar1.(2) ar2.(2)) then raise_notrace Exit;
let inj2 = match lib_ref_opt "core.eqdep_dec.inj_pair2" with
| None ->
warn_inject_no_eqdep_dec (env,ind);
raise_notrace Exit
| Some v -> v
in
let new_eq_args = [|pf_get_type_of gl ar1.(3);ar1.(3);ar2.(3)|] in
find_scheme (!eq_dec_scheme_kind_name()) ind >>= fun c ->
let c = if Global.is_polymorphic (ConstRef c)
then CErrors.anomaly Pp.(str "Unexpected univ poly in inject_if_homogenous_dependent_pair")
else UnsafeMonomorphic.mkConst c
in
tclTHENLIST
[
intro;
onLastHyp (fun hyp ->
Tacticals.pf_constr_of_global Coqlib.(lib_ref "core.eq.type") >>= fun ceq ->
tclTHENS (cut (mkApp (ceq,new_eq_args)))
[clear [destVar sigma hyp];
Tacticals.pf_constr_of_global inj2 >>= fun inj2 ->
Tactics.exact_check
(mkApp(inj2,[|ar1.(0);c;ar1.(1);ar1.(2);ar1.(3);ar2.(3);hyp|]))
])]
with Exit ->
Proofview.tclUNIT ()
end
let simplify_args env sigma t =
match decompose_app sigma t with
| eq, [|t;c1;c2|] -> applist (eq,[t;simpl env sigma c1;simpl env sigma c2])
| eq, [|t1;c1;t2;c2|] -> applist (eq,[t1;simpl env sigma c1;t2;simpl env sigma c2])
| _ -> t
let inject_at_positions env sigma l2r eq posns tac =
let { eq_data = (eq, (t,t1,t2)); eq_term = v; eq_evar = evs } = eq in
let e = next_ident_away eq_baseid (vars_of_env env) in
let e_env = push_named (LocalAssum (make_annot e Sorts.Relevant,t)) env in
let evdref = ref sigma in
let filter (cpath, t1', t2') =
try
let sigma, (injbody,resty) = build_injector e_env !evdref t1' (mkVar e) cpath in
let injfun = mkNamedLambda sigma (make_annot e Sorts.Relevant) t injbody in
let sigma,congr = Evd.fresh_global env sigma eq.congr in
let mk c = Retyping.get_judgment_of env sigma c in
let args = Array.map mk [|t; resty; injfun; t1; t2|] in
let sigma, pf = Typing.judge_of_apply env sigma (mk congr) args in
let { Environ.uj_val = pf; Environ.uj_type = pf_typ } = pf in
let pf_typ = Vars.subst1 mkProp (pi3 @@ destProd sigma pf_typ) in
let pf = mkApp (pf, [| v |]) in
let ty = simplify_args env sigma pf_typ in
evdref := sigma;
Some (pf, ty)
with Failure _ -> None
in
let injectors = List.map_filter filter posns in
if List.is_empty injectors then
tclZEROMSG (str "Failed to decompose the equality.")
else
let map (pf, ty) =
tclTHENS (cut ty) [
inject_if_homogenous_dependent_pair ty;
Tactics.exact_check pf <*> Proofview.Unsafe.tclNEWGOALS evs;
] in
Proofview.Unsafe.tclEVARS !evdref <*>
Tacticals.tclTHENFIRST
(Tacticals.tclMAP map (if l2r then List.rev injectors else injectors))
(tac (List.length injectors))
exception NothingToInject
let () = CErrors.register_handler (function
| NothingToInject -> Some (Pp.str "Nothing to inject.")
| _ -> None)
let injEqThen keep_proofs tac l2r eql =
Proofview.Goal.enter begin fun gl ->
let { eq_data = (eq, (t,t1,t2)) } = eql in
let sigma = Proofview.Goal.sigma gl in
let env = Proofview.Goal.env gl in
let id = try Some (destVar sigma eql.eq_term) with DestKO -> None in
match find_positions env sigma ~keep_proofs ~no_discr:true t1 t2 with
| Inl _ ->
assert false
| Inr [] ->
let suggestion =
if keep_proofs then
"" else
" You can try to use option Set Keep Proof Equalities." in
tclZEROMSG (strbrk("No information can be deduced from this equality and the injectivity of constructors. This may be because the terms are convertible, or due to pattern matching restrictions in the sort Prop." ^ suggestion))
| Inr [([],_,_)] ->
Proofview.tclZERO NothingToInject
| Inr posns ->
inject_at_positions env sigma l2r eql posns
(tac id)
end
let get_previous_hyp_position id gl =
let env, sigma = Proofview.Goal.(env gl, sigma gl) in
let rec aux dest = function
| [] -> raise (RefinerError (env, sigma, NoSuchHyp id))
| d :: right ->
let hyp = Context.Named.Declaration.get_id d in
if Id.equal hyp id then dest else aux (MoveAfter hyp) right
in
aux MoveLast (Proofview.Goal.hyps gl)
let injEq flags ?(injection_in_context = injection_in_context_flag ()) with_evars clear_flag ipats =
let ipats_style, l2r, dft_clear_flag, bounded_intro = match ipats with
| None when injection_in_context -> Some [], true, true, true
| None -> None, false, false, false
| _ -> let b = use_injection_pattern_l2r_order flags in ipats, b, b, b in
let post_tac id n =
match ipats_style with
| Some ipats ->
Proofview.Goal.enter begin fun gl ->
let destopt = match id with
| Some id -> get_previous_hyp_position id gl
| None -> MoveLast in
let clear_tac =
tclTRY (apply_clear_request clear_flag dft_clear_flag id) in
let intro_tac =
if bounded_intro
then intro_patterns_bound_to with_evars n destopt ipats
else intro_patterns_to with_evars destopt ipats in
tclTHEN clear_tac intro_tac
end
| None -> tclIDTAC in
injEqThen (keep_proof_equalities flags) post_tac l2r
let inj flags ?injection_in_context ipats with_evars clear_flag =
onEquality with_evars (injEq flags ?injection_in_context with_evars clear_flag ipats)
let injClause flags ?injection_in_context ipats with_evars = function
| None -> onNegatedEquality with_evars (injEq flags ?injection_in_context with_evars None ipats)
| Some c -> onInductionArg (inj flags ?injection_in_context ipats with_evars) c
let simpleInjClause flags with_evars = function
| None -> onNegatedEquality with_evars (injEq flags ~injection_in_context:false with_evars None None)
| Some c -> onInductionArg (fun clear_flag -> onEquality with_evars (injEq flags ~injection_in_context:false with_evars clear_flag None)) c
let injConcl flags ?injection_in_context () = injClause flags ?injection_in_context None false None
let injHyp flags ?injection_in_context clear_flag id = injClause flags ?injection_in_context None false (Some (clear_flag,ElimOnIdent CAst.(make id)))
let decompEqThen keep_proofs ntac eq =
let { eq_data = (_, (_,t1,t2) as u) } = eq in
Proofview.Goal.enter begin fun gl ->
let env = Proofview.Goal.env gl in
let sigma = Proofview.Goal.sigma gl in
let ido = try Some (destVar sigma eq.eq_term) with DestKO -> None in
match find_positions env sigma ~keep_proofs ~no_discr:false t1 t2 with
| Inl (cpath, (_,dirn), _) ->
discr_positions env sigma eq cpath dirn
| Inr [] ->
ntac ido 0
| Inr posns ->
inject_at_positions env sigma true eq posns (ntac ido)
end
let dEqThen0 ~keep_proofs with_evars ntac = function
| None -> onNegatedEquality with_evars (decompEqThen (use_keep_proofs keep_proofs) (ntac None))
| Some c -> onInductionArg (fun clear_flag -> onEquality with_evars (decompEqThen (use_keep_proofs keep_proofs) (ntac clear_flag))) c
let dEq ~keep_proofs with_evars =
dEqThen0 ~keep_proofs with_evars (fun clear_flag ido x ->
(apply_clear_request clear_flag (use_clear_hyp_by_default ()) ido))
let dEqThen ~keep_proofs with_evars ntac where =
dEqThen0 ~keep_proofs with_evars (fun _ _ n -> ntac n) where
let intro_decomp_eq tac (eq, _, data) (c, t) =
Proofview.Goal.enter begin fun gl ->
let eq = { eq_data = (eq, data); eq_term = c; eq_evar = [] } in
decompEqThen !keep_proof_equalities_for_injection (fun _ -> tac) eq
end
let () = declare_intro_decomp_eq intro_decomp_eq
let decomp_tuple_term env sigma c t =
let rec decomprec inner_code ex exty =
let iterated_decomp =
try
let ({proj1=p1; proj2=p2}),(i,a,p,car,cdr) = find_sigma_data_decompose env sigma ex in
let car_code = applist (mkConstU (destConstRef p1,i),[a;p;inner_code]) in
let cdr_code = applist (mkConstU (destConstRef p2,i),[a;p;inner_code]) in
let cdrtyp = beta_applist sigma (p,[car]) in
List.map (fun l -> ((car,a),car_code)::l) (decomprec cdr_code cdr cdrtyp)
with Constr_matching.PatternMatchingFailure ->
[]
in [((ex,exty),inner_code)]::iterated_decomp
in decomprec (mkRel 1) c t
let subst_tuple_term env sigma dep_pair1 dep_pair2 body =
let typ = get_type_of env sigma dep_pair1 in
let decomps1 = decomp_tuple_term env sigma dep_pair1 typ in
let decomps2 = decomp_tuple_term env sigma dep_pair2 typ in
let n = min (List.length decomps1) (List.length decomps2) in
let decomp1 = List.nth decomps1 (n-1) in
let decomp2 = List.nth decomps2 (n-1) in
let e1_list,proj_list = List.split decomp1 in
let e2_list,_ = List.split decomp2 in
let fold (e, t) body = lambda_create env sigma (Sorts.Relevant, t, subst_term sigma e body) in
let abst_B = List.fold_right fold e1_list body in
let ctx, abst_B = decompose_lambda_n_assum sigma (List.length e1_list) abst_B in
let sigma, _ = Typing.type_of (push_rel_context ctx env) sigma abst_B in
let sigma =
let env = push_rel (Rel.Declaration.LocalAssum (anonR, typ)) env in
let sigma, _ = Typing.type_of env sigma (List.last proj_list) in
sigma
in
let pred_body = Vars.substl (List.rev proj_list) abst_B in
let body = mkApp (lambda_create env sigma (Sorts.Relevant,typ,pred_body),[|dep_pair1|]) in
let expected_goal = Vars.substl (List.rev_map fst e2_list) abst_B in
let expected_goal = nf_betaiota env sigma expected_goal in
(sigma, (body, expected_goal))
let cutSubstInConcl l2r eqn =
Proofview.Goal.enter begin fun gl ->
let env = Proofview.Goal.env gl in
let sigma = Proofview.Goal.sigma gl in
let (lbeq,u,(t,e1,e2)) = pf_apply find_eq_data_decompose gl eqn in
let typ = pf_concl gl in
let (e1,e2) = if l2r then (e1,e2) else (e2,e1) in
let (sigma, (typ, expected)) = subst_tuple_term env sigma e1 e2 typ in
tclTHEN (Proofview.Unsafe.tclEVARS sigma)
(tclTHENFIRST
(tclTHENLIST [
(change_concl typ);
(replace_core onConcl l2r eqn)
])
(change_concl expected))
end
let cutSubstInHyp l2r eqn id =
Proofview.Goal.enter begin fun gl ->
let env = Proofview.Goal.env gl in
let sigma = Proofview.Goal.sigma gl in
let (lbeq,u,(t,e1,e2)) = pf_apply find_eq_data_decompose gl eqn in
let typ = pf_get_hyp_typ id gl in
let (e1,e2) = if l2r then (e1,e2) else (e2,e1) in
let (sigma, (typ, expected)) = subst_tuple_term env sigma e1 e2 typ in
tclTHEN (Proofview.Unsafe.tclEVARS sigma)
(tclTHENFIRST
(tclTHENLIST [
(change_in_hyp ~check:true None (make_change_arg typ) (id,InHypTypeOnly));
(replace_core (onHyp id) l2r eqn)
])
(change_in_hyp ~check:true None (make_change_arg expected) (id,InHypTypeOnly)))
end
let try_rewrite tac =
Proofview.tclORELSE tac begin function (e, info) -> match e with
| Constr_matching.PatternMatchingFailure ->
tclZEROMSG ~info (str "Not a primitive equality here.")
| e ->
tclZEROMSG ~info
(strbrk "Cannot find a well-typed generalization of the goal that makes the proof progress.")
end
let cutSubstClause l2r eqn cls =
match cls with
| None -> cutSubstInConcl l2r eqn
| Some id -> cutSubstInHyp l2r eqn id
let warn_deprecated_cutrewrite =
CWarnings.create ~name:"deprecated-cutrewrite" ~category:Deprecation.Version.v8_5
(fun () -> strbrk"\"cutrewrite\" is deprecated. Use \"replace\" instead.")
let cutRewriteClause l2r eqn cls =
warn_deprecated_cutrewrite ();
try_rewrite (cutSubstClause l2r eqn cls)
let cutRewriteInHyp l2r eqn id = cutRewriteClause l2r eqn (Some id)
let cutRewriteInConcl l2r eqn = cutRewriteClause l2r eqn None
let substClause l2r c cls =
Proofview.Goal.enter begin fun gl ->
let eq = pf_apply get_type_of gl c in
tclTHENS (cutSubstClause l2r eq cls)
[Proofview.tclUNIT (); exact_no_check c]
end
let rewriteClause l2r c cls = try_rewrite (substClause l2r c cls)
let rewriteInHyp l2r c id = rewriteClause l2r c (Some id)
let rewriteInConcl l2r c = rewriteClause l2r c None
let restrict_to_eq_and_identity env eq =
let is_ref b = match Coqlib.lib_ref_opt b with
| None -> false
| Some b -> Environ.QGlobRef.equal env eq b
in
if not (List.exists is_ref ["core.eq.type"; "core.identity.type"])
then raise Constr_matching.PatternMatchingFailure
exception FoundHyp of (Id.t * constr * bool)
let is_eq_x gl x d =
let id = NamedDecl.get_id d in
try
let is_var id c = match EConstr.kind (project gl) c with
| Var id' -> Id.equal id id'
| _ -> false
in
let c = pf_nf_evar gl (NamedDecl.get_type d) in
let (_,lhs,rhs) = pi3 (pf_apply find_eq_data_decompose gl c) in
if (is_var x lhs) && not (local_occur_var (project gl) x rhs) then raise (FoundHyp (id,rhs,true));
if (is_var x rhs) && not (local_occur_var (project gl) x lhs) then raise (FoundHyp (id,lhs,false))
with Constr_matching.PatternMatchingFailure ->
()
exception FoundDepInGlobal of Id.t option * GlobRef.t
let test_non_indirectly_dependent_section_variable gl x =
let env = Proofview.Goal.env gl in
let sigma = Tacmach.project gl in
let hyps = Proofview.Goal.hyps gl in
let concl = Proofview.Goal.concl gl in
List.iter (fun decl ->
NamedDecl.iter_constr (fun c ->
match occur_var_indirectly env sigma x c with
| Some gr -> raise (FoundDepInGlobal (Some (NamedDecl.get_id decl), gr))
| None -> ()) decl) hyps;
match occur_var_indirectly env sigma x concl with
| Some gr -> raise (FoundDepInGlobal (None, gr))
| None -> ()
let check_non_indirectly_dependent_section_variable gl x =
try test_non_indirectly_dependent_section_variable gl x
with FoundDepInGlobal (pos,gr) ->
let where = match pos with
| Some id -> str "hypothesis " ++ Id.print id
| None -> str "the conclusion of the goal" in
user_err
(strbrk "Section variable " ++ Id.print x ++
strbrk " occurs implicitly in global declaration " ++ Printer.pr_global gr ++
strbrk " present in " ++ where ++ strbrk ".")
let is_non_indirectly_dependent_section_variable gl z =
try test_non_indirectly_dependent_section_variable gl z; true
with FoundDepInGlobal (pos,gr) -> false
let subst_one dep_proof_ok x (hyp,rhs,dir) =
Proofview.Goal.enter begin fun gl ->
let sigma = Tacmach.project gl in
let hyps = Proofview.Goal.hyps gl in
let concl = Proofview.Goal.concl gl in
let dephyps =
List.rev (pi3 (List.fold_right (fun dcl (dest,deps,allhyps) ->
let id = NamedDecl.get_id dcl in
if not (Id.equal id hyp)
&& List.exists (fun y -> local_occur_var_in_decl sigma y dcl) deps
then
(dest,id::deps,(dest,id)::allhyps)
else
(MoveBefore id,deps,allhyps))
hyps
(MoveBefore x,[x],[]))) in
let depconcl = local_occur_var sigma x concl in
let need_rewrite = not (List.is_empty dephyps) || depconcl in
tclTHENLIST
((if need_rewrite then
[Generalize.revert (List.map snd dephyps);
general_rewrite ~where:None ~l2r:dir AtLeastOneOccurrence ~freeze:true ~dep:dep_proof_ok ~with_evars:false (mkVar hyp, NoBindings);
(tclMAP (fun (dest,id) -> intro_move (Some id) dest) dephyps)]
else
[Proofview.tclUNIT ()]) @
[tclTRY (clear [x; hyp])])
end
let subst_one_var dep_proof_ok x =
Proofview.Goal.enter begin fun gl ->
let decl = pf_get_hyp x gl in
if is_local_def decl then tclTHEN (unfold_body x) (clear [x]) else
let res =
try
let hyps = Proofview.Goal.hyps gl in
let test hyp _ = is_eq_x gl x hyp in
Context.Named.fold_outside test ~init:() hyps;
user_err
(str "Cannot find any non-recursive equality over " ++ Id.print x ++
str".")
with FoundHyp res -> res in
if is_section_variable (Global.env ()) x then
check_non_indirectly_dependent_section_variable gl x;
subst_one dep_proof_ok x res
end
let subst_gen dep_proof_ok ids =
tclMAP (subst_one_var dep_proof_ok) ids
let subst = subst_gen true
type subst_tactic_flags = {
only_leibniz : bool;
rewrite_dependent_proof : bool
}
let default_subst_tactic_flags =
{ only_leibniz = false; rewrite_dependent_proof = true }
let warn_deprecated_simple_subst =
CWarnings.create ~name:"deprecated-simple-subst" ~category:Deprecation.Version.v8_8
(fun () -> strbrk"\"simple subst\" is deprecated")
let subst_all ?(flags=default_subst_tactic_flags) () =
let () =
if flags.only_leibniz || not flags.rewrite_dependent_proof then
warn_deprecated_simple_subst ()
in
let process hyp =
Proofview.Goal.enter begin fun gl ->
let env = Proofview.Goal.env gl in
let sigma = project gl in
let c = pf_get_hyp hyp gl |> NamedDecl.get_type in
try
let lbeq,u,(_,x,y) = pf_apply find_eq_data_decompose gl c in
if flags.only_leibniz then restrict_to_eq_and_identity env lbeq.eq;
match EConstr.kind sigma x, EConstr.kind sigma y with
| Var x, Var y when Id.equal x y ->
Proofview.tclUNIT ()
| Var x', _ when not (Termops.local_occur_var sigma x' y) &&
not (is_evaluable env (EvalVarRef x')) &&
is_non_indirectly_dependent_section_variable gl x' ->
subst_one flags.rewrite_dependent_proof x' (hyp,y,true)
| _, Var y' when not (Termops.local_occur_var sigma y' x) &&
not (is_evaluable env (EvalVarRef y')) &&
is_non_indirectly_dependent_section_variable gl y' ->
subst_one flags.rewrite_dependent_proof y' (hyp,x,false)
| _ ->
Proofview.tclUNIT ()
with Constr_matching.PatternMatchingFailure ->
Proofview.tclUNIT ()
end
in
Proofview.Goal.enter begin fun gl ->
tclMAP process (List.rev (List.map NamedDecl.get_id (Proofview.Goal.hyps gl)))
end
let cond_eq_term_left c t gl =
try
let (_,x,_) = pi3 (pf_apply find_eq_data_decompose gl t) in
if pf_conv_x gl c x then true else failwith "not convertible"
with Constr_matching.PatternMatchingFailure -> failwith "not an equality"
let cond_eq_term_right c t gl =
try
let (_,_,x) = pi3 (pf_apply find_eq_data_decompose gl t) in
if pf_conv_x gl c x then false else failwith "not convertible"
with Constr_matching.PatternMatchingFailure -> failwith "not an equality"
let cond_eq_term c t gl =
try
let (_,x,y) = pi3 (pf_apply find_eq_data_decompose gl t) in
if pf_conv_x gl c x then true
else if pf_conv_x gl c y then false
else failwith "not convertible"
with Constr_matching.PatternMatchingFailure -> failwith "not an equality"
let rewrite_assumption_cond cond_eq_term cl =
let rec arec hyps gl = match hyps with
| [] -> user_err Pp.(str "No such assumption.")
| hyp ::rest ->
let id = NamedDecl.get_id hyp in
begin
try
let dir = cond_eq_term (NamedDecl.get_type hyp) gl in
general_rewrite_clause dir false (mkVar id,NoBindings) cl
with | Failure _ | UserError _ -> arec rest gl
end
in
Proofview.Goal.enter begin fun gl ->
let hyps = Proofview.Goal.hyps gl in
arec hyps gl
end
let replace_term dir_opt c =
let cond_eq_fun =
match dir_opt with
| None -> cond_eq_term c
| Some true -> cond_eq_term_left c
| Some false -> cond_eq_term_right c
in
rewrite_assumption_cond cond_eq_fun
let () =
let gmr l2r with_evars tac c = general_rewrite_clause l2r with_evars tac c in
Hook.set Tactics.general_rewrite_clause gmr
let () = Hook.set Tactics.subst_one subst_one