-
Notifications
You must be signed in to change notification settings - Fork 337
/
Copy pathrules-inf.c
4281 lines (3717 loc) · 145 KB
/
rules-inf.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
/**************************************************************/
/* ********************************************************** */
/* * * */
/* * INFERENCE RULES * */
/* * * */
/* * $Module: INFRULES * */
/* * * */
/* * 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$ */
/**************************************************************/
/* Includes */
/**************************************************************/
#include "rules-inf.h"
/**************************************************************/
/* Some auxiliary functions for testing postconditions */
/**************************************************************/
static BOOL inf_LitMax(CLAUSE Clause, int i, int j, SUBST Subst, BOOL Strict,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause, the index of a maximal literal, another
literal index, a substitution, a boolean flag, a
flag store and a precedence.
RETURNS: If <Strict>=FALSE the function returns TRUE iff the
literal at index <i> is still maximal in the
instantiated clause.
If <Strict>=TRUE the function returns TRUE iff the
literal is STRICTLY maximal in the instantiated
clause. The literal at index j is omitted at literal
comparison.
However, setting j to a negative number ensures that
all literals are compared with the literal at
index <i>.
CAUTION: DON'T call this function with a clause with selected
literals!
***************************************************************/
{
TERM Max, LitTerm;
LITERAL Lit;
ord_RESULT Compare;
int k, l;
#ifdef CHECK
if (!clause_LiteralIsMaximal(clause_GetLiteral(Clause, i)) ||
(Strict &&
!clause_LiteralGetFlag(clause_GetLiteral(Clause, i), STRICTMAXIMAL))) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_LitMax: Literal %d isn't %smaximal.",
i, Strict ? "strictly " : "");
misc_FinishErrorReport();
}
if (i < clause_FirstAntecedentLitIndex(Clause) ||
i > clause_LastSuccedentLitIndex(Clause)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_LitMax: Literal index %d is out of range.", i);
misc_FinishErrorReport();
}
/* If literal <i> is selected, there's no need to check for maximality, */
/* if <i> isn't selected, but there're other literals selected, */
/* inferences with literal <i> are forbidden. */
if (clause_GetFlag(Clause, CLAUSESELECT)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_LitMax: There're selected literals.", i);
misc_FinishErrorReport();
}
#endif
Lit = clause_GetLiteral(Clause, i);
/* Check necessary condition */
if (!clause_LiteralIsMaximal(Lit) ||
(Strict && !clause_LiteralGetFlag(Lit, STRICTMAXIMAL)))
return FALSE;
/* Only antecedent and succedent literals are compared, so if there's */
/* only one such literal, it's maximal. */
/* If the substitution is empty, the necessary condition tested above */
/* is sufficient, too. */
if ((clause_NumOfAnteLits(Clause) + clause_NumOfSuccLits(Clause) == 1) ||
subst_Empty(Subst))
return TRUE;
l = clause_LastSuccedentLitIndex(Clause);
Max = subst_Apply(Subst,term_Copy(clause_GetLiteralTerm(Clause,i)));
for (k = clause_FirstAntecedentLitIndex(Clause); k <= l; k++)
if (k != i && k != j &&
clause_LiteralIsMaximal(clause_GetLiteral(Clause, k))) {
/* Only compare with maximal literals, since for every non-maximal */
/* literal, there's at least one maximal literal, that is bigger. */
LitTerm = subst_Apply(Subst,term_Copy(clause_GetLiteralTerm(Clause,k)));
Compare = ord_LiteralCompare(Max,
clause_LiteralIsOrientedEquality(clause_GetLiteral(Clause,i)),
LitTerm,
clause_LiteralIsOrientedEquality(clause_GetLiteral(Clause,k)),
TRUE, Flags, Precedence);
if (Compare == ord_SmallerThan() || (Strict && Compare == ord_Equal())) {
term_Delete(Max);
term_Delete(LitTerm);
return FALSE;
}
term_Delete(LitTerm);
}
term_Delete(Max);
return TRUE;
}
static BOOL inf_LiteralsMax(CLAUSE Clause, int i, SUBST Subst,
CLAUSE PartnerClause, int j, SUBST PartnerSubst,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**************************************************************
INPUT: The parents of a resolution inference, the respective
literal indices and substitutions, a flag store and
a precedence.
RETURNS: TRUE iff the positive/negative literals are still
strictly maximal/maximal in the instantiated clause.
If a negative literal is selected, no comparison
is made.
***************************************************************/
{
#ifdef CHECK
if ((clause_GetFlag(Clause, CLAUSESELECT) &&
!clause_LiteralGetFlag(clause_GetLiteral(Clause,i),LITSELECT)) ||
(clause_GetFlag(PartnerClause, CLAUSESELECT) &&
!clause_LiteralGetFlag(clause_GetLiteral(PartnerClause,j),LITSELECT))) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_LiteralsMax: Another literal is selected.");
misc_FinishErrorReport();
}
#endif
if (!clause_GetFlag(Clause, CLAUSESELECT) &&
!inf_LitMax(Clause,i,-1,Subst,
i>clause_LastAntecedentLitIndex(Clause),Flags, Precedence))
return FALSE;
if (!clause_GetFlag(PartnerClause, CLAUSESELECT) &&
!inf_LitMax(PartnerClause,j,-1,PartnerSubst,
j>clause_LastAntecedentLitIndex(PartnerClause), Flags, Precedence))
return FALSE;
return TRUE;
}
static BOOL inf_LitMaxWith2Subst(CLAUSE Clause, int i, int j, SUBST Subst2,
SUBST Subst1, BOOL Strict, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause, the index of a maximal literal, another
literal index, two substitutions, a boolean flag,
a flag store and a precedence.
RETURNS: In contrast to the function inf_LitMax this function
compares the literals with respect to the composition
of the two substitutions Subst2 ° Subst1.
If <Strict>=FALSE the function returns TRUE iff the
literal at index <i> is still maximal in the
instantiated clause.
If <Strict>=TRUE the function returns TRUE iff the
literal is STRICTLY maximal in the instantiated
clause.
The literal at index j is omitted at literal
comparison.
However, setting j to a negative number ensures that
all literals are compared with the literal at
index <i>.
CAUTION: DON'T call this function with a clause with selected
literals!
***************************************************************/
{
TERM Max, LitTerm;
LITERAL Lit;
ord_RESULT Compare;
int k, l;
#ifdef CHECK
if (!clause_LiteralIsMaximal(clause_GetLiteral(Clause, i)) ||
(Strict &&
!clause_LiteralGetFlag(clause_GetLiteral(Clause, i), STRICTMAXIMAL))) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_LitMaxWith2Subst: Literal %d isn't %smaximal.",
i, Strict ? "strictly " : "");
misc_FinishErrorReport();
}
if (i < clause_FirstAntecedentLitIndex(Clause) ||
i > clause_LastSuccedentLitIndex(Clause)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_LitMaxWith2Subst: Literal index %d is out of range.", i);
misc_FinishErrorReport();
}
/* If literal <i> is selected, there's no need to check for maximality, */
/* if <i> isn't selected, but there're other literals selected, */
/* inferences with literal <i> are forbidden. */
if (clause_GetFlag(Clause, CLAUSESELECT)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_LitMaxWith2Subst: There're selected literals.", i);
misc_FinishErrorReport();
}
#endif
Lit = clause_GetLiteral(Clause, i);
/* Check necessary condition */
if (!clause_LiteralIsMaximal(Lit) ||
(Strict && !clause_LiteralGetFlag(Lit, STRICTMAXIMAL)))
return FALSE;
/* Only antecedent and succedent literals are compared, so if there's */
/* only one such literal, it's maximal. */
/* If both substitutions are empty, the necessary condition tested above */
/* is sufficient, too. */
if ((clause_NumOfAnteLits(Clause) + clause_NumOfSuccLits(Clause) == 1) ||
(subst_Empty(Subst1) && subst_Empty(Subst2)))
return TRUE;
l = clause_LastSuccedentLitIndex(Clause);
Max = subst_Apply(Subst1, term_Copy(clause_GetLiteralTerm(Clause,i)));
Max = subst_Apply(Subst2, Max);
for (k = clause_FirstAntecedentLitIndex(Clause); k <= l; k++)
if (k != i && k != j &&
clause_LiteralIsMaximal(clause_GetLiteral(Clause, k))) {
/* Only compare with maximal literals, since for every non-maximal */
/* literal, there's at least one maximal literal, that is bigger. */
LitTerm = subst_Apply(Subst1,term_Copy(clause_GetLiteralTerm(Clause,k)));
LitTerm = subst_Apply(Subst2, LitTerm);
Compare = ord_LiteralCompare(Max,
clause_LiteralIsOrientedEquality(clause_GetLiteral(Clause,i)),
LitTerm,
clause_LiteralIsOrientedEquality(clause_GetLiteral(Clause,k)),
TRUE, Flags, Precedence);
if (Compare == ord_SmallerThan() || (Strict && Compare == ord_Equal())) {
term_Delete(Max);
term_Delete(LitTerm);
return FALSE;
}
term_Delete(LitTerm);
}
term_Delete(Max);
return TRUE;
}
static BOOL inf_LiteralsMaxWith2Subst(CLAUSE Clause, int i, CLAUSE PartnerClause,
int j, SUBST Subst2, SUBST Subst1,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**************************************************************
INPUT: The parents of a resolution inference, the
respective literal indices and substitutions, a
flag store and a precedence.
RETURNS: In contrast to the function inf_LiteralsMax
the composition Subst2 ° Subst1 is applied to both
clauses.
The function returns TRUE iff the positive/negative
literals are still strictly maximal/maximal in the
instantiated clause.
If a negative literal is selected, no comparison
is made.
***************************************************************/
{
#ifdef CHECK
if ((clause_GetFlag(Clause, CLAUSESELECT) &&
!clause_LiteralGetFlag(clause_GetLiteral(Clause,i),LITSELECT)) ||
(clause_GetFlag(PartnerClause, CLAUSESELECT) &&
!clause_LiteralGetFlag(clause_GetLiteral(PartnerClause,j),LITSELECT))) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_LiteralsMaxWith2Subst: Another literal is selected.");
misc_FinishErrorReport();
}
#endif
if (!clause_GetFlag(Clause, CLAUSESELECT) &&
!inf_LitMaxWith2Subst(Clause, i, -1, Subst2, Subst1,
i>clause_LastAntecedentLitIndex(Clause), Flags, Precedence))
return FALSE;
if (!clause_GetFlag(PartnerClause, CLAUSESELECT) &&
!inf_LitMaxWith2Subst(PartnerClause, j, -1, Subst2, Subst1,
j>clause_LastAntecedentLitIndex(PartnerClause), Flags, Precedence))
return FALSE;
return TRUE;
}
/**************************************************************/
/* Inference rules */
/**************************************************************/
LIST inf_EqualityResolution(CLAUSE GivenClause, BOOL Ordered, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause and a flag determining whether ordering
constraints apply.
For <Ordered>=TRUE the function makes Equality Resolution
inferences, for <Ordered>=FALSE Reflexivity Resolution
inferences are made.
A flag store.
A precedence.
RETURNS: A list of clauses inferred from the GivenClause by
Equality/Reflexivity Resolution.
MEMORY: A list of clauses is produced, where memory for the list
and the clauses is allocated.
***************************************************************/
{
LIST Result;
LITERAL ActLit;
int i, last;
#ifdef CHECK
if (!clause_IsClause(GivenClause, Flags, Precedence)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_EqualityResolution: Illegal input.");
misc_FinishErrorReport();
}
#endif
if (clause_HasEmptyAntecedent(GivenClause) ||
!clause_HasSolvedConstraint(GivenClause)) {
return list_Nil();
}
Result = list_Nil();
last = clause_LastAntecedentLitIndex(GivenClause);
for (i = clause_FirstAntecedentLitIndex(GivenClause); i <= last; i++) {
ActLit = clause_GetLiteral(GivenClause, i);
if (clause_LiteralIsEquality(ActLit) &&
(clause_LiteralGetFlag(ActLit,LITSELECT) ||
(!clause_GetFlag(GivenClause,CLAUSESELECT) &&
(!Ordered || clause_LiteralIsMaximal(ActLit))))) {
TERM Atom;
Atom = clause_GetLiteralAtom(GivenClause, i);
cont_Check();
if (unify_UnifyCom(cont_LeftContext(),
term_FirstArgument(Atom),
term_SecondArgument(Atom))) {
SUBST mgu;
CLAUSE NewClause;
int j, k, bound;
subst_ExtractUnifierCom(cont_LeftContext(), &mgu);
/* Check postcondition */
if (clause_LiteralGetFlag(ActLit,LITSELECT) ||
!Ordered || inf_LitMax(GivenClause, i, -1, mgu,
FALSE, Flags, Precedence)) {
NewClause = clause_CreateBody(clause_Length(GivenClause) - 1);
clause_SetNumOfConsLits(NewClause, clause_NumOfConsLits(GivenClause));
clause_SetNumOfAnteLits(NewClause,
(clause_NumOfAnteLits(GivenClause) - 1));
clause_SetNumOfSuccLits(NewClause, clause_NumOfSuccLits(GivenClause));
bound = clause_LastLitIndex(GivenClause);
/* j iterates over the given clause, k iterates over the new one */
for (j = k = clause_FirstLitIndex(); j <= bound; j++) {
if (j != i) {
clause_SetLiteral(NewClause, k,
clause_LiteralCreate(subst_Apply(mgu,
term_Copy(clause_GetLiteralTerm(GivenClause,j))),NewClause));
k++;
}
}
clause_SetDataFromFather(NewClause, GivenClause, i, Flags, Precedence);
clause_SetFromEqualityResolution(NewClause);
Result = list_Cons(NewClause, Result);
}
subst_Delete(mgu);
}
cont_Reset();
} /* end of if 'ActLit is maximal'. */
} /*end of for 'all literals'. */
return(Result);
}
static CLAUSE inf_ApplyEqualityFactoring(CLAUSE Clause, TERM Left, TERM Right,
int i, int j, SUBST Subst,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause, two terms, two indices in the clause,
a substitution, a flag store and a precedence.
RETURNS: A new clause, where <Left>=<Right> is added as antecedent atom,
the <i>th literal is deleted, the <j>th kept and
<Subst> is applied to a copy of <clause>.
***************************************************************/
{
CLAUSE NewClause;
TERM Atom;
int k,c,a,s;
NewClause = clause_CreateBody(clause_Length(Clause));
c = clause_LastConstraintLitIndex(Clause);
clause_SetNumOfConsLits(NewClause, clause_NumOfConsLits(Clause));
a = clause_LastAntecedentLitIndex(Clause);
clause_SetNumOfAnteLits(NewClause, clause_NumOfAnteLits(Clause) + 1);
s = clause_LastSuccedentLitIndex(Clause);
clause_SetNumOfSuccLits(NewClause, clause_NumOfSuccLits(Clause) - 1);
for (k = clause_FirstLitIndex(); k <= c; k++) {
clause_SetLiteral(NewClause, k,
clause_LiteralCreate(subst_Apply(Subst,
term_Copy(clause_GetLiteralTerm(Clause, k))),NewClause));
}
for ( ; k <= a; k++) {
clause_SetLiteral(NewClause, k,
clause_LiteralCreate(subst_Apply(Subst,
term_Copy(clause_GetLiteralTerm(Clause, k))),NewClause));
}
Atom = term_Create(fol_Equality(),
list_Cons(term_Copy(Left),list_List(term_Copy(Right))));
clause_SetLiteral(NewClause, k, clause_LiteralCreate(
term_Create(fol_Not(), list_List(subst_Apply(Subst,Atom))), NewClause));
a = 1; /* Shift */
for ( ; k <= s; k++) {
if (k == i)
a = 0;
else {
clause_SetLiteral(NewClause, (k + a),
clause_LiteralCreate(subst_Apply(Subst,
term_Copy(clause_GetLiteralTerm(Clause, k))),NewClause));
}
}
clause_AddParentClause(NewClause, clause_Number(Clause));
clause_AddParentLiteral(NewClause, j);
clause_SetDataFromFather(NewClause, Clause, i, Flags, Precedence);
clause_SetFromEqualityFactoring(NewClause);
return NewClause;
}
static BOOL inf_EqualityFactoringApplicable(CLAUSE Clause, int i, TERM Left,
TERM Right, SUBST Subst,
FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause <Clause>, the index <i> of a maximal
equality literal in <Clause> <j>, <Left> and
<Right> are the left and right side of the literal,
where <Right> is not greater than <Left> wrt the
ordering, a unifier <Subst>, a flag store and a
precedence.
RETURNS: TRUE iff the literal at index <i> is strictly
maximal in the instantiated clause and <Right> is
not greater than or equal to <Left> after
application of the substitution.
Otherwise, the function returns FALSE.
***************************************************************/
{
ord_RESULT Help;
/* Literal oriented? */
if (!clause_LiteralIsOrientedEquality(clause_GetLiteral(Clause, i))) {
TERM NLeft, NRight;
NLeft = subst_Apply(Subst, term_Copy(Left));
NRight = subst_Apply(Subst, term_Copy(Right));
if ((Help = ord_Compare(NLeft,NRight,Flags, Precedence)) == ord_SmallerThan() ||
Help == ord_Equal()) {
term_Delete(NLeft);
term_Delete(NRight);
return FALSE;
}
term_Delete(NLeft);
term_Delete(NRight);
}
/* Literal maximal? */
return inf_LitMax(Clause, i, -1, Subst, FALSE, Flags, Precedence);
}
LIST inf_EqualityFactoring(CLAUSE GivenClause, FLAGSTORE Flags,
PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause, a flag store and a precedence.
RETURNS: A list of clauses derivable from 'GivenClause' by EF.
***************************************************************/
{
LIST Result;
LITERAL ActLit;
int i, j, last;
SUBST mgu;
#ifdef CHECK
if (!clause_IsClause(GivenClause, Flags, Precedence)) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_EqualityFactoring: Illegal input.");
misc_FinishErrorReport();
}
#endif
if (clause_HasEmptySuccedent(GivenClause) ||
clause_GetFlag(GivenClause, CLAUSESELECT) ||
!clause_HasSolvedConstraint(GivenClause)) {
return list_Nil();
}
Result = list_Nil();
last = clause_LastSuccedentLitIndex(GivenClause);
for (i = clause_FirstSuccedentLitIndex(GivenClause); i <= last; i++) {
ActLit = clause_GetLiteral(GivenClause, i);
if (clause_LiteralIsMaximal(ActLit) &&
clause_LiteralIsEquality(ActLit)) {
TERM Atom, Left, Right;
LITERAL PartnerLit;
Atom = clause_LiteralAtom(ActLit);
Left = term_FirstArgument(Atom);
Right = term_SecondArgument(Atom);
for (j = clause_FirstSuccedentLitIndex(GivenClause); j <= last; j++) {
PartnerLit = clause_GetLiteral(GivenClause, j);
if (i != j && clause_LiteralIsEquality(PartnerLit)) {
/* i==j can be excluded since this inference would either generate */
/* a copy of the given clause (if one side of the equality is */
/* unified with itself), or generate a tautology (if different */
/* sides of the equality are unified). */
TERM PartnerAtom, PartnerLeft, PartnerRight;
PartnerAtom = clause_LiteralAtom(PartnerLit);
PartnerLeft = term_FirstArgument(PartnerAtom);
PartnerRight = term_SecondArgument(PartnerAtom);
/* try <Left> and <PartnerLeft> */
cont_Check();
if (unify_UnifyCom(cont_LeftContext(), Left, PartnerLeft)) {
subst_ExtractUnifierCom(cont_LeftContext(), &mgu);
if (inf_EqualityFactoringApplicable(GivenClause, i, Left, Right,
mgu, Flags, Precedence))
Result = list_Cons(inf_ApplyEqualityFactoring(GivenClause,Right,
PartnerRight,i,j,
mgu,Flags,
Precedence),
Result);
subst_Delete(mgu);
}
cont_Reset();
/* try <Left> and <PartnerRight> */
cont_Check();
if (unify_UnifyCom(cont_LeftContext(), Left, PartnerRight)) {
subst_ExtractUnifierCom(cont_LeftContext(), &mgu);
if (inf_EqualityFactoringApplicable(GivenClause, i, Left, Right,
mgu, Flags, Precedence))
Result = list_Cons(inf_ApplyEqualityFactoring(GivenClause,Right,
PartnerLeft,i,j,
mgu,Flags,
Precedence),
Result);
subst_Delete(mgu);
}
cont_Reset();
if (!clause_LiteralIsOrientedEquality(ActLit)) {
/* try <Right> and <PartnerLeft> */
cont_Check();
if (unify_UnifyCom(cont_LeftContext(), Right, PartnerLeft)) {
subst_ExtractUnifierCom(cont_LeftContext(), &mgu);
if (inf_EqualityFactoringApplicable(GivenClause, i, Right, Left,
mgu, Flags, Precedence))
Result = list_Cons(inf_ApplyEqualityFactoring(GivenClause,Left,
PartnerRight,i,j,
mgu,Flags,
Precedence),
Result);
subst_Delete(mgu);
}
cont_Reset();
/* try <Right> and <PartnerRight> */
cont_Check();
if (unify_UnifyCom(cont_LeftContext(), Right, PartnerRight)) {
subst_ExtractUnifierCom(cont_LeftContext(), &mgu);
if (inf_EqualityFactoringApplicable(GivenClause, i, Right, Left,
mgu, Flags, Precedence))
Result = list_Cons(inf_ApplyEqualityFactoring(GivenClause,Left,
PartnerLeft,i,j,
mgu,Flags,
Precedence),
Result);
subst_Delete(mgu);
}
cont_Reset();
}
}
}
}
}
return Result;
}
/* START of block with new term replacement */
static BOOL inf_NAllTermsRplac(TERM Term, TERM TestTerm, TERM RplacTerm,
SUBST Subst)
/**************************************************************
INPUT: Three terms, a substitution and an integer.
All occurrences of <TestTerm> in <Term> are replaced
by <RplacTerm>. The substitution <Subst> is applied to <Term>.
RETURNS: TRUE, if TestTerm was replaced by RplacTerm,
FALSE otherwise.
EFFECT: <Term> is destructively changed!
***************************************************************/
{
LIST ArgListNode;
BOOL Replaced;
int Bottom;
Replaced = FALSE;
/* check if whole term must be replaced */
if (term_Equal(Term, TestTerm)) {
term_RplacTop(Term,term_TopSymbol(RplacTerm));
ArgListNode = term_ArgumentList(Term);
term_RplacArgumentList(Term, term_CopyTermList(term_ArgumentList(RplacTerm)));
term_DeleteTermList(ArgListNode);
return TRUE;
}
if (term_IsVariable(Term))
subst_Apply(Subst, Term);
/* if not, scan whole term. */
if (!list_Empty(term_ArgumentList(Term))) {
Bottom = stack_Bottom();
stack_Push(term_ArgumentList(Term));
while (!stack_Empty(Bottom)) {
ArgListNode = stack_Top();
Term = (TERM)list_Car(ArgListNode);
stack_RplacTop(list_Cdr(ArgListNode));
if (term_Equal(Term, TestTerm)) {
Replaced = TRUE;
list_Rplaca(ArgListNode, term_Copy(RplacTerm));
term_Delete(Term);
}
else {
if (term_IsComplex(Term))
stack_Push(term_ArgumentList(Term));
else if (term_IsVariable(Term))
subst_Apply(Subst,Term);
}
/* remove empty lists (corresponding to scanned terms) */
while (!stack_Empty(Bottom) && list_Empty(stack_Top()))
stack_Pop();
}
}
return Replaced;
}
static TERM inf_AllTermsRplac(TERM Term, TERM TestTerm, TERM RplacTerm,
SUBST Subst)
/**************************************************************
INPUT: Three terms, a substitution.
All occurrences of <TestTerm> in A COPY of <Term> are replaced
by <RplacTerm>. The substitution <Subst> is applied to
the copy of <Term>. If no occurrence is found,
NULL is returned.
This function is not destructive
like NAllTermRplac.
RETURNS: TRUE, if TestTerm was replaced by RplacTerm,
FALSE otherwise.
***************************************************************/
{
TERM ActTerm = term_Copy(Term);
if (!inf_NAllTermsRplac(ActTerm,TestTerm, RplacTerm, Subst )) {
term_Delete(ActTerm);
ActTerm = NULL;
}
return(ActTerm);
}
static TERM inf_AllTermsSideRplacs(TERM Term, TERM TestTerm, TERM RplacTerm,
SUBST Subst, BOOL Right)
/**************************************************************
INPUT: Three terms, a substitution and a boolean flag.
<Term> is typically an equality term.
RETURNS: If <TestTerm> occurs in the right (Right=TRUE) or
left side (Right=FALSE) of <Term>:
A copy of the term where all occurrences of <TestTerm>
in the ENTIRE <Term> are replaced by <RplacTerm> and
the substitution <Subst> is applied to all other subterms.
If <TestTerm> does not occur in the right/left side of
<Term>, NULL is returned.
In non-equality terms, The 'sides' correspond to the
first and second argument of the term.
***************************************************************/
{
TERM ActTerm = term_Copy(Term);
TERM ReplSide, OtherSide; /* ReplSide is the side in which terms are
replaced */
if (Right) {
ReplSide = term_SecondArgument(ActTerm);
OtherSide = term_FirstArgument(ActTerm);
}
else {
ReplSide = term_FirstArgument(ActTerm);
OtherSide = term_SecondArgument(ActTerm);
}
if (inf_NAllTermsRplac(ReplSide, TestTerm, RplacTerm, Subst))
/* If <TestTerm> occurs in <ReplSide> also replace it in <OtherSide>. */
inf_NAllTermsRplac(OtherSide, TestTerm, RplacTerm, Subst);
else {
term_Delete(ActTerm);
ActTerm = NULL;
}
return ActTerm;
}
static TERM inf_AllTermsRightRplac(TERM Term, TERM TestTerm, TERM RplacTerm,
SUBST Subst)
/**************************************************************
INPUT: Three terms, a substitution.
<Term> is typically an equality term.
RETURNS: See inf_AllTermSideRplac with argument
'Right' set to TRUE
**************************************************************/
{
return(inf_AllTermsSideRplacs(Term, TestTerm, RplacTerm, Subst, TRUE));
}
static TERM inf_AllTermsLeftRplac(TERM Term, TERM TestTerm, TERM RplacTerm,
SUBST Subst)
/**************************************************************
INPUT: Three terms, a substitution.
<Term> is typically an equality term.
RETURNS: See inf_AllTermSideRplac with argument
'Right' set to FALSE.
***************************************************************/
{
return(inf_AllTermsSideRplacs(Term, TestTerm, RplacTerm, Subst, FALSE));
}
/* END of block with new term replacement */
static CLAUSE inf_ApplyGenSuperposition(CLAUSE Clause, int ci, SUBST Subst,
CLAUSE PartnerClause, int pci,
SUBST PartnerSubst, TERM SupAtom,
BOOL Right, BOOL OrdPara, BOOL MaxPara,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**************************************************************
INPUT: Two clauses where a generalized superposition inference can be
applied using the positive equality literal <i> from <Clause> with
subst <Subst> using the literal <j> from <PartnerClause> with subst
<PartnerSubst> where SupAtom is a derivable atom. Returns
NULL if SupAtom is NULL.
Right is TRUE if the inference is a superposition right inference
Right is FALSE if the inference is a superposition left inference,
where the inference is selected by MaxPara and OrdPara:
(see also inf_GenSuperpositionLeft)
OrdPara=TRUE, MaxPara=TRUE
-> Superposition (Left or Right)
OrdPara=TRUE, MaxPara=FALSE
-> ordered Paramodulation
OrdPara=FALSE, MaxPara=FALSE
-> simple Paramodulation
OrdPara=FALSE, MaxPara=TRUE
-> not defined
A flag store.
A precedence.
RETURNS: The new clause.
MEMORY: Memory for the new clause is allocated.
***************************************************************/
{
CLAUSE NewClause;
int j,lc,la,ls,pls,pla,plc,help;
#ifdef CHECK
if (!OrdPara && MaxPara) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_ApplyGenSuperposition : Illegal inference");
misc_ErrorReport("\n rule selection, OrdPara=FALSE and MaxPara=TRUE.");
misc_FinishErrorReport();
}
if (SupAtom == NULL) {
misc_StartErrorReport();
misc_ErrorReport("\n In inf_ApplyGenSuperposition: Atom is NULL.");
misc_FinishErrorReport();
return clause_Null();
}
#endif
pls = clause_LastSuccedentLitIndex(PartnerClause);
pla = clause_LastAntecedentLitIndex(PartnerClause);
plc = clause_LastConstraintLitIndex(PartnerClause);
ls = clause_LastSuccedentLitIndex(Clause);
la = clause_LastAntecedentLitIndex(Clause);
lc = clause_LastConstraintLitIndex(Clause);
NewClause = clause_CreateBody(clause_Length(Clause) - 1 +
clause_Length(PartnerClause));
clause_SetNumOfConsLits(NewClause, (clause_NumOfConsLits(Clause) +
clause_NumOfConsLits(PartnerClause)));
clause_SetNumOfAnteLits(NewClause, (clause_NumOfAnteLits(Clause) +
clause_NumOfAnteLits(PartnerClause)));
clause_SetNumOfSuccLits(NewClause, ((clause_NumOfSuccLits(Clause) -1)+
clause_NumOfSuccLits(PartnerClause)));
/* First set the literals from the Clause : */
for (j = clause_FirstLitIndex(); j <= lc; j++) {
clause_SetLiteral(NewClause, j,
clause_LiteralCreate(subst_Apply(Subst, term_Copy(
clause_GetLiteralTerm(Clause, j))),NewClause));
}
/* help = number of literals to leave empty */
help = clause_NumOfConsLits(PartnerClause);
for ( ; j <= la; j++) {
clause_SetLiteral(NewClause, (j + help),
clause_LiteralCreate(subst_Apply(Subst, term_Copy(
clause_GetLiteralTerm(Clause, j))),NewClause));
}
/* help = number of literals to leave empty */
help += clause_NumOfAnteLits(PartnerClause);
for ( ; j <= ls; j++) {
if (j != ci) {
/* The literal used in the inference isn't copied */
clause_SetLiteral(NewClause, (j + help),
clause_LiteralCreate(subst_Apply(Subst,
term_Copy(clause_GetLiteralTerm(Clause, j))),NewClause));
} else {
/*the index has to be decreased to avoid an empty literal! */
help--;
}
}
/* Now we consider the PartnerClause : */
/* help = number of already set constraint (Clause) literals */
help = clause_NumOfConsLits(Clause);
for (j = clause_FirstLitIndex(); j <= plc; j++) {
clause_SetLiteral(NewClause, (j + help),
clause_LiteralCreate(subst_Apply(PartnerSubst,
term_Copy(clause_GetLiteralTerm(PartnerClause, j))),NewClause));
}
/* help = number of already set constraint and antecedent Given-literals */
help += clause_NumOfAnteLits(Clause);
for ( ; j <= pla; j++) {
if (j != pci) {
clause_SetLiteral(NewClause, (j + help),
clause_LiteralCreate(subst_Apply(PartnerSubst,
term_Copy(clause_GetLiteralTerm(PartnerClause, j))),NewClause));
} else {
/* The PartnerLit is modified appropriately! */
clause_SetLiteral(NewClause, (j + help), clause_LiteralCreate(
term_Create(fol_Not(),list_List(SupAtom)), NewClause));
}
}
/* help = number of already set Given-literals */
help = clause_Length(Clause) - 1;
for ( ; j <= pls; j++) {
if (j != pci) {
/* The PartnerLit isn't copied! */
clause_SetLiteral(NewClause, (j + help),
clause_LiteralCreate(subst_Apply(PartnerSubst,
term_Copy(clause_GetLiteralTerm(PartnerClause, j))),NewClause));
} else {
/* The PartnerLit is modified appropriately! */
clause_SetLiteral(NewClause, (j + help),
clause_LiteralCreate(SupAtom, NewClause));
}
}
/*
* Set inference type. Note that, in the case of (ordered) paramodulation,
* we do not distinguish which side was paramodulated into, as compared
* to the case of superposition.
*/
if (OrdPara && MaxPara) {
if (Right)
clause_SetFromSuperpositionRight(NewClause);
else
clause_SetFromSuperpositionLeft(NewClause);
}
else if (OrdPara && !MaxPara)
clause_SetFromOrderedParamodulation(NewClause);
else
clause_SetFromParamodulation(NewClause);
clause_SetDataFromParents(NewClause, PartnerClause, pci, Clause, ci, Flags,
Precedence);
return NewClause;
}
/* START of block with new superposition right rule */
static LIST inf_GenLitSPRight(CLAUSE Clause, TERM Left, TERM Right, int i,
SHARED_INDEX ShIndex, BOOL OrdPara, BOOL MaxPara,
FLAGSTORE Flags, PRECEDENCE Precedence)
/**************************************************************
INPUT: A clause (unshared) with a positive equality literal
at position <i> where <Left> and <Right> are the arguments
of just that literal and <Right> is not greater wrt. the
ordering than <Left>,
two boolean flags for controlling inference
preconditions (see inf_GenSuperpositionRight),
a flag store and a precedence.
RETURNS: A list of clauses derivable with the literals owning
clause by general superposition right wrt. the Index.
(see inf_GenSuperpositionRight for selection of inference
rule by OrdPara/MaxPara)
MEMORY: The list of clauses is extended, where memory for the