1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Morgan Deters, Mathias Preiner |
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 |
|
* This is the interface to TheoryUF implementations |
14 |
|
* |
15 |
|
* All implementations of TheoryUF should inherit from this class. |
16 |
|
*/ |
17 |
|
|
18 |
|
#include "cvc5_private.h" |
19 |
|
|
20 |
|
#ifndef CVC5__THEORY__UF__THEORY_UF_H |
21 |
|
#define CVC5__THEORY__UF__THEORY_UF_H |
22 |
|
|
23 |
|
#include "expr/node.h" |
24 |
|
#include "expr/node_trie.h" |
25 |
|
#include "theory/theory.h" |
26 |
|
#include "theory/theory_eq_notify.h" |
27 |
|
#include "theory/theory_state.h" |
28 |
|
#include "theory/uf/proof_checker.h" |
29 |
|
#include "theory/uf/symmetry_breaker.h" |
30 |
|
#include "theory/uf/theory_uf_rewriter.h" |
31 |
|
|
32 |
|
namespace cvc5 { |
33 |
|
namespace theory { |
34 |
|
namespace uf { |
35 |
|
|
36 |
|
class CardinalityExtension; |
37 |
|
class HoExtension; |
38 |
|
|
39 |
|
class TheoryUF : public Theory { |
40 |
|
public: |
41 |
9939 |
class NotifyClass : public TheoryEqNotifyClass |
42 |
|
{ |
43 |
|
public: |
44 |
9942 |
NotifyClass(TheoryInferenceManager& im, TheoryUF& uf) |
45 |
9942 |
: TheoryEqNotifyClass(im), d_uf(uf) |
46 |
|
{ |
47 |
9942 |
} |
48 |
|
|
49 |
278799 |
void eqNotifyNewClass(TNode t) override |
50 |
|
{ |
51 |
557598 |
Debug("uf-notify") << "NotifyClass::eqNotifyNewClass(" << t << ")" |
52 |
278799 |
<< std::endl; |
53 |
278799 |
d_uf.eqNotifyNewClass(t); |
54 |
278799 |
} |
55 |
|
|
56 |
4684949 |
void eqNotifyMerge(TNode t1, TNode t2) override |
57 |
|
{ |
58 |
9369898 |
Debug("uf-notify") << "NotifyClass::eqNotifyMerge(" << t1 << ", " << t2 |
59 |
4684949 |
<< ")" << std::endl; |
60 |
4684949 |
d_uf.eqNotifyMerge(t1, t2); |
61 |
4684949 |
} |
62 |
|
|
63 |
944255 |
void eqNotifyDisequal(TNode t1, TNode t2, TNode reason) override |
64 |
|
{ |
65 |
944255 |
Debug("uf-notify") << "NotifyClass::eqNotifyDisequal(" << t1 << ", " << t2 << ", " << reason << ")" << std::endl; |
66 |
944255 |
d_uf.eqNotifyDisequal(t1, t2, reason); |
67 |
944255 |
} |
68 |
|
|
69 |
|
private: |
70 |
|
/** Reference to the parent theory */ |
71 |
|
TheoryUF& d_uf; |
72 |
|
};/* class TheoryUF::NotifyClass */ |
73 |
|
|
74 |
|
private: |
75 |
|
/** The associated cardinality extension (or nullptr if it does not exist) */ |
76 |
|
std::unique_ptr<CardinalityExtension> d_thss; |
77 |
|
/** the higher-order solver extension (or nullptr if it does not exist) */ |
78 |
|
std::unique_ptr<HoExtension> d_ho; |
79 |
|
|
80 |
|
/** node for true */ |
81 |
|
Node d_true; |
82 |
|
|
83 |
|
/** All the function terms that the theory has seen */ |
84 |
|
context::CDList<TNode> d_functionsTerms; |
85 |
|
|
86 |
|
/** Symmetry analyzer */ |
87 |
|
SymmetryBreaker d_symb; |
88 |
|
|
89 |
|
/** called when a new equivalance class is created */ |
90 |
|
void eqNotifyNewClass(TNode t); |
91 |
|
|
92 |
|
/** called when two equivalance classes have merged */ |
93 |
|
void eqNotifyMerge(TNode t1, TNode t2); |
94 |
|
|
95 |
|
/** called when two equivalence classes are made disequal */ |
96 |
|
void eqNotifyDisequal(TNode t1, TNode t2, TNode reason); |
97 |
|
|
98 |
|
public: |
99 |
|
|
100 |
|
/** Constructs a new instance of TheoryUF w.r.t. the provided context.*/ |
101 |
|
TheoryUF(Env& env, |
102 |
|
OutputChannel& out, |
103 |
|
Valuation valuation, |
104 |
|
std::string instanceName = ""); |
105 |
|
|
106 |
|
~TheoryUF(); |
107 |
|
|
108 |
|
//--------------------------------- initialization |
109 |
|
/** get the official theory rewriter of this theory */ |
110 |
|
TheoryRewriter* getTheoryRewriter() override; |
111 |
|
/** get the proof checker of this theory */ |
112 |
|
ProofRuleChecker* getProofChecker() override; |
113 |
|
/** |
114 |
|
* Returns true if we need an equality engine. If so, we initialize the |
115 |
|
* information regarding how it should be setup. For details, see the |
116 |
|
* documentation in Theory::needsEqualityEngine. |
117 |
|
*/ |
118 |
|
bool needsEqualityEngine(EeSetupInfo& esi) override; |
119 |
|
/** finish initialization */ |
120 |
|
void finishInit() override; |
121 |
|
//--------------------------------- end initialization |
122 |
|
|
123 |
|
//--------------------------------- standard check |
124 |
|
/** Do we need a check call at last call effort? */ |
125 |
|
bool needsCheckLastEffort() override; |
126 |
|
/** Post-check, called after the fact queue of the theory is processed. */ |
127 |
|
void postCheck(Effort level) override; |
128 |
|
/** Notify fact */ |
129 |
|
void notifyFact(TNode atom, bool pol, TNode fact, bool isInternal) override; |
130 |
|
//--------------------------------- end standard check |
131 |
|
|
132 |
|
/** Collect model values in m based on the relevant terms given by termSet */ |
133 |
|
bool collectModelValues(TheoryModel* m, |
134 |
|
const std::set<Node>& termSet) override; |
135 |
|
|
136 |
|
TrustNode ppRewrite(TNode node, std::vector<SkolemLemma>& lems) override; |
137 |
|
void preRegisterTerm(TNode term) override; |
138 |
|
TrustNode explain(TNode n) override; |
139 |
|
|
140 |
|
void ppStaticLearn(TNode in, NodeBuilder& learned) override; |
141 |
|
void presolve() override; |
142 |
|
|
143 |
|
void computeCareGraph() override; |
144 |
|
|
145 |
|
EqualityStatus getEqualityStatus(TNode a, TNode b) override; |
146 |
|
|
147 |
|
std::string identify() const override { return "THEORY_UF"; } |
148 |
|
private: |
149 |
|
/** Explain why this literal is true by building an explanation */ |
150 |
|
void explain(TNode literal, Node& exp); |
151 |
|
|
152 |
|
bool areCareDisequal(TNode x, TNode y); |
153 |
|
void addCarePairs(const TNodeTrie* t1, |
154 |
|
const TNodeTrie* t2, |
155 |
|
unsigned arity, |
156 |
|
unsigned depth); |
157 |
|
/** |
158 |
|
* Is t a higher order type? A higher-order type is a function type having |
159 |
|
* an argument type that is also a function type. This is used for checking |
160 |
|
* logic exceptions. |
161 |
|
*/ |
162 |
|
bool isHigherOrderType(TypeNode tn); |
163 |
|
TheoryUfRewriter d_rewriter; |
164 |
|
/** Proof rule checker */ |
165 |
|
UfProofRuleChecker d_checker; |
166 |
|
/** A (default) theory state object */ |
167 |
|
TheoryState d_state; |
168 |
|
/** A (default) inference manager */ |
169 |
|
TheoryInferenceManager d_im; |
170 |
|
/** The notify class */ |
171 |
|
NotifyClass d_notify; |
172 |
|
/** Cache for isHigherOrderType */ |
173 |
|
std::map<TypeNode, bool> d_isHoType; |
174 |
|
};/* class TheoryUF */ |
175 |
|
|
176 |
|
} // namespace uf |
177 |
|
} // namespace theory |
178 |
|
} // namespace cvc5 |
179 |
|
|
180 |
|
#endif /* CVC5__THEORY__UF__THEORY_UF_H */ |