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
|
/*-----------------------------------------------------------------------
File : pcl_steps.c
Author: Stephan Schulz
Contents
Individual PCL steps and related stuff.
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> Thu Mar 30 19:04:05 MET DST 2000
New
-----------------------------------------------------------------------*/
#include "pcl_steps.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/* Support PCL without logical content - useful for analysing very
* very very large proofs, and faster for Isabelle proofs that don't
* need the intermediate results. This can only be set to true in
* tools that work only on the proof structure, not contents. */
bool SupportShellPCL = false;
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: print_shell_pcl_warning()
//
// Print a warning that a shell PCL step was encountered where a
// normal one was expected.
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
static void print_shell_pcl_warning(FILE* out, PCLStep_p step)
{
if(PCLStepIsShell(step))
{
Warning("Shell PCL step encountered where "
"full PCL step was required");
fprintf(out, "# Step ");
PCLIdPrint(out, step->id);
fprintf(out, " omitted (Shell)\n");
}
}
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: PCLStepFree()
//
// Free a PCL step.
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
void PCLStepFree(PCLStep_p junk)
{
assert(junk && junk->id);
PCLIdFree(junk->id);
if(!PCLStepIsShell(junk))
{
if(PCLStepIsClausal(junk))
{
ClauseFree(junk->logic.clause);
}
else
{
/* tformula collected by garbage collector */
}
}
PCLExprFree(junk->just);
if(junk->extra)
{
FREE(junk->extra);
}
PCLStepCellFree(junk);
}
/*-----------------------------------------------------------------------
//
// Function: PCLParseExternalType()
//
// Parse a list of type annotations for PCL steps and return a
// property word that can be used with SetProp() to set all
// necessary properties (the type field and the lemma bit).
//
// Global Variables: -
//
// Side Effects : Reads input
//
/----------------------------------------------------------------------*/
PCLStepProperties PCLParseExternalType(Scanner_p in)
{
PCLStepProperties type = PCLTypeAxiom, extra = PCLNoProp;
while(!TestInpTok(in, Colon))
{
if(TestInpId(in, "conj"))
{
type = PCLTypeConjecture;
NextToken(in);
}
else if(TestInpId(in, "que"))
{
type = PCLTypeQuestion;
NextToken(in);
}
else if(TestInpId(in, "neg"))
{
type = PCLTypeNegConjecture;
NextToken(in);
}
else if(TestInpId(in, "lemma"))
{
extra = PCLIsLemma;
NextToken(in);
}
else
{
CheckInpId(in, "conj|neg|lemma");
}
if(!TestInpTok(in, Colon))
{
AcceptInpTok(in, Comma);
}
}
return type | extra;
}
/*-----------------------------------------------------------------------
//
// Function: PCLStepParse()
//
// Parse a PCL step.
//
// Global Variables: -
//
// Side Effects : Input, memory operations
//
/----------------------------------------------------------------------*/
PCLStep_p PCLStepParse(Scanner_p in, TB_p bank)
{
PCLStep_p handle = PCLStepCellAlloc();
assert(in);
assert(bank);
handle->bank = bank;
PCLStepResetTreeData(handle, false);
handle->id = PCLIdParse(in);
AcceptInpTok(in, Colon);
handle->properties = PCLParseExternalType(in);
AcceptInpTok(in, Colon);
if(SupportShellPCL && TestInpTok(in, Colon))
{
handle->logic.clause = NULL;
PCLStepSetProp(handle, PCLIsShellStep);
}
else if(TestInpTok(in, OpenSquare))
{
handle->logic.clause = ClausePCLParse(in, bank);
PCLStepDelProp(handle, PCLIsFOFStep);
}
else
{
handle->logic.formula = TFormulaTPTPParse(in, bank);
PCLStepSetProp(handle, PCLIsFOFStep);
}
AcceptInpTok(in, Colon);
handle->just = PCLFullExprParse(in);
if(TestInpTok(in, Colon))
{
NextToken(in);
CheckInpTok(in, SQString|Name|PosInt);
handle->extra = DStrCopy(AktToken(in)->literal);
NextToken(in);
}
else
{
handle->extra = NULL;
}
PCLStepDelProp(handle, PCLIsProofStep);
if(handle->just->op == PCLOpInitial)
{
PCLStepSetProp(handle, PCLIsInitial);
}
return handle;
}
/*-----------------------------------------------------------------------
//
// Function: PCLPrintExternalType()
//
// Print the type(s) of a PCL step encoded in props.
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void PCLPrintExternalType(FILE* out, PCLStepProperties props)
{
char *prepend="";
if(props&PCLIsLemma)
{
fputs("lemma", out);
prepend = ",";
}
props = props & PCLTypeMask;
switch(props)
{
case PCLTypeNegConjecture:
fputs(prepend, out);
fputs("neg", out);
break;
case PCLTypeConjecture:
fputs(prepend, out);
fputs("conj", out);
break;
case PCLTypeQuestion:
fputs(prepend, out);
fputs("que", out);
break;
default:
break;
}
}
/*-----------------------------------------------------------------------
//
// Function: PCLStepPrintExtra()
//
// Print a PCL step.
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void PCLStepPrintExtra(FILE* out, PCLStep_p step, bool data)
{
assert(step);
PCLIdPrintFormatted(out, step->id, true);
fputs(" : ", out);
PCLPrintExternalType(out, step->properties);
fputs(" : ", out);
if(!PCLStepIsShell(step))
{
if(PCLStepIsFOF(step))
{
TFormulaTPTPPrint(out, step->bank, step->logic.formula, true, true);
}
else
{
ClausePCLPrint(out, step->logic.clause, true);
}
}
fputs(" : ", out);
PCLFullExprPrint(out, step->just);
if(step->extra)
{
fputs(" : ", out);
fprintf(out, "%s", step->extra);
}
else if(PCLStepQueryProp(step, PCLIsLemma))
{
fputs(" : 'lemma'", out);
}
#ifdef NEVER_DEFINED
fprintf(out, "/* %ld -> %f */", step->proof_tree_size, step->lemma_quality);
#endif
if(data)
{
#ifdef NEVER_DEFINED
fprintf(out, " /* %#8X %6ld %6ld %3ld %3ld %3ld %3ld %4.3f */",
step->properties,
step->proof_dag_size,
step->proof_tree_size,
step->active_pm_refs,
step->other_generating_refs,
step->active_simpl_refs,
step->passive_simpl_refs,
step->lemma_quality);
#endif
fprintf(out, " /* %3ld %3ld %3ld %3ld %3ld */",
step->contrib_simpl_refs,
step->contrib_gen_refs,
step->useless_simpl_refs,
step->useless_gen_refs,
step->proof_distance);
}
}
/*-----------------------------------------------------------------------
//
// Function: PCLPropToTSTPType()
//
// Given PCL properties, return the best string describing the
// type.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
char * PCLPropToTSTPType(PCLStepProperties props)
{
switch(props & PCLTypeMask)
{
case PCLTypeConjecture:
return "conjecture";
case PCLTypeQuestion:
return "question";
case PCLTypeNegConjecture:
return "negated_conjecture";
default:
if(props&PCLIsLemma)
{
return "lemma";
}
else
{
if(props&PCLIsInitial)
{
return "axiom";
}
else
{
return "plain";
}
}
}
}
/*-----------------------------------------------------------------------
//
// Function: PCLStepPrintTSTP()
//
// Print a PCL step in TSTP format.
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void PCLStepPrintTSTP(FILE* out, PCLStep_p step)
{
assert(step);
if(PCLStepIsClausal(step))
{
fprintf(out, "cnf(");
PCLIdPrintTSTP(out, step->id);
fputc(',', out);
fputs(PCLPropToTSTPType(step->properties), out);
fputc(',', out);
if(PCLStepIsShell(step))
{
}
else
{
ClauseTSTPCorePrint(out, step->logic.clause, true);
}
}
else
{
fprintf(out, "fof(");
PCLIdPrintTSTP(out, step->id);
fputc(',', out);
fputs(PCLPropToTSTPType(step->properties), out);
fputc(',', out);
if(PCLStepIsShell(step))
{
}
else
{
TFormulaTPTPPrint(out, step->bank, step->logic.formula, true, true);
}
}
fputc(',', out);
PCLExprPrintTSTP(out, step->just, false);
if(step->extra)
{
fprintf(out, ",[%s]", step->extra);
}
/* else if(PCLStepQueryProp(step, PCLIsLemma))
{
fputs(",['lemma']", out);
}*/
fputs(").", out);
}
/*-----------------------------------------------------------------------
//
// Function: PCLStepPrintTPTP
//
// Print the logical part of a PCL step as a TPTP-2 clause or
// formula.
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void PCLStepPrintTPTP(FILE* out, PCLStep_p step)
{
assert(step);
if(PCLStepIsShell(step))
{
print_shell_pcl_warning(out, step);
}
else
{
if(PCLStepIsClausal(step))
{
ClausePrintTPTPFormat(out, step->logic.clause);
}
else
{
fprintf(out, "input_formula(");
PCLIdPrintTSTP(out, step->id);
fputc(',', out);
fputs(PCLPropToTSTPType(step->properties), out);
fputc(',', out);
TFormulaTPTPPrint(out, step->bank, step->logic.formula, true, true);
fputc(')',out);
}
}
}
/*-----------------------------------------------------------------------
//
// Function: PCLStepPrintLOP()
//
// Print the logical part of a PCL step as a LOP clause or formula
// (where TPTP core syntax has to stand in for missing LOP syntac).
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void PCLStepPrintLOP(FILE* out, PCLStep_p step)
{
assert(step);
if(PCLStepIsShell(step))
{
print_shell_pcl_warning(out, step);
}
else
{
if(PCLStepIsClausal(step))
{
ClausePrintLOPFormat(out, step->logic.clause, true);
}
else
{
TFormulaTPTPPrint(out, step->bank, step->logic.formula, true, true);
}
}
}
/*-----------------------------------------------------------------------
//
// Function: PCLStepPrintFormat()
//
// Print a PCL step in the requested format.
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void PCLStepPrintFormat(FILE* out, PCLStep_p step, bool data,
OutputFormatType format)
{
switch(format)
{
case pcl_format:
PCLStepPrintExtra(out, step, data);
break;
case lop_format:
PCLStepPrintLOP(out, step);
break;
case tptp_format:
PCLStepPrintTPTP(out, step);
break;
case tstp_format:
PCLStepPrintTSTP(out, step);
break;
default:
assert(false);
break;
}
}
/*-----------------------------------------------------------------------
//
// Function: PCLStepPrintExampe()
//
// Print a PCL step in the correct format for an E example file for
// pattern-based learning. The format is as follows:
// id: (pd, su, sf, gu, gs, ss):clause
// where currently id is meaningless (a survivor from the old output
// format), pd is the proof distance, su, sf, gu, gs are the
// relative number of simplified or generated proof/nonproof
// clauses, and ss is 0 (it used to be a subsumption count in the
// old format, that information is no longer available in PCL).
//
// Global Variables: -
//
// Side Effects : Output
//
/----------------------------------------------------------------------*/
void PCLStepPrintExample(FILE* out, PCLStep_p step, long id,
long proof_steps, long total_steps)
{
assert(!PCLStepQueryProp(step,PCLIsFOFStep));
if(PCLStepIsShell(step))
{
print_shell_pcl_warning(out, step);
}
else
{
fprintf(out, "%4ld:(%ld, %f,%f,%f,%f):",
id,
step->proof_distance,
step->contrib_simpl_refs/(float)(proof_steps+1),
step->useless_simpl_refs/(float)(total_steps-proof_steps+1),
step->contrib_gen_refs/(float)(proof_steps+1),
step->useless_gen_refs/(float)(total_steps-proof_steps+1));
ClausePrint(out, step->logic.clause, true);
}
}
/*-----------------------------------------------------------------------
//
// Function: PCLStepIdCompare()
//
// Compare two PCL steps by idents (forPTreeObj-Operations).
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
int PCLStepIdCompare(const void* s1, const void* s2)
{
const PCLStep_p step1 = (const PCLStep_p)s1;
const PCLStep_p step2 = (const PCLStep_p)s2;
return PCLIdCompare(step1->id, step2->id);
}
/*-----------------------------------------------------------------------
//
// Function: PCLStepResetTreeData()
//
// Reset all counters and size data elements in the step to 0.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
void PCLStepResetTreeData(PCLStep_p step, bool just_weights)
{
step->proof_dag_size = PCLNoWeight;
step->proof_tree_size = PCLNoWeight;
if(!just_weights)
{
step->active_pm_refs = 0;
step->other_generating_refs = 0;
step->active_simpl_refs = 0;
step->passive_simpl_refs = 0;
step->pure_quote_refs = 0;
step->lemma_quality = 0.0;
step->contrib_simpl_refs = 0;
step->contrib_gen_refs = 0;
step->useless_simpl_refs = 0;
step->useless_gen_refs = 0;
step->proof_distance = PCL_PROOF_DIST_UNKNOWN;
PCLStepDelProp(step,PCLIsLemma|PCLIsMarked);
}
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|