(proof-new) Update add lazy step interface in LazyCDProof (#5299)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Tue, 20 Oct 2020 20:20:35 +0000 (15:20 -0500)
committerGitHub <noreply@github.com>
Tue, 20 Oct 2020 20:20:35 +0000 (15:20 -0500)
Ensuring closed proofs should not be enabled by default, it is actually not used very often as a whole. Moreover, the "trust id" argument is the most useful argument and hence should come as the 3rd argument. This updates all uses of addLazyStep for the change in interface, also changes term conversion generator which had a similar issue with default arguments.

Notice that some calls to addLazyStep were checking closed but without providing a debug string, these I've left alone (they no longer check closed).

15 files changed:
src/expr/lazy_proof.cpp
src/expr/lazy_proof.h
src/expr/term_conversion_proof_generator.cpp
src/expr/term_conversion_proof_generator.h
src/preprocessing/assertion_pipeline.cpp
src/prop/proof_cnf_stream.cpp
src/smt/proof_post_processor.cpp
src/smt/term_formula_removal.cpp
src/smt/witness_form.cpp
src/theory/quantifiers/instantiate.cpp
src/theory/theory_engine.cpp
src/theory/theory_preprocessor.cpp
src/theory/trust_substitutions.cpp
src/theory/trust_substitutions.h
src/theory/uf/proof_equality_engine.cpp

index a96e30fde585b2fd5c6f76802500af07d4cb79aa..267da2607f15362b392d6ca63c53f98ad2256f3b 100644 (file)
@@ -133,10 +133,10 @@ std::shared_ptr<ProofNode> LazyCDProof::getProofFor(Node fact)
 
 void LazyCDProof::addLazyStep(Node expected,
                               ProofGenerator* pg,
+                              PfRule idNull,
                               bool isClosed,
                               const char* ctx,
-                              bool forceOverwrite,
-                              PfRule idNull)
+                              bool forceOverwrite)
 {
   if (pg == nullptr)
   {
index 691902945e79f7dfded8fc51b9d85f8045020348..e2bba30158ba69b2a504c12d1f6ef2693c05ed2f 100644 (file)
@@ -67,23 +67,23 @@ class LazyCDProof : public CDProof
    *
    * @param expected The fact that can be proven.
    * @param pg The generator that can proof expected.
+   * @param trustId If a null proof generator is provided, we add a step to
+   * the proof that has trustId as the rule and expected as the sole argument.
+   * We do this only if trustId is not PfRule::ASSUME. This is primarily used
+   * for identifying the kind of hole when a proof generator is not given.
    * @param isClosed Whether to expect that pg can provide a closed proof for
    * this fact.
    * @param ctx The context we are in (for debugging).
    * @param forceOverwrite If this flag is true, then this call overwrites
    * an existing proof generator provided for expected, if one was provided
    * via a previous call to addLazyStep in the current context.
-   * @param trustId If a null proof generator is provided, we add a step to
-   * the proof that has trustId as the rule and expected as the sole argument.
-   * We do this only if trustId is not PfRule::ASSUME. This is primarily used
-   * for identifying the kind of hole when a proof generator is not given.
    */
   void addLazyStep(Node expected,
                    ProofGenerator* pg,
-                   bool isClosed = true,
+                   PfRule trustId = PfRule::ASSUME,
+                   bool isClosed = false,
                    const char* ctx = "LazyCDProof::addLazyStep",
-                   bool forceOverwrite = false,
-                   PfRule trustId = PfRule::ASSUME);
+                   bool forceOverwrite = false);
   /**
    * Does this have any proof generators? This method always returns true
    * if the default is non-null.
index 11e8eb05443c1a3c84630689decd6a322fae3090..02613345f8bdac2ceb332d6c19dc989a9a824902 100644 (file)
@@ -62,13 +62,17 @@ TConvProofGenerator::TConvProofGenerator(ProofNodeManager* pnm,
 
 TConvProofGenerator::~TConvProofGenerator() {}
 
-void TConvProofGenerator::addRewriteStep(
-    Node t, Node s, ProofGenerator* pg, bool isClosed, uint32_t tctx)
+void TConvProofGenerator::addRewriteStep(Node t,
+                                         Node s,
+                                         ProofGenerator* pg,
+                                         PfRule trustId,
+                                         bool isClosed,
+                                         uint32_t tctx)
 {
   Node eq = registerRewriteStep(t, s, tctx);
   if (!eq.isNull())
   {
-    d_proof.addLazyStep(eq, pg, isClosed);
+    d_proof.addLazyStep(eq, pg, trustId, isClosed);
   }
 }
 
index 184f24e13cf9eed9fe6581f363fb8ae65162ddd7..0a1f4e70a3b96f4d9f1419e0fd2193efe4d8232e 100644 (file)
@@ -144,6 +144,8 @@ class TConvProofGenerator : public ProofGenerator
   /**
    * Add rewrite step t --> s based on proof generator.
    *
+   * @param trustId If a null proof generator is provided, we add a step to
+   * the proof that has trustId as the rule and expected as the sole argument.
    * @param isClosed whether to expect that pg can provide a closed proof for
    * this fact.
    * @param tctx The term context identifier for the rewrite step. This
@@ -154,7 +156,8 @@ class TConvProofGenerator : public ProofGenerator
   void addRewriteStep(Node t,
                       Node s,
                       ProofGenerator* pg,
-                      bool isClosed = true,
+                      PfRule trustId = PfRule::ASSUME,
+                      bool isClosed = false,
                       uint32_t tctx = 0);
   /** Same as above, for a single step */
   void addRewriteStep(Node t, Node s, ProofStep ps, uint32_t tctx = 0);
index 78c459cb7b5249eaea6c77639e07373d443a9946..cd7aadf9a2c1ce3cb214edf022d48997af4881f7 100644 (file)
@@ -177,7 +177,7 @@ void AssertionPipeline::conjoin(size_t i, Node n, ProofGenerator* pg)
       //   rewrite( d_nodes[i] ^ n )
       // allocate a fresh proof which will act as the proof generator
       LazyCDProof* lcp = d_pppg->allocateHelperProof();
-      lcp->addLazyStep(n, pg, false);
+      lcp->addLazyStep(n, pg, PfRule::PREPROCESS);
       if (d_nodes[i].isConst() && d_nodes[i].getConst<bool>())
       {
         // skip the AND_INTRO if the previous d_nodes[i] was true
index b2d33a61d92b0917d72f7c31753a080b7405c37e..790e5aeb2d0e16b6303efba4a19083258fe5e381 100644 (file)
@@ -81,8 +81,11 @@ void ProofCnfStream::convertAndAssert(TNode node,
     Trace("cnf") << "ProofCnfStream::convertAndAssert: pg: " << pg->identify()
                  << "\n";
     Node toJustify = negated ? node.notNode() : static_cast<Node>(node);
-    d_proof.addLazyStep(
-        toJustify, pg, true, "ProofCnfStream::convertAndAssert:cnf");
+    d_proof.addLazyStep(toJustify,
+                        pg,
+                        PfRule::ASSUME,
+                        true,
+                        "ProofCnfStream::convertAndAssert:cnf");
   }
   convertAndAssert(node, negated);
   // process saved steps in buffer
@@ -519,8 +522,11 @@ void ProofCnfStream::convertPropagation(theory::TrustNode trn)
   Assert(trn.getGenerator()->getProofFor(proven)->isClosed());
   Trace("cnf-steps") << proven << " by explainPropagation "
                      << trn.identifyGenerator() << std::endl;
-  d_proof.addLazyStep(
-      proven, trn.getGenerator(), true, "ProofCnfStream::convertPropagation");
+  d_proof.addLazyStep(proven,
+                      trn.getGenerator(),
+                      PfRule::ASSUME,
+                      true,
+                      "ProofCnfStream::convertPropagation");
   // since the propagation is added directly to the SAT solver via theoryProxy,
   // do the transformation of the lemma E1 ^ ... ^ En => P into CNF here
   NodeManager* nm = NodeManager::currentNM();
index 0c2f8ccf8e7107fb17b37fbf33e343fffbefb348..a7723d265ff14c562291c85eb785f5e965232f01 100644 (file)
@@ -460,8 +460,7 @@ Node ProofPostprocessCallback::expandMacros(PfRule id,
           // add previous rewrite steps
           for (unsigned j = 0, nvars = vvec.size(); j < nvars; j++)
           {
-            // not necessarily closed, so we pass false to addRewriteStep.
-            tcg.addRewriteStep(vvec[j], svec[j], pgs[j], false);
+            tcg.addRewriteStep(vvec[j], svec[j], pgs[j]);
           }
           // get the proof for the update to the current substitution
           Node seqss = subs.eqNode(ss);
@@ -506,8 +505,7 @@ Node ProofPostprocessCallback::expandMacros(PfRule id,
                                true);
       for (unsigned j = 0, nvars = vvec.size(); j < nvars; j++)
       {
-        // not necessarily closed, so we pass false to addRewriteStep.
-        tcpg.addRewriteStep(vvec[j], svec[j], pgs[j], false);
+        tcpg.addRewriteStep(vvec[j], svec[j], pgs[j]);
       }
       // add the proof constructed by the term conversion utility
       std::shared_ptr<ProofNode> pfn = tcpg.getProofFor(eq);
@@ -545,10 +543,10 @@ Node ProofPostprocessCallback::expandMacros(PfRule id,
     Node eq = args[0].eqNode(ret);
     if (idr == MethodId::RW_REWRITE || idr == MethodId::RW_REWRITE_EQ_EXT)
     {
-      // rewrites from theory::Rewriter
       // automatically expand THEORY_REWRITE as well here if set
       bool elimTR =
           (d_elimRules.find(PfRule::THEORY_REWRITE) != d_elimRules.end());
+      // rewrites from theory::Rewriter
       bool isExtEq = (idr == MethodId::RW_REWRITE_EQ_EXT);
       // use rewrite with proof interface
       Rewriter* rr = d_smte->getRewriter();
index cf7c00e2b4d49a63fe3417d608dd530d45b377d4..46135f12a5303d65e4111dba0b66dfe998257cd3 100644 (file)
@@ -334,10 +334,9 @@ Node RemoveTermFormulas::runCurrent(std::pair<Node, uint32_t>& curr,
           ProofGenerator* expg = sm->getProofGenerator(existsAssertion);
           d_lp->addLazyStep(existsAssertion,
                             expg,
+                            PfRule::WITNESS_AXIOM,
                             true,
-                            "RemoveTermFormulas::run:skolem_pf",
-                            false,
-                            PfRule::WITNESS_AXIOM);
+                            "RemoveTermFormulas::run:skolem_pf");
           d_lp->addStep(newAssertion, PfRule::SKOLEMIZE, {existsAssertion}, {});
           newAssertionPg = d_lp.get();
         }
index e4f0a56dcf3f8be335cacb69fc94a445d1e71b3c..9c2c035a8078964632ade172594fe812e46ec035 100644 (file)
@@ -114,12 +114,11 @@ Node WitnessFormGenerator::convertToWitnessForm(Node t)
           d_wintroPf.addLazyStep(
               exists,
               pg,
+              PfRule::WITNESS_AXIOM,
               true,
-              "WitnessFormGenerator::convertToWitnessForm:witness_axiom",
-              false,
-              PfRule::WITNESS_AXIOM);
+              "WitnessFormGenerator::convertToWitnessForm:witness_axiom");
           d_wintroPf.addStep(eq, PfRule::WITNESS_INTRO, {exists}, {});
-          d_tcpg.addRewriteStep(cur, curw, &d_wintroPf);
+          d_tcpg.addRewriteStep(cur, curw, &d_wintroPf, PfRule::ASSUME, true);
         }
         else
         {
index f88c2e7a061cdb0aab1788a07d2db9b946f9e69d..8549b1eae0a17c49b38f9890747a06d8f5edd24b 100644 (file)
@@ -268,10 +268,9 @@ bool Instantiate::addInstantiation(
       // add the transformation proof, or THEORY_PREPROCESS if none provided
       pfTmp->addLazyStep(proven,
                          tpBody.getGenerator(),
+                         PfRule::THEORY_PREPROCESS,
                          true,
-                         "Instantiate::getInstantiation:qpreprocess",
-                         false,
-                         PfRule::THEORY_PREPROCESS);
+                         "Instantiate::getInstantiation:qpreprocess");
       pfTmp->addStep(body, PfRule::EQ_RESOLVE, {orig_body, proven}, {});
     }
   }
@@ -477,10 +476,9 @@ Node Instantiate::getInstantiation(Node q,
         Node proven = trn.getProven();
         pf->addLazyStep(proven,
                         trn.getGenerator(),
+                        PfRule::THEORY_PREPROCESS,
                         true,
-                        "Instantiate::getInstantiation:rewrite_inst",
-                        false,
-                        PfRule::THEORY_PREPROCESS);
+                        "Instantiate::getInstantiation:rewrite_inst");
         pf->addStep(newBody, PfRule::EQ_RESOLVE, {body, proven}, {});
       }
       body = newBody;
index aaa0101483e85c9a413c8801390d08b3d25ca58b..924d045daf6612a7e97cb6b27c80981c3a68cf54 100644 (file)
@@ -1462,10 +1462,9 @@ theory::LemmaStatus TheoryEngine::lemma(theory::TrustNode tlemma,
         {
           d_lazyProof->addLazyStep(tplemma.getProven(),
                                    tplemma.getGenerator(),
+                                   PfRule::PREPROCESS_LEMMA,
                                    true,
-                                   "TheoryEngine::lemma_pp",
-                                   false,
-                                   PfRule::PREPROCESS_LEMMA);
+                                   "TheoryEngine::lemma_pp");
           // ---------- from d_lazyProof -------------- from theory preprocess
           // lemma                       lemma = lemmap
           // ------------------------------------------ EQ_RESOLVE
index e7cdb8f2c353f7db8c708cff7cd112213b4d6db9..b37a459671a1666a7d0797b82abdda4c6b491dee 100644 (file)
@@ -213,10 +213,9 @@ TrustNode TheoryPreprocessor::preprocess(TNode node,
         // store in the lazy proof
         d_lp->addLazyStep(assertion,
                           trn.getGenerator(),
+                          PfRule::THEORY_PREPROCESS_LEMMA,
                           true,
-                          "TheoryPreprocessor::rewrite_lemma_new",
-                          false,
-                          PfRule::THEORY_PREPROCESS_LEMMA);
+                          "TheoryPreprocessor::rewrite_lemma_new");
         d_lp->addStep(rewritten,
                       PfRule::MACRO_SR_PRED_TRANSFORM,
                       {assertion},
@@ -433,7 +432,8 @@ Node TheoryPreprocessor::preprocessWithProof(Node term)
       trn.debugCheckClosed("tpp-proof-debug",
                            "TheoryPreprocessor::preprocessWithProof");
       // always use term context hash 0 (default)
-      d_tpg->addRewriteStep(term, termr, trn.getGenerator());
+      d_tpg->addRewriteStep(
+          term, termr, trn.getGenerator(), PfRule::ASSUME, true);
     }
     else
     {
index 482c487eb5c68dc535c07b8ecc7048577847bfbe..27159f96437a8aa9744bf61159e2853d5eafb2d0 100644 (file)
@@ -54,12 +54,7 @@ void TrustSubstitutionMap::addSubstitution(TNode x, TNode t, ProofGenerator* pg)
     // current substitution node is no longer valid.
     d_currentSubs = Node::null();
     // add to lazy proof
-    d_subsPg->addLazyStep(tnl.getProven(),
-                          pg,
-                          false,
-                          "TrustSubstitutionMap::addSubstitution",
-                          false,
-                          d_trustId);
+    d_subsPg->addLazyStep(tnl.getProven(), pg, d_trustId);
   }
 }
 
@@ -79,7 +74,9 @@ void TrustSubstitutionMap::addSubstitution(TNode x,
   addSubstitution(x, t, stepPg);
 }
 
-void TrustSubstitutionMap::addSubstitutionSolved(TNode x, TNode t, TrustNode tn)
+ProofGenerator* TrustSubstitutionMap::addSubstitutionSolved(TNode x,
+                                                            TNode t,
+                                                            TrustNode tn)
 {
   Trace("trust-subs") << "TrustSubstitutionMap::addSubstitutionSolved: add "
                       << x << " -> " << t << " from " << tn.getProven()
@@ -89,7 +86,7 @@ void TrustSubstitutionMap::addSubstitutionSolved(TNode x, TNode t, TrustNode tn)
     // no generator or not proof enabled, nothing to do
     addSubstitution(x, t, nullptr);
     Trace("trust-subs") << "...no proof" << std::endl;
-    return;
+    return nullptr;
   }
   Node eq = x.eqNode(t);
   Node proven = tn.getProven();
@@ -100,7 +97,7 @@ void TrustSubstitutionMap::addSubstitutionSolved(TNode x, TNode t, TrustNode tn)
     // no rewrite required, just use the generator
     addSubstitution(x, t, tn.getGenerator());
     Trace("trust-subs") << "...use generator directly" << std::endl;
-    return;
+    return tn.getGenerator();
   }
   LazyCDProof* solvePg = d_helperPf.allocateProof();
   // Try to transform tn.getProven() to (= x t) here, if necessary
@@ -109,7 +106,7 @@ void TrustSubstitutionMap::addSubstitutionSolved(TNode x, TNode t, TrustNode tn)
     // failed to rewrite
     addSubstitution(x, t, nullptr);
     Trace("trust-subs") << "...failed to rewrite" << std::endl;
-    return;
+    return nullptr;
   }
   Trace("trust-subs") << "...successful rewrite" << std::endl;
   solvePg->addSteps(*d_tspb.get());
@@ -117,6 +114,7 @@ void TrustSubstitutionMap::addSubstitutionSolved(TNode x, TNode t, TrustNode tn)
   // link the given generator
   solvePg->addLazyStep(proven, tn.getGenerator());
   addSubstitution(x, t, solvePg);
+  return solvePg;
 }
 
 void TrustSubstitutionMap::addSubstitutions(TrustSubstitutionMap& t)
index 91555ee56fa12d7f3322805d70421a452c44c7f6..d7f48d05462e51ef1151543824637a0f61ed7e7b 100644 (file)
@@ -68,8 +68,10 @@ class TrustSubstitutionMap
    * based on transforming the tn.getProven() to (= x t) if tn has a
    * non-null proof generator; otherwise if tn has no proof generator
    * we simply add the substitution.
+   *
+   * @return The proof generator that can prove (= x t).
    */
-  void addSubstitutionSolved(TNode x, TNode t, TrustNode tn);
+  ProofGenerator* addSubstitutionSolved(TNode x, TNode t, TrustNode tn);
   /**
    * Add substitutions from trust substitution map t. This adds all
    * substitutions from the map t and carries over its information about proofs.
index 77ee1effd40bdfbdfdd73fda138bb62bdf3dc13b..184584aa9c657e72bafd0f0f292409a72a83bd19 100644 (file)
@@ -68,7 +68,7 @@ bool ProofEqEngine::assertFact(Node lit,
   ps.d_args = args;
   d_factPg.addStep(lit, ps);
   // add lazy step to proof
-  d_proof.addLazyStep(lit, &d_factPg, false);
+  d_proof.addLazyStep(lit, &d_factPg);
   // second, assert it to the equality engine
   Node reason = NodeManager::currentNM()->mkAnd(exp);
   return assertFactInternal(atom, polarity, reason);
@@ -116,7 +116,7 @@ bool ProofEqEngine::assertFact(Node lit,
   ps.d_args = args;
   d_factPg.addStep(lit, ps);
   // add lazy step to proof
-  d_proof.addLazyStep(lit, &d_factPg, false);
+  d_proof.addLazyStep(lit, &d_factPg);
   // second, assert it to the equality engine
   return assertFactInternal(atom, polarity, exp);
 }
@@ -140,7 +140,7 @@ bool ProofEqEngine::assertFact(Node lit, Node exp, ProofStepBuffer& psb)
     d_factPg.addStep(step.first, step.second);
   }
   // add lazy step to proof
-  d_proof.addLazyStep(lit, &d_factPg, false);
+  d_proof.addLazyStep(lit, &d_factPg);
   // second, assert it to the equality engine
   return assertFactInternal(atom, polarity, exp);
 }
@@ -157,7 +157,7 @@ bool ProofEqEngine::assertFact(Node lit, Node exp, ProofGenerator* pg)
     return false;
   }
   // note the proof generator is responsible for remembering the explanation
-  d_proof.addLazyStep(lit, pg, false);
+  d_proof.addLazyStep(lit, pg);
   // second, assert it to the equality engine
   return assertFactInternal(atom, polarity, exp);
 }