(proof-new) Setup proof infrastructure for transcendental solver (#5703)
authorGereon Kremer <gkremer@stanford.edu>
Fri, 18 Dec 2020 17:11:51 +0000 (18:11 +0100)
committerGitHub <noreply@github.com>
Fri, 18 Dec 2020 17:11:51 +0000 (11:11 -0600)
This PR introduces the infrastructure for adding proofs to the transcendental solver:

a CDProofSet to easily create new proofs
a proof checker

src/CMakeLists.txt
src/theory/arith/nl/nonlinear_extension.cpp
src/theory/arith/nl/transcendental/proof_checker.cpp [new file with mode: 0644]
src/theory/arith/nl/transcendental/proof_checker.h [new file with mode: 0644]
src/theory/arith/nl/transcendental/transcendental_solver.cpp
src/theory/arith/nl/transcendental/transcendental_solver.h
src/theory/arith/nl/transcendental/transcendental_state.cpp
src/theory/arith/nl/transcendental/transcendental_state.h

index 8dc30e54978b02895da5c27d35e8f754551888e4..82e88f330d29fe1b0e6276746c19feb5edec844a 100644 (file)
@@ -391,6 +391,8 @@ libcvc4_add_sources(
   theory/arith/nl/strategy.h
   theory/arith/nl/transcendental/exponential_solver.cpp
   theory/arith/nl/transcendental/exponential_solver.h
+  theory/arith/nl/transcendental/proof_checker.cpp
+  theory/arith/nl/transcendental/proof_checker.h
   theory/arith/nl/transcendental/sine_solver.cpp
   theory/arith/nl/transcendental/sine_solver.h
   theory/arith/nl/transcendental/taylor_generator.cpp
index d52095e958ae06bd03bcdf7c52e961e822df1732..b97a53f953489591a39114bad7c01d228d6e15aa 100644 (file)
@@ -47,7 +47,7 @@ NonlinearExtension::NonlinearExtension(TheoryArith& containing,
                   containing.getUserContext(),
                   containing.getOutputChannel()),
       d_model(containing.getSatContext()),
-      d_trSlv(d_im, d_model),
+      d_trSlv(d_im, d_model, pnm, containing.getUserContext()),
       d_extState(d_im, d_model, pnm, containing.getUserContext()),
       d_factoringSlv(d_im, d_model),
       d_monomialBoundsSlv(&d_extState),
diff --git a/src/theory/arith/nl/transcendental/proof_checker.cpp b/src/theory/arith/nl/transcendental/proof_checker.cpp
new file mode 100644 (file)
index 0000000..d407621
--- /dev/null
@@ -0,0 +1,55 @@
+/*********************                                                        */
+/*! \file proof_checker.cpp
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Gereon Kremer
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
+ ** in the top-level source directory and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Implementation of proof checker for transcendentals
+ **/
+
+#include "theory/arith/nl/transcendental/proof_checker.h"
+
+#include "expr/sequence.h"
+#include "theory/arith/arith_utilities.h"
+#include "theory/arith/nl/transcendental/taylor_generator.h"
+#include "theory/rewriter.h"
+
+using namespace CVC4::kind;
+
+namespace CVC4 {
+namespace theory {
+namespace arith {
+namespace nl {
+namespace transcendental {
+
+void TranscendentalProofRuleChecker::registerTo(ProofChecker* pc)
+{
+}
+
+Node TranscendentalProofRuleChecker::checkInternal(
+    PfRule id, const std::vector<Node>& children, const std::vector<Node>& args)
+{
+  NodeManager* nm = NodeManager::currentNM();
+  auto zero = nm->mkConst<Rational>(0);
+  auto one = nm->mkConst<Rational>(1);
+  auto mone = nm->mkConst<Rational>(-1);
+  auto pi = nm->mkNullaryOperator(nm->realType(), Kind::PI);
+  auto mpi = nm->mkNode(Kind::MULT, mone, pi);
+  Trace("nl-trans-checker") << "Checking " << id << std::endl;
+  for (const auto& c : children)
+  {
+    Trace("nl-trans-checker") << "\t" << c << std::endl;
+  }
+  return Node::null();
+}
+
+}  // namespace transcendental
+}  // namespace nl
+}  // namespace arith
+}  // namespace theory
+}  // namespace CVC4
diff --git a/src/theory/arith/nl/transcendental/proof_checker.h b/src/theory/arith/nl/transcendental/proof_checker.h
new file mode 100644 (file)
index 0000000..2634d70
--- /dev/null
@@ -0,0 +1,58 @@
+/*********************                                                        */
+/*! \file proof_checker.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Gereon Kremer
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
+ ** in the top-level source directory and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Proof checker utility for transcendental solver
+ **/
+
+#include "cvc4_private.h"
+
+#ifndef CVC4__THEORY__ARITH__NL__TRANSCENDENTAL__PROOF_CHECKER_H
+#define CVC4__THEORY__ARITH__NL__TRANSCENDENTAL__PROOF_CHECKER_H
+
+#include "expr/node.h"
+#include "expr/proof_checker.h"
+#include "expr/proof_node.h"
+
+namespace CVC4 {
+namespace theory {
+namespace arith {
+namespace nl {
+namespace transcendental {
+
+/**
+ * A checker for NlExt proofs
+ *
+ * This proof checker takes care of all proofs for lemmas from the
+ * transcendental subsolver.
+ */
+class TranscendentalProofRuleChecker : public ProofRuleChecker
+{
+ public:
+  TranscendentalProofRuleChecker() = default;
+  ~TranscendentalProofRuleChecker() = default;
+
+  /** Register all rules owned by this rule checker in pc. */
+  void registerTo(ProofChecker* pc) override;
+
+ protected:
+  /** Return the conclusion of the given proof step, or null if it is invalid */
+  Node checkInternal(PfRule id,
+                     const std::vector<Node>& children,
+                     const std::vector<Node>& args) override;
+};
+
+}  // namespace transcendental
+}  // namespace nl
+}  // namespace arith
+}  // namespace theory
+}  // namespace CVC4
+
+#endif /* CVC4__THEORY__STRINGS__PROOF_CHECKER_H */
index c2841c13505c1b336a3146744707de554aa8fe42..233667e5be7dd2953dd1b9c624208f2b2c906d04 100644 (file)
@@ -33,8 +33,11 @@ namespace arith {
 namespace nl {
 namespace transcendental {
 
-TranscendentalSolver::TranscendentalSolver(InferenceManager& im, NlModel& m)
-    : d_tstate(im, m), d_expSlv(&d_tstate), d_sineSlv(&d_tstate)
+TranscendentalSolver::TranscendentalSolver(InferenceManager& im,
+                                           NlModel& m,
+                                           ProofNodeManager* pnm,
+                                           context::UserContext* c)
+    : d_tstate(im, m, pnm, c), d_expSlv(&d_tstate), d_sineSlv(&d_tstate)
 {
   d_taylor_degree = options::nlExtTfTaylorDegree();
 }
index 64f6db1633a036f609e823c5a653b3c4ee01a142..8135ba1fb5e834038e28fec9b8ed7dbf97e6efb4 100644 (file)
@@ -65,7 +65,10 @@ namespace transcendental {
 class TranscendentalSolver
 {
  public:
-  TranscendentalSolver(InferenceManager& im, NlModel& m);
+  TranscendentalSolver(InferenceManager& im,
+                       NlModel& m,
+                       ProofNodeManager* pnm,
+                       context::UserContext* c);
   ~TranscendentalSolver();
 
   /** init last call
index 6dbb847a604f0122ea6e9d20c59f4bb151edb762..67db4f2cc875428719dfef81f692310ba9d1ffe2 100644 (file)
@@ -23,14 +23,34 @@ namespace arith {
 namespace nl {
 namespace transcendental {
 
-TranscendentalState::TranscendentalState(InferenceManager& im, NlModel& model)
-    : d_im(im), d_model(model)
+TranscendentalState::TranscendentalState(InferenceManager& im,
+                                         NlModel& model,
+                                         ProofNodeManager* pnm,
+                                         context::UserContext* c)
+    : d_im(im), d_model(model), d_pnm(pnm), d_ctx(c)
 {
   d_true = NodeManager::currentNM()->mkConst(true);
   d_false = NodeManager::currentNM()->mkConst(false);
   d_zero = NodeManager::currentNM()->mkConst(Rational(0));
   d_one = NodeManager::currentNM()->mkConst(Rational(1));
   d_neg_one = NodeManager::currentNM()->mkConst(Rational(-1));
+  if (d_pnm != nullptr)
+  {
+    d_proof.reset(new CDProofSet<CDProof>(d_pnm, d_ctx, "nl-trans"));
+    d_proofChecker.reset(new TranscendentalProofRuleChecker());
+    d_proofChecker->registerTo(pnm->getChecker());
+  }
+}
+
+bool TranscendentalState::isProofEnabled() const
+{
+  return d_proof.get() != nullptr;
+}
+
+CDProof* TranscendentalState::getProof()
+{
+  Assert(isProofEnabled());
+  return d_proof->allocateProof(d_ctx);
 }
 
 void TranscendentalState::init(const std::vector<Node>& xts,
index f940ae2e3f5b56fb022c7a2bfccd131824ddd202..93ac4627a3844e59a4848ceed933667ac694f6f8 100644 (file)
 #define CVC4__THEORY__ARITH__NL__TRANSCENDENTAL__TRANSCENDENTAL_STATE_H
 
 #include "expr/node.h"
+#include "expr/proof_set.h"
 #include "theory/arith/inference_manager.h"
 #include "theory/arith/nl/nl_model.h"
+#include "theory/arith/nl/transcendental/proof_checker.h"
 #include "theory/arith/nl/transcendental/taylor_generator.h"
 
 namespace CVC4 {
@@ -52,7 +54,19 @@ inline std::ostream& operator<<(std::ostream& os, Convexity c) {
  */
 struct TranscendentalState
 {
-  TranscendentalState(InferenceManager& im, NlModel& model);
+  TranscendentalState(InferenceManager& im,
+                      NlModel& model,
+                      ProofNodeManager* pnm,
+                      context::UserContext* c);
+
+  /**
+   * Checks whether proofs are enabled.
+   */
+  bool isProofEnabled() const;
+  /**
+   * Creates and returns a new LazyCDProof that can be used to prove some lemma.
+   */
+  CDProof* getProof();
 
   /** init last call
    *
@@ -151,6 +165,20 @@ struct TranscendentalState
   NlModel& d_model;
   /** Utility to compute taylor approximations */
   TaylorGenerator d_taylor;
+  /**
+   * Pointer to the current proof node manager. nullptr, if proofs are
+   * disabled.
+   */
+  ProofNodeManager* d_pnm;
+  /** The user context. */
+  context::UserContext* d_ctx;
+  /**
+   * A CDProofSet that hands out CDProof objects for lemmas.
+   */
+  std::unique_ptr<CDProofSet<CDProof>> d_proof;
+
+  /** The proof checker for transcendental proofs */
+  std::unique_ptr<TranscendentalProofRuleChecker> d_proofChecker;
 
   /**
    * Some transcendental functions f(t) are "purified", e.g. we add