1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Gereon Kremer, 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 |
|
* Common data shared by multiple checks. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/arith/nl/ext/ext_state.h" |
17 |
|
|
18 |
|
#include <vector> |
19 |
|
|
20 |
|
#include "expr/node.h" |
21 |
|
#include "proof/proof.h" |
22 |
|
#include "theory/arith/inference_manager.h" |
23 |
|
#include "theory/arith/nl/ext/monomial.h" |
24 |
|
#include "theory/arith/nl/nl_lemma_utils.h" |
25 |
|
#include "theory/arith/nl/nl_model.h" |
26 |
|
#include "util/rational.h" |
27 |
|
|
28 |
|
namespace cvc5 { |
29 |
|
namespace theory { |
30 |
|
namespace arith { |
31 |
|
namespace nl { |
32 |
|
|
33 |
5150 |
ExtState::ExtState(InferenceManager& im, |
34 |
|
NlModel& model, |
35 |
|
ProofNodeManager* pnm, |
36 |
5150 |
context::UserContext* c) |
37 |
5150 |
: d_im(im), d_model(model), d_pnm(pnm), d_ctx(c) |
38 |
|
{ |
39 |
5150 |
d_false = NodeManager::currentNM()->mkConst(false); |
40 |
5150 |
d_true = NodeManager::currentNM()->mkConst(true); |
41 |
5150 |
d_zero = NodeManager::currentNM()->mkConst(Rational(0)); |
42 |
5150 |
d_one = NodeManager::currentNM()->mkConst(Rational(1)); |
43 |
5150 |
d_neg_one = NodeManager::currentNM()->mkConst(Rational(-1)); |
44 |
5150 |
if (d_pnm != nullptr) |
45 |
|
{ |
46 |
589 |
d_proof.reset(new CDProofSet<CDProof>(d_pnm, d_ctx, "nl-ext")); |
47 |
|
} |
48 |
5150 |
} |
49 |
|
|
50 |
2775 |
void ExtState::init(const std::vector<Node>& xts) |
51 |
|
{ |
52 |
2775 |
d_ms_vars.clear(); |
53 |
2775 |
d_ms.clear(); |
54 |
2775 |
d_mterms.clear(); |
55 |
2775 |
d_tplane_refine.clear(); |
56 |
|
|
57 |
2775 |
Trace("nl-ext-mv") << "Extended terms : " << std::endl; |
58 |
|
// for computing congruence |
59 |
5550 |
std::map<Kind, ArgTrie> argTrie; |
60 |
22621 |
for (unsigned i = 0, xsize = xts.size(); i < xsize; i++) |
61 |
|
{ |
62 |
39692 |
Node a = xts[i]; |
63 |
19846 |
d_model.computeConcreteModelValue(a); |
64 |
19846 |
d_model.computeAbstractModelValue(a); |
65 |
19846 |
d_model.printModelValue("nl-ext-mv", a); |
66 |
19846 |
Kind ak = a.getKind(); |
67 |
19846 |
if (ak == Kind::NONLINEAR_MULT) |
68 |
|
{ |
69 |
13112 |
d_ms.push_back(a); |
70 |
|
|
71 |
|
// context-independent registration |
72 |
13112 |
d_mdb.registerMonomial(a); |
73 |
|
|
74 |
13112 |
const std::vector<Node>& varList = d_mdb.getVariableList(a); |
75 |
38751 |
for (const Node& v : varList) |
76 |
|
{ |
77 |
25639 |
if (std::find(d_ms_vars.begin(), d_ms_vars.end(), v) == d_ms_vars.end()) |
78 |
|
{ |
79 |
12141 |
d_ms_vars.push_back(v); |
80 |
|
} |
81 |
|
} |
82 |
|
// mark processed if has a "one" factor (will look at reduced monomial)? |
83 |
|
} |
84 |
|
} |
85 |
|
|
86 |
|
// register constants |
87 |
2775 |
d_mdb.registerMonomial(d_one); |
88 |
|
|
89 |
|
// register variables |
90 |
2775 |
Trace("nl-ext-mv") << "Variables in monomials : " << std::endl; |
91 |
14916 |
for (unsigned i = 0; i < d_ms_vars.size(); i++) |
92 |
|
{ |
93 |
24282 |
Node v = d_ms_vars[i]; |
94 |
12141 |
d_mdb.registerMonomial(v); |
95 |
12141 |
d_model.computeConcreteModelValue(v); |
96 |
12141 |
d_model.computeAbstractModelValue(v); |
97 |
12141 |
d_model.printModelValue("nl-ext-mv", v); |
98 |
|
} |
99 |
|
|
100 |
2775 |
Trace("nl-ext") << "We have " << d_ms.size() << " monomials." << std::endl; |
101 |
2775 |
} |
102 |
|
|
103 |
4298 |
bool ExtState::isProofEnabled() const { return d_proof.get() != nullptr; } |
104 |
|
|
105 |
742 |
CDProof* ExtState::getProof() |
106 |
|
{ |
107 |
742 |
Assert(isProofEnabled()); |
108 |
742 |
return d_proof->allocateProof(d_ctx); |
109 |
|
} |
110 |
|
|
111 |
|
} // namespace nl |
112 |
|
} // namespace arith |
113 |
|
} // namespace theory |
114 |
29349 |
} // namespace cvc5 |