Eliminate more static options accesses (#8802)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Wed, 25 May 2022 19:43:04 +0000 (14:43 -0500)
committerGitHub <noreply@github.com>
Wed, 25 May 2022 19:43:04 +0000 (19:43 +0000)
A block of code changed indentation in the induction solver, this is cleaned to conform to guidelines.

src/options/quantifiers_options.toml
src/theory/difficulty_manager.cpp
src/theory/difficulty_manager.h
src/theory/quantifiers/conjecture_generator.cpp
src/theory/relevance_manager.cpp
test/regress/cli/regress2/sygus/issue4022-conjecture-gen.smt2

index 2d6d74bb4700f629ac9efd63eba2bb40423c6103..a624aae926c06eb1b334e95d5e19f29547004f73 100644 (file)
@@ -790,30 +790,6 @@ name   = "Quantifiers"
   default    = "1"
   help       = "number of conjectures to generate per instantiation round"
 
-[[option]]
-  name       = "conjectureFilterActiveTerms"
-  category   = "expert"
-  long       = "conjecture-filter-active-terms"
-  type       = "bool"
-  default    = "true"
-  help       = "filter based on active terms"
-
-[[option]]
-  name       = "conjectureFilterCanonical"
-  category   = "expert"
-  long       = "conjecture-filter-canonical"
-  type       = "bool"
-  default    = "true"
-  help       = "filter based on canonicity"
-
-[[option]]
-  name       = "conjectureFilterModel"
-  category   = "expert"
-  long       = "conjecture-filter-model"
-  type       = "bool"
-  default    = "true"
-  help       = "filter based on model"
-
 [[option]]
   name       = "conjectureGenGtEnum"
   category   = "expert"
index 797ebab797bae9cc65bd29983bd2567a09a91f3e..0b74cb0815abc380872a910cba702bb8f9a423e7 100644 (file)
@@ -26,10 +26,14 @@ using namespace cvc5::internal::kind;
 namespace cvc5::internal {
 namespace theory {
 
-DifficultyManager::DifficultyManager(RelevanceManager* rlv,
-                                     context::Context* c,
+DifficultyManager::DifficultyManager(Env& env,
+                                     RelevanceManager* rlv,
                                      Valuation val)
-    : d_rlv(rlv), d_input(c), d_val(val), d_dfmap(c)
+    : EnvObj(env),
+      d_rlv(rlv),
+      d_input(userContext()),
+      d_val(val),
+      d_dfmap(userContext())
 {
 }
 
@@ -55,11 +59,13 @@ void DifficultyManager::notifyLemma(Node n, bool inFullEffortCheck)
 {
   // compute if we should consider the lemma
   bool considerLemma = false;
-  if (options::difficultyMode() == options::DifficultyMode::LEMMA_LITERAL_ALL)
+  if (options().smt.difficultyMode
+      == options::DifficultyMode::LEMMA_LITERAL_ALL)
   {
     considerLemma = true;
   }
-  else if (options::difficultyMode() == options::DifficultyMode::LEMMA_LITERAL)
+  else if (options().smt.difficultyMode
+           == options::DifficultyMode::LEMMA_LITERAL)
   {
     considerLemma = inFullEffortCheck;
   }
@@ -103,7 +109,7 @@ void DifficultyManager::notifyLemma(Node n, bool inFullEffortCheck)
 
 void DifficultyManager::notifyCandidateModel(TheoryModel* m)
 {
-  if (options::difficultyMode() != options::DifficultyMode::MODEL_CHECK)
+  if (options().smt.difficultyMode != options::DifficultyMode::MODEL_CHECK)
   {
     return;
   }
index b30fbd22e3a907abaca7e1160d6862a06cb3b554..f0c694c6688ceb6a20b2bb266ac5e9d22097cb73 100644 (file)
@@ -21,6 +21,7 @@
 #include "context/cdhashmap.h"
 #include "context/cdhashset.h"
 #include "expr/node.h"
+#include "smt/env_obj.h"
 #include "theory/valuation.h"
 
 namespace cvc5::internal {
@@ -33,13 +34,13 @@ class RelevanceManager;
  * Difficulty manager, which tracks an estimate of the difficulty of each
  * preprocessed assertion during solving.
  */
-class DifficultyManager
+class DifficultyManager : protected EnvObj
 {
   typedef context::CDHashSet<Node> NodeSet;
   typedef context::CDHashMap<Node, uint64_t> NodeUIntMap;
 
  public:
-  DifficultyManager(RelevanceManager* rlv, context::Context* c, Valuation val);
+  DifficultyManager(Env& env, RelevanceManager* rlv, Valuation val);
   /** Notify input assertions */
   void notifyInputAssertions(const std::vector<Node>& assertions);
   /**
index f403dc32842b21e84a34f3fe93ff44f2c0666453..e8515d370d24f6d5c52236598905da21a1682a25 100644 (file)
@@ -675,8 +675,7 @@ void ConjectureGenerator::check(Theory::Effort e, QEffort quant_e)
         while( d_tge.getNextTerm() ){
           //construct term
           Node nn = d_tge.getTerm();
-          if (!options().quantifiers.conjectureFilterCanonical
-              || considerTermCanon(nn, true))
+          if (considerTermCanon(nn, true))
           {
             rel_term_count++;
             Trace("sg-rel-term") << "*** Relevant term : ";
@@ -916,9 +915,8 @@ unsigned ConjectureGenerator::flushWaitingConjectures( unsigned& addedLemmas, in
           //we have determined a relevant subgoal
           Node lhs = d_waiting_conjectures_lhs[i];
           Node rhs = d_waiting_conjectures_rhs[i];
-          if (options().quantifiers.conjectureFilterCanonical
-              && (getUniversalRepresentative(lhs) != lhs
-                  || getUniversalRepresentative(rhs) != rhs))
+          if (getUniversalRepresentative(lhs) != lhs
+              || getUniversalRepresentative(rhs) != rhs)
           {
             //skip
           }
@@ -1282,95 +1280,114 @@ int ConjectureGenerator::considerCandidateConjecture( TNode lhs, TNode rhs ) {
   if( lhs==rhs ){
     Trace("sg-cconj-debug") << "  -> trivial." << std::endl;
     return -1;
-  }else{
-    if( lhs.getKind()==APPLY_CONSTRUCTOR && rhs.getKind()==APPLY_CONSTRUCTOR ){
-      Trace("sg-cconj-debug") << "  -> irrelevant by syntactic analysis." << std::endl;
+  }
+  if (lhs.getKind() == APPLY_CONSTRUCTOR && rhs.getKind() == APPLY_CONSTRUCTOR)
+  {
+    Trace("sg-cconj-debug")
+        << "  -> irrelevant by syntactic analysis." << std::endl;
+    return -1;
+  }
+  // variables of LHS must subsume variables of RHS
+  for (std::pair<const TypeNode, unsigned>& p : d_pattern_var_id[rhs])
+  {
+    std::map<TypeNode, unsigned>::iterator itl =
+        d_pattern_var_id[lhs].find(p.first);
+    if (itl == d_pattern_var_id[lhs].end())
+    {
+      Trace("sg-cconj-debug")
+          << "  -> has no variables of sort " << p.first << "." << std::endl;
       return -1;
     }
-    //variables of LHS must subsume variables of RHS
-    for( std::map< TypeNode, unsigned >::iterator it = d_pattern_var_id[rhs].begin(); it != d_pattern_var_id[rhs].end(); ++it ){
-      std::map< TypeNode, unsigned >::iterator itl = d_pattern_var_id[lhs].find( it->first );
-      if( itl!=d_pattern_var_id[lhs].end() ){
-        if( itl->second<it->second ){
-          Trace("sg-cconj-debug") << "  -> variables of sort " << it->first << " are not subsumed." << std::endl;
-          return -1;
-        }else{
-          Trace("sg-cconj-debug2") << "  variables of sort " << it->first << " are : " << itl->second << " vs " << it->second << std::endl;
-        }
-      }else{
-        Trace("sg-cconj-debug") << "  -> has no variables of sort " << it->first << "." << std::endl;
-        return -1;
-      }
+    if (itl->second < p.second)
+    {
+      Trace("sg-cconj-debug") << "  -> variables of sort " << p.first
+                              << " are not subsumed." << std::endl;
+      return -1;
     }
+    Trace("sg-cconj-debug2")
+        << "  variables of sort " << p.first << " are : " << itl->second
+        << " vs " << p.second << std::endl;
+  }
 
-    //currently active conjecture?
-    std::map< Node, std::vector< Node > >::iterator iteq = d_eq_conjectures.find( lhs );
-    if( iteq!=d_eq_conjectures.end() ){
-      if( std::find( iteq->second.begin(), iteq->second.end(), rhs )!=iteq->second.end() ){
-        Trace("sg-cconj-debug") << "  -> this conjecture is already active." << std::endl;
-        return -1;
-      }
+  // currently active conjecture?
+  std::map<Node, std::vector<Node> >::iterator iteq =
+      d_eq_conjectures.find(lhs);
+  if (iteq != d_eq_conjectures.end())
+  {
+    if (std::find(iteq->second.begin(), iteq->second.end(), rhs)
+        != iteq->second.end())
+    {
+      Trace("sg-cconj-debug")
+          << "  -> this conjecture is already active." << std::endl;
+      return -1;
     }
-    //current a waiting conjecture?
-    std::map< Node, std::vector< Node > >::iterator itw = d_waiting_conjectures.find( lhs );
-    if( itw!=d_waiting_conjectures.end() ){
-      if( std::find( itw->second.begin(), itw->second.end(), rhs )!=itw->second.end() ){
-        Trace("sg-cconj-debug") << "  -> already are considering this conjecture." << std::endl;
-        return -1;
-      }
+  }
+  // current a waiting conjecture?
+  std::map<Node, std::vector<Node> >::iterator itw =
+      d_waiting_conjectures.find(lhs);
+  if (itw != d_waiting_conjectures.end())
+  {
+    if (std::find(itw->second.begin(), itw->second.end(), rhs)
+        != itw->second.end())
+    {
+      Trace("sg-cconj-debug")
+          << "  -> already are considering this conjecture." << std::endl;
+      return -1;
     }
-    // check if canonical representation (should be, but for efficiency this is
-    // not guarenteed) if( options().quantifiers.conjectureFilterCanonical && (
-    // getUniversalRepresentative( lhs )!=lhs || getUniversalRepresentative( rhs
-    // )!=rhs ) ){
-    //  Trace("sg-cconj") << "  -> after processing, not canonical." <<
-    //  std::endl; return -1;
-    //}
-
-    int score;
-    bool scoreSet = false;
+  }
 
-    Trace("sg-cconj") << "Consider possible candidate conjecture : " << lhs << " == " << rhs << "?" << std::endl;
-    //find witness for counterexample, if possible
-    if (options().quantifiers.conjectureFilterModel)
+  size_t score;
+  bool scoreSet = false;
+
+  Trace("sg-cconj") << "Consider possible candidate conjecture : " << lhs
+                    << " == " << rhs << "?" << std::endl;
+  // find witness for counterexample, if possible
+  Assert(d_rel_pattern_var_sum.find(lhs) != d_rel_pattern_var_sum.end());
+  Trace("sg-cconj-debug") << "Notify substitutions over "
+                          << d_rel_pattern_var_sum[lhs] << " variables."
+                          << std::endl;
+  std::map<TNode, TNode> subs;
+  d_subs_confirmCount = 0;
+  d_subs_confirmWitnessRange.clear();
+  d_subs_confirmWitnessDomain.clear();
+  d_subs_unkCount = 0;
+  if (!d_rel_pattern_subs_index[lhs].notifySubstitutions(
+          this, subs, rhs, d_rel_pattern_var_sum[lhs]))
+  {
+    Trace("sg-cconj") << "  -> found witness that falsifies the conjecture."
+                      << std::endl;
+    return -1;
+  }
+  // score is the minimum number of distinct substitutions for a variable
+  for (std::pair<const TNode, std::vector<TNode> >& w :
+       d_subs_confirmWitnessDomain)
+  {
+    size_t num = w.second.size();
+    if (!scoreSet || num < score)
     {
-      Assert(d_rel_pattern_var_sum.find(lhs) != d_rel_pattern_var_sum.end());
-      Trace("sg-cconj-debug") << "Notify substitutions over " << d_rel_pattern_var_sum[lhs] << " variables." << std::endl;
-      std::map< TNode, TNode > subs;
-      d_subs_confirmCount = 0;
-      d_subs_confirmWitnessRange.clear();
-      d_subs_confirmWitnessDomain.clear();
-      d_subs_unkCount = 0;
-      if( !d_rel_pattern_subs_index[lhs].notifySubstitutions( this, subs, rhs, d_rel_pattern_var_sum[lhs] ) ){
-        Trace("sg-cconj") << "  -> found witness that falsifies the conjecture." << std::endl;
-        return -1;
-      }
-      //score is the minimum number of distinct substitutions for a variable
-      for( std::map< TNode, std::vector< TNode > >::iterator it = d_subs_confirmWitnessDomain.begin(); it != d_subs_confirmWitnessDomain.end(); ++it ){
-        int num = (int)it->second.size();
-        if( !scoreSet || num<score ){
-          score = num;
-          scoreSet = true;
-        }
-      }
-      if( !scoreSet ){
-        score = 0;
-      }
-      Trace("sg-cconj") << "     confirmed = " << d_subs_confirmCount << ", #witnesses range = " << d_subs_confirmWitnessRange.size() << "." << std::endl;
-      for( std::map< TNode, std::vector< TNode > >::iterator it = d_subs_confirmWitnessDomain.begin(); it != d_subs_confirmWitnessDomain.end(); ++it ){
-        Trace("sg-cconj") << "     #witnesses for " << it->first << " : " << it->second.size() << std::endl;
-      }
+      score = num;
+      scoreSet = true;
     }
-    else
+  }
+  if (!scoreSet)
+  {
+    score = 0;
+  }
+  if (TraceIsOn("sg-cconj"))
+  {
+    Trace("sg-cconj") << "     confirmed = " << d_subs_confirmCount
+                      << ", #witnesses range = "
+                      << d_subs_confirmWitnessRange.size() << "." << std::endl;
+    for (std::pair<const TNode, std::vector<TNode> >& w :
+         d_subs_confirmWitnessDomain)
     {
-      score = 1;
+      Trace("sg-cconj") << "     #witnesses for " << w.first << " : "
+                        << w.second.size() << std::endl;
     }
-
     Trace("sg-cconj") << "  -> SUCCESS." << std::endl;
     Trace("sg-cconj") << "     score : " << score << std::endl;
-
-    return score;
   }
+  return static_cast<int>(score);
 }
 
 bool ConjectureGenerator::notifySubstitution( TNode glhs, std::map< TNode, TNode >& subs, TNode rhs ) {
@@ -2049,13 +2066,17 @@ bool TermGenEnv::considerCurrentTerm() {
       }
       Trace("sg-gen-tg-debug") << std::endl;
     }
-    if( options::conjectureFilterActiveTerms() && d_ccand_eqc[0][i].empty() ){
+    // filter based active terms
+    if (d_ccand_eqc[0][i].empty())
+    {
       Trace("sg-gen-consider-term") << "Do not consider term of form ";
       d_tg_alloc[0].debugPrint( this, "sg-gen-consider-term", "sg-gen-consider-term-debug" );
       Trace("sg-gen-consider-term") << " since no relevant EQC matches it." << std::endl;
       return false;
     }
-    if( options::conjectureFilterModel() && d_ccand_eqc[1][i].empty() ){
+    // filter based on model
+    if (d_ccand_eqc[1][i].empty())
+    {
       Trace("sg-gen-consider-term") << "Do not consider term of form ";
       d_tg_alloc[0].debugPrint( this, "sg-gen-consider-term", "sg-gen-consider-term-debug" );
       Trace("sg-gen-consider-term") << " since no ground EQC matches it." << std::endl;
@@ -2087,17 +2108,15 @@ void TermGenEnv::changeContext( bool add ) {
 
 bool TermGenEnv::considerCurrentTermCanon( unsigned tg_id ){
   Assert(tg_id < d_tg_alloc.size());
-  if( options::conjectureFilterCanonical() ){
-    //check based on a canonicity of the term (if there is one)
-    Trace("sg-gen-tg-debug") << "Consider term canon ";
-    d_tg_alloc[0].debugPrint( this, "sg-gen-tg-debug", "sg-gen-tg-debug" );
-    Trace("sg-gen-tg-debug") << ", tg is [" << tg_id << "]..." << std::endl;
-
-    Node ln = d_tg_alloc[tg_id].getTerm( this );
-    Trace("sg-gen-tg-debug") << "Term is " << ln << std::endl;
-    return d_cg->considerTermCanon( ln, d_gen_relevant_terms );
-  }
-  return true;
+  // filter based on canonical
+  // check based on a canonicity of the term (if there is one)
+  Trace("sg-gen-tg-debug") << "Consider term canon ";
+  d_tg_alloc[0].debugPrint(this, "sg-gen-tg-debug", "sg-gen-tg-debug");
+  Trace("sg-gen-tg-debug") << ", tg is [" << tg_id << "]..." << std::endl;
+
+  Node ln = d_tg_alloc[tg_id].getTerm(this);
+  Trace("sg-gen-tg-debug") << "Term is " << ln << std::endl;
+  return d_cg->considerTermCanon(ln, d_gen_relevant_terms);
 }
 
 bool TermGenEnv::isRelevantFunc( Node f ) {
index b9bf73da4e2b7a2a9a5f5734d4b819df2ddc79e9..5a497c48516cfb69ad42b7eda7e3902583ae12e6 100644 (file)
@@ -44,7 +44,7 @@ RelevanceManager::RelevanceManager(Env& env, Valuation val)
 {
   if (options().smt.produceDifficulty)
   {
-    d_dman = std::make_unique<DifficultyManager>(this, userContext(), val);
+    d_dman = std::make_unique<DifficultyManager>(env, this, val);
     d_trackRSetExp = true;
     // we cannot miniscope AND at the top level, since we need to
     // preserve the exact form of preprocessed assertions so the dependencies
index 37eccc67f3f03ec62b8e13d931ac729f919e20f6..b87cad954746d17bbc972a480671ce367fc2ad50 100644 (file)
@@ -1,10 +1,7 @@
 ; COMMAND-LINE:
 ; EXPECT: sat
 (set-logic ALL)
-(set-option :conjecture-filter-model true)
 (set-option :conjecture-gen true)
-(set-option :conjecture-filter-canonical false)
-(set-option :conjecture-filter-active-terms false)
 (set-option :quant-ind true)
 (set-option :sygus-inference true)
 (set-info :status sat)