GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/sygus/sygus_module.h Lines: 2 5 40.0 %
Date: 2021-09-18 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(Env& env,
57
              QuantifiersState& qs,
58
              QuantifiersInferenceManager& qim,
59
              TermDbSygus* tds,
60
              SynthConjecture* p);
61
4924
  virtual ~SygusModule() {}
62
  /** initialize
63
   *
64
   * This function initializes the module for solving the given conjecture. This
65
   * typically involves registering enumerators (for constructing terms) via
66
   * calls to TermDbSygus::registerEnumerator.
67
   *
68
   * This function returns true if this module will take responsibility for
69
   * constructing candidates for the given conjecture.
70
   *
71
   * conj is the synthesis conjecture (prior to deep-embedding).
72
   *
73
   * n is the "base instantiation" of the deep-embedding version of the
74
   * synthesis conjecture under candidates (see SynthConjecture::d_base_inst).
75
   *
76
   * This function may also sends lemmas during this call via the quantifiers
77
   * inference manager. Note that lemmas should be sent immediately via
78
   * d_qim.lemma in this call. This is in contrast to other methods which
79
   * add pending lemmas to d_qim.
80
   */
81
  virtual bool initialize(Node conj,
82
                          Node n,
83
                          const std::vector<Node>& candidates) = 0;
84
  /** get term list
85
   *
86
   * This gets the list of terms that will appear as arguments to a subsequent
87
   * call to constructCandidates.
88
   */
89
  virtual void getTermList(const std::vector<Node>& candidates,
90
                           std::vector<Node>& terms) = 0;
91
  /** allow partial model
92
   *
93
   * This method returns true if this module does not require that all
94
   * terms returned by getTermList have "proper" model values when calling
95
   * constructCandidates. A term may have a model value that is not proper
96
   * if is excluded by symmetry breaking, e.g. x+0 is not proper. All model
97
   * values that are not proper are replaced by "null" when calling
98
   * constructCandidates.
99
   */
100
34983
  virtual bool allowPartialModel() { return false; }
101
  /** construct candidate
102
   *
103
   * This function takes as input:
104
   *   terms : (a subset of) the terms returned by a call to getTermList,
105
   *   term_values : the current model values of terms,
106
   *   candidates : the list of candidates.
107
   *
108
   * In particular, notice that terms do not include inactive enumerators,
109
   * thus if inactive enumerators were added to getTermList, then the terms
110
   * list passed to this call will be a (strict) subset of that list.
111
   *
112
   * If this function returns true, it adds to candidate_values a list of terms
113
   * of the same length and type as candidates that are candidate solutions
114
   * to the synthesis conjecture in question. This candidate { v } will then be
115
   * tested by testing the (un)satisfiablity of P( v, cex ) for fresh cex by the
116
   * caller.
117
   *
118
   * This function may also add pending lemmas during this call via the
119
   * quantifiers inference manager d_qim. For an example of such lemmas, see
120
   * SygusPbe::constructCandidates..
121
   *
122
   * This function may return false if it does not have a candidate it wants
123
   * to test on this iteration. In this case, the module should have sent
124
   * lemmas.
125
   */
126
  virtual bool constructCandidates(const std::vector<Node>& terms,
127
                                   const std::vector<Node>& term_values,
128
                                   const std::vector<Node>& candidates,
129
                                   std::vector<Node>& candidate_values) = 0;
130
  /** register refinement lemma
131
   *
132
   * Assume this module, on a previous call to constructCandidates, added the
133
   * value { v } to candidate_values for candidates = { k }. This function is
134
   * called if the base instantiation of the synthesis conjecture has a model
135
   * under this substitution. In particular, in the above example, this function
136
   * is called when the refinement lemma P( v, cex ) has a model M. In calls to
137
   * this function, the argument vars is cex and lem is P( k, cex^M ).
138
   *
139
   * This function may also add pending lemmas during this call via the
140
   * quantifiers inference manager d_qim. For an example of such lemmas, see
141
   * Cegis::registerRefinementLemma.
142
   */
143
  virtual void registerRefinementLemma(const std::vector<Node>& vars, Node lem)
144
  {
145
  }
146
  /**
147
   * Are we trying to repair constants in candidate solutions?
148
   * If we return true for usingRepairConst is true, then this module has
149
   * attmepted to repair any solutions returned by constructCandidates.
150
   */
151
  virtual bool usingRepairConst() { return false; }
152
153
 protected:
154
  /** Reference to the state of the quantifiers engine */
155
  QuantifiersState& d_qstate;
156
  /** Reference to the quantifiers inference manager */
157
  QuantifiersInferenceManager& d_qim;
158
  /** sygus term database of d_qe */
159
  TermDbSygus* d_tds;
160
  /** reference to the parent conjecture */
161
  SynthConjecture* d_parent;
162
};
163
164
}  // namespace quantifiers
165
}  // namespace theory
166
}  // namespace cvc5
167
168
#endif /* CVC5__THEORY__QUANTIFIERS__SYGUS_MODULE_H */