1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Tim King, Abdalrhman Mohamed |
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 |
|
* Utility for processing single invocation synthesis conjectures. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__QUANTIFIERS__CE_GUIDED_SINGLE_INV_H |
19 |
|
#define CVC5__THEORY__QUANTIFIERS__CE_GUIDED_SINGLE_INV_H |
20 |
|
|
21 |
|
#include "context/cdlist.h" |
22 |
|
#include "expr/subs.h" |
23 |
|
#include "smt/env_obj.h" |
24 |
|
#include "theory/quantifiers/cegqi/inst_strategy_cegqi.h" |
25 |
|
#include "theory/quantifiers/inst_match_trie.h" |
26 |
|
#include "theory/quantifiers/single_inv_partition.h" |
27 |
|
#include "theory/quantifiers/sygus/sygus_stats.h" |
28 |
|
|
29 |
|
namespace cvc5 { |
30 |
|
namespace theory { |
31 |
|
namespace quantifiers { |
32 |
|
|
33 |
|
class SynthConjecture; |
34 |
|
class SygusReconstruct; |
35 |
|
|
36 |
|
// this class infers whether a conjecture is single invocation (Reynolds et al CAV 2015), and sets up the |
37 |
|
// counterexample-guided quantifier instantiation utility (d_cinst), and methods for solution |
38 |
|
// reconstruction (d_sol). |
39 |
|
// It also has more advanced techniques for: |
40 |
|
// (1) partitioning a conjecture into single invocation / non-single invocation portions for invariant synthesis, |
41 |
|
// (2) inferring whether the conjecture corresponds to a deterministic transistion system (by utility d_ti). |
42 |
|
// For these techniques, we may generate a template (d_templ) which specifies a restricted |
43 |
|
// solution space. We may in turn embed this template as a SyGuS grammar. |
44 |
|
class CegSingleInv : protected EnvObj |
45 |
|
{ |
46 |
|
public: |
47 |
|
CegSingleInv(Env& env, TermRegistry& tr, SygusStatistics& s); |
48 |
|
~CegSingleInv(); |
49 |
|
|
50 |
|
/** Get simplified conjecture. */ |
51 |
542 |
Node getSimplifiedConjecture() { return d_simp_quant; } |
52 |
|
/** initialize this class for synthesis conjecture q */ |
53 |
|
void initialize( Node q ); |
54 |
|
/** finish initialize |
55 |
|
* |
56 |
|
* This method sets up final decisions about whether to use single invocation |
57 |
|
* techniques. |
58 |
|
* |
59 |
|
* The argument syntaxRestricted is whether the syntax for solutions for the |
60 |
|
* initialized conjecture is restricted. |
61 |
|
*/ |
62 |
|
void finishInit(bool syntaxRestricted); |
63 |
|
/** solve |
64 |
|
* |
65 |
|
* If single invocation techniques are being used, it solves |
66 |
|
* the first order form of the negated synthesis conjecture using a fresh |
67 |
|
* copy of the SMT engine. This method returns true if it has successfully |
68 |
|
* found a solution to the synthesis conjecture using this method. |
69 |
|
*/ |
70 |
|
bool solve(); |
71 |
|
/** |
72 |
|
* Get solution for the sol_index^th function to synthesize of the conjecture |
73 |
|
* this class was assigned. |
74 |
|
* |
75 |
|
* @param sol_index The index of the function to synthesize |
76 |
|
* @param stn The sygus type of the solution, which corresponds to syntactic |
77 |
|
* restrictions |
78 |
|
* @param reconstructed Set to the status of reconstructing the solution, |
79 |
|
* where 1 = success, 0 = no reconstruction specified, -1 = failed |
80 |
|
* @param rconsSygus Whether to apply sygus reconstruction techniques based |
81 |
|
* on the underlying reconstruction module. If this is false, then the |
82 |
|
* solution does not necessarily fit the grammar. |
83 |
|
* @return the solution for the sol_index^th function to synthesize of the |
84 |
|
* conjecture assigned to this class. |
85 |
|
*/ |
86 |
|
Node getSolution(size_t sol_index, |
87 |
|
TypeNode stn, |
88 |
|
int8_t& reconstructed, |
89 |
|
bool rconsSygus = true); |
90 |
|
//reconstruct to syntax |
91 |
|
Node reconstructToSyntax(Node s, |
92 |
|
TypeNode stn, |
93 |
|
int8_t& reconstructed, |
94 |
|
bool rconsSygus = true); |
95 |
|
// is single invocation |
96 |
64049 |
bool isSingleInvocation() const { return !d_single_inv.isNull(); } |
97 |
|
/** preregister conjecture */ |
98 |
|
void preregisterConjecture( Node q ); |
99 |
|
|
100 |
|
//---------------------------------representation of the solution |
101 |
|
/** |
102 |
|
* The list of instantiations that suffice to show the first-order equivalent |
103 |
|
* of the negated synthesis conjecture is unsatisfiable. |
104 |
|
*/ |
105 |
|
std::vector<std::vector<Node> > d_inst; |
106 |
|
/** |
107 |
|
* The list of instantiation lemmas, corresponding to instantiations of the |
108 |
|
* first order conjecture for the term vectors above. |
109 |
|
*/ |
110 |
|
std::vector<Node> d_instConds; |
111 |
|
/** The solutions, without reconstruction to syntax */ |
112 |
|
std::vector<Node> d_solutions; |
113 |
|
/** The solutions, after reconstruction to syntax */ |
114 |
|
std::vector<Node> d_rcSolutions; |
115 |
|
/** is solved */ |
116 |
|
bool d_isSolved; |
117 |
|
//---------------------------------end representation of the solution |
118 |
|
|
119 |
|
private: |
120 |
|
// presolve |
121 |
|
void collectPresolveEqTerms(Node n, std::map<Node, std::vector<Node> >& teq); |
122 |
|
void getPresolveEqConjuncts(std::vector<Node>& vars, |
123 |
|
std::vector<Node>& terms, |
124 |
|
std::map<Node, std::vector<Node> >& teq, |
125 |
|
Node n, |
126 |
|
std::vector<Node>& conj); |
127 |
|
/** solve trivial |
128 |
|
* |
129 |
|
* If this method returns true, it sets d_isSolved to true and adds |
130 |
|
* t1 ... tn to d_inst if it can be shown that (forall x1 ... xn. P) is |
131 |
|
* unsatisfiable for instantiation {x1 -> t1 ... xn -> tn}. |
132 |
|
*/ |
133 |
|
bool solveTrivial(Node q); |
134 |
|
/** |
135 |
|
* Get solution from the instantiations stored in this class (d_inst) for |
136 |
|
* the index^th function to synthesize. The vector d_inst should be |
137 |
|
* initialized before calling this method. |
138 |
|
*/ |
139 |
|
Node getSolutionFromInst(size_t index); |
140 |
|
/** |
141 |
|
* Set solution, which sets the d_solutions / d_rcSolutions fields based on |
142 |
|
* calls to the above method getSolutionFromInst. |
143 |
|
*/ |
144 |
|
void setSolution(); |
145 |
|
|
146 |
|
// single invocation inference utility |
147 |
|
SingleInvocationPartition* d_sip; |
148 |
|
/** solution reconstruction */ |
149 |
|
std::unique_ptr<SygusReconstruct> d_srcons; |
150 |
|
|
151 |
|
// list of skolems for each argument of programs |
152 |
|
std::vector<Node> d_single_inv_arg_sk; |
153 |
|
// program to solution index |
154 |
|
std::map<Node, unsigned> d_prog_to_sol_index; |
155 |
|
// original conjecture |
156 |
|
Node d_orig_conjecture; |
157 |
|
|
158 |
|
Node d_simp_quant; |
159 |
|
// are we single invocation? |
160 |
|
bool d_single_invocation; |
161 |
|
// single invocation portion of quantified formula |
162 |
|
Node d_single_inv; |
163 |
|
|
164 |
|
/** Reference to the term registry */ |
165 |
|
TermRegistry& d_treg; |
166 |
|
/** The conjecture */ |
167 |
|
Node d_quant; |
168 |
|
//-------------- decomposed conjecture |
169 |
|
/** All functions */ |
170 |
|
std::vector<Node> d_funs; |
171 |
|
/** Unsolved functions */ |
172 |
|
std::vector<Node> d_unsolvedf; |
173 |
|
/** Mapping of solved functions */ |
174 |
|
Subs d_solvedf; |
175 |
|
//-------------- end decomposed conjecture |
176 |
|
}; |
177 |
|
|
178 |
|
} // namespace quantifiers |
179 |
|
} // namespace theory |
180 |
|
} // namespace cvc5 |
181 |
|
|
182 |
|
#endif |