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