1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Tim King, Alex Ozdemir, Haniel Barbosa |
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 |
|
* [[ Add one-line brief description here ]] |
14 |
|
* |
15 |
|
* [[ Add lengthier description here ]] |
16 |
|
* \todo document this file |
17 |
|
*/ |
18 |
|
#include "theory/arith/constraint.h" |
19 |
|
|
20 |
|
#include <algorithm> |
21 |
|
#include <ostream> |
22 |
|
#include <unordered_set> |
23 |
|
|
24 |
|
#include "base/output.h" |
25 |
|
#include "options/smt_options.h" |
26 |
|
#include "proof/eager_proof_generator.h" |
27 |
|
#include "proof/proof_node_manager.h" |
28 |
|
#include "smt/env.h" |
29 |
|
#include "smt/smt_statistics_registry.h" |
30 |
|
#include "theory/arith/arith_utilities.h" |
31 |
|
#include "theory/arith/congruence_manager.h" |
32 |
|
#include "theory/arith/normal_form.h" |
33 |
|
#include "theory/arith/partial_model.h" |
34 |
|
#include "theory/builtin/proof_checker.h" |
35 |
|
#include "theory/rewriter.h" |
36 |
|
|
37 |
|
using namespace std; |
38 |
|
using namespace cvc5::kind; |
39 |
|
|
40 |
|
namespace cvc5 { |
41 |
|
namespace theory { |
42 |
|
namespace arith { |
43 |
|
|
44 |
|
ConstraintRule::ConstraintRule() |
45 |
|
: d_constraint(NullConstraint), |
46 |
|
d_proofType(NoAP), |
47 |
|
d_antecedentEnd(AntecedentIdSentinel) |
48 |
|
{ |
49 |
|
d_farkasCoefficients = RationalVectorCPSentinel; |
50 |
|
} |
51 |
|
|
52 |
5966803 |
ConstraintRule::ConstraintRule(ConstraintP con, ArithProofType pt) |
53 |
5966803 |
: d_constraint(con), d_proofType(pt), d_antecedentEnd(AntecedentIdSentinel) |
54 |
|
{ |
55 |
5966803 |
d_farkasCoefficients = RationalVectorCPSentinel; |
56 |
5966803 |
} |
57 |
2078937 |
ConstraintRule::ConstraintRule(ConstraintP con, |
58 |
|
ArithProofType pt, |
59 |
2078937 |
AntecedentId antecedentEnd) |
60 |
2078937 |
: d_constraint(con), d_proofType(pt), d_antecedentEnd(antecedentEnd) |
61 |
|
{ |
62 |
2078937 |
d_farkasCoefficients = RationalVectorCPSentinel; |
63 |
2078937 |
} |
64 |
|
|
65 |
3290497 |
ConstraintRule::ConstraintRule(ConstraintP con, |
66 |
|
ArithProofType pt, |
67 |
|
AntecedentId antecedentEnd, |
68 |
3290497 |
RationalVectorCP coeffs) |
69 |
3290497 |
: d_constraint(con), d_proofType(pt), d_antecedentEnd(antecedentEnd) |
70 |
|
{ |
71 |
3290497 |
Assert(con->isProofProducing() || coeffs == RationalVectorCPSentinel); |
72 |
3290497 |
d_farkasCoefficients = coeffs; |
73 |
3290497 |
} |
74 |
|
|
75 |
|
/** Given a simplifiedKind this returns the corresponding ConstraintType. */ |
76 |
|
//ConstraintType constraintTypeOfLiteral(Kind k); |
77 |
599254 |
ConstraintType Constraint::constraintTypeOfComparison(const Comparison& cmp){ |
78 |
599254 |
Kind k = cmp.comparisonKind(); |
79 |
599254 |
switch(k){ |
80 |
158150 |
case LT: |
81 |
|
case LEQ: |
82 |
|
{ |
83 |
316300 |
Polynomial l = cmp.getLeft(); |
84 |
158150 |
if(l.leadingCoefficientIsPositive()){ // (< x c) |
85 |
132745 |
return UpperBound; |
86 |
|
}else{ |
87 |
25405 |
return LowerBound; // (< (-x) c) |
88 |
|
} |
89 |
|
} |
90 |
159708 |
case GT: |
91 |
|
case GEQ: |
92 |
|
{ |
93 |
319416 |
Polynomial l = cmp.getLeft(); |
94 |
159708 |
if(l.leadingCoefficientIsPositive()){ |
95 |
134126 |
return LowerBound; // (> x c) |
96 |
|
}else{ |
97 |
25582 |
return UpperBound; // (> (-x) c) |
98 |
|
} |
99 |
|
} |
100 |
140815 |
case EQUAL: |
101 |
140815 |
return Equality; |
102 |
140581 |
case DISTINCT: |
103 |
140581 |
return Disequality; |
104 |
|
default: Unhandled() << k; |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
746514 |
Constraint::Constraint(ArithVar x, |
109 |
|
ConstraintType t, |
110 |
|
const DeltaRational& v, |
111 |
746514 |
bool produceProofs) |
112 |
|
: d_variable(x), |
113 |
|
d_type(t), |
114 |
|
d_value(v), |
115 |
|
d_database(NULL), |
116 |
|
d_literal(Node::null()), |
117 |
|
d_negation(NullConstraint), |
118 |
|
d_canBePropagated(false), |
119 |
|
d_assertionOrder(AssertionOrderSentinel), |
120 |
|
d_witness(TNode::null()), |
121 |
|
d_crid(ConstraintRuleIdSentinel), |
122 |
|
d_split(false), |
123 |
|
d_variablePosition(), |
124 |
746514 |
d_produceProofs(produceProofs) |
125 |
|
{ |
126 |
746514 |
Assert(!initialized()); |
127 |
746514 |
} |
128 |
|
|
129 |
|
|
130 |
|
std::ostream& operator<<(std::ostream& o, const ArithProofType apt){ |
131 |
|
switch(apt){ |
132 |
|
case NoAP: o << "NoAP"; break; |
133 |
|
case AssumeAP: o << "AssumeAP"; break; |
134 |
|
case InternalAssumeAP: o << "InternalAssumeAP"; break; |
135 |
|
case FarkasAP: o << "FarkasAP"; break; |
136 |
|
case TrichotomyAP: o << "TrichotomyAP"; break; |
137 |
|
case EqualityEngineAP: o << "EqualityEngineAP"; break; |
138 |
|
case IntTightenAP: o << "IntTightenAP"; break; |
139 |
|
case IntHoleAP: o << "IntHoleAP"; break; |
140 |
|
default: break; |
141 |
|
} |
142 |
|
return o; |
143 |
|
} |
144 |
|
|
145 |
|
std::ostream& operator<<(std::ostream& o, const ConstraintCP c){ |
146 |
|
if(c == NullConstraint){ |
147 |
|
return o << "NullConstraint"; |
148 |
|
}else{ |
149 |
|
return o << *c; |
150 |
|
} |
151 |
|
} |
152 |
|
|
153 |
|
std::ostream& operator<<(std::ostream& o, const ConstraintP c){ |
154 |
|
if(c == NullConstraint){ |
155 |
|
return o << "NullConstraint"; |
156 |
|
}else{ |
157 |
|
return o << *c; |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
|
std::ostream& operator<<(std::ostream& o, const ConstraintType t){ |
162 |
|
switch(t){ |
163 |
|
case LowerBound: |
164 |
|
return o << ">="; |
165 |
|
case UpperBound: |
166 |
|
return o << "<="; |
167 |
|
case Equality: |
168 |
|
return o << "="; |
169 |
|
case Disequality: |
170 |
|
return o << "!="; |
171 |
|
default: |
172 |
|
Unreachable(); |
173 |
|
} |
174 |
|
} |
175 |
|
|
176 |
|
std::ostream& operator<<(std::ostream& o, const Constraint& c){ |
177 |
|
o << c.getVariable() << ' ' << c.getType() << ' ' << c.getValue(); |
178 |
|
if(c.hasLiteral()){ |
179 |
|
o << "(node " << c.getLiteral() << ')'; |
180 |
|
} |
181 |
|
return o; |
182 |
|
} |
183 |
|
|
184 |
|
std::ostream& operator<<(std::ostream& o, const ValueCollection& vc){ |
185 |
|
o << "{"; |
186 |
|
bool pending = false; |
187 |
|
if(vc.hasEquality()){ |
188 |
|
o << "eq: " << vc.getEquality(); |
189 |
|
pending = true; |
190 |
|
} |
191 |
|
if(vc.hasLowerBound()){ |
192 |
|
if(pending){ |
193 |
|
o << ", "; |
194 |
|
} |
195 |
|
o << "lb: " << vc.getLowerBound(); |
196 |
|
pending = true; |
197 |
|
} |
198 |
|
if(vc.hasUpperBound()){ |
199 |
|
if(pending){ |
200 |
|
o << ", "; |
201 |
|
} |
202 |
|
o << "ub: " << vc.getUpperBound(); |
203 |
|
pending = true; |
204 |
|
} |
205 |
|
if(vc.hasDisequality()){ |
206 |
|
if(pending){ |
207 |
|
o << ", "; |
208 |
|
} |
209 |
|
o << "de: " << vc.getDisequality(); |
210 |
|
} |
211 |
|
return o << "}"; |
212 |
|
} |
213 |
|
|
214 |
|
std::ostream& operator<<(std::ostream& o, const ConstraintCPVec& v){ |
215 |
|
o << "[" << v.size() << "x"; |
216 |
|
ConstraintCPVec::const_iterator i, end; |
217 |
|
for(i=v.begin(), end=v.end(); i != end; ++i){ |
218 |
|
ConstraintCP c = *i; |
219 |
|
o << ", " << (*c); |
220 |
|
} |
221 |
|
o << "]"; |
222 |
|
return o; |
223 |
|
} |
224 |
|
|
225 |
2702457 |
ValueCollection::ValueCollection() |
226 |
|
: d_lowerBound(NullConstraint), |
227 |
|
d_upperBound(NullConstraint), |
228 |
|
d_equality(NullConstraint), |
229 |
2702457 |
d_disequality(NullConstraint) |
230 |
2702457 |
{} |
231 |
|
|
232 |
24641446 |
bool ValueCollection::hasLowerBound() const{ |
233 |
24641446 |
return d_lowerBound != NullConstraint; |
234 |
|
} |
235 |
|
|
236 |
28040213 |
bool ValueCollection::hasUpperBound() const{ |
237 |
28040213 |
return d_upperBound != NullConstraint; |
238 |
|
} |
239 |
|
|
240 |
4783073 |
bool ValueCollection::hasEquality() const{ |
241 |
4783073 |
return d_equality != NullConstraint; |
242 |
|
} |
243 |
|
|
244 |
18270143 |
bool ValueCollection::hasDisequality() const { |
245 |
18270143 |
return d_disequality != NullConstraint; |
246 |
|
} |
247 |
|
|
248 |
5373230 |
ConstraintP ValueCollection::getLowerBound() const { |
249 |
5373230 |
Assert(hasLowerBound()); |
250 |
5373230 |
return d_lowerBound; |
251 |
|
} |
252 |
|
|
253 |
5822683 |
ConstraintP ValueCollection::getUpperBound() const { |
254 |
5822683 |
Assert(hasUpperBound()); |
255 |
5822683 |
return d_upperBound; |
256 |
|
} |
257 |
|
|
258 |
372313 |
ConstraintP ValueCollection::getEquality() const { |
259 |
372313 |
Assert(hasEquality()); |
260 |
372313 |
return d_equality; |
261 |
|
} |
262 |
|
|
263 |
2742016 |
ConstraintP ValueCollection::getDisequality() const { |
264 |
2742016 |
Assert(hasDisequality()); |
265 |
2742016 |
return d_disequality; |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
501412 |
void ValueCollection::push_into(std::vector<ConstraintP>& vec) const { |
270 |
501412 |
Debug("arith::constraint") << "push_into " << *this << endl; |
271 |
501412 |
if(hasEquality()){ |
272 |
144803 |
vec.push_back(d_equality); |
273 |
|
} |
274 |
501412 |
if(hasLowerBound()){ |
275 |
227558 |
vec.push_back(d_lowerBound); |
276 |
|
} |
277 |
501412 |
if(hasUpperBound()){ |
278 |
227558 |
vec.push_back(d_upperBound); |
279 |
|
} |
280 |
501412 |
if(hasDisequality()){ |
281 |
144803 |
vec.push_back(d_disequality); |
282 |
|
} |
283 |
501412 |
} |
284 |
|
|
285 |
|
ValueCollection ValueCollection::mkFromConstraint(ConstraintP c){ |
286 |
|
ValueCollection ret; |
287 |
|
Assert(ret.empty()); |
288 |
|
switch(c->getType()){ |
289 |
|
case LowerBound: |
290 |
|
ret.d_lowerBound = c; |
291 |
|
break; |
292 |
|
case UpperBound: |
293 |
|
ret.d_upperBound = c; |
294 |
|
break; |
295 |
|
case Equality: |
296 |
|
ret.d_equality = c; |
297 |
|
break; |
298 |
|
case Disequality: |
299 |
|
ret.d_disequality = c; |
300 |
|
break; |
301 |
|
default: |
302 |
|
Unreachable(); |
303 |
|
} |
304 |
|
return ret; |
305 |
|
} |
306 |
|
|
307 |
4633453 |
bool ValueCollection::hasConstraintOfType(ConstraintType t) const{ |
308 |
4633453 |
switch(t){ |
309 |
1439261 |
case LowerBound: |
310 |
1439261 |
return hasLowerBound(); |
311 |
2805365 |
case UpperBound: |
312 |
2805365 |
return hasUpperBound(); |
313 |
388827 |
case Equality: |
314 |
388827 |
return hasEquality(); |
315 |
|
case Disequality: |
316 |
|
return hasDisequality(); |
317 |
|
default: |
318 |
|
Unreachable(); |
319 |
|
} |
320 |
|
} |
321 |
|
|
322 |
251283 |
ArithVar ValueCollection::getVariable() const{ |
323 |
251283 |
Assert(!empty()); |
324 |
251283 |
return nonNull()->getVariable(); |
325 |
|
} |
326 |
|
|
327 |
251283 |
const DeltaRational& ValueCollection::getValue() const{ |
328 |
251283 |
Assert(!empty()); |
329 |
251283 |
return nonNull()->getValue(); |
330 |
|
} |
331 |
|
|
332 |
744722 |
void ValueCollection::add(ConstraintP c){ |
333 |
744722 |
Assert(c != NullConstraint); |
334 |
|
|
335 |
744722 |
Assert(empty() || getVariable() == c->getVariable()); |
336 |
744722 |
Assert(empty() || getValue() == c->getValue()); |
337 |
|
|
338 |
744722 |
switch(c->getType()){ |
339 |
227558 |
case LowerBound: |
340 |
227558 |
Assert(!hasLowerBound()); |
341 |
227558 |
d_lowerBound = c; |
342 |
227558 |
break; |
343 |
144803 |
case Equality: |
344 |
144803 |
Assert(!hasEquality()); |
345 |
144803 |
d_equality = c; |
346 |
144803 |
break; |
347 |
227558 |
case UpperBound: |
348 |
227558 |
Assert(!hasUpperBound()); |
349 |
227558 |
d_upperBound = c; |
350 |
227558 |
break; |
351 |
144803 |
case Disequality: |
352 |
144803 |
Assert(!hasDisequality()); |
353 |
144803 |
d_disequality = c; |
354 |
144803 |
break; |
355 |
|
default: |
356 |
|
Unreachable(); |
357 |
|
} |
358 |
744722 |
} |
359 |
|
|
360 |
3628739 |
ConstraintP ValueCollection::getConstraintOfType(ConstraintType t) const{ |
361 |
3628739 |
switch(t){ |
362 |
953056 |
case LowerBound: Assert(hasLowerBound()); return d_lowerBound; |
363 |
244024 |
case Equality: Assert(hasEquality()); return d_equality; |
364 |
2431659 |
case UpperBound: Assert(hasUpperBound()); return d_upperBound; |
365 |
|
case Disequality: Assert(hasDisequality()); return d_disequality; |
366 |
|
default: Unreachable(); |
367 |
|
} |
368 |
|
} |
369 |
|
|
370 |
744722 |
void ValueCollection::remove(ConstraintType t){ |
371 |
744722 |
switch(t){ |
372 |
227558 |
case LowerBound: |
373 |
227558 |
Assert(hasLowerBound()); |
374 |
227558 |
d_lowerBound = NullConstraint; |
375 |
227558 |
break; |
376 |
144803 |
case Equality: |
377 |
144803 |
Assert(hasEquality()); |
378 |
144803 |
d_equality = NullConstraint; |
379 |
144803 |
break; |
380 |
227558 |
case UpperBound: |
381 |
227558 |
Assert(hasUpperBound()); |
382 |
227558 |
d_upperBound = NullConstraint; |
383 |
227558 |
break; |
384 |
144803 |
case Disequality: |
385 |
144803 |
Assert(hasDisequality()); |
386 |
144803 |
d_disequality = NullConstraint; |
387 |
144803 |
break; |
388 |
|
default: |
389 |
|
Unreachable(); |
390 |
|
} |
391 |
744722 |
} |
392 |
|
|
393 |
2736732 |
bool ValueCollection::empty() const{ |
394 |
|
return |
395 |
6598145 |
!(hasLowerBound() || |
396 |
4606256 |
hasUpperBound() || |
397 |
2249079 |
hasEquality() || |
398 |
4240968 |
hasDisequality()); |
399 |
|
} |
400 |
|
|
401 |
502566 |
ConstraintP ValueCollection::nonNull() const{ |
402 |
|
//This can be optimized by caching, but this is not necessary yet! |
403 |
|
/* "Premature optimization is the root of all evil." */ |
404 |
502566 |
if(hasLowerBound()){ |
405 |
151230 |
return d_lowerBound; |
406 |
351336 |
}else if(hasUpperBound()){ |
407 |
51316 |
return d_upperBound; |
408 |
300020 |
}else if(hasEquality()){ |
409 |
300020 |
return d_equality; |
410 |
|
}else if(hasDisequality()){ |
411 |
|
return d_disequality; |
412 |
|
}else{ |
413 |
|
return NullConstraint; |
414 |
|
} |
415 |
|
} |
416 |
|
|
417 |
3009226 |
bool Constraint::initialized() const { |
418 |
3009226 |
return d_database != NULL; |
419 |
|
} |
420 |
|
|
421 |
|
const ConstraintDatabase& Constraint::getDatabase() const{ |
422 |
|
Assert(initialized()); |
423 |
|
return *d_database; |
424 |
|
} |
425 |
|
|
426 |
744722 |
void Constraint::initialize(ConstraintDatabase* db, SortedConstraintMapIterator v, ConstraintP negation){ |
427 |
744722 |
Assert(!initialized()); |
428 |
744722 |
d_database = db; |
429 |
744722 |
d_variablePosition = v; |
430 |
744722 |
d_negation = negation; |
431 |
744722 |
} |
432 |
|
|
433 |
1493028 |
Constraint::~Constraint() { |
434 |
|
// Call this instead of safeToGarbageCollect() |
435 |
746514 |
Assert(!contextDependentDataIsSet()); |
436 |
|
|
437 |
746514 |
if(initialized()){ |
438 |
744722 |
ValueCollection& vc = d_variablePosition->second; |
439 |
744722 |
Debug("arith::constraint") << "removing" << vc << endl; |
440 |
|
|
441 |
744722 |
vc.remove(getType()); |
442 |
|
|
443 |
744722 |
if(vc.empty()){ |
444 |
501412 |
Debug("arith::constraint") << "erasing" << vc << endl; |
445 |
501412 |
SortedConstraintMap& perVariable = d_database->getVariableSCM(getVariable()); |
446 |
501412 |
perVariable.erase(d_variablePosition); |
447 |
|
} |
448 |
|
|
449 |
744722 |
if(hasLiteral()){ |
450 |
601046 |
d_database->d_nodetoConstraintMap.erase(getLiteral()); |
451 |
|
} |
452 |
|
} |
453 |
746514 |
} |
454 |
|
|
455 |
34248506 |
const ConstraintRule& Constraint::getConstraintRule() const { |
456 |
34248506 |
Assert(hasProof()); |
457 |
34248506 |
return d_database->d_watches->d_constraintProofs[d_crid]; |
458 |
|
} |
459 |
|
|
460 |
3849260 |
const ValueCollection& Constraint::getValueCollection() const{ |
461 |
3849260 |
return d_variablePosition->second; |
462 |
|
} |
463 |
|
|
464 |
|
|
465 |
125305 |
ConstraintP Constraint::getCeiling() { |
466 |
125305 |
Debug("getCeiling") << "Constraint_::getCeiling on " << *this << endl; |
467 |
125305 |
Assert(getValue().getInfinitesimalPart().sgn() > 0); |
468 |
|
|
469 |
250610 |
const DeltaRational ceiling(getValue().ceiling()); |
470 |
250610 |
return d_database->getConstraint(getVariable(), getType(), ceiling); |
471 |
|
} |
472 |
|
|
473 |
1793086 |
ConstraintP Constraint::getFloor() { |
474 |
1793086 |
Assert(getValue().getInfinitesimalPart().sgn() < 0); |
475 |
|
|
476 |
3586172 |
const DeltaRational floor(Rational(getValue().floor())); |
477 |
3586172 |
return d_database->getConstraint(getVariable(), getType(), floor); |
478 |
|
} |
479 |
|
|
480 |
935998 |
void Constraint::setCanBePropagated() { |
481 |
935998 |
Assert(!canBePropagated()); |
482 |
935998 |
d_database->pushCanBePropagatedWatch(this); |
483 |
935998 |
} |
484 |
|
|
485 |
7107347 |
void Constraint::setAssertedToTheTheory(TNode witness, bool nowInConflict) { |
486 |
7107347 |
Assert(hasLiteral()); |
487 |
7107347 |
Assert(!assertedToTheTheory()); |
488 |
7107347 |
Assert(negationHasProof() == nowInConflict); |
489 |
7107347 |
d_database->pushAssertionOrderWatch(this, witness); |
490 |
|
|
491 |
7107347 |
if(Debug.isOn("constraint::conflictCommit") && nowInConflict ){ |
492 |
|
Debug("constraint::conflictCommit") << "inConflict@setAssertedToTheTheory"; |
493 |
|
Debug("constraint::conflictCommit") << "\t" << this << std::endl; |
494 |
|
Debug("constraint::conflictCommit") << "\t" << getNegation() << std::endl; |
495 |
|
Debug("constraint::conflictCommit") << "\t" << getNegation()->externalExplainByAssertions() << std::endl; |
496 |
|
|
497 |
|
} |
498 |
7107347 |
} |
499 |
|
|
500 |
|
bool Constraint::satisfiedBy(const DeltaRational& dr) const { |
501 |
|
switch(getType()){ |
502 |
|
case LowerBound: |
503 |
|
return getValue() <= dr; |
504 |
|
case Equality: |
505 |
|
return getValue() == dr; |
506 |
|
case UpperBound: |
507 |
|
return getValue() >= dr; |
508 |
|
case Disequality: |
509 |
|
return getValue() != dr; |
510 |
|
} |
511 |
|
Unreachable(); |
512 |
|
} |
513 |
|
|
514 |
14324222 |
bool Constraint::isInternalAssumption() const { |
515 |
14324222 |
return getProofType() == InternalAssumeAP; |
516 |
|
} |
517 |
|
|
518 |
|
TrustNode Constraint::externalExplainByAssertions() const |
519 |
|
{ |
520 |
|
NodeBuilder nb(kind::AND); |
521 |
|
auto pfFromAssumptions = externalExplain(nb, AssertionOrderSentinel); |
522 |
|
Node exp = safeConstructNary(nb); |
523 |
|
if (d_database->isProofEnabled()) |
524 |
|
{ |
525 |
|
std::vector<Node> assumptions; |
526 |
|
if (exp.getKind() == Kind::AND) |
527 |
|
{ |
528 |
|
assumptions.insert(assumptions.end(), exp.begin(), exp.end()); |
529 |
|
} |
530 |
|
else |
531 |
|
{ |
532 |
|
assumptions.push_back(exp); |
533 |
|
} |
534 |
|
auto pf = d_database->d_pnm->mkScope(pfFromAssumptions, assumptions); |
535 |
|
return d_database->d_pfGen->mkTrustedPropagation( |
536 |
|
getLiteral(), safeConstructNary(Kind::AND, assumptions), pf); |
537 |
|
} |
538 |
|
return TrustNode::mkTrustPropExp(getLiteral(), exp); |
539 |
|
} |
540 |
|
|
541 |
15043244 |
bool Constraint::isAssumption() const { |
542 |
15043244 |
return getProofType() == AssumeAP; |
543 |
|
} |
544 |
|
|
545 |
701672 |
bool Constraint::hasEqualityEngineProof() const { |
546 |
701672 |
return getProofType() == EqualityEngineAP; |
547 |
|
} |
548 |
|
|
549 |
|
bool Constraint::hasFarkasProof() const { |
550 |
|
return getProofType() == FarkasAP; |
551 |
|
} |
552 |
|
|
553 |
|
bool Constraint::hasSimpleFarkasProof() const |
554 |
|
{ |
555 |
|
Debug("constraints::hsfp") << "hasSimpleFarkasProof " << this << std::endl; |
556 |
|
if (!hasFarkasProof()) |
557 |
|
{ |
558 |
|
Debug("constraints::hsfp") << "There is no simple Farkas proof because " |
559 |
|
"there is no farkas proof." |
560 |
|
<< std::endl; |
561 |
|
return false; |
562 |
|
} |
563 |
|
|
564 |
|
// For each antecdent ... |
565 |
|
AntecedentId i = getConstraintRule().d_antecedentEnd; |
566 |
|
for (ConstraintCP a = d_database->getAntecedent(i); a != NullConstraint; |
567 |
|
a = d_database->getAntecedent(--i)) |
568 |
|
{ |
569 |
|
// ... that antecdent must be an assumption OR a tightened assumption ... |
570 |
|
if (a->isPossiblyTightenedAssumption()) |
571 |
|
{ |
572 |
|
continue; |
573 |
|
} |
574 |
|
|
575 |
|
// ... otherwise, we do not have a simple Farkas proof. |
576 |
|
if (Debug.isOn("constraints::hsfp")) |
577 |
|
{ |
578 |
|
Debug("constraints::hsfp") << "There is no simple Farkas proof b/c there " |
579 |
|
"is an antecdent w/ rule "; |
580 |
|
a->getConstraintRule().print(Debug("constraints::hsfp"), d_produceProofs); |
581 |
|
Debug("constraints::hsfp") << std::endl; |
582 |
|
} |
583 |
|
|
584 |
|
return false; |
585 |
|
} |
586 |
|
return true; |
587 |
|
} |
588 |
|
|
589 |
|
bool Constraint::isPossiblyTightenedAssumption() const |
590 |
|
{ |
591 |
|
// ... that antecdent must be an assumption ... |
592 |
|
|
593 |
|
if (isAssumption()) return true; |
594 |
|
if (!hasIntTightenProof()) return false; |
595 |
|
if (getConstraintRule().d_antecedentEnd == AntecedentIdSentinel) return false; |
596 |
|
return d_database->getAntecedent(getConstraintRule().d_antecedentEnd) |
597 |
|
->isAssumption(); |
598 |
|
} |
599 |
|
|
600 |
|
bool Constraint::hasIntTightenProof() const { |
601 |
|
return getProofType() == IntTightenAP; |
602 |
|
} |
603 |
|
|
604 |
|
bool Constraint::hasIntHoleProof() const { |
605 |
|
return getProofType() == IntHoleAP; |
606 |
|
} |
607 |
|
|
608 |
|
bool Constraint::hasTrichotomyProof() const { |
609 |
|
return getProofType() == TrichotomyAP; |
610 |
|
} |
611 |
|
|
612 |
|
void Constraint::printProofTree(std::ostream& out, size_t depth) const |
613 |
|
{ |
614 |
|
if (d_produceProofs) |
615 |
|
{ |
616 |
|
const ConstraintRule& rule = getConstraintRule(); |
617 |
|
out << std::string(2 * depth, ' ') << "* " << getVariable() << " ["; |
618 |
|
out << getProofLiteral(); |
619 |
|
if (assertedToTheTheory()) |
620 |
|
{ |
621 |
|
out << " | wit: " << getWitness(); |
622 |
|
} |
623 |
|
out << "]" << ' ' << getType() << ' ' << getValue() << " (" |
624 |
|
<< getProofType() << ")"; |
625 |
|
if (getProofType() == FarkasAP) |
626 |
|
{ |
627 |
|
out << " ["; |
628 |
|
bool first = true; |
629 |
|
for (const auto& coeff : *rule.d_farkasCoefficients) |
630 |
|
{ |
631 |
|
if (not first) |
632 |
|
{ |
633 |
|
out << ", "; |
634 |
|
} |
635 |
|
first = false; |
636 |
|
out << coeff; |
637 |
|
} |
638 |
|
out << "]"; |
639 |
|
} |
640 |
|
out << endl; |
641 |
|
|
642 |
|
for (AntecedentId i = rule.d_antecedentEnd; i != AntecedentIdSentinel; --i) |
643 |
|
{ |
644 |
|
ConstraintCP antecdent = d_database->getAntecedent(i); |
645 |
|
if (antecdent == NullConstraint) |
646 |
|
{ |
647 |
|
break; |
648 |
|
} |
649 |
|
antecdent->printProofTree(out, depth + 1); |
650 |
|
} |
651 |
|
return; |
652 |
|
} |
653 |
|
out << "Cannot print proof. This is not a proof build." << endl; |
654 |
|
} |
655 |
|
|
656 |
601046 |
bool Constraint::sanityChecking(Node n) const { |
657 |
1202092 |
Comparison cmp = Comparison::parseNormalForm(n); |
658 |
601046 |
Kind k = cmp.comparisonKind(); |
659 |
1202092 |
Polynomial pleft = cmp.normalizedVariablePart(); |
660 |
601046 |
Assert(k == EQUAL || k == DISTINCT || pleft.leadingCoefficientIsPositive()); |
661 |
601046 |
Assert(k != EQUAL || Monomial::isMember(n[0])); |
662 |
601046 |
Assert(k != DISTINCT || Monomial::isMember(n[0][0])); |
663 |
|
|
664 |
1202092 |
TNode left = pleft.getNode(); |
665 |
1202092 |
DeltaRational right = cmp.normalizedDeltaRational(); |
666 |
|
|
667 |
601046 |
const ArithVariables& avariables = d_database->getArithVariables(); |
668 |
|
|
669 |
601046 |
Debug("Constraint::sanityChecking") << cmp.getNode() << endl; |
670 |
601046 |
Debug("Constraint::sanityChecking") << k << endl; |
671 |
601046 |
Debug("Constraint::sanityChecking") << pleft.getNode() << endl; |
672 |
601046 |
Debug("Constraint::sanityChecking") << left << endl; |
673 |
601046 |
Debug("Constraint::sanityChecking") << right << endl; |
674 |
601046 |
Debug("Constraint::sanityChecking") << getValue() << endl; |
675 |
601046 |
Debug("Constraint::sanityChecking") << avariables.hasArithVar(left) << endl; |
676 |
601046 |
Debug("Constraint::sanityChecking") << avariables.asArithVar(left) << endl; |
677 |
601046 |
Debug("Constraint::sanityChecking") << getVariable() << endl; |
678 |
|
|
679 |
|
|
680 |
3005230 |
if(avariables.hasArithVar(left) && |
681 |
3005230 |
avariables.asArithVar(left) == getVariable() && |
682 |
601046 |
getValue() == right){ |
683 |
601046 |
switch(getType()){ |
684 |
319416 |
case LowerBound: |
685 |
|
case UpperBound: |
686 |
|
//Be overapproximate |
687 |
319416 |
return k == GT || k == GEQ ||k == LT || k == LEQ; |
688 |
140815 |
case Equality: |
689 |
140815 |
return k == EQUAL; |
690 |
140815 |
case Disequality: |
691 |
140815 |
return k == DISTINCT; |
692 |
|
default: |
693 |
|
Unreachable(); |
694 |
|
} |
695 |
|
}else{ |
696 |
|
return false; |
697 |
|
} |
698 |
|
} |
699 |
|
|
700 |
|
ConstraintCP ConstraintDatabase::getAntecedent (AntecedentId p) const { |
701 |
|
Assert(p < d_antecedents.size()); |
702 |
|
return d_antecedents[p]; |
703 |
|
} |
704 |
|
|
705 |
|
void ConstraintRule::print(std::ostream& out, bool produceProofs) const |
706 |
|
{ |
707 |
|
RationalVectorCP coeffs = produceProofs ? d_farkasCoefficients : nullptr; |
708 |
|
out << "{ConstraintRule, "; |
709 |
|
out << d_constraint << std::endl; |
710 |
|
out << "d_proofType= " << d_proofType << ", " << std::endl; |
711 |
|
out << "d_antecedentEnd= "<< d_antecedentEnd << std::endl; |
712 |
|
|
713 |
|
if (d_constraint != NullConstraint && d_antecedentEnd != AntecedentIdSentinel) |
714 |
|
{ |
715 |
|
const ConstraintDatabase& database = d_constraint->getDatabase(); |
716 |
|
|
717 |
|
size_t coeffIterator = (coeffs != RationalVectorCPSentinel) ? coeffs->size()-1 : 0; |
718 |
|
AntecedentId p = d_antecedentEnd; |
719 |
|
// must have at least one antecedent |
720 |
|
ConstraintCP antecedent = database.getAntecedent(p); |
721 |
|
while(antecedent != NullConstraint){ |
722 |
|
if(coeffs != RationalVectorCPSentinel){ |
723 |
|
out << coeffs->at(coeffIterator); |
724 |
|
} else { |
725 |
|
out << "_"; |
726 |
|
} |
727 |
|
out << " * (" << *antecedent << ")" << std::endl; |
728 |
|
|
729 |
|
Assert((coeffs == RationalVectorCPSentinel) || coeffIterator > 0); |
730 |
|
--p; |
731 |
|
coeffIterator = (coeffs != RationalVectorCPSentinel) ? coeffIterator-1 : 0; |
732 |
|
antecedent = database.getAntecedent(p); |
733 |
|
} |
734 |
|
if(coeffs != RationalVectorCPSentinel){ |
735 |
|
out << coeffs->front(); |
736 |
|
} else { |
737 |
|
out << "_"; |
738 |
|
} |
739 |
|
out << " * (" << *(d_constraint->getNegation()) << ")"; |
740 |
|
out << " [not d_constraint] " << endl; |
741 |
|
} |
742 |
|
out << "}"; |
743 |
|
} |
744 |
|
|
745 |
3290497 |
bool Constraint::wellFormedFarkasProof() const { |
746 |
3290497 |
Assert(hasProof()); |
747 |
|
|
748 |
3290497 |
const ConstraintRule& cr = getConstraintRule(); |
749 |
3290497 |
if(cr.d_constraint != this){ return false; } |
750 |
3290497 |
if(cr.d_proofType != FarkasAP){ return false; } |
751 |
|
|
752 |
3290497 |
AntecedentId p = cr.d_antecedentEnd; |
753 |
|
|
754 |
|
// must have at least one antecedent |
755 |
3290497 |
ConstraintCP antecedent = d_database->d_antecedents[p]; |
756 |
3290497 |
if(antecedent == NullConstraint) { return false; } |
757 |
|
|
758 |
3290497 |
if (!d_produceProofs) |
759 |
|
{ |
760 |
2461130 |
return cr.d_farkasCoefficients == RationalVectorCPSentinel; |
761 |
|
} |
762 |
829367 |
Assert(d_produceProofs); |
763 |
|
|
764 |
829367 |
if(cr.d_farkasCoefficients == RationalVectorCPSentinel){ return false; } |
765 |
829367 |
if(cr.d_farkasCoefficients->size() < 2){ return false; } |
766 |
|
|
767 |
829367 |
const ArithVariables& vars = d_database->getArithVariables(); |
768 |
|
|
769 |
1658734 |
DeltaRational rhs(0); |
770 |
1658734 |
Node lhs = Polynomial::mkZero().getNode(); |
771 |
|
|
772 |
829367 |
RationalVector::const_iterator coeffIterator = cr.d_farkasCoefficients->end()-1; |
773 |
829367 |
RationalVector::const_iterator coeffBegin = cr.d_farkasCoefficients->begin(); |
774 |
|
|
775 |
3235953 |
while(antecedent != NullConstraint){ |
776 |
1203293 |
Assert(lhs.isNull() || Polynomial::isMember(lhs)); |
777 |
|
|
778 |
1203293 |
const Rational& coeff = *coeffIterator; |
779 |
1203293 |
int coeffSgn = coeff.sgn(); |
780 |
|
|
781 |
1203293 |
rhs += antecedent->getValue() * coeff; |
782 |
|
|
783 |
1203293 |
ArithVar antVar = antecedent->getVariable(); |
784 |
1203293 |
if(!lhs.isNull() && vars.hasNode(antVar)){ |
785 |
2406586 |
Node antAsNode = vars.asNode(antVar); |
786 |
1203293 |
if(Polynomial::isMember(antAsNode)){ |
787 |
2406586 |
Polynomial lhsPoly = Polynomial::parsePolynomial(lhs); |
788 |
2406586 |
Polynomial antPoly = Polynomial::parsePolynomial(antAsNode); |
789 |
2406586 |
Polynomial sum = lhsPoly + (antPoly * coeff); |
790 |
1203293 |
lhs = sum.getNode(); |
791 |
|
}else{ |
792 |
|
lhs = Node::null(); |
793 |
|
} |
794 |
|
} else { |
795 |
|
lhs = Node::null(); |
796 |
|
} |
797 |
1203293 |
Debug("constraints::wffp") << "running sum: " << lhs << " <= " << rhs << endl; |
798 |
|
|
799 |
1203293 |
switch( antecedent->getType() ){ |
800 |
365525 |
case LowerBound: |
801 |
|
// fc[l] < 0, therefore return false if coeffSgn >= 0 |
802 |
365525 |
if(coeffSgn >= 0){ return false; } |
803 |
365525 |
break; |
804 |
211110 |
case UpperBound: |
805 |
|
// fc[u] > 0, therefore return false if coeffSgn <= 0 |
806 |
211110 |
if(coeffSgn <= 0){ return false; } |
807 |
211110 |
break; |
808 |
626658 |
case Equality: |
809 |
626658 |
if(coeffSgn == 0) { return false; } |
810 |
626658 |
break; |
811 |
|
case Disequality: |
812 |
|
default: |
813 |
|
return false; |
814 |
|
} |
815 |
|
|
816 |
1203293 |
if(coeffIterator == coeffBegin){ return false; } |
817 |
1203293 |
--coeffIterator; |
818 |
1203293 |
--p; |
819 |
1203293 |
antecedent = d_database->d_antecedents[p]; |
820 |
|
} |
821 |
829367 |
if(coeffIterator != coeffBegin){ return false; } |
822 |
|
|
823 |
829367 |
const Rational& firstCoeff = (*coeffBegin); |
824 |
829367 |
int firstCoeffSgn = firstCoeff.sgn(); |
825 |
829367 |
rhs += (getNegation()->getValue()) * firstCoeff; |
826 |
829367 |
if(!lhs.isNull() && vars.hasNode(getVariable())){ |
827 |
1658734 |
Node firstAsNode = vars.asNode(getVariable()); |
828 |
829367 |
if(Polynomial::isMember(firstAsNode)){ |
829 |
1658734 |
Polynomial lhsPoly = Polynomial::parsePolynomial(lhs); |
830 |
1658734 |
Polynomial firstPoly = Polynomial::parsePolynomial(firstAsNode); |
831 |
1658734 |
Polynomial sum = lhsPoly + (firstPoly * firstCoeff); |
832 |
829367 |
lhs = sum.getNode(); |
833 |
|
}else{ |
834 |
|
lhs = Node::null(); |
835 |
|
} |
836 |
|
}else{ |
837 |
|
lhs = Node::null(); |
838 |
|
} |
839 |
|
|
840 |
829367 |
switch( getNegation()->getType() ){ |
841 |
244112 |
case LowerBound: |
842 |
|
// fc[l] < 0, therefore return false if coeffSgn >= 0 |
843 |
244112 |
if(firstCoeffSgn >= 0){ return false; } |
844 |
244112 |
break; |
845 |
253510 |
case UpperBound: |
846 |
|
// fc[u] > 0, therefore return false if coeffSgn <= 0 |
847 |
253510 |
if(firstCoeffSgn <= 0){ return false; } |
848 |
253510 |
break; |
849 |
331745 |
case Equality: |
850 |
331745 |
if(firstCoeffSgn == 0) { return false; } |
851 |
331745 |
break; |
852 |
|
case Disequality: |
853 |
|
default: |
854 |
|
return false; |
855 |
|
} |
856 |
829367 |
Debug("constraints::wffp") << "final sum: " << lhs << " <= " << rhs << endl; |
857 |
|
// 0 = lhs <= rhs < 0 |
858 |
2488101 |
return (lhs.isNull() || (Constant::isMember(lhs) && Constant(lhs).isZero())) |
859 |
2488101 |
&& rhs.sgn() < 0; |
860 |
|
} |
861 |
|
|
862 |
73630 |
ConstraintP Constraint::makeNegation(ArithVar v, |
863 |
|
ConstraintType t, |
864 |
|
const DeltaRational& r, |
865 |
|
bool produceProofs) |
866 |
|
{ |
867 |
73630 |
switch(t){ |
868 |
4097 |
case LowerBound: |
869 |
|
{ |
870 |
4097 |
Assert(r.infinitesimalSgn() >= 0); |
871 |
4097 |
if(r.infinitesimalSgn() > 0){ |
872 |
|
Assert(r.getInfinitesimalPart() == 1); |
873 |
|
// make (not (v > r)), which is (v <= r) |
874 |
|
DeltaRational dropInf(r.getNoninfinitesimalPart(), 0); |
875 |
|
return new Constraint(v, UpperBound, dropInf, produceProofs); |
876 |
|
}else{ |
877 |
4097 |
Assert(r.infinitesimalSgn() == 0); |
878 |
|
// make (not (v >= r)), which is (v < r) |
879 |
8194 |
DeltaRational addInf(r.getNoninfinitesimalPart(), -1); |
880 |
4097 |
return new Constraint(v, UpperBound, addInf, produceProofs); |
881 |
|
} |
882 |
|
} |
883 |
65311 |
case UpperBound: |
884 |
|
{ |
885 |
65311 |
Assert(r.infinitesimalSgn() <= 0); |
886 |
65311 |
if(r.infinitesimalSgn() < 0){ |
887 |
|
Assert(r.getInfinitesimalPart() == -1); |
888 |
|
// make (not (v < r)), which is (v >= r) |
889 |
|
DeltaRational dropInf(r.getNoninfinitesimalPart(), 0); |
890 |
|
return new Constraint(v, LowerBound, dropInf, produceProofs); |
891 |
|
}else{ |
892 |
65311 |
Assert(r.infinitesimalSgn() == 0); |
893 |
|
// make (not (v <= r)), which is (v > r) |
894 |
130622 |
DeltaRational addInf(r.getNoninfinitesimalPart(), 1); |
895 |
65311 |
return new Constraint(v, LowerBound, addInf, produceProofs); |
896 |
|
} |
897 |
|
} |
898 |
4222 |
case Equality: return new Constraint(v, Disequality, r, produceProofs); |
899 |
|
case Disequality: return new Constraint(v, Equality, r, produceProofs); |
900 |
|
default: Unreachable(); return NullConstraint; |
901 |
|
} |
902 |
|
} |
903 |
|
|
904 |
15271 |
ConstraintDatabase::ConstraintDatabase(Env& env, |
905 |
|
const ArithVariables& avars, |
906 |
|
ArithCongruenceManager& cm, |
907 |
|
RaiseConflict raiseConflict, |
908 |
15271 |
EagerProofGenerator* pfGen) |
909 |
|
: EnvObj(env), |
910 |
|
d_varDatabases(), |
911 |
|
d_toPropagate(context()), |
912 |
|
d_antecedents(context(), false), |
913 |
15271 |
d_watches(new Watches(context(), userContext())), |
914 |
|
d_avariables(avars), |
915 |
|
d_congruenceManager(cm), |
916 |
|
d_pfGen(pfGen), |
917 |
15271 |
d_pnm(d_env.isTheoryProofProducing() ? d_env.getProofNodeManager() |
918 |
|
: nullptr), |
919 |
|
d_raiseConflict(raiseConflict), |
920 |
|
d_one(1), |
921 |
45813 |
d_negOne(-1) |
922 |
|
{ |
923 |
15271 |
} |
924 |
|
|
925 |
13717735 |
SortedConstraintMap& ConstraintDatabase::getVariableSCM(ArithVar v) const{ |
926 |
13717735 |
Assert(variableDatabaseIsSetup(v)); |
927 |
13717735 |
return d_varDatabases[v]->d_constraints; |
928 |
|
} |
929 |
|
|
930 |
37574 |
void ConstraintDatabase::pushSplitWatch(ConstraintP c){ |
931 |
37574 |
Assert(!c->d_split); |
932 |
37574 |
c->d_split = true; |
933 |
37574 |
d_watches->d_splitWatches.push_back(c); |
934 |
37574 |
} |
935 |
|
|
936 |
|
|
937 |
935998 |
void ConstraintDatabase::pushCanBePropagatedWatch(ConstraintP c){ |
938 |
935998 |
Assert(!c->d_canBePropagated); |
939 |
935998 |
c->d_canBePropagated = true; |
940 |
935998 |
d_watches->d_canBePropagatedWatches.push_back(c); |
941 |
935998 |
} |
942 |
|
|
943 |
7107347 |
void ConstraintDatabase::pushAssertionOrderWatch(ConstraintP c, TNode witness){ |
944 |
7107347 |
Assert(!c->assertedToTheTheory()); |
945 |
7107347 |
c->d_assertionOrder = d_watches->d_assertionOrderWatches.size(); |
946 |
7107347 |
c->d_witness = witness; |
947 |
7107347 |
d_watches->d_assertionOrderWatches.push_back(c); |
948 |
7107347 |
} |
949 |
|
|
950 |
|
|
951 |
11336237 |
void ConstraintDatabase::pushConstraintRule(const ConstraintRule& crp){ |
952 |
11336237 |
ConstraintP c = crp.d_constraint; |
953 |
11336237 |
Assert(c->d_crid == ConstraintRuleIdSentinel); |
954 |
11336237 |
Assert(!c->hasProof()); |
955 |
11336237 |
c->d_crid = d_watches->d_constraintProofs.size(); |
956 |
11336237 |
d_watches->d_constraintProofs.push_back(crp); |
957 |
11336237 |
} |
958 |
|
|
959 |
2174376 |
ConstraintP ConstraintDatabase::getConstraint(ArithVar v, ConstraintType t, const DeltaRational& r){ |
960 |
|
//This must always return a constraint. |
961 |
|
|
962 |
2174376 |
SortedConstraintMap& scm = getVariableSCM(v); |
963 |
2174376 |
pair<SortedConstraintMapIterator, bool> insertAttempt; |
964 |
2174376 |
insertAttempt = scm.insert(make_pair(r, ValueCollection())); |
965 |
|
|
966 |
2174376 |
SortedConstraintMapIterator pos = insertAttempt.first; |
967 |
2174376 |
ValueCollection& vc = pos->second; |
968 |
2174376 |
if(vc.hasConstraintOfType(t)){ |
969 |
2100746 |
return vc.getConstraintOfType(t); |
970 |
|
}else{ |
971 |
73630 |
ConstraintP c = new Constraint(v, t, r, options().smt.produceProofs); |
972 |
|
ConstraintP negC = |
973 |
73630 |
Constraint::makeNegation(v, t, r, options().smt.produceProofs); |
974 |
|
|
975 |
73630 |
SortedConstraintMapIterator negPos; |
976 |
73630 |
if(t == Equality || t == Disequality){ |
977 |
4222 |
negPos = pos; |
978 |
|
}else{ |
979 |
69408 |
pair<SortedConstraintMapIterator, bool> negInsertAttempt; |
980 |
69408 |
negInsertAttempt = scm.insert(make_pair(negC->getValue(), ValueCollection())); |
981 |
69408 |
Assert(negInsertAttempt.second |
982 |
|
|| !negInsertAttempt.first->second.hasConstraintOfType( |
983 |
|
negC->getType())); |
984 |
69408 |
negPos = negInsertAttempt.first; |
985 |
|
} |
986 |
|
|
987 |
73630 |
c->initialize(this, pos, negC); |
988 |
73630 |
negC->initialize(this, negPos, c); |
989 |
|
|
990 |
73630 |
vc.add(c); |
991 |
73630 |
negPos->second.add(negC); |
992 |
|
|
993 |
73630 |
return c; |
994 |
|
} |
995 |
|
} |
996 |
|
|
997 |
426917 |
ConstraintP ConstraintDatabase::ensureConstraint(ValueCollection& vc, ConstraintType t){ |
998 |
426917 |
if(vc.hasConstraintOfType(t)){ |
999 |
418944 |
return vc.getConstraintOfType(t); |
1000 |
|
}else{ |
1001 |
7973 |
return getConstraint(vc.getVariable(), t, vc.getValue()); |
1002 |
|
} |
1003 |
|
} |
1004 |
|
|
1005 |
|
bool ConstraintDatabase::emptyDatabase(const std::vector<PerVariableDatabase>& vec){ |
1006 |
|
std::vector<PerVariableDatabase>::const_iterator first = vec.begin(); |
1007 |
|
std::vector<PerVariableDatabase>::const_iterator last = vec.end(); |
1008 |
|
return std::find_if(first, last, PerVariableDatabase::IsEmpty) == last; |
1009 |
|
} |
1010 |
|
|
1011 |
30532 |
ConstraintDatabase::~ConstraintDatabase(){ |
1012 |
15266 |
delete d_watches; |
1013 |
|
|
1014 |
30532 |
std::vector<ConstraintP> constraintList; |
1015 |
|
|
1016 |
376094 |
while(!d_varDatabases.empty()){ |
1017 |
180414 |
PerVariableDatabase* back = d_varDatabases.back(); |
1018 |
|
|
1019 |
180414 |
SortedConstraintMap& scm = back->d_constraints; |
1020 |
180414 |
SortedConstraintMapIterator i = scm.begin(), i_end = scm.end(); |
1021 |
1183238 |
for(; i != i_end; ++i){ |
1022 |
501412 |
(i->second).push_into(constraintList); |
1023 |
|
} |
1024 |
1669858 |
while(!constraintList.empty()){ |
1025 |
744722 |
ConstraintP c = constraintList.back(); |
1026 |
744722 |
constraintList.pop_back(); |
1027 |
744722 |
delete c; |
1028 |
|
} |
1029 |
180414 |
Assert(scm.empty()); |
1030 |
180414 |
d_varDatabases.pop_back(); |
1031 |
180414 |
delete back; |
1032 |
|
} |
1033 |
|
|
1034 |
15266 |
Assert(d_nodetoConstraintMap.empty()); |
1035 |
15266 |
} |
1036 |
|
|
1037 |
15271 |
ConstraintDatabase::Statistics::Statistics() |
1038 |
15271 |
: d_unatePropagateCalls(smtStatisticsRegistry().registerInt( |
1039 |
30542 |
"theory::arith::cd::unatePropagateCalls")), |
1040 |
15271 |
d_unatePropagateImplications(smtStatisticsRegistry().registerInt( |
1041 |
30542 |
"theory::arith::cd::unatePropagateImplications")) |
1042 |
|
{ |
1043 |
15271 |
} |
1044 |
|
|
1045 |
|
void ConstraintDatabase::deleteConstraintAndNegation(ConstraintP c){ |
1046 |
|
Assert(c->safeToGarbageCollect()); |
1047 |
|
ConstraintP neg = c->getNegation(); |
1048 |
|
Assert(neg->safeToGarbageCollect()); |
1049 |
|
delete c; |
1050 |
|
delete neg; |
1051 |
|
} |
1052 |
|
|
1053 |
180414 |
void ConstraintDatabase::addVariable(ArithVar v){ |
1054 |
180414 |
if(d_reclaimable.isMember(v)){ |
1055 |
|
SortedConstraintMap& scm = getVariableSCM(v); |
1056 |
|
|
1057 |
|
std::vector<ConstraintP> constraintList; |
1058 |
|
|
1059 |
|
for(SortedConstraintMapIterator i = scm.begin(), end = scm.end(); i != end; ++i){ |
1060 |
|
(i->second).push_into(constraintList); |
1061 |
|
} |
1062 |
|
while(!constraintList.empty()){ |
1063 |
|
ConstraintP c = constraintList.back(); |
1064 |
|
constraintList.pop_back(); |
1065 |
|
Assert(c->safeToGarbageCollect()); |
1066 |
|
delete c; |
1067 |
|
} |
1068 |
|
Assert(scm.empty()); |
1069 |
|
|
1070 |
|
d_reclaimable.remove(v); |
1071 |
|
}else{ |
1072 |
180414 |
Debug("arith::constraint") << "about to fail" << v << " " << d_varDatabases.size() << endl; |
1073 |
180414 |
Assert(v == d_varDatabases.size()); |
1074 |
180414 |
d_varDatabases.push_back(new PerVariableDatabase(v)); |
1075 |
|
} |
1076 |
180414 |
} |
1077 |
|
|
1078 |
|
void ConstraintDatabase::removeVariable(ArithVar v){ |
1079 |
|
Assert(!d_reclaimable.isMember(v)); |
1080 |
|
d_reclaimable.add(v); |
1081 |
|
} |
1082 |
|
|
1083 |
|
bool Constraint::safeToGarbageCollect() const{ |
1084 |
|
// Do not call during destructor as getNegation() may be Null by this point |
1085 |
|
Assert(getNegation() != NullConstraint); |
1086 |
|
return !contextDependentDataIsSet() && ! getNegation()->contextDependentDataIsSet(); |
1087 |
|
} |
1088 |
|
|
1089 |
746514 |
bool Constraint::contextDependentDataIsSet() const{ |
1090 |
746514 |
return hasProof() || isSplit() || canBePropagated() || assertedToTheTheory(); |
1091 |
|
} |
1092 |
|
|
1093 |
18787 |
TrustNode Constraint::split() |
1094 |
|
{ |
1095 |
18787 |
Assert(isEquality() || isDisequality()); |
1096 |
|
|
1097 |
18787 |
bool isEq = isEquality(); |
1098 |
|
|
1099 |
18787 |
ConstraintP eq = isEq ? this : d_negation; |
1100 |
18787 |
ConstraintP diseq = isEq ? d_negation : this; |
1101 |
|
|
1102 |
37574 |
TNode eqNode = eq->getLiteral(); |
1103 |
18787 |
Assert(eqNode.getKind() == kind::EQUAL); |
1104 |
37574 |
TNode lhs = eqNode[0]; |
1105 |
37574 |
TNode rhs = eqNode[1]; |
1106 |
|
|
1107 |
37574 |
Node leqNode = NodeBuilder(kind::LEQ) << lhs << rhs; |
1108 |
37574 |
Node ltNode = NodeBuilder(kind::LT) << lhs << rhs; |
1109 |
37574 |
Node gtNode = NodeBuilder(kind::GT) << lhs << rhs; |
1110 |
37574 |
Node geqNode = NodeBuilder(kind::GEQ) << lhs << rhs; |
1111 |
|
|
1112 |
37574 |
Node lemma = NodeBuilder(OR) << leqNode << geqNode; |
1113 |
|
|
1114 |
18787 |
TrustNode trustedLemma; |
1115 |
18787 |
if (d_database->isProofEnabled()) |
1116 |
|
{ |
1117 |
|
// Farkas proof that this works. |
1118 |
2529 |
auto nm = NodeManager::currentNM(); |
1119 |
5058 |
auto nLeqPf = d_database->d_pnm->mkAssume(leqNode.negate()); |
1120 |
2529 |
auto gtPf = d_database->d_pnm->mkNode( |
1121 |
5058 |
PfRule::MACRO_SR_PRED_TRANSFORM, {nLeqPf}, {gtNode}); |
1122 |
5058 |
auto nGeqPf = d_database->d_pnm->mkAssume(geqNode.negate()); |
1123 |
2529 |
auto ltPf = d_database->d_pnm->mkNode( |
1124 |
5058 |
PfRule::MACRO_SR_PRED_TRANSFORM, {nGeqPf}, {ltNode}); |
1125 |
2529 |
auto sumPf = d_database->d_pnm->mkNode( |
1126 |
|
PfRule::MACRO_ARITH_SCALE_SUM_UB, |
1127 |
|
{gtPf, ltPf}, |
1128 |
5058 |
{nm->mkConst<Rational>(-1), nm->mkConst<Rational>(1)}); |
1129 |
2529 |
auto botPf = d_database->d_pnm->mkNode( |
1130 |
5058 |
PfRule::MACRO_SR_PRED_TRANSFORM, {sumPf}, {nm->mkConst(false)}); |
1131 |
5058 |
std::vector<Node> a = {leqNode.negate(), geqNode.negate()}; |
1132 |
5058 |
auto notAndNotPf = d_database->d_pnm->mkScope(botPf, a); |
1133 |
|
// No need to ensure that the expected node aggrees with `a` because we are |
1134 |
|
// not providing an expected node. |
1135 |
|
auto orNotNotPf = |
1136 |
5058 |
d_database->d_pnm->mkNode(PfRule::NOT_AND, {notAndNotPf}, {}); |
1137 |
2529 |
auto orPf = d_database->d_pnm->mkNode( |
1138 |
5058 |
PfRule::MACRO_SR_PRED_TRANSFORM, {orNotNotPf}, {lemma}); |
1139 |
2529 |
trustedLemma = d_database->d_pfGen->mkTrustNode(lemma, orPf); |
1140 |
|
} |
1141 |
|
else |
1142 |
|
{ |
1143 |
16258 |
trustedLemma = TrustNode::mkTrustLemma(lemma); |
1144 |
|
} |
1145 |
|
|
1146 |
18787 |
eq->d_database->pushSplitWatch(eq); |
1147 |
18787 |
diseq->d_database->pushSplitWatch(diseq); |
1148 |
|
|
1149 |
37574 |
return trustedLemma; |
1150 |
|
} |
1151 |
|
|
1152 |
1202093 |
bool ConstraintDatabase::hasLiteral(TNode literal) const { |
1153 |
1202093 |
return lookup(literal) != NullConstraint; |
1154 |
|
} |
1155 |
|
|
1156 |
300523 |
ConstraintP ConstraintDatabase::addLiteral(TNode literal){ |
1157 |
300523 |
Assert(!hasLiteral(literal)); |
1158 |
300523 |
bool isNot = (literal.getKind() == NOT); |
1159 |
601046 |
Node atomNode = (isNot ? literal[0] : literal); |
1160 |
601046 |
Node negationNode = atomNode.notNode(); |
1161 |
|
|
1162 |
300523 |
Assert(!hasLiteral(atomNode)); |
1163 |
300523 |
Assert(!hasLiteral(negationNode)); |
1164 |
601046 |
Comparison posCmp = Comparison::parseNormalForm(atomNode); |
1165 |
|
|
1166 |
300523 |
ConstraintType posType = Constraint::constraintTypeOfComparison(posCmp); |
1167 |
|
|
1168 |
601046 |
Polynomial nvp = posCmp.normalizedVariablePart(); |
1169 |
300523 |
ArithVar v = d_avariables.asArithVar(nvp.getNode()); |
1170 |
|
|
1171 |
601046 |
DeltaRational posDR = posCmp.normalizedDeltaRational(); |
1172 |
|
|
1173 |
|
ConstraintP posC = |
1174 |
300523 |
new Constraint(v, posType, posDR, options().smt.produceProofs); |
1175 |
|
|
1176 |
300523 |
Debug("arith::constraint") << "addliteral( literal ->" << literal << ")" << endl; |
1177 |
300523 |
Debug("arith::constraint") << "addliteral( posC ->" << posC << ")" << endl; |
1178 |
|
|
1179 |
300523 |
SortedConstraintMap& scm = getVariableSCM(posC->getVariable()); |
1180 |
300523 |
pair<SortedConstraintMapIterator, bool> insertAttempt; |
1181 |
300523 |
insertAttempt = scm.insert(make_pair(posC->getValue(), ValueCollection())); |
1182 |
|
|
1183 |
300523 |
SortedConstraintMapIterator posI = insertAttempt.first; |
1184 |
|
// If the attempt succeeds, i points to a new empty ValueCollection |
1185 |
|
// If the attempt fails, i points to a pre-existing ValueCollection |
1186 |
|
|
1187 |
300523 |
if(posI->second.hasConstraintOfType(posC->getType())){ |
1188 |
|
//This is the situation where the ConstraintP exists, but |
1189 |
|
//the literal has not been associated with it. |
1190 |
1792 |
ConstraintP hit = posI->second.getConstraintOfType(posC->getType()); |
1191 |
1792 |
Debug("arith::constraint") << "hit " << hit << endl; |
1192 |
1792 |
Debug("arith::constraint") << "posC " << posC << endl; |
1193 |
|
|
1194 |
1792 |
delete posC; |
1195 |
|
|
1196 |
1792 |
hit->setLiteral(atomNode); |
1197 |
1792 |
hit->getNegation()->setLiteral(negationNode); |
1198 |
1792 |
return isNot ? hit->getNegation(): hit; |
1199 |
|
}else{ |
1200 |
597462 |
Comparison negCmp = Comparison::parseNormalForm(negationNode); |
1201 |
|
|
1202 |
298731 |
ConstraintType negType = Constraint::constraintTypeOfComparison(negCmp); |
1203 |
597462 |
DeltaRational negDR = negCmp.normalizedDeltaRational(); |
1204 |
|
|
1205 |
|
ConstraintP negC = |
1206 |
298731 |
new Constraint(v, negType, negDR, options().smt.produceProofs); |
1207 |
|
|
1208 |
298731 |
SortedConstraintMapIterator negI; |
1209 |
|
|
1210 |
298731 |
if(posC->isEquality()){ |
1211 |
140581 |
negI = posI; |
1212 |
|
}else{ |
1213 |
158150 |
Assert(posC->isLowerBound() || posC->isUpperBound()); |
1214 |
|
|
1215 |
158150 |
pair<SortedConstraintMapIterator, bool> negInsertAttempt; |
1216 |
158150 |
negInsertAttempt = scm.insert(make_pair(negC->getValue(), ValueCollection())); |
1217 |
|
|
1218 |
158150 |
Debug("nf::tmp") << "sdhjfgdhjkldfgljkhdfg" << endl; |
1219 |
158150 |
Debug("nf::tmp") << negC << endl; |
1220 |
158150 |
Debug("nf::tmp") << negC->getValue() << endl; |
1221 |
|
|
1222 |
|
//This should always succeed as the DeltaRational for the negation is unique! |
1223 |
158150 |
Assert(negInsertAttempt.second); |
1224 |
|
|
1225 |
158150 |
negI = negInsertAttempt.first; |
1226 |
|
} |
1227 |
|
|
1228 |
298731 |
(posI->second).add(posC); |
1229 |
298731 |
(negI->second).add(negC); |
1230 |
|
|
1231 |
298731 |
posC->initialize(this, posI, negC); |
1232 |
298731 |
negC->initialize(this, negI, posC); |
1233 |
|
|
1234 |
298731 |
posC->setLiteral(atomNode); |
1235 |
298731 |
negC->setLiteral(negationNode); |
1236 |
|
|
1237 |
298731 |
return isNot ? negC : posC; |
1238 |
|
} |
1239 |
|
} |
1240 |
|
|
1241 |
|
|
1242 |
12086060 |
ConstraintP ConstraintDatabase::lookup(TNode literal) const{ |
1243 |
12086060 |
NodetoConstraintMap::const_iterator iter = d_nodetoConstraintMap.find(literal); |
1244 |
12086060 |
if(iter == d_nodetoConstraintMap.end()){ |
1245 |
2192278 |
return NullConstraint; |
1246 |
|
}else{ |
1247 |
9893782 |
return iter->second; |
1248 |
|
} |
1249 |
|
} |
1250 |
|
|
1251 |
5704607 |
void Constraint::setAssumption(bool nowInConflict){ |
1252 |
5704607 |
Debug("constraints::pf") << "setAssumption(" << this << ")" << std::endl; |
1253 |
5704607 |
Assert(!hasProof()); |
1254 |
5704607 |
Assert(negationHasProof() == nowInConflict); |
1255 |
5704607 |
Assert(hasLiteral()); |
1256 |
5704607 |
Assert(assertedToTheTheory()); |
1257 |
|
|
1258 |
5704607 |
d_database->pushConstraintRule(ConstraintRule(this, AssumeAP)); |
1259 |
|
|
1260 |
5704607 |
Assert(inConflict() == nowInConflict); |
1261 |
5704607 |
if(Debug.isOn("constraint::conflictCommit") && inConflict()){ |
1262 |
|
Debug("constraint::conflictCommit") << "inConflict@setAssumption " << this << std::endl; |
1263 |
|
} |
1264 |
5704607 |
} |
1265 |
|
|
1266 |
5286107 |
void Constraint::tryToPropagate(){ |
1267 |
5286107 |
Assert(hasProof()); |
1268 |
5286107 |
Assert(!isAssumption()); |
1269 |
5286107 |
Assert(!isInternalAssumption()); |
1270 |
|
|
1271 |
5286107 |
if(canBePropagated() && !assertedToTheTheory() && !isAssumption() && !isInternalAssumption()){ |
1272 |
1105792 |
propagate(); |
1273 |
|
} |
1274 |
5286107 |
} |
1275 |
|
|
1276 |
1125047 |
void Constraint::propagate(){ |
1277 |
1125047 |
Assert(hasProof()); |
1278 |
1125047 |
Assert(canBePropagated()); |
1279 |
1125047 |
Assert(!assertedToTheTheory()); |
1280 |
1125047 |
Assert(!isAssumption()); |
1281 |
1125047 |
Assert(!isInternalAssumption()); |
1282 |
|
|
1283 |
1125047 |
d_database->d_toPropagate.push(this); |
1284 |
1125047 |
} |
1285 |
|
|
1286 |
|
|
1287 |
|
/* |
1288 |
|
* Example: |
1289 |
|
* x <= a and a < b |
1290 |
|
* |= x <= b |
1291 |
|
* --- |
1292 |
|
* 1*(x <= a) + (-1)*(x > b) => (0 <= a-b) |
1293 |
|
*/ |
1294 |
3174777 |
void Constraint::impliedByUnate(ConstraintCP imp, bool nowInConflict){ |
1295 |
3174777 |
Debug("constraints::pf") << "impliedByUnate(" << this << ", " << *imp << ")" << std::endl; |
1296 |
3174777 |
Assert(!hasProof()); |
1297 |
3174777 |
Assert(imp->hasProof()); |
1298 |
3174777 |
Assert(negationHasProof() == nowInConflict); |
1299 |
|
|
1300 |
3174777 |
d_database->d_antecedents.push_back(NullConstraint); |
1301 |
3174777 |
d_database->d_antecedents.push_back(imp); |
1302 |
|
|
1303 |
3174777 |
AntecedentId antecedentEnd = d_database->d_antecedents.size() - 1; |
1304 |
|
|
1305 |
|
RationalVectorP coeffs; |
1306 |
3174777 |
if (d_produceProofs) |
1307 |
|
{ |
1308 |
783681 |
std::pair<int, int> sgns = unateFarkasSigns(getNegation(), imp); |
1309 |
|
|
1310 |
1567362 |
Rational first(sgns.first); |
1311 |
1567362 |
Rational second(sgns.second); |
1312 |
|
|
1313 |
783681 |
coeffs = new RationalVector(); |
1314 |
783681 |
coeffs->push_back(first); |
1315 |
783681 |
coeffs->push_back(second); |
1316 |
|
} |
1317 |
|
else |
1318 |
|
{ |
1319 |
2391096 |
coeffs = RationalVectorPSentinel; |
1320 |
|
} |
1321 |
|
// no need to delete coeffs the memory is owned by ConstraintRule |
1322 |
3174777 |
d_database->pushConstraintRule(ConstraintRule(this, FarkasAP, antecedentEnd, coeffs)); |
1323 |
|
|
1324 |
3174777 |
Assert(inConflict() == nowInConflict); |
1325 |
3174777 |
if(Debug.isOn("constraint::conflictCommit") && inConflict()){ |
1326 |
|
Debug("constraint::conflictCommit") << "inConflict@impliedByUnate " << this << std::endl; |
1327 |
|
} |
1328 |
|
|
1329 |
3174777 |
if(Debug.isOn("constraints::wffp") && !wellFormedFarkasProof()){ |
1330 |
|
getConstraintRule().print(Debug("constraints::wffp"), d_produceProofs); |
1331 |
|
} |
1332 |
3174777 |
Assert(wellFormedFarkasProof()); |
1333 |
3174777 |
} |
1334 |
|
|
1335 |
523624 |
void Constraint::impliedByTrichotomy(ConstraintCP a, ConstraintCP b, bool nowInConflict){ |
1336 |
523624 |
Debug("constraints::pf") << "impliedByTrichotomy(" << this << ", " << *a << ", "; |
1337 |
523624 |
Debug("constraints::pf") << *b << ")" << std::endl; |
1338 |
523624 |
Assert(!hasProof()); |
1339 |
523624 |
Assert(negationHasProof() == nowInConflict); |
1340 |
523624 |
Assert(a->hasProof()); |
1341 |
523624 |
Assert(b->hasProof()); |
1342 |
|
|
1343 |
523624 |
d_database->d_antecedents.push_back(NullConstraint); |
1344 |
523624 |
d_database->d_antecedents.push_back(a); |
1345 |
523624 |
d_database->d_antecedents.push_back(b); |
1346 |
|
|
1347 |
523624 |
AntecedentId antecedentEnd = d_database->d_antecedents.size() - 1; |
1348 |
523624 |
d_database->pushConstraintRule(ConstraintRule(this, TrichotomyAP, antecedentEnd)); |
1349 |
|
|
1350 |
523624 |
Assert(inConflict() == nowInConflict); |
1351 |
523624 |
if(Debug.isOn("constraint::conflictCommit") && inConflict()){ |
1352 |
|
Debug("constraint::conflictCommit") << "inConflict@impliedByTrichotomy " << this << std::endl; |
1353 |
|
} |
1354 |
523624 |
} |
1355 |
|
|
1356 |
|
|
1357 |
115720 |
bool Constraint::allHaveProof(const ConstraintCPVec& b){ |
1358 |
1593402 |
for(ConstraintCPVec::const_iterator i=b.begin(), i_end=b.end(); i != i_end; ++i){ |
1359 |
1477682 |
ConstraintCP cp = *i; |
1360 |
1477682 |
if(! (cp->hasProof())){ return false; } |
1361 |
|
} |
1362 |
115720 |
return true; |
1363 |
|
} |
1364 |
|
|
1365 |
1555313 |
void Constraint::impliedByIntTighten(ConstraintCP a, bool nowInConflict){ |
1366 |
1555313 |
Debug("constraints::pf") << "impliedByIntTighten(" << this << ", " << *a << ")" << std::endl; |
1367 |
1555313 |
Assert(!hasProof()); |
1368 |
1555313 |
Assert(negationHasProof() == nowInConflict); |
1369 |
1555313 |
Assert(a->hasProof()); |
1370 |
3110626 |
Debug("pf::arith") << "impliedByIntTighten(" << this << ", " << a << ")" |
1371 |
1555313 |
<< std::endl; |
1372 |
|
|
1373 |
1555313 |
d_database->d_antecedents.push_back(NullConstraint); |
1374 |
1555313 |
d_database->d_antecedents.push_back(a); |
1375 |
1555313 |
AntecedentId antecedentEnd = d_database->d_antecedents.size() - 1; |
1376 |
1555313 |
d_database->pushConstraintRule(ConstraintRule(this, IntTightenAP, antecedentEnd)); |
1377 |
|
|
1378 |
1555313 |
Assert(inConflict() == nowInConflict); |
1379 |
1555313 |
if(inConflict()){ |
1380 |
3184 |
Debug("constraint::conflictCommit") << "inConflict impliedByIntTighten" << this << std::endl; |
1381 |
|
} |
1382 |
1555313 |
} |
1383 |
|
|
1384 |
|
void Constraint::impliedByIntHole(ConstraintCP a, bool nowInConflict){ |
1385 |
|
Debug("constraints::pf") << "impliedByIntHole(" << this << ", " << *a << ")" << std::endl; |
1386 |
|
Assert(!hasProof()); |
1387 |
|
Assert(negationHasProof() == nowInConflict); |
1388 |
|
Assert(a->hasProof()); |
1389 |
|
Debug("pf::arith") << "impliedByIntHole(" << this << ", " << a << ")" |
1390 |
|
<< std::endl; |
1391 |
|
|
1392 |
|
d_database->d_antecedents.push_back(NullConstraint); |
1393 |
|
d_database->d_antecedents.push_back(a); |
1394 |
|
AntecedentId antecedentEnd = d_database->d_antecedents.size() - 1; |
1395 |
|
d_database->pushConstraintRule(ConstraintRule(this, IntHoleAP, antecedentEnd)); |
1396 |
|
|
1397 |
|
Assert(inConflict() == nowInConflict); |
1398 |
|
if(Debug.isOn("constraint::conflictCommit") && inConflict()){ |
1399 |
|
Debug("constraint::conflictCommit") << "inConflict impliedByIntHole" << this << std::endl; |
1400 |
|
} |
1401 |
|
} |
1402 |
|
|
1403 |
|
void Constraint::impliedByIntHole(const ConstraintCPVec& b, bool nowInConflict){ |
1404 |
|
Debug("constraints::pf") << "impliedByIntHole(" << this; |
1405 |
|
if (Debug.isOn("constraints::pf")) { |
1406 |
|
for (const ConstraintCP& p : b) |
1407 |
|
{ |
1408 |
|
Debug("constraints::pf") << ", " << p; |
1409 |
|
} |
1410 |
|
} |
1411 |
|
Debug("constraints::pf") << ")" << std::endl; |
1412 |
|
|
1413 |
|
Assert(!hasProof()); |
1414 |
|
Assert(negationHasProof() == nowInConflict); |
1415 |
|
Assert(allHaveProof(b)); |
1416 |
|
|
1417 |
|
CDConstraintList& antecedents = d_database->d_antecedents; |
1418 |
|
antecedents.push_back(NullConstraint); |
1419 |
|
for(ConstraintCPVec::const_iterator i=b.begin(), i_end=b.end(); i != i_end; ++i){ |
1420 |
|
antecedents.push_back(*i); |
1421 |
|
} |
1422 |
|
AntecedentId antecedentEnd = antecedents.size() - 1; |
1423 |
|
|
1424 |
|
d_database->pushConstraintRule(ConstraintRule(this, IntHoleAP, antecedentEnd)); |
1425 |
|
|
1426 |
|
Assert(inConflict() == nowInConflict); |
1427 |
|
if(Debug.isOn("constraint::conflictCommit") && inConflict()){ |
1428 |
|
Debug("constraint::conflictCommit") << "inConflict@impliedByIntHole[vec] " << this << std::endl; |
1429 |
|
} |
1430 |
|
} |
1431 |
|
|
1432 |
|
/* |
1433 |
|
* If proofs are off, coeffs == RationalVectorSentinal. |
1434 |
|
* If proofs are on, |
1435 |
|
* coeffs != RationalVectorSentinal, |
1436 |
|
* coeffs->size() = a.size() + 1, |
1437 |
|
* for i in [0,a.size) : coeff[i] corresponds to a[i], and |
1438 |
|
* coeff.back() corresponds to the current constraint. |
1439 |
|
*/ |
1440 |
115720 |
void Constraint::impliedByFarkas(const ConstraintCPVec& a, RationalVectorCP coeffs, bool nowInConflict){ |
1441 |
115720 |
Debug("constraints::pf") << "impliedByFarkas(" << this; |
1442 |
115720 |
if (Debug.isOn("constraints::pf")) { |
1443 |
|
for (const ConstraintCP& p : a) |
1444 |
|
{ |
1445 |
|
Debug("constraints::pf") << ", " << p; |
1446 |
|
} |
1447 |
|
} |
1448 |
115720 |
Debug("constraints::pf") << ", <coeffs>"; |
1449 |
115720 |
Debug("constraints::pf") << ")" << std::endl; |
1450 |
115720 |
Assert(!hasProof()); |
1451 |
115720 |
Assert(negationHasProof() == nowInConflict); |
1452 |
115720 |
Assert(allHaveProof(a)); |
1453 |
|
|
1454 |
115720 |
Assert(d_produceProofs == (coeffs != RationalVectorCPSentinel)); |
1455 |
115720 |
Assert(!d_produceProofs || coeffs->size() == a.size() + 1); |
1456 |
|
|
1457 |
115720 |
Assert(a.size() >= 1); |
1458 |
|
|
1459 |
115720 |
d_database->d_antecedents.push_back(NullConstraint); |
1460 |
1593402 |
for(ConstraintCPVec::const_iterator i = a.begin(), end = a.end(); i != end; ++i){ |
1461 |
1477682 |
ConstraintCP c_i = *i; |
1462 |
1477682 |
Assert(c_i->hasProof()); |
1463 |
1477682 |
d_database->d_antecedents.push_back(c_i); |
1464 |
|
} |
1465 |
115720 |
AntecedentId antecedentEnd = d_database->d_antecedents.size() - 1; |
1466 |
|
|
1467 |
|
RationalVectorCP coeffsCopy; |
1468 |
115720 |
if (d_produceProofs) |
1469 |
|
{ |
1470 |
45686 |
Assert(coeffs != RationalVectorCPSentinel); |
1471 |
45686 |
coeffsCopy = new RationalVector(*coeffs); |
1472 |
|
} |
1473 |
|
else |
1474 |
|
{ |
1475 |
70034 |
coeffsCopy = RationalVectorCPSentinel; |
1476 |
|
} |
1477 |
115720 |
d_database->pushConstraintRule(ConstraintRule(this, FarkasAP, antecedentEnd, coeffsCopy)); |
1478 |
|
|
1479 |
115720 |
Assert(inConflict() == nowInConflict); |
1480 |
115720 |
if(Debug.isOn("constraint::conflictCommit") && inConflict()){ |
1481 |
|
Debug("constraint::conflictCommit") << "inConflict@impliedByFarkas " << this << std::endl; |
1482 |
|
} |
1483 |
115720 |
if(Debug.isOn("constraints::wffp") && !wellFormedFarkasProof()){ |
1484 |
|
getConstraintRule().print(Debug("constraints::wffp"), d_produceProofs); |
1485 |
|
} |
1486 |
115720 |
Assert(wellFormedFarkasProof()); |
1487 |
115720 |
} |
1488 |
|
|
1489 |
|
|
1490 |
|
void Constraint::setInternalAssumption(bool nowInConflict){ |
1491 |
|
Debug("constraints::pf") << "setInternalAssumption(" << this; |
1492 |
|
Debug("constraints::pf") << ")" << std::endl; |
1493 |
|
Assert(!hasProof()); |
1494 |
|
Assert(negationHasProof() == nowInConflict); |
1495 |
|
Assert(!assertedToTheTheory()); |
1496 |
|
|
1497 |
|
d_database->pushConstraintRule(ConstraintRule(this, InternalAssumeAP)); |
1498 |
|
|
1499 |
|
Assert(inConflict() == nowInConflict); |
1500 |
|
if(Debug.isOn("constraint::conflictCommit") && inConflict()){ |
1501 |
|
Debug("constraint::conflictCommit") << "inConflict@setInternalAssumption " << this << std::endl; |
1502 |
|
} |
1503 |
|
} |
1504 |
|
|
1505 |
|
|
1506 |
262196 |
void Constraint::setEqualityEngineProof(){ |
1507 |
262196 |
Debug("constraints::pf") << "setEqualityEngineProof(" << this; |
1508 |
262196 |
Debug("constraints::pf") << ")" << std::endl; |
1509 |
262196 |
Assert(truthIsUnknown()); |
1510 |
262196 |
Assert(hasLiteral()); |
1511 |
262196 |
d_database->pushConstraintRule(ConstraintRule(this, EqualityEngineAP)); |
1512 |
262196 |
} |
1513 |
|
|
1514 |
|
|
1515 |
4847613 |
SortedConstraintMap& Constraint::constraintSet() const{ |
1516 |
4847613 |
Assert(d_database->variableDatabaseIsSetup(d_variable)); |
1517 |
4847613 |
return (d_database->d_varDatabases[d_variable])->d_constraints; |
1518 |
|
} |
1519 |
|
|
1520 |
|
bool Constraint::antecentListIsEmpty() const{ |
1521 |
|
Assert(hasProof()); |
1522 |
|
return d_database->d_antecedents[getEndAntecedent()] == NullConstraint; |
1523 |
|
} |
1524 |
|
|
1525 |
|
bool Constraint::antecedentListLengthIsOne() const { |
1526 |
|
Assert(hasProof()); |
1527 |
|
return !antecentListIsEmpty() && |
1528 |
|
d_database->d_antecedents[getEndAntecedent()-1] == NullConstraint; |
1529 |
|
} |
1530 |
|
|
1531 |
133400 |
Node Constraint::externalImplication(const ConstraintCPVec& b) const{ |
1532 |
133400 |
Assert(hasLiteral()); |
1533 |
266800 |
Node antecedent = externalExplainByAssertions(b); |
1534 |
266800 |
Node implied = getLiteral(); |
1535 |
266800 |
return antecedent.impNode(implied); |
1536 |
|
} |
1537 |
|
|
1538 |
|
|
1539 |
1557886 |
Node Constraint::externalExplainByAssertions(const ConstraintCPVec& b){ |
1540 |
1557886 |
return externalExplain(b, AssertionOrderSentinel); |
1541 |
|
} |
1542 |
|
|
1543 |
17726 |
TrustNode Constraint::externalExplainForPropagation(TNode lit) const |
1544 |
|
{ |
1545 |
17726 |
Assert(hasProof()); |
1546 |
17726 |
Assert(!isAssumption()); |
1547 |
17726 |
Assert(!isInternalAssumption()); |
1548 |
35452 |
NodeBuilder nb(Kind::AND); |
1549 |
35452 |
auto pfFromAssumptions = externalExplain(nb, d_assertionOrder); |
1550 |
35452 |
Node n = safeConstructNary(nb); |
1551 |
17726 |
if (d_database->isProofEnabled()) |
1552 |
|
{ |
1553 |
|
// Check that the literal we're explaining via this constraint actually |
1554 |
|
// matches the constraint's canonical literal. |
1555 |
2428 |
Assert(Rewriter::rewrite(lit) == getLiteral()); |
1556 |
4856 |
std::vector<Node> assumptions; |
1557 |
2428 |
if (n.getKind() == Kind::AND) |
1558 |
|
{ |
1559 |
1464 |
assumptions.insert(assumptions.end(), n.begin(), n.end()); |
1560 |
|
} |
1561 |
|
else |
1562 |
|
{ |
1563 |
964 |
assumptions.push_back(n); |
1564 |
|
} |
1565 |
2428 |
if (getProofLiteral() != lit) |
1566 |
|
{ |
1567 |
4761 |
pfFromAssumptions = d_database->d_pnm->mkNode( |
1568 |
3174 |
PfRule::MACRO_SR_PRED_TRANSFORM, {pfFromAssumptions}, {lit}); |
1569 |
|
} |
1570 |
4856 |
auto pf = d_database->d_pnm->mkScope(pfFromAssumptions, assumptions); |
1571 |
2428 |
return d_database->d_pfGen->mkTrustedPropagation( |
1572 |
2428 |
lit, safeConstructNary(Kind::AND, assumptions), pf); |
1573 |
|
} |
1574 |
|
else |
1575 |
|
{ |
1576 |
15298 |
return TrustNode::mkTrustPropExp(lit, n); |
1577 |
|
} |
1578 |
|
} |
1579 |
|
|
1580 |
90615 |
TrustNode Constraint::externalExplainConflict() const |
1581 |
|
{ |
1582 |
90615 |
Debug("pf::arith::explain") << this << std::endl; |
1583 |
90615 |
Assert(inConflict()); |
1584 |
181230 |
NodeBuilder nb(kind::AND); |
1585 |
181230 |
auto pf1 = externalExplainByAssertions(nb); |
1586 |
181230 |
auto not2 = getNegation()->getProofLiteral().negate(); |
1587 |
181230 |
auto pf2 = getNegation()->externalExplainByAssertions(nb); |
1588 |
181230 |
Node n = safeConstructNary(nb); |
1589 |
90615 |
if (d_database->isProofEnabled()) |
1590 |
|
{ |
1591 |
13064 |
auto pfNot2 = d_database->d_pnm->mkNode( |
1592 |
26128 |
PfRule::MACRO_SR_PRED_TRANSFORM, {pf1}, {not2}); |
1593 |
26128 |
std::vector<Node> lits; |
1594 |
13064 |
if (n.getKind() == Kind::AND) |
1595 |
|
{ |
1596 |
13064 |
lits.insert(lits.end(), n.begin(), n.end()); |
1597 |
|
} |
1598 |
|
else |
1599 |
|
{ |
1600 |
|
lits.push_back(n); |
1601 |
|
} |
1602 |
13064 |
if (Debug.isOn("arith::pf::externalExplainConflict")) |
1603 |
|
{ |
1604 |
|
Debug("arith::pf::externalExplainConflict") << "Lits:" << std::endl; |
1605 |
|
for (const auto& l : lits) |
1606 |
|
{ |
1607 |
|
Debug("arith::pf::externalExplainConflict") << " : " << l << std::endl; |
1608 |
|
} |
1609 |
|
} |
1610 |
|
std::vector<Node> contraLits = {getProofLiteral(), |
1611 |
26128 |
getNegation()->getProofLiteral()}; |
1612 |
|
auto bot = |
1613 |
13064 |
not2.getKind() == Kind::NOT |
1614 |
36309 |
? d_database->d_pnm->mkNode(PfRule::CONTRA, {pf2, pfNot2}, {}) |
1615 |
51295 |
: d_database->d_pnm->mkNode(PfRule::CONTRA, {pfNot2, pf2}, {}); |
1616 |
13064 |
if (Debug.isOn("arith::pf::tree")) |
1617 |
|
{ |
1618 |
|
Debug("arith::pf::tree") << *this << std::endl; |
1619 |
|
Debug("arith::pf::tree") << *getNegation() << std::endl; |
1620 |
|
Debug("arith::pf::tree") << "\n\nTree:\n"; |
1621 |
|
printProofTree(Debug("arith::pf::tree")); |
1622 |
|
getNegation()->printProofTree(Debug("arith::pf::tree")); |
1623 |
|
} |
1624 |
26128 |
auto confPf = d_database->d_pnm->mkScope(bot, lits); |
1625 |
13064 |
return d_database->d_pfGen->mkTrustNode( |
1626 |
13064 |
safeConstructNary(Kind::AND, lits), confPf, true); |
1627 |
|
} |
1628 |
|
else |
1629 |
|
{ |
1630 |
77551 |
return TrustNode::mkTrustConflict(n); |
1631 |
|
} |
1632 |
|
} |
1633 |
|
|
1634 |
|
struct ConstraintCPHash { |
1635 |
|
/* Todo replace with an id */ |
1636 |
|
size_t operator()(ConstraintCP c) const{ |
1637 |
|
Assert(sizeof(ConstraintCP) > 0); |
1638 |
|
return ((size_t)c)/sizeof(ConstraintCP); |
1639 |
|
} |
1640 |
|
}; |
1641 |
|
|
1642 |
|
void Constraint::assertionFringe(ConstraintCPVec& v){ |
1643 |
|
unordered_set<ConstraintCP, ConstraintCPHash> visited; |
1644 |
|
size_t writePos = 0; |
1645 |
|
|
1646 |
|
if(!v.empty()){ |
1647 |
|
const ConstraintDatabase* db = v.back()->d_database; |
1648 |
|
const CDConstraintList& antecedents = db->d_antecedents; |
1649 |
|
for(size_t i = 0; i < v.size(); ++i){ |
1650 |
|
ConstraintCP vi = v[i]; |
1651 |
|
if(visited.find(vi) == visited.end()){ |
1652 |
|
Assert(vi->hasProof()); |
1653 |
|
visited.insert(vi); |
1654 |
|
if(vi->onFringe()){ |
1655 |
|
v[writePos] = vi; |
1656 |
|
writePos++; |
1657 |
|
}else{ |
1658 |
|
Assert(vi->hasTrichotomyProof() || vi->hasFarkasProof() |
1659 |
|
|| vi->hasIntHoleProof() || vi->hasIntTightenProof()); |
1660 |
|
AntecedentId p = vi->getEndAntecedent(); |
1661 |
|
|
1662 |
|
ConstraintCP antecedent = antecedents[p]; |
1663 |
|
while(antecedent != NullConstraint){ |
1664 |
|
v.push_back(antecedent); |
1665 |
|
--p; |
1666 |
|
antecedent = antecedents[p]; |
1667 |
|
} |
1668 |
|
} |
1669 |
|
} |
1670 |
|
} |
1671 |
|
v.resize(writePos); |
1672 |
|
} |
1673 |
|
} |
1674 |
|
|
1675 |
|
void Constraint::assertionFringe(ConstraintCPVec& o, const ConstraintCPVec& i){ |
1676 |
|
o.insert(o.end(), i.begin(), i.end()); |
1677 |
|
assertionFringe(o); |
1678 |
|
} |
1679 |
|
|
1680 |
1557886 |
Node Constraint::externalExplain(const ConstraintCPVec& v, AssertionOrder order){ |
1681 |
3115772 |
NodeBuilder nb(kind::AND); |
1682 |
1557886 |
ConstraintCPVec::const_iterator i, end; |
1683 |
3449673 |
for(i = v.begin(), end = v.end(); i != end; ++i){ |
1684 |
1891787 |
ConstraintCP v_i = *i; |
1685 |
1891787 |
v_i->externalExplain(nb, order); |
1686 |
|
} |
1687 |
3115772 |
return safeConstructNary(nb); |
1688 |
|
} |
1689 |
|
|
1690 |
6789550 |
std::shared_ptr<ProofNode> Constraint::externalExplain( |
1691 |
|
NodeBuilder& nb, AssertionOrder order) const |
1692 |
|
{ |
1693 |
6789550 |
if (Debug.isOn("pf::arith::explain")) |
1694 |
|
{ |
1695 |
|
this->printProofTree(Debug("arith::pf::tree")); |
1696 |
|
Debug("pf::arith::explain") << "Explaining: " << this << " with rule "; |
1697 |
|
getConstraintRule().print(Debug("pf::arith::explain"), d_produceProofs); |
1698 |
|
Debug("pf::arith::explain") << std::endl; |
1699 |
|
} |
1700 |
6789550 |
Assert(hasProof()); |
1701 |
6789550 |
Assert(!isAssumption() || assertedToTheTheory()); |
1702 |
6789550 |
Assert(!isInternalAssumption()); |
1703 |
6789550 |
std::shared_ptr<ProofNode> pf{}; |
1704 |
|
|
1705 |
6789550 |
ProofNodeManager* pnm = d_database->d_pnm; |
1706 |
|
|
1707 |
6789550 |
if (assertedBefore(order)) |
1708 |
|
{ |
1709 |
6087878 |
Debug("pf::arith::explain") << " already asserted" << std::endl; |
1710 |
6087878 |
nb << getWitness(); |
1711 |
6087878 |
if (d_database->isProofEnabled()) |
1712 |
|
{ |
1713 |
685327 |
pf = pnm->mkAssume(getWitness()); |
1714 |
|
// If the witness and literal differ, prove the difference through a |
1715 |
|
// rewrite. |
1716 |
685327 |
if (getWitness() != getProofLiteral()) |
1717 |
|
{ |
1718 |
1349010 |
pf = pnm->mkNode( |
1719 |
899340 |
PfRule::MACRO_SR_PRED_TRANSFORM, {pf}, {getProofLiteral()}); |
1720 |
|
} |
1721 |
|
} |
1722 |
|
} |
1723 |
701672 |
else if (hasEqualityEngineProof()) |
1724 |
|
{ |
1725 |
7159 |
Debug("pf::arith::explain") << " going to ee:" << std::endl; |
1726 |
14318 |
TrustNode exp = d_database->eeExplain(this); |
1727 |
7159 |
if (d_database->isProofEnabled()) |
1728 |
|
{ |
1729 |
965 |
Assert(exp.getProven().getKind() == Kind::IMPLIES); |
1730 |
1930 |
std::vector<std::shared_ptr<ProofNode>> hypotheses; |
1731 |
965 |
hypotheses.push_back(exp.getGenerator()->getProofFor(exp.getProven())); |
1732 |
965 |
if (exp.getNode().getKind() == Kind::AND) |
1733 |
|
{ |
1734 |
3254 |
for (const auto& h : exp.getNode()) |
1735 |
|
{ |
1736 |
2390 |
hypotheses.push_back( |
1737 |
4780 |
pnm->mkNode(PfRule::TRUE_INTRO, {pnm->mkAssume(h)}, {})); |
1738 |
|
} |
1739 |
|
} |
1740 |
|
else |
1741 |
|
{ |
1742 |
404 |
hypotheses.push_back(pnm->mkNode( |
1743 |
303 |
PfRule::TRUE_INTRO, {pnm->mkAssume(exp.getNode())}, {})); |
1744 |
|
} |
1745 |
1930 |
pf = pnm->mkNode( |
1746 |
965 |
PfRule::MACRO_SR_PRED_TRANSFORM, {hypotheses}, {getProofLiteral()}); |
1747 |
|
} |
1748 |
14318 |
Debug("pf::arith::explain") |
1749 |
7159 |
<< " explanation: " << exp.getNode() << std::endl; |
1750 |
7159 |
if (exp.getNode().getKind() == Kind::AND) |
1751 |
|
{ |
1752 |
6215 |
nb.append(exp.getNode().begin(), exp.getNode().end()); |
1753 |
|
} |
1754 |
|
else |
1755 |
|
{ |
1756 |
944 |
nb << exp.getNode(); |
1757 |
|
} |
1758 |
|
} |
1759 |
|
else |
1760 |
|
{ |
1761 |
694513 |
Debug("pf::arith::explain") << " recursion!" << std::endl; |
1762 |
694513 |
Assert(!isAssumption()); |
1763 |
694513 |
AntecedentId p = getEndAntecedent(); |
1764 |
694513 |
ConstraintCP antecedent = d_database->d_antecedents[p]; |
1765 |
1389026 |
std::vector<std::shared_ptr<ProofNode>> children; |
1766 |
|
|
1767 |
4055513 |
while (antecedent != NullConstraint) |
1768 |
|
{ |
1769 |
1680500 |
Debug("pf::arith::explain") << "Explain " << antecedent << std::endl; |
1770 |
3361000 |
auto pn = antecedent->externalExplain(nb, order); |
1771 |
1680500 |
if (d_database->isProofEnabled()) |
1772 |
|
{ |
1773 |
161936 |
children.push_back(pn); |
1774 |
|
} |
1775 |
1680500 |
--p; |
1776 |
1680500 |
antecedent = d_database->d_antecedents[p]; |
1777 |
|
} |
1778 |
|
|
1779 |
694513 |
if (d_database->isProofEnabled()) |
1780 |
|
{ |
1781 |
90149 |
switch (getProofType()) |
1782 |
|
{ |
1783 |
|
case ArithProofType::AssumeAP: |
1784 |
|
case ArithProofType::EqualityEngineAP: |
1785 |
|
{ |
1786 |
|
Unreachable() << "These should be handled above"; |
1787 |
|
break; |
1788 |
|
} |
1789 |
13594 |
case ArithProofType::FarkasAP: |
1790 |
|
{ |
1791 |
|
// Per docs in constraint.h, |
1792 |
|
// the 0th farkas coefficient is for the negation of the deduced |
1793 |
|
// constraint the 1st corresponds to the last antecedent the nth |
1794 |
|
// corresponds to the first antecedent Then, the farkas coefficients |
1795 |
|
// and the antecedents are in the same order. |
1796 |
|
|
1797 |
|
// Enumerate child proofs (negation included) in d_farkasCoefficients |
1798 |
|
// order |
1799 |
27188 |
std::vector<std::shared_ptr<ProofNode>> farkasChildren; |
1800 |
13594 |
farkasChildren.push_back( |
1801 |
27188 |
pnm->mkAssume(getNegation()->getProofLiteral())); |
1802 |
13594 |
farkasChildren.insert( |
1803 |
27188 |
farkasChildren.end(), children.rbegin(), children.rend()); |
1804 |
|
|
1805 |
13594 |
NodeManager* nm = NodeManager::currentNM(); |
1806 |
|
|
1807 |
|
// Enumerate d_farkasCoefficients as nodes. |
1808 |
27188 |
std::vector<Node> farkasCoeffs; |
1809 |
105811 |
for (Rational r : *getFarkasCoefficients()) |
1810 |
|
{ |
1811 |
92217 |
farkasCoeffs.push_back(nm->mkConst<Rational>(r)); |
1812 |
|
} |
1813 |
|
|
1814 |
|
// Apply the scaled-sum rule. |
1815 |
|
std::shared_ptr<ProofNode> sumPf = pnm->mkNode( |
1816 |
27188 |
PfRule::MACRO_ARITH_SCALE_SUM_UB, farkasChildren, farkasCoeffs); |
1817 |
|
|
1818 |
|
// Provable rewrite the result |
1819 |
|
auto botPf = pnm->mkNode( |
1820 |
27188 |
PfRule::MACRO_SR_PRED_TRANSFORM, {sumPf}, {nm->mkConst(false)}); |
1821 |
|
|
1822 |
|
// Scope out the negated constraint, yielding a proof of the |
1823 |
|
// constraint. |
1824 |
27188 |
std::vector<Node> assump{getNegation()->getProofLiteral()}; |
1825 |
27188 |
auto maybeDoubleNotPf = pnm->mkScope(botPf, assump, false); |
1826 |
|
|
1827 |
|
// No need to ensure that the expected node aggrees with `assump` |
1828 |
|
// because we are not providing an expected node. |
1829 |
|
// |
1830 |
|
// Prove that this is the literal (may need to clean a double-not) |
1831 |
40782 |
pf = pnm->mkNode(PfRule::MACRO_SR_PRED_TRANSFORM, |
1832 |
|
{maybeDoubleNotPf}, |
1833 |
27188 |
{getProofLiteral()}); |
1834 |
|
|
1835 |
13594 |
break; |
1836 |
|
} |
1837 |
69797 |
case ArithProofType::IntTightenAP: |
1838 |
|
{ |
1839 |
69797 |
if (isUpperBound()) |
1840 |
|
{ |
1841 |
67542 |
pf = pnm->mkNode( |
1842 |
135084 |
PfRule::INT_TIGHT_UB, children, {}, getProofLiteral()); |
1843 |
|
} |
1844 |
2255 |
else if (isLowerBound()) |
1845 |
|
{ |
1846 |
2255 |
pf = pnm->mkNode( |
1847 |
4510 |
PfRule::INT_TIGHT_LB, children, {}, getProofLiteral()); |
1848 |
|
} |
1849 |
|
else |
1850 |
|
{ |
1851 |
|
Unreachable(); |
1852 |
|
} |
1853 |
69797 |
break; |
1854 |
|
} |
1855 |
|
case ArithProofType::IntHoleAP: |
1856 |
|
{ |
1857 |
|
Node t = |
1858 |
|
builtin::BuiltinProofRuleChecker::mkTheoryIdNode(THEORY_ARITH); |
1859 |
|
pf = pnm->mkNode(PfRule::THEORY_INFERENCE, |
1860 |
|
children, |
1861 |
|
{getProofLiteral(), t}, |
1862 |
|
getProofLiteral()); |
1863 |
|
break; |
1864 |
|
} |
1865 |
6758 |
case ArithProofType::TrichotomyAP: |
1866 |
|
{ |
1867 |
13516 |
pf = pnm->mkNode(PfRule::ARITH_TRICHOTOMY, |
1868 |
|
children, |
1869 |
|
{getProofLiteral()}, |
1870 |
20274 |
getProofLiteral()); |
1871 |
6758 |
break; |
1872 |
|
} |
1873 |
|
case ArithProofType::InternalAssumeAP: |
1874 |
|
case ArithProofType::NoAP: |
1875 |
|
default: |
1876 |
|
{ |
1877 |
|
Unreachable() << getProofType() |
1878 |
|
<< " should not be visible in explanation"; |
1879 |
|
break; |
1880 |
|
} |
1881 |
|
} |
1882 |
|
} |
1883 |
|
} |
1884 |
6789550 |
return pf; |
1885 |
|
} |
1886 |
|
|
1887 |
1851 |
Node Constraint::externalExplainByAssertions(ConstraintCP a, ConstraintCP b){ |
1888 |
3702 |
NodeBuilder nb(kind::AND); |
1889 |
1851 |
a->externalExplainByAssertions(nb); |
1890 |
1851 |
b->externalExplainByAssertions(nb); |
1891 |
3702 |
return nb; |
1892 |
|
} |
1893 |
|
|
1894 |
|
Node Constraint::externalExplainByAssertions(ConstraintCP a, ConstraintCP b, ConstraintCP c){ |
1895 |
|
NodeBuilder nb(kind::AND); |
1896 |
|
a->externalExplainByAssertions(nb); |
1897 |
|
b->externalExplainByAssertions(nb); |
1898 |
|
c->externalExplainByAssertions(nb); |
1899 |
|
return nb; |
1900 |
|
} |
1901 |
|
|
1902 |
771476 |
ConstraintP Constraint::getStrictlyWeakerLowerBound(bool hasLiteral, bool asserted) const { |
1903 |
771476 |
Assert(initialized()); |
1904 |
771476 |
Assert(!asserted || hasLiteral); |
1905 |
|
|
1906 |
771476 |
SortedConstraintMapConstIterator i = d_variablePosition; |
1907 |
771476 |
const SortedConstraintMap& scm = constraintSet(); |
1908 |
771476 |
SortedConstraintMapConstIterator i_begin = scm.begin(); |
1909 |
2569802 |
while(i != i_begin){ |
1910 |
1040160 |
--i; |
1911 |
1040160 |
const ValueCollection& vc = i->second; |
1912 |
1040160 |
if(vc.hasLowerBound()){ |
1913 |
290529 |
ConstraintP weaker = vc.getLowerBound(); |
1914 |
|
|
1915 |
|
// asserted -> hasLiteral |
1916 |
|
// hasLiteral -> weaker->hasLiteral() |
1917 |
|
// asserted -> weaker->assertedToTheTheory() |
1918 |
585907 |
if((!hasLiteral || (weaker->hasLiteral())) && |
1919 |
307523 |
(!asserted || ( weaker->assertedToTheTheory()))){ |
1920 |
140997 |
return weaker; |
1921 |
|
} |
1922 |
|
} |
1923 |
|
} |
1924 |
630479 |
return NullConstraint; |
1925 |
|
} |
1926 |
|
|
1927 |
411835 |
ConstraintP Constraint::getStrictlyWeakerUpperBound(bool hasLiteral, bool asserted) const { |
1928 |
411835 |
SortedConstraintMapConstIterator i = d_variablePosition; |
1929 |
411835 |
const SortedConstraintMap& scm = constraintSet(); |
1930 |
411835 |
SortedConstraintMapConstIterator i_end = scm.end(); |
1931 |
|
|
1932 |
411835 |
++i; |
1933 |
1224357 |
for(; i != i_end; ++i){ |
1934 |
561747 |
const ValueCollection& vc = i->second; |
1935 |
561747 |
if(vc.hasUpperBound()){ |
1936 |
211376 |
ConstraintP weaker = vc.getUpperBound(); |
1937 |
535351 |
if((!hasLiteral || (weaker->hasLiteral())) && |
1938 |
331640 |
(!asserted || ( weaker->assertedToTheTheory()))){ |
1939 |
155486 |
return weaker; |
1940 |
|
} |
1941 |
|
} |
1942 |
|
} |
1943 |
|
|
1944 |
256349 |
return NullConstraint; |
1945 |
|
} |
1946 |
|
|
1947 |
10616306 |
ConstraintP ConstraintDatabase::getBestImpliedBound(ArithVar v, ConstraintType t, const DeltaRational& r) const { |
1948 |
10616306 |
Assert(variableDatabaseIsSetup(v)); |
1949 |
10616306 |
Assert(t == UpperBound || t == LowerBound); |
1950 |
|
|
1951 |
10616306 |
SortedConstraintMap& scm = getVariableSCM(v); |
1952 |
10616306 |
if(t == UpperBound){ |
1953 |
5363827 |
SortedConstraintMapConstIterator i = scm.lower_bound(r); |
1954 |
5363827 |
SortedConstraintMapConstIterator i_end = scm.end(); |
1955 |
5363827 |
Assert(i == i_end || r <= i->first); |
1956 |
10928693 |
for(; i != i_end; i++){ |
1957 |
4728765 |
Assert(r <= i->first); |
1958 |
4728765 |
const ValueCollection& vc = i->second; |
1959 |
4728765 |
if(vc.hasUpperBound()){ |
1960 |
1946332 |
return vc.getUpperBound(); |
1961 |
|
} |
1962 |
|
} |
1963 |
3417495 |
return NullConstraint; |
1964 |
|
}else{ |
1965 |
5252479 |
Assert(t == LowerBound); |
1966 |
5252479 |
if(scm.empty()){ |
1967 |
314361 |
return NullConstraint; |
1968 |
|
}else{ |
1969 |
4938118 |
SortedConstraintMapConstIterator i = scm.lower_bound(r); |
1970 |
4938118 |
SortedConstraintMapConstIterator i_begin = scm.begin(); |
1971 |
4938118 |
SortedConstraintMapConstIterator i_end = scm.end(); |
1972 |
4938118 |
Assert(i == i_end || r <= i->first); |
1973 |
|
|
1974 |
4938118 |
int fdj = 0; |
1975 |
|
|
1976 |
4938118 |
if(i == i_end){ |
1977 |
2219992 |
--i; |
1978 |
2219992 |
Debug("getBestImpliedBound") << fdj++ << " " << r << " " << i->first << endl; |
1979 |
2718126 |
}else if( (i->first) > r){ |
1980 |
776012 |
if(i == i_begin){ |
1981 |
702547 |
return NullConstraint; |
1982 |
|
}else{ |
1983 |
73465 |
--i; |
1984 |
73465 |
Debug("getBestImpliedBound") << fdj++ << " " << r << " " << i->first << endl; |
1985 |
|
} |
1986 |
|
} |
1987 |
|
|
1988 |
|
do{ |
1989 |
4767227 |
Debug("getBestImpliedBound") << fdj++ << " " << r << " " << i->first << endl; |
1990 |
4767227 |
Assert(r >= i->first); |
1991 |
4767227 |
const ValueCollection& vc = i->second; |
1992 |
|
|
1993 |
4767227 |
if(vc.hasLowerBound()){ |
1994 |
2147095 |
return vc.getLowerBound(); |
1995 |
|
} |
1996 |
|
|
1997 |
2620132 |
if(i == i_begin){ |
1998 |
2088476 |
break; |
1999 |
|
}else{ |
2000 |
531656 |
--i; |
2001 |
531656 |
} |
2002 |
|
}while(true); |
2003 |
2088476 |
return NullConstraint; |
2004 |
|
} |
2005 |
|
} |
2006 |
|
} |
2007 |
7159 |
TrustNode ConstraintDatabase::eeExplain(const Constraint* const c) const |
2008 |
|
{ |
2009 |
7159 |
Assert(c->hasLiteral()); |
2010 |
7159 |
return d_congruenceManager.explain(c->getLiteral()); |
2011 |
|
} |
2012 |
|
|
2013 |
|
void ConstraintDatabase::eeExplain(ConstraintCP c, NodeBuilder& nb) const |
2014 |
|
{ |
2015 |
|
Assert(c->hasLiteral()); |
2016 |
|
// NOTE: this is not a recommended method since it ignores proofs |
2017 |
|
d_congruenceManager.explain(c->getLiteral(), nb); |
2018 |
|
} |
2019 |
|
|
2020 |
29181654 |
bool ConstraintDatabase::variableDatabaseIsSetup(ArithVar v) const { |
2021 |
29181654 |
return v < d_varDatabases.size(); |
2022 |
|
} |
2023 |
|
|
2024 |
|
|
2025 |
15271 |
ConstraintDatabase::Watches::Watches(context::Context* satContext, context::Context* userContext): |
2026 |
|
d_constraintProofs(satContext), |
2027 |
|
d_canBePropagatedWatches(satContext), |
2028 |
|
d_assertionOrderWatches(satContext), |
2029 |
15271 |
d_splitWatches(userContext) |
2030 |
15271 |
{} |
2031 |
|
|
2032 |
|
|
2033 |
601046 |
void Constraint::setLiteral(Node n) { |
2034 |
601046 |
Debug("arith::constraint") << "Mapping " << *this << " to " << n << std::endl; |
2035 |
601046 |
Assert(Comparison::isNormalAtom(n)); |
2036 |
601046 |
Assert(!hasLiteral()); |
2037 |
601046 |
Assert(sanityChecking(n)); |
2038 |
601046 |
d_literal = n; |
2039 |
601046 |
NodetoConstraintMap& map = d_database->d_nodetoConstraintMap; |
2040 |
601046 |
Assert(map.find(n) == map.end()); |
2041 |
601046 |
map.insert(make_pair(d_literal, this)); |
2042 |
601046 |
} |
2043 |
|
|
2044 |
1429334 |
Node Constraint::getProofLiteral() const |
2045 |
|
{ |
2046 |
1429334 |
Assert(d_database != nullptr); |
2047 |
1429334 |
Assert(d_database->d_avariables.hasNode(d_variable)); |
2048 |
2858668 |
Node varPart = d_database->d_avariables.asNode(d_variable); |
2049 |
|
Kind cmp; |
2050 |
1429334 |
bool neg = false; |
2051 |
1429334 |
switch (d_type) |
2052 |
|
{ |
2053 |
545953 |
case ConstraintType::UpperBound: |
2054 |
|
{ |
2055 |
545953 |
if (d_value.infinitesimalIsZero()) |
2056 |
|
{ |
2057 |
153422 |
cmp = Kind::LEQ; |
2058 |
|
} |
2059 |
|
else |
2060 |
|
{ |
2061 |
392531 |
cmp = Kind::LT; |
2062 |
|
} |
2063 |
545953 |
break; |
2064 |
|
} |
2065 |
228775 |
case ConstraintType::LowerBound: |
2066 |
|
{ |
2067 |
228775 |
if (d_value.infinitesimalIsZero()) |
2068 |
|
{ |
2069 |
188361 |
cmp = Kind::GEQ; |
2070 |
|
} |
2071 |
|
else |
2072 |
|
{ |
2073 |
40414 |
cmp = Kind::GT; |
2074 |
|
} |
2075 |
228775 |
break; |
2076 |
|
} |
2077 |
520216 |
case ConstraintType::Equality: |
2078 |
|
{ |
2079 |
520216 |
cmp = Kind::EQUAL; |
2080 |
520216 |
break; |
2081 |
|
} |
2082 |
134390 |
case ConstraintType::Disequality: |
2083 |
|
{ |
2084 |
134390 |
cmp = Kind::EQUAL; |
2085 |
134390 |
neg = true; |
2086 |
134390 |
break; |
2087 |
|
} |
2088 |
|
default: Unreachable() << d_type; |
2089 |
|
} |
2090 |
1429334 |
NodeManager* nm = NodeManager::currentNM(); |
2091 |
2858668 |
Node constPart = nm->mkConst<Rational>(d_value.getNoninfinitesimalPart()); |
2092 |
2858668 |
Node posLit = nm->mkNode(cmp, varPart, constPart); |
2093 |
2858668 |
return neg ? posLit.negate() : posLit; |
2094 |
|
} |
2095 |
|
|
2096 |
40209 |
void ConstraintDatabase::proveOr(std::vector<TrustNode>& out, |
2097 |
|
ConstraintP a, |
2098 |
|
ConstraintP b, |
2099 |
|
bool negateSecond) const |
2100 |
|
{ |
2101 |
80418 |
Node la = a->getLiteral(); |
2102 |
80418 |
Node lb = b->getLiteral(); |
2103 |
80418 |
Node orN = (la < lb) ? la.orNode(lb) : lb.orNode(la); |
2104 |
40209 |
if (isProofEnabled()) |
2105 |
|
{ |
2106 |
6373 |
Assert(b->getNegation()->getType() != ConstraintType::Disequality); |
2107 |
6373 |
auto nm = NodeManager::currentNM(); |
2108 |
6373 |
auto pf_neg_la = d_pnm->mkNode(PfRule::MACRO_SR_PRED_TRANSFORM, |
2109 |
12746 |
{d_pnm->mkAssume(la.negate())}, |
2110 |
25492 |
{a->getNegation()->getProofLiteral()}); |
2111 |
6373 |
auto pf_neg_lb = d_pnm->mkNode(PfRule::MACRO_SR_PRED_TRANSFORM, |
2112 |
12746 |
{d_pnm->mkAssume(lb.negate())}, |
2113 |
25492 |
{b->getNegation()->getProofLiteral()}); |
2114 |
6373 |
int sndSign = negateSecond ? -1 : 1; |
2115 |
|
auto bot_pf = |
2116 |
6373 |
d_pnm->mkNode(PfRule::MACRO_SR_PRED_TRANSFORM, |
2117 |
6373 |
{d_pnm->mkNode(PfRule::MACRO_ARITH_SCALE_SUM_UB, |
2118 |
|
{pf_neg_la, pf_neg_lb}, |
2119 |
|
{nm->mkConst<Rational>(-1 * sndSign), |
2120 |
25492 |
nm->mkConst<Rational>(sndSign)})}, |
2121 |
31865 |
{nm->mkConst(false)}); |
2122 |
12746 |
std::vector<Node> as; |
2123 |
19119 |
std::transform(orN.begin(), orN.end(), std::back_inserter(as), [](Node n) { |
2124 |
|
return n.negate(); |
2125 |
19119 |
}); |
2126 |
|
// No need to ensure that the expected node aggrees with `as` because we |
2127 |
|
// are not providing an expected node. |
2128 |
6373 |
auto pf = d_pnm->mkNode( |
2129 |
|
PfRule::MACRO_SR_PRED_TRANSFORM, |
2130 |
19119 |
{d_pnm->mkNode(PfRule::NOT_AND, {d_pnm->mkScope(bot_pf, as)}, {})}, |
2131 |
31865 |
{orN}); |
2132 |
6373 |
out.push_back(d_pfGen->mkTrustNode(orN, pf)); |
2133 |
|
} |
2134 |
|
else |
2135 |
|
{ |
2136 |
33836 |
out.push_back(TrustNode::mkTrustLemma(orN)); |
2137 |
|
} |
2138 |
40209 |
} |
2139 |
|
|
2140 |
37438 |
void ConstraintDatabase::implies(std::vector<TrustNode>& out, |
2141 |
|
ConstraintP a, |
2142 |
|
ConstraintP b) const |
2143 |
|
{ |
2144 |
74876 |
Node la = a->getLiteral(); |
2145 |
74876 |
Node lb = b->getLiteral(); |
2146 |
|
|
2147 |
74876 |
Node neg_la = (la.getKind() == kind::NOT)? la[0] : la.notNode(); |
2148 |
|
|
2149 |
37438 |
Assert(lb != neg_la); |
2150 |
37438 |
Assert(b->getNegation()->getType() == ConstraintType::LowerBound |
2151 |
|
|| b->getNegation()->getType() == ConstraintType::UpperBound); |
2152 |
37438 |
proveOr(out, |
2153 |
|
a->getNegation(), |
2154 |
|
b, |
2155 |
37438 |
b->getNegation()->getType() == ConstraintType::LowerBound); |
2156 |
37438 |
} |
2157 |
|
|
2158 |
2771 |
void ConstraintDatabase::mutuallyExclusive(std::vector<TrustNode>& out, |
2159 |
|
ConstraintP a, |
2160 |
|
ConstraintP b) const |
2161 |
|
{ |
2162 |
5542 |
Node la = a->getLiteral(); |
2163 |
5542 |
Node lb = b->getLiteral(); |
2164 |
|
|
2165 |
5542 |
Node neg_la = la.negate(); |
2166 |
5542 |
Node neg_lb = lb.negate(); |
2167 |
2771 |
proveOr(out, a->getNegation(), b->getNegation(), true); |
2168 |
2771 |
} |
2169 |
|
|
2170 |
62559 |
void ConstraintDatabase::outputUnateInequalityLemmas( |
2171 |
|
std::vector<TrustNode>& out, ArithVar v) const |
2172 |
|
{ |
2173 |
62559 |
SortedConstraintMap& scm = getVariableSCM(v); |
2174 |
62559 |
SortedConstraintMapConstIterator scm_iter = scm.begin(); |
2175 |
62559 |
SortedConstraintMapConstIterator scm_end = scm.end(); |
2176 |
62559 |
ConstraintP prev = NullConstraint; |
2177 |
|
//get transitive unates |
2178 |
|
//Only lower bounds or upperbounds should be done. |
2179 |
331903 |
for(; scm_iter != scm_end; ++scm_iter){ |
2180 |
134672 |
const ValueCollection& vc = scm_iter->second; |
2181 |
134672 |
if(vc.hasUpperBound()){ |
2182 |
64741 |
ConstraintP ub = vc.getUpperBound(); |
2183 |
64741 |
if(ub->hasLiteral()){ |
2184 |
64741 |
if(prev != NullConstraint){ |
2185 |
28628 |
implies(out, prev, ub); |
2186 |
|
} |
2187 |
64741 |
prev = ub; |
2188 |
|
} |
2189 |
|
} |
2190 |
|
} |
2191 |
62559 |
} |
2192 |
|
|
2193 |
62559 |
void ConstraintDatabase::outputUnateEqualityLemmas(std::vector<TrustNode>& out, |
2194 |
|
ArithVar v) const |
2195 |
|
{ |
2196 |
125118 |
vector<ConstraintP> equalities; |
2197 |
|
|
2198 |
62559 |
SortedConstraintMap& scm = getVariableSCM(v); |
2199 |
62559 |
SortedConstraintMapConstIterator scm_iter = scm.begin(); |
2200 |
62559 |
SortedConstraintMapConstIterator scm_end = scm.end(); |
2201 |
|
|
2202 |
331903 |
for(; scm_iter != scm_end; ++scm_iter){ |
2203 |
134672 |
const ValueCollection& vc = scm_iter->second; |
2204 |
134672 |
if(vc.hasEquality()){ |
2205 |
19217 |
ConstraintP eq = vc.getEquality(); |
2206 |
19217 |
if(eq->hasLiteral()){ |
2207 |
19217 |
equalities.push_back(eq); |
2208 |
|
} |
2209 |
|
} |
2210 |
|
} |
2211 |
|
|
2212 |
62559 |
vector<ConstraintP>::const_iterator i, j, eq_end = equalities.end(); |
2213 |
81776 |
for(i = equalities.begin(); i != eq_end; ++i){ |
2214 |
19217 |
ConstraintP at_i = *i; |
2215 |
21988 |
for(j= i + 1; j != eq_end; ++j){ |
2216 |
2771 |
ConstraintP at_j = *j; |
2217 |
|
|
2218 |
2771 |
mutuallyExclusive(out, at_i, at_j); |
2219 |
|
} |
2220 |
|
} |
2221 |
|
|
2222 |
81776 |
for(i = equalities.begin(); i != eq_end; ++i){ |
2223 |
19217 |
ConstraintP eq = *i; |
2224 |
19217 |
const ValueCollection& vc = eq->getValueCollection(); |
2225 |
19217 |
Assert(vc.hasEquality() && vc.getEquality()->hasLiteral()); |
2226 |
|
|
2227 |
19217 |
bool hasLB = vc.hasLowerBound() && vc.getLowerBound()->hasLiteral(); |
2228 |
19217 |
bool hasUB = vc.hasUpperBound() && vc.getUpperBound()->hasLiteral(); |
2229 |
|
|
2230 |
19217 |
ConstraintP lb = hasLB ? |
2231 |
19217 |
vc.getLowerBound() : eq->getStrictlyWeakerLowerBound(true, false); |
2232 |
19217 |
ConstraintP ub = hasUB ? |
2233 |
19217 |
vc.getUpperBound() : eq->getStrictlyWeakerUpperBound(true, false); |
2234 |
|
|
2235 |
19217 |
if(hasUB && hasLB && !eq->isSplit()){ |
2236 |
115 |
out.push_back(eq->split()); |
2237 |
|
} |
2238 |
19217 |
if(lb != NullConstraint){ |
2239 |
3289 |
implies(out, eq, lb); |
2240 |
|
} |
2241 |
19217 |
if(ub != NullConstraint){ |
2242 |
5521 |
implies(out, eq, ub); |
2243 |
|
} |
2244 |
|
} |
2245 |
62559 |
} |
2246 |
|
|
2247 |
8880 |
void ConstraintDatabase::outputUnateEqualityLemmas( |
2248 |
|
std::vector<TrustNode>& lemmas) const |
2249 |
|
{ |
2250 |
71439 |
for(ArithVar v = 0, N = d_varDatabases.size(); v < N; ++v){ |
2251 |
62559 |
outputUnateEqualityLemmas(lemmas, v); |
2252 |
|
} |
2253 |
8880 |
} |
2254 |
|
|
2255 |
8880 |
void ConstraintDatabase::outputUnateInequalityLemmas( |
2256 |
|
std::vector<TrustNode>& lemmas) const |
2257 |
|
{ |
2258 |
71439 |
for(ArithVar v = 0, N = d_varDatabases.size(); v < N; ++v){ |
2259 |
62559 |
outputUnateInequalityLemmas(lemmas, v); |
2260 |
|
} |
2261 |
8880 |
} |
2262 |
|
|
2263 |
5750981 |
bool ConstraintDatabase::handleUnateProp(ConstraintP ant, ConstraintP cons){ |
2264 |
5750981 |
if(cons->negationHasProof()){ |
2265 |
|
Debug("arith::unate") << "handleUnate: " << ant << " implies " << cons << endl; |
2266 |
|
cons->impliedByUnate(ant, true); |
2267 |
|
d_raiseConflict.raiseConflict(cons, InferenceId::UNKNOWN); |
2268 |
|
return true; |
2269 |
5750981 |
}else if(!cons->isTrue()){ |
2270 |
3169123 |
++d_statistics.d_unatePropagateImplications; |
2271 |
3169123 |
Debug("arith::unate") << "handleUnate: " << ant << " implies " << cons << endl; |
2272 |
3169123 |
cons->impliedByUnate(ant, false); |
2273 |
3169123 |
cons->tryToPropagate(); |
2274 |
3169123 |
return false; |
2275 |
|
} else { |
2276 |
2581858 |
return false; |
2277 |
|
} |
2278 |
|
} |
2279 |
|
|
2280 |
1261613 |
void ConstraintDatabase::unatePropLowerBound(ConstraintP curr, ConstraintP prev){ |
2281 |
1261613 |
Debug("arith::unate") << "unatePropLowerBound " << curr << " " << prev << endl; |
2282 |
1261613 |
Assert(curr != prev); |
2283 |
1261613 |
Assert(curr != NullConstraint); |
2284 |
1261613 |
bool hasPrev = ! (prev == NullConstraint); |
2285 |
1261613 |
Assert(!hasPrev || curr->getValue() > prev->getValue()); |
2286 |
|
|
2287 |
1261613 |
++d_statistics.d_unatePropagateCalls; |
2288 |
|
|
2289 |
1261613 |
const SortedConstraintMap& scm = curr->constraintSet(); |
2290 |
1261613 |
const SortedConstraintMapConstIterator scm_begin = scm.begin(); |
2291 |
1261613 |
SortedConstraintMapConstIterator scm_i = curr->d_variablePosition; |
2292 |
|
|
2293 |
|
//Ignore the first ValueCollection |
2294 |
|
// NOPE: (>= p c) then (= p c) NOPE |
2295 |
|
// NOPE: (>= p c) then (not (= p c)) NOPE |
2296 |
|
|
2297 |
7822885 |
while(scm_i != scm_begin){ |
2298 |
3576186 |
--scm_i; // move the iterator back |
2299 |
|
|
2300 |
3576186 |
const ValueCollection& vc = scm_i->second; |
2301 |
|
|
2302 |
|
//If it has the previous element, do nothing and stop! |
2303 |
4550985 |
if(hasPrev && |
2304 |
974799 |
vc.hasConstraintOfType(prev->getType()) |
2305 |
4203208 |
&& vc.getConstraintOfType(prev->getType()) == prev){ |
2306 |
295550 |
break; |
2307 |
|
} |
2308 |
|
|
2309 |
|
//Don't worry about implying the negation of upperbound. |
2310 |
|
//These should all be handled by propagating the LowerBounds! |
2311 |
3280636 |
if(vc.hasLowerBound()){ |
2312 |
1253207 |
ConstraintP lb = vc.getLowerBound(); |
2313 |
1253207 |
if(handleUnateProp(curr, lb)){ return; } |
2314 |
|
} |
2315 |
3280636 |
if(vc.hasDisequality()){ |
2316 |
375185 |
ConstraintP dis = vc.getDisequality(); |
2317 |
375185 |
if(handleUnateProp(curr, dis)){ return; } |
2318 |
|
} |
2319 |
|
} |
2320 |
|
} |
2321 |
|
|
2322 |
1245747 |
void ConstraintDatabase::unatePropUpperBound(ConstraintP curr, ConstraintP prev){ |
2323 |
1245747 |
Debug("arith::unate") << "unatePropUpperBound " << curr << " " << prev << endl; |
2324 |
1245747 |
Assert(curr != prev); |
2325 |
1245747 |
Assert(curr != NullConstraint); |
2326 |
1245747 |
bool hasPrev = ! (prev == NullConstraint); |
2327 |
1245747 |
Assert(!hasPrev || curr->getValue() < prev->getValue()); |
2328 |
|
|
2329 |
1245747 |
++d_statistics.d_unatePropagateCalls; |
2330 |
|
|
2331 |
1245747 |
const SortedConstraintMap& scm = curr->constraintSet(); |
2332 |
1245747 |
const SortedConstraintMapConstIterator scm_end = scm.end(); |
2333 |
1245747 |
SortedConstraintMapConstIterator scm_i = curr->d_variablePosition; |
2334 |
1245747 |
++scm_i; |
2335 |
8950903 |
for(; scm_i != scm_end; ++scm_i){ |
2336 |
4091055 |
const ValueCollection& vc = scm_i->second; |
2337 |
|
|
2338 |
|
//If it has the previous element, do nothing and stop! |
2339 |
4847893 |
if(hasPrev && |
2340 |
4571290 |
vc.hasConstraintOfType(prev->getType()) && |
2341 |
480235 |
vc.getConstraintOfType(prev->getType()) == prev){ |
2342 |
238477 |
break; |
2343 |
|
} |
2344 |
|
//Don't worry about implying the negation of upperbound. |
2345 |
|
//These should all be handled by propagating the UpperBounds! |
2346 |
3852578 |
if(vc.hasUpperBound()){ |
2347 |
1544644 |
ConstraintP ub = vc.getUpperBound(); |
2348 |
1544644 |
if(handleUnateProp(curr, ub)){ return; } |
2349 |
|
} |
2350 |
3852578 |
if(vc.hasDisequality()){ |
2351 |
335756 |
ConstraintP dis = vc.getDisequality(); |
2352 |
335756 |
if(handleUnateProp(curr, dis)){ return; } |
2353 |
|
} |
2354 |
|
} |
2355 |
|
} |
2356 |
|
|
2357 |
1156942 |
void ConstraintDatabase::unatePropEquality(ConstraintP curr, ConstraintP prevLB, ConstraintP prevUB){ |
2358 |
1156942 |
Debug("arith::unate") << "unatePropEquality " << curr << " " << prevLB << " " << prevUB << endl; |
2359 |
1156942 |
Assert(curr != prevLB); |
2360 |
1156942 |
Assert(curr != prevUB); |
2361 |
1156942 |
Assert(curr != NullConstraint); |
2362 |
1156942 |
bool hasPrevLB = ! (prevLB == NullConstraint); |
2363 |
1156942 |
bool hasPrevUB = ! (prevUB == NullConstraint); |
2364 |
1156942 |
Assert(!hasPrevLB || curr->getValue() >= prevLB->getValue()); |
2365 |
1156942 |
Assert(!hasPrevUB || curr->getValue() <= prevUB->getValue()); |
2366 |
|
|
2367 |
1156942 |
++d_statistics.d_unatePropagateCalls; |
2368 |
|
|
2369 |
1156942 |
const SortedConstraintMap& scm = curr->constraintSet(); |
2370 |
1156942 |
SortedConstraintMapConstIterator scm_curr = curr->d_variablePosition; |
2371 |
1156942 |
SortedConstraintMapConstIterator scm_last = hasPrevUB ? prevUB->d_variablePosition : scm.end(); |
2372 |
1156942 |
SortedConstraintMapConstIterator scm_i; |
2373 |
1156942 |
if(hasPrevLB){ |
2374 |
214746 |
scm_i = prevLB->d_variablePosition; |
2375 |
214746 |
if(scm_i != scm_curr){ // If this does not move this past scm_curr, move it one forward |
2376 |
42003 |
++scm_i; |
2377 |
|
} |
2378 |
|
}else{ |
2379 |
942196 |
scm_i = scm.begin(); |
2380 |
|
} |
2381 |
|
|
2382 |
3569278 |
for(; scm_i != scm_curr; ++scm_i){ |
2383 |
|
// between the previous LB and the curr |
2384 |
1206168 |
const ValueCollection& vc = scm_i->second; |
2385 |
|
|
2386 |
|
//Don't worry about implying the negation of upperbound. |
2387 |
|
//These should all be handled by propagating the LowerBounds! |
2388 |
1206168 |
if(vc.hasLowerBound()){ |
2389 |
458991 |
ConstraintP lb = vc.getLowerBound(); |
2390 |
458991 |
if(handleUnateProp(curr, lb)){ return; } |
2391 |
|
} |
2392 |
1206168 |
if(vc.hasDisequality()){ |
2393 |
397785 |
ConstraintP dis = vc.getDisequality(); |
2394 |
397785 |
if(handleUnateProp(curr, dis)){ return; } |
2395 |
|
} |
2396 |
|
} |
2397 |
1156942 |
Assert(scm_i == scm_curr); |
2398 |
1156942 |
if(!hasPrevUB || scm_i != scm_last){ |
2399 |
1127056 |
++scm_i; |
2400 |
|
} // hasPrevUB implies scm_i != scm_last |
2401 |
|
|
2402 |
5550638 |
for(; scm_i != scm_last; ++scm_i){ |
2403 |
|
// between the curr and the previous UB imply the upperbounds and disequalities. |
2404 |
2196848 |
const ValueCollection& vc = scm_i->second; |
2405 |
|
|
2406 |
|
//Don't worry about implying the negation of upperbound. |
2407 |
|
//These should all be handled by propagating the UpperBounds! |
2408 |
2196848 |
if(vc.hasUpperBound()){ |
2409 |
828077 |
ConstraintP ub = vc.getUpperBound(); |
2410 |
828077 |
if(handleUnateProp(curr, ub)){ return; } |
2411 |
|
} |
2412 |
2196848 |
if(vc.hasDisequality()){ |
2413 |
557336 |
ConstraintP dis = vc.getDisequality(); |
2414 |
557336 |
if(handleUnateProp(curr, dis)){ return; } |
2415 |
|
} |
2416 |
|
} |
2417 |
|
} |
2418 |
|
|
2419 |
783681 |
std::pair<int, int> Constraint::unateFarkasSigns(ConstraintCP ca, ConstraintCP cb){ |
2420 |
783681 |
ConstraintType a = ca->getType(); |
2421 |
783681 |
ConstraintType b = cb->getType(); |
2422 |
|
|
2423 |
783681 |
Assert(a != Disequality); |
2424 |
783681 |
Assert(b != Disequality); |
2425 |
|
|
2426 |
783681 |
int a_sgn = (a == LowerBound) ? -1 : ((a == UpperBound) ? 1 : 0); |
2427 |
783681 |
int b_sgn = (b == LowerBound) ? -1 : ((b == UpperBound) ? 1 : 0); |
2428 |
|
|
2429 |
783681 |
if(a_sgn == 0 && b_sgn == 0){ |
2430 |
190939 |
Assert(a == Equality); |
2431 |
190939 |
Assert(b == Equality); |
2432 |
190939 |
Assert(ca->getValue() != cb->getValue()); |
2433 |
381878 |
if(ca->getValue() < cb->getValue()){ |
2434 |
61486 |
a_sgn = 1; |
2435 |
61486 |
b_sgn = -1; |
2436 |
|
}else{ |
2437 |
129453 |
a_sgn = -1; |
2438 |
129453 |
b_sgn = 1; |
2439 |
|
} |
2440 |
592742 |
}else if(a_sgn == 0){ |
2441 |
132547 |
Assert(b_sgn != 0); |
2442 |
132547 |
Assert(a == Equality); |
2443 |
132547 |
a_sgn = -b_sgn; |
2444 |
460195 |
}else if(b_sgn == 0){ |
2445 |
248905 |
Assert(a_sgn != 0); |
2446 |
248905 |
Assert(b == Equality); |
2447 |
248905 |
b_sgn = -a_sgn; |
2448 |
|
} |
2449 |
783681 |
Assert(a_sgn != 0); |
2450 |
783681 |
Assert(b_sgn != 0); |
2451 |
|
|
2452 |
1567362 |
Debug("arith::unateFarkasSigns") << "Constraint::unateFarkasSigns("<<a <<", " << b << ") -> " |
2453 |
783681 |
<< "("<<a_sgn<<", "<< b_sgn <<")"<< endl; |
2454 |
783681 |
return make_pair(a_sgn, b_sgn); |
2455 |
|
} |
2456 |
|
|
2457 |
|
} // namespace arith |
2458 |
|
} // namespace theory |
2459 |
31125 |
} // namespace cvc5 |