Skip to content

Commit 6a5448c

Browse files
committed
new feature '--unite': create union of proof summary files
1 parent 5ff3872 commit 6a5448c

File tree

5 files changed

+153
-3
lines changed

5 files changed

+153
-3
lines changed

README.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ <h4 id="usage">Usage</h4>
491491
-e: keep expanded proof strings ; show fully detailed condensed detachment proofs rather than allowing them to contain references
492492
-i: decrease memory requirements but increase time consumption by not storing intermediate unfoldings that exceed a certain length ; default: -1
493493
-l: abort computation when combined requested proof sequences exceed the given limit in bytes ; default: 134217728 (i.e. 128 MiB)
494-
-b: duplicate conclusion removal ; replace each given subproof that has a redundant conclusion with its first shortest alternative and remove duplicates ; beneficial in preparing '-z'
494+
-b: duplicate conclusion removal ; replace each given subproof that has a redundant conclusion with its first shortest alternative and remove duplicates ; beneficial in preparing '-x' or '-z'
495495
-w: read input without conclusions given
496496
-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
497497
-x: proof compression with extended modification range; before each round generate relative abstract proofs (D-rules only) with up to &lt;range&gt; steps, potentially improving rules with new formulas ; default: 0
@@ -514,6 +514,12 @@ <h4 id="usage">Usage</h4>
514514
-f: proof summary is given by input file path ; ignores lines that are empty or starting with '%'
515515
-o: redirect the result's output to the specified file
516516
-d: print debug information
517+
--unite &lt;input files&gt; [-n] [-b] [-o &lt;output file&gt;] [-d]
518+
Unite proof summary files of the same system which are given by a comma-separated list of paths ; targets and prints all used conclusions ; ignores configured system (proof summaries provide their own axioms)
519+
-n: specify and print formulas in normal Polish notation (e.g. "CpCqp"), not with numeric variables (e.g. "C0C1.0")
520+
-b: duplicate conclusion removal ; replace each given subproof that has a redundant conclusion with its first shortest alternative and remove duplicates
521+
-o: redirect the result's output to the specified file
522+
-d: print debug information
517523
--ndconvert &lt;input file&gt; [-b &lt;base file&gt;] [-n] [-u] [-h] [-k] [-o &lt;output file&gt;] [-d]
518524
Convert proof from Fitch-style natural deduction to condensed detachment in a user-definable Hilbert system and print its proof summary (usable via '--transform' and '--unfold') ; ignores configured system
519525
Input file must contain propositional FitchFX proof without premises, as exportable from https://mrieppel.github.io/FitchFX/ ; supported rules: 'Assumption','IP','~I','~E','&gt;I','&gt;E','&I','&E','vI','vE','&lt;&gt;I','&lt;&gt;E','Reit'
@@ -589,6 +595,8 @@ <h4 id="usage">Usage</h4>
589595
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
590596
pmGenerator --transform data/m.txt -f -n -t CpCqp,CCpCqrCCpqCpr,CCNpNqCqp,Cpp,CCpqCCqrCpr,CCNppp,CpCNpq -j -1 -p -2 -d
591597
pmGenerator --transform "CCCpqrCCrpCsp=1,[0]=DDDD1D1D1D1DDDD1D1D11111111,[1]=D1DD[0]1[0],[2]=DDDD1DD[1][1]1111" -n -w -t _
598+
pmGenerator --unite data/w1.txt,data/w1-m.txt,data/w1-w2.txt,data/w1-w3.txt,data/w1-w4.txt,data/w1-w5.txt,data/w1-w6.txt -n -b -o data/w1-minax-full.txt
599+
pmGenerator --ndconvert data/m_ffx.txt -n -b data/w1.txt -o data/w1-m.txt
592600
pmGenerator --ndconvert data/m_ffx.txt -n -b data/w1.txt -u
593601
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
594602
pmGenerator -c -n -s CCCCCpqCNrNsrtCCtpCsp --search CpCqp,CCpCqrCCpqCpr,CCNpNqCqp -n

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Some more – and very special – proof systems are illustrated [further down b
123123
-e: keep expanded proof strings ; show fully detailed condensed detachment proofs rather than allowing them to contain references
124124
-i: decrease memory requirements but increase time consumption by not storing intermediate unfoldings that exceed a certain length ; default: -1
125125
-l: abort computation when combined requested proof sequences exceed the given limit in bytes ; default: 134217728 (i.e. 128 MiB)
126-
-b: duplicate conclusion removal ; replace each given subproof that has a redundant conclusion with its first shortest alternative and remove duplicates ; beneficial in preparing '-z'
126+
-b: duplicate conclusion removal ; replace each given subproof that has a redundant conclusion with its first shortest alternative and remove duplicates ; beneficial in preparing '-x' or '-z'
127127
-w: read input without conclusions given
128128
-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
129129
-x: proof compression with extended modification range; before each round generate relative abstract proofs (D-rules only) with up to <range> steps, potentially improving rules with new formulas ; default: 0
@@ -146,6 +146,12 @@ Some more – and very special – proof systems are illustrated [further down b
146146
-f: proof summary is given by input file path ; ignores lines that are empty or starting with '%'
147147
-o: redirect the result's output to the specified file
148148
-d: print debug information
149+
--unite <input files> [-n] [-b] [-o <output file>] [-d]
150+
Unite proof summary files of the same system which are given by a comma-separated list of paths ; targets and prints all used conclusions ; ignores configured system (proof summaries provide their own axioms)
151+
-n: specify and print formulas in normal Polish notation (e.g. "CpCqp"), not with numeric variables (e.g. "C0C1.0")
152+
-b: duplicate conclusion removal ; replace each given subproof that has a redundant conclusion with its first shortest alternative and remove duplicates
153+
-o: redirect the result's output to the specified file
154+
-d: print debug information
149155
--ndconvert <input file> [-b <base file>] [-n] [-u] [-h] [-k] [-o <output file>] [-d]
150156
Convert proof from Fitch-style natural deduction to condensed detachment in a user-definable Hilbert system and print its proof summary (usable via '--transform' and '--unfold') ; ignores configured system
151157
Input file must contain propositional FitchFX proof without premises, as exportable from https://mrieppel.github.io/FitchFX/ ; supported rules: 'Assumption','IP','~I','~E','>I','>E','&I','&E','vI','vE','<>I','<>E','Reit'
@@ -222,6 +228,8 @@ Some more – and very special – proof systems are illustrated [further down b
222228
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
223229
pmGenerator --transform data/m.txt -f -n -t CpCqp,CCpCqrCCpqCpr,CCNpNqCqp,Cpp,CCpqCCqrCpr,CCNppp,CpCNpq -j -1 -p -2 -d
224230
pmGenerator --transform "CCCpqrCCrpCsp=1,[0]=DDDD1D1D1D1DDDD1D1D11111111,[1]=D1DD[0]1[0],[2]=DDDD1DD[1][1]1111" -n -w -t _
231+
pmGenerator --unite data/w1.txt,data/w1-m.txt,data/w1-w2.txt,data/w1-w3.txt,data/w1-w4.txt,data/w1-w5.txt,data/w1-w6.txt -n -b -o data/w1-minax-full.txt
232+
pmGenerator --ndconvert data/m_ffx.txt -n -b data/w1.txt -o data/w1-m.txt
225233
pmGenerator --ndconvert data/m_ffx.txt -n -b data/w1.txt -u
226234
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
227235
pmGenerator -c -n -s CCCCCpqCNrNsrtCCtpCsp --search CpCqp,CCpCqrCCpqCpr,CCNpNqCqp -n

logic/DlProofEnumerator.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,52 @@ inline string myTime() {
3333
time_t time = chrono::system_clock::to_time_t(chrono::system_clock::now());
3434
return strtok(ctime(&time), "\n");
3535
}
36+
inline void switchRefs(char& c, bool& inReference, unsigned& refIndex, const auto& inRefAction, const auto& outRefAction) {
37+
if (inReference)
38+
switch (c) {
39+
case '0':
40+
refIndex = 10 * refIndex;
41+
break;
42+
case '1':
43+
refIndex = 10 * refIndex + 1;
44+
break;
45+
case '2':
46+
refIndex = 10 * refIndex + 2;
47+
break;
48+
case '3':
49+
refIndex = 10 * refIndex + 3;
50+
break;
51+
case '4':
52+
refIndex = 10 * refIndex + 4;
53+
break;
54+
case '5':
55+
refIndex = 10 * refIndex + 5;
56+
break;
57+
case '6':
58+
refIndex = 10 * refIndex + 6;
59+
break;
60+
case '7':
61+
refIndex = 10 * refIndex + 7;
62+
break;
63+
case '8':
64+
refIndex = 10 * refIndex + 8;
65+
break;
66+
case '9':
67+
refIndex = 10 * refIndex + 9;
68+
break;
69+
case ']':
70+
inRefAction();
71+
refIndex = 0;
72+
inReference = false;
73+
break;
74+
default:
75+
throw invalid_argument("DlProofEnumerator::switchRefs(): Invalid character '" + string { c } + "': Not part of a proof reference.");
76+
}
77+
else if (c == '[')
78+
inReference = true;
79+
else
80+
outRefAction();
81+
}
3682
}
3783

3884
const vector<const vector<string>*>& DlProofEnumerator::builtinRepresentatives() {
@@ -1146,6 +1192,67 @@ void DlProofEnumerator::unfoldProofSummary(const string& input, bool useInputFil
11461192
}
11471193
}
11481194

1195+
void DlProofEnumerator::uniteProofSummary(const string& input, bool normalPolishNotation, bool removeDuplicateConclusions, const string* outputFile, bool debug) {
1196+
chrono::time_point<chrono::steady_clock> startTime;
1197+
vector<string> paths = FctHelper::stringSplit(input, ",");
1198+
vector<DRuleParser::AxiomInfo> targetAxioms;
1199+
vector<string> abstractDProof;
1200+
vector<shared_ptr<DlFormula>> conclusions;
1201+
for (const string& path : paths) {
1202+
vector<DRuleParser::AxiomInfo> targetAxioms_part;
1203+
vector<string> abstractDProof_part;
1204+
DlProofEnumerator::convertProofSummaryToAbstractDProof(path, &targetAxioms_part, &abstractDProof_part, nullptr, true, normalPolishNotation, false, debug);
1205+
size_t shift = abstractDProof.size();
1206+
if (targetAxioms.empty()) {
1207+
targetAxioms = targetAxioms_part;
1208+
abstractDProof = abstractDProof_part;
1209+
} else if (targetAxioms.size() != targetAxioms_part.size())
1210+
throw invalid_argument("Cannot unite proof summaries with different axioms.");
1211+
else {
1212+
for (size_t i = 0; i < targetAxioms.size(); i++)
1213+
if (*targetAxioms[i].refinedAxiom != *targetAxioms_part[i].refinedAxiom)
1214+
throw invalid_argument("Cannot unite proof summaries with different axioms.");
1215+
auto translate = [&](const string& s) -> string {
1216+
string result;
1217+
bool inReference = false;
1218+
unsigned refIndex = 0;
1219+
for (char c : s) {
1220+
switchRefs(c, inReference, refIndex, [&]() {
1221+
result += "[" + to_string(refIndex + shift) + "]";
1222+
}, [&]() { result += string { c }; });
1223+
}
1224+
if (inReference)
1225+
throw invalid_argument("DlProofEnumerator::uniteProofSummary(): Missing character ']' after '['.");
1226+
return result;
1227+
};
1228+
for (const string& s : abstractDProof_part)
1229+
abstractDProof.push_back(translate(s));
1230+
}
1231+
if (debug)
1232+
cout << "Appended " << abstractDProof.size() << " abstract D-proofs from \"" << path << "\"." << endl;
1233+
}
1234+
abstractDProof = DRuleParser::recombineAbstractDProof(abstractDProof, conclusions, &targetAxioms, true, nullptr, nullptr, 1, nullptr, debug, SIZE_MAX, true, SIZE_MAX, SIZE_MAX, removeDuplicateConclusions);
1235+
if (debug)
1236+
startTime = chrono::steady_clock::now();
1237+
if (outputFile) { // Not using FctHelper::writeToFile() in order to write huge files without huge string acquisition.
1238+
filesystem::path file = filesystem::u8path(*outputFile);
1239+
while (!filesystem::exists(file) && !FctHelper::ensureDirExists(file.string()))
1240+
cerr << "Failed to create file at \"" << file.string() << "\", trying again." << endl;
1241+
string::size_type bytes;
1242+
{
1243+
ofstream fout(file, fstream::out | fstream::binary);
1244+
bytes = DlProofEnumerator::printProofSummary(fout, targetAxioms, abstractDProof, conclusions, normalPolishNotation);
1245+
}
1246+
if (debug)
1247+
cout << FctHelper::durationStringMs(chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now() - startTime)) << " taken to print and save " << bytes << " bytes to " << file.string() << "." << endl;
1248+
} else {
1249+
string::size_type bytes = DlProofEnumerator::printProofSummary(cout, targetAxioms, abstractDProof, conclusions, normalPolishNotation);
1250+
cout << flush;
1251+
if (debug)
1252+
cout << FctHelper::durationStringMs(chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now() - startTime)) << " taken to print " << bytes << " bytes." << endl;
1253+
}
1254+
}
1255+
11491256
bool DlProofEnumerator::loadDProofRepresentatives(vector<vector<string>>& allRepresentatives, vector<vector<string>>* optOut_allConclusions, uint64_t* optOut_allRepresentativesCount, map<uint32_t, uint64_t>* optOut_representativeCounts, uint32_t* optOut_firstMissingIndex, bool debug, const string& filePrefix, const string& filePostfix, bool initFresh, uint32_t limit, const uint32_t* proofLenStepSize) {
11501257
const uint32_t c = proofLenStepSize ? *proofLenStepSize : _necessitationLimit ? 1 : 2;
11511258
chrono::time_point<chrono::steady_clock> startTime;

logic/DlProofEnumerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct DlProofEnumerator {
7777
static void convertProofSummaryToAbstractDProof(const std::string& input, std::vector<metamath::DRuleParser::AxiomInfo>* optOut_customAxioms = nullptr, std::vector<std::string>* optOut_abstractDProof = nullptr, std::vector<metamath::DRuleParser::AxiomInfo>* optOut_requiredIntermediateResults = nullptr, bool useInputFile = false, bool normalPolishNotation = false, bool noInputConclusions = false, bool debug = true);
7878
static void recombineProofSummary(const std::string& input, bool useInputFile, const std::string* conclusionsWithHelperProofs = nullptr, unsigned minUseAmountToCreateHelperProof = 2, std::size_t maxLengthToKeepProof = SIZE_MAX, bool normalPolishNotation = false, bool printInfixUnicode = false, const std::string* filterForTheorems = nullptr, bool abstractProofStrings = true, std::size_t storeIntermediateUnfoldingLimit = SIZE_MAX, std::size_t maxLengthToComputeDProof = 134217728, bool removeDuplicateConclusions = false, bool compress = false, bool noInputConclusions = false, const std::string* outputFile = nullptr, bool debug = false, bool compress_concurrentDRuleSearch = true, std::size_t compress_modificationRange = 0, bool compress_keepMaxRules = false, const std::string* compress_vaultFile = nullptr, bool compress_sureSaves = false, bool compress_skipFirstPrep = false);
7979
static void unfoldProofSummary(const std::string& input, bool useInputFile, bool normalPolishNotation, const std::string* filterForTheorems = nullptr, std::size_t storeIntermediateUnfoldingLimit = SIZE_MAX, std::size_t maxLengthToComputeDProof = 134217728, bool wrap = false, bool noInputConclusions = false, const std::string* outputFile = nullptr, bool debug = false);
80+
static void uniteProofSummary(const std::string& input, bool normalPolishNotation, bool removeDuplicateConclusions = false, const std::string* outputFile = nullptr, bool debug = false);
8081

8182
// Data prediction
8283
static void printGenerationExpenditures(bool redundantSchemaRemoval = true, bool withConclusions = true, bool debug = false);

0 commit comments

Comments
 (0)