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