Refactor equality engine setup for arithmetic congruence manager (#6902)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Sun, 25 Jul 2021 14:54:28 +0000 (09:54 -0500)
committerGitHub <noreply@github.com>
Sun, 25 Jul 2021 14:54:28 +0000 (14:54 +0000)
Allows congruence manager to use its own (non-official) equality engine if both it and the arithmetic equality solver are enabled.

src/theory/arith/congruence_manager.cpp
src/theory/arith/congruence_manager.h
src/theory/arith/theory_arith_private.cpp

index 9e7202f1dfdb238ba7277d36b5a9d25dee7783f9..3a35319eda87be33e1770e23f58a9047b52b0b35 100644 (file)
@@ -71,24 +71,44 @@ ArithCongruenceManager::~ArithCongruenceManager() {}
 
 bool ArithCongruenceManager::needsEqualityEngine(EeSetupInfo& esi)
 {
+  Assert(!options::arithEqSolver());
   esi.d_notify = &d_notify;
-  esi.d_name = "theory::arith::ArithCongruenceManager";
+  esi.d_name = "arithCong::ee";
   return true;
 }
 
-void ArithCongruenceManager::finishInit(eq::EqualityEngine* ee,
-                                        eq::ProofEqEngine* pfee)
+void ArithCongruenceManager::finishInit(eq::EqualityEngine* ee)
 {
-  Assert(ee != nullptr);
-  d_ee = ee;
+  if (options::arithEqSolver())
+  {
+    // use our own copy
+    d_allocEe.reset(
+        new eq::EqualityEngine(d_notify, d_satContext, "arithCong::ee", true));
+    d_ee = d_allocEe.get();
+    if (d_pnm != nullptr)
+    {
+      // allocate an internal proof equality engine
+      d_allocPfee.reset(
+          new eq::ProofEqEngine(d_satContext, d_userContext, *d_ee, d_pnm));
+      d_ee->setProofEqualityEngine(d_allocPfee.get());
+    }
+  }
+  else
+  {
+    Assert(ee != nullptr);
+    // otherwise, we use the official one
+    d_ee = ee;
+  }
+  // set the congruence kinds on the separate equality engine
   d_ee->addFunctionKind(kind::NONLINEAR_MULT);
   d_ee->addFunctionKind(kind::EXPONENTIAL);
   d_ee->addFunctionKind(kind::SINE);
   d_ee->addFunctionKind(kind::IAND);
   d_ee->addFunctionKind(kind::POW2);
+  // the proof equality engine is the one from the equality engine
+  d_pfee = d_ee->getProofEqualityEngine();
   // have proof equality engine only if proofs are enabled
-  Assert(isProofEnabled() == (pfee != nullptr));
-  d_pfee = pfee;
+  Assert(isProofEnabled() == (d_pfee != nullptr));
 }
 
 ArithCongruenceManager::Statistics::Statistics()
index 4ab0b313b48dd7194f1b2ecbbb6dcf77e6a03b72..2c59a405feb9c2b51e9131529c3c0c96a2cc6c36 100644 (file)
@@ -110,6 +110,8 @@ private:
 
   /** The equality engine being used by this class */
   eq::EqualityEngine* d_ee;
+  /** The equality engine we allocated */
+  std::unique_ptr<eq::EqualityEngine> d_allocEe;
   /** The sat context */
   context::Context* d_satContext;
   /** The user context */
@@ -143,6 +145,8 @@ private:
 
   /** Pointer to the proof equality engine of TheoryArith */
   theory::eq::ProofEqEngine* d_pfee;
+  /** The proof equality engine we allocated */
+  std::unique_ptr<eq::ProofEqEngine> d_allocPfee;
 
   /** Raise a conflict node `conflict` to the theory of arithmetic.
    *
@@ -240,9 +244,9 @@ private:
   bool needsEqualityEngine(EeSetupInfo& esi);
   /**
    * Finish initialize. This class is instructed by TheoryArithPrivate to use
-   * the equality engine ee and proof equality engine pfee.
+   * the equality engine ee.
    */
-  void finishInit(eq::EqualityEngine* ee, eq::ProofEqEngine* pfee);
+  void finishInit(eq::EqualityEngine* ee);
   //--------------------------------- end initialization
 
   /**
index fb9de9641914f2bd9a2c5ad79164ebf288b53868..d7ae08379396addefce25710ea66d4a0000c57b4 100644 (file)
@@ -181,14 +181,20 @@ TheoryArithPrivate::~TheoryArithPrivate(){
 
 bool TheoryArithPrivate::needsEqualityEngine(EeSetupInfo& esi)
 {
+  if (!d_cmEnabled)
+  {
+    return false;
+  }
   return d_congruenceManager.needsEqualityEngine(esi);
 }
 void TheoryArithPrivate::finishInit()
 {
-  eq::EqualityEngine* ee = d_containing.getEqualityEngine();
-  eq::ProofEqEngine* pfee = d_containing.getProofEqEngine();
-  Assert(ee != nullptr);
-  d_congruenceManager.finishInit(ee, pfee);
+  if (d_cmEnabled)
+  {
+    eq::EqualityEngine* ee = d_containing.getEqualityEngine();
+    Assert(ee != nullptr);
+    d_congruenceManager.finishInit(ee);
+  }
 }
 
 static bool contains(const ConstraintCPVec& v, ConstraintP con){