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 |
265101 |
TrustNode TrustNode::mkTrustConflict(Node conf, ProofGenerator* g) |
42 |
|
{ |
43 |
530202 |
Node ckey = getConflictProven(conf); |
44 |
|
// if a generator is provided, should confirm that it can prove it |
45 |
265101 |
Assert(g == nullptr || g->hasProofFor(ckey)); |
46 |
530202 |
return TrustNode(TrustNodeKind::CONFLICT, ckey, g); |
47 |
|
} |
48 |
|
|
49 |
2253446 |
TrustNode TrustNode::mkTrustLemma(Node lem, ProofGenerator* g) |
50 |
|
{ |
51 |
4506892 |
Node lkey = getLemmaProven(lem); |
52 |
|
// if a generator is provided, should confirm that it can prove it |
53 |
2253446 |
Assert(g == nullptr || g->hasProofFor(lkey)); |
54 |
4506892 |
return TrustNode(TrustNodeKind::LEMMA, lkey, g); |
55 |
|
} |
56 |
|
|
57 |
552466 |
TrustNode TrustNode::mkTrustPropExp(TNode lit, Node exp, ProofGenerator* g) |
58 |
|
{ |
59 |
1104932 |
Node pekey = getPropExpProven(lit, exp); |
60 |
552466 |
Assert(g == nullptr || g->hasProofFor(pekey)); |
61 |
1104932 |
return TrustNode(TrustNodeKind::PROP_EXP, pekey, g); |
62 |
|
} |
63 |
|
|
64 |
2101420 |
TrustNode TrustNode::mkTrustRewrite(TNode n, Node nr, ProofGenerator* g) |
65 |
|
{ |
66 |
4202840 |
Node rkey = getRewriteProven(n, nr); |
67 |
2101420 |
Assert(g == nullptr || g->hasProofFor(rkey)); |
68 |
4202840 |
return TrustNode(TrustNodeKind::REWRITE, rkey, g); |
69 |
|
} |
70 |
|
|
71 |
4542178 |
TrustNode TrustNode::null() |
72 |
|
{ |
73 |
4542178 |
return TrustNode(TrustNodeKind::INVALID, Node::null()); |
74 |
|
} |
75 |
|
|
76 |
9714611 |
TrustNode::TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g) |
77 |
9714611 |
: d_tnk(tnk), d_proven(p), d_gen(g) |
78 |
|
{ |
79 |
|
// does not make sense to provide null node with generator |
80 |
9714611 |
Assert(!d_proven.isNull() || d_gen == nullptr); |
81 |
9714611 |
} |
82 |
|
|
83 |
2862583 |
TrustNodeKind TrustNode::getKind() const { return d_tnk; } |
84 |
|
|
85 |
7234023 |
Node TrustNode::getNode() const |
86 |
|
{ |
87 |
7234023 |
switch (d_tnk) |
88 |
|
{ |
89 |
|
// the node of lemma is the node itself |
90 |
3003584 |
case TrustNodeKind::LEMMA: return d_proven; |
91 |
|
// the node of the rewrite is the right hand side of EQUAL |
92 |
2548463 |
case TrustNodeKind::REWRITE: return d_proven[1]; |
93 |
|
// the node of an explained propagation is the antecendant of an IMPLIES |
94 |
|
// the node of a conflict is underneath a NOT |
95 |
1681976 |
default: return d_proven[0]; |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
3776478 |
Node TrustNode::getProven() const { return d_proven; } |
100 |
|
|
101 |
1806056 |
ProofGenerator* TrustNode::getGenerator() const { return d_gen; } |
102 |
|
|
103 |
7792219 |
bool TrustNode::isNull() const { return d_proven.isNull(); } |
104 |
|
|
105 |
109180 |
std::shared_ptr<ProofNode> TrustNode::toProofNode() const |
106 |
|
{ |
107 |
109180 |
if (d_gen == nullptr) |
108 |
|
{ |
109 |
849 |
return nullptr; |
110 |
|
} |
111 |
108331 |
return d_gen->getProofFor(d_proven); |
112 |
|
} |
113 |
|
|
114 |
279938 |
Node TrustNode::getConflictProven(Node conf) { return conf.notNode(); } |
115 |
|
|
116 |
2477656 |
Node TrustNode::getLemmaProven(Node lem) { return lem; } |
117 |
|
|
118 |
606499 |
Node TrustNode::getPropExpProven(TNode lit, Node exp) |
119 |
|
{ |
120 |
606499 |
return NodeManager::currentNM()->mkNode(kind::IMPLIES, exp, lit); |
121 |
|
} |
122 |
|
|
123 |
2101420 |
Node TrustNode::getRewriteProven(TNode n, Node nr) { return n.eqNode(nr); } |
124 |
|
|
125 |
577367 |
void TrustNode::debugCheckClosed(const char* c, |
126 |
|
const char* ctx, |
127 |
|
bool reqNullGen) |
128 |
|
{ |
129 |
577367 |
pfgEnsureClosed(d_proven, d_gen, c, ctx, reqNullGen); |
130 |
577367 |
} |
131 |
|
|
132 |
56779 |
std::string TrustNode::identifyGenerator() const |
133 |
|
{ |
134 |
56779 |
if (d_gen == nullptr) |
135 |
|
{ |
136 |
442 |
return "null"; |
137 |
|
} |
138 |
56337 |
return d_gen->identify(); |
139 |
|
} |
140 |
|
|
141 |
|
std::ostream& operator<<(std::ostream& out, TrustNode n) |
142 |
|
{ |
143 |
|
out << "(" << n.getKind() << " " << n.getProven() << " " |
144 |
|
<< n.identifyGenerator() << ")"; |
145 |
|
return out; |
146 |
|
} |
147 |
|
|
148 |
29286 |
} // namespace cvc5 |