1 /********************* */
2 /*! \file trust_node.cpp
4 ** Top contributors (to current version):
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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.\endverbatim
12 ** \brief Implementation of the trust node utility
15 #include "theory/trust_node.h"
17 #include "expr/proof_ensure_closed.h"
18 #include "expr/proof_generator.h"
23 const char* toString(TrustNodeKind tnk
)
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";
35 std::ostream
& operator<<(std::ostream
& out
, TrustNodeKind tnk
)
41 TrustNode
TrustNode::mkTrustConflict(Node conf
, ProofGenerator
* g
)
43 Node ckey
= getConflictProven(conf
);
44 // if a generator is provided, should confirm that it can prove it
45 Assert(g
== nullptr || g
->hasProofFor(ckey
));
46 return TrustNode(TrustNodeKind::CONFLICT
, ckey
, g
);
49 TrustNode
TrustNode::mkTrustLemma(Node lem
, ProofGenerator
* g
)
51 Node lkey
= getLemmaProven(lem
);
52 // if a generator is provided, should confirm that it can prove it
53 Assert(g
== nullptr || g
->hasProofFor(lkey
));
54 return TrustNode(TrustNodeKind::LEMMA
, lkey
, g
);
57 TrustNode
TrustNode::mkTrustPropExp(TNode lit
, Node exp
, ProofGenerator
* g
)
59 Node pekey
= getPropExpProven(lit
, exp
);
60 Assert(g
== nullptr || g
->hasProofFor(pekey
));
61 return TrustNode(TrustNodeKind::PROP_EXP
, pekey
, g
);
64 TrustNode
TrustNode::mkTrustRewrite(TNode n
, Node nr
, ProofGenerator
* g
)
66 Node rkey
= getRewriteProven(n
, nr
);
67 Assert(g
== nullptr || g
->hasProofFor(rkey
));
68 return TrustNode(TrustNodeKind::REWRITE
, rkey
, g
);
71 TrustNode
TrustNode::null()
73 return TrustNode(TrustNodeKind::INVALID
, Node::null());
76 TrustNode::TrustNode(TrustNodeKind tnk
, Node p
, ProofGenerator
* g
)
77 : d_tnk(tnk
), d_proven(p
), d_gen(g
)
79 // does not make sense to provide null node with generator
80 Assert(!d_proven
.isNull() || d_gen
== nullptr);
83 TrustNodeKind
TrustNode::getKind() const { return d_tnk
; }
85 Node
TrustNode::getNode() const
89 // the node of lemma is the node itself
90 case TrustNodeKind::LEMMA
: return d_proven
;
91 // the node of the rewrite is the right hand side of EQUAL
92 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 default: return d_proven
[0];
99 Node
TrustNode::getProven() const { return d_proven
; }
101 ProofGenerator
* TrustNode::getGenerator() const { return d_gen
; }
103 bool TrustNode::isNull() const { return d_proven
.isNull(); }
105 std::shared_ptr
<ProofNode
> TrustNode::toProofNode() const
107 if (d_gen
== nullptr)
111 return d_gen
->getProofFor(d_proven
);
114 Node
TrustNode::getConflictProven(Node conf
) { return conf
.notNode(); }
116 Node
TrustNode::getLemmaProven(Node lem
) { return lem
; }
118 Node
TrustNode::getPropExpProven(TNode lit
, Node exp
)
120 return NodeManager::currentNM()->mkNode(kind::IMPLIES
, exp
, lit
);
123 Node
TrustNode::getRewriteProven(TNode n
, Node nr
) { return n
.eqNode(nr
); }
125 void TrustNode::debugCheckClosed(const char* c
,
129 pfgEnsureClosed(d_proven
, d_gen
, c
, ctx
, reqNullGen
);
132 std::string
TrustNode::identifyGenerator() const
134 if (d_gen
== nullptr)
138 return d_gen
->identify();
141 std::ostream
& operator<<(std::ostream
& out
, TrustNode n
)
143 out
<< "(" << n
.getKind() << " " << n
.getProven() << " "
144 << n
.identifyGenerator() << ")";
148 } // namespace theory