forked from xamidi/pmGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
1460 lines (1433 loc) · 94.2 KB
/
main.cpp
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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "helper/FctHelper.h"
#include "helper/Version.h"
#include "metamath/DRuleReducer.h"
#include "logic/DlProofEnumerator.h"
#include <boost/algorithm/string.hpp>
#include <cstring>
#include <ctime>
#ifdef _MSC_VER
#include <process.h>
#else
#include <unistd.h>
#endif
using namespace std;
using namespace xamidi::helper;
using namespace xamidi::metamath;
using namespace xamidi::logic;
struct A {
string myTime() {
time_t time = chrono::system_clock::to_time_t(chrono::system_clock::now());
return strtok(ctime(&time), "\n");
}
string myInfo() {
stringstream ss;
ss << "[pid: " << getpid() << ", tid:" << this_thread::get_id() << "]";
return ss.str();
}
A() { cout << myTime() << ": Process started. " << myInfo() << endl; }
~A() { cout << myTime() << ": Process terminated. " << myInfo() << endl; }
} a;
enum class Task {
Invalid,
Customize, // -c
Generate, // -g
CreateReplacements, // -r
ApplyReplacements, // -a
ParseAndPrintProofs, // --parse
TransformProofSummary, // --transform
UnfoldProofSummary, // --unfold
SearchProofFiles, // --search
ExtractFromProofFiles, // --extract
IterateProofCandidates, // --iterate
FileConversion, // --variate
ConclusionLengthPlot, // --plot
MpiFilter // -m
};
static const map<Task, string>& cmdInfo() {
static const map<Task, string> _ = []() {
map<Task, string> _;
_[Task::Customize] =
" -c [-i <file>] [-s <string>] [-n] [-N <limit or -1>] [-l] [-e <id>] [-d]\n"
" Proof system customization ; Generates a SHA-512/224 hash to identify the system, sets the effective data location to \"<data location>/<hash>\", and (if nonexisting) creates the !.def file.\n"
" -i: specify axioms by input file path (where a LF-separated string of axioms is stored), ignoring lines that are empty or starting with '%'\n"
" -s: specify axioms by comma-separated string ; used only when '-i' unspecified ; default: \"C0C1.0,CC0C1.2CC0.1C0.2,CCN0N1C1.0\"\n"
" -n: specify formulas in normal Polish notation (e.g. \"CpCqp\"), not with numeric variables (e.g. \"C0C1.0\")\n"
" -N: enable necessitation rule \"N\" for the given system with unlimited (-N 0) or limited (-N <positive amount>) consecutive necessitation steps allowed\n"
" -l: disable lazy N-rule parsing ; parse proofs Nα:Lβ despite knowing α:β (requires more time but less memory)\n"
" -e: specify extracted system with the given identifier\n"
" -d: default system ; ignore all other arguments except '-e'\n";
_[Task::Generate] =
" -g <limit or -1> [-u] [-q <limit>] [-s] [-l <limit or -1>]\n"
" Generate proof files ; at ./data/[<hash>/]/dProofs-withConclusions/ when '-s' unspecified ; otherwise at ./data/[<hash>/]/dProofs-withoutConclusions/\n"
" -u: unfiltered (significantly faster, but generates redundant proofs)\n"
" -q: limit number of proof candidate strings queued per worker thread (may lower memory requirements for systems with low acceptance rates)\n"
" -s: proof files without conclusions, requires additional parsing\n"
" -l: limit symbolic length of generated conclusions to at most the given number ; works only in extracted environments ; recommended to use in combination with '-q' to save memory\n";
_[Task::CreateReplacements] =
" -r <D-proof database> <output file> [-l <path>] [-i <prefix>] [-s] [-d]\n"
" Replacements file creation based on proof files\n"
" -l: customize data location path ; default: \"data\"\n"
" -i: customize input file path prefix in data location ; default: \"dProofs-withConclusions/dProofs\"\n"
" -s: proof files without conclusions, requires additional parsing ; sets default input file path prefix to \"dProofs-withoutConclusions/dProofs\"\n"
" -d: print debug information\n";
_[Task::ApplyReplacements] =
" -a <initials> <replacements file> <D-proof database> <output file> [-s] [-l] [-w] [-d]\n"
" Apply replacements file\n"
" -s: style all proofs (replace proofs with alphanumerically smaller variants)\n"
" -l: list all proofs (i.e. not only modified proofs)\n"
" -w: wrap results\n"
" -d: print debug information\n";
_[Task::ParseAndPrintProofs] =
" --parse <string> [-n] [-u] [-j <limit or -1>] [-b] [-s] [-e] [-f] [-o <output file>] [-d]\n"
" Parse and print proofs given by a comma-separated string\n"
" -n: print formulas in normal Polish notation (e.g. \"CpCqp\"), not with numeric variables (e.g. \"C0C1.0\")\n"
" -u: print formulas in infix notation with operators as Unicode characters ; used only when '-n' unspecified\n"
" -j: join common subproofs together when they are used at least a given amount of times ; default: 2\n"
" -b: only print conclusions of the given proofs ; sets default of '-j' to 1\n"
" -s: only print summary with conclusions and abstract condensed detachment proofs ; used only when '-b' unspecified\n"
" -e: keep expanded proof strings ; show fully detailed condensed detachment proofs rather than allowing them to contain references ; used only when '-b' unspecified\n"
" -f: proofs are given by input file path (where a comma-separated string is stored), ignoring all CR, LF, whitespace, and lines starting with '%'\n"
" -o: redirect the result's output to the specified file\n"
" -d: print debug information\n";
_[Task::TransformProofSummary] =
" --transform <string> [-s <string>] [-j <limit or -1>] [-p <limit or -1>] [-n] [-u] [-t <string>] [-e] [-i <limit or -1>] [-l <limit or -1>] [-z] [-f] [-o <output file>] [-d]\n"
" Transform proof summary (as by '--parse [...] -s') into recombined variant ; ignores configured system (proof summaries provide their own axioms) ; \",\" represents LF\n"
" -s: list a subproof with its conclusion if it occurs in the given comma-separated list of conclusions\n"
" -j: join common subproofs together when they are used at least a given amount of times ; default: 2\n"
" -p: only keep subproofs with primitive lengths not exceeding the given limit ; default: -1\n"
" -n: specify and print formulas in normal Polish notation (e.g. \"CpCqp\"), not with numeric variables (e.g. \"C0C1.0\")\n"
" -u: print formulas in infix notation with operators as Unicode characters ; does not affect input format (for which '-n' can still be specified)\n"
" -t: only transform proofs of specified theorems (proven by subsequences of the input), given by a comma-separated string ; \".\" to keep all conclusions ; default: final theorem only\n"
" -e: keep expanded proof strings ; show fully detailed condensed detachment proofs rather than allowing them to contain references\n"
" -i: decrease memory requirements but increase time consumption by not storing intermediate unfoldings that exceed a certain length ; default: -1\n"
" -l: abort computation when combined requested proof sequences exceed the given limit in bytes ; default: 134217728 (i.e. 128 MiB)\n"
" -z: proof compression ; find and remove internal redundancies (e.g. non-trivial parts not affecting intermediate theorems) by attempting to use shorter owned subproofs at all positions\n"
" -f: proof summary is given by input file path ; ignores lines that are empty or starting with '%'\n"
" -o: redirect the result's output to the specified file\n"
" -d: print debug information\n";
_[Task::UnfoldProofSummary] =
" --unfold <string> [-n] [-t <string>] [-i <limit or -1>] [-l <limit or -1>] [-w] [-f] [-o <output file>] [-d]\n"
" Break down proof summary (as by '--parse [...] -s') into primitive steps ; ignores configured system (proof summaries provide their own axioms) ; \",\" represents LF\n"
" -n: specify formulas in normal Polish notation (e.g. \"CpCqp\"), not with numeric variables (e.g. \"C0C1.0\")\n"
" -t: obtain proofs of specified theorems (proven by subsequences of the input), given by a comma-separated string ; \".\" to obtain a proof for each conclusion ; default: final theorem only\n"
" -i: decrease memory requirements but increase time consumption by not storing intermediate unfoldings that exceed a certain length ; default: -1\n"
" -l: abort computation when combined requested proof sequences exceed the given limit in bytes ; default: 134217728 (i.e. 128 MiB)\n"
" -w: wrap results\n"
" -f: proof summary is given by input file path ; ignores lines that are empty or starting with '%'\n"
" -o: redirect the result's output to the specified file\n"
" -d: print debug information\n";
_[Task::SearchProofFiles] =
" --search <string> [-n] [-s] [-w] [-p] [-f] [-d]\n"
" Search in proof files at ./data/[<hash>/]/dProofs-withConclusions/ via comma-separated string of full formulas or full proofs ; [Hint: Generate missing files with '--variate 1 -s'.]\n"
" -n: specify formulas in normal Polish notation (e.g. \"CpCqp\"), not with numeric variables (e.g. \"C0C1.0\")\n"
" -s: search for schemas of the given formulas\n"
" -w: search whole collections of schemas (i.e. enable multiple results per term) ; entails '-s'\n"
" -p: search proofs (rather than conclusions) ; used only when '-n' and '-s' unspecified\n"
" -f: search terms are given by input file path (where a comma-separated string is stored), ignoring all CR, LF, whitespace, and lines starting with '%'\n"
" -d: print debug information\n";
_[Task::ExtractFromProofFiles] =
" --extract [-t <limit or -1>] [-o <output file>] [-s] [-# <amount up to 35>] [-h <string>] [-l <limit or -1>] [-f] [-d]\n"
" Various options to extract information from proof files ; [Hint: Generate missing files with '--variate 1 -s'.]\n"
" -t: compose file with up to the given amount of smallest conclusions that occur in proof files ; includes origins, symbolic lengths, proofs, and formulas in normal Polish notation\n"
" -o: specify output file path for '-t' ; relative to effective data location ; default: \"top<amount>SmallestConclusions_<min proof length>to<max proof length>Steps<unfiltered info>.txt\"\n"
" -s: redundant schema removal for '-t' ; very time-intensive for requesting huge collections from unfiltered proof files - better pre-filter via '-g' or '-m' instead ; default: false\n"
" -#: initialize proof system at ./data/[<hash>/]/extraction-<id>/ with the given amount of smallest filtered conclusions that occur in proof files ; specify with '-c <parent system> -e <id>'\n"
" -h: similar to '-#' ; hand-pick conclusions with a comma-separated string of proofs ; \".\" to not modify axioms\n"
" -l: similar to '-#' (but creates identical system with prebuilt proof files) ; copy proofs with conclusions that have a symbolic length of at most the given number\n"
" -f: proofs for '-h' are given by input file path (where a comma-separated string is stored), ignoring all CR, LF, whitespace, and lines starting with '%'\n"
" -d: print debug information\n";
_[Task::IterateProofCandidates] =
" --iterate [-u] [-s]\n"
" Iterate proof candidates currently next up for generation and print (and store for custom proof systems) their amount for prediction purposes\n"
" -u: use unfiltered proof files\n"
" -s: use proof files without conclusions\n";
_[Task::FileConversion] =
" --variate ( 0 | 1 ) [-l <path>] [-i <prefix>] [-o <prefix>] [-s] [-d]\n"
" Create proof files with removed (--variate 0) or added (--variate 1) conclusions from in-memory data and proof files of the other variant\n"
" -l: customize data location path ; default: \"data\"\n"
" -i: customize input file path prefix in data location ; default: \"dProofs-withConclusions/dProofs\" or \"dProofs-withoutConclusions/dProofs\"\n"
" -o: customize output file path prefix in data location ; default: \"dProofs-withoutConclusions/dProofs\" or \"dProofs-withConclusions/dProofs\"\n"
" -s: only use data stored in-memory\n"
" -d: print debug information\n";
_[Task::ConclusionLengthPlot] =
" --plot [-l <path>] [-i <prefix>] [-s] [-t] [-x <limit or -1>] [-y <limit or -1>] [-o <output file>] [-d]\n"
" Print conclusion length plot data\n"
" -l: customize data location path ; default: \"data\"\n"
" -i: customize input file path prefix in data location ; requires files with conclusions ; default: \"dProofs-withConclusions/dProofs\"\n"
" -s: measure symbolic length (in contrast to conclusion representation length)\n"
" -u: include unfiltered proof files\n"
" -t: table arrangement, one data point per row\n"
" -x: upper horizontal limit\n"
" -y: upper vertical limit\n"
" -o: print to given output file\n"
" -d: print debug information\n";
_[Task::MpiFilter] =
" -m <limit> [-s]\n"
" MPI-based multi-node filtering (-m <n>) of a first unfiltered proof file (with conclusions) at ./data/[<hash>/]dProofs-withConclusions/dProofs<n>-unfiltered<n>+.txt. Creates dProofs<n>.txt.\n"
" -s: disable smooth progress mode (lowers memory requirements, but makes terrible progress predictions)\n";
return _;
}();
return _;
}
int main(int argc, char* argv[]) { // argc = 1 + N, argv = { <command>, <arg1>, ..., <argN> }
// Custom tools' code - (v1.2) : https://github.com/xamidi/pmGenerator/commit/018ac7854f3e620406ba04726802a77acbd6d461
#if 0 //### ./dProofsFromDB ; extract comma-separated list of proofs from all proofs explicitly given in a proof database
if (argc <= 2) {
cerr << "Need 1. path to proof database and 2. path for output file. Optional: 3. whether to only keep unique proofs (default: 0), 4. whether to remove proofs of length 1 (which are invalid in abstract proofs, default: 0)" << endl;
return 0;
}
string outputFile = argv[2];
bool filter = false;
bool removeTrivial = false;
if (argc >= 4) {
string s = argv[3];
filter = (s != "0" && s != "false");
}
if (argc >= 5) {
string s = argv[4];
removeTrivial = (s != "0" && s != "false");
}
vector<string> dProofs = DRuleParser::readFromMmsolitaireFile(argv[1], nullptr, true);
if (filter) {
set<string> s;
vector<string> uniqueDProofs;
for (const string& dProof : dProofs)
if (s.emplace(dProof).second)
uniqueDProofs.push_back(dProof);
dProofs = uniqueDProofs;
}
if (removeTrivial) {
for (vector<string>::iterator it = dProofs.begin(); it != dProofs.end();)
if (it->length() == 1)
it = dProofs.erase(it);
else
it++;
}
stringstream ss;
for (size_t i = 0; i < dProofs.size(); i++) {
if (i)
ss << ",\n";
ss << dProofs[i];
}
ss << "\n";
if (!FctHelper::writeToFile(outputFile, ss.str()))
cerr << "Failed." << endl;
else
cout << ss.str().length() << " bytes written to \"" << outputFile<< "\"." << endl;
return 0;
#endif
#if 0 //### ./findCompactSummary ; determine which args for '--transform <param1> -f -n -t <param2> -j -1 -s <args>' yields a small output (in bytes)
// NOTE: assumes that every formula is derived by a unique proof
// e.g.: ./findCompactSummary data/w3.txt CpCqp,CCpCqrCCpqCpr,CCNpNqCqp,Cpp,CCpqCCqrCpr,CCNppp,CpCNpq
if (argc <= 2) {
cerr << "Need 1. path to proof summary, and 2. requested theorem list in normal Polish notation" << endl;
return 0;
}
string tmpFile = "data/tmp.txt";
string inputFile = argv[1];
unsigned minUseAmountToCreateHelperProof = 2;
size_t maxLengthToKeepProof = SIZE_MAX;
string filterForTheorems = argv[2];
size_t maxLengthToComputeDProof = 134217728;
bool debug = true;
DlProofEnumerator::recombineProofSummary(inputFile, true, nullptr, minUseAmountToCreateHelperProof, maxLengthToKeepProof, true, false, &filterForTheorems, true, SIZE_MAX, maxLengthToComputeDProof, false, &tmpFile, debug);
string summary;
if (!FctHelper::readFile(tmpFile, summary)) {
cerr << "Invalid file path" << endl;
return 0;
}
size_t smallestResultLen = summary.length();
string bestDedicatedConclusions = "all of '-j 2'";
cout << "|summary| = " << smallestResultLen << endl;
vector<string> lines = FctHelper::stringSplitAndSkip(summary, "\n", " ", true);
//#for (const string& line : lines)
//# cout << line << endl;
for (size_t i = 0; i < lines.size(); i++) {
string& line = lines[i];
string::size_type start = line.find(' ');
string::size_type end = line.find(' ', start + 1);
if (start == string::npos || end == string::npos) {
cerr << "Invalid summary: Could not read intermediate conclusions." << endl;
return 0;
}
line = line.substr(start + 1, end - start - 1);
}
//#cout << "lines = " << FctHelper::vectorString(lines) << endl;
minUseAmountToCreateHelperProof = -1;
vector<string> theoremsVec = FctHelper::stringSplit(filterForTheorems, ",");
//#cout << "theorems = " << FctHelper::vectorString(theoremsVec) << endl;
set<string> theorems(theoremsVec.begin(), theoremsVec.end());
vector<string> sharedConclusions;
for (const string& line : lines)
if (!theorems.count(line))
sharedConclusions.push_back(line);
cout << "sharedConclusions = " << FctHelper::vectorString(sharedConclusions) << endl;
cout << "|sharedConclusions| = " << sharedConclusions.size() << endl;
#if 0 // NOTE: In case the function does not work properly (e.g. because there are redundancies in the abstract proof, causing it
// to be greater when using '--transform -s' such that '--transform -j 2' never gets undercut by single modifications),
// a pre-defined list can be used here as a starting point for sucessful reduction.
string startList = "CCCpCCqrCsrtCCCqrCsrt,CCCCCpCCqrCsrtCCCqrCsrtuCvu,CCCpCqrsCCqrs,CCCCCpqrCqrsCts,CCpqCCCpqrCsr,CCCpqrCqr,CCCNpqrCpr,CCNpCCNqrCCCCCCstuCtuvCCvwCxwyCCypCqp,CCCCNpqCrqpCsp,CpCCpqCrq,CpCqCrp,CCCCCCpqCrqsNttCut,CCCNpqCCCCNrsCCtCutvCCvwCrwxCCxyCpy,CCCCCpqrCsrtCqt,CCCpCqrsCrs,CNNCpqCrCpq,CCNCCpCqpNrsCrs,CCCpqCNprCsCNpr,CpCCNCqrrCqr,CCCpCqpNCNNCNrrsCtr,CCpqCNNpq,CCCpqrCNpr,CCNNpqCpq,CCNpqCNCrpq,CCNpqCNCrCspq,CCpqCCNppq,CNCpqCrCsp,CCpCpqCpq,CCpqCCNqpq,CpCCpqq,CCpCqrCqCpr";
vector<string> startList_vec = FctHelper::stringSplit(startList, ",");
set<string> usedConclusions = set<string>(startList_vec.begin(), startList_vec.end());
#else
set<string> usedConclusions = set<string>(sharedConclusions.begin(), sharedConclusions.end());
#endif
size_t oldSmallestResultLen;
do {
oldSmallestResultLen = smallestResultLen;
string usedSequence;
for (set<string>::iterator it = usedConclusions.begin(); it != usedConclusions.end(); ++it) {
if (it != usedConclusions.begin())
usedSequence += ",";
usedSequence += *it;
}
//#cout << "sharedConclusions = " << FctHelper::vectorString(sharedConclusions, { }, { }, ",") << endl;
for (const string& conclusion : sharedConclusions) {
string conclusionsWithHelperProofs;
if (usedConclusions.count(conclusion)) { // used, try to not use it
bool first = true;
for (const string& c : sharedConclusions)
if (usedConclusions.count(c) && c != conclusion) { // iterate used conclusion in correct order (since space for indices may vary)
if (first)
first = false;
else
conclusionsWithHelperProofs += ",";
conclusionsWithHelperProofs += c;
}
//#cout << "[check] removed conclusion: " << conclusion << endl;
} else { // not used, try to use it
bool first = true;
for (const string& c : sharedConclusions)
if (usedConclusions.count(c) || c == conclusion) { // iterate used conclusion in correct order (since space for indices may vary)
if (first)
first = false;
else
conclusionsWithHelperProofs += ",";
conclusionsWithHelperProofs += c;
}
//#cout << "[check] added conclusion: " << conclusion << endl;
}
//#cout << "[NOTE conclusion = " << conclusion << "] Trying " << conclusionsWithHelperProofs << "." << endl;
string bestToggledConclusion;
debug = false;
try {
DlProofEnumerator::recombineProofSummary(inputFile, true, &conclusionsWithHelperProofs, minUseAmountToCreateHelperProof, maxLengthToKeepProof, true, false, &filterForTheorems, true, SIZE_MAX, maxLengthToComputeDProof, false, &tmpFile, debug);
if (!FctHelper::readFile(tmpFile, summary)) {
cerr << "Invalid file path" << endl;
return 0;
}
size_t resultLen = summary.length();
//#cout << "[NOTE] Result: " << resultLen << "(best: " << smallestResultLen << ")" << endl;
if (resultLen < smallestResultLen || (resultLen == smallestResultLen && conclusionsWithHelperProofs.length() < bestDedicatedConclusions.length() && bestDedicatedConclusions != "all of '-j 2'")) {
smallestResultLen = resultLen;
bestDedicatedConclusions = conclusionsWithHelperProofs;
bestToggledConclusion = conclusion;
cout << "new smallestResultLen: " << smallestResultLen << endl;
cout << "new bestDedicatedConclusions: " << bestDedicatedConclusions << endl;
}
} catch (...) {
}
if (!bestToggledConclusion.empty()) {
if (usedConclusions.count(bestToggledConclusion)) { // used, do not use it
usedConclusions.erase(bestToggledConclusion);
} else { // not used, use it
usedConclusions.emplace(bestToggledConclusion);
}
}
}
} while (oldSmallestResultLen != smallestResultLen);
return 0;
#endif //###
#if 0 //### ./searchShorterSubproofs ; search shorter proofs for conclusions used in a given proof summary ; TODO: Use as concept for a low-memory proof reduction function.
// NOTE: Requires '#include "logic/DlCore.h"' and '#include <numeric>'.
// e.g. ./searchShorterSubproofs data/w3.txt 0 data/tmp.txt CpCqp,CCpCqrCCpqCpr,CCNpNqCqp,Cpp,CCpqCCqrCpr,CCNppp,CpCNpq 0
if (argc <= 1) {
cerr << "Need 1. path to proof summary. Optional: 2. necessitation limit (or -1), 3. output file path, 4. target theorems in normal Polish notation, 5. extracted system ID" << endl;
return 0;
}
string proofSummaryFile = argv[1];
uint32_t necessitationLimit = 0;
if (argc >= 3) {
try {
necessitationLimit = stoi(argv[2]);
cout << "Necessitation limit set to " << necessitationLimit << "." << endl;
} catch (...) {
cerr << "Invalid format for \"2. necessitation limit (or -1)\"." << endl;
return 0;
}
}
string tmpFile = "data/tmp.txt";
string _outputFile;
string* outputFile = nullptr;
if (argc >= 4) {
_outputFile = argv[3];
outputFile = &_outputFile;
}
vector<DRuleParser::AxiomInfo>* targetTheorems = nullptr;
vector<DRuleParser::AxiomInfo> _targetTheorems;
if (argc >= 5) {
vector<string> theorems = FctHelper::stringSplit(argv[4], ",");
for (const string& theorem : theorems) {
shared_ptr<DlFormula> f;
if (!DlCore::fromPolishNotation(f, theorem)) {
cerr << "Invalid format for \"4. target theorems in normal Polish notation\"." << endl;
return 0;
}
_targetTheorems.push_back(DRuleParser::AxiomInfo(theorem, f));
}
targetTheorems = &_targetTheorems;
}
string _extractedSystemId;
string* extractedSystemId = nullptr;
if (argc >= 6) {
_extractedSystemId = argv[5];
extractedSystemId = &_extractedSystemId;
}
// 1. Obtain all conclusions used by proof summary (i.e. all which are relevant).
string filterForTheorems = ".";
DlProofEnumerator::recombineProofSummary(proofSummaryFile, true, nullptr, 1, SIZE_MAX, true, false, &filterForTheorems, true, SIZE_MAX, 134217728, false, &tmpFile, false);
vector<string> conclusions;
vector<size_t> fundamentalProofLengths;
vector<DRuleParser::AxiomInfo> customAxioms;
vector<string> abstractDProof;
vector<shared_ptr<DlFormula>> abstractDProofConclusions;
vector<DRuleParser::AxiomInfo> requiredIntermediateResults;
{
DlProofEnumerator::convertProofSummaryToAbstractDProof(tmpFile, customAxioms, abstractDProof, &requiredIntermediateResults, true, true, false);
for (const DRuleParser::AxiomInfo& info : requiredIntermediateResults) {
const shared_ptr<DlFormula>& f = info.refinedAxiom;
abstractDProofConclusions.push_back(f);
//conclusions.push_back(DlCore::toPolishNotation(f));
conclusions.push_back(DlCore::toPolishNotation_noRename(f));
}
vector<size_t> targetIndices(abstractDProof.size());
iota(targetIndices.begin(), targetIndices.end(), 0);
fundamentalProofLengths = DRuleParser::measureFundamentalLengthsInAbstractDProof(targetIndices, abstractDProof, abstractDProofConclusions);
}
if (conclusions.size() != fundamentalProofLengths.size()) {
cerr << "|conclusions| = " << conclusions.size() << " != " << fundamentalProofLengths.size() << " = |fundamentalProofLengths|" << endl;
return 0;
}
cout << "Found " << conclusions.size() << " relevant conclusions." << endl;
cout << "<conclusion>:<fundamental proof length>-pairs:" << endl;
for (size_t i = 0; i < conclusions.size(); i++)
cout << conclusions[i] << ":" << fundamentalProofLengths[i] << endl;
cout << "[Copy] List of Conclusions: " << FctHelper::vectorString(conclusions, { }, { }, ",") << endl;
cout << "[Copy] List of fundamental proof lengths: " << FctHelper::vectorString(fundamentalProofLengths, { }, { }, ",") << endl;
// 2. Search conclusions in proof files.
//#
{
vector<string> axioms;
for (const DRuleParser::AxiomInfo& ax : customAxioms)
axioms.push_back(DlCore::toPolishNotation_noRename(ax.refinedAxiom));
DlProofEnumerator::resetRepresentativesFor(&axioms, false, necessitationLimit, true, extractedSystemId);
}
//#
vector<string> improvedAbstractDProof = abstractDProof;
map<string, string> bestResults = DlProofEnumerator::searchProofFiles(conclusions, false, false, true, nullptr, true);
vector<size_t> indicesToCheck;
vector<string> proofsToCheck;
for (size_t i = 0; i < conclusions.size(); i++) {
const string& conclusion = conclusions[i];
map<string, string>::const_iterator searchResult = bestResults.find(conclusion);
if (searchResult != bestResults.end()) {
size_t usedLen = fundamentalProofLengths[i];
const string& storedProof = searchResult->second;
if (storedProof.length() < usedLen) {
cout << "Found shorter proof " << storedProof << " (length " << storedProof.length() << ") for " << conclusion << " (" << DlCore::toPolishNotation(abstractDProofConclusions[i]) << "), for which a proof of fundamental length " << usedLen << " was given." << endl;
improvedAbstractDProof[i] = storedProof;
} else if (storedProof.length() == usedLen) { // Proof of same length is stored => Need to unfold proof in order to compare alphanumerically.
indicesToCheck.push_back(i);
proofsToCheck.push_back(storedProof);
}
}
}
// 3. Replace with shorter (sub)-proofs.
vector<string> unfoldedProofs = DRuleParser::unfoldRulesInAbstractDProof(indicesToCheck, abstractDProof);
for (size_t j = 0; j < indicesToCheck.size(); j++) {
size_t i = indicesToCheck[j];
const string& conclusion = conclusions[i];
const string& storedProof = proofsToCheck[j];
if (storedProof.length() != fundamentalProofLengths[i])
throw logic_error("storedProof.length() = " + to_string(storedProof.length()) + " != " + to_string(fundamentalProofLengths[i]) + " = fundamentalProofLengths[" + to_string(i) + "]");
const string& unfoldedProof = unfoldedProofs[j];
if (storedProof < unfoldedProof) {
cout << "Found alphanumerically smaller proof " << storedProof << " of the same fundamental length (" << storedProof.length() << ") for " << conclusion << " (" << DlCore::toPolishNotation(abstractDProofConclusions[i]) << ")." << endl;
improvedAbstractDProof[i] = storedProof;
}
}
// 4. Regenerate resulting abstract proof.
vector<shared_ptr<DlFormula>> improvedConclusions;
improvedAbstractDProof = DRuleParser::recombineAbstractDProof(improvedAbstractDProof, improvedConclusions, &customAxioms, targetTheorems, nullptr, 2, &requiredIntermediateResults, true, -2);
// 5. Print result.
bool normalPolishNotation = true; //###
auto print = [&](ostream& mout) -> string::size_type {
string::size_type bytes = 0;
for (const DRuleParser::AxiomInfo& ax : customAxioms) {
string f = normalPolishNotation ? DlCore::toPolishNotation(ax.refinedAxiom) : DlCore::toPolishNotation_noRename(ax.refinedAxiom);
mout << " " << f << " = " << ax.name << "\n";
bytes += 9 + f.length();
}
for (size_t i = 0; i < improvedAbstractDProof.size(); i++) {
string f = normalPolishNotation ? DlCore::toPolishNotation(improvedConclusions[i]) : DlCore::toPolishNotation_noRename(improvedConclusions[i]);
const string& p = improvedAbstractDProof[i];
mout << "[" << i << "] " << f << " = " << p << "\n";
bytes += 7 + FctHelper::digitsNum_uint64(i) + f.length() + p.length();
}
return bytes;
};
chrono::time_point<chrono::steady_clock> startTime = chrono::steady_clock::now();
if (outputFile) { // Not using FctHelper::writeToFile() in order to write huge files without huge string acquisition.
filesystem::path file = filesystem::u8path(*outputFile);
while (!filesystem::exists(file) && !FctHelper::ensureDirExists(file.string()))
cerr << "Failed to create file at \"" << file.string() << "\", trying again." << endl;
string::size_type bytes;
{
ofstream fout(file, fstream::out | fstream::binary);
bytes = print(fout);
}
cout << FctHelper::durationStringMs(chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now() - startTime)) << " taken to print and save " << bytes << " bytes to " << file.string() << "." << endl;
} else {
string::size_type bytes = print(cout);
cout << flush;
cout << FctHelper::durationStringMs(chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now() - startTime)) << " taken to print " << bytes << " bytes." << endl;
}
return 0;
#endif
#if 0 //### ./DBExtractBySummary ; extract those proofs from a proof database which appear in a given proof summary
// NOTE: Requires '#include "logic/DlCore.h"'.
if (argc <= 3) {
cerr << "Need 1. path to proof database (with conclusions commented in normal Polish notation), 2. path to proof summary, and 3. path for output file." << endl;
return 0;
}
string proofDBFile = argv[1];
string proofSummaryFile = argv[2];
string outputFile = argv[3];
// 1. Obtain all conclusions used by proof summary (i.e. all which are relevant).
string filterForTheorems = ".";
DlProofEnumerator::recombineProofSummary(proofSummaryFile, true, nullptr, 1, SIZE_MAX, true, false, &filterForTheorems, true, SIZE_MAX, 134217728, false, &outputFile, false);
unordered_set<string> conclusions;
vector<DRuleParser::AxiomInfo> customAxioms;
{
//vector<DRuleParser::AxiomInfo> customAxioms;
vector<string> abstractDProof;
vector<DRuleParser::AxiomInfo> requiredIntermediateResults;
DlProofEnumerator::convertProofSummaryToAbstractDProof(outputFile, customAxioms, abstractDProof, &requiredIntermediateResults, true, true, false);
//#cout << "abstractDProof = " << FctHelper::vectorString(abstractDProof) << endl;
//#cout << "|abstractDProof| = " << abstractDProof.size() << endl;
//#cout << "requiredIntermediateResults = " << FctHelper::vectorStringF(requiredIntermediateResults, [](const DRuleParser::AxiomInfo& ax) { return DlCore::toPolishNotation(ax.refinedAxiom); }) << endl;
//#cout << "|requiredIntermediateResults| = " << requiredIntermediateResults.size() << endl;
for (const DRuleParser::AxiomInfo& info : requiredIntermediateResults)
conclusions.emplace(DlCore::toPolishNotation(info.refinedAxiom));
}
cout << "Found " << conclusions.size() << " relevant conclusions." << endl;
vector<string> dProofNamesInFile;
vector<string> dProofsInFile = DRuleParser::readFromMmsolitaireFile(proofDBFile, &dProofNamesInFile, true);
// 2. Copy relevant conclusion's D-proofs into new proof database.
vector<size_t> relevantIndices;
string result;
for (size_t i = 0; i < dProofNamesInFile.size(); i++) {
string dProof = dProofsInFile[i];
//vector<DProofInfo> rawParseData = DRuleParser::parseDProof_raw(dProof, &customAxioms);
//const shared_ptr<DlFormula>& conclusion = get<0>(rawParseData.back().second).back();
//string f_ = DlCore::toPolishNotation(conclusion);
string dProofName = dProofNamesInFile[i];
string::size_type pos = dProofName.find("; ! ");
if (pos == string::npos) {
cerr << "Invalid DB file" << endl;
return 0;
}
string::size_type posEnd = dProofName.find(' ', pos + 5);
string f = dProofName.substr(pos + 4, posEnd == string::npos ? string::npos : posEnd - pos - 4);
//if (f != f_) {
// cerr << "f: " << f << ", f_: " << f_ << ", for " << dProofNamesInFile[i] << endl;
// return 0;
//}
if (conclusions.count(f)) {
result += DRuleParser::toDBProof(dProof, &customAxioms, posEnd == string::npos ? f : dProofName.substr(pos + 4)) + "\n";
relevantIndices.push_back(i);
}
}
cout << "Copied for " << relevantIndices.size() << " relevant indices: " << FctHelper::vectorString(relevantIndices) << endl;
if (!FctHelper::writeToFile(outputFile, result))
cerr << "Failed." << endl;
else
cout << result.length() << " bytes written to \"" << outputFile<< "\"." << endl;
// e.g. ./DBExtractBySummary data/exs/m-topDB.txt data/m.txt data/exs/m-relevantDB.txt
return 0;
#endif
#if 0 //### entropy calculation
map<char, size_t> m;
uint32_t num = 57;
ifstream fin("data/0df075acc552c62513b49b6ed674bfcde1c1b018e532c665be229314/dProofs-withConclusions/dProofs" + to_string(num) + ".txt", fstream::in | fstream::binary);
if (!fin.is_open()) {
cerr << "Failed to read the data file. Aborting." << endl;
return 0;
}
char c;
while (fin.get(c))
m[c]++;
size_t len = 0;
for (pair<char, size_t> p : m)
len += p.second;
double result = 0.0;
for (const pair<char, size_t> p : m) {
double frequency = static_cast<double>(p.second) / static_cast<double>(len);
result -= frequency * log2(frequency);
}
cout << "Shannon entropy: " << result << " bits of information per byte" << endl; // e.g. 3.3841 for data/0df075acc552c62513b49b6ed674bfcde1c1b018e532c665be229314/dProofs-withConclusions/dProofs57.txt
cout << "Length: " << len << endl;
cout << "Amounts: " << FctHelper::mapStringF(m, [](const pair<char, size_t>& p) { return "'" + (p.first == '\n' ? "\\n" : string { p.first }) + "':" + to_string(p.second); }) << endl;
return 0;
#endif //###
//#cout << "argc = " << argc << ", argv = { " << [&]() { string s; for (int i = 0; i < argc; i++) { if (i) s += ", "; s += string { argv[i] }; } return s; }() << " }" << endl;
auto printUsage = [&](const string& error = "", Task task = Task::Invalid) {
if (!error.empty())
cerr << error << endl;
switch (task) {
case Task::Invalid:
cout << "\n" << xamidi::version << " ; repository at " << xamidi::repository;
cout << "\nUsage:\n"
" pmGenerator ( <configuring command> | <composable command> )+ | <configuring command>* <standalone command>\n"
"Configuring:\n";
cout << cmdInfo().at(Task::Customize);
cout << "Composable:\n";
cout << cmdInfo().at(Task::Generate);
cout << cmdInfo().at(Task::CreateReplacements);
cout << cmdInfo().at(Task::ApplyReplacements);
cout << cmdInfo().at(Task::ParseAndPrintProofs);
cout << cmdInfo().at(Task::TransformProofSummary);
cout << cmdInfo().at(Task::UnfoldProofSummary);
cout << cmdInfo().at(Task::SearchProofFiles);
cout << cmdInfo().at(Task::ExtractFromProofFiles);
cout << cmdInfo().at(Task::IterateProofCandidates);
cout << cmdInfo().at(Task::FileConversion);
cout << cmdInfo().at(Task::ConclusionLengthPlot);
cout << "Standalone:\n";
cout << cmdInfo().at(Task::MpiFilter);
cout << "Examples:\n"
" pmGenerator -g -1 -q 50\n"
" pmGenerator -g 19 -g 21 -u -r data/pmproofs-old.txt data/pmproofs-reducer.txt -d -a SD data/pmproofs-reducer.txt data/pmproofs-old.txt data/pmproofs-result-styleAll-modifiedOnly.txt -s -w -d\n"
" pmGenerator --variate 0 -l data/ -o \"dProofs-withoutConclusions (all)/dProofs\" -d\n"
" pmGenerator --variate 1 -s --search CNpCCNpqNp -n -d --search CNpCCNpqNp -n -s\n"
" pmGenerator --variate 1 -s --search CCNpCpqCNpCpq,CCCCppCppCCCppCppCNCCqqCqqCCCqqCqqCCqqCqqCCCppCppCNCCqqCqqCCCqqCqqCCqqCqq -n -w -d\n"
" pmGenerator --plot -s -d --plot -s -t -x 50 -y 100 -o data/plot_data_x50_y100.txt\n"
" pmGenerator -c -N -1 -n -s CpCqp,CCpCqrCCpqCpr,CCNpNqCqp,CLpp,CLCpqCLpLq,CNLNpLNLNp --parse DD2D16DD2DD2D13DD2D1D2DD2D1D2D1DD2DD2D13D1DD2DD2D13DD2D13114DD2D13DD2D1311D3DD2DD2D13DD2D1311 -j 2 -n\n"
" pmGenerator --parse DD2D11DD2D13DD2D1DD22D11DD2D11DD2D131 -n -s -o data/CNCpNqCrCsq.txt --transform data/CNCpNqCrCsq.txt -f -n -j 1 -e --transform data/CNCpNqCrCsq.txt -f -n -t CNCpNqCrq -d\n"
" pmGenerator --unfold CpCqp=1,CCpCqrCCpqCpr=2,CCNpNqCqp=3,[0]CCpCNqNrCpCrq:D2D13,[1]Cpp:DD211,[2]NCCppNCqq:DD3DD2DD2D[0]D[0]11D1[1][1] -n -t CNNpp,NCCppNCqq\n"
" pmGenerator --transform data/m.txt -f -n -t CpCqp,CCpCqrCCpqCpr,CCNpNqCqp,Cpp,CCpqCCqrCpr,CCNppp,CpCNpq -j -1 -p -2 -d\n"
" pmGenerator -c -s CCCCC0.1CN2N3.2.4CC4.0C3.0 -g 35 --plot -s -t -x 50 -y 100 -o data/478804cd4793bc7f87041d99326aff4595662146d8a68175dda22bed/plot_data_x50_y100.txt\n"
" pmGenerator -c -n -s CCCCCpqCNrNsrtCCtpCsp --search CpCqp,CCpCqrCCpqCpr,CCNpNqCqp -n\n"
" pmGenerator --variate 1 -s --extract -t 1000 -s -d\n"
" pmGenerator --variate 1 -s --extract -# 35 -d -c -d -e 0\n"
" pmGenerator -m 17 -s\n" << endl;
break;
default:
cout << "\n" << cmdInfo().at(task) << endl;
break;
}
return 0;
};
#if 0 // default command
if (argc <= 1) {
//for (unsigned i = 0; i < 26; i++) cout << ", { \"" << i << "\", \"" << string { (char) ('p' + i <= 'z' ? 'p' + i : 'a' + i - 'z' + 'p' - 1) } << "\" }" << flush; cout << endl; return 0;
//#DlProofEnumerator::sampleCombinations();
//#for (unsigned knownLimit = 1; knownLimit < 100; knownLimit++)
//# cout << knownLimit << ":" << DlProofEnumerator::proofLengthCombinationsD_allLengths(knownLimit, false).size() << endl;
//#return 0;
//#static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -g 19 -g 21 -u -r data/pmproofs-old.txt data/pmproofs-reducer.txt -a SD data/pmproofs-reducer.txt data/pmproofs-old.txt data/pmproofs-result-all.txt -l -w", " ");
//#static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -g 19 -g 21 -u -r data/pmproofs-old.txt data/pmproofs-reducer.txt -a SD data/pmproofs-reducer.txt data/pmproofs-old.txt data/pmproofs-result-styleAll-all.txt -s -l -w", " ");
//#static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -g 19 -g 21 -u -r data/pmproofs-old.txt data/pmproofs-reducer.txt -a SD data/pmproofs-reducer.txt data/pmproofs-old.txt data/pmproofs-result-modifiedOnly.txt -w", " ");
//#static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -g 19 -g 21 -u -r data/pmproofs-old.txt data/pmproofs-reducer.txt -a SD data/pmproofs-reducer.txt data/pmproofs-old.txt data/pmproofs-result-styleAll-modifiedOnly.txt -s -w", " ");
//#static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -g 19 -g 21 -u -r data/pmproofs-old.txt data/pmproofs-reducer.txt -a SD data/pmproofs-reducer.txt data/pmproofs-old.txt data/pmproofs-result-styleAll-modifiedOnly-noWrap.txt -s", " ");
//static vector<string> customCmd = FctHelper::stringSplit("pmGenerator --plot -s -d --plot -s -t -x 50 -y 100 -o data/plot_data_x50_y100.txt", " ");
//static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -r data/pmproofs-unified.txt data/pmproofs-reducer33.txt -d", " ");
//static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -a SD data/pmproofs-reducer33.txt data/pmproofs-unified.txt data/pmproofs-unified33-modifiedOnly-noWrap.txt -s", " ");
//static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -a SD data/pmproofs-reducer33.txt data/pmproofs-unified.txt data/pmproofs-unified33.txt -s -l -w -d", " ");
//static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -g 35 -u", " ");
//static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -m 17", " ");
// Redundancy check ; generates ./data/bf8f05b7537814a14fca0790dab97644033d9ca0ba5293063831124f/{!.def, dProofs-withConclusions/dProofs1.txt}, with "#removals;1:4" in !.def, and "4:C0C1.1" as only representative.
static vector<string> customCmd = FctHelper::stringSplit("pmGenerator -c -s CN0C1.1,C0CN1N1,C0CN1N1,C0C1.1,C0C1.1 --variate 1", " ");
argc = static_cast<int>(customCmd.size());
argv = new char*[customCmd.size()];
for (size_t i = 0; i < customCmd.size(); i++)
argv[i] = const_cast<char*>(customCmd[i].c_str());
}
#endif
if (argc <= 1)
return printUsage();
struct TaskInfo {
Task task;
map<string, string> str;
map<string, int64_t> num;
map<string, bool> bln;
TaskInfo(Task task, const map<string, string>& str, const map<string, int64_t>& num, const map<string, bool>& bln) :
task(task), str(str), num(num), bln(bln) {
}
};
vector<TaskInfo> tasks;
auto lastTask = [&]() -> Task { return tasks.empty() ? Task::Invalid : tasks.back().task; };
string mpiArg;
size_t mpiIgnoreCount = 0;
bool extractedEnv = false;
for (int i = 1; i < argc; i++) {
auto recent = [&](const string& s = "?") {
if (s == "c")
return Task::Customize;
else if (s == "g")
return Task::Generate;
else if (s == "r")
return Task::CreateReplacements;
else if (s == "a")
return Task::ApplyReplacements;
else if (s == "parse")
return Task::ParseAndPrintProofs;
else if (s == "search")
return Task::SearchProofFiles;
else if (s == "iterate")
return Task::IterateProofCandidates;
else if (s == "variate")
return Task::FileConversion;
else if (s == "plot")
return Task::ConclusionLengthPlot;
else if (s == "m")
return Task::MpiFilter;
else
return tasks.empty() ? Task::Invalid : tasks.back().task;
};
if (argv[i][0] != '-' || argv[i][1] == '\0' || (argv[i][2] != '\0' && argv[i][1] != '-') || (argv[i][1] == '-' && argv[i][2] == '\0'))
return printUsage("Invalid argument \"" + string { argv[i] } + "\".", recent());
const char c = argv[i][1];
switch (c) {
// Commands
case 'c': // -c [-i <file>] [-s <string>] [-n] [-N <limit or -1>] [-l] [-e <id>] [-d]
if (!mpiArg.empty())
return printUsage("Invalid argument \"-" + string { c } + "\": Cannot configure after \"" + mpiArg + "\".");
tasks.emplace_back(Task::Customize, map<string, string> { { "axiomString", "C0C1.0,CC0C1.2CC0.1C0.2,CCN0N1C1.0" }, { "axiomFilePath", "" }, { "extractedSystemId", "" } }, map<string, int64_t> { { "necessitationLimit", 0 } }, map<string, bool> { { "useInputFile", false }, { "normalPolishNotation", false }, { "speedupN", true }, { "extractedSystem", false }, { "defaultSystem", false } });
mpiIgnoreCount++;
extractedEnv = false;
break;
case 'g': // -g <limit or -1> [-u] [-q <limit>] [-s] [-l <limit or -1>]
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
try {
tasks.emplace_back(Task::Generate, map<string, string> { }, map<string, int64_t> { { "limit", stoi(argv[++i]) }, { "candidateQueueCapacities", 0 }, { "maxSymbolicConclusionLength", -1 } }, map<string, bool> { { "redundantSchemaRemoval", true }, { "withConclusions", true }, { "whether -q was called", false } });
} catch (...) {
return printUsage("Invalid parameter \"" + string(argv[i]) + "\" for \"-" + string { c } + "\".", recent(string { c }));
}
break;
case 'r': // -r <D-proof database> <output file> [-l <path>] [-i <prefix>] [-s] [-d]
if (i + 2 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
tasks.emplace_back(Task::CreateReplacements, map<string, string> { { "dProofDB", argv[i + 1] }, { "outputFile", argv[i + 2] }, { "dataLocation", "data" }, { "inputFilePrefix", "dProofs-withConclusions/dProofs" } }, map<string, int64_t> { }, map<string, bool> { { "withConclusions", true }, { "debug", false }, { "whether -i was called", false } });
i += 2;
break;
case 'a': // -a <initials> <replacements file> <D-proof database> <output file> [-s] [-l] [-w] [-d]
if (i + 4 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
tasks.emplace_back(Task::ApplyReplacements, map<string, string> { { "initials", argv[i + 1] }, { "replacementsFile", argv[i + 2] }, { "dProofDB", argv[i + 3] }, { "outputFile", argv[i + 4] } }, map<string, int64_t> { }, map<string, bool> { { "styleAll", false }, { "listAll", false }, { "wrap", false }, { "debug", false } });
i += 4;
break;
case 'm': // -m <limit> [-s]
if (tasks.size() > mpiIgnoreCount)
return printUsage("Invalid argument \"-" + string { c } + "\": Can only be combined with preceding configuring commands.");
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
else {
string param = string(argv[++i]);
unsigned value;
from_chars_result result = FctHelper::toUInt(param, value);
if (result.ec != errc())
return printUsage("Invalid parameter \"" + param + "\" for \"-" + string { c } + "\".", recent(string { c }));
tasks.emplace_back(Task::MpiFilter, map<string, string> { }, map<string, int64_t> { { "wordLengthLimit", value } }, map<string, bool> { { "smoothProgress", true } });
mpiArg = "-m";
}
break;
case '-': { // "--<command>"
string command { argv[i] + 2 };
if (command == "parse") { // --parse <string> [-n] [-u] [-j <limit or -1>] [-b] [-s] [-e] [-f] [-o <output file>] [-d]
if (i + 1 >= argc)
return printUsage("Missing parameter for \"--" + command + "\".", recent(command));
tasks.emplace_back(Task::ParseAndPrintProofs, map<string, string> { { "string", argv[++i] }, { "outputFile", "" } }, map<string, int64_t> { { "minUseAmountToCreateHelperProof", 2 } }, map<string, bool> { { "useInputFile", false }, { "useOutputFile", false }, { "normalPolishNotation", false }, { "unicodeInfixNotation", false }, { "conclusionsOnly", false }, { "summaryMode", false }, { "abstractProofStrings", true }, { "debug", false }, { "whether -j was called", false } });
} else if (command == "transform") { // --transform <string> [-s <string>] [-j <limit or -1>] [-p <limit or -1>] [-n] [-u] [-t <string>] [-e] [-i <limit or -1>] [-l <limit or -1>] [-z] [-f] [-o <output file>] [-d]
if (i + 1 >= argc)
return printUsage("Missing parameter for \"--" + command + "\".", recent(command));
tasks.emplace_back(Task::TransformProofSummary, map<string, string> { { "string", argv[++i] }, { "conclusionsWithHelperProofs", "" }, { "filterForTheorems", "" }, { "outputFile", "" } }, map<string, int64_t> { { "minUseAmountToCreateHelperProof", 2 }, { "maxLengthToKeepProof", -1 }, { "storeIntermediateUnfoldingLimit", -1 }, { "maxLengthToComputeDProof", 134217728 } }, map<string, bool> { { "useInputFile", false }, { "useOutputFile", false }, { "normalPolishNotation", false }, { "printInfixUnicode", false }, { "abstractProofStrings", true }, { "compress", false }, { "debug", false }, { "whether -s was called", false }, { "whether -t was called", false } });
} else if (command == "unfold") { // --unfold <string> [-n] [-t <string>] [-i <limit or -1>] [-l <limit or -1>] [-w] [-f] [-o <output file>] [-d]
if (i + 1 >= argc)
return printUsage("Missing parameter for \"--" + command + "\".", recent(command));
tasks.emplace_back(Task::UnfoldProofSummary, map<string, string> { { "string", argv[++i] }, { "filterForTheorems", "" }, { "outputFile", "" } }, map<string, int64_t> { { "storeIntermediateUnfoldingLimit", -1 }, { "maxLengthToComputeDProof", 134217728 } }, map<string, bool> { { "useInputFile", false }, { "useOutputFile", false }, { "normalPolishNotation", false }, { "wrap", false }, { "debug", false }, { "whether -t was called", false } });
} else if (command == "search") { // --search <string> [-n] [-s] [-w] [-p] [-f] [-d]
if (i + 1 >= argc)
return printUsage("Missing parameter for \"--" + command + "\".", recent(command));
tasks.emplace_back(Task::SearchProofFiles, map<string, string> { { "string", argv[++i] } }, map<string, int64_t> { }, map<string, bool> { { "useInputFile", false }, { "normalPolishNotation", false }, { "searchProofs", false }, { "schemaSearch", false }, { "multiSchemaSearch", false }, { "debug", false } });
} else if (command == "extract") // --extract [-t <limit or -1>] [-o <output file>] [-s] [-# <amount up to 35>] [-h <string>] [-l <limit or -1>] [-f] [-d]
tasks.emplace_back(Task::ExtractFromProofFiles, map<string, string> { { "proofs", "" }, { "outputFile", "" } }, map<string, int64_t> { { "extractToFileAmount", 0 }, { "extractToSystemAmount", 0 }, { "maxConclusionLength", 0 } }, map<string, bool> { { "useInputFile", false }, { "useOutputFile", false }, { "allowRedundantSchemaRemoval", false }, { "debug", false }, { "whether -f was called", false }, { "whether -# was called", false }, { "whether -h was called", false }, { "whether -l was called", false } });
else if (command == "iterate") // --iterate [-u] [-s]
tasks.emplace_back(Task::IterateProofCandidates, map<string, string> { }, map<string, int64_t> { }, map<string, bool> { { "redundantSchemaRemoval", true }, { "withConclusions", true } });
else if (command == "variate") { // --variate ( 0 | 1 ) [-l <path>] [-i <prefix>] [-o <prefix>] [-s] [-d]
if (i + 1 >= argc)
return printUsage("Missing parameter for \"--" + command + "\".", recent(command));
else {
string param = string(argv[++i]);
if (param != "0" && param != "1")
return printUsage("Invalid parameter \"" + param + "\" for \"--" + command + "\".", recent(command));
bool with = param == "1";
tasks.emplace_back(Task::FileConversion, map<string, string> { { "dataLocation", "data" }, { "inputFilePrefix", with ? "dProofs-withoutConclusions/dProofs" : "dProofs-withConclusions/dProofs" }, { "outputFilePrefix", with ? "dProofs-withConclusions/dProofs" : "dProofs-withoutConclusions/dProofs" } }, map<string, int64_t> { }, map<string, bool> { { "memoryOnly", false }, { "debug", false }, { "with", with } });
}
break;
} else if (command == "plot") // --plot [-l <path>] [-i <prefix>] [-s] [-t] [-x <limit or -1>] [-y <limit or -1>] [-o <output file>] [-d]
tasks.emplace_back(Task::ConclusionLengthPlot, map<string, string> { { "dataLocation", "data" }, { "inputFilePrefix", "dProofs-withConclusions/dProofs" }, { "mout", "" } }, map<string, int64_t> { { "cutX", -1 }, { "cutY", -1 } }, map<string, bool> { { "measureSymbolicLength", false }, { "table", false }, { "includeUnfiltered", false }, { "debug", false } });
else
return printUsage("Invalid argument \"--" + command + "\".", recent(command));
break;
}
// Arguments
case '#':
switch (lastTask()) {
default:
return printUsage("Invalid argument \"-" + string { c } + "\".", recent());
case Task::ExtractFromProofFiles: // --extract -# <amount up to 35> (initialize proof system at ./data/[<hash>/]/extraction-<id>/ with the given amount [...])
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
try {
unsigned num = stoi(argv[++i]);
if (num > 35)
throw "";
tasks.back().num["extractToSystemAmount"] = num;
} catch (...) {
return printUsage("Invalid parameter \"" + string(argv[i]) + "\" for \"-" + string { c } + "\".", recent(string { c }));
}
tasks.back().bln["whether -# was called"] = true;
break;
}
break;
case 'b':
switch (lastTask()) {
default:
return printUsage("Invalid argument \"-" + string { c } + "\".", recent());
case Task::ParseAndPrintProofs: // --parse -b (only print conclusions of the given proofs)
tasks.back().bln["conclusionsOnly"] = true;
if (!tasks.back().bln["whether -j was called"])
tasks.back().num["minUseAmountToCreateHelperProof"] = 1;
break;
}
break;
case 'd':
switch (lastTask()) {
default:
return printUsage("Invalid argument \"-" + string { c } + "\".", recent());
case Task::Customize: // -c -d (default system)
tasks.back().bln["defaultSystem"] = true;
break;
case Task::CreateReplacements: // -r -d (print debug information)
case Task::ApplyReplacements: // -a -d (print debug information)
case Task::ParseAndPrintProofs: // --parse -d (print debug information)
case Task::TransformProofSummary: // --transform -d (print debug information)
case Task::UnfoldProofSummary: // --unfold -d (print debug information)
case Task::SearchProofFiles: // --search -d (print debug information)
case Task::ExtractFromProofFiles: // --extract -d (print debug information)
case Task::FileConversion: // --variate -d (print debug information)
case Task::ConclusionLengthPlot: // --plot -d (print debug information)
tasks.back().bln["debug"] = true;
break;
}
break;
case 'e':
switch (lastTask()) {
default:
return printUsage("Invalid argument \"-" + string { c } + "\".", recent());
case Task::Customize: // -c -e <id> (specify extracted system with the given identifie)
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
tasks.back().str["extractedSystemId"] = argv[++i];
tasks.back().bln["extractedSystem"] = true;
extractedEnv = true;
break;
case Task::ParseAndPrintProofs: // --parse -e (keep expanded proof strings)
case Task::TransformProofSummary: // --transform -e (keep expanded proof strings)
tasks.back().bln["abstractProofStrings"] = false;
break;
}
break;
case 'f':
switch (lastTask()) {
default:
return printUsage("Invalid argument \"-" + string { c } + "\".", recent());
case Task::ParseAndPrintProofs: // --parse -f (proofs are given by input file path)
case Task::TransformProofSummary: // --transform -f (proof summary is given by input file path)
case Task::UnfoldProofSummary: // --unfold -f (proof summary is given by input file path)
case Task::SearchProofFiles: // --search -f (search terms are given by input file path)
case Task::ExtractFromProofFiles: // --extract -f (proofs for '-h' are given by input file path)
tasks.back().bln["useInputFile"] = true;
break;
}
break;
case 'h':
switch (lastTask()) {
default:
return printUsage("Invalid argument \"-" + string { c } + "\".", recent());
case Task::ExtractFromProofFiles: // --extract -h <string> (similar to '-#' ; hand-pick conclusions with a comma-separated string of proofs)
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
tasks.back().str["proofs"] = argv[++i];
tasks.back().bln["whether -h was called"] = true;
break;
}
break;
case 'i':
switch (lastTask()) {
default:
return printUsage("Invalid argument \"-" + string { c } + "\".", recent());
case Task::Customize: // -c -i <file> (specify axioms by input file path)
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
tasks.back().str["axiomFilePath"] = argv[++i];
tasks.back().bln["useInputFile"] = true;
break;
case Task::CreateReplacements: // -r -i <prefix> (customize input file path prefix in data location)
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
tasks.back().str["inputFilePrefix"] = argv[++i];
tasks.back().bln["whether -i was called"] = true;
break;
case Task::TransformProofSummary: // --transform -i <limit or -1> (decrease memory requirements but increase time consumption by not storing intermediate unfoldings that exceed a certain length)
case Task::UnfoldProofSummary: // --unfold -i <limit or -1> (decrease memory requirements but increase time consumption by not storing intermediate unfoldings that exceed a certain length)
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
try {
tasks.back().num["storeIntermediateUnfoldingLimit"] = stoi(argv[++i]);
} catch (...) {
return printUsage("Invalid parameter \"" + string(argv[i]) + "\" for \"-" + string { c } + "\".", recent(string { c }));
}
break;
case Task::FileConversion: // --variate -i <prefix> (customize input file path prefix in data location)
case Task::ConclusionLengthPlot: // --plot -i <prefix> (customize input file path prefix in data location)
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
tasks.back().str["inputFilePrefix"] = argv[++i];
break;
}
break;
case 'j':
switch (lastTask()) {
default:
return printUsage("Invalid argument \"-" + string { c } + "\".", recent());
case Task::ParseAndPrintProofs: // --parse -j <limit or -1> (join common subproofs together when they are used at least a given amount of times)
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
try {
tasks.back().num["minUseAmountToCreateHelperProof"] = stoi(argv[++i]);
} catch (...) {
return printUsage("Invalid parameter \"" + string(argv[i]) + "\" for \"-" + string { c } + "\".", recent(string { c }));
}
tasks.back().bln["whether -j was called"] = true;
break;
case Task::TransformProofSummary: // --transform -j <limit or -1> (join common subproofs together when they are used at least a given amount of times)
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
try {
tasks.back().num["minUseAmountToCreateHelperProof"] = stoi(argv[++i]);
} catch (...) {
return printUsage("Invalid parameter \"" + string(argv[i]) + "\" for \"-" + string { c } + "\".", recent(string { c }));
}
break;
}
break;
case 'l':
switch (lastTask()) {
default:
return printUsage("Invalid argument \"-" + string { c } + "\".", recent());
case Task::Generate: // -g -l <limit or -1> (limit symbolic length of generated conclusions to at most the given number)
if (!extractedEnv)
return printUsage("Invalid argument \"-" + string { c } + "\" for \"-g\": Specific filters can only be used in extracted environments. [Hint: '--extract -h .' extracts a system with all axioms unmodified that can be specified with '-c <parent system> -e <id>'.]", recent(string { c }));
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
try {
tasks.back().num["maxSymbolicConclusionLength"] = stoi(argv[++i]);
} catch (...) {
return printUsage("Invalid parameter \"" + string(argv[i]) + "\" for \"-" + string { c } + "\".", recent(string { c }));
}
break;
case Task::Customize: // -c -l (disable lazy N-rule parsing)
tasks.back().bln["speedupN"] = false;
break;
case Task::CreateReplacements: // -r -l <path> (customize data location path)
case Task::FileConversion: // --variate -l <path> (customize data location path)
case Task::ConclusionLengthPlot: // --plot -l <path> (customize data location path)
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
tasks.back().str["dataLocation"] = argv[++i];
break;
case Task::ApplyReplacements: // -a -l (list all proofs)
tasks.back().bln["listAll"] = true;
break;
case Task::TransformProofSummary: // --transform -l <limit or -1> (abort computation when combined requested proof sequences exceed the given limit in bytes)
case Task::UnfoldProofSummary: // --unfold -l <limit or -1> (abort computation when combined requested proof sequences exceed the given limit in bytes)
if (i + 1 >= argc)
return printUsage("Missing parameter for \"-" + string { c } + "\".", recent(string { c }));
try {
tasks.back().num["maxLengthToComputeDProof"] = stoi(argv[++i]);
} catch (...) {
return printUsage("Invalid parameter \"" + string(argv[i]) + "\" for \"-" + string { c } + "\".", recent(string { c }));
}
break;
case Task::ExtractFromProofFiles: // --extract -l <limit or -1> (similar to '-#' ; copy proofs with conclusions that have a symbolic length of at most the given number)