1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Dejan Jovanovic, Gereon Kremer |
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 |
|
* Base class for shared solver. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__SHARED_SOLVER__H |
19 |
|
#define CVC5__THEORY__SHARED_SOLVER__H |
20 |
|
|
21 |
|
#include "expr/node.h" |
22 |
|
#include "theory/shared_terms_database.h" |
23 |
|
#include "theory/term_registration_visitor.h" |
24 |
|
#include "theory/valuation.h" |
25 |
|
|
26 |
|
namespace cvc5 { |
27 |
|
|
28 |
|
class LogicInfo; |
29 |
|
class ProofNodeManager; |
30 |
|
class TheoryEngine; |
31 |
|
|
32 |
|
namespace theory { |
33 |
|
|
34 |
|
struct EeSetupInfo; |
35 |
|
|
36 |
|
/** |
37 |
|
* A base class for shared solver. The shared solver is the component of theory |
38 |
|
* engine that behaves like a theory solver, and whose purpose is to ensure the |
39 |
|
* main theory combination method can be performed in CombinationEngine. |
40 |
|
* Its role is to: |
41 |
|
* (1) Notify the individual theories of shared terms via addSharedTerms, |
42 |
|
* (2) Be the official interface for equality statuses, |
43 |
|
* (3) Propagate equalities to TheoryEngine when necessary and explain them. |
44 |
|
*/ |
45 |
|
class SharedSolver |
46 |
|
{ |
47 |
|
public: |
48 |
|
SharedSolver(TheoryEngine& te, ProofNodeManager* pnm); |
49 |
9459 |
virtual ~SharedSolver() {} |
50 |
|
//------------------------------------- initialization |
51 |
|
/** |
52 |
|
* Returns true if we need an equality engine, this has the same contract |
53 |
|
* as Theory::needsEqualityEngine. |
54 |
|
*/ |
55 |
|
virtual bool needsEqualityEngine(theory::EeSetupInfo& esi); |
56 |
|
/** |
57 |
|
* Set the equality engine. This should be called by equality engine manager |
58 |
|
* during EqEngineManager::initializeTheories. |
59 |
|
*/ |
60 |
|
virtual void setEqualityEngine(eq::EqualityEngine* ee) = 0; |
61 |
|
//------------------------------------- end initialization |
62 |
|
/** |
63 |
|
* Called when the given atom is pre-registered in TheoryEngine. |
64 |
|
* |
65 |
|
* This calls Theory::preRegisterTerm on all subterms of atom for the |
66 |
|
* appropriate theories. |
67 |
|
* |
68 |
|
* Also, if sharing is enabled, this adds atom as an equality to propagate in |
69 |
|
* the shared terms database if it is an equality, and adds its shared terms |
70 |
|
* to the appropariate theories. |
71 |
|
* |
72 |
|
* @param atom The atom to preregister |
73 |
|
*/ |
74 |
|
void preRegister(TNode atom); |
75 |
|
/** |
76 |
|
* Pre-notify assertion fact with the given atom. This is called when any |
77 |
|
* fact is asserted in TheoryEngine, just before it is dispatched to the |
78 |
|
* appropriate theory. |
79 |
|
* |
80 |
|
* This calls Theory::notifySharedTerm for the shared terms of the atom. |
81 |
|
*/ |
82 |
|
void preNotifySharedFact(TNode atom); |
83 |
|
/** |
84 |
|
* Get the equality status of a and b. |
85 |
|
* |
86 |
|
* This method is used by theories via Valuation mostly for determining their |
87 |
|
* care graph. |
88 |
|
*/ |
89 |
|
virtual EqualityStatus getEqualityStatus(TNode a, TNode b); |
90 |
|
/** |
91 |
|
* Explain literal, which returns a conjunction of literals that entail |
92 |
|
* the given one. |
93 |
|
*/ |
94 |
|
virtual TrustNode explain(TNode literal, TheoryId id) = 0; |
95 |
|
/** |
96 |
|
* Assert equality to the shared terms database. |
97 |
|
* |
98 |
|
* This method is called by TheoryEngine when a fact has been marked to |
99 |
|
* send to THEORY_BUILTIN, meaning that shared terms database should |
100 |
|
* maintain this fact. This is the case when either an equality is |
101 |
|
* asserted from the SAT solver or a theory propagates an equality between |
102 |
|
* shared terms. |
103 |
|
*/ |
104 |
|
virtual void assertSharedEquality(TNode equality, |
105 |
|
bool polarity, |
106 |
|
TNode reason) = 0; |
107 |
|
/** Is term t a shared term? */ |
108 |
|
virtual bool isShared(TNode t) const; |
109 |
|
|
110 |
|
/** |
111 |
|
* Method called by equalityEngine when a becomes (dis-)equal to b and a and b |
112 |
|
* are shared with the theory. Returns false if there is a direct conflict |
113 |
|
* (via rewrite for example). |
114 |
|
*/ |
115 |
|
bool propagateSharedEquality(theory::TheoryId theory, |
116 |
|
TNode a, |
117 |
|
TNode b, |
118 |
|
bool value); |
119 |
|
/** Send lemma to the theory engine, atomsTo is the theory to send atoms to */ |
120 |
|
void sendLemma(TrustNode trn, TheoryId atomsTo); |
121 |
|
|
122 |
|
protected: |
123 |
|
/** Solver-specific pre-register shared */ |
124 |
|
virtual void preRegisterSharedInternal(TNode t) = 0; |
125 |
|
/** Reference to the theory engine */ |
126 |
|
TheoryEngine& d_te; |
127 |
|
/** Logic info of theory engine (cached) */ |
128 |
|
const LogicInfo& d_logicInfo; |
129 |
|
/** The database of shared terms.*/ |
130 |
|
SharedTermsDatabase d_sharedTerms; |
131 |
|
/** Default visitor for pre-registration */ |
132 |
|
PreRegisterVisitor d_preRegistrationVisitor; |
133 |
|
/** Visitor for collecting shared terms */ |
134 |
|
SharedTermsVisitor d_sharedTermsVisitor; |
135 |
|
}; |
136 |
|
|
137 |
|
} // namespace theory |
138 |
|
} // namespace cvc5 |
139 |
|
|
140 |
|
#endif /* CVC5__THEORY__SHARED_SOLVER__H */ |