@@ -761,7 +761,7 @@ void DlProofEnumerator::sampleCombinations() {
761761 cerr << " Some tests failed." << endl;
762762}
763763
764- void DlProofEnumerator::printProofs (const vector<string>& dProofs, DlFormulaStyle outputNotation, bool conclusionsOnly, bool summaryMode, unsigned minUseAmountToCreateHelperProof, bool abstractProofStrings, const string* inputFile, const string* outputFile, bool debug) {
764+ void DlProofEnumerator::printProofs (const vector<string>& dProofs, DlFormulaStyle outputNotation, bool conclusionsOnly, bool summaryMode, unsigned minUseAmountToCreateHelperProof, bool abstractProofStrings, const string* inputFile, const string* outputFile, bool debug, string* optOut_result, unordered_map< size_t , size_t >* optOut_indexOrigins ) {
765765 chrono::time_point<chrono::steady_clock> startTime;
766766 vector<string> dProofsFromFile;
767767 if (inputFile) {
@@ -869,20 +869,40 @@ void DlProofEnumerator::printProofs(const vector<string>& dProofs, DlFormulaStyl
869869 }
870870 }
871871 }
872- if (!outputFile)
873- cout << ss.str () << flush;
874- else {
872+ if (optOut_result)
873+ *optOut_result = ss.str ();
874+ if (optOut_indexOrigins)
875+ *optOut_indexOrigins = indexOrigins;
876+ if (outputFile) {
875877 if (debug)
876878 startTime = chrono::steady_clock::now ();
877879 if (!FctHelper::writeToFile (*outputFile, ss.str ()))
878880 throw runtime_error (" Failed to write to file at \" " + *outputFile + " \" ." );
879881 if (debug)
880882 cout << FctHelper::durationStringMs (chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now () - startTime)) << " taken to save " << ss.str ().length () << " bytes to \" " << *outputFile << " \" ." << endl;
881- }
882- if (!conclusionsOnly && (_dProofs.size () != rawParseData.size () || !duplicates.empty ()))
883+ } else if (!optOut_result)
884+ cout << ss.str () << flush;
885+ if (!conclusionsOnly && (_dProofs.size () != rawParseData.size () || !duplicates.empty () || any_of (indexOrigins.begin (), indexOrigins.end (), [](const pair<const size_t , size_t >& p) { return p.first != p.second ; })))
883886 cout << " Index correspondences (out,in) are " << FctHelper::mapString (map<size_t , size_t >(indexOrigins.begin (), indexOrigins.end ())) << " ." << endl;
884887}
885888
889+ string::size_type DlProofEnumerator::printProofSummary (ostream& mout, const vector<DRuleParser::AxiomInfo>& axioms, const vector<string>& abstractDProof, const vector<shared_ptr<DlFormula>>& conclusions, bool normalPolishNotation, bool printInfixUnicode) {
890+ auto infixUnicode = [](const shared_ptr<DlFormula>& f) { string s = DlCore::formulaRepresentation_traverse(f); boost::replace_all(s, DlCore::terminalStr_and(), "∧"); boost::replace_all(s, DlCore::terminalStr_or(), "∨"); boost::replace_all(s, DlCore::terminalStr_nand(), "↑"); boost::replace_all(s, DlCore::terminalStr_nor(), "↓"); boost::replace_all(s, DlCore::terminalStr_imply(), "→"); boost::replace_all(s, DlCore::terminalStr_implied(), "←"); boost::replace_all(s, DlCore::terminalStr_nimply(), "↛"); boost::replace_all(s, DlCore::terminalStr_nimplied(), "↚"); boost::replace_all(s, DlCore::terminalStr_equiv(), "↔"); boost::replace_all(s, DlCore::terminalStr_xor(), "↮"); boost::replace_all(s, DlCore::terminalStr_com(), "↷"); boost::replace_all(s, DlCore::terminalStr_app(), "↝"); boost::replace_all(s, DlCore::terminalStr_not(), "¬"); boost::replace_all(s, DlCore::terminalStr_nece(), "□"); boost::replace_all(s, DlCore::terminalStr_poss(), "◇"); boost::replace_all(s, DlCore::terminalStr_obli(), "○"); boost::replace_all(s, DlCore::terminalStr_perm(), "⌔"); boost::replace_all(s, DlCore::terminalStr_top(), "⊤"); boost::replace_all(s, DlCore::terminalStr_bot(), "⊥"); return s; };
891+ string::size_type bytes = 0 ;
892+ for (const DRuleParser::AxiomInfo& ax : axioms) {
893+ string f = printInfixUnicode ? infixUnicode (ax.refinedAxiom ) : normalPolishNotation ? DlCore::toPolishNotation (ax.refinedAxiom ) : DlCore::toPolishNotation_noRename (ax.refinedAxiom );
894+ mout << " " << f << " = " << ax.name << " \n " ;
895+ bytes += 9 + f.length ();
896+ }
897+ for (size_t i = 0 ; i < abstractDProof.size (); i++) {
898+ string f = printInfixUnicode ? infixUnicode (conclusions[i]) : normalPolishNotation ? DlCore::toPolishNotation (conclusions[i]) : DlCore::toPolishNotation_noRename (conclusions[i]);
899+ const string& p = abstractDProof[i];
900+ mout << " [" << i << " ] " << f << " = " << p << " \n " ;
901+ bytes += 7 + FctHelper::digitsNum_uint64 (i) + f.length () + p.length ();
902+ }
903+ return bytes;
904+ }
905+
886906void DlProofEnumerator::convertProofSummaryToAbstractDProof (const string& input, vector<DRuleParser::AxiomInfo>* optOut_customAxioms, vector<string>* optOut_abstractDProof, vector<DRuleParser::AxiomInfo>* optOut_requiredIntermediateResults, bool useInputFile, bool normalPolishNotation, bool noInputConclusions, bool debug) {
887907 vector<string> summaryLines;
888908 {
@@ -942,7 +962,7 @@ void DlProofEnumerator::convertProofSummaryToAbstractDProof(const string& input,
942962 throw invalid_argument (" Missing axiom name in \" " + line + " \" ." );
943963 string axName = line.substr (pos);
944964 if (axName.length () != 1 || ((axName[0 ] < ' 1' || axName[0 ] > ' 9' ) && (axName[0 ] < ' a' || axName[0 ] > ' z' )))
945- throw invalid_argument (" Invalid axiom name in \" " + line + " \" ." );
965+ throw invalid_argument (" Invalid axiom name ( \" " + axName + " \" ) in \" " + line + " \" ." );
946966 size_t num = axName[0 ] >= ' 1' && axName[0 ] <= ' 9' ? axName[0 ] - ' 1' : 10 + axName[0 ] - ' a' - 1 ;
947967 if (num != axiomIndex++)
948968 throw invalid_argument (" [axiomIndex = " + to_string (axiomIndex - 1 ) + " , char = " + to_string (axiomIndex - 10 + ' a' ) + " ] Invalid axiom number in \" " + line + " \" . Should be " + (axiomIndex <= 9 ? string { char (axiomIndex + ' 0' ) } : string { char (axiomIndex - 10 + ' a' ) }) + " ." );
@@ -1013,22 +1033,6 @@ void DlProofEnumerator::recombineProofSummary(const string& input, bool useInput
10131033 vector<shared_ptr<DlFormula>> conclusions;
10141034 const vector<string> abstractDProof = DRuleParser::recombineAbstractDProof (abstractDProof_input, conclusions, &customAxioms, targetEverything, filterForTheorems && !targetEverything ? *filterForTheorems != " ." || noInputConclusions ? &filterForTheorems_axInfo : &requiredIntermediateResults : nullptr , conclusionsWithHelperProofs ? &conclusionsWithHelperProofs_axInfo : nullptr , minUseAmountToCreateHelperProof, noInputConclusions ? nullptr : &requiredIntermediateResults, debug, maxLengthToKeepProof, abstractProofStrings, storeIntermediateUnfoldingLimit, maxLengthToComputeDProof, removeDuplicateConclusions, compress, compress_concurrentDRuleSearch, compress_modificationRange, compress_keepMaxRules, compress_vaultFile, compress_sureSaves, compress_skipFirstPrep);
10151035
1016- auto print = [&](ostream& mout) -> string::size_type {
1017- auto infixUnicode = [](const shared_ptr<DlFormula>& f) { string s = DlCore::formulaRepresentation_traverse(f); boost::replace_all(s, DlCore::terminalStr_and(), "∧"); boost::replace_all(s, DlCore::terminalStr_or(), "∨"); boost::replace_all(s, DlCore::terminalStr_nand(), "↑"); boost::replace_all(s, DlCore::terminalStr_nor(), "↓"); boost::replace_all(s, DlCore::terminalStr_imply(), "→"); boost::replace_all(s, DlCore::terminalStr_implied(), "←"); boost::replace_all(s, DlCore::terminalStr_nimply(), "↛"); boost::replace_all(s, DlCore::terminalStr_nimplied(), "↚"); boost::replace_all(s, DlCore::terminalStr_equiv(), "↔"); boost::replace_all(s, DlCore::terminalStr_xor(), "↮"); boost::replace_all(s, DlCore::terminalStr_com(), "↷"); boost::replace_all(s, DlCore::terminalStr_app(), "↝"); boost::replace_all(s, DlCore::terminalStr_not(), "¬"); boost::replace_all(s, DlCore::terminalStr_nece(), "□"); boost::replace_all(s, DlCore::terminalStr_poss(), "◇"); boost::replace_all(s, DlCore::terminalStr_obli(), "○"); boost::replace_all(s, DlCore::terminalStr_perm(), "⌔"); boost::replace_all(s, DlCore::terminalStr_top(), "⊤"); boost::replace_all(s, DlCore::terminalStr_bot(), "⊥"); return s; };
1018- string::size_type bytes = 0 ;
1019- for (const DRuleParser::AxiomInfo& ax : customAxioms) {
1020- string f = printInfixUnicode ? infixUnicode (ax.refinedAxiom ) : normalPolishNotation ? DlCore::toPolishNotation (ax.refinedAxiom ) : DlCore::toPolishNotation_noRename (ax.refinedAxiom );
1021- mout << " " << f << " = " << ax.name << " \n " ;
1022- bytes += 9 + f.length ();
1023- }
1024- for (size_t i = 0 ; i < abstractDProof.size (); i++) {
1025- string f = printInfixUnicode ? infixUnicode (conclusions[i]) : normalPolishNotation ? DlCore::toPolishNotation (conclusions[i]) : DlCore::toPolishNotation_noRename (conclusions[i]);
1026- const string& p = abstractDProof[i];
1027- mout << " [" << i << " ] " << f << " = " << p << " \n " ;
1028- bytes += 7 + FctHelper::digitsNum_uint64 (i) + f.length () + p.length ();
1029- }
1030- return bytes;
1031- };
10321036 chrono::time_point<chrono::steady_clock> startTime;
10331037 if (debug)
10341038 startTime = chrono::steady_clock::now ();
@@ -1039,12 +1043,12 @@ void DlProofEnumerator::recombineProofSummary(const string& input, bool useInput
10391043 string::size_type bytes;
10401044 {
10411045 ofstream fout (file, fstream::out | fstream::binary);
1042- bytes = print (fout);
1046+ bytes = printProofSummary (fout, customAxioms, abstractDProof, conclusions, normalPolishNotation, printInfixUnicode );
10431047 }
10441048 if (debug)
10451049 cout << FctHelper::durationStringMs (chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now () - startTime)) << " taken to print and save " << bytes << " bytes to " << file.string () << " ." << endl;
10461050 } else {
1047- string::size_type bytes = print (cout);
1051+ string::size_type bytes = printProofSummary (cout, customAxioms, abstractDProof, conclusions, normalPolishNotation, printInfixUnicode );
10481052 cout << flush;
10491053 if (debug)
10501054 cout << FctHelper::durationStringMs (chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now () - startTime)) << " taken to print " << bytes << " bytes." << endl;
@@ -4063,9 +4067,9 @@ void DlProofEnumerator::printConclusionLengthPlotData(bool measureSymbolicLength
40634067 ++it;
40644068 }
40654069 if (table)
4066- ss << FctHelper::mapStringF (allAmounts, [](const pair<size_t , size_t >& p) { return to_string (p.first ) + " \t " + to_string (p.second ); }, { }, " \n " , " \n " ) << " \n " ;
4070+ ss << FctHelper::mapStringF (allAmounts, [](const pair<const size_t , size_t >& p) { return to_string (p.first ) + " \t " + to_string (p.second ); }, { }, " \n " , " \n " ) << " \n " ;
40674071 else
4068- ss << FctHelper::mapStringF (allAmounts, [](const pair<size_t , size_t >& p) { return to_string (p.first ) + " " + to_string (p.second ); }, { }, " \n " , " " ) << " \n " ;
4072+ ss << FctHelper::mapStringF (allAmounts, [](const pair<const size_t , size_t >& p) { return to_string (p.first ) + " " + to_string (p.second ); }, { }, " \n " , " " ) << " \n " ;
40694073 } else
40704074 ss << " \n " ;
40714075 // formula representation lengths: ([1,1000] data) [x <= 500] https://www.desmos.com/calculator/b9qvvkinal, https://i.imgur.com/IMFY84S.png ; [x,y <= 1000] https://www.desmos.com/calculator/tjej0cpyju, https://i.imgur.com/1Z4WjJa.png ; [x <= 1000, y <= 100] https://www.desmos.com/calculator/zpe5zw41cm, https://i.imgur.com/6aCR6iq.png
0 commit comments