GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/nonlinear_extension.h Lines: 1 1 100.0 %
Date: 2021-08-20 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Gereon Kremer, Tim King
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * Extensions to the theory of arithmetic incomplete handling of nonlinear
14
 * multiplication via axiom instantiations.
15
 */
16
17
#ifndef CVC5__THEORY__ARITH__NL__NONLINEAR_EXTENSION_H
18
#define CVC5__THEORY__ARITH__NL__NONLINEAR_EXTENSION_H
19
20
#include <map>
21
#include <vector>
22
23
#include "expr/node.h"
24
#include "theory/arith/nl/cad_solver.h"
25
#include "theory/arith/nl/ext/ext_state.h"
26
#include "theory/arith/nl/ext/factoring_check.h"
27
#include "theory/arith/nl/ext/monomial_bounds_check.h"
28
#include "theory/arith/nl/ext/monomial_check.h"
29
#include "theory/arith/nl/ext/proof_checker.h"
30
#include "theory/arith/nl/ext/split_zero_check.h"
31
#include "theory/arith/nl/ext/tangent_plane_check.h"
32
#include "theory/arith/nl/ext_theory_callback.h"
33
#include "theory/arith/nl/iand_solver.h"
34
#include "theory/arith/nl/icp/icp_solver.h"
35
#include "theory/arith/nl/nl_model.h"
36
#include "theory/arith/nl/pow2_solver.h"
37
#include "theory/arith/nl/stats.h"
38
#include "theory/arith/nl/strategy.h"
39
#include "theory/arith/nl/transcendental/transcendental_solver.h"
40
#include "theory/ext_theory.h"
41
#include "theory/theory.h"
42
#include "util/result.h"
43
44
namespace cvc5 {
45
namespace theory {
46
namespace eq {
47
  class EqualityEngine;
48
}
49
namespace arith {
50
51
class InferenceManager;
52
class TheoryArith;
53
54
namespace nl {
55
56
class NlLemma;
57
58
/** Non-linear extension class
59
 *
60
 * This class implements model-based refinement schemes
61
 * for non-linear arithmetic, described in:
62
 *
63
 * - "Invariant Checking of NRA Transition Systems
64
 * via Incremental Reduction to LRA with EUF" by
65
 * Cimatti et al., TACAS 2017.
66
 *
67
 * - Section 5 of "Desiging Theory Solvers with
68
 * Extensions" by Reynolds et al., FroCoS 2017.
69
 *
70
 * - "Satisfiability Modulo Transcendental
71
 * Functions via Incremental Linearization" by Cimatti
72
 * et al., CADE 2017.
73
 *
74
 * It's main functionality is a check(...) method,
75
 * which is called by TheoryArithPrivate either:
76
 * (1) at full effort with no conflicts or lemmas emitted, or
77
 * (2) at last call effort.
78
 * In this method, this class calls d_im.lemma(...)
79
 * for valid arithmetic theory lemmas, based on the current set of assertions,
80
 * where d_im is the inference manager of TheoryArith.
81
 */
82
class NonlinearExtension
83
{
84
  typedef context::CDHashSet<Node> NodeSet;
85
86
 public:
87
  NonlinearExtension(TheoryArith& containing, ArithState& state);
88
  ~NonlinearExtension();
89
  /**
90
   * Does non-context dependent setup for a node connected to a theory.
91
   */
92
  void preRegisterTerm(TNode n);
93
  /** Check at effort level e.
94
   *
95
   * This call may result in (possibly multiple) calls to d_im.lemma(...)
96
   * where d_im is the inference manager of TheoryArith.
97
   *
98
   * If e is FULL, then we add lemmas based on context-depedent
99
   * simplification (see Reynolds et al FroCoS 2017).
100
   *
101
   * If e is LAST_CALL, we add lemmas based on model-based refinement
102
   * (see additionally Cimatti et al., TACAS 2017). The lemmas added at this
103
   * effort may be computed during a call to interceptModel as described below.
104
   */
105
  void check(Theory::Effort e);
106
  /** intercept model
107
   *
108
   * This method is called during TheoryArith::collectModelInfo, which is
109
   * invoked after the linear arithmetic solver passes a full effort check
110
   * with no lemmas.
111
   *
112
   * The argument arithModel is a map of the form { v1 -> c1, ..., vn -> cn }
113
   * which represents the linear arithmetic theory solver's contribution to the
114
   * current candidate model. That is, its collectModelInfo method is requesting
115
   * that equalities v1 = c1, ..., vn = cn be added to the current model, where
116
   * v1, ..., vn are arithmetic variables and c1, ..., cn are constants. Notice
117
   * arithmetic variables may be real-valued terms belonging to other theories,
118
   * or abstractions of applications of multiplication (kind NONLINEAR_MULT).
119
   *
120
   * This method requests that the non-linear solver inspect this model and
121
   * do any number of the following:
122
   * (1) Construct lemmas based on a model-based refinement procedure inspired
123
   * by Cimatti et al., TACAS 2017.,
124
   * (2) In the case that the nonlinear solver finds that the current
125
   * constraints are satisfiable, it may "repair" the values in the argument
126
   * arithModel so that it satisfies certain nonlinear constraints. This may
127
   * involve e.g. solving for variables in nonlinear equations.
128
   */
129
  void interceptModel(std::map<Node, Node>& arithModel,
130
                      const std::set<Node>& termSet);
131
  /** Does this class need a call to check(...) at last call effort? */
132
18962
  bool needsCheckLastEffort() const { return d_needsLastCall; }
133
  /** presolve
134
   *
135
   * This function is called during TheoryArith's presolve command.
136
   * In this function, we send lemmas we accumulated during preprocessing,
137
   * for instance, definitional lemmas from expandDefinitions are sent out
138
   * on the output channel of TheoryArith in this function.
139
   */
140
  void presolve();
141
142
  /** Process side effect se */
143
  void processSideEffect(const NlLemma& se);
144
145
  /** Obtain options object */
146
  const Options& options() const;
147
148
 private:
149
  /** Model-based refinement
150
   *
151
   * This is the main entry point of this class for generating lemmas on the
152
   * output channel of the theory of arithmetic.
153
   *
154
   * It is currently run at last call effort. It applies lemma schemas
155
   * described in Reynolds et al. FroCoS 2017 that are based on ruling out
156
   * the current candidate model.
157
   *
158
   * This function returns whether we found a satisfying assignment
159
   * (Result::Sat::SAT), or not (Result::Sat::UNSAT). Note that UNSAT does not
160
   * necessarily means the whole query is UNSAT, but that the linear model was
161
   * refuted by a lemma.
162
   */
163
  Result::Sat modelBasedRefinement(const std::set<Node>& termSet);
164
165
  /** get assertions
166
   *
167
   * Let M be the set of assertions known by THEORY_ARITH. This function adds a
168
   * set of literals M' to assertions such that M' and M are equivalent.
169
   *
170
   * Examples of how M' differs with M:
171
   * (1) M' may not include t < c (in M) if t < c' is in M' for c' < c, where
172
   * c and c' are constants,
173
   * (2) M' may contain t = c if both t >= c and t <= c are in M.
174
   */
175
  void getAssertions(std::vector<Node>& assertions);
176
  /** check model
177
   *
178
   * Returns the subset of assertions whose concrete values we cannot show are
179
   * true in the current model. Notice that we typically cannot compute concrete
180
   * values for assertions involving transcendental functions. Any assertion
181
   * whose model value cannot be computed is included in the return value of
182
   * this function.
183
   */
184
  std::vector<Node> checkModelEval(const std::vector<Node>& assertions);
185
186
  //---------------------------check model
187
  /** Check model
188
   *
189
   * Checks the current model based on solving for equalities, and using error
190
   * bounds on the Taylor approximation.
191
   *
192
   * If this function returns true, then all assertions in the input argument
193
   * "assertions" are satisfied for all interpretations of variables within
194
   * their computed bounds (as stored in d_check_model_bounds).
195
   *
196
   * For details, see Section 3 of Cimatti et al CADE 2017 under the heading
197
   * "Detecting Satisfiable Formulas".
198
   */
199
  bool checkModel(const std::vector<Node>& assertions);
200
  //---------------------------end check model
201
  /** compute relevant assertions */
202
  void computeRelevantAssertions(const std::vector<Node>& assertions,
203
                                 std::vector<Node>& keep);
204
205
  /** run check strategy
206
   *
207
   * Check assertions for consistency in the effort LAST_CALL with a subset of
208
   * the assertions, false_asserts, that evaluate to false in the current model.
209
   *
210
   * xts : the list of (non-reduced) extended terms in the current context.
211
   *
212
   * This method adds lemmas to d_im directly.
213
   */
214
  void runStrategy(Theory::Effort effort,
215
                   const std::vector<Node>& assertions,
216
                   const std::vector<Node>& false_asserts,
217
                   const std::vector<Node>& xts);
218
219
  /** commonly used terms */
220
  Node d_zero;
221
  Node d_one;
222
  Node d_neg_one;
223
  Node d_true;
224
  // The theory of arithmetic containing this extension.
225
  TheoryArith& d_containing;
226
  /** A reference to the arithmetic state object */
227
  ArithState& d_astate;
228
  InferenceManager& d_im;
229
  /** The statistics class */
230
  NlStats d_stats;
231
  // needs last call effort
232
  bool d_needsLastCall;
233
  /**
234
   * The number of times we have the called main check method
235
   * (modelBasedRefinement). This counter is used for interleaving strategies.
236
   */
237
  unsigned d_checkCounter;
238
  /** The callback for the extended theory below */
239
  NlExtTheoryCallback d_extTheoryCb;
240
  /** Extended theory, responsible for context-dependent simplification. */
241
  ExtTheory d_extTheory;
242
  /** The non-linear model object
243
   *
244
   * This class is responsible for computing model values for arithmetic terms
245
   * and for establishing when we are able to answer "SAT".
246
   */
247
  NlModel d_model;
248
249
  /** The transcendental extension object
250
   *
251
   * This is the subsolver responsible for running the procedure for
252
   * transcendental functions.
253
   */
254
  transcendental::TranscendentalSolver d_trSlv;
255
  /** The proof checker for proofs of the nlext. */
256
  ExtProofRuleChecker d_proofChecker;
257
  /**
258
   * Holds common lookup data for the checks implemented in the "nl-ext"
259
   * solvers (from Cimatti et al., TACAS 2017).
260
   */
261
  ExtState d_extState;
262
  /** Solver for factoring lemmas. */
263
  FactoringCheck d_factoringSlv;
264
  /** Solver for lemmas about monomial bounds. */
265
  MonomialBoundsCheck d_monomialBoundsSlv;
266
  /** Solver for lemmas about monomials. */
267
  MonomialCheck d_monomialSlv;
268
  /** Solver for lemmas that split multiplication at zero. */
269
  SplitZeroCheck d_splitZeroSlv;
270
  /** Solver for tangent plane lemmas. */
271
  TangentPlaneCheck d_tangentPlaneSlv;
272
  /** The CAD-based solver */
273
  CadSolver d_cadSlv;
274
  /** The ICP-based solver */
275
  icp::ICPSolver d_icpSlv;
276
  /** The integer and solver
277
   *
278
   * This is the subsolver responsible for running the procedure for
279
   * constraints involving integer and.
280
   */
281
  IAndSolver d_iandSlv;
282
283
  /** The pow2 solver
284
   *
285
   * This is the subsolver responsible for running the procedure for
286
   * constraints involving powers of 2.
287
   */
288
  Pow2Solver d_pow2Slv;
289
290
  /** The strategy for the nonlinear extension. */
291
  Strategy d_strategy;
292
293
  /**
294
   * The approximations computed during collectModelInfo. For details, see
295
   * NlModel::getModelValueRepair.
296
   */
297
  std::map<Node, std::pair<Node, Node>> d_approximations;
298
  /**
299
   * The witnesses computed during collectModelInfo. For details, see
300
   * NlModel::getModelValueRepair.
301
   */
302
  std::map<Node, Node> d_witnesses;
303
}; /* class NonlinearExtension */
304
305
}  // namespace nl
306
}  // namespace arith
307
}  // namespace theory
308
}  // namespace cvc5
309
310
#endif /* CVC5__THEORY__ARITH__NONLINEAR_EXTENSION_H */