1 /********************* */
2 /*! \file inference_manager_buffered.cpp
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Gereon Kremer
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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.\endverbatim
12 ** \brief A buffered inference manager
15 #include "theory/inference_manager_buffered.h"
17 #include "theory/rewriter.h"
18 #include "theory/theory.h"
20 using namespace CVC4::kind
;
25 InferenceManagerBuffered::InferenceManagerBuffered(Theory
& t
,
27 ProofNodeManager
* pnm
,
28 const std::string
& name
,
30 : TheoryInferenceManager(t
, state
, pnm
, name
, cacheLemmas
),
31 d_processingPendingLemmas(false)
35 bool InferenceManagerBuffered::hasPending() const
37 return hasPendingFact() || hasPendingLemma();
40 bool InferenceManagerBuffered::hasPendingFact() const
42 return !d_pendingFact
.empty();
45 bool InferenceManagerBuffered::hasPendingLemma() const
47 return !d_pendingLem
.empty();
50 bool InferenceManagerBuffered::addPendingLemma(Node lem
,
58 // check if it is unique up to rewriting
59 Node lemr
= Rewriter::rewrite(lem
);
60 if (hasCachedLemma(lemr
, p
))
65 // make the simple theory lemma
66 d_pendingLem
.emplace_back(new SimpleTheoryLemma(id
, lem
, p
, pg
));
70 void InferenceManagerBuffered::addPendingLemma(
71 std::unique_ptr
<TheoryInference
> lemma
)
73 d_pendingLem
.emplace_back(std::move(lemma
));
76 void InferenceManagerBuffered::addPendingFact(Node conc
,
81 // make a simple theory internal fact
82 Assert(conc
.getKind() != AND
&& conc
.getKind() != OR
);
83 d_pendingFact
.emplace_back(new SimpleTheoryInternalFact(id
, conc
, exp
, pg
));
86 void InferenceManagerBuffered::addPendingFact(
87 std::unique_ptr
<TheoryInference
> fact
)
89 d_pendingFact
.emplace_back(std::move(fact
));
92 void InferenceManagerBuffered::addPendingPhaseRequirement(Node lit
, bool pol
)
94 // it is the responsibility of the caller to ensure lit is rewritten
95 d_pendingReqPhase
[lit
] = pol
;
98 void InferenceManagerBuffered::doPendingFacts()
101 while (!d_theoryState
.isInConflict() && i
< d_pendingFact
.size())
103 // assert the internal fact, which notice may enqueue more pending facts in
104 // this loop, or result in a conflict.
105 assertInternalFactTheoryInference(d_pendingFact
[i
].get());
108 d_pendingFact
.clear();
111 void InferenceManagerBuffered::doPendingLemmas()
113 if (d_processingPendingLemmas
)
115 // already processing
118 d_processingPendingLemmas
= true;
120 while (i
< d_pendingLem
.size())
122 // process this lemma, which notice may enqueue more pending lemmas in this
123 // loop, or clear the lemmas.
124 lemmaTheoryInference(d_pendingLem
[i
].get());
127 d_pendingLem
.clear();
128 d_processingPendingLemmas
= false;
131 void InferenceManagerBuffered::doPendingPhaseRequirements()
133 // process the pending require phase calls
134 for (const std::pair
<const Node
, bool>& prp
: d_pendingReqPhase
)
136 requirePhase(prp
.first
, prp
.second
);
138 d_pendingReqPhase
.clear();
140 void InferenceManagerBuffered::clearPending()
142 d_pendingFact
.clear();
143 d_pendingLem
.clear();
144 d_pendingReqPhase
.clear();
146 void InferenceManagerBuffered::clearPendingFacts() { d_pendingFact
.clear(); }
147 void InferenceManagerBuffered::clearPendingLemmas() { d_pendingLem
.clear(); }
148 void InferenceManagerBuffered::clearPendingPhaseRequirements()
150 d_pendingReqPhase
.clear();
153 std::size_t InferenceManagerBuffered::numPendingLemmas() const
155 return d_pendingLem
.size();
157 std::size_t InferenceManagerBuffered::numPendingFacts() const
159 return d_pendingFact
.size();
162 void InferenceManagerBuffered::lemmaTheoryInference(TheoryInference
* lem
)
164 // process this lemma
165 LemmaProperty p
= LemmaProperty::NONE
;
166 TrustNode tlem
= lem
->processLemma(p
);
167 Assert(!tlem
.isNull());
169 trustedLemma(tlem
, lem
->getId(), p
);
172 void InferenceManagerBuffered::assertInternalFactTheoryInference(
173 TheoryInference
* fact
)
176 std::vector
<Node
> exp
;
177 ProofGenerator
* pg
= nullptr;
178 Node lit
= fact
->processFact(exp
, pg
);
179 Assert(!lit
.isNull());
180 bool pol
= lit
.getKind() != NOT
;
181 TNode atom
= pol
? lit
: lit
[0];
182 // no double negation or conjunctive conclusions
183 Assert(atom
.getKind() != NOT
&& atom
.getKind() != AND
);
184 // assert the internal fact
185 assertInternalFact(atom
, pol
, fact
->getId(), exp
, pg
);
188 } // namespace theory