Enable --nl-cad by default (#5345)
authorGereon Kremer <gereon.kremer@cs.rwth-aachen.de>
Tue, 27 Oct 2020 12:57:55 +0000 (13:57 +0100)
committerGitHub <noreply@github.com>
Tue, 27 Oct 2020 12:57:55 +0000 (13:57 +0100)
This PR enables `--nl-cad` for QF_NRA (and QF_UFNRA) by default to improve nonlinear arithmetic solving.
Furthermore, it takes care of disabling it when libpoly is not available. It also adds a fix to the CadSolver that avoids incorrect SATs in the presence of theory combination.

src/options/arith_options.toml
src/smt/set_defaults.cpp
src/theory/arith/nl/cad_solver.cpp
test/regress/regress1/nl/iand-native-1.smt2
test/regress/regress1/nl/issue3300-approx-sqrt-witness.smt2

index fad1b3dcdae0766699e13120a36a384476ff1454..f99c8df90d83d32b764e90cbbe1709b51ffaea99 100644 (file)
@@ -433,7 +433,6 @@ header = "options/arith_options.h"
   long       = "nl-ext"
   type       = "bool"
   default    = "true"
-  read_only  = true
   help       = "incremental linearization approach to non-linear"
 
 [[option]]
@@ -564,7 +563,7 @@ header = "options/arith_options.h"
   category   = "regular"
   long       = "nl-cad"
   type       = "bool"
-  default    = "false"
+  default    = "true"
   help       = "whether to use the cylindrical algebraic decomposition solver for non-linear arithmetic"
 
 [[option]]
index 27959a6bcf1a4555b8bbfea5c70faf7426f3d2ec..7a206e2aaa4c0e9cefb407338bba1cc28e4f3d6e 100644 (file)
@@ -1437,6 +1437,36 @@ void setDefaults(LogicInfo& logic, bool isInternalSubsolver)
   {
     throw OptionException("--proof-new is not yet supported.");
   }
+
+  if (logic == LogicInfo("QF_UFNRA"))
+  {
+#ifdef CVC4_USE_POLY
+    if (!options::nlCad() && !options::nlCad.wasSetByUser())
+    {
+      options::nlCad.set(true);
+      options::nlExt.set(false);
+      options::nlRlvMode.set(options::NlRlvMode::INTERLEAVE);
+    }
+#endif
+  }
+#ifndef CVC4_USE_POLY
+  if (options::nlCad())
+  {
+    if (options::nlCad.wasSetByUser())
+    {
+      std::stringstream ss;
+      ss << "Cannot use " << options::nlCad.getName() << " without configuring with --poly.";
+      throw OptionException(ss.str());
+    }
+    else
+    {
+      Notice() << "Cannot use --" << options::nlCad.getName()
+               << " without configuring with --poly." << std::endl;
+      options::nlCad.set(false);
+      options::nlExt.set(true);
+    }
+  }
+#endif
 }
 
 }  // namespace smt
index b63a8398c9c1b466179e99eb128464186a7644c9..d12a861ac6ff86c93ae8374c31385d9973d4c42e 100644 (file)
@@ -18,6 +18,7 @@
 #include <poly/polyxx.h>
 #endif
 
+#include "options/arith_options.h"
 #include "theory/arith/inference_id.h"
 #include "theory/arith/nl/cad/cdcac.h"
 #include "theory/arith/nl/poly_conversion.h"
@@ -145,10 +146,15 @@ bool CadSolver::constructModelIfAvailable(std::vector<Node>& assertions)
   {
     return false;
   }
-  assertions.clear();
+  bool foundNonVariable = false;
   for (const auto& v : d_CAC.getVariableOrdering())
   {
     Node variable = d_CAC.getConstraints().varMapper()(v);
+    if (!variable.isVar())
+    {
+      Trace("nl-cad") << "Not a variable: " << variable << std::endl;
+      foundNonVariable = true;
+    }
     Node value = value_to_node(d_CAC.getModel().get(v), d_ranVariable);
     if (value.isConst())
     {
@@ -160,6 +166,16 @@ bool CadSolver::constructModelIfAvailable(std::vector<Node>& assertions)
     }
     Trace("nl-cad") << "-> " << v << " = " << value << std::endl;
   }
+  if (foundNonVariable)
+  {
+    Trace("nl-cad")
+        << "Some variable was an extended term, don't clear list of assertions."
+        << std::endl;
+    return false;
+  }
+  Trace("nl-cad") << "Constructed a full assignment, clear list of assertions."
+                  << std::endl;
+  assertions.clear();
   return true;
 #else
   Warning() << "Tried to use CadSolver but libpoly is not available. Compile "
index e6a25bcc47f673835927d2214728ef66e4138019..0f50dcaed6db41e1a08fcf82dc783a1cb290a128 100644 (file)
@@ -1,5 +1,5 @@
-; COMMAND-LINE: --iand-mode=value
-; COMMAND-LINE: --iand-mode=sum --bvand-integer-granularity=1 --finite-model-find
+; COMMAND-LINE: --iand-mode=value --no-check-models
+; COMMAND-LINE: --iand-mode=sum --bvand-integer-granularity=1 --finite-model-find --no-check-models
 ; EXPECT: sat
 (set-logic QF_NIA)
 (set-info :status sat)
index 3a4332176230889960a7cd01322ba43dceb5373a..512c8d2e17671a536e65d36f57bf64547991397c 100644 (file)
@@ -1,4 +1,4 @@
-; SCRUBBER: sed -e 's/BOUND_VARIABLE_[0-9]*/BOUND_VARIABLE/; s/((x (witness ((BOUND_VARIABLE Real)) (or (= BOUND_VARIABLE.*/SUCCESS/'
+; SCRUBBER: sed -e 's/BOUND_VARIABLE_[0-9]*/BOUND_VARIABLE/; s/((x (witness ((BOUND_VARIABLE Real)) (.*/SUCCESS/'
 ; COMMAND-LINE: --produce-models --model-witness-value --no-check-models
 ; EXPECT: sat
 ; EXPECT: SUCCESS