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
|
/**************************************************************/
/* ********************************************************** */
/* * * */
/* * INFERENCE RULES FOR SORTS * */
/* * * */
/* * $Module: SORTRULES * */
/* * * */
/* * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 * */
/* * MPI fuer Informatik * */
/* * * */
/* * This program is free software; you can redistribute * */
/* * it and/or modify it under the terms of the FreeBSD * */
/* * Licence. * */
/* * * */
/* * This program is distributed in the hope that it will * */
/* * be useful, but WITHOUT ANY WARRANTY; without even * */
/* * the implied warranty of MERCHANTABILITY or FITNESS * */
/* * FOR A PARTICULAR PURPOSE. See the LICENCE file * */
/* * for more details. * */
/* * * */
/* * * */
/* $Revision: 1.4 $ * */
/* $State: Exp $ * */
/* $Date: 2011-05-25 07:58:17 $ * */
/* $Author: weidenb $ * */
/* * * */
/* * Contact: * */
/* * Christoph Weidenbach * */
/* * MPI fuer Informatik * */
/* * Stuhlsatzenhausweg 85 * */
/* * 66123 Saarbruecken * */
/* * Email: spass@mpi-inf.mpg.de * */
/* * Germany * */
/* * * */
/* ********************************************************** */
/**************************************************************/
/* $RCSfile: rules-sort.c,v $ */
/**************************************************************/
/* Includes */
/**************************************************************/
#include "rules-sort.h"
/**************************************************************/
/* Functions */
/**************************************************************/
static LIST inf_GetForwardPartnerLits(LITERAL, st_INDEX);
static SORT inf_GetSortFromLits(LIST, SORTTHEORY);
static BOOL inf_SubsortPrecheck(CLAUSE Clause, LIST TLits, LITERAL Special,
st_INDEX Index, SORTTHEORY SortTheory)
/**************************************************************
INPUT: A clause, a list of constraint literal indices in
that clause, a special literal, an index of clauses,
and the actual sort theory.
RETURNS: TRUE, if there exists any subsort of the <TLits> sort.
***************************************************************/
{
SORT tSort, unifierSort;
LIST unifiers;
BOOL result;
unifiers = inf_GetForwardPartnerLits(clause_GetLiteral(Clause,(intptr_t)list_Car(TLits)),
Index);
unifierSort = inf_GetSortFromLits(unifiers, SortTheory);
list_Delete(unifiers);
tSort = sort_TopSort();
for (; !list_Empty(TLits); TLits = list_Cdr(TLits)) {
TERM actAtom = clause_GetLiteralAtom(Clause, (intptr_t)list_Car(TLits));
tSort = sort_Intersect(sort_TheorySortOfSymbol(SortTheory, term_TopSymbol(actAtom)),
tSort);
}
tSort = list_PointerDeleteDuplicates(tSort);
if (Special == NULL)
result = sort_TheoryIsSubsortOf(SortTheory, unifierSort, tSort);
else {
SORT extraSort;
extraSort = sort_TheorySortOfSymbol(SortTheory, clause_LiteralPredicate(Special));
result = sort_TheoryIsSubsortOfExtra(SortTheory, extraSort, unifierSort, tSort);
sort_Delete(extraSort);
}
sort_Delete(tSort);
sort_Delete(unifierSort);
return result;
}
static LIST inf_GetSortResolutionPartnerLits(TERM Atom, st_INDEX Index)
/**************************************************************
INPUT: A clause, and an Index of clauses.
RETURNS: A list of literals with which sortresolution is possible.
MEMORY: Allocates memory for the list.
***************************************************************/
{
LIST Result, TermList, LitScan;
LITERAL NextLit;
CLAUSE Clause;
#ifdef CHECK
if (!term_IsAtom(Atom)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_GetSortResolutionPartnerLits: Variable as atom input.\n");
misc_FinishErrorReport();
}
#endif
Result = list_Nil();
TermList = st_GetUnifier(cont_LeftContext(), Index, cont_RightContext(), Atom);
for ( ; !list_Empty(TermList); TermList = list_Pop(TermList)) {
if (term_IsAtom(list_Car(TermList))) {
for (LitScan = sharing_NAtomDataList(list_Car(TermList));
!list_Empty(LitScan);
LitScan = list_Cdr(LitScan)){
NextLit = list_Car(LitScan);
Clause = clause_LiteralOwningClause(NextLit);
if (clause_LiteralIsPositive(NextLit) &&
clause_LiteralGetFlag(NextLit,STRICTMAXIMAL) &&
clause_GetFlag(Clause, WORKEDOFF) &&
clause_HasSolvedConstraint(Clause) &&
!list_PointerMember(Result, NextLit))
Result = list_Cons(NextLit, Result);
}
}
}
return Result;
}
static CLAUSE inf_BuildConstraintHyperResolvent(CLAUSE Clause, LIST Lits,
SUBST Subst, LIST Foundlits,
FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A <Clause> where the sort constraint is resolved,
a list <Lits> of constraint indices in <Clause> where
all corresponding constraints have the same term,
the overall substitution <Subst>,
a list <Foundlits> of literals of found partner clauses,
a flag store and a precedence.
RETURNS: A clause, the resolvent of a resolution step.
***************************************************************/
{
CLAUSE NewClause, ClauseCopy;
LIST Constraint, Antecedent, Succedent, ParentCls, ParentLits, Scan;
TERM Atom;
SYMBOL MaxVar,MaxCand;
intptr_t i;
int bound, depth;
BOOL IsFromEmptySort;
LIST Partners;
ParentCls = list_Nil();
ParentLits = list_Nil();
Constraint = list_Nil();
Antecedent = list_Nil();
Succedent = list_Nil();
Partners = list_Nil();
depth = clause_Depth(Clause);
for (Scan=Foundlits; !list_Empty(Scan); Scan=list_Cdr(Scan))
depth = misc_Max(depth,
clause_Depth(clause_LiteralOwningClause(list_Car(Scan))));
ClauseCopy = clause_Copy(Clause);
Partners = list_Cons(ClauseCopy, Partners);
clause_SubstApply(Subst, ClauseCopy);
IsFromEmptySort = term_IsVariable(term_FirstArgument(
clause_GetLiteralAtom(Clause, (intptr_t)list_Car(Lits))));
bound = clause_LastConstraintLitIndex(ClauseCopy);
for (i = clause_FirstLitIndex(); i <= bound; i++)
if (!list_PointerMember(Lits, (POINTER)i)) {
Atom = term_Copy(clause_GetLiteralAtom(ClauseCopy, i));
Constraint = list_Cons(Atom, Constraint);
}
else {
ParentCls = list_Cons((POINTER)clause_Number(ClauseCopy), ParentCls);
ParentLits = list_Cons((POINTER)i, ParentLits);
}
bound = clause_LastAntecedentLitIndex(ClauseCopy);
for ( ; i <= bound; i++) {
Atom = term_Copy(clause_GetLiteralAtom(ClauseCopy, i));
Antecedent = list_Cons(Atom, Antecedent);
}
bound = clause_LastSuccedentLitIndex(ClauseCopy);
for (; i <= bound; i++) {
Atom = term_Copy(clause_GetLiteralAtom(ClauseCopy, i));
Succedent = list_Cons(Atom, Succedent);
}
bound = clause_LastConstraintLitIndex(Clause);
for (i = clause_FirstLitIndex(); i <= bound; i++) {
/* Hier sollen die gematchten Constraintliterale dazu fuehren, dass die */
/* c,a und s- literale der Partnerclauses in die Listen kommen... */
if (list_PointerMember(Lits, (POINTER)i)) {
CLAUSE PartnerCopy;
LITERAL PLit;
TERM PAtom;
SUBST NewSubst,RightSubst;
int j,lc,la,n;
intptr_t PLitInd;
Atom = clause_GetLiteralAtom(ClauseCopy, i);
NewClause = clause_CreateUnnormalized(Constraint, Antecedent, Succedent);
list_Delete(Constraint);
list_Delete(Antecedent);
list_Delete(Succedent);
Constraint = list_Nil();
Antecedent = list_Nil();
Succedent = list_Nil();
/* Find corresponding Foundlit: */
for (Scan = Foundlits;
term_TopSymbol(Atom) !=
term_TopSymbol(clause_LiteralAtom(list_Car(Scan)));
Scan = list_Cdr(Scan));
PLit = list_Car(Scan);
PLitInd = clause_LiteralGetIndex(PLit);
PartnerCopy = clause_Copy(clause_LiteralOwningClause(PLit));
Partners = list_Cons(PartnerCopy, Partners);
ParentCls = list_Cons((POINTER)clause_Number(PartnerCopy), ParentCls);
ParentLits = list_Cons((POINTER)PLitInd, ParentLits);
MaxVar = clause_SearchMaxVar(ClauseCopy);
MaxCand = clause_SearchMaxVar(NewClause);
MaxVar = ((MaxVar > MaxCand) ? MaxVar : MaxCand);
/* MaxVar is the maximal variable in the new clause or the ClauseCopy, */
/* the latter to guarantee the stability of variable names. */
clause_RenameVarsBiggerThan(PartnerCopy, MaxVar);
PLit = clause_GetLiteral(PartnerCopy, PLitInd);
PAtom = clause_LiteralAtom(PLit);
cont_Check();
if (!unify_UnifyNoOC(cont_LeftContext(), PAtom, cont_RightContext(), Atom)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_BuildConstraintHyperResolvent: Unification failed.");
misc_FinishErrorReport();
}
subst_ExtractUnifier(cont_LeftContext(), &RightSubst, cont_RightContext(), &NewSubst);
cont_Reset();
clause_SubstApply(NewSubst, NewClause);
clause_SubstApply(NewSubst, ClauseCopy);
subst_Delete(NewSubst);
n = clause_Length(PartnerCopy);
lc = clause_LastConstraintLitIndex(PartnerCopy);
la = clause_LastAntecedentLitIndex(PartnerCopy);
for (j = clause_FirstLitIndex(); j < n; j++) {
if (j <= lc)
Constraint = list_Cons(subst_Apply(RightSubst,
term_Copy(clause_GetLiteralAtom(PartnerCopy, j))),
Constraint);
else if (j <= la)
Antecedent = list_Cons(subst_Apply(RightSubst,
term_Copy(clause_GetLiteralAtom(PartnerCopy, j))),
Antecedent);
else if (j != PLitInd)
Succedent = list_Cons(subst_Apply(RightSubst,
term_Copy(clause_GetLiteralAtom(PartnerCopy, j))),
Succedent);
}
subst_Delete(RightSubst);
n = clause_Length(NewClause);
lc = clause_LastConstraintLitIndex(NewClause);
la = clause_LastAntecedentLitIndex(NewClause);
for (j = clause_FirstLitIndex(); j < n; j++) {
if (j <= lc)
Constraint = list_Cons(term_Copy(clause_GetLiteralAtom(NewClause, j)),
Constraint);
else if (j <= la)
Antecedent = list_Cons(term_Copy(clause_GetLiteralAtom(NewClause, j)),
Antecedent);
else
Succedent = list_Cons(term_Copy(clause_GetLiteralAtom(NewClause, j)),
Succedent);
}
clause_Delete(NewClause);
clause_DecreaseCounter();
}
}
NewClause = clause_Create(Constraint, Antecedent, Succedent, Flags,Precedence);
list_Delete(Constraint);
list_Delete(Antecedent);
list_Delete(Succedent);
if (IsFromEmptySort)
clause_SetFromEmptySort(NewClause);
else
clause_SetFromSortResolution(NewClause);
clause_SetDepth(NewClause, depth + 1);
clause_SetSplitDataFromList(NewClause, Partners);
clause_DeleteClauseList(Partners);
clause_SetParentClauses(NewClause, list_NReverse(ParentCls));
clause_SetParentLiterals(NewClause, list_NReverse(ParentLits));
return NewClause;
}
static LIST inf_ConstraintHyperResolvents(CLAUSE Clause, LIST Lits,
SUBST Subst, LIST Restlits,
LIST Foundlits, st_INDEX Index,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**************************************************************
INPUT: A <Clause> where the sort constraint is resolved,
a list <Lits> of constraint indices in <Clause> where
all corresponding constraints have the same term,
the overall substitution <Subst>,
a list <Restlits> of constraint indeces for which
a partner clause is searched with respect to <Index>,
a list <Foundlits> of literals of already found partner clauses,
a flag store and a precedence.
RETURNS: The list of possible resolvents.
***************************************************************/
{
if (list_Empty(Restlits))
return list_List(inf_BuildConstraintHyperResolvent(Clause,Lits,Subst,
Foundlits, Flags,
Precedence));
else {
CLAUSE PartnerCopy;
LITERAL Lit, PLit;
LIST Result, NextLits;
TERM AtomCopy;
SUBST NewSubst, RightSubst, HelpSubst;
SYMBOL MaxVar, MaxCand;
int PLitInd;
Result = list_Nil();
Lit = clause_GetLiteral(Clause, (intptr_t) list_Car(Restlits));
AtomCopy = subst_Apply(Subst, term_Copy(clause_LiteralAtom(Lit)));
NextLits = inf_GetSortResolutionPartnerLits(AtomCopy,Index);
MaxVar = clause_MaxVar(Clause);
MaxCand = clause_AtomMaxVar(AtomCopy);
MaxVar = (symbol_GreaterVariable(MaxVar, MaxCand) ? MaxVar : MaxCand);
for ( ; !list_Empty(NextLits); NextLits = list_Pop(NextLits)) {
PLit = list_Car(NextLits);
PLitInd = clause_LiteralGetIndex(PLit);
Foundlits = list_Cons(PLit, Foundlits);
PartnerCopy = clause_Copy(clause_LiteralOwningClause(PLit));
clause_RenameVarsBiggerThan(PartnerCopy, MaxVar);
PLit = clause_GetLiteral(PartnerCopy, PLitInd);
cont_Check();
unify_UnifyNoOC(cont_LeftContext(), AtomCopy,
cont_RightContext(), clause_LiteralAtom(PLit));
subst_ExtractUnifier(cont_LeftContext(), &NewSubst, cont_RightContext(), &RightSubst);
cont_Reset();
subst_Delete(RightSubst);
HelpSubst = NewSubst;
NewSubst = subst_Compose(NewSubst, subst_Copy(Subst));
Result = list_Nconc(inf_ConstraintHyperResolvents(Clause, Lits, NewSubst,
list_Cdr(Restlits),
Foundlits, Index, Flags,
Precedence),
Result);
subst_Delete(NewSubst);
subst_Delete(HelpSubst);
clause_Delete(PartnerCopy);
Foundlits = list_Pop(Foundlits);
}
term_Delete(AtomCopy);
return Result;
}
}
LIST inf_BackwardSortResolution(CLAUSE GivenClause, st_INDEX Index,
SORTTHEORY SortTheory, BOOL Precheck,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause with a solved sort constraint, an index of clauses,
a sort theory, a boolean flag indicating whether the subsort
precheck can be applied, a flag store and a precedence.
RETURNS: A list of clauses inferred from the GivenClause by
SortResolution with the given clause.
MEMORY: A list of clauses is produced, where memory for the list
and the clauses is allocated.
***************************************************************/
{
LIST result;
int i, ls;
#ifdef CHECK
if (!clause_IsClause(GivenClause, Flags, Precedence) ||
!clause_HasSolvedConstraint(GivenClause)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_BackwardSortResolution: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
result = list_Nil();
ls = clause_LastSuccedentLitIndex(GivenClause);
for (i = clause_FirstSuccedentLitIndex(GivenClause); i <= ls; i++) {
LITERAL pLit;
TERM pAtom;
pLit = clause_GetLiteral(GivenClause, i);
pAtom = clause_LiteralAtom(pLit);
if (clause_LiteralGetFlag(pLit,STRICTMAXIMAL) &&
clause_LiteralIsSort(pLit)) {
LIST termList;
termList = st_GetUnifier(cont_LeftContext(),Index,cont_RightContext(),pAtom);
for ( ; !list_Empty(termList); termList = list_Pop(termList)){
if (term_IsAtom(list_Car(termList)) &&
!term_IsVariable(term_FirstArgument(list_Car(termList)))) {
LIST litScan;
litScan = sharing_NAtomDataList(list_Car(termList));
for ( ; !list_Empty(litScan); litScan = list_Cdr(litScan)) {
LITERAL gLit;
CLAUSE gClause;
gLit = list_Car(litScan);
gClause = clause_LiteralOwningClause(gLit);
if (clause_LiteralGetIndex(gLit) < clause_FirstAntecedentLitIndex(gClause) &&
clause_GetFlag(gClause,WORKEDOFF)) {
TERM gAtom;
intptr_t gi,j;
int lc;
LIST tLits, restLits;
gAtom = clause_LiteralAtom(gLit);
lc = clause_LastConstraintLitIndex(gClause);
gi = clause_LiteralGetIndex(gLit);
tLits = list_List((POINTER)gi);
restLits = list_Nil();
for (j = clause_FirstLitIndex(); j <= lc; j++) {
LITERAL tCand;
tCand = clause_GetLiteral(gClause, j);
if (j != gi &&
term_FirstArgument(clause_LiteralAtom(tCand))
== term_FirstArgument(gAtom)) {
tLits = list_Cons((POINTER)j, tLits);
restLits = list_Cons((POINTER)j, restLits);
}
}
if (!Precheck ||
inf_SubsortPrecheck(gClause,tLits,pLit,Index,SortTheory)) {
CLAUSE pClauseCopy;
SYMBOL minVar;
LIST foundLits;
SUBST leftSubst, rightSubst;
pClauseCopy = clause_Copy(GivenClause);
minVar = clause_MaxVar(gClause);
foundLits = list_List(pLit);
clause_RenameVarsBiggerThan(pClauseCopy, minVar);
pAtom = clause_GetLiteralAtom(pClauseCopy, i);
/* set, to unify correctly! */
cont_Check();
unify_UnifyNoOC(cont_LeftContext(), gAtom, cont_RightContext(), pAtom);
subst_ExtractUnifier(cont_LeftContext(), &leftSubst,
cont_RightContext(), &rightSubst);
cont_Reset();
subst_Delete(rightSubst);
result =
list_Nconc(inf_ConstraintHyperResolvents(gClause, tLits,
leftSubst, restLits,
foundLits, Index,
Flags, Precedence),
result);
pAtom = clause_LiteralAtom(pLit);
subst_Delete(leftSubst);
list_Delete(foundLits);
clause_Delete(pClauseCopy);
} /* if Precheck */
list_Delete(tLits);
list_Delete(restLits);
}
}
}
}
}
}
return result;
}
LIST inf_ForwardSortResolution(CLAUSE GivenClause, st_INDEX Index,
SORTTHEORY SortTheory, BOOL Precheck,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause with an unsolved sort constraint, an index of clauses,
a sort theory, a boolean flag indicating whether the subsort
precheck can be applied, a flag store and a precedence.
RETURNS: A list of clauses inferred from the GivenClause by
SortResolution on the given clause.
MEMORY: A list of clauses is produced, where memory for the list
and the clauses is allocated.
***************************************************************/
{
LIST Result, TLits, RestLits;
intptr_t i,j;
int lc;
BOOL Hit;
TERM TAtom;
#ifdef CHECK
if (!clause_IsClause(GivenClause, Flags, Precedence) ||
!clause_HasTermSortConstraintLits(GivenClause)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_ForwardSortResolution: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
Result = list_Nil();
lc = clause_LastConstraintLitIndex(GivenClause);
Hit = FALSE;
i = clause_FirstLitIndex();
while (i <= lc && !Hit) {
TAtom = clause_GetLiteralAtom(GivenClause, i);
if (!term_IsVariable(term_FirstArgument(TAtom)))
Hit = TRUE;
else
i++;
}
if (!Hit)
return list_Nil();
/* added because of compiler warnings */
TAtom = clause_GetLiteralAtom(GivenClause, i);
/* Search the other T_i from <GivenClause> */
TLits = list_List((POINTER)i);
for (j = i+1; j <= lc; j++) {
if (term_FirstArgument(clause_GetLiteralAtom(GivenClause, j))
== term_FirstArgument(TAtom))
TLits = list_Cons((POINTER)j, TLits);
}
RestLits = list_Copy(TLits);
if (!Precheck ||
inf_SubsortPrecheck(GivenClause, TLits, NULL, Index, SortTheory)) {
Result = inf_ConstraintHyperResolvents(GivenClause, TLits, subst_Nil(),
RestLits, list_Nil(), Index, Flags,
Precedence);
}
list_Delete(RestLits);
list_Delete(TLits);
return Result;
}
LIST inf_BackwardEmptySort(CLAUSE GivenClause, st_INDEX Index,
SORTTHEORY SortTheory, BOOL Precheck,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause with a solved sort constraint, an 'Index' of clauses,
a sort theory, a boolean flag indicating whether the subsort
precheck can be applied, a flag store and a precedence.
RETURNS: A list of clauses inferred from the GivenClause by
EmptySort with the given clause.
MEMORY: A list of clauses is produced, where memory for the list
and the clauses is allocated.
***************************************************************/
{
LIST result;
int i, ls;
#ifdef CHECK
if (!(clause_IsClause(GivenClause, Flags, Precedence)) ||
!clause_HasSolvedConstraint(GivenClause)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_BackwardEmptySort: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
result = list_Nil();
ls = clause_LastSuccedentLitIndex(GivenClause);
for (i = clause_FirstSuccedentLitIndex(GivenClause); i <= ls; i++) {
LITERAL pLit = clause_GetLiteral(GivenClause, i);
TERM pAtom = clause_LiteralAtom(pLit);
if (clause_LiteralGetFlag(pLit,STRICTMAXIMAL) &&
clause_LiteralIsSort(pLit)) {
LIST unifiers = st_GetUnifier(cont_LeftContext(),Index,cont_RightContext(),pAtom);
for ( ; !list_Empty(unifiers); unifiers = list_Pop(unifiers)){
if (term_IsAtom(list_Car(unifiers)) &&
term_IsVariable(term_FirstArgument(list_Car(unifiers)))) {
LIST litScan = sharing_NAtomDataList(list_Car(unifiers));
for ( ; !list_Empty(litScan); litScan = list_Cdr(litScan)){
LITERAL gLit = list_Car(litScan);
CLAUSE gClause = clause_LiteralOwningClause(gLit);
if (clause_LiteralGetIndex(gLit) < clause_FirstAntecedentLitIndex(gClause) &&
clause_GetFlag(gClause,WORKEDOFF) &&
clause_HasOnlyVarsInConstraint(gClause, Flags, Precedence)) {
TERM gAtom = clause_LiteralAtom(gLit);
SYMBOL var = term_TopSymbol(term_FirstArgument(gAtom));
int lc = clause_LastConstraintLitIndex(gClause);
intptr_t gi = clause_LiteralGetIndex(gLit);
BOOL varOccursNoMore;
intptr_t j;
int bound;
varOccursNoMore = TRUE;
bound = clause_LastSuccedentLitIndex(gClause);
for (j = clause_FirstAntecedentLitIndex(gClause);
(j <= bound) && varOccursNoMore;
j++) {
if (term_ContainsSymbol(clause_GetLiteralAtom(gClause, j), var))
varOccursNoMore = FALSE;
}
if (varOccursNoMore || clause_HasOnlySpecDomArgs(gClause)) {
LIST tLits, restLits;
/* Search the other T_i from <gClause> */
tLits = list_List((POINTER)gi);
restLits = list_Nil();
for (j = clause_FirstLitIndex(); j <= lc; j++) {
LITERAL tCand = clause_GetLiteral(gClause, j);
if (j != gi &&
term_FirstArgument(clause_LiteralAtom(tCand))
== term_FirstArgument(gAtom)) {
tLits = list_Cons((POINTER)j, tLits);
restLits = list_Cons((POINTER)j, restLits);
}
}
if (!Precheck ||
inf_SubsortPrecheck(gClause,tLits,pLit,Index,SortTheory)) {
CLAUSE pCopy = clause_Copy(GivenClause);
SYMBOL minVar = clause_MaxVar(gClause);
LIST foundLits = list_List(pLit);
SUBST leftSubst, rightSubst;
clause_RenameVarsBiggerThan(pCopy, minVar);
pAtom = clause_GetLiteralAtom(pCopy, i);
/* set, to adress the renamed term! */
cont_Check();
unify_UnifyNoOC(cont_LeftContext(), gAtom, cont_RightContext(), pAtom);
subst_ExtractUnifier(cont_LeftContext(), &leftSubst,
cont_RightContext(), &rightSubst);
cont_Reset();
subst_Delete(rightSubst);
result =
list_Nconc(inf_ConstraintHyperResolvents(gClause, tLits,
leftSubst,restLits,
foundLits, Index,
Flags, Precedence),
result);
list_Delete(foundLits);
subst_Delete(leftSubst);
clause_Delete(pCopy);
pAtom = clause_LiteralAtom(pLit);
/* reset to original clauses literal! */
} /* if Precheck */
list_Delete(tLits);
list_Delete(restLits);
}
}
}
}
}
}
}
return result;
}
LIST inf_ForwardEmptySort(CLAUSE GivenClause, st_INDEX Index,
SORTTHEORY SortTheory, BOOL Precheck, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause, an index of clauses, a sort theory,
a boolean flag indicating whether the subsort
precheck can be applied, a flag store and a precedence.
The constraint of <GivenClause> is necessarily unsolved
RETURNS: A list of clauses inferred from the GivenClause by
EmptySort on the given clause.
MEMORY: A list of clauses is produced, where memory for the list
and the clauses is allocated.
***************************************************************/
{
LIST Result, TLits, RestLits;
intptr_t i,j;
int lc, ls;
BOOL Hit;
TERM TAtom;
SYMBOL Var;
#ifdef CHECK
if (clause_HasTermSortConstraintLits(GivenClause) ||
clause_HasSolvedConstraint(GivenClause)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_ForwardEmptySort: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
Result = list_Nil();
lc = clause_LastConstraintLitIndex(GivenClause);
Hit = FALSE;
i = clause_FirstLitIndex();
while (i <= lc && !Hit) {
TAtom = clause_GetLiteralAtom(GivenClause, i);
if (term_IsVariable(term_FirstArgument(TAtom))) {
Var = term_TopSymbol(term_FirstArgument(TAtom));
ls = clause_LastSuccedentLitIndex(GivenClause);
Hit = TRUE;
/* Check if the variable occurs in antecedent or succedent literals */
for (j = clause_FirstAntecedentLitIndex(GivenClause);
j <= ls && Hit; j++) {
if (term_ContainsSymbol(clause_GetLiteralAtom(GivenClause,j), Var))
Hit = FALSE; /* Variable occurs in antecedent/constraint literal */
}
}
if (!Hit)
i++;
}
if (!Hit) /* Must be a SpecDomArgsClause */
i = clause_FirstConstraintLitIndex(GivenClause);
TAtom = clause_GetLiteralAtom(GivenClause, i);
Var = term_TopSymbol(term_FirstArgument(TAtom));
/* Search the other T_i(t) literals */
TLits = list_List((POINTER)i);
for (j = i+1; j <= lc; j++) {
TERM TCand;
TCand = clause_GetLiteralAtom(GivenClause, j);
if (symbol_Equal(term_TopSymbol(term_FirstArgument(TCand)), Var))
TLits = list_Cons((POINTER)j, TLits);
}
RestLits = list_Copy(TLits);
if (!Precheck ||
inf_SubsortPrecheck(GivenClause, TLits, NULL, Index, SortTheory)) {
Result = inf_ConstraintHyperResolvents(GivenClause, TLits, subst_Nil(),
RestLits, list_Nil(), Index, Flags,
Precedence);
}
list_Delete(RestLits);
list_Delete(TLits);
return Result;
}
static LIST inf_GetForwardPartnerLits(LITERAL Literal, st_INDEX Index)
/**************************************************************
INPUT: A monadic literal, and an index of clauses.
RETURNS: A list of monadic succedent literals whose subterm
is unifiable with the (one) subterm of <Literal>.
The literals are strict maximal in their respective clauses,
the clauses are "WORKEDOFF" and either the subterm
is not a variable or the clause has an empty constraint.
MEMORY: Allocates memory for the list.
***************************************************************/
{
LIST result, unifiers, atomScan, litScan;
#ifdef CHECK
if (!clause_LiteralIsLiteral(Literal) || !clause_LiteralIsSort(Literal)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_GetForwardPartnerLits: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
result = list_Nil();
/* Search unifiers for the literal's subterm */
unifiers = st_GetUnifier(cont_LeftContext(), Index, cont_RightContext(),
term_FirstArgument(clause_LiteralAtom(Literal)));
for ( ; !list_Empty(unifiers); unifiers = list_Pop(unifiers)) {
if (!term_IsAtom(list_Car(unifiers))) { /* Can happen if arg is variable */
for (atomScan = term_SupertermList(list_Car(unifiers));
!list_Empty(atomScan);
atomScan = list_Cdr(atomScan)) {
TERM atomCand;
atomCand = (TERM) list_Car(atomScan);
if (term_IsDeclaration(atomCand)) {
/* We are looking for an unary atom */
for (litScan = sharing_NAtomDataList(atomCand);
!list_Empty(litScan);
litScan = list_Cdr(litScan)) {
LITERAL nextLit;
CLAUSE nextClause;
nextLit = list_Car(litScan);
nextClause = clause_LiteralOwningClause(nextLit);
if (clause_LiteralIsPositive(nextLit) &&
clause_LiteralGetFlag(nextLit,STRICTMAXIMAL) &&
clause_GetFlag(nextClause, WORKEDOFF) &&
(!term_IsVariable(list_Car(unifiers)) ||
clause_HasEmptyConstraint(nextClause)) &&
clause_HasSolvedConstraint(nextClause)) {
/* Add the literal from the copied clause */
result = list_Cons(nextLit, result);
}
} /* litScan */
} /* if IsAtom */
} /* atomScan */
} /* ! variable */
} /* unifiers */
return result;
}
static BOOL inf_LiteralsHaveSameSubtermAndAreFromSameClause(LITERAL L1, LITERAL L2)
/**************************************************************
INPUT: Two literals.
RETURNS: TRUE, if both literals have the same term and are
from the same clause, FALSE otherwise.
Since both literals are shared, pointer equality
is used to detect this.
This function is used by inf_GetBackwardPartnerLits().
***************************************************************/
{
return (term_FirstArgument(clause_LiteralAtom(L1))
== term_FirstArgument(clause_LiteralAtom(L2)) &&
clause_LiteralOwningClause(L1) == clause_LiteralOwningClause(L2));
}
static void inf_GetBackwardPartnerLits(LITERAL Literal, st_INDEX Index,
LIST* ConstraintLits, LIST* Unifiers,
BOOL IsFromEmptySort, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A literal, an index of clauses, two pointers to lists,
a boolean value, a flag store and a precedence.
RETURNS:
MEMORY: Allocates memory for the list.
***************************************************************/
{
LIST candidates, atomScan, litScan;
LITERAL nextLit;
CLAUSE nextClause;
#ifdef CHECK
if (!clause_LiteralIsLiteral(Literal) || !clause_LiteralIsSort(Literal)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_GetBackwardPartnerLits: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
candidates = st_GetUnifier(cont_LeftContext(), Index, cont_RightContext(),
term_FirstArgument(clause_LiteralAtom(Literal)));
for ( ; !list_Empty(candidates); candidates = list_Pop(candidates)) {
if (!term_IsAtom(list_Car(candidates))) { /* May happen if arg is variable */
/* Consider variable unifiers only if called from BackwardEmptySort */
for (atomScan = term_SupertermList(list_Car(candidates));
!list_Empty(atomScan);
atomScan = list_Cdr(atomScan)) {
TERM atomCand;
atomCand = (TERM) list_Car(atomScan);
if (term_IsDeclaration(atomCand)) {
/* We are looking for unary atoms */
for (litScan = sharing_NAtomDataList(atomCand);
!list_Empty(litScan);
litScan = list_Cdr(litScan)) {
nextLit = list_Car(litScan);
nextClause = clause_LiteralOwningClause(nextLit);
if (clause_GetFlag(nextClause, WORKEDOFF)) {
if (clause_LiteralIsPositive(nextLit)) {
if (clause_LiteralGetFlag(nextLit,STRICTMAXIMAL) &&
(!term_IsVariable(list_Car(candidates)) ||
clause_HasEmptyConstraint(nextClause)) &&
clause_HasSolvedConstraint(nextClause) &&
!symbol_Equal(clause_LiteralPredicate(Literal),
clause_LiteralPredicate(nextLit))) {
/* Don't consider literals with same top symbol as given literal */
/* since the given clause must be part of any inference */
*Unifiers = list_Cons(nextLit, *Unifiers);
}
} else if (clause_LiteralGetIndex(nextLit) < clause_FirstAntecedentLitIndex(nextClause) &&
((!term_IsVariable(list_Car(candidates)) && !IsFromEmptySort) ||
(term_IsVariable(list_Car(candidates)) && IsFromEmptySort &&
clause_HasOnlyVarsInConstraint(nextClause,Flags, Precedence)))) {
*ConstraintLits = list_Cons(nextLit, *ConstraintLits);
}
}
} /* litScan */
}
} /* atomScan */
}
} /* candidates */
/* We have to avoid constraint literals from the same clause with the same
term or variable, since those would create the same result clause. */
*ConstraintLits =
list_DeleteDuplicates(*ConstraintLits,
(BOOL (*)(POINTER,POINTER)) inf_LiteralsHaveSameSubtermAndAreFromSameClause);
}
static void inf_MakeClausesDisjoint(CLAUSE GClause, LIST Literals)
/**************************************************************
INPUT: A clause and a non-empty list of literals.
EFFECT: All input clauses, those pointed to by the literals,
are variable disjointly renamed.
***************************************************************/
{
SYMBOL maxVar, maxCand;
CLAUSE lastClause;
maxVar = clause_MaxVar(GClause);
lastClause = clause_LiteralOwningClause(list_Car(Literals));
clause_RenameVarsBiggerThan(lastClause, maxVar);
Literals = list_Cdr(Literals);
for ( ; !list_Empty(Literals); Literals = list_Cdr(Literals)) {
CLAUSE actClause;
clause_UpdateMaxVar(lastClause);
maxCand = clause_MaxVar(lastClause);
maxVar = (symbol_GreaterVariable(maxVar,maxCand)? maxVar : maxCand);
actClause = clause_LiteralOwningClause(list_Car(Literals));
clause_RenameVarsBiggerThan(actClause, maxVar);
}
}
static void inf_CopyUnifierClauses(LIST Literals)
/**************************************************************
INPUT: A list of literals.
EFFECT: Replaces all literals by pointers to literals of copies
of the respective clauses.
***************************************************************/
{
for ( ; !list_Empty(Literals); Literals = list_Cdr(Literals)) {
CLAUSE actClause;
int i;
actClause = clause_LiteralOwningClause(list_Car(Literals));
i = clause_LiteralGetIndex(list_Car(Literals));
actClause = clause_Copy(actClause);
list_Rplaca(Literals, clause_GetLiteral(actClause, i)); /* Set to literal from copy */
}
}
static void inf_DeleteUnifierClauses(LIST Literals)
/**************************************************************
INPUT: A list of literals.
EFFECT: Deletes all clauses the literals point to.
***************************************************************/
{
for ( ; !list_Empty(Literals); Literals = list_Cdr(Literals)) {
clause_Delete(clause_LiteralOwningClause(list_Car(Literals)));
list_Rplaca(Literals, NULL);
}
}
static SORT inf_GetSortFromLits(LIST Literals, SORTTHEORY SortTheory)
/**************************************************************
INPUT: A list of literals and a sort theory.
RETURNS: The sort created from the literals' predicates.
***************************************************************/
{
SORT result = sort_TopSort();
for ( ; !list_Empty(Literals); Literals = list_Cdr(Literals)) {
SORT newSort = sort_TheorySortOfSymbol(SortTheory,
clause_LiteralPredicate(list_Car(Literals)));
result = sort_Intersect(newSort, result);
}
list_PointerDeleteDuplicates(result);
return result;
}
static LIST inf_ApplyWeakening(CLAUSE Clause, LIST TLits, LIST Partners,
LIST Clauses, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause, a list of constraint indices in <Clause>,
a list of maximal, monadic succedent literals,
a subsort condition, a flag store and a precedence.
RETURNS: A one-element list with a clause derived from the
clause and the partner clauses by the Weakening or
Empty Sort rule.
The flag store is needed to create the result clause.
MEMORY: Memory is allocated for the returned list and the clause.
***************************************************************/
{
LIST scan, parents;
LIST constraint, antecedent, succedent;
LIST parentClauses, parentLits; /* clause numbers and literal indices */
intptr_t i;
int bound, depth;
TERM tSubterm;
CLAUSE newClause;
#ifdef CHECK
if (!clause_IsClause(Clause, Flags, Precedence) || list_Empty(TLits) ||
list_Empty(Partners) || Clauses == NULL) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_ApplyWeakening: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
constraint = antecedent = succedent = list_Nil();
parentClauses = parentLits = list_Nil();
parents = list_Nil(); /* Used to set split data */
depth = clause_Depth(Clause);
tSubterm = term_FirstArgument(clause_GetLiteralAtom(Clause, (intptr_t)list_Car(TLits)));
/* update parents and depth from condition clauses */
for (scan=Clauses; !list_Empty(scan); scan=list_Cdr(scan)) {
CLAUSE condClause;
condClause = list_Car(scan);
parents = list_Cons(condClause, parents);
parentClauses = list_Cons((POINTER)clause_Number(condClause), parentClauses);
parentLits = list_Cons((POINTER)clause_FirstSuccedentLitIndex(condClause), parentLits);
depth = misc_Max(depth, clause_Depth(condClause));
}
/* Now we consider the partner clauses */
for (scan = Partners; !list_Empty(scan); scan = list_Cdr(scan)) {
LITERAL pLit;
CLAUSE pClause;
intptr_t pi;
pLit = list_Car(scan);
pClause = clause_LiteralOwningClause(pLit);
pi = clause_LiteralGetIndex(pLit);
bound = clause_LastConstraintLitIndex(pClause);
for (i = clause_FirstLitIndex(); i <= bound; i++) {
constraint = list_Cons(cont_CopyAndApplyBindings(cont_RightContext(),
clause_GetLiteralAtom(pClause,i)),
constraint);
}
bound = clause_LastAntecedentLitIndex(pClause);
for (i = clause_FirstAntecedentLitIndex(pClause); i <= bound; i++) {
antecedent = list_Cons(cont_CopyAndApplyBindings(cont_RightContext(),
clause_GetLiteralAtom(pClause,i)),
antecedent);
}
bound = clause_LastSuccedentLitIndex(pClause);
for (i = clause_FirstSuccedentLitIndex(pClause); i <= bound; i++) {
if (i != pi)
succedent = list_Cons(cont_CopyAndApplyBindings(cont_RightContext(),
clause_GetLiteralAtom(pClause,i)),
succedent);
}
parents = list_Cons(pClause, parents);
parentClauses = list_Cons((POINTER)clause_Number(pClause), parentClauses);
parentLits = list_Cons((POINTER) pi, parentLits);
depth = misc_Max(depth, clause_Depth(pClause));
}
/* Last but not least we consider the <Clause> itself */
bound = clause_LastConstraintLitIndex(Clause);
for (i = clause_FirstLitIndex(); i <= bound; i++) {
if (!list_PointerMember(TLits, (POINTER)i))
constraint = list_Cons(cont_CopyAndApplyBindings(cont_LeftContext(),
clause_GetLiteralAtom(Clause,i)),
constraint);
else {
parentClauses = list_Cons((POINTER)clause_Number(Clause), parentClauses);
parentLits = list_Cons((POINTER)i, parentLits);
}
}
bound = clause_LastAntecedentLitIndex(Clause);
for (i = clause_FirstAntecedentLitIndex(Clause); i <= bound; i++) {
antecedent = list_Cons(cont_CopyAndApplyBindings(cont_LeftContext(),
clause_GetLiteralAtom(Clause,i)),
antecedent);
}
bound = clause_LastSuccedentLitIndex(Clause);
for (i = clause_FirstSuccedentLitIndex(Clause); i <= bound; i++) {
succedent = list_Cons(cont_CopyAndApplyBindings(cont_LeftContext(),
clause_GetLiteralAtom(Clause,i)),
succedent);
}
parents = list_Cons(Clause, parents);
/* Now we've got all data we need */
newClause = clause_Create(constraint, antecedent, succedent, Flags,Precedence);
list_Delete(constraint);
list_Delete(antecedent);
list_Delete(succedent);
if (term_IsVariable(tSubterm))
clause_SetFromEmptySort(newClause);
else
clause_SetFromSortResolution(newClause);
clause_SetDepth(newClause, depth+1);
clause_SetFlag(newClause, DOCCLAUSE);
clause_SetSplitDataFromList(newClause, parents);
list_Delete(parents);
clause_SetParentClauses(newClause, parentClauses);
clause_SetParentLiterals(newClause, parentLits);
return list_List(newClause);
}
static LIST inf_InternWeakening(CLAUSE Clause, LIST TLits, LIST Unifiers,
LITERAL Special, LIST SojuList, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A <Clause> with unsolved sort constraint,
a list <TLits> of constraint indices in <Clause> where
all corresponding constraints have the same term,
a list <Unifiers> of monadic succedent literals whose
subterm is unifiable with the subterm of the <TLits>,
and a flag store.
If called from a backward rule the literal <Special>
will be the succedent literal from the respective
GivenClause, that must be part of every considered
SOJU sort. If called from a forward rule <Special> is NULL.
A list <SojuList> of sort pairs.
A flag store and a precedence.
RETURNS: The list of possible resolvents.
EFFECT: ATTENTION: <SojuList> is deleted.
MEMORY: Memory is allocated for the returned list and the clauses.
***************************************************************/
{
LIST result, myUnifiers;
TERM searchTerm;
int stack;
LIST scan;
#ifdef CHECK
if (!clause_IsClause(Clause, Flags, Precedence) || list_Empty(TLits) ||
list_Empty(Unifiers)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_InternWeakening: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
putchar('\n'); clause_Print(Clause);
fputs("\nT_k = ", stdout);
for (scan = TLits; !list_Empty(scan); scan = list_Cdr(scan)) {
clause_LiteralPrint(clause_GetLiteral(Clause, (intptr_t)list_Car(scan)));
putchar(' ');
}
fputs("\nS_k =", stdout);
for (scan = Unifiers; !list_Empty(scan); scan = list_Cdr(scan)) {
putchar('\n');
clause_LiteralPrint(list_Car(scan));
fputs(" in ", stdout);
clause_Print(clause_LiteralOwningClause(list_Car(scan)));
}
putchar('\n');
if (list_Empty(SojuList))
return list_Nil();
/*return list_Nil();*/
/* Und Schluss */
result = list_Nil();
myUnifiers = list_Copy(Unifiers);
inf_CopyUnifierClauses(myUnifiers);
inf_MakeClausesDisjoint(Clause, myUnifiers);
searchTerm =
term_FirstArgument(clause_GetLiteralAtom(Clause, (intptr_t)list_Car(TLits)));
stack = stack_Bottom();
for ( ; !list_Empty(SojuList); SojuList = list_Pop(SojuList)) {
SOJU actSoju = list_Car(SojuList);
fputs("\nSOJU: ", stdout); sort_PairPrint(actSoju); fflush(stdout);
if (Special == NULL ||
sort_ContainsSymbol(sort_PairSort(actSoju),
clause_LiteralPredicate(Special))) {
LIST actSortSymbols, symbolScan, unifierScan, subset;
actSortSymbols = sort_GetSymbolsFromSort(sort_PairSort(actSoju));
subset = list_Nil();
symbolScan = actSortSymbols;
unifierScan = myUnifiers;
do {
while (!list_Empty(symbolScan) && !list_Empty(unifierScan)) {
LITERAL actLit = list_Car(unifierScan);
if (symbol_Equal(clause_LiteralPredicate(list_Car(unifierScan)),
(SYMBOL)list_Car(symbolScan))) {
cont_StartBinding();
if (unify_UnifyNoOC(cont_LeftContext(), searchTerm, cont_RightContext(),
term_FirstArgument(clause_LiteralAtom(actLit)))) {
/* Found corresponding literal for sort symbol */
stack_Push(symbolScan);
stack_Push(list_Cdr(unifierScan));
subset = list_Cons(actLit, subset);
/* Now search literals for the next sort symbol */
symbolScan = list_Cdr(symbolScan);
if (!list_Empty(symbolScan))
/* Start search for literal at the beginning of unifier list */
unifierScan = myUnifiers;
else
unifierScan = list_Cdr(unifierScan);
} else {
cont_BackTrack();
unifierScan = list_Cdr(unifierScan);
}
} else
unifierScan = list_Cdr(unifierScan);
}
if (list_Empty(symbolScan)) {
/*putchar('\n');
clause_LiteralListPrint(subset);*/
/* Found subset */
result = list_Nconc(inf_ApplyWeakening(Clause, TLits, subset,
sort_PairClauses(actSoju),
Flags, Precedence),
result);
}
while (!stack_Empty(stack) && list_Empty(stack_Top())) {
/* No more literals */
stack_NPop(2);
cont_BackTrack();
subset = list_Pop(subset);
}
if (!stack_Empty(stack)) {
/* Implies that stack_Top is a non-empty list */
unifierScan = stack_PopResult();
symbolScan = stack_PopResult();
cont_BackTrack();
subset = list_Pop(subset);
}
} while (!stack_Empty(stack) || !list_Empty(unifierScan));
list_Delete(actSortSymbols);
}
sort_PairDelete(actSoju);
} /* For all SOJUs */
inf_DeleteUnifierClauses(myUnifiers);
list_Delete(myUnifiers);
return result;
}
LIST inf_ForwardWeakening(CLAUSE GivenClause, st_INDEX Index,
SORTTHEORY SortTheory, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause, an index of clauses, a sort theory, a flag store
and a precedence.
The sort constraint of the clause must contain a non-variable term
(this implies the sort constraint is unsolved).
RETURNS: A list of clauses derived from the GivenClause by
the Weakening rule.
MEMORY: Memory is allocated for the returned list and the clauses.
***************************************************************/
{
LIST result;
intptr_t i;
int lc;
BOOL hit;
#ifdef CHECK
if (!clause_HasTermSortConstraintLits(GivenClause)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_ForwardWeakening: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
result = list_Nil();
lc = clause_LastConstraintLitIndex(GivenClause);
hit = FALSE;
for (i = clause_FirstLitIndex(); i <= lc && !hit; i++) {
if (!term_IsVariable(term_FirstArgument(clause_GetLiteralAtom(GivenClause, i)))) {
/* Condition implies that constraint is unsolved */
LITERAL tLit;
LIST unifiers;
intptr_t j;
tLit = clause_GetLiteral(GivenClause, i);
hit = TRUE; /* Try only the first appropriate constraint literal */
unifiers = inf_GetForwardPartnerLits(tLit, Index);
if (!list_Empty(unifiers)) {
TERM tAtom;
LIST tLits, sojuList;
SORT tSort, unifierSort;
tAtom = clause_GetLiteralAtom(GivenClause, i);
/* Search the other T_k(t) in GivenClause */
tLits = list_Nil();
tSort = sort_TopSort();
for (j = lc; j > i; j--) {
TERM actAtom;
actAtom = clause_GetLiteralAtom(GivenClause, j);
if (term_FirstArgument(actAtom) == term_FirstArgument(tAtom)) {
tLits = list_Cons((POINTER)j, tLits);
tSort = sort_Intersect(sort_TheorySortOfSymbol(SortTheory, term_TopSymbol(actAtom)),
tSort);
}
}
tLits = list_Cons((POINTER)i, tLits);
tSort = sort_Intersect(sort_TheorySortOfSymbol(SortTheory, term_TopSymbol(tAtom)),
tSort);
list_PointerDeleteDuplicates(tSort);
/* Necessary for Christoph's function */
unifierSort = inf_GetSortFromLits(unifiers, SortTheory);
sojuList = sort_TheoryComputeAllSubsortHits(SortTheory, unifierSort, tSort);
sort_Delete(unifierSort);
sort_Delete(tSort);
result =
list_Nconc(inf_InternWeakening(GivenClause, tLits, unifiers, NULL,
sojuList, Flags, Precedence),
result);
list_Delete(tLits);
list_Delete(unifiers);
}
}
}
return result;
}
LIST inf_BackwardWeakening(CLAUSE GivenClause, st_INDEX Index,
SORTTHEORY SortTheory, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause with solved sort constraint, an index of clauses,
a sort theory, a flag store and a precedence.
RETURNS: A list of clauses inferred from the GivenClause by
the Weakening rule.
MEMORY: Memory is allocated for the list and the clauses.
***************************************************************/
{
LIST result;
int i, ls;
#ifdef CHECK
if (!clause_HasSolvedConstraint(GivenClause)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_BackwardWeakening: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
result = list_Nil();
ls = clause_LastSuccedentLitIndex(GivenClause);
for (i = clause_FirstSuccedentLitIndex(GivenClause); i <= ls; i++) {
LITERAL sLit;
TERM sAtom;
sLit = clause_GetLiteral(GivenClause, i);
sAtom = clause_LiteralAtom(sLit);
if (clause_LiteralGetFlag(sLit, STRICTMAXIMAL) &&
clause_LiteralIsSort(sLit) &&
(!term_IsVariable(term_FirstArgument(sAtom)) ||
clause_HasEmptyConstraint(GivenClause))) {
LIST unifiers, partners;
SORT unifierSort;
unifiers = partners = list_Nil();
inf_GetBackwardPartnerLits(sLit,Index,&partners,&unifiers,FALSE,Flags,
Precedence);
unifiers = list_Cons(sLit, unifiers);
/* <partners> holds monadic constraint literals */
/* <unifiers> holds monadic, maximal succedent literals */
unifierSort = inf_GetSortFromLits(unifiers, SortTheory);
for ( ; !list_Empty(partners); partners = list_Pop(partners)) {
LITERAL tLit;
CLAUSE tClause;
TERM tAtom;
intptr_t ti;
int lc;
intptr_t j;
LIST tLits, sojuList;
SORT tSort;
tLit = list_Car(partners);
tClause = clause_LiteralOwningClause(tLit);
tAtom = clause_LiteralAtom(tLit);
ti = clause_LiteralGetIndex(tLit);
lc = clause_LastConstraintLitIndex(tClause);
/* Search the other T_k(t) in GivenClause */
tLits = list_Nil();
tSort = sort_TopSort();
for (j = lc; j >= clause_FirstLitIndex(); j--) {
TERM actAtom;
actAtom = clause_GetLiteralAtom(tClause, j);
if (j != ti &&
term_FirstArgument(actAtom) == term_FirstArgument(tAtom)) {
tLits = list_Cons((POINTER)j, tLits);
tSort = sort_Intersect(sort_TheorySortOfSymbol(SortTheory, term_TopSymbol(actAtom)),
tSort);
}
}
tLits = list_Cons((POINTER)ti, tLits);
tSort = sort_Intersect(sort_TheorySortOfSymbol(SortTheory, term_TopSymbol(tAtom)),
tSort);
list_PointerDeleteDuplicates(tSort);
sojuList = sort_TheoryComputeAllSubsortHits(SortTheory, unifierSort, tSort);
sort_Delete(tSort);
cont_StartBinding();
unify_UnifyNoOC(cont_LeftContext(), tAtom,
cont_RightContext(), sAtom);
result =
list_Nconc(inf_InternWeakening(tClause, tLits, unifiers, sLit,
sojuList, Flags, Precedence),
result);
cont_BackTrack();
list_Delete(tLits);
}
sort_Delete(unifierSort);
list_Delete(unifiers);
}
}
return result;
}
LIST inf_ForwardEmptySortPlusPlus(CLAUSE GivenClause, st_INDEX Index,
SORTTHEORY SortTheory, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause, an 'Index' of clauses, a sort theory, a flag store
and a precedence.
The sort constraint of the clause must not contain a
non-variable term, but the sort constraint has to be unsolved.
RETURNS: A list of clauses derived from the GivenClause by
the Empty Sort rule.
MEMORY: Memory is allocated for the returned list and the clauses.
***************************************************************/
{
LIST result;
intptr_t i;
int lc;
BOOL hit;
#ifdef CHECK
if (clause_HasTermSortConstraintLits(GivenClause) ||
clause_HasSolvedConstraint(GivenClause)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_ForwardEmptySortPlusPlus: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
result = list_Nil();
lc = clause_LastConstraintLitIndex(GivenClause);
hit = FALSE;
for (i = clause_FirstLitIndex(); i <= lc && !hit; i++) {
if (term_IsVariable(term_FirstArgument(clause_GetLiteralAtom(GivenClause,i)))) {
LITERAL tLit;
TERM var;
intptr_t j;
int ls;
BOOL varOccursNoMore;
tLit = clause_GetLiteral(GivenClause, i);
var = term_FirstArgument(clause_LiteralAtom(tLit));
ls = clause_LastSuccedentLitIndex(GivenClause);
varOccursNoMore = TRUE;
/* Check if the variable occurs in antecedent or succedent literals */
for (j = clause_FirstAntecedentLitIndex(GivenClause);
(j <= ls) && varOccursNoMore; j++) {
if (term_ContainsSymbol(clause_GetLiteralAtom(GivenClause,j),
term_TopSymbol(var)))
varOccursNoMore = FALSE;
}
if (varOccursNoMore) {
/* Condition implies that constraint is unsolved */
LIST unifiers;
unifiers = inf_GetForwardPartnerLits(tLit, Index);
hit = TRUE; /* We found the first appropriate constraint literal */
if (!list_Empty(unifiers)) {
TERM tAtom = clause_LiteralAtom(tLit);
LIST tLits, sojuList;
SORT tSort, unifierSort;
/* Search the other T_k(t) in GivenClause */
tLits = list_Nil();
tSort = sort_TopSort();
for (j = lc; j > i; j--) {
TERM actAtom;
actAtom = clause_GetLiteralAtom(GivenClause, j);
if (term_FirstArgument(actAtom) == var) { /* tClause is shared */
tLits = list_Cons((POINTER)j, tLits);
tSort = sort_Intersect(sort_TheorySortOfSymbol(SortTheory,
term_TopSymbol(actAtom)),
tSort);
}
}
tLits = list_Cons((POINTER)i, tLits);
tSort = sort_Intersect(sort_TheorySortOfSymbol(SortTheory,
term_TopSymbol(tAtom)),
tSort);
list_PointerDeleteDuplicates(tSort);
unifierSort = inf_GetSortFromLits(unifiers, SortTheory);
sojuList = sort_TheoryComputeAllSubsortHits(SortTheory, unifierSort, tSort);
sort_Delete(unifierSort);
sort_Delete(tSort);
result =
list_Nconc(inf_InternWeakening(GivenClause, tLits, unifiers, NULL,
sojuList, Flags, Precedence),
result);
list_Delete(tLits);
list_Delete(unifiers);
}
}
}
}
return result;
}
LIST inf_BackwardEmptySortPlusPlus(CLAUSE GivenClause, st_INDEX Index,
SORTTHEORY SortTheory, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause with solved sort constraint, an index of clauses,
a sort theory, a flag store and a precedence.
RETURNS: A list of clauses inferred from the GivenClause by
the Empty Sort rule.
MEMORY: Memory is allocated for the list and the clauses.
***************************************************************/
{
LIST result;
int i, ls;
#ifdef CHECK
if (!clause_HasSolvedConstraint(GivenClause)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_BackwardEmptySortPlusPlus: Illegal input.\n");
misc_FinishErrorReport();
}
#endif
result = list_Nil();
ls = clause_LastSuccedentLitIndex(GivenClause);
for (i = clause_FirstSuccedentLitIndex(GivenClause); i <= ls; i++) {
LITERAL sLit;
TERM sAtom;
sLit = clause_GetLiteral(GivenClause, i);
sAtom = clause_LiteralAtom(sLit);
if (clause_LiteralGetFlag(sLit,STRICTMAXIMAL) &&
clause_LiteralIsSort(sLit) &&
(!term_IsVariable(term_FirstArgument(sAtom)) ||
clause_HasEmptyConstraint(GivenClause))) {
LIST unifiers, partners;
SORT unifierSort;
unifiers = partners = list_Nil();
inf_GetBackwardPartnerLits(sLit, Index, &partners, &unifiers, TRUE, Flags,
Precedence);
unifiers = list_Cons(sLit, unifiers);
/* <partners> holds monadic constraint literals */
/* <unifiers> holds monadic, maximal succedent literals */
unifierSort = inf_GetSortFromLits(unifiers, SortTheory);
for ( ; !list_Empty(partners); partners = list_Pop(partners)) {
LITERAL tLit;
CLAUSE tClause;
TERM tAtom;
intptr_t ti;
int li;
TERM var;
BOOL varOccursNoMore;
intptr_t j;
tLit = list_Car(partners);
tClause = clause_LiteralOwningClause(tLit);
tAtom = clause_LiteralAtom(tLit);
ti = clause_LiteralGetIndex(tLit);
li = clause_LastSuccedentLitIndex(tClause);
var = term_FirstArgument(tAtom);
varOccursNoMore = TRUE;
for (j = clause_FirstAntecedentLitIndex(tClause);
j <= li && varOccursNoMore;
j++) {
if (term_ContainsSymbol(clause_GetLiteralAtom(tClause,j),
term_TopSymbol(var)))
varOccursNoMore = FALSE;
}
if (varOccursNoMore) {
/* Condition implies that constraint is unsolved */
int lc;
LIST tLits, sojuList;
SORT tSort;
lc = clause_LastConstraintLitIndex(tClause);
/* Search the other T_k(t) in GivenClause */
tLits = list_Nil();
tSort = sort_TopSort();
for (j = lc; j >= clause_FirstLitIndex(); j--) {
TERM actAtom;
actAtom = clause_GetLiteralAtom(tClause, j);
if (j != ti &&
term_TopSymbol(term_FirstArgument(actAtom)) == term_TopSymbol(var)) {
tLits = list_Cons((POINTER)j, tLits);
tSort = sort_Intersect(sort_TheorySortOfSymbol(SortTheory, term_TopSymbol(actAtom)),
tSort);
}
}
tLits = list_Cons((POINTER)ti, tLits);
tSort = sort_Intersect(sort_TheorySortOfSymbol(SortTheory, term_TopSymbol(tAtom)),
tSort);
list_PointerDeleteDuplicates(tSort);
sojuList = sort_TheoryComputeAllSubsortHits(SortTheory, unifierSort, tSort);
sort_Delete(tSort);
cont_StartBinding();
unify_UnifyNoOC(cont_LeftContext(), tAtom,
cont_RightContext(), sAtom);
result =
list_Nconc(inf_InternWeakening(tClause, tLits, unifiers, sLit,
sojuList, Flags, Precedence),
result);
cont_BackTrack();
list_Delete(tLits);
}
}
sort_Delete(unifierSort);
list_Delete(unifiers);
}
}
return result;
}
|