@@ -1844,7 +1844,6 @@ vector<string> DRuleParser::unfoldAbstractDProof(const vector<string>& abstractD
1844
1844
}
1845
1845
1846
1846
void DRuleParser::compressAbstractDProof (vector<string>& retractedDProof, vector<shared_ptr<DlFormula>>& abstractDProofConclusions, vector<string>& helperRules, vector<shared_ptr<DlFormula>>& helperRulesConclusions, vector<size_t >& indexEvalSequence, vector<size_t >& targetIndices, const vector<AxiomInfo>* customAxioms, bool targetEverything, vector<AxiomInfo>* filterForTheorems, bool concurrentDRuleSearch, size_t modificationRange, bool keepMaxRules, const string* vaultFile, bool sureSaves, bool skipFirstPrep) {
1847
- constexpr bool lowMemoryCollection = true ; // ### TODO
1848
1847
if (modificationRange >= 3 && UINT16_MAX < modificationRange) {
1849
1848
cerr << " [Proof compression] ERROR Requested D-proofs of lengths up to " << modificationRange << " (exceeding 2^16 = " << UINT16_MAX + 1 << " required indices). Aborting." << endl;
1850
1849
exit (0 );
@@ -1970,8 +1969,7 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
1970
1969
const vector<tbb::concurrent_vector<AbstractDProof>>& extraData;
1971
1970
atomic<bool > active = true ;
1972
1971
array<int64_t , 2 > dRule; // i >= 0: proofElements[i], -1 <= i <= -35: axioms[-i - 1], i <= -64 && (-i & 64): extraData[(-i >> 7) & UINT16_MAX][-i >> 23] (i.e. up to 2^(64-1-23)-1 = 2^40-1 = 1099511627775 entries for D-proofs of each length)
1973
- string sResult ; // used in case lowMemoryCollection
1974
- shared_ptr<DlFormula> tResult; // used in case !lowMemoryCollection
1972
+ string sResult ;
1975
1973
size_t fundamentalLength;
1976
1974
int64_t improvedOriginal = -1 ;
1977
1975
int64_t improvedByExtra = 0 ;
@@ -1981,40 +1979,19 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
1981
1979
sResult = f;
1982
1980
fundamentalLength = funLen;
1983
1981
}
1984
- AbstractDProof (const vector<tbb::concurrent_vector<AbstractDProof>>& extraData, const array<int64_t , 2 >& r, const shared_ptr<DlFormula>& f, size_t funLen) :
1985
- extraData (extraData) {
1986
- dRule = r;
1987
- tResult = f;
1988
- fundamentalLength = funLen;
1989
- }
1990
1982
bool clearIfInactive () { // to free memory without removing the element in order to not touch indices
1991
- if (!active) {
1992
- tResult.reset ();
1993
- return true ;
1994
- }
1995
- return false ;
1996
- }
1997
- bool clearIfInactive_lowMem () { // to free memory without removing the element in order to not touch indices
1998
1983
if (!active) {
1999
1984
sResult .clear ();
2000
1985
return true ;
2001
1986
}
2002
1987
return false ;
2003
1988
}
2004
- string formulaString_numVars (bool lowMemoryCollection) const {
2005
- if (!active)
2006
- return " [inactive]" ;
2007
- return lowMemoryCollection ? sResult : DlCore::toPolishNotation_numVars (tResult);
2008
- }
2009
- string formulaString (bool lowMemoryCollection) const {
1989
+ string formulaString () const {
2010
1990
if (!active)
2011
1991
return " [inactive]" ;
2012
- if (lowMemoryCollection) {
2013
- shared_ptr<DlFormula> _f;
2014
- DlCore::fromPolishNotation_noRename (_f, sResult );
2015
- return DlCore::toPolishNotation (_f);
2016
- } else
2017
- return DlCore::toPolishNotation (tResult);
1992
+ shared_ptr<DlFormula> _f;
1993
+ DlCore::fromPolishNotation_noRename (_f, sResult );
1994
+ return DlCore::toPolishNotation (_f);
2018
1995
}
2019
1996
string toString () const override {
2020
1997
stringstream ss;
@@ -2031,11 +2008,11 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2031
2008
}
2032
2009
return ss.str ();
2033
2010
}
2034
- string toConclusionString (bool lowMemoryCollection ) const {
2035
- return toString () + (active ? " = " + formulaString (lowMemoryCollection ) : " (inactive)" );
2011
+ string toConclusionString () const {
2012
+ return toString () + (active ? " = " + formulaString () : " (inactive)" );
2036
2013
}
2037
- string toDetailedString (bool lowMemoryCollection ) const {
2038
- return toString () + (active ? " = " + formulaString (lowMemoryCollection ) + " (" : " (inactive; " ) + " fundamental length " + to_string (fundamentalLength) + " )" ;
2014
+ string toDetailedString () const {
2015
+ return toString () + (active ? " = " + formulaString () + " (" : " (inactive; " ) + " fundamental length " + to_string (fundamentalLength) + " )" ;
2039
2016
}
2040
2017
};
2041
2018
vector<tbb::concurrent_vector<AbstractDProof>> extraData; // relative abstract D-proofs of length index
@@ -2393,17 +2370,7 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2393
2370
map<string, shared_ptr<DlFormula>> substitutions;
2394
2371
if (DlCore::tryUnifyTrees (antecedent, conditional_children[0 ], &substitutions)) {
2395
2372
consequent = DlCore::substitute (conditional_children[1 ], substitutions);
2396
- if (lowMemoryCollection)
2397
- consequent_isomorph = DlCore::toPolishNotation_numVars (consequent);
2398
- else { // Obtain unique variables.
2399
- DlCore::fromPolishNotation_noRename (consequent, consequent_isomorph = DlCore::toPolishNotation_numVars (consequent));
2400
- vector<string> vars = DlCore::primitivesOfFormula_ordered (consequent);
2401
- map<string, shared_ptr<DlFormula>> substitutions;
2402
- string varId = to_string (lenA) + " _" + to_string (iA) + " _" + to_string (lenB) + " _" + to_string (iB) + " _" ;
2403
- for (const string& v : vars)
2404
- substitutions.emplace (v, make_shared<DlFormula>(make_shared<String>(varId + v)));
2405
- consequent = DlCore::substitute (consequent, substitutions);
2406
- }
2373
+ consequent_isomorph = DlCore::toPolishNotation_numVars (consequent);
2407
2374
// NOTE: In the final iteration, the only potentially useful new proofs (which thus shall be memorized) are those towards known intermediate conclusions, except in
2408
2375
// cases where a longer relative abstract proof with lower fundamental length could later be used as an improving replacement for a subproof towards a new formula.
2409
2376
// However, only storing proofs towards known intermediate conclusions here effectively enables the user to run with the next higher modification range (i.e. increased by two)
@@ -2458,10 +2425,7 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2458
2425
obtainedConclusions.find (wAcc, consequent_isomorph);
2459
2426
wAcc->second = obtainedConclusionVal; // update 'obtainedConclusions'
2460
2427
}
2461
- if (lowMemoryCollection)
2462
- output.emplace_back (extraData, dRule, consequent_isomorph, funLen);
2463
- else
2464
- output.emplace_back (extraData, dRule, consequent, funLen);
2428
+ output.emplace_back (extraData, dRule, consequent_isomorph, funLen);
2465
2429
if (improvedFor >= 0 ) {
2466
2430
output.back ().improvedOriginal = improvedFor;
2467
2431
stringstream ss;
@@ -2495,7 +2459,7 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2495
2459
if (l < 0 && (-l & 64 )) {
2496
2460
const AbstractDProof& proof = extraData[(-l >> 7 ) & UINT16_MAX][-l >> 23 ];
2497
2461
fL = proof.fundamentalLength ;
2498
- return lowMemoryCollection ? [&]() { shared_ptr<DlFormula> f; DlCore::fromPolishNotation_noRename (f, proof.sResult ); return f; }() : proof. tResult ;
2462
+ return [&]() { shared_ptr<DlFormula> f; DlCore::fromPolishNotation_noRename (f, proof.sResult ); return f; }();
2499
2463
} else {
2500
2464
fL = i < numRules ? fundamentalLengths[i] : 1 ;
2501
2465
return proofElements[i].result ;
@@ -2544,8 +2508,8 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2544
2508
shared_ptr<DlFormula> consequent;
2545
2509
string consequent_isomorph;
2546
2510
if (isCandidate (antecedent, conditional_children, lenA, iA, lenB, iB, funLen, consequent, consequent_isomorph, finalLoop)) {
2547
- if (vault.at (p.first )[i].second != (lowMemoryCollection ? consequent_isomorph : DlCore::toPolishNotation_numVars (consequent)) ) {
2548
- cerr << " [Proof compression] ERROR Mismatching stored vault entry " << vault.at (p.first )[i].first << " = " << vault.at (p.first )[i].second << " != " << (lowMemoryCollection ? consequent_isomorph : DlCore::toPolishNotation_numVars (consequent)) << " = D(" << conditional_str << " )(" << antecedent_str << " ). Aborting." << endl;
2511
+ if (vault.at (p.first )[i].second != consequent_isomorph) {
2512
+ cerr << " [Proof compression] ERROR Mismatching stored vault entry " << vault.at (p.first )[i].first << " = " << vault.at (p.first )[i].second << " != " << consequent_isomorph << " = D(" << conditional_str << " )(" << antecedent_str << " ). Aborting." << endl;
2549
2513
exit (0 );
2550
2514
}
2551
2515
array<int64_t , 2 > dRule { conditional_loc, antecedent_loc };
@@ -2622,7 +2586,7 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2622
2586
if (!eB.active )
2623
2587
return ;
2624
2588
shared_ptr<DlFormula> _f;
2625
- const shared_ptr<DlFormula>& conditional = lowMemoryCollection ? [&]() { DlCore::fromPolishNotation_noRename (_f, eB.sResult ); return _f; }() : eB. tResult ;
2589
+ const shared_ptr<DlFormula>& conditional = [&]() { DlCore::fromPolishNotation_noRename (_f, eB.sResult ); return _f; }();
2626
2590
const vector<shared_ptr<DlFormula>>& conditional_children = conditional->getChildren ();
2627
2591
if (conditional_children.size () != 2 || conditional->getValue ()->value != DlCore::terminalStr_imply ())
2628
2592
return ; // 'conditional' is no conditional => skip already
@@ -2659,7 +2623,7 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2659
2623
if (addFunLen_overflow (eA.fundamentalLength , funLen_known (eB, iB), &funLen))
2660
2624
continue ; // skip results with fundamental lengths above SIZE_MAX
2661
2625
shared_ptr<DlFormula> _f;
2662
- const shared_ptr<DlFormula>& antecedent = lowMemoryCollection ? [&]() { DlCore::fromPolishNotation_noRename (_f, eA.sResult ); return _f; }() : eA. tResult ;
2626
+ const shared_ptr<DlFormula>& antecedent = [&]() { DlCore::fromPolishNotation_noRename (_f, eA.sResult ); return _f; }();
2663
2627
shared_ptr<DlFormula> consequent;
2664
2628
string consequent_isomorph;
2665
2629
if (isCandidate (antecedent, conditional_children, lenA, iA, lenB, iB, funLen, consequent, consequent_isomorph, finalLoop)) {
@@ -2679,7 +2643,7 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2679
2643
if (!eB.active )
2680
2644
return ;
2681
2645
shared_ptr<DlFormula> _f;
2682
- const shared_ptr<DlFormula>& conditional = lowMemoryCollection ? [&]() { DlCore::fromPolishNotation_noRename (_f, eB.sResult ); return _f; }() : eB. tResult ;
2646
+ const shared_ptr<DlFormula>& conditional = [&]() { DlCore::fromPolishNotation_noRename (_f, eB.sResult ); return _f; }();
2683
2647
const vector<shared_ptr<DlFormula>>& conditional_children = conditional->getChildren ();
2684
2648
if (conditional_children.size () != 2 || conditional->getValue ()->value != DlCore::terminalStr_imply ())
2685
2649
return ; // 'conditional' is no conditional => skip already
@@ -2701,7 +2665,7 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2701
2665
_distinguishedFormula = DlCore::substitute (f, substitutions);
2702
2666
return _distinguishedFormula;
2703
2667
};
2704
- const shared_ptr<DlFormula>& antecedent = lowMemoryCollection ? distinguishVariables ([&]() { DlCore::fromPolishNotation_noRename (_distinguishedFormula, eA.sResult ); return _distinguishedFormula; }()) : (lenA == lenB && iA == iB ? distinguishVariables (eA. tResult ) : eA. tResult );
2668
+ const shared_ptr<DlFormula>& antecedent = distinguishVariables ([&]() { DlCore::fromPolishNotation_noRename (_distinguishedFormula, eA.sResult ); return _distinguishedFormula; }());
2705
2669
shared_ptr<DlFormula> consequent;
2706
2670
string consequent_isomorph;
2707
2671
if (isCandidate (antecedent, conditional_children, lenA, iA, lenB, iB, funLen, consequent, consequent_isomorph, finalLoop)) {
@@ -2724,22 +2688,13 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2724
2688
if (!output.empty ()) {
2725
2689
chrono::time_point<chrono::steady_clock> startTime = chrono::steady_clock::now ();
2726
2690
atomic<size_t > c = 0 , d = 0 ;
2727
- if (lowMemoryCollection)
2728
- tbb::parallel_for_each (output.begin (), output.end (), [&](AbstractDProof& proof) {
2729
- if (!proof.sResult .empty ()) {
2730
- if (proof.clearIfInactive_lowMem ())
2731
- c++;
2732
- } else
2733
- d++;
2734
- });
2735
- else
2736
- tbb::parallel_for_each (output.begin (), output.end (), [&](AbstractDProof& proof) {
2737
- if (proof.tResult .get ()) {
2738
- if (proof.clearIfInactive ())
2739
- c++;
2740
- } else
2741
- d++;
2742
- });
2691
+ tbb::parallel_for_each (output.begin (), output.end (), [&](AbstractDProof& proof) {
2692
+ if (!proof.sResult .empty ()) {
2693
+ if (proof.clearIfInactive ())
2694
+ c++;
2695
+ } else
2696
+ d++;
2697
+ });
2743
2698
cout << FctHelper::round (static_cast <long double >(chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now () - startTime).count ()) / 1000.0 , 2 ) << " ms taken to clear " << c << " of " << output.size () << " proof" << (output.size () == 1 ? " " : " s" ) << " from extraData[" << len << " ], " << output.size () - c - d << " remain active. (" << d << " already clear and skipped)" << endl;
2744
2699
}
2745
2700
}
@@ -2779,7 +2734,7 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2779
2734
}
2780
2735
improvements.emplace (i, location);
2781
2736
const AbstractDProof& proof = extraData[(-location >> 7 ) & UINT16_MAX][-location >> 23 ];
2782
- cout << " [Summary] Rule [" << i << " ] (fundamental length " << fundamentalLengths[i] << " ) improved by: " << proof.toDetailedString (lowMemoryCollection ) << endl;
2737
+ cout << " [Summary] Rule [" << i << " ] (fundamental length " << fundamentalLengths[i] << " ) improved by: " << proof.toDetailedString () << endl;
2783
2738
auto obtainBestVariantString = [&](const AbstractDProof& proof, const auto & me) -> string {
2784
2739
stringstream ss;
2785
2740
ss << " D" ;
@@ -2808,8 +2763,6 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2808
2763
size_t optimizedFunLen = measure (optimizedRule);
2809
2764
cout << " [Summary] Rule [" << i << " ] " << string (24 + FctHelper::digitsNum_uint64 (fundamentalLengths[i]), ' ' ) << " optimized: " << optimizedRule << " (fundamental length " << optimizedFunLen << " )" << endl;
2810
2765
}
2811
- if (proof.improvedByExtra )
2812
- cout << " [WARNING] Rule [" << i << " ] improvement has proof.improvedByExtra = " << proof.improvedByExtra << endl; // ### TODO Remove after testing.
2813
2766
}
2814
2767
}
2815
2768
@@ -2837,13 +2790,13 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2837
2790
const AbstractDProof& current = extraData[(e >> 7 ) & UINT16_MAX][e >> 23 ];
2838
2791
int64_t best = e; // already negated
2839
2792
size_t minFunLen = measure (current.toString ());
2840
- // #cout << "> Found funLen: " << minFunLen << " (of " << current.toConclusionString(lowMemoryCollection ) << ") <initial>" << endl;
2793
+ // #cout << "> Found funLen: " << minFunLen << " (of " << current.toConclusionString() << ") <initial>" << endl;
2841
2794
auto iterateImprovingExtras = [&](const AbstractDProof& p, const auto & me) -> const AbstractDProof& {
2842
2795
int64_t l = -p.improvedByExtra ;
2843
2796
if (l) {
2844
2797
const AbstractDProof& next = extraData[(l >> 7 ) & UINT16_MAX][l >> 23 ];
2845
2798
size_t funLen = measure (next.toString ());
2846
- // #cout << "> Found funLen: " << funLen << " (of " << next.toConclusionString(lowMemoryCollection ) << ") <subsequent>" << endl;
2799
+ // #cout << "> Found funLen: " << funLen << " (of " << next.toConclusionString() << ") <subsequent>" << endl;
2847
2800
if (funLen < minFunLen) {
2848
2801
best = l;
2849
2802
minFunLen = funLen;
@@ -2874,7 +2827,7 @@ void DRuleParser::compressAbstractDProof(vector<string>& retractedDProof, vector
2874
2827
const AbstractDProof& candidate = extraData[(location >> 7 ) & UINT16_MAX][location >> 23 ];
2875
2828
size_t funLen_candidate = measure (candidate.toString ());
2876
2829
stringstream ss1;
2877
- ss1 << " [Summary] Step: (" << index << " , " << dProof << " -> " << candidate.toConclusionString (lowMemoryCollection ) << " ), fundamental lengths (" << funLen << " , " << funLen_candidate << " )" << endl;
2830
+ ss1 << " [Summary] Step: (" << index << " , " << dProof << " -> " << candidate.toConclusionString () << " ), fundamental lengths (" << funLen << " , " << funLen_candidate << " )" << endl;
2878
2831
cout << ss1.str () << flush;
2879
2832
if (vaultOutput)
2880
2833
ss << ss1.str ();
0 commit comments