forked from eprover/eprover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcco_sine.c
617 lines (521 loc) · 18.3 KB
/
cco_sine.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
/*-----------------------------------------------------------------------
File : cco_sine.c
Author: Stephan Schulz (schulz@eprover.org)
Contents
SinE-like specification filtering.
Copyright 2012 by the author.
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.
Changes
<1> Thu May 10 15:39:26 CEST 2012
New
-----------------------------------------------------------------------*/
#include "cco_sine.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: sine_get_filter()
//
// Given a filter string (a definition or a name), return the
// described filter. Initialize filters with a set of filters
// including the described one.
//
// Global Variables: -
//
// Side Effects : Termination in error case.
//
/----------------------------------------------------------------------*/
static AxFilter_p sine_get_filter(char* fname, AxFilterSet_p *filters)
{
AxFilter_p filter;
Scanner_p in;
in = CreateScanner(StreamTypeOptionString, fname, true, NULL, true);
CheckInpTok(in, Name);
if(TestTok(LookToken(in,1), NoToken))
{
*filters = AxFilterSetCreateInternal(AxFilterDefaultSet);
filter = AxFilterSetFindFilter(*filters, fname);
if(!filter)
{
DStr_p fstring = DStrAlloc();
AxFilterSetAddNames(fstring, *filters);
Error("Unknown SinE-filter '%s' selected (valid choices: %s)",
USAGE_ERROR,
fname,
DStrView(fstring));
DStrFree(fstring);
}
}
else
{
*filters = AxFilterSetAlloc();
filter = AxFilterDefParse(in);
AxFilterSetAddFilter(*filters, filter);
}
DestroyScanner(in);
return filter;
}
/*-----------------------------------------------------------------------
//
// The following variable settings describe the association of (raw)
// problem class and SInE-Strategy. This is automatically generated
// from suitable test runs. Note that the named strategies must be
// described in che_axfilter.c
//
/----------------------------------------------------------------------*/
/* -------------------------------------------------------*/
/* The following code is generated automagically with */
/* generate_auto.py. Yes, it is fairly ugly ;-) */
/* -------------------------------------------------------*/
/* Class dir used: */
/* CLASS_LMSSMLL : protokoll_X----_auto_300 0 */
/* CLASS_MMSSMSL : protokoll_X----_auto_300 3 */
/* CLASS_LMLSMSL : protokoll_X----_auto_sine16 20 */
/* CLASS_MMSSMSM : protokoll_X----_auto_300 18 */
/* CLASS_MSSMLSM : protokoll_X----_auto_300 0 */
/* CLASS_LMLSLLL : protokoll_X----_auto_sine31 1 */
/* CLASS_MMSMMSM : protokoll_X----_auto_300 13 */
/* CLASS_LMMSMLL : protokoll_X----_auto_sine03 24 */
/* CLASS_LLLLMLL : protokoll_X----_auto_sine11 76 */
/* CLASS_MSLMMSL : protokoll_X----_auto_300 47 */
/* CLASS_MSLSMSL : protokoll_X----_auto_sine11 209 */
/* CLASS_SSSSLSM : protokoll_X----_auto_300 205 */
/* CLASS_SSSSLSL : protokoll_X----_auto_300 23 */
/* CLASS_SSSSMSL : protokoll_X----_auto_300 216 */
/* CLASS_SSSSMSM : protokoll_X----_auto_300 2302 */
/* CLASS_SSSSMSS : protokoll_X----_auto_300 6294 */
/* CLASS_SMSSMSM : protokoll_X----_auto_sine16 4 */
/* CLASS_LSMSMSL : protokoll_X----_auto_sine18 23 */
/* CLASS_SSSSLSS : protokoll_X----_auto_NIX 154 */
/* CLASS_LLLSMSL : protokoll_X----_auto_sine17 3 */
/* CLASS_MSSSMML : protokoll_X----_auto_sine13 6 */
/* CLASS_MSSSMSS : protokoll_X----_auto_sine17 12 */
/* CLASS_LMLMMLL : protokoll_X----_auto_sine12 7 */
/* CLASS_LMLMLLL : protokoll_X----_auto_sine13 23 */
/* CLASS_LSLSMSL : protokoll_X----_auto_sine11 19 */
/* CLASS_MMSSMLL : protokoll_X----_auto_sine31 2 */
/* CLASS_MSSSMSL : protokoll_X----_auto_sine17 14 */
/* CLASS_MSSSMSM : protokoll_X----_auto_300 348 */
/* CLASS_LSSSMSM : protokoll_X----_auto_300 4 */
/* CLASS_MSMSMSL : protokoll_X----_auto_300 22 */
/* CLASS_LMLLMSL : protokoll_X----_auto_300 42 */
/* CLASS_MSSSLSM : protokoll_X----_auto_300 26 */
/* CLASS_SSSSMLL : protokoll_X----_auto_300 1 */
/* CLASS_LLLMLLL : protokoll_X----_auto_sine31 10 */
/* CLASS_LMMMMLL : protokoll_X----_auto_sine16 6 */
/* CLASS_MSSSMLL : protokoll_X----_auto_sine12 24 */
/* CLASS_MMMSMLL : protokoll_X----_auto_sine12 2 */
/* Raw association */
char* raw_class[] =
{
"LMSSMLL", /* 0 protokoll_X----_auto_300 */
"MMSSMSL", /* 3 protokoll_X----_auto_300 */
"LMLSMSL", /* 20 protokoll_X----_auto_sine16 */
"MMSSMSM", /* 18 protokoll_X----_auto_300 */
"MSSMLSM", /* 0 protokoll_X----_auto_300 */
"LMLSLLL", /* 1 protokoll_X----_auto_sine31 */
"MMSMMSM", /* 13 protokoll_X----_auto_300 */
"LMMSMLL", /* 24 protokoll_X----_auto_sine03 */
"LLLLMLL", /* 76 protokoll_X----_auto_sine11 */
"MSLMMSL", /* 47 protokoll_X----_auto_300 */
"MSLSMSL", /* 209 protokoll_X----_auto_sine11 */
"SSSSLSM", /* 205 protokoll_X----_auto_300 */
"SSSSLSL", /* 23 protokoll_X----_auto_300 */
"SSSSMSL", /* 216 protokoll_X----_auto_300 */
"SSSSMSM", /* 2302 protokoll_X----_auto_300 */
"SSSSMSS", /* 6294 protokoll_X----_auto_300 */
"SMSSMSM", /* 4 protokoll_X----_auto_sine16 */
"LSMSMSL", /* 23 protokoll_X----_auto_sine18 */
"SSSSLSS", /* 154 protokoll_X----_auto_NIX */
"LLLSMSL", /* 3 protokoll_X----_auto_sine17 */
"MSSSMML", /* 6 protokoll_X----_auto_sine13 */
"MSSSMSS", /* 12 protokoll_X----_auto_sine17 */
"LMLMMLL", /* 7 protokoll_X----_auto_sine12 */
"LMLMLLL", /* 23 protokoll_X----_auto_sine13 */
"LSLSMSL", /* 19 protokoll_X----_auto_sine11 */
"MMSSMLL", /* 2 protokoll_X----_auto_sine31 */
"MSSSMSL", /* 14 protokoll_X----_auto_sine17 */
"MSSSMSM", /* 348 protokoll_X----_auto_300 */
"LSSSMSM", /* 4 protokoll_X----_auto_300 */
"MSMSMSL", /* 22 protokoll_X----_auto_300 */
"LMLLMSL", /* 42 protokoll_X----_auto_300 */
"MSSSLSM", /* 26 protokoll_X----_auto_300 */
"SSSSMLL", /* 1 protokoll_X----_auto_300 */
"LLLMLLL", /* 10 protokoll_X----_auto_sine31 */
"LMMMMLL", /* 6 protokoll_X----_auto_sine16 */
"MSSSMLL", /* 24 protokoll_X----_auto_sine12 */
"MMMSMLL", /* 2 protokoll_X----_auto_sine12 */
NULL
};
char* raw_sine[] =
{
NULL,
NULL,
"gf200_h_gu_R03_F100_L20000",
NULL,
NULL,
"gf120_h_gu_RUU_F100_L01000",
NULL,
"gf120_gu_R02_F100_L20000",
"gf500_h_gu_R04_F100_L20000",
NULL,
"gf500_h_gu_R04_F100_L20000",
NULL,
NULL,
NULL,
NULL,
NULL,
"gf200_h_gu_R03_F100_L20000",
"gf200_h_gu_RUU_F100_L20000",
NULL,
"gf600_h_gu_R05_F100_L20000",
"gf120_h_gu_R02_F100_L20000",
"gf600_h_gu_R05_F100_L20000",
"gf120_h_gu_RUU_F100_L00500",
"gf120_h_gu_R02_F100_L20000",
"gf500_h_gu_R04_F100_L20000",
"gf120_h_gu_RUU_F100_L01000",
"gf600_h_gu_R05_F100_L20000",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
"gf120_h_gu_RUU_F100_L01000",
"gf200_h_gu_R03_F100_L20000",
"gf120_h_gu_RUU_F100_L00500",
"gf120_h_gu_RUU_F100_L00500",
NULL
};
/* Predicted solutions: 10203 */
/*-----------------------------------------------------------------------
//
// Function: find_auto_sine()
//
// Given a proof state, return the name of the "best" SInE-Strategy,
// or NULL if SInE is not recommended.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
static char* find_auto_sine(ProofState_p state)
{
SpecLimitsCell limits;
RawSpecFeatureCell features;
int i;
limits.ax_some_limit = 1199;
limits.ax_many_limit = 10396;
limits.term_medium_limit = 664277;
limits.term_large_limit = 5573560;
limits.symbols_medium_limit = 2471;
limits.symbols_large_limit = 4140;
limits.predc_medium_limit = 0;
limits.predc_large_limit = 2;
limits.pred_medium_limit = 1225;
limits.pred_large_limit = 4000;
limits.func_medium_limit = 8;
limits.func_large_limit = 110;
limits.fun_medium_limit = 360;
limits.fun_large_limit = 400;
RawSpecFeaturesCompute(&features, state);
RawSpecFeaturesClassify(&features, &limits, "aaaaaaa");
/* Hard-coded exception - no conjecture & no hypotheses == no
useful SInE! */
if(!(features.conjecture_count+features.hypothesis_count))
{
return NULL;
}
for(i=0; raw_class[i]; i++)
{
if(strcmp(raw_class[i], features.class)==0)
{
return raw_sine[i];
}
}
return NULL;
}
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: StructFOFSpecCreate()
//
// Create a FOF spec, given the term bank (and thus the sig).
//
// Global Variables: -
//
// Side Effects : Memory operations.
//
/----------------------------------------------------------------------*/
StructFOFSpec_p StructFOFSpecCreate(TB_p terms)
{
StructFOFSpec_p handle = StructFOFSpecCellAlloc();
handle->sig = terms->sig;
handle->terms = terms;
handle->clause_sets = PStackAlloc();
handle->formula_sets = PStackAlloc();
handle->parsed_includes = NULL;
handle->f_distrib = GenDistribAlloc(handle->sig);
handle->shared_ax_sp = 0;
return handle;
}
/*-----------------------------------------------------------------------
//
// Function: StructFOFSpecAlloc()
//
// Allocate a Structures problem data structure.
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
StructFOFSpec_p StructFOFSpecAlloc(void)
{
Sig_p sig;
TB_p terms;
TypeBank_p sort_table;
sort_table = TypeBankAlloc();
sig = SigAlloc(sort_table);
SigInsertInternalCodes(sig);
/* We assume free numers for LTB to avoid problems with the
TFF-enabled parser */
sig->distinct_props = sig->distinct_props&~
(FPIsInteger|FPIsRational|FPIsFloat);
terms = TBAlloc(sig);
return StructFOFSpecCreate(terms);
}
/*-----------------------------------------------------------------------
//
// Function: StructFOFSpecFree()
//
// Free a StructFOFSpec data structure.
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
void StructFOFSpecFree(StructFOFSpec_p ctrl)
{
FormulaSet_p fset;
ClauseSet_p cset;
while(!PStackEmpty(ctrl->clause_sets))
{
cset = PStackPopP(ctrl->clause_sets);
ClauseSetFree(cset);
}
PStackFree(ctrl->clause_sets);
while(!PStackEmpty(ctrl->formula_sets))
{
fset = PStackPopP(ctrl->formula_sets);
FormulaSetFree(fset);
}
PStackFree(ctrl->formula_sets);
if(ctrl->sig)
{
if(ctrl->sig->type_bank)
{
TypeBankFree(ctrl->sig->type_bank);
ctrl->sig->type_bank = NULL;
}
SigFree(ctrl->sig);
ctrl->terms->sig = NULL;
}
if(ctrl->terms)
{
TBFree(ctrl->terms);
ctrl->terms = NULL;
}
StrTreeFree(ctrl->parsed_includes);
GenDistribFree(ctrl->f_distrib);
StructFOFSpecCellFree(ctrl);
}
/*-----------------------------------------------------------------------
//
// Function: StructFOFSpecCollectFCode()
//
// Push all formulas that contain f_code onto result. Return number
// of formulas found. Ignores clauses (clauses are deprecated here).
//
// Global Variables: -
//
// Side Effects : Only via PStackPushP()
//
/----------------------------------------------------------------------*/
long StructFOFSpecCollectFCode(StructFOFSpec_p ctrl,
FunCode f_code,
PStack_p res_formulas)
{
long ret = 0;
FormulaSet_p handle;
PStackPointer i;
for(i = 0;
i < PStackGetSP(ctrl->formula_sets);
i++)
{
handle = PStackElementP(ctrl->formula_sets, i);
ret += FormulaSetCollectFCode(handle, f_code, res_formulas);
}
return ret;
}
/*-----------------------------------------------------------------------
//
// Function: StructFOFSpecParseAxioms()
//
// Initialize a StructFOFSpeclCell by parsing all the include files
// in axfiles.
//
// Global Variables: -
//
// Side Effects : I/O, memory operations
//
/----------------------------------------------------------------------*/
long StructFOFSpecParseAxioms(StructFOFSpec_p ctrl, PStack_p axfiles,
IOFormat parse_format, char* default_dir)
{
PStackPointer i;
char* iname;
FormulaSet_p fset;
ClauseSet_p cset;
Scanner_p in;
long res = 0;
static IntOrP dummy = {0};
//printf("# XXX Called with %ld axiom files\n", PStackGetSP(axfiles));
for(i=0; i<PStackGetSP(axfiles); i++)
{
iname = PStackElementP(axfiles, i);
if(!StrTreeFind(&(ctrl->parsed_includes), iname))
{
//printf("Calling with %s\n", iname);
in = CreateScanner(StreamTypeFile, iname, true, default_dir, false);
//printf("Result: %p\n", in);
if(in)
{
ScannerSetFormat(in, parse_format);
fprintf(GlobalOut, "# Parsing %s\n", iname);
cset = ClauseSetAlloc();
fset = FormulaSetAlloc();
res += FormulaAndClauseSetParse(in, fset, cset, ctrl->terms,
NULL,
&(ctrl->parsed_includes));
assert(ClauseSetCardinality(cset)==0);
PStackPushP(ctrl->clause_sets, cset);
PStackPushP(ctrl->formula_sets, fset);
StrTreeStore(&(ctrl->parsed_includes), iname, dummy, dummy);
DestroyScanner(in);
}
else
{
fprintf(GlobalOut, "# Could not find %s\n", iname);
}
}
}
ctrl->shared_ax_sp = PStackGetSP(ctrl->clause_sets);
return res;
}
/*-----------------------------------------------------------------------
//
// Function: StructFOFSpecInitDistrib()
//
// Initialize the f_distrib element of an otherwise initialized
// structured problem cell.
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
void StructFOFSpecInitDistrib(StructFOFSpec_p ctrl)
{
GenDistribSizeAdjust(ctrl->f_distrib, ctrl->sig);
GenDistribAddClauseSets(ctrl->f_distrib, ctrl->clause_sets);
GenDistribAddFormulaSets(ctrl->f_distrib, ctrl->formula_sets);
}
/*-----------------------------------------------------------------------
//
// Function: ProofStateSinE()
//
// Apply SinE with the specified filter to the proofstate (in
// particular state->f_axioms and state->axioms). This is
// destructive. Returns number of axioms deleted.
//
// Global Variables: -
//
// Side Effects : Memory operations aplenty.
//
/----------------------------------------------------------------------*/
long ProofStateSinE(ProofState_p state, char* fname)
{
long axno_orig, axno;
AxFilterSet_p filters = NULL;
AxFilter_p filter;
StructFOFSpec_p spec;
PStack_p clauses, formulas;
if(!fname)
{
return 0;
}
if(strcmp(fname, "Auto")==0)
{
fname = find_auto_sine(state);
}
if(!fname)
{
printf("# No SInE strategy applied\n");
return 0;
}
printf("# SinE strategy is %s\n", fname);
filter = sine_get_filter(fname, &filters);
axno_orig = ClauseSetCardinality(state->axioms)+
FormulaSetCardinality(state->f_axioms);
/* printf("# Magic happens here %s!\n", fname);
printf("# Filter: ");
AxFilterPrint(stdout, filter);
printf("\n"); */
formulas = PStackAlloc();
clauses = PStackAlloc();
spec = StructFOFSpecCreate(state->terms);
/* The following moves the responsibility for the sets into the spec! */
StructFOFSpecAddProblem(spec, state->axioms, state->f_axioms);
GCDeregisterFormulaSet(state->gc_terms, state->f_axioms);
GCDeregisterClauseSet(state->gc_terms, state->axioms);
/* ...so we need to povide fresh, empty axioms sets */
state->axioms = ClauseSetAlloc();
state->f_axioms = FormulaSetAlloc();
GCRegisterFormulaSet(state->gc_terms, state->f_axioms);
GCRegisterClauseSet(state->gc_terms, state->axioms);
StructFOFSpecInitDistrib(spec);
StructFOFSpecGetProblem(spec,
filter,
clauses,
formulas);
PStackClausesMove(clauses, state->axioms);
PStackFormulasMove(formulas, state->f_axioms);
PStackFree(formulas);
PStackFree(clauses);
/* Now rescue signature and term bank. */
spec->sig = NULL;
spec->terms = NULL;
StructFOFSpecFree(spec);
AxFilterSetFree(filters);
axno = ClauseSetCardinality(state->axioms)+
FormulaSetCardinality(state->f_axioms);
return axno_orig-axno;
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/