1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Martin Brain, Aina Niemetz |
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 |
|
* Theory of floating-point arithmetic. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__FP__THEORY_FP_H |
19 |
|
#define CVC5__THEORY__FP__THEORY_FP_H |
20 |
|
|
21 |
|
#include <string> |
22 |
|
#include <utility> |
23 |
|
|
24 |
|
#include "context/cdhashset.h" |
25 |
|
#include "context/cdo.h" |
26 |
|
#include "theory/fp/theory_fp_rewriter.h" |
27 |
|
#include "theory/theory.h" |
28 |
|
#include "theory/theory_inference_manager.h" |
29 |
|
#include "theory/theory_state.h" |
30 |
|
#include "theory/uf/equality_engine.h" |
31 |
|
|
32 |
|
namespace cvc5 { |
33 |
|
namespace theory { |
34 |
|
namespace fp { |
35 |
|
|
36 |
|
class FpConverter; |
37 |
|
|
38 |
19706 |
class TheoryFp : public Theory |
39 |
|
{ |
40 |
|
public: |
41 |
|
/** Constructs a new instance of TheoryFp w.r.t. the provided contexts. */ |
42 |
|
TheoryFp(context::Context* c, |
43 |
|
context::UserContext* u, |
44 |
|
OutputChannel& out, |
45 |
|
Valuation valuation, |
46 |
|
const LogicInfo& logicInfo, |
47 |
|
ProofNodeManager* pnm = nullptr); |
48 |
|
|
49 |
|
//--------------------------------- initialization |
50 |
|
/** Get the official theory rewriter of this theory. */ |
51 |
|
TheoryRewriter* getTheoryRewriter() override; |
52 |
|
/** get the proof checker of this theory */ |
53 |
|
ProofRuleChecker* getProofChecker() override; |
54 |
|
/** |
55 |
|
* Returns true if we need an equality engine. If so, we initialize the |
56 |
|
* information regarding how it should be setup. For details, see the |
57 |
|
* documentation in Theory::needsEqualityEngine. |
58 |
|
*/ |
59 |
|
bool needsEqualityEngine(EeSetupInfo& esi) override; |
60 |
|
/** Finish initialization. */ |
61 |
|
void finishInit() override; |
62 |
|
//--------------------------------- end initialization |
63 |
|
|
64 |
|
void preRegisterTerm(TNode node) override; |
65 |
|
TrustNode ppRewrite(TNode node, std::vector<SkolemLemma>& lems) override; |
66 |
|
|
67 |
|
//--------------------------------- standard check |
68 |
|
/** Do we need a check call at last call effort? */ |
69 |
|
bool needsCheckLastEffort() override; |
70 |
|
/** Post-check, called after the fact queue of the theory is processed. */ |
71 |
|
void postCheck(Effort level) override; |
72 |
|
/** Pre-notify fact, return true if processed. */ |
73 |
|
bool preNotifyFact(TNode atom, |
74 |
|
bool pol, |
75 |
|
TNode fact, |
76 |
|
bool isPrereg, |
77 |
|
bool isInternal) override; |
78 |
|
//--------------------------------- end standard check |
79 |
|
|
80 |
|
Node getModelValue(TNode var) override; |
81 |
|
bool collectModelInfo(TheoryModel* m, |
82 |
|
const std::set<Node>& relevantTerms) override; |
83 |
|
/** |
84 |
|
* Collect model values in m based on the relevant terms given by |
85 |
|
* relevantTerms. |
86 |
|
*/ |
87 |
|
bool collectModelValues(TheoryModel* m, |
88 |
|
const std::set<Node>& relevantTerms) override; |
89 |
|
|
90 |
|
std::string identify() const override { return "THEORY_FP"; } |
91 |
|
|
92 |
|
TrustNode explain(TNode n) override; |
93 |
|
|
94 |
|
protected: |
95 |
|
using ConversionAbstractionMap = context::CDHashMap<TypeNode, Node>; |
96 |
|
using AbstractionMap = context::CDHashMap<Node, Node>; |
97 |
|
|
98 |
|
/** Equality engine. */ |
99 |
9853 |
class NotifyClass : public eq::EqualityEngineNotify { |
100 |
|
protected: |
101 |
|
TheoryFp& d_theorySolver; |
102 |
|
|
103 |
|
public: |
104 |
9853 |
NotifyClass(TheoryFp& solver) : d_theorySolver(solver) {} |
105 |
|
bool eqNotifyTriggerPredicate(TNode predicate, bool value) override; |
106 |
|
bool eqNotifyTriggerTermEquality(TheoryId tag, |
107 |
|
TNode t1, |
108 |
|
TNode t2, |
109 |
|
bool value) override; |
110 |
|
void eqNotifyConstantTermMerge(TNode t1, TNode t2) override; |
111 |
7050 |
void eqNotifyNewClass(TNode t) override {} |
112 |
5546 |
void eqNotifyMerge(TNode t1, TNode t2) override {} |
113 |
4496 |
void eqNotifyDisequal(TNode t1, TNode t2, TNode reason) override {} |
114 |
|
}; |
115 |
|
friend NotifyClass; |
116 |
|
|
117 |
|
void notifySharedTerm(TNode n) override; |
118 |
|
|
119 |
|
NotifyClass d_notification; |
120 |
|
|
121 |
|
/** General utility. */ |
122 |
|
void registerTerm(TNode node); |
123 |
|
bool isRegistered(TNode node); |
124 |
|
|
125 |
|
context::CDHashSet<Node> d_registeredTerms; |
126 |
|
|
127 |
|
/** The word-blaster. Translates FP -> BV. */ |
128 |
|
std::unique_ptr<FpConverter> d_conv; |
129 |
|
|
130 |
|
bool d_expansionRequested; |
131 |
|
|
132 |
|
void convertAndEquateTerm(TNode node); |
133 |
|
|
134 |
|
/** Interaction with the rest of the solver **/ |
135 |
|
void handleLemma(Node node, InferenceId id); |
136 |
|
/** |
137 |
|
* Called when literal node is inferred by the equality engine. This |
138 |
|
* propagates node on the output channel. |
139 |
|
*/ |
140 |
|
bool propagateLit(TNode node); |
141 |
|
/** |
142 |
|
* Called when two constants t1 and t2 merge in the equality engine. This |
143 |
|
* sends a conflict on the output channel. |
144 |
|
*/ |
145 |
|
void conflictEqConstantMerge(TNode t1, TNode t2); |
146 |
|
|
147 |
|
bool refineAbstraction(TheoryModel* m, TNode abstract, TNode concrete); |
148 |
|
|
149 |
|
Node abstractRealToFloat(Node); |
150 |
|
Node abstractFloatToReal(Node); |
151 |
|
|
152 |
|
private: |
153 |
|
ConversionAbstractionMap d_realToFloatMap; |
154 |
|
ConversionAbstractionMap d_floatToRealMap; |
155 |
|
AbstractionMap d_abstractionMap; // abstract -> original |
156 |
|
|
157 |
|
/** The theory rewriter for this theory. */ |
158 |
|
TheoryFpRewriter d_rewriter; |
159 |
|
/** A (default) theory state object. */ |
160 |
|
TheoryState d_state; |
161 |
|
/** A (default) inference manager. */ |
162 |
|
TheoryInferenceManager d_im; |
163 |
|
/** Cache of word-blasted facts. */ |
164 |
|
context::CDHashSet<Node> d_wbFactsCache; |
165 |
|
}; |
166 |
|
|
167 |
|
} // namespace fp |
168 |
|
} // namespace theory |
169 |
|
} // namespace cvc5 |
170 |
|
|
171 |
|
#endif /* CVC5__THEORY__FP__THEORY_FP_H */ |