1 /********************* */
2 /*! \file output_channel.h
4 ** Original author: Morgan Deters
5 ** Major contributors: none
6 ** Minor contributors (to current version): Andrew Reynolds, Dejan Jovanovic, Tim King
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2013 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief The theory output channel interface
14 ** The theory output channel interface.
17 #include "cvc4_private.h"
19 #ifndef __CVC4__THEORY__OUTPUT_CHANNEL_H
20 #define __CVC4__THEORY__OUTPUT_CHANNEL_H
22 #include "util/cvc4_assert.h"
23 #include "theory/interrupted.h"
31 * A LemmaStatus, returned from OutputChannel::lemma(), provides information
32 * about the lemma added. In particular, it contains the T-rewritten lemma
33 * for inspection and the user-level at which the lemma will reside.
36 Node d_rewrittenLemma
;
40 LemmaStatus(TNode rewrittenLemma
, unsigned level
) :
41 d_rewrittenLemma(rewrittenLemma
),
45 /** Get the T-rewritten form of the lemma. */
46 TNode
getRewrittenLemma() const throw() { return d_rewrittenLemma
; }
49 * Get the user-level at which the lemma resides. After this user level
50 * is popped, the lemma is un-asserted from the SAT layer. This level
51 * will be 0 if the lemma didn't reach the SAT layer at all.
53 unsigned getLevel() const throw() { return d_level
; }
55 };/* class LemmaStatus */
58 * Generic "theory output channel" interface.
61 /** Disallow copying: private constructor */
62 OutputChannel(const OutputChannel
&) CVC4_UNDEFINED
;
64 /** Disallow assignment: private operator=() */
65 OutputChannel
& operator=(const OutputChannel
&) CVC4_UNDEFINED
;
70 * Construct an OutputChannel.
76 * Destructs an OutputChannel. This implementation does nothing,
77 * but we need a virtual destructor for safety in case subclasses
80 virtual ~OutputChannel() {
84 * With safePoint(), the theory signals that it is at a safe point
85 * and can be interrupted.
87 virtual void safePoint() throw(Interrupted
, AssertionException
) {
91 * Indicate a theory conflict has arisen.
93 * @param n - a conflict at the current decision level. This should
94 * be an AND-kinded node of literals that are TRUE in the current
95 * assignment and are in conflict (i.e., at least one must be
96 * assigned false), or else a literal by itself (in the case of a
97 * unit conflict) which is assigned TRUE (and T-conflicting) in the
100 virtual void conflict(TNode n
) throw(AssertionException
) = 0;
103 * Propagate a theory literal.
105 * @param n - a theory consequence at the current decision level
106 * @return false if an immediate conflict was encountered
108 virtual bool propagate(TNode n
) throw(AssertionException
) = 0;
111 * Tell the core that a valid theory lemma at decision level 0 has
112 * been detected. (This requests a split.)
114 * @param n - a theory lemma valid at decision level 0
115 * @param removable - whether the lemma can be removed at any point
116 * @param preprocess - whether to apply more aggressive preprocessing
117 * @return the "status" of the lemma, including user level at which
118 * the lemma resides; the lemma will be removed when this user level pops
120 virtual LemmaStatus
lemma(TNode n
, bool removable
= false,
121 bool preprocess
= false)
122 throw(TypeCheckingExceptionPrivate
, AssertionException
) = 0;
125 * Request a split on a new theory atom. This is equivalent to
126 * calling lemma({OR n (NOT n)}).
128 * @param n - a theory atom; must be of Boolean type
130 LemmaStatus
split(TNode n
)
131 throw(TypeCheckingExceptionPrivate
, AssertionException
) {
132 return splitLemma(n
.orNode(n
.notNode()));
135 virtual LemmaStatus
splitLemma(TNode n
, bool removable
= false)
136 throw(TypeCheckingExceptionPrivate
, AssertionException
) = 0;
139 * If a decision is made on n, it must be in the phase specified.
140 * Note that this is enforced *globally*, i.e., it is completely
141 * context-INdependent. If you ever requirePhase() on a literal,
142 * it is phase-locked forever and ever. If it is to ever have the
143 * other phase as its assignment, it will be because it has been
144 * propagated that way (or it's a unit, at decision level 0).
146 * @param n - a theory atom with a SAT literal assigned; must have
147 * been pre-registered
148 * @param phase - the phase to decide on n
150 virtual void requirePhase(TNode n
, bool phase
)
151 throw(Interrupted
, TypeCheckingExceptionPrivate
, AssertionException
) = 0;
154 * Flips the most recent unflipped decision to the other phase and
155 * returns true. If all decisions have been flipped, the root
156 * decision is re-flipped and flipDecision() returns false. If no
157 * decisions (flipped nor unflipped) are on the decision stack, the
158 * state is not affected and flipDecision() returns false.
160 * For example, if l1, l2, and l3 are all decision literals, and
161 * have been decided in positive phase, a series of flipDecision()
162 * calls has the following effects:
168 * l1 (and flipDecision() returns false)
170 * Naturally, flipDecision() might be interleaved with search. For example:
173 * flipDecision() <br/>
175 * flipDecision() <br/>
177 * SAT decides l3 <br/>
179 * flipDecision() <br/>
181 * flipDecision() <br/>
183 * SAT decides l2 <br/>
185 * flipDecision() <br/>
187 * flipDecision() returns FALSE<br/>
190 * @return true if a decision was flipped; false if no decision
191 * could be flipped, or if the root decision was re-flipped
193 virtual bool flipDecision()
194 throw(Interrupted
, TypeCheckingExceptionPrivate
, AssertionException
) = 0;
197 * Notification from a theory that it realizes it is incomplete at
198 * this context level. If SAT is later determined by the
199 * TheoryEngine, it should actually return an UNKNOWN result.
201 virtual void setIncomplete() throw(AssertionException
) = 0;
204 * "Spend" a "resource." The meaning is specific to the context in
205 * which the theory is operating, and may even be ignored. The
206 * intended meaning is that if the user has set a limit on the "units
207 * of resource" that can be expended in a search, and that limit is
208 * exceeded, then the search is terminated. Note that the check for
209 * termination occurs in the main search loop, so while theories
210 * should call OutputChannel::spendResource() during particularly
211 * long-running operations, they cannot rely on resource() to break
212 * out of infinite or intractable computations.
214 virtual void spendResource() throw() {}
217 * Handle user attribute.
218 * Associates theory t with the attribute attr. Theory t will be
219 * notified whenever an attribute of name attr is set on a node.
220 * This can happen through, for example, the SMT-LIBv2 language.
222 virtual void handleUserAttribute(const char* attr
, Theory
* t
) {}
225 /** Demands that the search restart from sat search level 0.
226 * Using this leads to non-termination issues.
227 * It is appropriate for prototyping for theories.
229 virtual void demandRestart() throw(TypeCheckingExceptionPrivate
, AssertionException
) {}
231 };/* class OutputChannel */
233 }/* CVC4::theory namespace */
234 }/* CVC4 namespace */
236 #endif /* __CVC4__THEORY__OUTPUT_CHANNEL_H */