1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, 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 |
|
* The trust node utility. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__PROOF__TRUST_NODE_H |
19 |
|
#define CVC5__PROOF__TRUST_NODE_H |
20 |
|
|
21 |
|
#include "expr/node.h" |
22 |
|
|
23 |
|
namespace cvc5 { |
24 |
|
|
25 |
|
class ProofGenerator; |
26 |
|
class ProofNode; |
27 |
|
|
28 |
|
/** A kind for trust nodes */ |
29 |
|
enum class TrustNodeKind : uint32_t |
30 |
|
{ |
31 |
|
CONFLICT, |
32 |
|
LEMMA, |
33 |
|
PROP_EXP, |
34 |
|
REWRITE, |
35 |
|
INVALID |
36 |
|
}; |
37 |
|
/** |
38 |
|
* Converts a proof rule to a string. Note: This function is also used in |
39 |
|
* `safe_print()`. Changing this function name or signature will result in |
40 |
|
* `safe_print()` printing "<unsupported>" instead of the proper strings for |
41 |
|
* the enum values. |
42 |
|
* |
43 |
|
* Returns a string with static lifetime: it should not be freed. |
44 |
|
* |
45 |
|
* @param tnk The trust node kind |
46 |
|
* @return The name of the trust node kind |
47 |
|
*/ |
48 |
|
const char* toString(TrustNodeKind tnk); |
49 |
|
|
50 |
|
/** |
51 |
|
* Writes a trust node kind name to a stream. |
52 |
|
* |
53 |
|
* @param out The stream to write to |
54 |
|
* @param tnk The trust node kind to write to the stream |
55 |
|
* @return The stream |
56 |
|
*/ |
57 |
|
std::ostream& operator<<(std::ostream& out, TrustNodeKind tnk); |
58 |
|
|
59 |
|
/** |
60 |
|
* A trust node is a pair (F, G) where F is a formula and G is a proof |
61 |
|
* generator that can construct a proof for F if asked. |
62 |
|
* |
63 |
|
* More generally, a trust node is any node that can be used for a specific |
64 |
|
* purpose that requires justification, such as being passed to |
65 |
|
* OutputChannel::lemma. That justification is intended to be given by the |
66 |
|
* generator that is required to construct this object. |
67 |
|
* |
68 |
|
* They are intended to be constructed by ProofGenerator objects themselves (a |
69 |
|
* proof generator wraps itself in TrustNode it returns) and passed |
70 |
|
* to ProofOutputChannel by theory solvers. |
71 |
|
* |
72 |
|
* The static functions for constructing them check that the generator, if |
73 |
|
* provided, is capable of proving the given conflict or lemma, or an assertion |
74 |
|
* failure occurs. Otherwise an assertion error is given. |
75 |
|
* |
76 |
|
* While this is not enforced, a `TrustNode` generally encapsulates a **closed** |
77 |
|
* proof of the formula: one without free assumptions. |
78 |
|
*/ |
79 |
9367591 |
class TrustNode |
80 |
|
{ |
81 |
|
public: |
82 |
3400726 |
TrustNode() : d_tnk(TrustNodeKind::INVALID), d_gen(nullptr) {} |
83 |
|
/** Make a proven node for conflict */ |
84 |
|
static TrustNode mkTrustConflict(Node conf, ProofGenerator* g = nullptr); |
85 |
|
/** Make a proven node for lemma */ |
86 |
|
static TrustNode mkTrustLemma(Node lem, ProofGenerator* g = nullptr); |
87 |
|
/** Make a proven node for explanation of propagated literal */ |
88 |
|
static TrustNode mkTrustPropExp(TNode lit, |
89 |
|
Node exp, |
90 |
|
ProofGenerator* g = nullptr); |
91 |
|
/** Make a proven node for rewrite */ |
92 |
|
static TrustNode mkTrustRewrite(TNode n, |
93 |
|
Node nr, |
94 |
|
ProofGenerator* g = nullptr); |
95 |
|
/** The null proven node */ |
96 |
|
static TrustNode null(); |
97 |
20210080 |
~TrustNode() {} |
98 |
|
/** get kind */ |
99 |
|
TrustNodeKind getKind() const; |
100 |
|
/** get node |
101 |
|
* |
102 |
|
* This is the node that is used in a common interface, either: |
103 |
|
* (1) A T-unsat conjunction conf to pass to OutputChannel::conflict, |
104 |
|
* (2) A valid T-formula lem to pass to OutputChannel::lemma, |
105 |
|
* (3) A conjunction of literals exp to return in Theory::explain(lit), or |
106 |
|
* (4) A result of rewriting a term n into an equivalent one nr. |
107 |
|
* |
108 |
|
* Notice that this node does not necessarily correspond to a valid formula. |
109 |
|
* The call getProven() below retrieves a valid formula corresponding to |
110 |
|
* the above calls. |
111 |
|
*/ |
112 |
|
Node getNode() const; |
113 |
|
/** get proven |
114 |
|
* |
115 |
|
* This is the corresponding formula that is proven by the proof generator |
116 |
|
* for the above cases: |
117 |
|
* (1) (not conf), for conflicts, |
118 |
|
* (2) lem, for lemmas, |
119 |
|
* (3) (=> exp lit), for propagations from explanations, |
120 |
|
* (4) (= n nr), for results of rewriting. |
121 |
|
* |
122 |
|
* When constructing this trust node, the proof generator should be able to |
123 |
|
* provide a proof for this fact. |
124 |
|
*/ |
125 |
|
Node getProven() const; |
126 |
|
/** get generator */ |
127 |
|
ProofGenerator* getGenerator() const; |
128 |
|
/** is null? */ |
129 |
|
bool isNull() const; |
130 |
|
/** |
131 |
|
* Gets the proof node for this trust node, which is obtained by |
132 |
|
* calling the generator's getProofFor method on the proven node. |
133 |
|
*/ |
134 |
|
std::shared_ptr<ProofNode> toProofNode() const; |
135 |
|
|
136 |
|
/** Get the proven formula corresponding to a conflict call */ |
137 |
|
static Node getConflictProven(Node conf); |
138 |
|
/** Get the proven formula corresponding to a lemma call */ |
139 |
|
static Node getLemmaProven(Node lem); |
140 |
|
/** Get the proven formula corresponding to explanations for propagation */ |
141 |
|
static Node getPropExpProven(TNode lit, Node exp); |
142 |
|
/** Get the proven formula corresponding to a rewrite */ |
143 |
|
static Node getRewriteProven(TNode n, Node nr); |
144 |
|
/** For debugging */ |
145 |
|
std::string identifyGenerator() const; |
146 |
|
|
147 |
|
/** |
148 |
|
* debug check closed on Trace c, context ctx is string for debugging |
149 |
|
* |
150 |
|
* @param reqNullGen Whether we consider a null generator to be a failure. |
151 |
|
*/ |
152 |
|
void debugCheckClosed(const char* c, const char* ctx, bool reqNullGen = true); |
153 |
|
|
154 |
|
private: |
155 |
|
TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g = nullptr); |
156 |
|
/** The kind */ |
157 |
|
TrustNodeKind d_tnk; |
158 |
|
/** The proven node */ |
159 |
|
Node d_proven; |
160 |
|
/** The generator */ |
161 |
|
ProofGenerator* d_gen; |
162 |
|
}; |
163 |
|
|
164 |
|
/** |
165 |
|
* Writes a trust node to a stream. |
166 |
|
* |
167 |
|
* @param out The stream to write to |
168 |
|
* @param n The trust node to write to the stream |
169 |
|
* @return The stream |
170 |
|
*/ |
171 |
|
std::ostream& operator<<(std::ostream& out, TrustNode n); |
172 |
|
|
173 |
|
} // namespace cvc5 |
174 |
|
|
175 |
|
#endif /* CVC5__PROOF__TRUST_NODE_H */ |