-
Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathrules-red.c
4508 lines (3938 loc) · 151 KB
/
rules-red.c
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
/**************************************************************/
/* ********************************************************** */
/* * * */
/* * REDUCTION RULES * */
/* * * */
/* * $Module: REDRULES * */
/* * * */
/* * 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 GNU * */
/* * General Public License as published by the Free * */
/* * Software Foundation; either version 2 of the License, * */
/* * or (at your option) any later version. * */
/* * * */
/* * 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 GNU General Public * */
/* * License for more details. * */
/* * * */
/* * You should have received a copy of the GNU General * */
/* * Public License along with this program; if not, write * */
/* * to the Free Software Foundation, Inc., 59 Temple * */
/* * Place, Suite 330, Boston, MA 02111-1307 USA * */
/* * * */
/* * * */
/* $Revision$ * */
/* $State$ * */
/* $Date$ * */
/* $Author$ * */
/* * * */
/* * Contact: * */
/* * Christoph Weidenbach * */
/* * MPI fuer Informatik * */
/* * Stuhlsatzenhausweg 85 * */
/* * 66123 Saarbruecken * */
/* * Email: weidenb@mpi-sb.mpg.de * */
/* * Germany * */
/* * * */
/* ********************************************************** */
/**************************************************************/
/* $RCSfile$ */
#include "rules-red.h"
/**************************************************************/
/* ********************************************************** */
/* * * */
/* * Globals * */
/* * * */
/* ********************************************************** */
/**************************************************************/
/* Needed for term stamping in red_RewriteRedUnitClause */
static NAT red_STAMPID;
const NAT red_USABLE = 1;
const NAT red_WORKEDOFF = 2;
const NAT red_ALL = 3;
/**************************************************************/
/* FUNTION PROTOTYPES */
/**************************************************************/
static BOOL red_SortSimplification(SORTTHEORY, CLAUSE, NAT, BOOL, FLAGSTORE,
PRECEDENCE, CLAUSE*);
static BOOL red_SelectedStaticReductions(PROOFSEARCH, CLAUSE*, CLAUSE*, LIST*,
NAT);
/**************************************************************/
/* ********************************************************** */
/* * * */
/* * Functions * */
/* * * */
/* ********************************************************** */
/**************************************************************/
static void red_HandleRedundantIndexedClauses(PROOFSEARCH Search, LIST Blocked,
CLAUSE RedClause)
/*********************************************************
INPUT: A proof search object, a list <Blocked> of clauses from
the proof search object and a clause that causes the
already indexed clauses in <Blocked> to be redundant.
RETURNS: Nothing.
**********************************************************/
{
FLAGSTORE Flags;
CLAUSE Clause;
LIST Scan;
Flags = prfs_Store(Search);
for (Scan = Blocked; !list_Empty(Scan); Scan = list_Cdr(Scan)) {
Clause = (CLAUSE)list_Car(Scan);
if (prfs_SplitLevelCondition(clause_SplitLevel(RedClause),clause_SplitLevel(Clause),
prfs_LastBacktrackLevel(Search)))
split_DeleteClauseAtLevel(Search, Clause, clause_SplitLevel(RedClause));
else {
if (clause_GetFlag(Clause, WORKEDOFF)) {
if (flag_GetFlagValue(Flags, flag_DOCPROOF))
prfs_MoveWorkedOffDocProof(Search, Clause);
else
prfs_DeleteWorkedOff(Search, Clause);
}
else
if (flag_GetFlagValue(Flags, flag_DOCPROOF))
prfs_MoveUsableDocProof(Search, Clause);
else
prfs_DeleteUsable(Search, Clause);
}
}
}
static void red_HandleRedundantDerivedClauses(PROOFSEARCH Search, LIST Blocked,
CLAUSE RedClause)
/*********************************************************
INPUT: A proof search object, a list <Blocked> of clauses from
the proof search object and a clause that causes the
derived clauses in <Blocked> to be redundant.
RETURNS: Nothing.
**********************************************************/
{
CLAUSE Clause;
LIST Scan;
for (Scan = Blocked; !list_Empty(Scan); Scan = list_Cdr(Scan)) {
Clause = (CLAUSE)list_Car(Scan);
if (prfs_SplitLevelCondition(clause_SplitLevel(RedClause),clause_SplitLevel(Clause),
prfs_LastBacktrackLevel(Search))) {
split_KeepClauseAtLevel(Search, Clause, clause_SplitLevel(RedClause));
}
else {
if (flag_GetFlagValue(prfs_Store(Search), flag_DOCPROOF))
prfs_InsertDocProofClause(Search, Clause);
else
clause_Delete(Clause);
}
}
}
void red_Init(void)
/*********************************************************
INPUT: None.
RETURNS: Nothing.
EFFECT: Initializes the Reduction module, in particular
its stampid to stamp terms.
**********************************************************/
{
red_STAMPID = term_GetStampID();
}
static void red_DocumentObviousReductions(CLAUSE Clause, LIST Indexes)
/*********************************************************
INPUT: A clause and a list of literal indexes removed by
obvious reductions.
RETURNS: None
MEMORY: The <Indexes> list is consumed.
**********************************************************/
{
list_Delete(clause_ParentClauses(Clause));
list_Delete(clause_ParentLiterals(Clause));
clause_SetParentClauses(Clause, list_Nil());
clause_SetParentLiterals(Clause, Indexes);
clause_AddParentClause(Clause,clause_Number(Clause)); /* Has to be done before increasing it! */
clause_SetNumber(Clause, clause_IncreaseCounter());
clause_SetFromObviousReductions(Clause);
}
static BOOL red_ObviousReductions(CLAUSE Clause, BOOL Document,
FLAGSTORE Flags, PRECEDENCE Precedence,
CLAUSE *Changed)
/**********************************************************
INPUT: A clause, a boolean flag for proof
documentation, a flag store and a precedence.
RETURNS: TRUE iff obvious reductions are possible.
If <Document> is false the clause is
destructively changed,
else a reduced copy of the clause is returned
in <*Changed>.
EFFECT: Multiple occurrences of the same literal as
well as trivial equations are removed.
********************************************************/
{
int i, j, end;
LIST Indexes;
TERM Atom, PartnerAtom;
#ifdef CHECK
clause_Check(Clause, Flags, Precedence);
#endif
Indexes = list_Nil();
end = clause_LastAntecedentLitIndex(Clause);
for (i = clause_FirstConstraintLitIndex(Clause); i <= end; i++) {
Atom = clause_LiteralAtom(clause_GetLiteral(Clause,i));
if (fol_IsEquality(Atom) &&
!clause_LiteralIsOrientedEquality(clause_GetLiteral(Clause, i)) &&
term_Equal(term_FirstArgument(Atom),term_SecondArgument(Atom))) {
Indexes = list_Cons((POINTER)i,Indexes);
}
else
for (j = i+1; j <= end; j++) {
PartnerAtom = clause_LiteralAtom(clause_GetLiteral(Clause,j));
if (term_Equal(PartnerAtom, Atom) ||
(fol_IsEquality(Atom) &&
fol_IsEquality(PartnerAtom) &&
term_Equal(term_FirstArgument(Atom),term_SecondArgument(PartnerAtom)) &&
term_Equal(term_FirstArgument(PartnerAtom),term_SecondArgument(Atom)))) {
Indexes = list_Cons((POINTER)i,Indexes);
j = end;
}
}
}
end = clause_LastSuccedentLitIndex(Clause);
for (i = clause_FirstSuccedentLitIndex(Clause); i <= end; i++) {
Atom = clause_LiteralAtom(clause_GetLiteral(Clause,i));
for (j = i+1; j <= end; j++) {
PartnerAtom = clause_LiteralAtom(clause_GetLiteral(Clause,j));
if (term_Equal(PartnerAtom,Atom) ||
(fol_IsEquality(Atom) &&
fol_IsEquality(PartnerAtom) &&
term_Equal(term_FirstArgument(Atom),term_SecondArgument(PartnerAtom)) &&
term_Equal(term_FirstArgument(PartnerAtom),term_SecondArgument(Atom)))) {
Indexes = list_Cons((POINTER)i,Indexes);
j = end;
}
}
}
if (clause_Length(Clause) == 1 &&
clause_NumOfAnteLits(Clause) == 1 &&
!list_PointerMember(Indexes,(POINTER)clause_FirstAntecedentLitIndex(Clause)) &&
fol_IsEquality(clause_GetLiteralAtom(Clause,clause_FirstAntecedentLitIndex(Clause)))) {
cont_StartBinding();
if (unify_UnifyCom(cont_LeftContext(),
term_FirstArgument(clause_LiteralAtom(clause_GetLiteral(Clause,clause_FirstAntecedentLitIndex(Clause)))),
term_SecondArgument(clause_LiteralAtom(clause_GetLiteral(Clause,clause_FirstAntecedentLitIndex(Clause))))))
Indexes = list_Cons((POINTER)clause_FirstAntecedentLitIndex(Clause),Indexes);
cont_BackTrack();
}
if (!list_Empty(Indexes)) {
if (flag_GetFlagValue(Flags, flag_POBV)) {
fputs("\nObvious: ", stdout);
clause_Print(Clause);
fputs(" ==> ", stdout);
}
if (Document) {
CLAUSE Copy;
Copy = clause_Copy(Clause);
clause_DeleteLiterals(Copy,Indexes, Flags, Precedence);
red_DocumentObviousReductions(Copy,Indexes); /* Indexes is consumed */
if (flag_GetFlagValue(Flags, flag_POBV))
clause_Print(Copy);
*Changed = Copy;
}
else {
clause_DeleteLiterals(Clause,Indexes, Flags, Precedence);
list_Delete(Indexes);
if (flag_GetFlagValue(Flags, flag_POBV))
clause_Print(Clause);
}
return TRUE;
}
return FALSE;
}
static void red_DocumentCondensing(CLAUSE Clause, LIST Indexes)
/*********************************************************
INPUT: A clause and a list of literal indexes removed by condensing.
RETURNS: Nothing.
MEMORY: The <Indexes> list is consumed.
**********************************************************/
{
list_Delete(clause_ParentClauses(Clause));
list_Delete(clause_ParentLiterals(Clause));
clause_SetParentClauses(Clause, list_Nil());
clause_SetParentLiterals(Clause, Indexes);
clause_AddParentClause(Clause,clause_Number(Clause)); /* Has to be done before increasing it! */
clause_SetNumber(Clause, clause_IncreaseCounter());
clause_SetFromCondensing(Clause);
}
static BOOL red_Condensing(CLAUSE Clause, BOOL Document, FLAGSTORE Flags,
PRECEDENCE Precedence, CLAUSE *Changed)
/**********************************************************
INPUT: A non-empty unshared clause, a boolean flag
concerning proof documentation, a flag store and
a precedence.
RETURNS: TRUE iff condensing is applicable to <Clause>.
If <Document> is false the clause is
destructively changed else a condensed copy of
the clause is returned in <*Changed>.
***********************************************************/
{
LIST Indexes;
#ifdef CHECK
if (!clause_IsClause(Clause, Flags, Precedence) ||
(*Changed != (CLAUSE)NULL)) {
misc_StartErrorReport();
misc_ErrorReport("\n In red_Condensing : ");
misc_ErrorReport("Illegal input.\n");
misc_FinishErrorReport();
}
clause_Check(Clause, Flags, Precedence);
#endif
Indexes = cond_CondFast(Clause);
if (!list_Empty(Indexes)) {
if (flag_GetFlagValue(Flags, flag_PCON)) {
fputs("\nCondensing: ", stdout);
clause_Print(Clause);
fputs(" ==> ", stdout);
}
if (Document) {
CLAUSE Copy;
Copy = clause_Copy(Clause);
clause_DeleteLiterals(Copy, Indexes, Flags, Precedence);
red_DocumentCondensing(Copy, Indexes);
if (flag_GetFlagValue(Flags, flag_PCON))
clause_Print(Copy);
*Changed = Copy;
}
else {
clause_DeleteLiterals(Clause, Indexes, Flags, Precedence);
list_Delete(Indexes);
if (flag_GetFlagValue(Flags, flag_PCON))
clause_Print(Clause);
}
return TRUE;
}
return FALSE;
}
static void red_DocumentAssignmentEquationDeletion(CLAUSE Clause, LIST Indexes,
NAT NonTrivClauseNumber)
/*********************************************************
INPUT: A clause and a list of literal indexes pointing to
redundant equations and the clause number of a clause
implying a non-trivial domain.
RETURNS: Nothing.
MEMORY: The <Indexes> list is consumed.
**********************************************************/
{
list_Delete(clause_ParentClauses(Clause));
list_Delete(clause_ParentLiterals(Clause));
clause_SetParentClauses(Clause, list_Nil());
clause_SetParentLiterals(Clause, Indexes);
clause_AddParentClause(Clause,clause_Number(Clause)); /* Has to be done before increasing it! */
clause_SetNumber(Clause, clause_IncreaseCounter());
clause_SetFromAssignmentEquationDeletion(Clause);
if (NonTrivClauseNumber != 0) { /* Such a clause exists */
clause_AddParentClause(Clause, NonTrivClauseNumber);
clause_AddParentLiteral(Clause, 0); /* The non triv clause has exactly one negative literal */
}
}
static BOOL red_AssignmentEquationDeletion(CLAUSE Clause, FLAGSTORE Flags,
PRECEDENCE Precedence, CLAUSE *Changed,
NAT NonTrivClauseNumber,
BOOL NonTrivDomain)
/**********************************************************
INPUT: A non-empty unshared clause, a flag store, a
precedence, the clause number of a clause
implying a non-trivial domain and a boolean
flag indicating whether the current domain has
more than one element.
RETURNS: TRUE iff equations are removed.
If the <DocProof> flag is false the clause is
destructively changed else a copy of the clause
where redundant equations are removed is
returned in <*Changed>.
***********************************************************/
{
LIST Indexes; /* List of indexes of redundant equations*/
NAT i;
TERM LeftArg, RightArg;
#ifdef CHECK
if (!clause_IsClause(Clause, Flags, Precedence) ||
(*Changed != (CLAUSE)NULL) ||
(NonTrivDomain && NonTrivClauseNumber == 0) ||
(!NonTrivDomain && NonTrivClauseNumber > 0)) {
misc_StartErrorReport();
misc_ErrorReport("\n In red_AssignmentEquationDeletion: ");
misc_ErrorReport("Illegal input.\n");
misc_FinishErrorReport();
}
clause_Check(Clause, Flags, Precedence);
#endif
Indexes = list_Nil();
if (clause_ContainsNegativeEquations(Clause)) {
for (i = clause_FirstAntecedentLitIndex(Clause); i <= clause_LastAntecedentLitIndex(Clause); i++) {
if (clause_LiteralIsEquality(clause_GetLiteral(Clause,i))) {
LeftArg = term_FirstArgument(clause_GetLiteralAtom(Clause,i));
RightArg = term_SecondArgument(clause_GetLiteralAtom(Clause,i));
if ((term_IsVariable(LeftArg) &&
clause_NumberOfSymbolOccurrences(Clause, term_TopSymbol(LeftArg)) == 1) ||
(term_IsVariable(RightArg) &&
clause_NumberOfSymbolOccurrences(Clause, term_TopSymbol(RightArg)) == 1))
Indexes = list_Cons((POINTER)i, Indexes);
}
}
}
else
if (NonTrivDomain && clause_ContainsPositiveEquations(Clause)) {
for (i = clause_FirstSuccedentLitIndex(Clause); i <= clause_LastSuccedentLitIndex(Clause); i++) {
if (clause_LiteralIsEquality(clause_GetLiteral(Clause,i))) {
LeftArg = term_FirstArgument(clause_GetLiteralAtom(Clause,i));
RightArg = term_SecondArgument(clause_GetLiteralAtom(Clause,i));
if ((term_IsVariable(LeftArg) &&
clause_NumberOfSymbolOccurrences(Clause, term_TopSymbol(LeftArg)) == 1) ||
(term_IsVariable(RightArg) &&
clause_NumberOfSymbolOccurrences(Clause, term_TopSymbol(RightArg)) == 1))
Indexes = list_Cons((POINTER)i, Indexes);
}
}
}
if (!list_Empty(Indexes)) {
if (flag_GetFlagValue(Flags, flag_PAED)) {
fputs("\nAED: ", stdout);
clause_Print(Clause);
fputs(" ==> ", stdout);
}
if (flag_GetFlagValue(Flags, flag_DOCPROOF)) {
CLAUSE Copy;
Copy = clause_Copy(Clause);
clause_DeleteLiterals(Copy, Indexes, Flags, Precedence);
red_DocumentAssignmentEquationDeletion(Copy, Indexes, NonTrivClauseNumber);
if (flag_GetFlagValue(Flags, flag_PAED))
clause_Print(Copy);
*Changed = Copy;
}
else {
clause_DeleteLiterals(Clause, Indexes, Flags, Precedence);
list_Delete(Indexes);
if (flag_GetFlagValue(Flags, flag_PAED))
clause_Print(Clause);
}
return TRUE;
}
return FALSE;
}
static BOOL red_Tautology(CLAUSE Clause, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**********************************************************
INPUT: A non-empty clause, a flag store and a
precedence.
RETURNS: The boolean value TRUE if 'Clause' is a
tautology.
***********************************************************/
{
TERM Atom;
int i,j, la,n;
BOOL Result;
#ifdef CHECK
if (!clause_IsClause(Clause, Flags, Precedence)) {
misc_StartErrorReport();
misc_ErrorReport("\n In red_Tautology :");
misc_ErrorReport(" Illegal input.\n");
misc_FinishErrorReport();
}
clause_Check(Clause, Flags, Precedence);
#endif
la = clause_LastAntecedentLitIndex(Clause);
n = clause_Length(Clause);
Result = FALSE;
for (j = clause_FirstSuccedentLitIndex(Clause); j < n && !Result; j++) {
Atom = clause_LiteralAtom(clause_GetLiteral(Clause, j));
if (fol_IsEquality(Atom) &&
!clause_LiteralIsOrientedEquality(clause_GetLiteral(Clause, j)) &&
term_Equal(term_FirstArgument(Atom),term_SecondArgument(Atom)))
Result = TRUE;
for (i = clause_FirstLitIndex(); i <= la && !Result; i++)
if (term_Equal(Atom, clause_LiteralAtom(clause_GetLiteral(Clause, i))))
Result = TRUE;
}
if (!Result &&
flag_GetFlagValue(Flags, flag_RTAUT) == flag_RTAUTSEMANTIC &&
clause_NumOfAnteLits(Clause) != 0 &&
clause_NumOfSuccLits(Clause) != 0) {
Result = cc_Tautology(Clause);
}
if (Result && flag_GetFlagValue(Flags, flag_PTAUT)) {
fputs("\nTautology: ", stdout);
clause_Print(Clause);
}
return Result;
}
static LITERAL red_GetMRResLit(LITERAL ActLit, SHARED_INDEX ShIndex)
/**************************************************************
INPUT: A literal and an Index.
RETURNS: The most valid clause with a complementary literal,
(CLAUSE)NULL, if no such clause exists.
***************************************************************/
{
LITERAL NextLit;
int i;
CLAUSE ActClause;
TERM CandTerm;
LIST LitScan;
NextLit = (LITERAL)NULL;
ActClause = clause_LiteralOwningClause(ActLit);
i = clause_LiteralGetIndex(ActLit);
CandTerm = st_ExistGen(cont_LeftContext(),
sharing_Index(ShIndex),
clause_LiteralAtom(ActLit));
while (CandTerm) { /* First check units */
if (!term_IsVariable(CandTerm)) { /* Has to be an Atom! */
LitScan = sharing_NAtomDataList(CandTerm); /* CAUTION !!! the List is not a copy */
while (!list_Empty(LitScan)) {
NextLit = list_Car(LitScan);
if (clause_LiteralsAreComplementary(ActLit,NextLit))
if (clause_Length(clause_LiteralOwningClause(NextLit)) == 1 ||
subs_SubsumesBasic(clause_LiteralOwningClause(NextLit),ActClause,
clause_LiteralGetIndex(NextLit),i)) {
st_CancelExistRetrieval();
return NextLit;
}
LitScan = list_Cdr(LitScan);
}
}
CandTerm = st_NextCandidate();
}
return (LITERAL)NULL;
}
static void red_DocumentMatchingReplacementResolution(CLAUSE Clause, LIST LitInds,
LIST ClauseNums, LIST PLitInds)
/*********************************************************
INPUT: A clause, the involved literals indices in <Clause>,
the literal indices of the reduction literals
and the clauses number.
RETURNS: Nothing.
MEMORY: All input lists are consumed.
**********************************************************/
{
LIST Scan,Help;
Help = list_Nil();
for (Scan=LitInds; !list_Empty(Scan); Scan = list_Cdr(Scan)) {
Help = list_Cons((POINTER)clause_Number(Clause), Help);
/* Has to be done before increasing the clause number! */
}
list_Delete(clause_ParentClauses(Clause));
list_Delete(clause_ParentLiterals(Clause));
clause_SetParentClauses(Clause, list_Nconc(Help,ClauseNums));
clause_SetParentLiterals(Clause, list_Nconc(LitInds,PLitInds));
clause_SetNumber(Clause, clause_IncreaseCounter());
clause_SetFromMatchingReplacementResolution(Clause);
}
static BOOL red_MatchingReplacementResolution(CLAUSE Clause, SHARED_INDEX ShIndex,
FLAGSTORE Flags, PRECEDENCE Precedence,
CLAUSE *Changed, int Level)
/**************************************************************
INPUT: A clause, an Index, a flag store, a precedence and a
split level indicating the need of a copy if
<Clause> is reduced by a clause of higher split
level than <Level>.
RETURNS: TRUE if reduction wrt the indexed clauses was
possible.
If the <DocProof> flag is true or the clauses used
for reductions have a higher split level then a
changed copy is returned in <*Changed>.
Otherwise <Clause> is destructively changed.
***************************************************************/
{
CLAUSE PClause,Copy;
LITERAL ActLit,PLit;
int i, j, length;
LIST ReducedBy,ReducedLits,PLits,Scan1,Scan2;
BOOL Document;
#ifdef CHECK
if (!clause_IsClause(Clause, Flags, Precedence) ||
(*Changed != (CLAUSE)NULL)) {
misc_StartErrorReport();
misc_ErrorReport("\n In red_MatchingReplacementResolution:");
misc_ErrorReport(" Illegal input.\n");
misc_FinishErrorReport();
}
clause_Check(Clause, Flags, Precedence);
#endif
Copy = Clause;
length = clause_Length(Clause);
ReducedBy = list_Nil();
ReducedLits = list_Nil();
PLits = list_Nil();
i = clause_FirstLitIndex();
j = 0;
Document = flag_GetFlagValue(Flags, flag_DOCPROOF);
while (i < length) {
ActLit = clause_GetLiteral(Copy, i);
if (!fol_IsEquality(clause_LiteralAtom(ActLit)) || /* Reduce with negative equations. */
clause_LiteralIsPositive(ActLit)) {
PLit = red_GetMRResLit(ActLit, ShIndex);
if (clause_LiteralExists(PLit)) {
if (list_Empty(PLits) && flag_GetFlagValue(Flags, flag_PMRR)) {
fputs("\nFMatchingReplacementResolution: ", stdout);
clause_Print(Copy);
}
PClause = clause_LiteralOwningClause(PLit);
ReducedBy = list_Cons((POINTER)clause_Number(PClause), ReducedBy);
PLits = list_Cons((POINTER)clause_LiteralGetIndex(PLit),PLits);
ReducedLits = list_Cons((POINTER)(i+j), ReducedLits);
if (Copy == Clause &&
(Document || prfs_SplitLevelCondition(clause_SplitLevel(PClause),clause_SplitLevel(Copy),Level)))
Copy = clause_Copy(Clause);
clause_UpdateSplitDataFromPartner(Copy, PClause);
clause_DeleteLiteral(Copy,i, Flags, Precedence);
length--;
j++;
}
else
i++;
}
else
i++;
}
if (!list_Empty(ReducedBy)) {
if (Document) {
ReducedBy = list_NReverse(ReducedBy);
ReducedLits = list_NReverse(ReducedLits);
PLits = list_NReverse(PLits);
red_DocumentMatchingReplacementResolution(Copy, ReducedLits, ReducedBy, PLits); /* Lists are consumed */
if (flag_GetFlagValue(Flags, flag_PMRR)) {
fputs(" ==> [ ", stdout);
for(Scan1=ReducedBy,Scan2=ReducedLits;!list_Empty(Scan1);
Scan1=list_Cdr(Scan1),Scan2=list_Cdr(Scan2))
printf("%d.%d ",(NAT)list_Car(Scan1),(NAT)list_Car(Scan2));
fputs("] ", stdout);
clause_Print(Copy);
}
}
else {
if (flag_GetFlagValue(Flags, flag_PMRR)) {
fputs(" ==> [ ", stdout);
for(Scan1=ReducedBy,Scan2=ReducedLits;!list_Empty(Scan1);
Scan1=list_Cdr(Scan1),Scan2=list_Cdr(Scan2))
printf("%d.%d ",(NAT)list_Car(Scan1),(NAT)list_Car(Scan2));
fputs("] ", stdout);
clause_Print(Copy);
}
list_Delete(ReducedBy);
list_Delete(ReducedLits);
list_Delete(PLits);
}
if (Copy != Clause)
*Changed = Copy;
return TRUE;
}
return FALSE;
}
static void red_DocumentUnitConflict(CLAUSE Clause, LIST LitInds,
LIST ClauseNums, LIST PLitInds)
/*********************************************************
INPUT: A clause, the involved literals indices and the clauses number.
RETURNS: Nothing.
MEMORY: All input lists are consumed.
**********************************************************/
{
list_Delete(clause_ParentClauses(Clause));
list_Delete(clause_ParentLiterals(Clause));
clause_SetParentClauses(Clause, list_Nconc(list_List((POINTER)clause_Number(Clause)),ClauseNums));
clause_SetParentLiterals(Clause, list_Nconc(LitInds,PLitInds));
clause_SetNumber(Clause, clause_IncreaseCounter());
clause_SetFromUnitConflict(Clause);
}
static BOOL red_UnitConflict(CLAUSE Clause, SHARED_INDEX ShIndex,
FLAGSTORE Flags, PRECEDENCE Precedence,
CLAUSE *Changed, int Level)
/**************************************************************
INPUT: A clause, an Index, a flag store and a splitlevel
indicating the need of a copy if <Clause> is reduced
by a clause of higher split level than <Level>.
RETURNS: TRUE if a unit conflict with <Clause> and the
clauses in <ShIndex> happened.
If the <DocProof> flag is true or the clauses used for
reductions have a higher split level then a changed
copy is returned in <*Changed>.
Otherwise <Clause> is destructively changed.
***************************************************************/
{
CLAUSE PClause,Copy;
LITERAL ActLit,PLit;
LIST Scan;
TERM CandTerm;
BOOL Document;
#ifdef CHECK
if (!clause_IsClause(Clause, Flags, Precedence) || (*Changed != (CLAUSE)NULL)) {
misc_StartErrorReport();
misc_ErrorReport("\n In red_ForwardUnitConflict :");
misc_ErrorReport(" Illegal input.\n");
misc_FinishErrorReport();
}
clause_Check(Clause, Flags, Precedence);
#endif
if (clause_Length(Clause) == 1) {
Copy = Clause;
Document = flag_GetFlagValue(Flags, flag_DOCPROOF);
ActLit = clause_GetLiteral(Copy, clause_FirstLitIndex());
PLit = (LITERAL)NULL;
CandTerm = st_ExistUnifier(cont_LeftContext(), sharing_Index(ShIndex), cont_RightContext(),
clause_LiteralAtom(ActLit));
while (PLit == (LITERAL)NULL && CandTerm) {
if (!term_IsVariable(CandTerm)) {
Scan = sharing_NAtomDataList(CandTerm); /* CAUTION !!! the List is not a copy */
while (!list_Empty(Scan)) {
PLit = list_Car(Scan);
if (clause_LiteralsAreComplementary(ActLit,PLit) &&
clause_Length(clause_LiteralOwningClause(PLit)) == 1) {
st_CancelExistRetrieval();
Scan = list_Nil();
}
else {
PLit = (LITERAL)NULL;
Scan = list_Cdr(Scan);
}
}
}
if (PLit == (LITERAL)NULL)
CandTerm = st_NextCandidate();
}
if (PLit == (LITERAL)NULL && fol_IsEquality(clause_LiteralAtom(ActLit))) {
TERM Atom;
Atom = term_Create(fol_Equality(),list_Reverse(term_ArgumentList(clause_LiteralAtom(ActLit))));
CandTerm = st_ExistUnifier(cont_LeftContext(), sharing_Index(ShIndex), cont_RightContext(), Atom);
while (PLit == (LITERAL)NULL && CandTerm) {
if (!term_IsVariable(CandTerm)) {
Scan = sharing_NAtomDataList(CandTerm); /* CAUTION !!! the List is not a copy */
while (!list_Empty(Scan)) {
PLit = list_Car(Scan);
if (clause_LiteralsAreComplementary(ActLit,PLit) &&
clause_Length(clause_LiteralOwningClause(PLit)) == 1) {
st_CancelExistRetrieval();
Scan = list_Nil();
}
else {
PLit = (LITERAL)NULL;
Scan = list_Cdr(Scan);
}
}
}
if (PLit == (LITERAL)NULL)
CandTerm = st_NextCandidate();
}
list_Delete(term_ArgumentList(Atom));
term_Free(Atom);
}
if (clause_LiteralExists(PLit)) {
if (flag_GetFlagValue(Flags, flag_PUNC)) {
fputs("\nUnitConflict: ", stdout);
clause_Print(Copy);
}
PClause = clause_LiteralOwningClause(PLit);
if (Copy == Clause &&
(Document || prfs_SplitLevelCondition(clause_SplitLevel(PClause),clause_SplitLevel(Copy),Level)))
Copy = clause_Copy(Clause);
clause_UpdateSplitDataFromPartner(Copy, PClause);
clause_DeleteLiteral(Copy,clause_FirstLitIndex(), Flags, Precedence);
if (Document)
red_DocumentUnitConflict(Copy, list_List((POINTER)clause_FirstLitIndex()),
list_List((POINTER)clause_Number(PClause)),
list_List((POINTER)clause_FirstLitIndex()));
if (flag_GetFlagValue(Flags, flag_PUNC)) {
printf(" ==> [ %d.%d ]", clause_Number(PClause), clause_FirstLitIndex());
clause_Print(Copy);
}
if (Copy != Clause)
*Changed = Copy;
return TRUE;
}
}
return FALSE;
}
static CLAUSE red_ForwardSubsumer(CLAUSE RedCl, SHARED_INDEX ShIndex,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**********************************************************
INPUT: A pointer to a non-empty clause, an index of
clauses, a flag store and a precedence.
RETURNS: A clause that subsumes <RedCl>, or NULL if no such
clause exists.
***********************************************************/
{
TERM Atom,AtomGen;
CLAUSE CandCl;
LITERAL CandLit;
LIST LitScan;
int i, lc, fa, la, fs, ls;
#ifdef CHECK
if (!clause_IsClause(RedCl, Flags, Precedence)) {
misc_StartErrorReport();
misc_ErrorReport("\n In red_ForwardSubsumer:");
misc_ErrorReport(" Illegal input.\n");
misc_FinishErrorReport();
}
clause_Check(RedCl, Flags, Precedence);
#endif
lc = clause_LastConstraintLitIndex(RedCl);
fa = clause_FirstAntecedentLitIndex(RedCl);
la = clause_LastAntecedentLitIndex(RedCl);
fs = clause_FirstSuccedentLitIndex(RedCl);
ls = clause_LastSuccedentLitIndex(RedCl);
for (i = 0; i <= ls; i++) {
Atom = clause_GetLiteralAtom(RedCl, i);
AtomGen = st_ExistGen(cont_LeftContext(), sharing_Index(ShIndex), Atom);
while (AtomGen) {
if (!term_IsVariable(AtomGen)) {
for (LitScan = sharing_NAtomDataList(AtomGen);
!list_Empty(LitScan);
LitScan = list_Cdr(LitScan)) {
CandLit = list_Car(LitScan);
CandCl = clause_LiteralOwningClause(CandLit);
if (CandCl != RedCl &&
clause_GetLiteral(CandCl,clause_FirstLitIndex()) == CandLit &&
/* Literals must be from same part of the clause */
((i<=lc && clause_LiteralIsFromConstraint(CandLit)) ||
(i>=fa && i<=la && clause_LiteralIsFromAntecedent(CandLit)) ||
(i>=fs && clause_LiteralIsFromSuccedent(CandLit))) &&
subs_SubsumesBasic(CandCl, RedCl, clause_FirstLitIndex(), i)) {
st_CancelExistRetrieval();
return (CandCl);
}
}
}
AtomGen = st_NextCandidate();
}
if (fol_IsEquality(Atom) &&
clause_LiteralIsNotOrientedEquality(clause_GetLiteral(RedCl,i))) {
Atom = term_Create(fol_Equality(),list_Reverse(term_ArgumentList(Atom)));
AtomGen = st_ExistGen(cont_LeftContext(), sharing_Index(ShIndex), Atom);
while (AtomGen) {
if (!term_IsVariable(AtomGen)) {
for (LitScan = sharing_NAtomDataList(AtomGen);
!list_Empty(LitScan);
LitScan = list_Cdr(LitScan)) {
CandLit = list_Car(LitScan);
CandCl = clause_LiteralOwningClause(CandLit);
if (CandCl != RedCl &&
clause_GetLiteral(CandCl,clause_FirstLitIndex()) == CandLit &&
/* Literals must be from same part of the clause */
((i<=lc && clause_LiteralIsFromConstraint(CandLit)) ||
(i>=fa && i<=la && clause_LiteralIsFromAntecedent(CandLit)) ||
(i>=fs && clause_LiteralIsFromSuccedent(CandLit))) &&
subs_SubsumesBasic(CandCl, RedCl, clause_FirstLitIndex(), i)) {
st_CancelExistRetrieval();
list_Delete(term_ArgumentList(Atom));
term_Free(Atom);
return (CandCl);
}
}
}
AtomGen = st_NextCandidate();
}
list_Delete(term_ArgumentList(Atom));
term_Free(Atom);
}
}
return((CLAUSE)NULL);
}
static CLAUSE red_ForwardSubsumption(CLAUSE RedClause, SHARED_INDEX ShIndex,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**********************************************************
INPUT: A clause, an index of clauses, a flag store and
a precedence.
RETURNS: The clause <RedClause> is subsumed by in <ShIndex>.
***********************************************************/
{
CLAUSE Subsumer;
#ifdef CHECK
if (!clause_IsClause(RedClause, Flags, Precedence)) {
misc_StartErrorReport();
misc_ErrorReport("\n In red_ForwardSubsumption:");
misc_ErrorReport(" Illegal input.\n");
misc_FinishErrorReport();
}
clause_Check(RedClause, Flags, Precedence);
#endif
Subsumer = red_ForwardSubsumer(RedClause, ShIndex, Flags, Precedence);
if (flag_GetFlagValue(Flags, flag_PSUB) && Subsumer) {
fputs("\nFSubsumption: ", stdout);
clause_Print(RedClause);
printf(" by %d %d ",clause_Number(Subsumer),clause_SplitLevel(Subsumer));
}
return Subsumer;
}
static void red_DocumentRewriting(CLAUSE Clause, int i, CLAUSE Rule, int ri)
/*********************************************************
INPUT: Two clauses and the literal indices involved in the rewrite step.
RETURNS: Nothing.
EFFECT: Documentation in <Clause> is set.
**********************************************************/
{
list_Delete(clause_ParentClauses(Clause));
list_Delete(clause_ParentLiterals(Clause));
clause_SetParentClauses(Clause,
list_List((POINTER)clause_Number(Clause)));
/* Has to be done before increasing the number! */
clause_SetParentLiterals(Clause, list_List((POINTER)i));
clause_NewNumber(Clause);
clause_SetFromRewriting(Clause);
clause_AddParentClause(Clause,clause_Number(Rule));
clause_AddParentLiteral(Clause,ri);
}
static void red_DocumentFurtherRewriting(CLAUSE Clause, int i, CLAUSE Rule, int ri)
/*********************************************************
INPUT: Two clauses and the literal indices involved in the rewrite step.
RETURNS: Nothing.
EFFECT: Documentation in <Clause> is set.
**********************************************************/
{
clause_AddParentClause(Clause,
(int) list_Car(list_Cdr(clause_ParentClauses(Clause))));
clause_AddParentLiteral(Clause, i);
clause_AddParentClause(Clause, clause_Number(Rule));
clause_AddParentLiteral(Clause, ri);
}