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
|
/*-----------------------------------------------------------------------
File : pcl_propanalysis.c
Author: Stephan Schulz
Contents
Functions for collecting various amounts of statistical information
about a PCL protocol.
Copyright 1998-2011 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> Fri Mar 8 15:56:49 CET 2002
New
-----------------------------------------------------------------------*/
#include "pcl_propanalysis.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: pcl_weight_compare()
//
// Compare two PCL steps by standard weight of the clause.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
static int pcl_weight_compare(PCLStep_p step1, PCLStep_p step2)
{
double w1, w2;
if(PCLStepIsFOF(step1) && PCLStepIsFOF(step2))
{
return 0;
}
else if(PCLStepIsFOF(step1))
{
return -1;
}
else if(PCLStepIsFOF(step2))
{
return 1;
}
w1 = ClauseStandardWeight(step1->logic.clause);
w2 = ClauseStandardWeight(step2->logic.clause);
if(w1 < w2)
{
return -1;
}
if(w1 > w2)
{
return 1;
}
return 0;
}
/*-----------------------------------------------------------------------
//
// Function: pcl_sc_compare()
//
// Compare two clause PCL steps by strict symbol count of the
// clause. FOF steps are always smaller and equivalent.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
static int pcl_sc_compare(PCLStep_p step1, PCLStep_p step2)
{
double w1, w2;
if(PCLStepIsFOF(step1) && PCLStepIsFOF(step2))
{
return 0;
}
else if(PCLStepIsFOF(step1))
{
return -1;
}
else if(PCLStepIsFOF(step2))
{
return 1;
}
w1 = ClauseSymTypeWeight(step1->logic.clause, 1,1,1,1,1,1,1,1);
w2 = ClauseSymTypeWeight(step2->logic.clause, 1,1,1,1,1,1,1,1);
if(w1 < w2)
{
return -1;
}
if(w1 > w2)
{
return 1;
}
return 0;
}
/*-----------------------------------------------------------------------
//
// Function: pcl_litno_compare()
//
// Compare two PCL steps by literal number.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
static int pcl_litno_compare(PCLStep_p step1, PCLStep_p step2)
{
int w1, w2;
if(PCLStepIsFOF(step1) && PCLStepIsFOF(step2))
{
return 0;
}
else if(PCLStepIsFOF(step1))
{
return -1;
}
else if(PCLStepIsFOF(step2))
{
return 1;
}
w1 = ClauseLiteralNumber(step1->logic.clause);
w2 = ClauseLiteralNumber(step2->logic.clause);
if(w1 < w2)
{
return -1;
}
if(w1 > w2)
{
return 1;
}
return 0;
}
/*-----------------------------------------------------------------------
//
// Function: pcl_depth_compare()
//
// Compare two PCL steps by clause depth.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
static int pcl_depth_compare(PCLStep_p step1, PCLStep_p step2)
{
int w1, w2;
if(PCLStepIsFOF(step1) && PCLStepIsFOF(step2))
{
return 0;
}
else if(PCLStepIsFOF(step1))
{
return -1;
}
else if(PCLStepIsFOF(step2))
{
return 1;
}
w1 = ClauseDepth(step1->logic.clause);
w2 = ClauseDepth(step2->logic.clause);
if(w1 < w2)
{
return -1;
}
if(w1 > w2)
{
return 1;
}
return 0;
}
/*-----------------------------------------------------------------------
//
// Function: pcl_prot_global_count()
//
// Determine the global properties of the PCL listing.
//
// Global Variables: -
//
// Side Effects : Only temporary memory operations.
//
/----------------------------------------------------------------------*/
static void pcl_prot_global_count(PCLProt_p prot, PCLPropData_p data)
{
PCLStep_p tmp;
Clause_p clause;
PStackPointer i;
assert(prot && data);
data->fof_formulae = 0;
data->pos_clauses = 0;
data->neg_clauses = 0;
data->mix_clauses = 0;
data->pos_clause_literals = 0;
data->neg_clause_literals = 0;
data->mix_clause_literals = 0;
data->pos_literals = 0;
data->neg_literals = 0;
data->const_count = 0;
data->func_count = 0;
data->pred_count = 0;
data->var_count = 0;
PCLProtSerialize(prot);
for(i=0; i<PStackGetSP(prot->in_order); i++)
{
tmp = PStackElementP(prot->in_order, i);
if(PCLStepIsFOF(tmp))
{
data->fof_formulae++;
}
else
{
clause = tmp->logic.clause;
if(!ClauseIsEmpty(clause))
{
if(ClauseIsPositive(clause))
{
data->pos_clauses++;
data->pos_clause_literals += ClauseLiteralNumber(clause);
}
else if(ClauseIsNegative(clause))
{
data->neg_clauses++;
data->neg_clause_literals += ClauseLiteralNumber(clause);
}
else
{
data->mix_clauses++;
data->mix_clause_literals += ClauseLiteralNumber(clause);
}
data->pos_literals += clause->pos_lit_no;
data->neg_literals += clause->neg_lit_no;
data->const_count += ClauseSymTypeWeight(clause,
1,1,1,0,0,1,0,1);
data->func_count += ClauseSymTypeWeight(clause,
1,1,1,0,1,0,0,1);
data->pred_count += ClauseSymTypeWeight(clause,
1,1,1,0,0,0,1,1);
data->var_count += ClauseSymTypeWeight(clause,
1,1,1,1,0,0,0,1);
}
}
}
}
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: PCLProtFindMaxStep()
//
// Find and return the first PCL step from the protocol that is
// maximal with respect to cmp, NULL if prot is empty.
//
// Global Variables: -
//
// Side Effects : Only temporary memory operations.
//
/----------------------------------------------------------------------*/
PCLStep_p PCLProtFindMaxStep(PCLProt_p prot, PCLCmpFunType cmp)
{
PCLStep_p res = NULL, tmp;
PStack_p stack;
PTree_p cell;
assert(prot && cmp);
if(!prot->steps)
{
return NULL;
}
stack = PTreeTraverseInit(prot->steps);
cell = PTreeTraverseNext(stack);
res = cell->key;
while((cell=PTreeTraverseNext(stack)))
{
tmp = cell->key;
if(cmp(tmp,res) > 0)
{
res = tmp;
}
}
PStackFree(stack);
return res;
}
/*-----------------------------------------------------------------------
//
// Function: PCLProtPropAnalyse()
//
// Analyse the PCL protocol and put the relevant information into
// data.
//
// Global Variables:
//
// Side Effects :
//
/----------------------------------------------------------------------*/
void PCLProtPropAnalyse(PCLProt_p prot, PCLPropData_p data)
{
data->max_standard_weight_clause =
PCLProtFindMaxStep(prot, pcl_weight_compare);
data->longest_clause =
PCLProtFindMaxStep(prot, pcl_litno_compare);
data->max_symbol_clause =
PCLProtFindMaxStep(prot, pcl_sc_compare);
data->max_depth_clause =
PCLProtFindMaxStep(prot, pcl_depth_compare);
pcl_prot_global_count(prot, data);
}
/*-----------------------------------------------------------------------
//
// Function: PCLProtPropDataPrint()
//
// Print the result of the property analysis in reasonably readable
// form.
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void PCLProtPropDataPrint(FILE* out, PCLPropData_p data)
{
long clauses =
data->pos_clauses+data->neg_clauses+data->mix_clauses;
fprintf(out,
"# Protocol properties\n"
"# ===================\n"
"# Number of clauses : %6ld\n"
"# ...of those positive : %6ld\n"
"# ...of those negative : %6ld\n"
"# ...of those mixed : %6ld\n"
"# Average number of literals : %6.4f\n"
"# ...in positive clauses : %6.4f\n"
"# ...in negative clauses : %6.4f\n"
"# ...in mixed clauses : %6.4f\n"
"# ...positive literals only : %6.4f\n"
"# ...negative literals only : %6.4f\n"
"# Average number of function symbols: %6.4f\n"
"# Average number of variable symbols: %6.4f\n"
"# Average number of constant symbols: %6.4f\n"
"# Average number of predicate symbols: %6.4f\n",
clauses,
data->pos_clauses,
data->neg_clauses,
data->mix_clauses,
(double)(data->pos_literals+data->neg_literals)/clauses,
(double)(data->pos_clause_literals)/data->pos_clauses,
(double)(data->neg_clause_literals)/data->neg_clauses,
(double)(data->mix_clause_literals)/data->mix_clauses,
(double)(data->pos_literals)/clauses,
(double)(data->neg_literals)/clauses,
(double)(data->func_count)/clauses,
(double)(data->var_count)/clauses,
(double)(data->const_count)/clauses,
(double)(data->pred_count)/clauses);
fprintf(out, "# Longest Clause (if any): \n");
PCLStepPrint(out, data->longest_clause);
fprintf(out, "\n# Largest Clause (if any): \n");
PCLStepPrint(out, data->max_symbol_clause);
fprintf(out, "\n# Heaviest Clause (if any): \n");
ClausePropInfoPrint(out, data->max_standard_weight_clause->logic.clause);
PCLStepPrint(out, data->max_standard_weight_clause);
fprintf(out, "\n# Deepest Clause (if any): \n");
PCLStepPrint(out, data->max_depth_clause);
fprintf(out, "\n");
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|