1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Alex Ozdemir |
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 |
|
* Implementation of the abstract proof generator class. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "proof/eager_proof_generator.h" |
17 |
|
|
18 |
|
#include "proof/proof.h" |
19 |
|
#include "proof/proof_node.h" |
20 |
|
#include "proof/proof_node_manager.h" |
21 |
|
|
22 |
|
namespace cvc5 { |
23 |
|
|
24 |
86281 |
EagerProofGenerator::EagerProofGenerator(ProofNodeManager* pnm, |
25 |
|
context::Context* c, |
26 |
86281 |
std::string name) |
27 |
86281 |
: d_pnm(pnm), d_name(name), d_proofs(c == nullptr ? &d_context : c) |
28 |
|
{ |
29 |
86281 |
} |
30 |
|
|
31 |
378832 |
void EagerProofGenerator::setProofFor(Node f, std::shared_ptr<ProofNode> pf) |
32 |
|
{ |
33 |
|
// pf should prove f |
34 |
757664 |
Assert(pf->getResult() == f) |
35 |
|
<< "EagerProofGenerator::setProofFor: unexpected result" << std::endl |
36 |
378832 |
<< "Expected: " << f << std::endl |
37 |
378832 |
<< "Actual: " << pf->getResult() << std::endl; |
38 |
378832 |
d_proofs[f] = pf; |
39 |
378832 |
} |
40 |
16417 |
void EagerProofGenerator::setProofForConflict(Node conf, |
41 |
|
std::shared_ptr<ProofNode> pf) |
42 |
|
{ |
43 |
|
// Normalize based on key |
44 |
32834 |
Node ckey = TrustNode::getConflictProven(conf); |
45 |
16417 |
setProofFor(ckey, pf); |
46 |
16417 |
} |
47 |
|
|
48 |
255406 |
void EagerProofGenerator::setProofForLemma(Node lem, |
49 |
|
std::shared_ptr<ProofNode> pf) |
50 |
|
{ |
51 |
|
// Normalize based on key |
52 |
510812 |
Node lkey = TrustNode::getLemmaProven(lem); |
53 |
255406 |
setProofFor(lkey, pf); |
54 |
255406 |
} |
55 |
|
|
56 |
58511 |
void EagerProofGenerator::setProofForPropExp(TNode lit, |
57 |
|
Node exp, |
58 |
|
std::shared_ptr<ProofNode> pf) |
59 |
|
{ |
60 |
|
// Normalize based on key |
61 |
117022 |
Node pekey = TrustNode::getPropExpProven(lit, exp); |
62 |
58511 |
setProofFor(pekey, pf); |
63 |
58511 |
} |
64 |
|
|
65 |
139345 |
std::shared_ptr<ProofNode> EagerProofGenerator::getProofFor(Node f) |
66 |
|
{ |
67 |
139345 |
NodeProofNodeMap::iterator it = d_proofs.find(f); |
68 |
139345 |
if (it == d_proofs.end()) |
69 |
|
{ |
70 |
2690 |
return nullptr; |
71 |
|
} |
72 |
136655 |
return (*it).second; |
73 |
|
} |
74 |
|
|
75 |
889666 |
bool EagerProofGenerator::hasProofFor(Node f) |
76 |
|
{ |
77 |
889666 |
return d_proofs.find(f) != d_proofs.end(); |
78 |
|
} |
79 |
|
|
80 |
263825 |
TrustNode EagerProofGenerator::mkTrustNode(Node n, |
81 |
|
std::shared_ptr<ProofNode> pf, |
82 |
|
bool isConflict) |
83 |
|
{ |
84 |
263825 |
if (pf == nullptr) |
85 |
|
{ |
86 |
|
return TrustNode::null(); |
87 |
|
} |
88 |
263825 |
if (isConflict) |
89 |
|
{ |
90 |
|
// this shouldnt modify the key |
91 |
13403 |
setProofForConflict(n, pf); |
92 |
|
// we can now return the trust node |
93 |
13403 |
return TrustNode::mkTrustConflict(n, this); |
94 |
|
} |
95 |
|
// this shouldnt modify the key |
96 |
250422 |
setProofForLemma(n, pf); |
97 |
|
// we can now return the trust node |
98 |
250422 |
return TrustNode::mkTrustLemma(n, this); |
99 |
|
} |
100 |
|
|
101 |
14380 |
TrustNode EagerProofGenerator::mkTrustNode(Node conc, |
102 |
|
PfRule id, |
103 |
|
const std::vector<Node>& exp, |
104 |
|
const std::vector<Node>& args, |
105 |
|
bool isConflict) |
106 |
|
{ |
107 |
|
// if no children, its easy |
108 |
14380 |
if (exp.empty()) |
109 |
|
{ |
110 |
28098 |
std::shared_ptr<ProofNode> pf = d_pnm->mkNode(id, {}, args, conc); |
111 |
14049 |
return mkTrustNode(conc, pf, isConflict); |
112 |
|
} |
113 |
|
// otherwise, we use CDProof + SCOPE |
114 |
662 |
CDProof cdp(d_pnm); |
115 |
331 |
cdp.addStep(conc, id, exp, args); |
116 |
662 |
std::shared_ptr<ProofNode> pf = cdp.getProofFor(conc); |
117 |
|
// We use mkNode instead of mkScope, since there is no reason to check |
118 |
|
// whether the free assumptions of pf are in exp, since they are by the |
119 |
|
// construction above. |
120 |
662 |
std::shared_ptr<ProofNode> pfs = d_pnm->mkNode(PfRule::SCOPE, {pf}, exp); |
121 |
331 |
return mkTrustNode(pfs->getResult(), pfs, isConflict); |
122 |
|
} |
123 |
|
|
124 |
2647 |
TrustNode EagerProofGenerator::mkTrustedRewrite(Node a, |
125 |
|
Node b, |
126 |
|
std::shared_ptr<ProofNode> pf) |
127 |
|
{ |
128 |
2647 |
if (pf == nullptr) |
129 |
|
{ |
130 |
|
return TrustNode::null(); |
131 |
|
} |
132 |
5294 |
Node eq = a.eqNode(b); |
133 |
2647 |
setProofFor(eq, pf); |
134 |
2647 |
return TrustNode::mkTrustRewrite(a, b, this); |
135 |
|
} |
136 |
|
|
137 |
3040 |
TrustNode EagerProofGenerator::mkTrustedPropagation( |
138 |
|
Node n, Node exp, std::shared_ptr<ProofNode> pf) |
139 |
|
{ |
140 |
3040 |
if (pf == nullptr) |
141 |
|
{ |
142 |
|
return TrustNode::null(); |
143 |
|
} |
144 |
3040 |
setProofForPropExp(n, exp, pf); |
145 |
3040 |
return TrustNode::mkTrustPropExp(n, exp, this); |
146 |
|
} |
147 |
|
|
148 |
10029 |
TrustNode EagerProofGenerator::mkTrustNodeSplit(Node f) |
149 |
|
{ |
150 |
|
// make the lemma |
151 |
20058 |
Node lem = f.orNode(f.notNode()); |
152 |
20058 |
return mkTrustNode(lem, PfRule::SPLIT, {}, {f}, false); |
153 |
|
} |
154 |
|
|
155 |
284389 |
std::string EagerProofGenerator::identify() const { return d_name; } |
156 |
|
|
157 |
29511 |
} // namespace cvc5 |