1 /******************************************************************************
2 * Top contributors (to current version):
5 * This file is part of the cvc5 project.
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 * ****************************************************************************
13 * Implementation of expression miner manager.
16 #include "theory/quantifiers/expr_miner_manager.h"
18 #include "options/quantifiers_options.h"
22 namespace quantifiers
{
24 ExpressionMinerManager::ExpressionMinerManager(Env
& env
)
28 d_doFilterLogicalStrength(false),
29 d_use_sygus_type(false),
32 options::sygusRewSynthCheck(),
33 options::sygusRewSynthAccel(),
40 void ExpressionMinerManager::initialize(const std::vector
<Node
>& vars
,
47 d_doFilterLogicalStrength
= false;
48 d_sygus_fun
= Node::null();
49 d_use_sygus_type
= false;
51 // initialize the sampler
52 d_sampler
.initialize(tn
, vars
, nsamples
, unique_type_ids
);
55 void ExpressionMinerManager::initializeSygus(TermDbSygus
* tds
,
62 d_doFilterLogicalStrength
= false;
64 d_use_sygus_type
= useSygusType
;
66 // initialize the sampler
67 d_sampler
.initializeSygus(d_tds
, f
, nsamples
, useSygusType
);
70 void ExpressionMinerManager::enableRewriteRuleSynth()
78 std::vector
<Node
> vars
;
79 d_sampler
.getVariables(vars
);
80 // initialize the candidate rewrite database
81 if (!d_sygus_fun
.isNull())
83 Assert(d_tds
!= nullptr);
84 d_crd
.initializeSygus(vars
, d_tds
, d_sygus_fun
, &d_sampler
);
88 d_crd
.initialize(vars
, &d_sampler
);
90 d_crd
.setExtendedRewriter(&d_ext_rew
);
91 d_crd
.setSilent(false);
94 void ExpressionMinerManager::enableQueryGeneration(unsigned deqThresh
)
102 std::vector
<Node
> vars
;
103 d_sampler
.getVariables(vars
);
104 // must also enable rewrite rule synthesis
107 // initialize the candidate rewrite database, in silent mode
108 enableRewriteRuleSynth();
109 d_crd
.setSilent(true);
111 // initialize the query generator
112 d_qg
.initialize(vars
, &d_sampler
);
113 d_qg
.setThreshold(deqThresh
);
116 void ExpressionMinerManager::enableFilterWeakSolutions()
118 d_doFilterLogicalStrength
= true;
119 std::vector
<Node
> vars
;
120 d_sampler
.getVariables(vars
);
121 d_sols
.initialize(vars
, &d_sampler
);
122 d_sols
.setLogicallyStrong(true);
125 void ExpressionMinerManager::enableFilterStrongSolutions()
127 d_doFilterLogicalStrength
= true;
128 std::vector
<Node
> vars
;
129 d_sampler
.getVariables(vars
);
130 d_sols
.initialize(vars
, &d_sampler
);
131 d_sols
.setLogicallyStrong(false);
134 bool ExpressionMinerManager::addTerm(Node sol
,
138 // set the builtin version
140 if (d_use_sygus_type
)
142 solb
= d_tds
->sygusToBuiltin(sol
);
145 // add to the candidate rewrite rule database
149 Node rsol
= d_crd
.addTerm(sol
, options::sygusRewSynthRec(), out
, rew_print
);
153 // a unique term, let's try the query generator
154 if (ret
&& d_doQueryGen
)
156 d_qg
.addTerm(solb
, out
);
159 // filter based on logical strength
160 if (ret
&& d_doFilterLogicalStrength
)
162 ret
= d_sols
.addTerm(solb
, out
);
167 bool ExpressionMinerManager::addTerm(Node sol
, std::ostream
& out
)
169 bool rew_print
= false;
170 return addTerm(sol
, out
, rew_print
);
173 } // namespace quantifiers
174 } // namespace theory