1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Haniel Barbosa, Dejan Jovanovic, Liana Hadarean |
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 |
|
* The proof-producing CNF stream. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__PROP__PROOF_CNF_STREAM_H |
19 |
|
#define CVC5__PROP__PROOF_CNF_STREAM_H |
20 |
|
|
21 |
|
#include "context/cdhashmap.h" |
22 |
|
#include "expr/node.h" |
23 |
|
#include "proof/eager_proof_generator.h" |
24 |
|
#include "proof/lazy_proof.h" |
25 |
|
#include "proof/proof_node.h" |
26 |
|
#include "proof/proof_node_manager.h" |
27 |
|
#include "proof/theory_proof_step_buffer.h" |
28 |
|
#include "prop/cnf_stream.h" |
29 |
|
#include "prop/sat_proof_manager.h" |
30 |
|
|
31 |
|
namespace cvc5 { |
32 |
|
namespace prop { |
33 |
|
|
34 |
|
class SatProofManager; |
35 |
|
|
36 |
|
/** |
37 |
|
* A proof generator for CNF transformation. It is a layer on top of CNF stream, |
38 |
|
* tracking the justifications for clauses added into the underlying SAT solver |
39 |
|
* in a user-context dependent manner in a lazy context-dependent (LazyCDProof) |
40 |
|
* object. The proof is lazy because formulas asserted to this class may also |
41 |
|
* take proof generators (which is the case, for example, for theory lemmas), so |
42 |
|
* that getting the proof of a clausified formula will also extend to its |
43 |
|
* registered proof generator. |
44 |
|
*/ |
45 |
2498 |
class ProofCnfStream : public ProofGenerator |
46 |
|
{ |
47 |
|
public: |
48 |
|
ProofCnfStream(context::UserContext* u, |
49 |
|
CnfStream& cnfStream, |
50 |
|
SatProofManager* satPM, |
51 |
|
ProofNodeManager* pnm); |
52 |
|
|
53 |
|
/** Invokes getProofFor of the underlying LazyCDProof */ |
54 |
|
std::shared_ptr<ProofNode> getProofFor(Node f) override; |
55 |
|
/** Whether there is a concrete step or a generator associated with f in the |
56 |
|
* underlying LazyCDProof. */ |
57 |
|
bool hasProofFor(Node f) override; |
58 |
|
/** identify */ |
59 |
|
std::string identify() const override; |
60 |
|
/** |
61 |
|
* Converts a formula into CNF into CNF and asserts the generated clauses into |
62 |
|
* the underlying SAT solver of d_cnfStream. Every transformation the formula |
63 |
|
* goes through is saved as a concrete step in d_proof. |
64 |
|
* |
65 |
|
* The given formula has arbitrary Boolean structure via kinds AND, OR, EQUAL, |
66 |
|
* XOR, IMPLIES. ITE and NOT. The conversion is done polynomially via Tseitin |
67 |
|
* transformation, with the children of non-conjunctive kinds being abstracted |
68 |
|
* as new literals, which are clausified with the respective "handle" methods |
69 |
|
* below. |
70 |
|
|
71 |
|
* @param node formula to convert and assert |
72 |
|
* @param negated whether we are asserting the node negated |
73 |
|
* @param removable whether the SAT solver can choose to remove the clauses |
74 |
|
* @param pg a proof generator for node |
75 |
|
*/ |
76 |
|
void convertAndAssert(TNode node, |
77 |
|
bool negated, |
78 |
|
bool removable, |
79 |
|
ProofGenerator* pg); |
80 |
|
|
81 |
|
/** |
82 |
|
* Clausifies the given propagation lemma *without* registering the resoluting |
83 |
|
* clause in the SAT solver, as this is handled internally by the SAT |
84 |
|
* solver. The clausification steps and the generator within the trust node |
85 |
|
* are saved in d_proof if we are producing proofs in the theory engine. */ |
86 |
|
void convertPropagation(TrustNode ttn); |
87 |
|
/** |
88 |
|
* Ensure that the given node will have a designated SAT literal that is |
89 |
|
* definitionally equal to it. The result of this function is that the Node |
90 |
|
* can be queried via getSatValue(). Essentially, this is like a "convert-but- |
91 |
|
* don't-assert" version of convertAndAssert(). |
92 |
|
*/ |
93 |
|
void ensureLiteral(TNode n); |
94 |
|
|
95 |
|
/** |
96 |
|
* Blocks a proof, so that it is not further updated by a post processor of |
97 |
|
* this class's proof. */ |
98 |
|
void addBlocked(std::shared_ptr<ProofNode> pfn); |
99 |
|
|
100 |
|
/** |
101 |
|
* Whether a given proof is blocked for further updates. An example of a |
102 |
|
* blocked proof node is one integrated into this class via an external proof |
103 |
|
* generator. */ |
104 |
|
bool isBlocked(std::shared_ptr<ProofNode> pfn); |
105 |
|
|
106 |
|
private: |
107 |
|
/** |
108 |
|
* Same as above, except that uses the saved d_removable flag. It calls the |
109 |
|
* dedicated converter for the possible formula kinds. |
110 |
|
*/ |
111 |
|
void convertAndAssert(TNode node, bool negated); |
112 |
|
/** Specific converters for each formula kind. */ |
113 |
|
void convertAndAssertAnd(TNode node, bool negated); |
114 |
|
void convertAndAssertOr(TNode node, bool negated); |
115 |
|
void convertAndAssertXor(TNode node, bool negated); |
116 |
|
void convertAndAssertIff(TNode node, bool negated); |
117 |
|
void convertAndAssertImplies(TNode node, bool negated); |
118 |
|
void convertAndAssertIte(TNode node, bool negated); |
119 |
|
/** |
120 |
|
* Transforms the node into CNF recursively and yields a literal |
121 |
|
* definitionally equal to it. |
122 |
|
* |
123 |
|
* This method also populates caches, kept in d_cnfStream, between formulas |
124 |
|
* and literals to avoid redundant work and to retrieve formulas from literals |
125 |
|
* and vice-versa. |
126 |
|
* |
127 |
|
* @param node the formula to transform |
128 |
|
* @param negated whether the literal is negated |
129 |
|
* @return the literal representing the root of the formula |
130 |
|
*/ |
131 |
|
SatLiteral toCNF(TNode node, bool negated = false); |
132 |
|
/** |
133 |
|
* Specific clausifiers, based on the formula kinds, that clausify a formula, |
134 |
|
* by calling toCNF into each of the formula's children under the respective |
135 |
|
* kind, and introduce a literal definitionally equal to it. */ |
136 |
|
SatLiteral handleXor(TNode node); |
137 |
|
SatLiteral handleImplies(TNode node); |
138 |
|
SatLiteral handleIff(TNode node); |
139 |
|
SatLiteral handleIte(TNode node); |
140 |
|
SatLiteral handleAnd(TNode node); |
141 |
|
SatLiteral handleOr(TNode node); |
142 |
|
|
143 |
|
/** Normalizes a clause node and registers it in the SAT proof manager. |
144 |
|
* |
145 |
|
* Normalization (factoring, reordering, double negation elimination) is done |
146 |
|
* via the TheoryProofStepBuffer of this class, which will register the |
147 |
|
* respective steps, if any. This normalization is necessary so that the |
148 |
|
* resulting clauses of the clausification process are synchronized with the |
149 |
|
* clauses used in the underlying SAT solver, which automatically performs the |
150 |
|
* above normalizations on all added clauses. |
151 |
|
*/ |
152 |
|
void normalizeAndRegister(TNode clauseNode); |
153 |
|
|
154 |
|
/** Reference to the underlying cnf stream. */ |
155 |
|
CnfStream& d_cnfStream; |
156 |
|
/** The proof manager of underlying SAT solver associated with this stream. */ |
157 |
|
SatProofManager* d_satPM; |
158 |
|
/** The proof node manager. */ |
159 |
|
ProofNodeManager* d_pnm; |
160 |
|
/** The user-context-dependent proof object. */ |
161 |
|
LazyCDProof d_proof; |
162 |
|
/** An accumulator of steps that may be applied to normalize the clauses |
163 |
|
* generated during clausification. */ |
164 |
|
TheoryProofStepBuffer d_psb; |
165 |
|
/** Blocked proofs. |
166 |
|
* |
167 |
|
* These are proof nodes added to this class by external generators. */ |
168 |
|
context::CDHashSet<std::shared_ptr<ProofNode>, ProofNodeHashFunction> |
169 |
|
d_blocked; |
170 |
|
}; |
171 |
|
|
172 |
|
} // namespace prop |
173 |
|
} // namespace cvc5 |
174 |
|
|
175 |
|
#endif |