GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/nonlinear_extension.h Lines: 1 1 100.0 %
Date: 2021-08-16 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,
88
                     ArithState& state,
89
                     eq::EqualityEngine* ee,
90
                     ProofNodeManager* pnm);
91
  ~NonlinearExtension();
92
  /**
93
   * Does non-context dependent setup for a node connected to a theory.
94
   */
95
  void preRegisterTerm(TNode n);
96
  /** Check at effort level e.
97
   *
98
   * This call may result in (possibly multiple) calls to d_im.lemma(...)
99
   * where d_im is the inference manager of TheoryArith.
100
   *
101
   * If e is FULL, then we add lemmas based on context-depedent
102
   * simplification (see Reynolds et al FroCoS 2017).
103
   *
104
   * If e is LAST_CALL, we add lemmas based on model-based refinement
105
   * (see additionally Cimatti et al., TACAS 2017). The lemmas added at this
106
   * effort may be computed during a call to interceptModel as described below.
107
   */
108
  void check(Theory::Effort e);
109
  /** intercept model
110
   *
111
   * This method is called during TheoryArith::collectModelInfo, which is
112
   * invoked after the linear arithmetic solver passes a full effort check
113
   * with no lemmas.
114
   *
115
   * The argument arithModel is a map of the form { v1 -> c1, ..., vn -> cn }
116
   * which represents the linear arithmetic theory solver's contribution to the
117
   * current candidate model. That is, its collectModelInfo method is requesting
118
   * that equalities v1 = c1, ..., vn = cn be added to the current model, where
119
   * v1, ..., vn are arithmetic variables and c1, ..., cn are constants. Notice
120
   * arithmetic variables may be real-valued terms belonging to other theories,
121
   * or abstractions of applications of multiplication (kind NONLINEAR_MULT).
122
   *
123
   * This method requests that the non-linear solver inspect this model and
124
   * do any number of the following:
125
   * (1) Construct lemmas based on a model-based refinement procedure inspired
126
   * by Cimatti et al., TACAS 2017.,
127
   * (2) In the case that the nonlinear solver finds that the current
128
   * constraints are satisfiable, it may "repair" the values in the argument
129
   * arithModel so that it satisfies certain nonlinear constraints. This may
130
   * involve e.g. solving for variables in nonlinear equations.
131
   */
132
  void interceptModel(std::map<Node, Node>& arithModel,
133
                      const std::set<Node>& termSet);
134
  /** Does this class need a call to check(...) at last call effort? */
135
19024
  bool needsCheckLastEffort() const { return d_needsLastCall; }
136
  /** presolve
137
   *
138
   * This function is called during TheoryArith's presolve command.
139
   * In this function, we send lemmas we accumulated during preprocessing,
140
   * for instance, definitional lemmas from expandDefinitions are sent out
141
   * on the output channel of TheoryArith in this function.
142
   */
143
  void presolve();
144
145
  /** Process side effect se */
146
  void processSideEffect(const NlLemma& se);
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
  InferenceManager& d_im;
227
  /** The statistics class */
228
  NlStats d_stats;
229
  // needs last call effort
230
  bool d_needsLastCall;
231
  /**
232
   * The number of times we have the called main check method
233
   * (modelBasedRefinement). This counter is used for interleaving strategies.
234
   */
235
  unsigned d_checkCounter;
236
  /** The callback for the extended theory below */
237
  NlExtTheoryCallback d_extTheoryCb;
238
  /** Extended theory, responsible for context-dependent simplification. */
239
  ExtTheory d_extTheory;
240
  /** The non-linear model object
241
   *
242
   * This class is responsible for computing model values for arithmetic terms
243
   * and for establishing when we are able to answer "SAT".
244
   */
245
  NlModel d_model;
246
247
  /** The transcendental extension object
248
   *
249
   * This is the subsolver responsible for running the procedure for
250
   * transcendental functions.
251
   */
252
  transcendental::TranscendentalSolver d_trSlv;
253
  /** The proof checker for proofs of the nlext. */
254
  ExtProofRuleChecker d_proofChecker;
255
  /**
256
   * Holds common lookup data for the checks implemented in the "nl-ext"
257
   * solvers (from Cimatti et al., TACAS 2017).
258
   */
259
  ExtState d_extState;
260
  /** Solver for factoring lemmas. */
261
  FactoringCheck d_factoringSlv;
262
  /** Solver for lemmas about monomial bounds. */
263
  MonomialBoundsCheck d_monomialBoundsSlv;
264
  /** Solver for lemmas about monomials. */
265
  MonomialCheck d_monomialSlv;
266
  /** Solver for lemmas that split multiplication at zero. */
267
  SplitZeroCheck d_splitZeroSlv;
268
  /** Solver for tangent plane lemmas. */
269
  TangentPlaneCheck d_tangentPlaneSlv;
270
  /** The CAD-based solver */
271
  CadSolver d_cadSlv;
272
  /** The ICP-based solver */
273
  icp::ICPSolver d_icpSlv;
274
  /** The integer and solver
275
   *
276
   * This is the subsolver responsible for running the procedure for
277
   * constraints involving integer and.
278
   */
279
  IAndSolver d_iandSlv;
280
281
  /** The pow2 solver
282
   *
283
   * This is the subsolver responsible for running the procedure for
284
   * constraints involving powers of 2.
285
   */
286
  Pow2Solver d_pow2Slv;
287
288
  /** The strategy for the nonlinear extension. */
289
  Strategy d_strategy;
290
291
  /**
292
   * The approximations computed during collectModelInfo. For details, see
293
   * NlModel::getModelValueRepair.
294
   */
295
  std::map<Node, std::pair<Node, Node>> d_approximations;
296
  /**
297
   * The witnesses computed during collectModelInfo. For details, see
298
   * NlModel::getModelValueRepair.
299
   */
300
  std::map<Node, Node> d_witnesses;
301
}; /* class NonlinearExtension */
302
303
}  // namespace nl
304
}  // namespace arith
305
}  // namespace theory
306
}  // namespace cvc5
307
308
#endif /* CVC5__THEORY__ARITH__NONLINEAR_EXTENSION_H */