1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
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 trust node utility. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "proof/trust_node.h" |
17 |
|
|
18 |
|
#include "proof/proof_ensure_closed.h" |
19 |
|
#include "proof/proof_generator.h" |
20 |
|
|
21 |
|
namespace cvc5 { |
22 |
|
|
23 |
|
const char* toString(TrustNodeKind tnk) |
24 |
|
{ |
25 |
|
switch (tnk) |
26 |
|
{ |
27 |
|
case TrustNodeKind::CONFLICT: return "CONFLICT"; |
28 |
|
case TrustNodeKind::LEMMA: return "LEMMA"; |
29 |
|
case TrustNodeKind::PROP_EXP: return "PROP_EXP"; |
30 |
|
case TrustNodeKind::REWRITE: return "REWRITE"; |
31 |
|
default: return "?"; |
32 |
|
} |
33 |
|
} |
34 |
|
|
35 |
|
std::ostream& operator<<(std::ostream& out, TrustNodeKind tnk) |
36 |
|
{ |
37 |
|
out << toString(tnk); |
38 |
|
return out; |
39 |
|
} |
40 |
|
|
41 |
290605 |
TrustNode TrustNode::mkTrustConflict(Node conf, ProofGenerator* g) |
42 |
|
{ |
43 |
581210 |
Node ckey = getConflictProven(conf); |
44 |
|
// if a generator is provided, should confirm that it can prove it |
45 |
290605 |
Assert(g == nullptr || g->hasProofFor(ckey)); |
46 |
581210 |
return TrustNode(TrustNodeKind::CONFLICT, ckey, g); |
47 |
|
} |
48 |
|
|
49 |
2301057 |
TrustNode TrustNode::mkTrustLemma(Node lem, ProofGenerator* g) |
50 |
|
{ |
51 |
4602114 |
Node lkey = getLemmaProven(lem); |
52 |
|
// if a generator is provided, should confirm that it can prove it |
53 |
2301057 |
Assert(g == nullptr || g->hasProofFor(lkey)); |
54 |
4602114 |
return TrustNode(TrustNodeKind::LEMMA, lkey, g); |
55 |
|
} |
56 |
|
|
57 |
584744 |
TrustNode TrustNode::mkTrustPropExp(TNode lit, Node exp, ProofGenerator* g) |
58 |
|
{ |
59 |
1169488 |
Node pekey = getPropExpProven(lit, exp); |
60 |
584744 |
Assert(g == nullptr || g->hasProofFor(pekey)); |
61 |
1169488 |
return TrustNode(TrustNodeKind::PROP_EXP, pekey, g); |
62 |
|
} |
63 |
|
|
64 |
2061167 |
TrustNode TrustNode::mkTrustRewrite(TNode n, Node nr, ProofGenerator* g) |
65 |
|
{ |
66 |
4122334 |
Node rkey = getRewriteProven(n, nr); |
67 |
2061167 |
Assert(g == nullptr || g->hasProofFor(rkey)); |
68 |
4122334 |
return TrustNode(TrustNodeKind::REWRITE, rkey, g); |
69 |
|
} |
70 |
|
|
71 |
|
TrustNode TrustNode::mkReplaceGenTrustNode(const TrustNode& orig, |
72 |
|
ProofGenerator* g) |
73 |
|
{ |
74 |
|
return TrustNode(orig.getKind(), orig.getProven(), g); |
75 |
|
} |
76 |
|
|
77 |
4566748 |
TrustNode TrustNode::null() |
78 |
|
{ |
79 |
4566748 |
return TrustNode(TrustNodeKind::INVALID, Node::null()); |
80 |
|
} |
81 |
|
|
82 |
9804321 |
TrustNode::TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g) |
83 |
9804321 |
: d_tnk(tnk), d_proven(p), d_gen(g) |
84 |
|
{ |
85 |
|
// does not make sense to provide null node with generator |
86 |
9804321 |
Assert(!d_proven.isNull() || d_gen == nullptr); |
87 |
9804321 |
} |
88 |
|
|
89 |
2870200 |
TrustNodeKind TrustNode::getKind() const { return d_tnk; } |
90 |
|
|
91 |
7341042 |
Node TrustNode::getNode() const |
92 |
|
{ |
93 |
7341042 |
switch (d_tnk) |
94 |
|
{ |
95 |
|
// the node of lemma is the node itself |
96 |
3073237 |
case TrustNodeKind::LEMMA: return d_proven; |
97 |
|
// the node of the rewrite is the right hand side of EQUAL |
98 |
2471886 |
case TrustNodeKind::REWRITE: return d_proven[1]; |
99 |
|
// the node of an explained propagation is the antecendant of an IMPLIES |
100 |
|
// the node of a conflict is underneath a NOT |
101 |
1795919 |
default: return d_proven[0]; |
102 |
|
} |
103 |
|
} |
104 |
|
|
105 |
4265713 |
Node TrustNode::getProven() const { return d_proven; } |
106 |
|
|
107 |
1809626 |
ProofGenerator* TrustNode::getGenerator() const { return d_gen; } |
108 |
|
|
109 |
7786536 |
bool TrustNode::isNull() const { return d_proven.isNull(); } |
110 |
|
|
111 |
114259 |
std::shared_ptr<ProofNode> TrustNode::toProofNode() const |
112 |
|
{ |
113 |
114259 |
if (d_gen == nullptr) |
114 |
|
{ |
115 |
865 |
return nullptr; |
116 |
|
} |
117 |
113394 |
return d_gen->getProofFor(d_proven); |
118 |
|
} |
119 |
|
|
120 |
307016 |
Node TrustNode::getConflictProven(Node conf) { return conf.notNode(); } |
121 |
|
|
122 |
2556490 |
Node TrustNode::getLemmaProven(Node lem) { return lem; } |
123 |
|
|
124 |
643383 |
Node TrustNode::getPropExpProven(TNode lit, Node exp) |
125 |
|
{ |
126 |
643383 |
return NodeManager::currentNM()->mkNode(kind::IMPLIES, exp, lit); |
127 |
|
} |
128 |
|
|
129 |
2061167 |
Node TrustNode::getRewriteProven(TNode n, Node nr) { return n.eqNode(nr); } |
130 |
|
|
131 |
595031 |
void TrustNode::debugCheckClosed(const char* c, |
132 |
|
const char* ctx, |
133 |
|
bool reqNullGen) |
134 |
|
{ |
135 |
595031 |
pfgEnsureClosed(d_proven, d_gen, c, ctx, reqNullGen); |
136 |
595031 |
} |
137 |
|
|
138 |
61915 |
std::string TrustNode::identifyGenerator() const |
139 |
|
{ |
140 |
61915 |
if (d_gen == nullptr) |
141 |
|
{ |
142 |
441 |
return "null"; |
143 |
|
} |
144 |
61474 |
return d_gen->identify(); |
145 |
|
} |
146 |
|
|
147 |
|
std::ostream& operator<<(std::ostream& out, TrustNode n) |
148 |
|
{ |
149 |
|
out << "(" << n.getKind() << " " << n.getProven() << " " |
150 |
|
<< n.identifyGenerator() << ")"; |
151 |
|
return out; |
152 |
|
} |
153 |
|
|
154 |
29505 |
} // namespace cvc5 |