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
|
/**************************************************************/
/* ********************************************************** */
/* * * */
/* * PROOF CHECKING * */
/* * * */
/* * Copyright (C) 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.5 $ * */
/* $State: Exp $ * */
/* $Date: 2011-05-25 06:50:40 $ * */
/* $Author: weidenb $ * */
/* * * */
/* * * */
/* * Contact: * */
/* * Christoph Weidenbach * */
/* * MPI fuer Informatik * */
/* * Stuhlsatzenhausweg 85 * */
/* * 66123 Saarbruecken * */
/* * Email: spass@mpi-inf.mpg.de * */
/* * Germany * */
/* * * */
/* ********************************************************** */
/* $RCSfile: proofcheck.c,v $ */
#include "proofcheck.h"
/* options */
int pcheck_Timelimit;
const char *pcheck_ProofFileSuffix;
BOOL pcheck_Quiet;
/* options for graph generation */
BOOL pcheck_ClauseCg;
BOOL pcheck_GenNamedCg, pcheck_GenRedCg;
const char *pcheck_CgName, *pcheck_RedCgName;
GRAPHFORMAT pcheck_GraphFormat;
static int pcheck_MaxSplitLevel(LIST Clauses)
/**************************************************************
INPUT: A list of clauses.
RETURNS: The maximum split level of a clause.
***************************************************************/
{
int Max;
int Act;
Max = 0;
while (!list_Empty(Clauses)) {
Act = clause_SplitLevel(list_Car(Clauses));
if (Act > Max)
Max = Act;
Clauses = list_Cdr(Clauses);
}
return Max;
}
int pcheck_MaxParentSplitLevel(CLAUSE Clause)
/**************************************************************
INPUT: A clause
RETURNS: The max split level of the parent clauses
***************************************************************/
{
return pcheck_MaxSplitLevel(clause_ParentClauses(Clause));
}
static BOOL pcheck_ClauseIsFromLeftSplit(CLAUSE Clause)
/**************************************************************
INPUT : A Clause
RETURNS: TRUE iff the clause is the left half of a split
CAUTION: This works also for clauses without parents, since
pcheck_MaxParentSplitLevel returns 0 in that case.
***************************************************************/
{
return (clause_SplitLevel(Clause) > pcheck_MaxParentSplitLevel(Clause));
}
static BOOL pcheck_ClauseIsFromRightSplit(CLAUSE Clause)
/**************************************************************
INPUT: A clause
RETURNS: TRUE iff the clause is from the right half of a split
***************************************************************/
{
if (list_Empty(clause_ParentClauses(Clause)))
return FALSE;
return clause_IsEmptyClause(list_Car(clause_ParentClauses(Clause)));
}
static BOOL pcheck_ClauseIsFromSplit(CLAUSE Clause)
/**************************************************************
INPUT : A clause
RETURNS: TRUE iff the clause is from a split
***************************************************************/
{
return (pcheck_ClauseIsFromRightSplit(Clause) ||
pcheck_ClauseIsFromLeftSplit(Clause));
}
static intptr_t pcheck_LabelToNumber(const char* Label)
/**************************************************************
INPUT: A clause label
RETURNS: The label converted to a number.
EFFECT: If the conversion fails an error message is printed
and the program exits.
***************************************************************/
{
intptr_t Number;
if (!string_StringToInt(Label, FALSE, &Number)) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n In pcheck_LabelToNumber:");
misc_UserErrorReport(" Could not convert clause");
misc_UserErrorReport(" label %s to a number.\n", Label);
misc_FinishUserErrorReport();
}
return Number;
}
static int pcheck_CompareNumberAndClause(const void* Number, const void* ClausePtr)
/**************************************************************
INPUT: A number and a pointer to a CLAUSE.
RETURNS: 1) a negative number if <number> is < number of <Clause>
2) 0 if <Number> is equal to the number of <Clause>
3) a positive number if <Number> is > number of <Clause>
EFFECT: This function is used as parameter to the bsearch function.
***************************************************************/
{
return (intptr_t)Number - clause_Number(*(const CLAUSE*)ClausePtr);
}
static void pcheck_ParentNumbersToPointersInVector(CLAUSE* ClauseVector, int Size)
/**************************************************************
INPUT: A clause vector without duplicate clauses and the maximal
number of elements in the vector
EFFECTS: All clause parent numbers are replaced by pointers
to the parents.
CAUTION: The clause vector has to be sorted by increasing
clause numbers, since this function performs a binary search
on the vector.
***************************************************************/
{
int Position;
LIST NewParents, OldParents;
LIST ScanParents;
intptr_t ParentNum;
CLAUSE* Parent;
for (Position = 0; Position < Size; Position++) {
OldParents = clause_ParentClauses(ClauseVector[Position]);
NewParents = list_Copy(OldParents);
for (ScanParents = NewParents; !list_Empty(ScanParents); ScanParents = list_Cdr(ScanParents)) {
ParentNum = (intptr_t)list_Car(ScanParents);
/* Binary search for parent clause with number <ParentNum>. */
Parent = bsearch((const void*)ParentNum, ClauseVector, Size,
sizeof(CLAUSE), pcheck_CompareNumberAndClause);
if (Parent != NULL)
list_Rplaca(ScanParents, *Parent);
else {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Missing parent clause %d of clause %d.\n",
ParentNum, clause_Number(ClauseVector[Position]));
misc_FinishUserErrorReport();
}
}
clause_SetParentClauses(ClauseVector[Position], NewParents);
list_Delete(OldParents);
}
}
static LIST pcheck_ForceParentNumbersToPointersInVector(CLAUSE* ClauseVector,
int Size)
/**************************************************************
INPUT: A clause vector, possibly with duplicates
RETURNS: All numbers of clauses <c> that are missing a parent clause
from the transitive hull of parent clauses of <c>.
EFFECTS: All MARKED and HIDDEN flags of the clauses are changed.
All parent numbers are converted to pointers, if the
parents exist, otherwise the parent number is deleted
from the list.
The parent literal list is changed accordingly.
A clause <c> is marked as HIDDEN, if any clause
from the transitive hull of parent clauses of <c>
was missing in <ClauseVector>.
***************************************************************/
{
int Position;
LIST NewParents, NewPLits, Parents, PLits, Missing;
intptr_t ParentNum, PLitNum;
CLAUSE *Parent, Clause;
Missing = list_Nil();
for (Position = 0; Position < Size; Position++) {
clause_RemoveFlag(ClauseVector[Position], MARKED);
clause_RemoveFlag(ClauseVector[Position], HIDDEN);
}
for (Position = 0; Position < Size; Position++) {
Clause = ClauseVector[Position];
if (!clause_GetFlag(Clause, MARKED)) {
clause_SetFlag(Clause, MARKED);
Parents = clause_ParentClauses(Clause);
PLits = clause_ParentLiterals(Clause);
NewParents = list_Nil();
NewPLits = list_Nil();
while (!list_Empty(Parents)) {
ParentNum = (intptr_t)list_Car(Parents);
PLitNum = (intptr_t)list_Car(PLits);
/* Binary search for parent clause with number <ParentNum>. */
Parent = bsearch((const void*)ParentNum, ClauseVector, Size,
sizeof(CLAUSE), pcheck_CompareNumberAndClause);
if (Parent == NULL) {
Missing = list_Cons((POINTER)ParentNum, Missing);
clause_SetFlag(Clause, HIDDEN);
} else {
if (clause_GetFlag(*Parent, HIDDEN))
clause_SetFlag(Clause, HIDDEN);
NewParents = list_Cons((POINTER)*Parent, NewParents);
NewPLits = list_Cons((POINTER)PLitNum, NewPLits);
}
Parents = list_Cdr(Parents);
PLits = list_Cdr(PLits);
}
list_Delete(clause_ParentClauses(Clause));
list_Delete(clause_ParentLiterals(Clause));
NewParents = list_NReverse(NewParents);
NewPLits = list_NReverse(NewPLits);
clause_SetParentClauses(Clause, NewParents);
clause_SetParentLiterals(Clause, NewPLits);
} /* if clause is not marked */
} /* for all clauses */
return Missing;
}
static int pcheck_CompareClauseNumber(const void* C1, const void* C2)
/**************************************************************
INPUT : Two pointers to CLAUSEs.
RETURNS: 1) a negative number if the number of C1 is < number of C2.
2) 0 if C1 and C2 have the same clause number
(that means a possible bug in SPASS)
3) a positive number if number of C1 > number of C2
EFFECT: This function is used as parameter to the qsort function.
************************************************************/
{
return clause_Number(*(const CLAUSE*)C1) - clause_Number(*(const CLAUSE*)C2);
}
static LIST pcheck_ConvertParentsInList(LIST List)
/**************************************************************
INPUT: A list of clauses.
RETURNS: The list of missing parent clause numbers from the list
EFFECTS: Parent numbers are converted to pointers
***************************************************************/
{
int Size, Index;
CLAUSE* ClauseVector;
LIST Missing;
Size = list_Length(List);
if (Size == 0)
return list_Nil();
/* convert list into vector for binary search */
ClauseVector = (CLAUSE*)memory_Malloc(sizeof(CLAUSE) * Size);
for (Index = 0; !list_Empty(List); List = list_Cdr(List), Index++)
ClauseVector[Index] = list_Car(List);
/* sort the clauses in vector by increasing clause number */
qsort(ClauseVector, Size, sizeof(CLAUSE), pcheck_CompareClauseNumber);
/* convert parent lists */
Missing = pcheck_ForceParentNumbersToPointersInVector(ClauseVector, Size);
memory_Free(ClauseVector, sizeof(CLAUSE) * Size);
return Missing;
}
LIST pcheck_ConvertParentsInSPASSProof(PROOFSEARCH Search, LIST EmptyClauses)
/**************************************************************
INPUT : A proofsearch object with clauses sorted by weight
and an unsorted list <EmptyClauses>
RETURNS: The lists, where the clauses in <EmptyClauses> are
now sorted by weight, and parent numbers
in the clauses are replaced by parent pointers
***************************************************************/
{
LIST AllLists;
LIST Missing;
AllLists = list_Nconc(list_Copy(prfs_DocProofClauses(Search)),
list_Copy(EmptyClauses));
AllLists = list_Nconc(list_Copy(prfs_UsableClauses(Search)), AllLists);
AllLists = list_Nconc(list_Copy(prfs_WorkedOffClauses(Search)), AllLists);
AllLists = pcheck_ClauseNumberMergeSort(AllLists);
Missing = pcheck_ConvertParentsInList(AllLists);
list_Delete(AllLists);
return Missing;
}
static LIST pcheck_ParentNumbersToParents(LIST Proof)
/**************************************************************
INPUT: A list of clauses, representing a proof.
RETURNS: The list, where parent numbers in the
parent list of clauses are replaced
by the parents (pointers).
CAUTION: For finding the clause corresponding to a
a clause number, the <Proof> list is searched
with binary search. This is correct only if
the clause numbers in <Proof> are increasing.
************************************************************/
{
LIST ScanClauses;
int ProofLength, Position;
CLAUSE* ClauseVector;
if (list_Empty(Proof))
return list_Nil();
/* convert list into vector for binary search */
ProofLength = list_Length(Proof);
ClauseVector = (CLAUSE*) memory_Malloc(ProofLength * sizeof(CLAUSE));
for (ScanClauses = Proof, Position = 0; !list_Empty(ScanClauses);
ScanClauses = list_Cdr(ScanClauses), Position++) {
ClauseVector[Position] = list_Car(ScanClauses);
}
/* sort the clauses in vector by increasing clause number */
qsort(ClauseVector, ProofLength, sizeof(CLAUSE), pcheck_CompareClauseNumber);
/* convert parent lists */
pcheck_ParentNumbersToPointersInVector(ClauseVector, ProofLength);
memory_Free(ClauseVector, ProofLength * sizeof(CLAUSE));
return Proof;
}
LIST pcheck_ParentPointersToParentNumbers(LIST Clauses)
/**************************************************************
INPUT : A list of clauses
RETURNS: The list with parent pointers replaced by
parent numbers
EFFECTS: Sets marks on all clauses.
***************************************************************/
{
LIST ScanClauses;
LIST ScanParents;
pcheck_ClauseListRemoveFlag(Clauses, MARKED);
for (ScanClauses = Clauses; !list_Empty(ScanClauses); ScanClauses = list_Cdr(ScanClauses)) {
if (!clause_GetFlag(list_Car(ScanClauses), MARKED)) {
for (ScanParents = clause_ParentClauses(list_Car(ScanClauses)); !list_Empty(ScanParents);
ScanParents = list_Cdr(ScanParents))
list_Rplaca(ScanParents, (POINTER)clause_Number(list_Car(ScanParents)));
clause_SetFlag(list_Car(ScanClauses), MARKED);
}
}
return Clauses;
}
LIST pcheck_ConvertTermListToClauseList(LIST ProofRest, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A list of quintupels (lists) representing a proof,
a flag store, and a precedence.
RETURNS: The conversion of this list into the internal clause
structure. For each clause, the numbers of parent
clauses are replaced by pointers to the parents.
***************************************************************/
{
LIST Clauses;
LIST ProofLine;
TERM ClauseTerm;
CLAUSE Clause;
intptr_t Level;
int ClauseNumber;
LIST ParentLabels;
LIST ParentIds;
LIST ParentLits; /* this is a dummy list; parent lits are not yet specified in a SPASS proof */
RULE Origin;
char* ClauseLabel;
Clauses = list_Nil(); /* result */
while (!list_Empty(ProofRest)) {
/* break proof line into components */
ProofLine = list_Car(ProofRest);
ClauseLabel = list_First(ProofLine);
ClauseTerm = list_Second(ProofLine);
/* replace by NULL clause, since dfg_CreateClauseFromTerm deletes clause ! */
list_Rplaca(list_Cdr(ProofLine), clause_Null());
ParentLabels = (LIST)list_Third(ProofLine);
Level = (intptr_t)list_Fourth(ProofLine);
Origin = (RULE)list_Fifth(ProofLine);
/* Conversion */
Clause = dfg_CreateClauseFromTerm(ClauseTerm, TRUE, Flags,Precedence);
/* It's necessary to update the weight since dfg_CreateClauseFromTerm */
/* doesn't set it. */
clause_UpdateWeight(Clause, Flags);
ClauseNumber = pcheck_LabelToNumber(ClauseLabel);
ParentIds = list_Nil();
ParentLits = list_Nil();
while (!list_Empty(ParentLabels)) {
ParentIds = list_Cons((POINTER)pcheck_LabelToNumber(list_Car(ParentLabels)), ParentIds);
ParentLits = list_Cons(0, ParentLits);
ParentLabels = list_Cdr(ParentLabels);
}
/* set all data */
clause_SetNumber(Clause, ClauseNumber);
ParentIds = list_NReverse(ParentIds);
clause_SetParentClauses(Clause, ParentIds);
clause_SetParentLiterals(Clause, ParentLits);
Clause->origin = Origin;
clause_SetSplitLevel(Clause, Level);
if (Level > 0) {
clause_ClearSplitField(Clause);
clause_SetSplitFieldBit(Clause, Level);
} else
clause_SetSplitField(Clause, (SPLITFIELD)NULL,0);
clause_RemoveFlag(Clause, MARKED);
Clauses = list_Cons(Clause, Clauses);
ProofRest = list_Cdr(ProofRest);
}
Clauses = list_NReverse(Clauses);
/* convert parent numbers to pointers */
Clauses = pcheck_ParentNumbersToParents(Clauses);
return Clauses;
}
static BOOL pcheck_ClauseIsUnmarked(CLAUSE C)
/**************************************************************
INPUT: A clause
RETURNS: The value of the clauses MARKED flag
***************************************************************/
{
return !clause_GetFlag(C, MARKED);
}
static void pcheck_RemoveUnmarkedFromTableau(TABLEAU T)
/**************************************************************
INPUT: A tableau
RETURNS: Nothing.
EFFECTS: Delete all clauses that have the MARKED flag
set from tableau.
***************************************************************/
{
if (tab_IsEmpty(T))
return;
tab_SetClauses(T, list_DeleteElementIf(tab_Clauses(T),
(BOOL (*)(POINTER))pcheck_ClauseIsUnmarked));
pcheck_RemoveUnmarkedFromTableau(tab_LeftBranch(T));
pcheck_RemoveUnmarkedFromTableau(tab_RightBranch(T));
}
static void pcheck_CollectUnmarkedSplits(TABLEAU T, LIST* Splits)
/**************************************************************
INPUT: A tableau, a list of clauses by reference
RETURNS: Nothing.
EFFECTS: Add all split clauses in the tableau that are not
marked to the <Splits> list.
***************************************************************/
{
LIST Scan;
if (tab_IsEmpty(T))
return;
for (Scan = tab_Clauses(T); !list_Empty(Scan); Scan = list_Cdr(Scan)) {
if (!clause_GetFlag(list_Car(Scan), MARKED) && clause_IsFromSplitting(list_Car(Scan)))
(*Splits) = list_Cons(list_Car(Scan), *Splits);
}
pcheck_CollectUnmarkedSplits(tab_LeftBranch(T), Splits);
pcheck_CollectUnmarkedSplits(tab_RightBranch(T), Splits);
}
/* EK: unused, only recursive */
void pcheck_TableauSplitsComplete(TABLEAU T)
/**************************************************************
INPUT : A tableau
RETURNS: Checks that every split has exactly two or no
successors. This condition must be true after
tab_RemoveRedundantSplits has been called.
***************************************************************/
{
if (tab_IsEmpty(T))
return;
if (tab_RightBranchIsEmpty(T) && !tab_LeftBranchIsEmpty(T)) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Split of clause %d has no right branch.\n",
clause_Number(tab_SplitClause(T)));
misc_FinishUserErrorReport();
}
if (!tab_RightBranchIsEmpty(T) && tab_LeftBranchIsEmpty(T)) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Split of clause %d has no left branch.\n",
clause_Number(tab_SplitClause(T)));
misc_FinishUserErrorReport();
}
pcheck_TableauSplitsComplete(tab_LeftBranch(T));
pcheck_TableauSplitsComplete(tab_RightBranch(T));
}
static void pcheck_RightSplitParents(CLAUSE SplitClause, CLAUSE RightSplitClause,
CLAUSE LeftSplitClause)
/**************************************************************
INPUT: A split clause, and its left and right successors
EFFECTS: Prints an error message if the split is not correctly
closed.
***************************************************************/
{
LIST Scan;
BOOL HasEmpty, ContainsSplitClause;
HasEmpty = ContainsSplitClause = FALSE;
for (Scan = clause_ParentClauses(RightSplitClause);
!list_Empty(Scan); Scan = list_Cdr(Scan)) {
if (clause_IsEmptyClause(list_Car(Scan)))
HasEmpty = TRUE;
if (clause_Number(list_Car(Scan)) == clause_Number(SplitClause))
ContainsSplitClause = TRUE;
}
if (!HasEmpty) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Right split clause %d has no empty clause as parent.\n",
clause_Number(SplitClause));
misc_FinishUserErrorReport();
}
if (!ContainsSplitClause) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Right split clause %d", clause_Number(SplitClause));
misc_UserErrorReport(" does not have its split parent as parent clause.\n");
misc_FinishUserErrorReport();
}
}
/* EK: unused, only recursive */
void pcheck_SplitFormats(TABLEAU T)
/**************************************************************
INPUT : A tableau
RETURNS: TRUE iff all splits:
- have generated negations of the left split clause
if the left split clause is ground
- the conditions for right split clauses are
as demanded in pcheck_RightSplitParents
***************************************************************/
{
LIST Scan;
if (tab_IsEmpty(T))
return;
/* for right splits, check that parents have an empty clause */
/* and the split clause as a parent */
for (Scan = tab_RightSplitClauses(T); !list_Empty(Scan);
Scan = list_Cdr(Scan)) {
pcheck_RightSplitParents(tab_SplitClause(T), list_Car(Scan),
tab_LeftSplitClause(T));
}
pcheck_SplitFormats(tab_RightBranch(T));
pcheck_SplitFormats(tab_LeftBranch(T));
}
static void pcheck_SplitLevels(TABLEAU T)
/**************************************************************
INPUT : A Tableau
RETURNS: TRUE iff all clauses in the tableau that
are not splitting clauses have the max split
level of their parents.
CAUTION: We assume that <T> has correct and complete split
entries. See pcheck_SplitToProblems.
***************************************************************/
{
LIST Scan;
CLAUSE Clause;
int CorrectLevel;
if (tab_IsEmpty(T))
return;
/* check split levels */
for (Scan = tab_Clauses(T); !list_Empty(Scan); Scan = list_Cdr(Scan)) {
Clause = list_Car(Scan);
if (!list_Empty(clause_ParentClauses(Clause))
&& !clause_IsFromSplitting(Clause)) {
CorrectLevel = pcheck_MaxParentSplitLevel(Clause);
if (clause_SplitLevel(Clause) != CorrectLevel) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Split level of clause %d should be %d.\n",
clause_Number(Clause), CorrectLevel);
misc_FinishUserErrorReport();
}
}
}
pcheck_SplitLevels(tab_RightBranch(T));
pcheck_SplitLevels(tab_LeftBranch(T));
}
/* EK: unused, only recursive */
void pcheck_SplitPrecheck(TABLEAU T)
/**************************************************************
INPUT : A tableau.
EFFECTS: Stops and prints an error message if a left half
of a split does not subsume its parents, or
if negations have been generated for a non-ground
left split clause.
***************************************************************/
{
if (tab_IsEmpty(T))
return;
if (!subs_Subsumes(tab_LeftSplitClause(T), tab_SplitClause(T), -1, -1)) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Incorrect split of %d,", tab_SplitClause(T));
misc_UserErrorReport(" left half of split does not subsume splitted clause.\n");
misc_FinishUserErrorReport();
}
if (list_Length(tab_RightSplitClauses(T)) > 1 &&
!clause_IsGround(tab_LeftSplitClause(T))) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Incorrect split of %d,", tab_SplitClause(T));
misc_UserErrorReport(" non-ground split generated more than two clause.\n");
misc_FinishUserErrorReport();
}
pcheck_SplitPrecheck(tab_LeftBranch(T));
pcheck_SplitPrecheck(tab_RightBranch(T));
}
BOOL pcheck_BuildTableauFromProof(LIST Proof, TABLEAU* Tableau)
/**************************************************************
INPUT : A list of clauses representing a proof, and a pointer
to a tableau used as return value.
RETURNS: TRUE iff no errors occurred, FALSE otherwise.
If TRUE is returned <Tableau> is set to a tableau
representing the proof.
EFFECTS: Errors are commented when they occur.
***************************************************************/
{
LIST ProofRest;
TABLEAU SplitPos;
TABPATH Path;
CLAUSE Clause;
int ClauseLevel, SplitLevel;
int ProofDepth;
if (list_Empty(Proof)) {
*Tableau = tab_EmptyTableau();
return TRUE;
}
ProofDepth = pcheck_MaxSplitLevel(Proof);
*Tableau = tab_CreateNode();
Path = tab_PathCreate(ProofDepth, *Tableau);
ProofRest = Proof;
while (!list_Empty(ProofRest)) {
SplitLevel = tab_PathLength(Path);
Clause = list_Car(ProofRest);
ClauseLevel = clause_SplitLevel(Clause);
/* Special treatment for clauses that result from a splitting step */
if (pcheck_ClauseIsFromSplit(Clause)) {
if (ClauseLevel == 0) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Split level of split clause %d is 0.\n", clause_Number(Clause));
misc_FinishUserErrorReport();
}
if (ClauseLevel > SplitLevel+1) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Split level of split clause %d", clause_Number(Clause));
misc_UserErrorReport(" is not increment of current split level.\n");
misc_FinishUserErrorReport();
}
SplitPos = tab_PathNthNode(Path, ClauseLevel-1);
if (pcheck_ClauseIsFromLeftSplit(Clause)) {
/* Left branch of a splitting step */
if (!tab_LeftBranchIsEmpty(SplitPos)) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Multiple left splits for clause %d.\n",
clause_Number(tab_SplitClause(SplitPos)));
misc_FinishUserErrorReport();
}
Path = tab_PathPrefix(ClauseLevel-1, Path);
tab_SetSplitClause(SplitPos, list_Car(clause_ParentClauses(Clause)));
tab_SetLeftSplitClause(SplitPos, Clause);
tab_AddSplitAtCursor(Path, TRUE);
} else {
/* Right branch of a splitting step */
if (tab_RightBranchIsEmpty(SplitPos)) {
if (tab_LeftBranchIsEmpty(SplitPos)) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Right split with incorrect split level, clause %d.\n",
clause_Number(Clause));
misc_FinishUserErrorReport();
}
Path = tab_PathPrefix(ClauseLevel-1, Path);
tab_AddSplitAtCursor(Path, FALSE);
}
tab_AddRightSplitClause(SplitPos, Clause);
} /* clause from right split */
} /* clause from split */
if (ClauseLevel > tab_PathLength(Path)) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Split level of clause %d greater than current level.\n",
clause_Number(Clause));
misc_FinishUserErrorReport();
}
tab_AddClauseOnItsLevel(Clause, Path);
ProofRest = list_Cdr(ProofRest);
} /* while proof is not empty */
tab_PathDelete(Path);
return TRUE;
}
static BOOL pcheck_TableauJustificationsRec(TABLEAU T, TABPATH Path)
/**************************************************************
INPUT : A Tableau <T>, a <Path> in the tableau
RETURNS: TRUE iff all clauses in the last node of the
path are correctly justified.
***************************************************************/
{
CLAUSE Clause;
LIST ScanClauses;
LIST ScanParents;
LIST Parents;
CLAUSE Parent;
BOOL Ok, RightSplit;
if (tab_IsEmpty(T))
return TRUE;
Ok = TRUE;
/* for each clause, check that its parents have been justified */
for (ScanClauses = tab_Clauses(tab_PathTop(Path));
!list_Empty(ScanClauses); ScanClauses = list_Cdr(ScanClauses)) {
Clause = list_Car(ScanClauses);
Parents = clause_ParentClauses(Clause);
RightSplit = pcheck_ClauseIsFromRightSplit(Clause);
/* check all parents */
for (ScanParents = Parents; !list_Empty(ScanParents);
ScanParents = list_Cdr(ScanParents)) {
Parent = list_Car(ScanParents);
if ((!(RightSplit && clause_IsEmptyClause(Parent)) &&
!(RightSplit && pcheck_ClauseIsFromLeftSplit(Parent))) ||
(clause_Number(Parent) > clause_Number(Clause)) ) {
if (!tab_PathContainsClause(Path, Parent)) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Parent clause with number %d is not yet justified.\n",
clause_Number(Parent));
misc_FinishUserErrorReport();
}
}
}
} /* for all clauses in current node */
/* Recursion */
if (!tab_LeftBranchIsEmpty(T)) {
Path = tab_PathPush(tab_LeftBranch(T), Path);
Ok = Ok && pcheck_TableauJustificationsRec(tab_LeftBranch(T), Path);
Path = tab_PathPop(Path);
}
if (!tab_RightBranchIsEmpty(T)) {
Path = tab_PathPush(tab_RightBranch(T), Path);
Ok = Ok && pcheck_TableauJustificationsRec(tab_RightBranch(T), Path);
Path = tab_PathPop(Path);
}
return Ok;
}
static BOOL pcheck_TableauJustifications(TABLEAU T)
/**************************************************************
INPUT : A Tableau
RETURNS: TRUE iff for each clause in tableau, all its parent
clauses have been derived in a split on the same level
or below.
***************************************************************/
{
TABPATH Path;
BOOL Ok;
Path = tab_PathCreate(tab_Depth(T),T);
Ok = pcheck_TableauJustificationsRec(T,Path);
tab_PathDelete(Path);
return Ok;
}
BOOL pcheck_TableauProof(TABLEAU* Tableau, LIST Proof)
/**************************************************************
INPUT:
RETURNS:
***************************************************************/
{
LIST RedundantClauses;
LIST EmptyClauses;
LIST UnmarkedSplits;
tab_LabelNodes(*Tableau);
/* print out current tableau */
if (pcheck_GenNamedCg)
tab_WriteTableau(*Tableau, pcheck_CgName, pcheck_GraphFormat);
RedundantClauses = list_Nil();
if (!pcheck_Quiet) {
fputs("pruning closed branches...", stdout);
fflush(stdout);
}
(*Tableau) = tab_PruneClosedBranches(*Tableau, &RedundantClauses); /* delete descendants of already closed branches */
if (!pcheck_Quiet)
puts("finished.");
if (!pcheck_Quiet) {
fputs("removing incomplete splits...", stdout);
fflush(stdout);
}
(*Tableau) = tab_RemoveIncompleteSplits(*Tableau, &RedundantClauses); /* reduce open node redundancies */
if (!pcheck_Quiet) {
fputs("removing unfinished splits...", stdout);
fflush(stdout);
}
(*Tableau) = tab_RemoveUnfinishedSplits(*Tableau, &RedundantClauses);
if (!pcheck_Quiet)
puts("finished.");
list_Delete(RedundantClauses);
/* remove all clauses that are not needed for the empty clauses */
/* of the proof or for the tableau structure (splits) */
EmptyClauses = list_Nil();
tab_GetEarliestEmptyClauses(*Tableau, &EmptyClauses);
pcheck_ClauseListRemoveFlag(Proof, MARKED);
pcheck_MarkRecursive(EmptyClauses);
UnmarkedSplits = list_Nil();
pcheck_CollectUnmarkedSplits(*Tableau, &UnmarkedSplits);
pcheck_MarkRecursive(UnmarkedSplits);
pcheck_RemoveUnmarkedFromTableau(*Tableau);
list_Delete(UnmarkedSplits);
list_Delete(EmptyClauses);
/* print reduced graph */
if (pcheck_GenRedCg)
tab_WriteTableau(*Tableau, pcheck_RedCgName, pcheck_GraphFormat);
tab_SetSplitLevels(*Tableau);
pcheck_SplitLevels(*Tableau);
tab_CheckEmpties(*Tableau);
if (!tab_IsClosed(*Tableau)) {
puts("\nerror: tableau is not closed.");
return FALSE;
}
/* check justifications */
if (!pcheck_Quiet) {
fputs("checking justifications...", stdout);
fflush(stdout);
}
if (!pcheck_TableauJustifications(*Tableau))
return FALSE;
if (!pcheck_Quiet)
puts("finished.");
return TRUE;
}
void pcheck_MarkRecursive(LIST Clauses)
/**************************************************************
INPUT: A list of clauses
RETURNS: Nothing.
EFFECTS: Marks all <Clauses> and its ancestors with the
MARKED clause flag.
***************************************************************/
{
CLAUSE Clause;
for (; !list_Empty(Clauses); Clauses = list_Cdr(Clauses)) {
Clause = list_Car(Clauses);
if (!clause_GetFlag(Clause, MARKED)) {
pcheck_MarkRecursive(clause_ParentClauses(Clause));
clause_SetFlag(Clause, MARKED);
}
}
}
static LIST pcheck_CollectTermVariables(TERM Term)
/**************************************************************
INPUT: A term.
RETURNS: A list of terms. For each variable in <Term> the list
contains exactly one term representing the variable.
EFFECT: Memory is allocated for the terms.
***************************************************************/
{
LIST Result, Scan;
Result = term_VariableSymbols(Term);
for (Scan = Result; !list_Empty(Scan); Scan = list_Cdr(Scan))
list_Rplaca(Scan, term_Create((SYMBOL)list_Car(Scan), list_Nil()));
return Result;
}
static BOOL pcheck_IsRightSplitHalf(CLAUSE C)
/**************************************************************
INPUT : A clause.
RETURNS: TRUE iff the following conditions are fulfilled:
- the first parent clause is an empty clause
- the clause subsumes its second parent
***************************************************************/
{
LIST Parents;
BOOL Ok;
Parents = list_Copy(clause_ParentClauses(C));
Parents = list_PointerDeleteDuplicates(Parents);
Ok = FALSE;
if (list_Length(Parents) == 2 && clause_IsEmptyClause(list_First(Parents)))
Ok = subs_Subsumes(C, list_Second(Parents), -1, -1);
list_Delete(Parents);
return Ok;
}
static TERM pcheck_UnivClosure(TERM T)
/**************************************************************
INPUT: A term, representing a formula.
RETURNS: The universal closure of the term.
EFFECTS: <T> is part of the returned term!
***************************************************************/
{
LIST Vars;
Vars = pcheck_CollectTermVariables(T);
if (list_Empty(Vars))
return T;
return fol_CreateQuantifier(fol_All(), Vars, list_List(T));
}
static TERM pcheck_ClauseToTerm(CLAUSE Clause)
/**************************************************************
INPUT: A clause.
RETURNS: The clause represented as a TERM.
***************************************************************/
{
int LitScan;
LIST Args;
TERM Lit;
TERM ClauseTerm;
Args = list_Nil();
for (LitScan = clause_FirstLitIndex(); LitScan <= clause_LastLitIndex(Clause);
LitScan++) {
Lit = clause_LiteralSignedAtom(clause_GetLiteral(Clause, LitScan));
Args = list_Cons(term_Copy(Lit), Args);
}
if (list_Empty(Args))
Args = list_List(term_Create(fol_False(), list_Nil()));
/* Build the disjunction of the literals */
if (list_Empty(list_Cdr(Args))) { /* only one arg */
ClauseTerm = list_Car(Args);
list_Delete(Args);
} else
ClauseTerm = term_Create(fol_Or(), Args);
ClauseTerm = pcheck_UnivClosure(ClauseTerm);
return ClauseTerm;
}
static LIST pcheck_ClauseListToTermList(LIST Clauses)
/**************************************************************
INPUT : A list of clauses.
RETURNS: A new list containing the clauses represented as TERMs.
***************************************************************/
{
LIST Terms;
Terms = list_Nil();
for (; !list_Empty(Clauses); Clauses = list_Cdr(Clauses))
Terms = list_Cons(pcheck_ClauseToTerm(list_Car(Clauses)), Terms);
return Terms;
}
static void pcheck_SaveNumberedDFGProblem(int Number, LIST Axioms,
LIST Conjectures,
const char* ProofFileName,
const char* DestPrefix)
/**************************************************************
INPUT : A (clause) number, a list of axioms and conjectures,
and a filename (of the proof file of the currently
checked proof)
RETURNS: Nothing.
EFFECTS: Saves a DFG file containing <Axioms> and <Conjectures>
under the name "<DestPrefix><Number>_<ProofFileName>"
***************************************************************/
{
char *Filename, *Tmp, *NumStr;
FILE *File;
NumStr = string_IntToString(Number);
Tmp = pcheck_GenericFilename(ProofFileName, NumStr);
Filename = string_Conc(DestPrefix, Tmp);
File = misc_OpenFile(Filename, "w");
fol_FPrintDFGProblem(File, "{*Sub Proof*}", "{* Proof Checker *}",
"unsatisfiable",
"{* The problem is the correctness test for a single proof line *}",
Axioms, Conjectures);
misc_CloseFile(File, Filename);
string_StringFree(NumStr);
string_StringFree(Tmp);
string_StringFree(Filename);
}
static void pcheck_SplitToProblems(TABLEAU T, const char* ProofFileName,
const char* DestPrefix)
/**************************************************************
INPUT: A tableau, which isn't a leaf of the tableau tree,
the name of a proof file and a file name prefix used for
generating files.
RETURNS: Nothing.
EFFECT: This function generates proof check tasks for clauses
resulting from splitting steps and writes them to
output files.
CAUTION: We assume that we get non-null clauses when calling
tab_SplitClause and tab_LeftSplitClause.
***************************************************************/
{
TERM SplitClauseTerm, LeftClauseTerm, RightClauseTerm;
TERM Equiv, Disj, Tmp;
LIST Conj, Args, Negations;
#ifdef CHECK
if (tab_IsLeaf(T)) {
misc_StartErrorReport();
misc_ErrorReport("\n In pcheck_SplitToProblems: Tableau is a leaf of the ");
misc_ErrorReport("tableau tree.");
misc_FinishErrorReport();
}
#endif
SplitClauseTerm = pcheck_ClauseToTerm(tab_SplitClause(T));
LeftClauseTerm = pcheck_ClauseToTerm(tab_LeftSplitClause(T));
/* by default, take all right split clauses as negations */
/* if the first clause is the second half of a split clause, */
/* take only the rest of the right split clauses as negations. */
Negations = tab_RightSplitClauses(T);
if (!list_Empty(Negations) && pcheck_IsRightSplitHalf(list_Car(Negations))) {
/* EK: Meiner Meinung nach ist es eine Invariante, da die erste */
/* Elternklausel die rechte Hlfte eines Splittings ist??? */
Negations = list_Cdr(Negations);
/* build C <=> C' v C'' */
RightClauseTerm = pcheck_ClauseToTerm(list_Car(tab_RightSplitClauses(T)));
Disj = term_Create(fol_Or(), list_Cons(LeftClauseTerm, list_List(RightClauseTerm)));
Equiv = term_Create(fol_Equiv(), list_Cons(SplitClauseTerm, list_List(Disj)));
Conj = list_List(Equiv);
pcheck_SaveNumberedDFGProblem(clause_Number(tab_LeftSplitClause(T)),
list_Nil(), Conj, ProofFileName, DestPrefix);
term_DeleteTermList(Conj);
}
Args = list_Nil();
/* build conjunction of negations, if there are any. */
if (!list_Empty(Negations)) {
LeftClauseTerm = pcheck_ClauseToTerm(tab_LeftSplitClause(T));
Args = pcheck_ClauseListToTermList(Negations);
/* Build the conjunction */
if (list_Empty(list_Cdr(Args))) { /* only one arg */
Tmp = list_Car(Args);
list_Delete(Args);
} else
Tmp = term_Create(fol_And(), Args);
Tmp = term_Create(fol_Not(), list_List(Tmp));
Equiv = term_Create(fol_Implies(),list_Cons(Tmp,list_List(LeftClauseTerm)));
Conj = list_List(Equiv);
/* problem id is number of right part of split clause, if it exists,
number of first negation otherwise */
pcheck_SaveNumberedDFGProblem(clause_Number(list_Car(tab_RightSplitClauses(T))),
list_Nil(), Conj, ProofFileName, DestPrefix);
term_DeleteTermList(Conj);
}
}
void pcheck_TableauToProofTask(TABLEAU T, const char* ProofFileName,
const char* DestPrefix)
/**************************************************************
INPUT: A Tableau, two strings for filename generation.
RETURNS: Nothing.
EFFECTS: Generates DFG problem files for each clause in the tableau.
The problem asserts that the clause follows from
its parents. For splits, see pcheck_SplitToProblems
***************************************************************/
{
LIST Scan;
LIST Axioms, Conj, Help;
CLAUSE Clause;
if (tab_IsEmpty(T))
return;
/* treat the splitting clauses at inner nodes of the tableau tree */
if (!tab_IsLeaf(T))
pcheck_SplitToProblems(T, ProofFileName, DestPrefix);
/* treat derived clauses that don't result from splitting */
for (Scan = tab_Clauses(T); !list_Empty(Scan); Scan = list_Cdr(Scan)) {
Clause = list_Car(Scan);
if (!clause_IsFromSplitting(Clause) &&
!list_Empty(clause_ParentClauses(Clause))) {
Axioms = list_Copy(clause_ParentClauses(Clause));
Axioms = list_PointerDeleteDuplicates(Axioms);
Help = Axioms;
Axioms = pcheck_ClauseListToTermList(Axioms);
list_Delete(Help);
Conj = list_List(pcheck_ClauseToTerm(Clause));
pcheck_SaveNumberedDFGProblem(clause_Number(Clause), Axioms, Conj,
ProofFileName, DestPrefix);
term_DeleteTermList(Axioms);
term_DeleteTermList(Conj);
}
}
/* recursion */
pcheck_TableauToProofTask(tab_RightBranch(T), ProofFileName, DestPrefix);
pcheck_TableauToProofTask(tab_LeftBranch(T), ProofFileName, DestPrefix);
}
int pcheck_SeqProofDepth(LIST Proof)
/**************************************************************
INPUT : A sequential proof (list of clauses)
RETURNS: The maximum clause depth in the proof
***************************************************************/
{
int Max;
Max = 0;
for ( ; !list_Empty(Proof); Proof = list_Cdr(Proof))
if (clause_Depth(list_Car(Proof)) > Max)
Max = clause_Depth(list_Car(Proof));
return Max;
}
LIST pcheck_ReduceSPASSProof(LIST Proof)
/**************************************************************
INPUT: A list of clauses representing a SPASS proof.
Parents are pointers.
RETURNS: A list of clauses where incomplete splits
and closed branches with descendants have been
removed.
***************************************************************/
{
LIST EmptyClauses, RedundantClauses;
LIST ReducedProof;
TABLEAU Tableau;
LIST UnmarkedSplits;
if (!pcheck_BuildTableauFromProof(Proof, &Tableau)) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n Error: Proof could not be translated into a closed tableau.\n");
misc_FinishUserErrorReport();
}
/* printf("\n\n (1) \n"); */
/* tab_PrintTableau(Tableau); */
RedundantClauses = list_Nil();
Tableau = tab_PruneClosedBranches(Tableau, &RedundantClauses);
/* printf("\n\n (2) \n"); */
/* tab_PrintTableau(Tableau); */
Tableau = tab_RemoveIncompleteSplits(Tableau, &RedundantClauses);
/* printf("\n\n (3) \n"); */
/* tab_PrintTableau(Tableau); */
Tableau = tab_RemoveUnfinishedSplits(Tableau, &RedundantClauses);
/* printf("\n\n (4) \n"); */
/* tab_PrintTableau(Tableau); */
list_Delete(RedundantClauses);
tab_SetSplitLevels(Tableau);
/*
* get minimal proof: First find earliest derived empty clauses,
* then recursively mark ancestors of these clauses. Put
* only marked clauses in <ReducedProof>.
*/
EmptyClauses = list_Nil();
tab_GetEarliestEmptyClauses(Tableau, &EmptyClauses);
pcheck_ClauseListRemoveFlag(Proof, MARKED);
pcheck_MarkRecursive(EmptyClauses);
UnmarkedSplits = list_Nil();
pcheck_CollectUnmarkedSplits(Tableau, &UnmarkedSplits);
pcheck_MarkRecursive(UnmarkedSplits);
pcheck_RemoveUnmarkedFromTableau(Tableau);
list_Delete(UnmarkedSplits);
ReducedProof = list_Nil();
tab_ToClauseList(Tableau, &ReducedProof);
ReducedProof = pcheck_ClauseNumberMergeSort(ReducedProof);
tab_Delete(Tableau);
list_Delete(EmptyClauses);
return ReducedProof;
}
void pcheck_DeleteProof(LIST Proof)
/**************************************************************
INPUT: A Proof
RETURNS: Nothing.
EFFECTS: Frees memory associated with proof
**************************************************************/
{
LIST Line, Scan2, Scan1;
Scan1 = Proof;
while (!list_Empty(Scan1)) {
Line = list_Car(Scan1);
string_StringFree(list_Car(Line));
if (list_Second(Line) != clause_Null()) /* clause */
term_Delete(list_Second(Line));
/* delete labels in justification list and list itself */
for (Scan2 = list_Third(Line); !list_Empty(Scan2); Scan2 = list_Cdr(Scan2))
string_StringFree(list_Car(Scan2));
list_Delete(list_Third(Line));
/* now contents of line are deleted. Delete line. */
list_Delete(Line);
Scan1 = list_Cdr(Scan1);
}
list_Delete(Proof);
}
char* pcheck_GenericFilename(const char* Filename, const char* Id)
/**************************************************************
INPUT: Two strings.
RETURNS: A string with Suffix as new extension to Filename
(Filename = name.ext -> name_<Id>.prf)
EFFECTS: Memory is allocated for the returned string.
**************************************************************/
{
char *Help1, *Help2;
int i;
Help1 = string_Conc("_", Id);
Help2 = string_Conc(Help1, pcheck_ProofFileSuffix);
string_StringFree(Help1);
/* remove filename extension */
for (i = 0; Filename[i] != '.' && i < strlen(Filename); i++)
/* empty */;
Help1 = string_Prefix(Filename, i);
return string_Nconc(Help1, Help2); /* Help1 and Help2 are freed, too */
}
void pcheck_ClauseListRemoveFlag(LIST Clauses, CLAUSE_FLAGS Flag)
/**************************************************************
INPUT: A list of clauses and a clause flag
RETURNS: Nothing.
EFFECTS: Removes the <Flag> in all clauses in the list
**************************************************************/
{
for (; !list_Empty(Clauses); Clauses = list_Cdr(Clauses))
clause_RemoveFlag(list_Car(Clauses), Flag);
}
LIST pcheck_ClauseNumberMergeSort(LIST L)
/**************************************************************
INPUT: A list of clauses
RETURNS: The sorted list: clause_Number(L[i]) < clause_Number(L[i+1])
EFFECTS: Destructive
***************************************************************/
{
return clause_NumberSort(L);
}
|