File: che_axiomscan.c

package info (click to toggle)
eprover 2.6%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 21,288 kB
  • sloc: ansic: 331,111; csh: 12,026; python: 10,178; awk: 5,825; makefile: 461; sh: 389
file content (232 lines) | stat: -rw-r--r-- 6,346 bytes parent folder | download
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
/*-----------------------------------------------------------------------

File  : che_axiomscan.c

Author: Stephan Schulz

Contents

  Functions for recognizing axioms.

  Copyright 1998, 1999 by the author.
  This code is released under the GNU General Public Licence and
  the GNU Lesser General Public License.
  See the file COPYING in the main E directory for details..
  Run "eprover -h" for contact information.

Changes

<1>     New

-----------------------------------------------------------------------*/

#include "che_axiomscan.h"



/*---------------------------------------------------------------------*/
/*                        Global Variables                             */
/*---------------------------------------------------------------------*/


/*---------------------------------------------------------------------*/
/*                      Forward Declarations                           */
/*---------------------------------------------------------------------*/


/*---------------------------------------------------------------------*/
/*                         Internal Functions                          */
/*---------------------------------------------------------------------*/


#define FAIL_ON(x) if(x){return 0;}


/*---------------------------------------------------------------------*/
/*                         Exported Functions                          */
/*---------------------------------------------------------------------*/

/*-----------------------------------------------------------------------
//
// Function: DetectCommutativity()
//
//   If clause is a comutativity axiom for some function symbol,
//   return this symbol. Otherwise return 0.
//
// Global Variables: -
//
// Side Effects    : -
//
/----------------------------------------------------------------------*/

FunCode DetectCommutativity(Clause_p clause)
{
   Eqn_p lit;

    /*printf("DetectCommutativity: ");
      ClausePrint(stdout,clause,true);printf("\n");*/

   FAIL_ON(!ClauseIsUnit(clause));
   lit = clause->literals;

   assert(lit);
   FAIL_ON(!EqnIsPositive(lit));
   FAIL_ON(TermIsAppliedVar(lit->lterm) || TermIsAppliedVar(lit->rterm));
   FAIL_ON((TermStandardWeight(lit->lterm)!=
       DEFAULT_FWEIGHT+(2*DEFAULT_VWEIGHT))||
      (TermStandardWeight(lit->rterm)!=
       DEFAULT_FWEIGHT+(2*DEFAULT_VWEIGHT)));

   FAIL_ON((lit->lterm->arity!=2)||
      (lit->lterm->f_code!=lit->rterm->f_code));
   assert(lit->lterm->args);
   assert(TermIsVar(lit->lterm->args[0])); /* Otherwise default weight */
   assert(TermIsVar(lit->lterm->args[1])); /* is borked */
   assert(lit->rterm->args);
   assert(TermIsVar(lit->rterm->args[0]));
   assert(TermIsVar(lit->rterm->args[1]));

   FAIL_ON(lit->lterm->args[0] == lit->lterm->args[1]);
   FAIL_ON((lit->lterm->args[0] != lit->rterm->args[1])||(lit->lterm->args[1] != lit->rterm->args[0]));

   return lit->lterm->f_code;
}



/*-----------------------------------------------------------------------
//
// Function: DetectAssociativity()
//
//  If clause is a associativity for some function symbol,
//  return this symbol. Otherwise return 0.
//
// Global Variables:
//
// Side Effects    :
//
/----------------------------------------------------------------------*/

FunCode DetectAssociativity(Clause_p clause)
{
   Eqn_p lit;
   Term_p lterm, rterm;
   FunCode v1, v2, v3;
   FunCode f;

   FAIL_ON(!ClauseIsUnit(clause));
   lit = clause->literals;

   assert(lit);
   FAIL_ON(!EqnIsPositive(lit));
   FAIL_ON((TermStandardWeight(lit->lterm)!=
       (2*DEFAULT_FWEIGHT+(3*DEFAULT_VWEIGHT)))||
      (TermStandardWeight(lit->lterm)!=
       (2*DEFAULT_FWEIGHT+(3*DEFAULT_VWEIGHT))));

   FAIL_ON(lit->lterm->f_code!=lit->rterm->f_code);
   FAIL_ON((lit->lterm->arity!=2));

   if(TermIsVar(lit->lterm->args[0]))
   {
      rterm=lit->lterm;
      lterm=lit->rterm;
   }
   else
   {
      rterm=lit->rterm;
      lterm=lit->lterm;
   }
   f = lterm->f_code;
   FAIL_ON(f!=lterm->args[0]->f_code);
   FAIL_ON(!TermIsVar(lterm->args[0]->args[0]));
   FAIL_ON(!TermIsVar(lterm->args[0]->args[1]));
   FAIL_ON(!TermIsVar(lterm->args[1]));
   v1 = lterm->args[0]->args[0]->f_code;
   v2 = lterm->args[0]->args[1]->f_code;
   v3 = lterm->args[1]->f_code;
   FAIL_ON((v1==v2) || (v1==v3) || (v2==v3));
   /* Now  we know that the left hand side matches. We also know that
      the top symbol of the right hand side is f */
   FAIL_ON(f!=rterm->args[1]->f_code);
   FAIL_ON(v1!=rterm->args[0]->f_code);
   FAIL_ON(v2!=rterm->args[1]->args[0]->f_code);
   FAIL_ON(v3!=rterm->args[1]->args[1]->f_code);

   return f;
}


/*-----------------------------------------------------------------------
//
// Function: ClauseScanAC()
//
//   Enter AC properties induced by clause into sig. Return true if at
//   least a C-axiom has beed detected.
//
// Global Variables: -
//
// Side Effects    : Changes properties in sig
//
/----------------------------------------------------------------------*/

bool ClauseScanAC(Sig_p sig, Clause_p clause)
{
   FunCode f;

   f = DetectCommutativity(clause);
   if(f)
   {
      if(!SigQueryFuncProp(sig, f, FPCommutative))
      {
    SigSetFuncProp(sig, f, FPCommutative);
    PStackPushP(sig->ac_axioms, clause);
      }
      return true;
   }
   f = DetectAssociativity(clause);
   if(f)
   {
      if(!SigQueryFuncProp(sig, f, FPAssociative))
      {
    SigSetFuncProp(sig, f, FPAssociative);
    PStackPushP(sig->ac_axioms, clause);
      }
   }
   return false;
}


/*-----------------------------------------------------------------------
//
// Function: ClauseSetScanAC()
//
//   Enter AC properties induced by clause set into sig. Return true
//   if at least a C-axiom has beed detected.
//
// Global Variables: -
//
// Side Effects    : Changes properties in sig
//
/----------------------------------------------------------------------*/

bool ClauseSetScanAC(Sig_p sig, ClauseSet_p set)
{
   bool res = false;
   Clause_p handle;

   for(handle = set->anchor->succ; handle!=set->anchor; handle =
     handle->succ)
   {
      res |= ClauseScanAC(sig, handle);
   }
   return res;
}



/*---------------------------------------------------------------------*/
/*                        End of File                                  */
/*---------------------------------------------------------------------*/