File: che_specsigfeatures.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 (276 lines) | stat: -rw-r--r-- 7,568 bytes parent folder | download | duplicates (2)
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
/*-----------------------------------------------------------------------

  File  : che_specsigfeatures.c

  Author: Stephan Schulz (schulz@eprover.org)

  Contents

  Functions for determining various features of specifications,
  i.e. clause and (later) formula sets. This is analoguous to
  che_clausesetfeatures.[ch], but uses different features.


  Copyright 2017 by the authors.
  This code is released under the GNU General Public Licence.
  See the file COPYING in the main CLIB directory for details.
  Run "eprover -h" for contact information.

  Created: Wed Aug 30 11:40:05 CEST 2017

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

#include "che_specsigfeatures.h"



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


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


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


/*-----------------------------------------------------------------------
//
// Function: term_collect_sig_features_rek()
//
//    Collect information of number and depth of occurrence of function
//    symbols of different arity in term.
//
// Global Variables: -
//
// Side Effects    : -
//
/----------------------------------------------------------------------*/

void term_collect_sig_features_rek(Sig_p sig, Term_p t, long* features,
                                   long depth)
{
   if(t->f_code > 0)
   {
      int i;
      features[SigGetFeatureOffset(sig, t->f_code)]++;
      if(!SigIsPredicate(sig, t->f_code) &&
         (depth > features[SigGetDepthFeatureOffset(sig, t->f_code)]))
      {
         features[SigGetDepthFeatureOffset(sig, t->f_code)] = depth;
      }
      for(i=0; i<t->arity; i++)
      {
         term_collect_sig_features_rek(sig, t->args[i], features, depth+1);
      }
   }
}



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


/*-----------------------------------------------------------------------
//
// Function: SpecSigFeatureInit()
//
//   Initialize (set to 0) all features. Could use memset(), but this
//   is more transparent and non critical...
//
// Global Variables: -
//
// Side Effects    : -
//
/----------------------------------------------------------------------*/

void SpecSigFeatureInit(SpecSigFeature_p specftrs)
{
   int i;

   for(i=0; i<SPECSIG_TOTAL_FTR_NO; i++)
   {
      specftrs->features[i] = 0;
   }
}

/*-----------------------------------------------------------------------
//
// Function: SpecSigFeaturePrint
//
//   Print all individual features as a coma-separated list.
//
// Global Variables: -
//
// Side Effects    : -
//
/----------------------------------------------------------------------*/

void SpecSigFeaturePrint(FILE*out, SpecSigFeature_p specftrs)
{
   int i;
   char* sep="";

   for(i=0; i<SPECSIG_TOTAL_FTR_NO; i++)
   {
      fprintf(out, "%s%5ld", sep, specftrs->features[i]);
      sep =", ";
   }
}


/*-----------------------------------------------------------------------
//
// Function: TermCollectSigFeatures()
//
//    Collect information of number and depth of occurrence of function
//    symbols of different arity in term.
//
// Global Variables: -
//
// Side Effects    : -
//
/----------------------------------------------------------------------*/

void TermCollectSigFeatures(Sig_p sig, Term_p term, long* features)
{
   term_collect_sig_features_rek(sig, term, features, 1);
}





/*-----------------------------------------------------------------------
//
// Function: ClauseCollectSigFeatures()
//
//   Collect positive and negative signature features (distribution of
//   arities) for the clause.
//
//   Structure of features (L = SIG_FEATURE_ARITY_LIMIT)
//   features[0]: Number of positive equational literals
//   features[1]: Number of negative equational literals
//   For positive literals:
//   features[...2+L]: Frequency of of pred-symbols of arity n
//   features[...2+2L]: Frequency of fun-symbols of arity n
//   features[...2+3L]: Max depth of fun-symbols of arity n
//   For negative literals:
//   features[...2+4L]: Frequency of of pred-symbols of arity n
//   features[...2+5L]: Frequency of fun-symbols of arity n
//   features[...2+6L]: Max depth of fun-symbols of arity n
//
// Global Variables: -
//
// Side Effects    : -
//
/----------------------------------------------------------------------*/

void ClauseCollectSigFeatures(Clause_p clause, long* features)
{
   Eqn_p handle;

   for(handle = clause->literals; handle; handle = handle->next)
   {
      if(EqnIsPositive(handle))
      {
         EqnCollectSigFeatures(handle, features+2);
         if(EqnIsEquLit(handle))
         {
            features[0]++;
         }
      }
      else
      {
         EqnCollectSigFeatures(handle, features+2+3*SIG_FEATURE_ARITY_LIMIT);
         if(EqnIsEquLit(handle))
         {
            features[1]++;
         }
      }
   }
}


/*-----------------------------------------------------------------------
//
// Function: ClauseComputeSigFeatures()
//
//   Compute the signature-based features of the clause. As above, but
//   zeros out the result vector first.
//
// Global Variables: -
//
// Side Effects    : -
//
/----------------------------------------------------------------------*/

void ClauseComputeSigFeatures(Clause_p clause, long* features)
{
   memset(features, 0, (2+6*SIG_FEATURE_ARITY_LIMIT)*sizeof(long));
   ClauseCollectSigFeatures(clause, features);
}


/*-----------------------------------------------------------------------
//
// Function:
//
//
//
// Global Variables:
//
// Side Effects    :
//
/----------------------------------------------------------------------*/

void ClauseSetCollectSigFeatures(Sig_p sig, ClauseSet_p set,
                                 SpecSigFeature_p specftrs)
{
   Clause_p handle;
   FunCode i;

   for(handle = set->anchor->succ; handle!=set->anchor; handle =
          handle->succ)
   {
      if(ClauseIsConjecture(handle))
      {
         ClauseCollectSigFeatures(handle, specftrs->features+SPECSIG_CJ_FTRS);
      }
      else
      {
         ClauseCollectSigFeatures(handle, specftrs->features+SPECSIG_AX_FTRS);
      }
      if(ClauseIsUnit(handle))
      {
         specftrs->features[SPECSIG_GLOBAL_UNIT]++;
      }
      else if(ClauseIsHorn(handle))
      {
         specftrs->features[SPECSIG_GLOBAL_HORN]++;
      }
      else
      {
         specftrs->features[SPECSIG_GLOBAL_GNRL]++;
      }
   }
   for(i=sig->internal_symbols+1; i<=sig->f_count; i++)
   {
      specftrs->features[SPECSIG_GLOBAL_SIG+SigGetFeatureOffset(sig, i)]++;
      //printf("# %s : %d -> %d\n", sig->f_info[i].name, sig->f_info[i].arity,
      //SigGetFeatureOffset(sig, i));
   }
}



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