1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
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 |
|
* Arithmetic equality solver |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__ARITH__EQUALITY_SOLVER_H |
19 |
|
#define CVC5__THEORY__ARITH__EQUALITY_SOLVER_H |
20 |
|
|
21 |
|
#include "context/cdhashset.h" |
22 |
|
#include "expr/node.h" |
23 |
|
#include "proof/trust_node.h" |
24 |
|
#include "smt/env_obj.h" |
25 |
|
#include "theory/arith/arith_state.h" |
26 |
|
#include "theory/ee_setup_info.h" |
27 |
|
#include "theory/uf/equality_engine.h" |
28 |
|
|
29 |
|
namespace cvc5 { |
30 |
|
namespace theory { |
31 |
|
namespace arith { |
32 |
|
|
33 |
|
class InferenceManager; |
34 |
|
|
35 |
|
/** |
36 |
|
* The arithmetic equality solver. This class manages arithmetic equalities |
37 |
|
* in the default way via an equality engine. |
38 |
|
* |
39 |
|
* Since arithmetic has multiple ways of propagating literals, it tracks |
40 |
|
* the literals that it propagates and only explains the literals that |
41 |
|
* originated from this class. |
42 |
|
*/ |
43 |
|
class EqualitySolver : protected EnvObj |
44 |
|
{ |
45 |
|
using NodeSet = context::CDHashSet<Node>; |
46 |
|
|
47 |
|
public: |
48 |
|
EqualitySolver(Env& env, ArithState& astate, InferenceManager& aim); |
49 |
78 |
~EqualitySolver() {} |
50 |
|
//--------------------------------- initialization |
51 |
|
/** |
52 |
|
* Returns true if we need an equality engine, see |
53 |
|
* Theory::needsEqualityEngine. |
54 |
|
*/ |
55 |
|
bool needsEqualityEngine(EeSetupInfo& esi); |
56 |
|
/** |
57 |
|
* Finish initialize |
58 |
|
*/ |
59 |
|
void finishInit(); |
60 |
|
//--------------------------------- end initialization |
61 |
|
/** |
62 |
|
* Pre-notify fact, return true if we are finished processing, false if |
63 |
|
* we wish to assert the fact to the equality engine of this class. |
64 |
|
*/ |
65 |
|
bool preNotifyFact( |
66 |
|
TNode atom, bool pol, TNode fact, bool isPrereg, bool isInternal); |
67 |
|
/** |
68 |
|
* Return an explanation for the literal lit (which was previously propagated |
69 |
|
* by this solver). |
70 |
|
*/ |
71 |
|
TrustNode explain(TNode lit); |
72 |
|
|
73 |
|
private: |
74 |
|
/** Notification class from the equality engine */ |
75 |
39 |
class EqualitySolverNotify : public eq::EqualityEngineNotify |
76 |
|
{ |
77 |
|
public: |
78 |
39 |
EqualitySolverNotify(EqualitySolver& es) : d_es(es) {} |
79 |
|
|
80 |
|
bool eqNotifyTriggerPredicate(TNode predicate, bool value) override; |
81 |
|
|
82 |
|
bool eqNotifyTriggerTermEquality(TheoryId tag, |
83 |
|
TNode t1, |
84 |
|
TNode t2, |
85 |
|
bool value) override; |
86 |
|
|
87 |
|
void eqNotifyConstantTermMerge(TNode t1, TNode t2) override; |
88 |
122 |
void eqNotifyNewClass(TNode t) override {} |
89 |
194 |
void eqNotifyMerge(TNode t1, TNode t2) override {} |
90 |
54 |
void eqNotifyDisequal(TNode t1, TNode t2, TNode reason) override {} |
91 |
|
|
92 |
|
private: |
93 |
|
/** reference to parent */ |
94 |
|
EqualitySolver& d_es; |
95 |
|
}; |
96 |
|
/** Propagate literal */ |
97 |
|
bool propagateLit(Node lit); |
98 |
|
/** Conflict when two constants merge */ |
99 |
|
void conflictEqConstantMerge(TNode a, TNode b); |
100 |
|
/** reference to the state */ |
101 |
|
ArithState& d_astate; |
102 |
|
/** reference to parent */ |
103 |
|
InferenceManager& d_aim; |
104 |
|
/** Equality solver notify */ |
105 |
|
EqualitySolverNotify d_notify; |
106 |
|
/** Pointer to the equality engine */ |
107 |
|
eq::EqualityEngine* d_ee; |
108 |
|
/** The literals we have propagated */ |
109 |
|
NodeSet d_propLits; |
110 |
|
}; |
111 |
|
|
112 |
|
} // namespace arith |
113 |
|
} // namespace theory |
114 |
|
} // namespace cvc5 |
115 |
|
|
116 |
|
#endif |