GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/smt_engine.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
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
 * SmtEngine: the main public entry point of libcvc5.
14
 */
15
16
#include "cvc5_public.h"
17
18
#ifndef CVC5__SMT_ENGINE_H
19
#define CVC5__SMT_ENGINE_H
20
21
#include <map>
22
#include <memory>
23
#include <string>
24
#include <vector>
25
26
#include "context/cdhashmap_forward.h"
27
#include "cvc5_export.h"
28
#include "options/options.h"
29
#include "smt/output_manager.h"
30
#include "smt/smt_mode.h"
31
#include "theory/logic_info.h"
32
#include "util/result.h"
33
34
namespace cvc5 {
35
36
template <bool ref_count> class NodeTemplate;
37
typedef NodeTemplate<true> Node;
38
typedef NodeTemplate<false> TNode;
39
class TypeNode;
40
41
class Env;
42
class NodeManager;
43
class TheoryEngine;
44
class UnsatCore;
45
class LogicRequest;
46
class StatisticsRegistry;
47
class Printer;
48
class ResourceManager;
49
struct InstantiationList;
50
51
/* -------------------------------------------------------------------------- */
52
53
namespace api {
54
class Solver;
55
}  // namespace api
56
57
/* -------------------------------------------------------------------------- */
58
59
namespace context {
60
  class Context;
61
  class UserContext;
62
  }  // namespace context
63
64
/* -------------------------------------------------------------------------- */
65
66
namespace preprocessing {
67
class PreprocessingPassContext;
68
}
69
70
/* -------------------------------------------------------------------------- */
71
72
namespace prop {
73
  class PropEngine;
74
  }  // namespace prop
75
76
/* -------------------------------------------------------------------------- */
77
78
namespace smt {
79
/** Utilities */
80
class Model;
81
class SmtEngineState;
82
class AbstractValues;
83
class Assertions;
84
class DumpManager;
85
class ResourceOutListener;
86
class SmtNodeManagerListener;
87
class OptionsManager;
88
class Preprocessor;
89
class CheckModels;
90
/** Subsolvers */
91
class SmtSolver;
92
class SygusSolver;
93
class AbductionSolver;
94
class InterpolationSolver;
95
class QuantElimSolver;
96
97
struct SmtEngineStatistics;
98
class SmtScope;
99
class PfManager;
100
class UnsatCoreManager;
101
102
}  // namespace smt
103
104
/* -------------------------------------------------------------------------- */
105
106
namespace theory {
107
  class Rewriter;
108
  class QuantifiersEngine;
109
  }  // namespace theory
110
111
/* -------------------------------------------------------------------------- */
112
113
class CVC5_EXPORT SmtEngine
114
{
115
  friend class ::cvc5::api::Solver;
116
  friend class ::cvc5::smt::SmtEngineState;
117
  friend class ::cvc5::smt::SmtScope;
118
  friend class ::cvc5::LogicRequest;
119
120
  /* .......................................................................  */
121
 public:
122
  /* .......................................................................  */
123
124
  /**
125
   * Construct an SmtEngine with the given expression manager.
126
   * If provided, optr is a pointer to a set of options that should initialize the values
127
   * of the options object owned by this class.
128
   */
129
  SmtEngine(NodeManager* nm, Options* optr = nullptr);
130
  /** Destruct the SMT engine.  */
131
  ~SmtEngine();
132
133
  //--------------------------------------------- concerning the state
134
135
  /**
136
   * This is the main initialization procedure of the SmtEngine.
137
   *
138
   * Should be called whenever the final options and logic for the problem are
139
   * set (at least, those options that are not permitted to change after
140
   * assertions and queries are made).
141
   *
142
   * Internally, this creates the theory engine, prop engine, decision engine,
143
   * and other utilities whose initialization depends on the final set of
144
   * options being set.
145
   *
146
   * This post-construction initialization is automatically triggered by the
147
   * use of the SmtEngine; e.g. when the first formula is asserted, a call
148
   * to simplify() is issued, a scope is pushed, etc.
149
   */
150
  void finishInit();
151
  /**
152
   * Return true if this SmtEngine is fully initialized (post-construction)
153
   * by the above call.
154
   */
155
  bool isFullyInited() const;
156
  /**
157
   * Return true if a checkEntailed() or checkSatisfiability() has been made.
158
   */
159
  bool isQueryMade() const;
160
  /** Return the user context level.  */
161
  size_t getNumUserLevels() const;
162
  /** Return the current mode of the solver. */
163
  SmtMode getSmtMode() const;
164
  /**
165
   * Whether the SmtMode allows for get-value, get-model, get-assignment, etc.
166
   * This is equivalent to:
167
   * getSmtMode()==SmtMode::SAT || getSmtMode()==SmtMode::SAT_UNKNOWN
168
   */
169
  bool isSmtModeSat() const;
170
  /**
171
   * Returns the most recent result of checkSat/checkEntailed or
172
   * (set-info :status).
173
   */
174
  Result getStatusOfLastCommand() const;
175
  //--------------------------------------------- end concerning the state
176
177
  /**
178
   * Set the logic of the script.
179
   * @throw ModalException, LogicException
180
   */
181
  void setLogic(const std::string& logic);
182
183
  /**
184
   * Set the logic of the script.
185
   * @throw ModalException, LogicException
186
   */
187
  void setLogic(const char* logic);
188
189
  /**
190
   * Set the logic of the script.
191
   * @throw ModalException
192
   */
193
  void setLogic(const LogicInfo& logic);
194
195
  /** Get the logic information currently set. */
196
  const LogicInfo& getLogicInfo() const;
197
198
  /** Get the logic information set by the user. */
199
  LogicInfo getUserLogicInfo() const;
200
201
  /**
202
   * Set information about the script executing.
203
   */
204
  void setInfo(const std::string& key, const std::string& value);
205
206
  /** Return true if given keyword is a valid SMT-LIB v2 get-info flag. */
207
  bool isValidGetInfoFlag(const std::string& key) const;
208
209
  /** Query information about the SMT environment.  */
210
  std::string getInfo(const std::string& key) const;
211
212
  /**
213
   * Set an aspect of the current SMT execution environment.
214
   * @throw OptionException, ModalException
215
   */
216
  void setOption(const std::string& key, const std::string& value);
217
218
  /** Set is internal subsolver.
219
   *
220
   * This function is called on SmtEngine objects that are created internally.
221
   * It is used to mark that this SmtEngine should not perform preprocessing
222
   * passes that rephrase the input, such as --sygus-rr-synth-input or
223
   * --sygus-abduct.
224
   */
225
  void setIsInternalSubsolver();
226
  /** Is this an internal subsolver? */
227
  bool isInternalSubsolver() const;
228
229
  /**
230
   * Notify that we are now parsing the input with the given filename.
231
   * This call sets the filename maintained by this SmtEngine for bookkeeping
232
   * and also makes a copy of the current options of this SmtEngine. This
233
   * is required so that the SMT-LIB command (reset) returns the SmtEngine
234
   * to a state where its options were prior to parsing but after e.g.
235
   * reading command line options.
236
   */
237
  void notifyStartParsing(const std::string& filename) CVC5_EXPORT;
238
  /** return the input name (if any) */
239
  const std::string& getFilename() const;
240
241
  /**
242
   * Helper method for the API to put the last check result into the statistics.
243
   */
244
  void setResultStatistic(const std::string& result) CVC5_EXPORT;
245
  /**
246
   * Helper method for the API to put the total runtime into the statistics.
247
   */
248
  void setTotalTimeStatistic(double seconds) CVC5_EXPORT;
249
250
  /**
251
   * Get the model (only if immediately preceded by a SAT or NOT_ENTAILED
252
   * query).  Only permitted if produce-models is on.
253
   *
254
   * TODO (issues#287): eliminate this method.
255
   */
256
  smt::Model* getModel();
257
258
  /**
259
   * Block the current model. Can be called only if immediately preceded by
260
   * a SAT or INVALID query. Only permitted if produce-models is on, and the
261
   * block-models option is set to a mode other than "none".
262
   *
263
   * This adds an assertion to the assertion stack that blocks the current
264
   * model based on the current options configured by cvc5.
265
   *
266
   * The return value has the same meaning as that of assertFormula.
267
   */
268
  Result blockModel();
269
270
  /**
271
   * Block the current model values of (at least) the values in exprs.
272
   * Can be called only if immediately preceded by a SAT or NOT_ENTAILED query.
273
   * Only permitted if produce-models is on, and the block-models option is set
274
   * to a mode other than "none".
275
   *
276
   * This adds an assertion to the assertion stack of the form:
277
   *  (or (not (= exprs[0] M0)) ... (not (= exprs[n] Mn)))
278
   * where M0 ... Mn are the current model values of exprs[0] ... exprs[n].
279
   *
280
   * The return value has the same meaning as that of assertFormula.
281
   */
282
  Result blockModelValues(const std::vector<Node>& exprs);
283
284
  /**
285
   * Declare heap. For smt2 inputs, this is called when the command
286
   * (declare-heap (locT datat)) is invoked by the user. This sets locT as the
287
   * location type and dataT is the data type for the heap. This command should
288
   * be executed only once, and must be invoked before solving separation logic
289
   * inputs.
290
   */
291
  void declareSepHeap(TypeNode locT, TypeNode dataT);
292
293
  /**
294
   * Get the separation heap types, which extracts which types were passed to
295
   * the method above.
296
   *
297
   * @return true if the separation logic heap types have been declared.
298
   */
299
  bool getSepHeapTypes(TypeNode& locT, TypeNode& dataT);
300
301
  /** When using separation logic, obtain the expression for the heap.  */
302
  Node getSepHeapExpr();
303
304
  /** When using separation logic, obtain the expression for nil.  */
305
  Node getSepNilExpr();
306
307
  /**
308
   * Get an aspect of the current SMT execution environment.
309
   * @throw OptionException
310
   */
311
  std::string getOption(const std::string& key) const;
312
313
  /**
314
   * Define function func in the current context to be:
315
   *   (lambda (formals) formula)
316
   * This adds func to the list of defined functions, which indicates that
317
   * all occurrences of func should be expanded during expandDefinitions.
318
   *
319
   * @param func a variable of function type that expects the arguments in
320
   *             formal
321
   * @param formals a list of BOUND_VARIABLE expressions
322
   * @param formula The body of the function, must not contain func
323
   * @param global True if this definition is global (i.e. should persist when
324
   *               popping the user context)
325
   */
326
  void defineFunction(Node func,
327
                      const std::vector<Node>& formals,
328
                      Node formula,
329
                      bool global = false);
330
331
  /**
332
   * Define functions recursive
333
   *
334
   * For each i, this constrains funcs[i] in the current context to be:
335
   *   (lambda (formals[i]) formulas[i])
336
   * where formulas[i] may contain variables from funcs. Unlike defineFunction
337
   * above, we do not add funcs[i] to the set of defined functions. Instead,
338
   * we consider funcs[i] to be a free uninterpreted function, and add:
339
   *   forall formals[i]. f(formals[i]) = formulas[i]
340
   * to the set of assertions in the current context.
341
   * This method expects input such that for each i:
342
   * - func[i] : a variable of function type that expects the arguments in
343
   *             formals[i], and
344
   * - formals[i] : a list of BOUND_VARIABLE expressions.
345
   *
346
   * @param global True if this definition is global (i.e. should persist when
347
   *               popping the user context)
348
   */
349
  void defineFunctionsRec(const std::vector<Node>& funcs,
350
                          const std::vector<std::vector<Node>>& formals,
351
                          const std::vector<Node>& formulas,
352
                          bool global = false);
353
  /**
354
   * Define function recursive
355
   * Same as above, but for a single function.
356
   */
357
  void defineFunctionRec(Node func,
358
                         const std::vector<Node>& formals,
359
                         Node formula,
360
                         bool global = false);
361
  /**
362
   * Add a formula to the current context: preprocess, do per-theory
363
   * setup, use processAssertionList(), asserting to T-solver for
364
   * literals and conjunction of literals.  Returns false if
365
   * immediately determined to be inconsistent. Note this formula will
366
   * be included in the unsat core when applicable.
367
   *
368
   * @throw TypeCheckingException, LogicException, UnsafeInterruptException
369
   */
370
  Result assertFormula(const Node& formula);
371
372
  /**
373
   * Reduce an unsatisfiable core to make it minimal.
374
   */
375
  std::vector<Node> reduceUnsatCore(const std::vector<Node>& core);
376
377
  /**
378
   * Check if a given (set of) expression(s) is entailed with respect to the
379
   * current set of assertions. We check this by asserting the negation of
380
   * the (big AND over the) given (set of) expression(s).
381
   * Returns ENTAILED, NOT_ENTAILED, or ENTAILMENT_UNKNOWN result.
382
   *
383
   * @throw Exception
384
   */
385
  Result checkEntailed(const Node& assumption);
386
  Result checkEntailed(const std::vector<Node>& assumptions);
387
388
  /**
389
   * Assert a formula (if provided) to the current context and call
390
   * check().  Returns SAT, UNSAT, or SAT_UNKNOWN result.
391
   *
392
   * @throw Exception
393
   */
394
  Result checkSat();
395
  Result checkSat(const Node& assumption);
396
  Result checkSat(const std::vector<Node>& assumptions);
397
398
  /**
399
   * Returns a set of so-called "failed" assumptions.
400
   *
401
   * The returned set is a subset of the set of assumptions of a previous
402
   * (unsatisfiable) call to checkSatisfiability. Calling checkSatisfiability
403
   * with this set of failed assumptions still produces an unsat answer.
404
   *
405
   * Note that the returned set of failed assumptions is not necessarily
406
   * minimal.
407
   */
408
  std::vector<Node> getUnsatAssumptions(void);
409
410
  /*---------------------------- sygus commands  ---------------------------*/
411
412
  /**
413
   * Add sygus variable declaration.
414
   *
415
   * Declared SyGuS variables may be used in SyGuS constraints, in which they
416
   * are assumed to be universally quantified.
417
   *
418
   * In SyGuS semantics, declared functions are treated in the same manner as
419
   * declared variables, i.e. as universally quantified (function) variables
420
   * which can occur in the SyGuS constraints that compose the conjecture to
421
   * which a function is being synthesized. Thus declared functions should use
422
   * this method as well.
423
   */
424
  void declareSygusVar(Node var);
425
426
  /**
427
   * Add a function-to-synthesize declaration.
428
   *
429
   * The given sygusType may not correspond to the actual function type of func
430
   * but to a datatype encoding the syntax restrictions for the
431
   * function-to-synthesize. In this case this information is stored to be used
432
   * during solving.
433
   *
434
   * vars contains the arguments of the function-to-synthesize. These variables
435
   * are also stored to be used during solving.
436
   *
437
   * isInv determines whether the function-to-synthesize is actually an
438
   * invariant. This information is necessary if we are dumping a command
439
   * corresponding to this declaration, so that it can be properly printed.
440
   */
441
  void declareSynthFun(Node func,
442
                       TypeNode sygusType,
443
                       bool isInv,
444
                       const std::vector<Node>& vars);
445
  /**
446
   * Same as above, without a sygus type.
447
   */
448
  void declareSynthFun(Node func, bool isInv, const std::vector<Node>& vars);
449
450
  /** Add a regular sygus constraint.*/
451
  void assertSygusConstraint(Node constraint);
452
453
  /**
454
   * Add an invariant constraint.
455
   *
456
   * Invariant constraints are not explicitly declared: they are given in terms
457
   * of the invariant-to-synthesize, the pre condition, transition relation and
458
   * post condition. The actual constraint is built based on the inputs of these
459
   * place holder predicates :
460
   *
461
   * PRE(x) -> INV(x)
462
   * INV() ^ TRANS(x, x') -> INV(x')
463
   * INV(x) -> POST(x)
464
   *
465
   * The regular and primed variables are retrieved from the declaration of the
466
   * invariant-to-synthesize.
467
   */
468
  void assertSygusInvConstraint(Node inv, Node pre, Node trans, Node post);
469
  /**
470
   * Assert a synthesis conjecture to the current context and call
471
   * check().  Returns sat, unsat, or unknown result.
472
   *
473
   * The actual synthesis conjecture is built based on the previously
474
   * communicated information to this module (universal variables, defined
475
   * functions, functions-to-synthesize, and which constraints compose it). The
476
   * built conjecture is a higher-order formula of the form
477
   *
478
   * exists f1...fn . forall v1...vm . F
479
   *
480
   * in which f1...fn are the functions-to-synthesize, v1...vm are the declared
481
   * universal variables and F is the set of declared constraints.
482
   *
483
   * @throw Exception
484
   */
485
  Result checkSynth();
486
487
  /*------------------------- end of sygus commands ------------------------*/
488
489
  /**
490
   * Declare pool whose initial value is the terms in initValue. A pool is
491
   * a variable of type (Set T) that is used in quantifier annotations and does
492
   * not occur in constraints.
493
   *
494
   * @param p The pool to declare, which should be a variable of type (Set T)
495
   * for some type T.
496
   * @param initValue The initial value of p, which should be a vector of terms
497
   * of type T.
498
   */
499
  void declarePool(const Node& p, const std::vector<Node>& initValue);
500
  /**
501
   * Simplify a formula without doing "much" work.  Does not involve
502
   * the SAT Engine in the simplification, but uses the current
503
   * definitions, assertions, and the current partial model, if one
504
   * has been constructed.  It also involves theory normalization.
505
   *
506
   * @throw TypeCheckingException, LogicException, UnsafeInterruptException
507
   *
508
   * @todo (design) is this meant to give an equivalent or an
509
   * equisatisfiable formula?
510
   */
511
  Node simplify(const Node& e);
512
513
  /**
514
   * Expand the definitions in a term or formula.
515
   *
516
   * @param n The node to expand
517
   *
518
   * @throw TypeCheckingException, LogicException, UnsafeInterruptException
519
   */
520
  Node expandDefinitions(const Node& n);
521
522
  /**
523
   * Get the assigned value of an expr (only if immediately preceded by a SAT
524
   * or NOT_ENTAILED query).  Only permitted if the SmtEngine is set to operate
525
   * interactively and produce-models is on.
526
   *
527
   * @throw ModalException, TypeCheckingException, LogicException,
528
   *        UnsafeInterruptException
529
   */
530
  Node getValue(const Node& e) const;
531
532
  /**
533
   * Same as getValue but for a vector of expressions
534
   */
535
  std::vector<Node> getValues(const std::vector<Node>& exprs);
536
537
  /** print instantiations
538
   *
539
   * Print all instantiations for all quantified formulas on out,
540
   * returns true if at least one instantiation was printed. The type of output
541
   * (list, num, etc.) is determined by printInstMode.
542
   */
543
  void printInstantiations(std::ostream& out);
544
  /**
545
   * Print the current proof. This method should be called after an UNSAT
546
   * response. It gets the proof of false from the PropEngine and passes
547
   * it to the ProofManager, which post-processes the proof and prints it
548
   * in the proper format.
549
   */
550
  void printProof();
551
552
  /**
553
   * Get synth solution.
554
   *
555
   * This method returns true if we are in a state immediately preceded by
556
   * a successful call to checkSynth.
557
   *
558
   * This method adds entries to solMap that map functions-to-synthesize with
559
   * their solutions, for all active conjectures. This should be called
560
   * immediately after the solver answers unsat for sygus input.
561
   *
562
   * Specifically, given a sygus conjecture of the form
563
   *   exists x1...xn. forall y1...yn. P( x1...xn, y1...yn )
564
   * where x1...xn are second order bound variables, we map each xi to
565
   * lambda term in solMap such that
566
   *    forall y1...yn. P( solMap[x1]...solMap[xn], y1...yn )
567
   * is a valid formula.
568
   */
569
  bool getSynthSolutions(std::map<Node, Node>& solMap);
570
571
  /**
572
   * Do quantifier elimination.
573
   *
574
   * This function takes as input a quantified formula q
575
   * of the form:
576
   *   Q x1...xn. P( x1...xn, y1...yn )
577
   * where P( x1...xn, y1...yn ) is a quantifier-free
578
   * formula in a logic that supports quantifier elimination.
579
   * Currently, the only logics supported by quantifier
580
   * elimination is LRA and LIA.
581
   *
582
   * This function returns a formula ret such that, given
583
   * the current set of formulas A asserted to this SmtEngine :
584
   *
585
   * If doFull = true, then
586
   *   - ( A ^ q ) and ( A ^ ret ) are equivalent
587
   *   - ret is quantifier-free formula containing
588
   *     only free variables in y1...yn.
589
   *
590
   * If doFull = false, then
591
   *   - (A ^ q) => (A ^ ret) if Q is forall or
592
   *     (A ^ ret) => (A ^ q) if Q is exists,
593
   *   - ret is quantifier-free formula containing
594
   *     only free variables in y1...yn,
595
   *   - If Q is exists, let A^Q_n be the formula
596
   *       A ^ ~ret^Q_1 ^ ... ^ ~ret^Q_n
597
   *     where for each i=1,...n, formula ret^Q_i
598
   *     is the result of calling doQuantifierElimination
599
   *     for q with the set of assertions A^Q_{i-1}.
600
   *     Similarly, if Q is forall, then let A^Q_n be
601
   *       A ^ ret^Q_1 ^ ... ^ ret^Q_n
602
   *     where ret^Q_i is the same as above.
603
   *     In either case, we have that ret^Q_j will
604
   *     eventually be true or false, for some finite j.
605
   *
606
   * The former feature is quantifier elimination, and
607
   * is run on invocations of the smt2 extended command get-qe.
608
   * The latter feature is referred to as partial quantifier
609
   * elimination, and is run on invocations of the smt2
610
   * extended command get-qe-disjunct, which can be used
611
   * for incrementally computing the result of a
612
   * quantifier elimination.
613
   *
614
   * The argument strict is whether to output
615
   * warnings, such as when an unexpected logic is used.
616
   *
617
   * throw@ Exception
618
   */
619
  Node getQuantifierElimination(Node q, bool doFull, bool strict = true);
620
621
  /**
622
   * This method asks this SMT engine to find an interpolant with respect to
623
   * the current assertion stack (call it A) and the conjecture (call it B). If
624
   * this method returns true, then interpolant is set to a formula I such that
625
   * A ^ ~I and I ^ ~B are both unsatisfiable.
626
   *
627
   * The argument grammarType is a sygus datatype type that encodes the syntax
628
   * restrictions on the shapes of possible solutions.
629
   *
630
   * This method invokes a separate copy of the SMT engine for solving the
631
   * corresponding sygus problem for generating such a solution.
632
   */
633
  bool getInterpol(const Node& conj,
634
                   const TypeNode& grammarType,
635
                   Node& interpol);
636
637
  /** Same as above, but without user-provided grammar restrictions */
638
  bool getInterpol(const Node& conj, Node& interpol);
639
640
  /**
641
   * This method asks this SMT engine to find an abduct with respect to the
642
   * current assertion stack (call it A) and the conjecture (call it B).
643
   * If this method returns true, then abd is set to a formula C such that
644
   * A ^ C is satisfiable, and A ^ ~B ^ C is unsatisfiable.
645
   *
646
   * The argument grammarType is a sygus datatype type that encodes the syntax
647
   * restrictions on the shape of possible solutions.
648
   *
649
   * This method invokes a separate copy of the SMT engine for solving the
650
   * corresponding sygus problem for generating such a solution.
651
   */
652
  bool getAbduct(const Node& conj, const TypeNode& grammarType, Node& abd);
653
654
  /** Same as above, but without user-provided grammar restrictions */
655
  bool getAbduct(const Node& conj, Node& abd);
656
657
  /**
658
   * Get list of quantified formulas that were instantiated on the last call
659
   * to check-sat.
660
   */
661
  void getInstantiatedQuantifiedFormulas(std::vector<Node>& qs);
662
663
  /**
664
   * Get instantiation term vectors for quantified formula q.
665
   *
666
   * This method is similar to above, but in the example above, we return the
667
   * (vectors of) terms t1, ..., tn instead.
668
   *
669
   * Notice that these are not guaranteed to come in the same order as the
670
   * instantiation lemmas above.
671
   */
672
  void getInstantiationTermVectors(Node q,
673
                                   std::vector<std::vector<Node>>& tvecs);
674
  /**
675
   * As above but only the instantiations that were relevant for the
676
   * refutation.
677
   */
678
  void getRelevantInstantiationTermVectors(
679
      std::map<Node, InstantiationList>& insts, bool getDebugInfo = false);
680
  /**
681
   * Get instantiation term vectors, which maps each instantiated quantified
682
   * formula to the list of instantiations for that quantified formula. This
683
   * list is minimized if proofs are enabled, and this call is immediately
684
   * preceded by an UNSAT or ENTAILED query
685
   */
686
  void getInstantiationTermVectors(
687
      std::map<Node, std::vector<std::vector<Node>>>& insts);
688
689
  /**
690
   * Get an unsatisfiable core (only if immediately preceded by an UNSAT or
691
   * ENTAILED query).  Only permitted if cvc5 was built with unsat-core support
692
   * and produce-unsat-cores is on.
693
   */
694
  UnsatCore getUnsatCore();
695
696
  /**
697
   * Get a refutation proof (only if immediately preceded by an UNSAT or
698
   * ENTAILED query). Only permitted if cvc5 was built with proof support and
699
   * the proof option is on. */
700
  std::string getProof();
701
702
  /**
703
   * Get the current set of assertions.  Only permitted if the
704
   * SmtEngine is set to operate interactively.
705
   */
706
  std::vector<Node> getAssertions();
707
708
  /**
709
   * Push a user-level context.
710
   * throw@ ModalException, LogicException, UnsafeInterruptException
711
   */
712
  void push();
713
714
  /**
715
   * Pop a user-level context.  Throws an exception if nothing to pop.
716
   * @throw ModalException
717
   */
718
  void pop();
719
720
  /** Reset all assertions, global declarations, etc.  */
721
  void resetAssertions();
722
723
  /**
724
   * Interrupt a running query.  This can be called from another thread
725
   * or from a signal handler.  Throws a ModalException if the SmtEngine
726
   * isn't currently in a query.
727
   *
728
   * @throw ModalException
729
   */
730
  void interrupt();
731
732
  /**
733
   * Set a resource limit for SmtEngine operations.  This is like a time
734
   * limit, but it's deterministic so that reproducible results can be
735
   * obtained.  Currently, it's based on the number of conflicts.
736
   * However, please note that the definition may change between different
737
   * versions of cvc5 (as may the number of conflicts required, anyway),
738
   * and it might even be different between instances of the same version
739
   * of cvc5 on different platforms.
740
   *
741
   * A cumulative and non-cumulative (per-call) resource limit can be
742
   * set at the same time.  A call to setResourceLimit() with
743
   * cumulative==true replaces any cumulative resource limit currently
744
   * in effect; a call with cumulative==false replaces any per-call
745
   * resource limit currently in effect.  Time limits can be set in
746
   * addition to resource limits; the SmtEngine obeys both.  That means
747
   * that up to four independent limits can control the SmtEngine
748
   * at the same time.
749
   *
750
   * When an SmtEngine is first created, it has no time or resource
751
   * limits.
752
   *
753
   * Currently, these limits only cause the SmtEngine to stop what its
754
   * doing when the limit expires (or very shortly thereafter); no
755
   * heuristics are altered by the limits or the threat of them expiring.
756
   * We reserve the right to change this in the future.
757
   *
758
   * @param units the resource limit, or 0 for no limit
759
   * @param cumulative whether this resource limit is to be a cumulative
760
   * resource limit for all remaining calls into the SmtEngine (true), or
761
   * whether it's a per-call resource limit (false); the default is false
762
   */
763
  void setResourceLimit(uint64_t units, bool cumulative = false);
764
765
  /**
766
   * Set a per-call time limit for SmtEngine operations.
767
   *
768
   * A per-call time limit can be set at the same time and replaces
769
   * any per-call time limit currently in effect.
770
   * Resource limits (either per-call or cumulative) can be set in
771
   * addition to a time limit; the SmtEngine obeys all three of them.
772
   *
773
   * Note that the per-call timer only ticks away when one of the
774
   * SmtEngine's workhorse functions (things like assertFormula(),
775
   * checkEntailed(), checkSat(), and simplify()) are running.
776
   * Between calls, the timer is still.
777
   *
778
   * When an SmtEngine is first created, it has no time or resource
779
   * limits.
780
   *
781
   * Currently, these limits only cause the SmtEngine to stop what its
782
   * doing when the limit expires (or very shortly thereafter); no
783
   * heuristics are altered by the limits or the threat of them expiring.
784
   * We reserve the right to change this in the future.
785
   *
786
   * @param millis the time limit in milliseconds, or 0 for no limit
787
   */
788
  void setTimeLimit(uint64_t millis);
789
790
  /**
791
   * Get the current resource usage count for this SmtEngine.  This
792
   * function can be used to ascertain reasonable values to pass as
793
   * resource limits to setResourceLimit().
794
   */
795
  unsigned long getResourceUsage() const;
796
797
  /** Get the current millisecond count for this SmtEngine.  */
798
  unsigned long getTimeUsage() const;
799
800
  /**
801
   * Get the remaining resources that can be consumed by this SmtEngine
802
   * according to the currently-set cumulative resource limit.  If there
803
   * is not a cumulative resource limit set, this function throws a
804
   * ModalException.
805
   *
806
   * @throw ModalException
807
   */
808
  unsigned long getResourceRemaining() const;
809
810
  /** Permit access to the underlying NodeManager. */
811
  NodeManager* getNodeManager() const;
812
813
  /**
814
   * Print statistics from the statistics registry in the env object owned by
815
   * this SmtEngine. Safe to use in a signal handler.
816
   */
817
  void printStatisticsSafe(int fd) const;
818
819
  /**
820
   * Print the changes to the statistics from the statistics registry in the
821
   * env object owned by this SmtEngine since this method was called the last
822
   * time. Internally prints the diff and then stores a snapshot for the next
823
   * call.
824
   */
825
  void printStatisticsDiff() const;
826
827
  /**
828
   * Set user attribute.
829
   * This function is called when an attribute is set by a user.
830
   * In SMT-LIBv2 this is done via the syntax (! expr :attr)
831
   */
832
  void setUserAttribute(const std::string& attr,
833
                        Node expr,
834
                        const std::vector<Node>& expr_values,
835
                        const std::string& str_value);
836
837
  /** Get the options object (const and non-const versions) */
838
  Options& getOptions();
839
  const Options& getOptions() const;
840
841
  /** Get a pointer to the UserContext owned by this SmtEngine. */
842
  context::UserContext* getUserContext();
843
844
  /** Get a pointer to the Context owned by this SmtEngine. */
845
  context::Context* getContext();
846
847
  /** Get a pointer to the TheoryEngine owned by this SmtEngine. */
848
  TheoryEngine* getTheoryEngine();
849
850
  /** Get a pointer to the PropEngine owned by this SmtEngine. */
851
  prop::PropEngine* getPropEngine();
852
853
  /** Get the resource manager of this SMT engine */
854
  ResourceManager* getResourceManager() const;
855
856
  /** Permit access to the underlying dump manager. */
857
  smt::DumpManager* getDumpManager();
858
859
  /** Get the printer used by this SMT engine */
860
  const Printer& getPrinter() const;
861
862
  /** Get the output manager for this SMT engine */
863
  OutputManager& getOutputManager();
864
865
  /** Get a pointer to the Rewriter owned by this SmtEngine. */
866
  theory::Rewriter* getRewriter();
867
  /**
868
   * Get expanded assertions.
869
   *
870
   * Return the set of assertions, after expanding definitions.
871
   */
872
  std::vector<Node> getExpandedAssertions();
873
874
  /**
875
   * !!!!! temporary, until the environment is passsed to all classes that
876
   * require it.
877
   */
878
  Env& getEnv();
879
  /* .......................................................................  */
880
 private:
881
  /* .......................................................................  */
882
883
  // disallow copy/assignment
884
  SmtEngine(const SmtEngine&) = delete;
885
  SmtEngine& operator=(const SmtEngine&) = delete;
886
887
  /** Set solver instance that owns this SmtEngine. */
888
6878
  void setSolver(api::Solver* solver) { d_solver = solver; }
889
890
  /** Get a pointer to the (new) PfManager owned by this SmtEngine. */
891
  smt::PfManager* getPfManager() { return d_pfManager.get(); };
892
893
  /** Get a pointer to the StatisticsRegistry owned by this SmtEngine. */
894
  StatisticsRegistry& getStatisticsRegistry();
895
896
  /**
897
   * Internal method to get an unsatisfiable core (only if immediately preceded
898
   * by an UNSAT or ENTAILED query). Only permitted if cvc5 was built with
899
   * unsat-core support and produce-unsat-cores is on. Does not dump the
900
   * command.
901
   */
902
  UnsatCore getUnsatCoreInternal();
903
904
  /**
905
   * Check that a generated proof checks. This method is the same as printProof,
906
   * but does not print the proof. Like that method, it should be called
907
   * after an UNSAT response. It ensures that a well-formed proof of false
908
   * can be constructed by the combination of the PropEngine and ProofManager.
909
   */
910
  void checkProof();
911
912
  /**
913
   * Check that an unsatisfiable core is indeed unsatisfiable.
914
   */
915
  void checkUnsatCore();
916
917
  /**
918
   * Check that a generated Model (via getModel()) actually satisfies
919
   * all user assertions.
920
   */
921
  void checkModel(bool hardFailure = true);
922
923
  /**
924
   * Check that a solution to an interpolation problem is indeed a solution.
925
   *
926
   * The check is made by determining that the assertions imply the solution of
927
   * the interpolation problem (interpol), and the solution implies the goal
928
   * (conj). If these criteria are not met, an internal error is thrown.
929
   */
930
  void checkInterpol(Node interpol,
931
                     const std::vector<Node>& easserts,
932
                     const Node& conj);
933
934
  /**
935
   * This is called by the destructor, just before destroying the
936
   * PropEngine, TheoryEngine, and DecisionEngine (in that order).  It
937
   * is important because there are destruction ordering issues
938
   * between PropEngine and Theory.
939
   */
940
  void shutdown();
941
942
  /**
943
   * Quick check of consistency in current context: calls
944
   * processAssertionList() then look for inconsistency (based only on
945
   * that).
946
   */
947
  Result quickCheck();
948
949
  /**
950
   * Get the (SMT-level) model pointer, if we are in SAT mode. Otherwise,
951
   * return nullptr.
952
   *
953
   * This ensures that the underlying theory model of the SmtSolver maintained
954
   * by this class is currently available, which means that cvc5 is producing
955
   * models, and is in "SAT mode", otherwise a recoverable exception is thrown.
956
   *
957
   * @param c used for giving an error message to indicate the context
958
   * this method was called.
959
   */
960
  smt::Model* getAvailableModel(const char* c) const;
961
  /**
962
   * Get available quantifiers engine, which throws a modal exception if it
963
   * does not exist. This can happen if a quantifiers-specific call (e.g.
964
   * getInstantiatedQuantifiedFormulas) is called in a non-quantified logic.
965
   *
966
   * @param c used for giving an error message to indicate the context
967
   * this method was called.
968
   */
969
  theory::QuantifiersEngine* getAvailableQuantifiersEngine(const char* c) const;
970
971
  // --------------------------------------- callbacks from the state
972
  /**
973
   * Notify push pre, which is called just before the user context of the state
974
   * pushes. This processes all pending assertions.
975
   */
976
  void notifyPushPre();
977
  /**
978
   * Notify push post, which is called just after the user context of the state
979
   * pushes. This performs a push on the underlying prop engine.
980
   */
981
  void notifyPushPost();
982
  /**
983
   * Notify pop pre, which is called just before the user context of the state
984
   * pops. This performs a pop on the underlying prop engine.
985
   */
986
  void notifyPopPre();
987
  /**
988
   * Notify post solve pre, which is called once per check-sat query. It
989
   * is triggered when the first d_state.doPendingPops() is issued after the
990
   * check-sat. This method is called before the contexts pop in the method
991
   * doPendingPops.
992
   */
993
  void notifyPostSolvePre();
994
  /**
995
   * Same as above, but after contexts are popped. This calls the postsolve
996
   * method of the underlying TheoryEngine.
997
   */
998
  void notifyPostSolvePost();
999
  // --------------------------------------- end callbacks from the state
1000
1001
  /**
1002
   * Internally handle the setting of a logic.  This function should always
1003
   * be called when d_logic is updated.
1004
   */
1005
  void setLogicInternal();
1006
1007
  /*
1008
   * Check satisfiability (used to check satisfiability and entailment).
1009
   */
1010
  Result checkSatInternal(const std::vector<Node>& assumptions,
1011
                          bool isEntailmentCheck);
1012
1013
  /**
1014
   * Check that all Expr in formals are of BOUND_VARIABLE kind, where func is
1015
   * the function that the formal argument list is for. This method is used
1016
   * as a helper function when defining (recursive) functions.
1017
   */
1018
  void debugCheckFormals(const std::vector<Node>& formals, Node func);
1019
1020
  /**
1021
   * Checks whether formula is a valid function body for func whose formal
1022
   * argument list is stored in formals. This method is
1023
   * used as a helper function when defining (recursive) functions.
1024
   */
1025
  void debugCheckFunctionBody(Node formula,
1026
                              const std::vector<Node>& formals,
1027
                              Node func);
1028
1029
  /**
1030
   * Helper method to obtain both the heap and nil from the solver. Returns a
1031
   * std::pair where the first element is the heap expression and the second
1032
   * element is the nil expression.
1033
   */
1034
  std::pair<Node, Node> getSepHeapAndNilExpr();
1035
1036
  /* Members -------------------------------------------------------------- */
1037
1038
  /** Solver instance that owns this SmtEngine instance. */
1039
  api::Solver* d_solver = nullptr;
1040
1041
  /**
1042
   * The environment object, which contains all utilities that are globally
1043
   * available to internal code.
1044
   */
1045
  std::unique_ptr<Env> d_env;
1046
  /**
1047
   * The state of this SmtEngine, which is responsible for maintaining which
1048
   * SMT mode we are in, the contexts, the last result, etc.
1049
   */
1050
  std::unique_ptr<smt::SmtEngineState> d_state;
1051
1052
  /** Abstract values */
1053
  std::unique_ptr<smt::AbstractValues> d_absValues;
1054
  /** Assertions manager */
1055
  std::unique_ptr<smt::Assertions> d_asserts;
1056
  /** Resource out listener */
1057
  std::unique_ptr<smt::ResourceOutListener> d_routListener;
1058
  /** Node manager listener */
1059
  std::unique_ptr<smt::SmtNodeManagerListener> d_snmListener;
1060
1061
  /** The SMT solver */
1062
  std::unique_ptr<smt::SmtSolver> d_smtSolver;
1063
1064
  /**
1065
   * The SMT-level model object, which contains information about how to
1066
   * print the model, as well as a pointer to the underlying TheoryModel
1067
   * implementation maintained by the SmtSolver.
1068
   */
1069
  std::unique_ptr<smt::Model> d_model;
1070
1071
  /**
1072
   * The utility used for checking models
1073
   */
1074
  std::unique_ptr<smt::CheckModels> d_checkModels;
1075
1076
  /**
1077
   * The proof manager, which manages all things related to checking,
1078
   * processing, and printing proofs.
1079
   */
1080
  std::unique_ptr<smt::PfManager> d_pfManager;
1081
1082
  /**
1083
   * The unsat core manager, which produces unsat cores and related information
1084
   * from refutations. */
1085
  std::unique_ptr<smt::UnsatCoreManager> d_ucManager;
1086
1087
  /** The solver for sygus queries */
1088
  std::unique_ptr<smt::SygusSolver> d_sygusSolver;
1089
1090
  /** The solver for abduction queries */
1091
  std::unique_ptr<smt::AbductionSolver> d_abductSolver;
1092
  /** The solver for interpolation queries */
1093
  std::unique_ptr<smt::InterpolationSolver> d_interpolSolver;
1094
  /** The solver for quantifier elimination queries */
1095
  std::unique_ptr<smt::QuantElimSolver> d_quantElimSolver;
1096
1097
  /**
1098
   * The logic set by the user. The actual logic, which may extend the user's
1099
   * logic, lives in the Env class.
1100
   */
1101
  LogicInfo d_userLogic;
1102
1103
  /** Whether this is an internal subsolver. */
1104
  bool d_isInternalSubsolver;
1105
1106
  /**
1107
   * Verbosity of various commands.
1108
   */
1109
  std::map<std::string, int> d_commandVerbosity;
1110
1111
  /** The statistics class */
1112
  std::unique_ptr<smt::SmtEngineStatistics> d_stats;
1113
1114
  /** the output manager for commands */
1115
  mutable OutputManager d_outMgr;
1116
  /**
1117
   * The preprocessor.
1118
   */
1119
  std::unique_ptr<smt::Preprocessor> d_pp;
1120
  /**
1121
   * The global scope object. Upon creation of this SmtEngine, it becomes the
1122
   * SmtEngine in scope. It says the SmtEngine in scope until it is destructed,
1123
   * or another SmtEngine is created.
1124
   */
1125
  std::unique_ptr<smt::SmtScope> d_scope;
1126
}; /* class SmtEngine */
1127
1128
/* -------------------------------------------------------------------------- */
1129
1130
}  // namespace cvc5
1131
1132
#endif /* CVC5__SMT_ENGINE_H */