1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Morgan Deters, Tim King |
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 |
|
* Implementation of the theory of quantifiers. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/quantifiers/theory_quantifiers.h" |
17 |
|
|
18 |
|
#include "options/quantifiers_options.h" |
19 |
|
#include "proof/proof_node_manager.h" |
20 |
|
#include "theory/quantifiers/quantifiers_macros.h" |
21 |
|
#include "theory/quantifiers/quantifiers_modules.h" |
22 |
|
#include "theory/quantifiers/quantifiers_rewriter.h" |
23 |
|
#include "theory/trust_substitutions.h" |
24 |
|
#include "theory/valuation.h" |
25 |
|
|
26 |
|
using namespace cvc5::kind; |
27 |
|
using namespace cvc5::context; |
28 |
|
|
29 |
|
namespace cvc5 { |
30 |
|
namespace theory { |
31 |
|
namespace quantifiers { |
32 |
|
|
33 |
9915 |
TheoryQuantifiers::TheoryQuantifiers(Env& env, |
34 |
|
OutputChannel& out, |
35 |
9915 |
Valuation valuation) |
36 |
|
: Theory(THEORY_QUANTIFIERS, env, out, valuation), |
37 |
|
d_qstate(env, valuation, logicInfo()), |
38 |
|
d_qreg(env), |
39 |
|
d_treg(env, d_qstate, d_qreg), |
40 |
|
d_qim(env, *this, d_qstate, d_qreg, d_treg, d_pnm), |
41 |
9915 |
d_qengine(nullptr) |
42 |
|
{ |
43 |
|
// construct the quantifiers engine |
44 |
19830 |
d_qengine.reset( |
45 |
9915 |
new QuantifiersEngine(env, d_qstate, d_qreg, d_treg, d_qim, d_pnm)); |
46 |
|
|
47 |
|
// indicate we are using the quantifiers theory state object |
48 |
9915 |
d_theoryState = &d_qstate; |
49 |
|
// use the inference manager as the official inference manager |
50 |
9915 |
d_inferManager = &d_qim; |
51 |
|
// Set the pointer to the quantifiers engine, which this theory owns. This |
52 |
|
// pointer will be retreived by TheoryEngine and set to all theories |
53 |
|
// post-construction. |
54 |
9915 |
d_quantEngine = d_qengine.get(); |
55 |
|
|
56 |
9915 |
if (options::macrosQuant()) |
57 |
|
{ |
58 |
22 |
d_qmacros.reset(new QuantifiersMacros(d_qreg)); |
59 |
|
} |
60 |
9915 |
} |
61 |
|
|
62 |
19824 |
TheoryQuantifiers::~TheoryQuantifiers() { |
63 |
19824 |
} |
64 |
|
|
65 |
9915 |
TheoryRewriter* TheoryQuantifiers::getTheoryRewriter() { return &d_rewriter; } |
66 |
|
|
67 |
3781 |
ProofRuleChecker* TheoryQuantifiers::getProofChecker() { return &d_checker; } |
68 |
|
|
69 |
9915 |
void TheoryQuantifiers::finishInit() |
70 |
|
{ |
71 |
|
// quantifiers are not evaluated in getModelValue |
72 |
9915 |
d_valuation.setUnevaluatedKind(EXISTS); |
73 |
9915 |
d_valuation.setUnevaluatedKind(FORALL); |
74 |
|
// witness is used in several instantiation strategies |
75 |
9915 |
d_valuation.setUnevaluatedKind(WITNESS); |
76 |
9915 |
} |
77 |
|
|
78 |
9915 |
bool TheoryQuantifiers::needsEqualityEngine(EeSetupInfo& esi) |
79 |
|
{ |
80 |
|
// use the master equality engine |
81 |
9915 |
esi.d_useMaster = true; |
82 |
9915 |
return true; |
83 |
|
} |
84 |
|
|
85 |
31975 |
void TheoryQuantifiers::preRegisterTerm(TNode n) |
86 |
|
{ |
87 |
31975 |
if (n.getKind() != FORALL) |
88 |
|
{ |
89 |
|
return; |
90 |
|
} |
91 |
63950 |
Debug("quantifiers-prereg") |
92 |
31975 |
<< "TheoryQuantifiers::preRegisterTerm() " << n << std::endl; |
93 |
|
// Preregister the quantified formula. |
94 |
|
// This initializes the modules used for handling n in this user context. |
95 |
31976 |
getQuantifiersEngine()->preRegisterQuantifier(n); |
96 |
63948 |
Debug("quantifiers-prereg") |
97 |
31974 |
<< "TheoryQuantifiers::preRegisterTerm() done " << n << std::endl; |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
15239 |
void TheoryQuantifiers::presolve() { |
102 |
15239 |
Debug("quantifiers-presolve") << "TheoryQuantifiers::presolve()" << std::endl; |
103 |
15239 |
if( getQuantifiersEngine() ){ |
104 |
8200 |
getQuantifiersEngine()->presolve(); |
105 |
|
} |
106 |
15239 |
} |
107 |
|
|
108 |
13392 |
Theory::PPAssertStatus TheoryQuantifiers::ppAssert( |
109 |
|
TrustNode tin, TrustSubstitutionMap& outSubstitutions) |
110 |
|
{ |
111 |
13392 |
if (d_qmacros != nullptr) |
112 |
|
{ |
113 |
|
bool reqGround = |
114 |
34 |
options::macrosQuantMode() != options::MacrosQuantMode::ALL; |
115 |
52 |
Node eq = d_qmacros->solve(tin.getProven(), reqGround); |
116 |
34 |
if (!eq.isNull()) |
117 |
|
{ |
118 |
|
// must be legal |
119 |
16 |
if (isLegalElimination(eq[0], eq[1])) |
120 |
|
{ |
121 |
16 |
outSubstitutions.addSubstitution(eq[0], eq[1]); |
122 |
16 |
return Theory::PP_ASSERT_STATUS_SOLVED; |
123 |
|
} |
124 |
|
} |
125 |
|
} |
126 |
13376 |
return Theory::PP_ASSERT_STATUS_UNSOLVED; |
127 |
|
} |
128 |
13773 |
void TheoryQuantifiers::ppNotifyAssertions( |
129 |
|
const std::vector<Node>& assertions) { |
130 |
27546 |
Trace("quantifiers-presolve") |
131 |
13773 |
<< "TheoryQuantifiers::ppNotifyAssertions" << std::endl; |
132 |
13773 |
if (getQuantifiersEngine()) { |
133 |
8162 |
getQuantifiersEngine()->ppNotifyAssertions(assertions); |
134 |
|
} |
135 |
13773 |
} |
136 |
|
|
137 |
13002 |
bool TheoryQuantifiers::collectModelValues(TheoryModel* m, |
138 |
|
const std::set<Node>& termSet) |
139 |
|
{ |
140 |
42480 |
for(assertions_iterator i = facts_begin(); i != facts_end(); ++i) { |
141 |
29478 |
if ((*i).d_assertion.getKind() == NOT) |
142 |
|
{ |
143 |
8276 |
Debug("quantifiers::collectModelInfo") |
144 |
4138 |
<< "got quant FALSE: " << (*i).d_assertion[0] << std::endl; |
145 |
4138 |
if (!m->assertPredicate((*i).d_assertion[0], false)) |
146 |
|
{ |
147 |
|
return false; |
148 |
|
} |
149 |
|
} |
150 |
|
else |
151 |
|
{ |
152 |
50680 |
Debug("quantifiers::collectModelInfo") |
153 |
25340 |
<< "got quant TRUE : " << *i << std::endl; |
154 |
25340 |
if (!m->assertPredicate(*i, true)) |
155 |
|
{ |
156 |
|
return false; |
157 |
|
} |
158 |
|
} |
159 |
|
} |
160 |
13002 |
return true; |
161 |
|
} |
162 |
|
|
163 |
86911 |
void TheoryQuantifiers::postCheck(Effort level) |
164 |
|
{ |
165 |
|
// call the quantifiers engine to check |
166 |
86911 |
getQuantifiersEngine()->check(level); |
167 |
86911 |
} |
168 |
|
|
169 |
89041 |
bool TheoryQuantifiers::preNotifyFact( |
170 |
|
TNode atom, bool polarity, TNode fact, bool isPrereg, bool isInternal) |
171 |
|
{ |
172 |
89041 |
Kind k = atom.getKind(); |
173 |
89041 |
if (k == FORALL) |
174 |
|
{ |
175 |
89041 |
getQuantifiersEngine()->assertQuantifier(atom, polarity); |
176 |
|
} |
177 |
|
else |
178 |
|
{ |
179 |
|
Unhandled() << "Unexpected fact " << fact; |
180 |
|
} |
181 |
|
// don't use equality engine, always return true |
182 |
89041 |
return true; |
183 |
|
} |
184 |
|
|
185 |
|
} // namespace quantifiers |
186 |
|
} // namespace theory |
187 |
29511 |
} // namespace cvc5 |