GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/sygus/sygus_module.h Lines: 2 5 40.0 %
Date: 2021-09-07 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner, Andres Noetzli
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
 * sygus_module
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__QUANTIFIERS__SYGUS_MODULE_H
19
#define CVC5__THEORY__QUANTIFIERS__SYGUS_MODULE_H
20
21
#include <vector>
22
23
#include "expr/node.h"
24
#include "smt/env_obj.h"
25
26
namespace cvc5 {
27
namespace theory {
28
namespace quantifiers {
29
30
class SynthConjecture;
31
class TermDbSygus;
32
class QuantifiersState;
33
class QuantifiersInferenceManager;
34
35
/** SygusModule
36
 *
37
 * This is the base class of sygus modules, owned by SynthConjecture. The
38
 * purpose of this class is to, when applicable, suggest candidate solutions for
39
 * SynthConjecture to test.
40
 *
41
 * In more detail, an instance of the conjecture class (SynthConjecture) creates
42
 * the negated deep embedding form of the synthesis conjecture. In the
43
 * following, assume this is:
44
 *   forall d. exists x. P( d, x )
45
 * where d are of sygus datatype type. The "base instantiation" of this
46
 * conjecture (see SynthConjecture::d_base_inst) is the formula:
47
 *   exists y. P( k, y )
48
 * where k are the "candidate" variables for the conjecture.
49
 *
50
 * Modules implement an initialize function, which determines whether the module
51
 * will take responsibility for the given conjecture.
52
 */
53
class SygusModule : protected EnvObj
54
{
55
 public:
56
  SygusModule(QuantifiersState& qs,
57
              QuantifiersInferenceManager& qim,
58
              TermDbSygus* tds,
59
              SynthConjecture* p);
60
4756
  virtual ~SygusModule() {}
61
  /** initialize
62
   *
63
   * This function initializes the module for solving the given conjecture. This
64
   * typically involves registering enumerators (for constructing terms) via
65
   * calls to TermDbSygus::registerEnumerator.
66
   *
67
   * This function returns true if this module will take responsibility for
68
   * constructing candidates for the given conjecture.
69
   *
70
   * conj is the synthesis conjecture (prior to deep-embedding).
71
   *
72
   * n is the "base instantiation" of the deep-embedding version of the
73
   * synthesis conjecture under candidates (see SynthConjecture::d_base_inst).
74
   *
75
   * This function may also sends lemmas during this call via the quantifiers
76
   * inference manager. Note that lemmas should be sent immediately via
77
   * d_qim.lemma in this call. This is in contrast to other methods which
78
   * add pending lemmas to d_qim.
79
   */
80
  virtual bool initialize(Node conj,
81
                          Node n,
82
                          const std::vector<Node>& candidates) = 0;
83
  /** get term list
84
   *
85
   * This gets the list of terms that will appear as arguments to a subsequent
86
   * call to constructCandidates.
87
   */
88
  virtual void getTermList(const std::vector<Node>& candidates,
89
                           std::vector<Node>& terms) = 0;
90
  /** allow partial model
91
   *
92
   * This method returns true if this module does not require that all
93
   * terms returned by getTermList have "proper" model values when calling
94
   * constructCandidates. A term may have a model value that is not proper
95
   * if is excluded by symmetry breaking, e.g. x+0 is not proper. All model
96
   * values that are not proper are replaced by "null" when calling
97
   * constructCandidates.
98
   */
99
35264
  virtual bool allowPartialModel() { return false; }
100
  /** construct candidate
101
   *
102
   * This function takes as input:
103
   *   terms : (a subset of) the terms returned by a call to getTermList,
104
   *   term_values : the current model values of terms,
105
   *   candidates : the list of candidates.
106
   *
107
   * In particular, notice that terms do not include inactive enumerators,
108
   * thus if inactive enumerators were added to getTermList, then the terms
109
   * list passed to this call will be a (strict) subset of that list.
110
   *
111
   * If this function returns true, it adds to candidate_values a list of terms
112
   * of the same length and type as candidates that are candidate solutions
113
   * to the synthesis conjecture in question. This candidate { v } will then be
114
   * tested by testing the (un)satisfiablity of P( v, cex ) for fresh cex by the
115
   * caller.
116
   *
117
   * This function may also add pending lemmas during this call via the
118
   * quantifiers inference manager d_qim. For an example of such lemmas, see
119
   * SygusPbe::constructCandidates..
120
   *
121
   * This function may return false if it does not have a candidate it wants
122
   * to test on this iteration. In this case, the module should have sent
123
   * lemmas.
124
   */
125
  virtual bool constructCandidates(const std::vector<Node>& terms,
126
                                   const std::vector<Node>& term_values,
127
                                   const std::vector<Node>& candidates,
128
                                   std::vector<Node>& candidate_values) = 0;
129
  /** register refinement lemma
130
   *
131
   * Assume this module, on a previous call to constructCandidates, added the
132
   * value { v } to candidate_values for candidates = { k }. This function is
133
   * called if the base instantiation of the synthesis conjecture has a model
134
   * under this substitution. In particular, in the above example, this function
135
   * is called when the refinement lemma P( v, cex ) has a model M. In calls to
136
   * this function, the argument vars is cex and lem is P( k, cex^M ).
137
   *
138
   * This function may also add pending lemmas during this call via the
139
   * quantifiers inference manager d_qim. For an example of such lemmas, see
140
   * Cegis::registerRefinementLemma.
141
   */
142
  virtual void registerRefinementLemma(const std::vector<Node>& vars, Node lem)
143
  {
144
  }
145
  /**
146
   * Are we trying to repair constants in candidate solutions?
147
   * If we return true for usingRepairConst is true, then this module has
148
   * attmepted to repair any solutions returned by constructCandidates.
149
   */
150
  virtual bool usingRepairConst() { return false; }
151
152
 protected:
153
  /** Reference to the state of the quantifiers engine */
154
  QuantifiersState& d_qstate;
155
  /** Reference to the quantifiers inference manager */
156
  QuantifiersInferenceManager& d_qim;
157
  /** sygus term database of d_qe */
158
  TermDbSygus* d_tds;
159
  /** reference to the parent conjecture */
160
  SynthConjecture* d_parent;
161
};
162
163
}  // namespace quantifiers
164
}  // namespace theory
165
}  // namespace cvc5
166
167
#endif /* CVC5__THEORY__QUANTIFIERS__SYGUS_MODULE_H */