1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Alex Ozdemir, 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 eager proof generator class. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__PROOF__EAGER_PROOF_GENERATOR_H |
19 |
|
#define CVC5__PROOF__EAGER_PROOF_GENERATOR_H |
20 |
|
|
21 |
|
#include "context/cdhashmap.h" |
22 |
|
#include "expr/node.h" |
23 |
|
#include "proof/proof_generator.h" |
24 |
|
#include "proof/proof_rule.h" |
25 |
|
#include "proof/trust_node.h" |
26 |
|
|
27 |
|
namespace cvc5 { |
28 |
|
|
29 |
|
class ProofNode; |
30 |
|
class ProofNodeManager; |
31 |
|
|
32 |
|
/** |
33 |
|
* An eager proof generator, with explicit proof caching. |
34 |
|
* |
35 |
|
* The intended use of this class is to store proofs for lemmas and conflicts |
36 |
|
* at the time they are sent out on the ProofOutputChannel. This means that the |
37 |
|
* getProofForConflict and getProofForLemma methods are lookups in a |
38 |
|
* (user-context depedent) map, the field d_proofs below. |
39 |
|
* |
40 |
|
* In detail, the method setProofForConflict(conf, pf) should be called prior to |
41 |
|
* calling ProofOutputChannel(TrustNode(conf,X)), where X is this generator. |
42 |
|
* Similarly for setProofForLemma. |
43 |
|
* |
44 |
|
* The intended usage of this class in combination with OutputChannel is |
45 |
|
* the following: |
46 |
|
* //----------------------------------------------------------- |
47 |
|
* class MyEagerProofGenerator : public EagerProofGenerator |
48 |
|
* { |
49 |
|
* public: |
50 |
|
* TrustNode getProvenConflictByMethodX(...) |
51 |
|
* { |
52 |
|
* // construct a conflict |
53 |
|
* Node conf = [construct conflict]; |
54 |
|
* // construct a proof for conf |
55 |
|
* std::shared_ptr<ProofNode> pf = [construct the proof for conf]; |
56 |
|
* // wrap the conflict in a trust node |
57 |
|
* return mkTrustNode(conf,pf); |
58 |
|
* } |
59 |
|
* }; |
60 |
|
* // [1] Make objects given user context u and output channel out. |
61 |
|
* |
62 |
|
* MyEagerProofGenerator epg(u); |
63 |
|
* OutputChannel out; |
64 |
|
* |
65 |
|
* // [2] Assume epg realizes there is a conflict. We have it store the proof |
66 |
|
* // internally and return the conflict node paired with epg. |
67 |
|
* |
68 |
|
* TrustNode pconf = epg.getProvenConflictByMethodX(...); |
69 |
|
* |
70 |
|
* // [3] Send the conflict on the output channel. |
71 |
|
* |
72 |
|
* out.trustedConflict(pconf); |
73 |
|
* |
74 |
|
* // [4] The trust node has information about what is proven and who can |
75 |
|
* // prove it, where this association is valid in the remainder of the user |
76 |
|
* // context. |
77 |
|
* |
78 |
|
* Node conf = pconf.getProven(); |
79 |
|
* ProofGenerator * pg = pconf.getGenerator(); |
80 |
|
* std::shared_ptr<ProofNode> pf = pg->getProofForConflict(conf); |
81 |
|
* //----------------------------------------------------------- |
82 |
|
* In other words, the proof generator epg is responsible for creating and |
83 |
|
* storing the proof internally, and the proof output channel is responsible for |
84 |
|
* maintaining the map that epg is who to ask for the proof of the conflict. |
85 |
|
*/ |
86 |
|
class EagerProofGenerator : public ProofGenerator |
87 |
|
{ |
88 |
|
typedef context::CDHashMap<Node, std::shared_ptr<ProofNode>> NodeProofNodeMap; |
89 |
|
|
90 |
|
public: |
91 |
|
EagerProofGenerator(ProofNodeManager* pnm, |
92 |
|
context::Context* c = nullptr, |
93 |
|
std::string name = "EagerProofGenerator"); |
94 |
139829 |
~EagerProofGenerator() {} |
95 |
|
/** Get the proof for formula f. */ |
96 |
|
std::shared_ptr<ProofNode> getProofFor(Node f) override; |
97 |
|
/** Can we give the proof for formula f? */ |
98 |
|
bool hasProofFor(Node f) override; |
99 |
|
/** |
100 |
|
* Set proof for fact f, called when pf is a proof of f. |
101 |
|
* |
102 |
|
* @param f The fact proven by pf, |
103 |
|
* @param pf The proof to store in this class. |
104 |
|
*/ |
105 |
|
void setProofFor(Node f, std::shared_ptr<ProofNode> pf); |
106 |
|
/** |
107 |
|
* Make trust node: wrap n in a trust node with this generator, and have it |
108 |
|
* store the proof pf to lemma or conflict n. |
109 |
|
* |
110 |
|
* @param n The proven node, |
111 |
|
* @param pf The proof of n, |
112 |
|
* @param isConflict Whether the returned trust node is a conflict (otherwise |
113 |
|
* it is a lemma), |
114 |
|
* @return The trust node corresponding to the fact that this generator has |
115 |
|
* a proof of n. |
116 |
|
*/ |
117 |
|
TrustNode mkTrustNode(Node n, |
118 |
|
std::shared_ptr<ProofNode> pf, |
119 |
|
bool isConflict = false); |
120 |
|
/** |
121 |
|
* Make trust node from a single step proof. This is a convenience function |
122 |
|
* that avoids the need to explictly construct ProofNode by the caller. |
123 |
|
* |
124 |
|
* @param conc The conclusion of the rule, |
125 |
|
* @param id The rule of the proof concluding conc |
126 |
|
* @param exp The explanation (premises) to the proof concluding conc, |
127 |
|
* @param args The arguments to the proof concluding conc, |
128 |
|
* @param isConflict Whether the returned trust node is a conflict (otherwise |
129 |
|
* it is a lemma), |
130 |
|
* @return The trust node corresponding to the fact that this generator has |
131 |
|
* a proof of (exp => conc), or of conc if exp is empty. |
132 |
|
*/ |
133 |
|
TrustNode mkTrustNode(Node conc, |
134 |
|
PfRule id, |
135 |
|
const std::vector<Node>& exp, |
136 |
|
const std::vector<Node>& args, |
137 |
|
bool isConflict = false); |
138 |
|
/** |
139 |
|
* Make trust node: wrap `exp => n` in a trust node with this generator, and |
140 |
|
* have it store the proof `pf` too. |
141 |
|
* |
142 |
|
* @param n The implication |
143 |
|
* @param exp A conjunction of literals that imply it |
144 |
|
* @param pf The proof of exp => n, |
145 |
|
* @return The trust node corresponding to the fact that this generator has |
146 |
|
* a proof of exp => n. |
147 |
|
*/ |
148 |
|
TrustNode mkTrustedPropagation(Node n, |
149 |
|
Node exp, |
150 |
|
std::shared_ptr<ProofNode> pf); |
151 |
|
/** |
152 |
|
* Make trust node: `a = b` as a Rewrite trust node |
153 |
|
* |
154 |
|
* @param a the original |
155 |
|
* @param b what is rewrites to |
156 |
|
* @param pf The proof of a = b, |
157 |
|
* @return The trust node corresponding to the fact that this generator has |
158 |
|
* a proof of a = b |
159 |
|
*/ |
160 |
|
TrustNode mkTrustedRewrite(Node a, Node b, std::shared_ptr<ProofNode> pf); |
161 |
|
//--------------------------------------- common proofs |
162 |
|
/** |
163 |
|
* This returns the trust node corresponding to the splitting lemma |
164 |
|
* (or f (not f)) and this generator. The method registers its proof in the |
165 |
|
* map maintained by this class. |
166 |
|
*/ |
167 |
|
TrustNode mkTrustNodeSplit(Node f); |
168 |
|
//--------------------------------------- end common proofs |
169 |
|
/** identify */ |
170 |
|
std::string identify() const override; |
171 |
|
|
172 |
|
protected: |
173 |
|
/** Set that pf is the proof for conflict conf */ |
174 |
|
void setProofForConflict(Node conf, std::shared_ptr<ProofNode> pf); |
175 |
|
/** Set that pf is the proof for lemma lem */ |
176 |
|
void setProofForLemma(Node lem, std::shared_ptr<ProofNode> pf); |
177 |
|
/** Set that pf is the proof for explained propagation */ |
178 |
|
void setProofForPropExp(TNode lit, Node exp, std::shared_ptr<ProofNode> pf); |
179 |
|
/** The proof node manager */ |
180 |
|
ProofNodeManager* d_pnm; |
181 |
|
/** Name identifier */ |
182 |
|
std::string d_name; |
183 |
|
/** A dummy context used by this class if none is provided */ |
184 |
|
context::Context d_context; |
185 |
|
/** |
186 |
|
* A user-context-dependent map from lemmas and conflicts to proofs provided |
187 |
|
* by calls to setProofForConflict and setProofForLemma above. |
188 |
|
*/ |
189 |
|
NodeProofNodeMap d_proofs; |
190 |
|
}; |
191 |
|
|
192 |
|
} // namespace cvc5 |
193 |
|
|
194 |
|
#endif /* CVC5__PROOF__PROOF_GENERATOR_H */ |