1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Mathias Preiner, 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 |
|
* candidate_rewrite_database |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_DATABASE_H |
19 |
|
#define CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_DATABASE_H |
20 |
|
|
21 |
|
#include <vector> |
22 |
|
|
23 |
|
#include "theory/quantifiers/candidate_rewrite_filter.h" |
24 |
|
#include "theory/quantifiers/expr_miner.h" |
25 |
|
#include "theory/quantifiers/sygus_sampler.h" |
26 |
|
|
27 |
|
namespace cvc5 { |
28 |
|
namespace theory { |
29 |
|
namespace quantifiers { |
30 |
|
|
31 |
|
/** CandidateRewriteDatabase |
32 |
|
* |
33 |
|
* This maintains the necessary data structures for generating a database |
34 |
|
* of candidate rewrite rules (see Noetzli et al "Syntax-Guided Rewrite Rule |
35 |
|
* Enumeration for SMT Solvers" SAT 2019). The primary responsibilities |
36 |
|
* of this class are to perform the "equivalence checking" and "congruence |
37 |
|
* and matching filtering" in Figure 1. The equivalence checking is done |
38 |
|
* through a combination of the sygus sampler object owned by this class |
39 |
|
* and the calls made to copies of the SmtEngine in ::addTerm. The rewrite |
40 |
|
* rule filtering (based on congruence, matching, variable ordering) is also |
41 |
|
* managed by the sygus sampler object. |
42 |
|
*/ |
43 |
|
class CandidateRewriteDatabase : public ExprMiner |
44 |
|
{ |
45 |
|
public: |
46 |
|
/** |
47 |
|
* Constructor |
48 |
|
* @param doCheck Whether to check rewrite rules using subsolvers. |
49 |
|
* @param rewAccel Whether to construct symmetry breaking lemmas based on |
50 |
|
* discovered rewrites (see option sygusRewSynthAccel()). |
51 |
|
* @param silent Whether to silence the output of rewrites discovered by this |
52 |
|
* class. |
53 |
|
* @param filterPairs Whether to filter rewrite pairs using filtering |
54 |
|
* techniques from the SAT 2019 paper above. |
55 |
|
*/ |
56 |
|
CandidateRewriteDatabase(bool doCheck, |
57 |
|
bool rewAccel = false, |
58 |
|
bool silent = false, |
59 |
|
bool filterPairs = true); |
60 |
115 |
~CandidateRewriteDatabase() {} |
61 |
|
/** Initialize this class */ |
62 |
|
void initialize(const std::vector<Node>& var, SygusSampler* ss) override; |
63 |
|
/** Initialize this class |
64 |
|
* |
65 |
|
* Serves the same purpose as the above function, but we will be using |
66 |
|
* sygus to enumerate terms and generate samples. |
67 |
|
* |
68 |
|
* tds : pointer to sygus term database. We use the extended rewriter of this |
69 |
|
* database when computing candidate rewrites, |
70 |
|
* f : a term of some SyGuS datatype type whose values we will be |
71 |
|
* testing under the free variables in the grammar of f. This is the |
72 |
|
* "candidate variable" CegConjecture::d_candidates. |
73 |
|
*/ |
74 |
|
void initializeSygus(const std::vector<Node>& vars, |
75 |
|
TermDbSygus* tds, |
76 |
|
Node f, |
77 |
|
SygusSampler* ss); |
78 |
|
/** add term |
79 |
|
* |
80 |
|
* Notifies this class that the solution sol was enumerated. This may |
81 |
|
* cause a candidate-rewrite to be printed on the output stream out. |
82 |
|
* |
83 |
|
* @param sol The term to add to this class. |
84 |
|
* @param rec If true, then we also recursively add all subterms of sol |
85 |
|
* to this class as well. |
86 |
|
* @param out The stream to output rewrite rules on. |
87 |
|
* @param rew_print Set to true if this class printed a rewrite involving sol. |
88 |
|
* @return A previous term eq_sol added to this class, such that sol is |
89 |
|
* equivalent to eq_sol based on the criteria used by this class. |
90 |
|
*/ |
91 |
|
Node addTerm(Node sol, bool rec, std::ostream& out, bool& rew_print); |
92 |
|
Node addTerm(Node sol, bool rec, std::ostream& out); |
93 |
|
/** |
94 |
|
* Same as above, returns true if the return value of addTerm was equal to |
95 |
|
* sol, in other words, sol was a new unique term. This assumes false for |
96 |
|
* the argument rec. |
97 |
|
*/ |
98 |
|
bool addTerm(Node sol, std::ostream& out) override; |
99 |
|
/** sets whether this class should output candidate rewrites it finds */ |
100 |
|
void setSilent(bool flag); |
101 |
|
/** set the (extended) rewriter used by this class */ |
102 |
|
void setExtendedRewriter(ExtendedRewriter* er); |
103 |
|
|
104 |
|
private: |
105 |
|
/** (required) pointer to the sygus term database of d_qe */ |
106 |
|
TermDbSygus* d_tds; |
107 |
|
/** an extended rewriter object */ |
108 |
|
ExtendedRewriter* d_ext_rewrite; |
109 |
|
/** the function-to-synthesize we are testing (if sygus) */ |
110 |
|
Node d_candidate; |
111 |
|
/** whether we are checking equivalence using subsolver */ |
112 |
|
bool d_doCheck; |
113 |
|
/** |
114 |
|
* If true, we use acceleration for symmetry breaking rewrites (see option |
115 |
|
* sygusRewSynthAccel()). |
116 |
|
*/ |
117 |
|
bool d_rewAccel; |
118 |
|
/** if true, we silence the output of candidate rewrites */ |
119 |
|
bool d_silent; |
120 |
|
/** if true, we filter pairs of terms to check equivalence */ |
121 |
|
bool d_filterPairs; |
122 |
|
/** whether we are using sygus */ |
123 |
|
bool d_using_sygus; |
124 |
|
/** candidate rewrite filter */ |
125 |
|
CandidateRewriteFilter d_crewrite_filter; |
126 |
|
/** the cache for results of addTerm */ |
127 |
|
std::unordered_map<Node, Node> d_add_term_cache; |
128 |
|
}; |
129 |
|
|
130 |
|
} // namespace quantifiers |
131 |
|
} // namespace theory |
132 |
|
} // namespace cvc5 |
133 |
|
|
134 |
|
#endif /* CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_DATABASE_H */ |