1 /********************* */
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 The trust node utility
15 #include "cvc4_private.h"
17 #ifndef CVC4__THEORY__TRUST_NODE_H
18 #define CVC4__THEORY__TRUST_NODE_H
20 #include "expr/node.h"
28 /** A kind for trust nodes */
29 enum class TrustNodeKind
: uint32_t
38 * Converts a proof rule to a string. Note: This function is also used in
39 * `safe_print()`. Changing this function name or signature will result in
40 * `safe_print()` printing "<unsupported>" instead of the proper strings for
43 * Returns a string with static lifetime: it should not be freed.
45 * @param tnk The trust node kind
46 * @return The name of the trust node kind
48 const char* toString(TrustNodeKind tnk
);
51 * Writes a trust node kind name to a stream.
53 * @param out The stream to write to
54 * @param tnk The trust node kind to write to the stream
57 std::ostream
& operator<<(std::ostream
& out
, TrustNodeKind tnk
);
60 * A trust node is a pair (F, G) where F is a formula and G is a proof
61 * generator that can construct a proof for F if asked.
63 * More generally, a trust node is any node that can be used for a specific
64 * purpose that requires justification, such as being passed to
65 * OutputChannel::lemma. That justification is intended to be given by the
66 * generator that is required to construct this object.
68 * They are intended to be constructed by ProofGenerator objects themselves (a
69 * proof generator wraps itself in TrustNode it returns) and passed
70 * to ProofOutputChannel by theory solvers.
72 * The static functions for constructing them check that the generator, if
73 * provided, is capable of proving the given conflict or lemma, or an assertion
74 * failure occurs. Otherwise an assertion error is given.
76 * While this is not enforced, a `TrustNode` generally encapsulates a **closed** proof
77 * of the formula: one without free assumptions.
82 TrustNode() : d_tnk(TrustNodeKind::INVALID
), d_gen(nullptr) {}
83 /** Make a proven node for conflict */
84 static TrustNode
mkTrustConflict(Node conf
, ProofGenerator
* g
= nullptr);
85 /** Make a proven node for lemma */
86 static TrustNode
mkTrustLemma(Node lem
, ProofGenerator
* g
= nullptr);
87 /** Make a proven node for explanation of propagated literal */
88 static TrustNode
mkTrustPropExp(TNode lit
,
90 ProofGenerator
* g
= nullptr);
91 /** Make a proven node for rewrite */
92 static TrustNode
mkTrustRewrite(TNode n
,
94 ProofGenerator
* g
= nullptr);
95 /** The null proven node */
96 static TrustNode
null();
99 TrustNodeKind
getKind() const;
102 * This is the node that is used in a common interface, either:
103 * (1) A T-unsat conjunction conf to pass to OutputChannel::conflict,
104 * (2) A valid T-formula lem to pass to OutputChannel::lemma,
105 * (3) A conjunction of literals exp to return in Theory::explain(lit), or
106 * (4) A result of rewriting a term n into an equivalent one nr.
108 * Notice that this node does not necessarily correspond to a valid formula.
109 * The call getProven() below retrieves a valid formula corresponding to
112 Node
getNode() const;
115 * This is the corresponding formula that is proven by the proof generator
116 * for the above cases:
117 * (1) (not conf), for conflicts,
118 * (2) lem, for lemmas,
119 * (3) (=> exp lit), for propagations from explanations,
120 * (4) (= n nr), for results of rewriting.
122 * When constructing this trust node, the proof generator should be able to
123 * provide a proof for this fact.
125 Node
getProven() const;
127 ProofGenerator
* getGenerator() const;
131 /** Get the proven formula corresponding to a conflict call */
132 static Node
getConflictProven(Node conf
);
133 /** Get the proven formula corresponding to a lemma call */
134 static Node
getLemmaProven(Node lem
);
135 /** Get the proven formula corresponding to explanations for propagation */
136 static Node
getPropExpProven(TNode lit
, Node exp
);
137 /** Get the proven formula corresponding to a rewrite */
138 static Node
getRewriteProven(TNode n
, Node nr
);
141 TrustNode(TrustNodeKind tnk
, Node p
, ProofGenerator
* g
= nullptr);
144 /** The proven node */
147 ProofGenerator
* d_gen
;
151 * Writes a trust node to a stream.
153 * @param out The stream to write to
154 * @param n The trust node to write to the stream
157 std::ostream
& operator<<(std::ostream
& out
, TrustNode n
);
159 } // namespace theory
162 #endif /* CVC4__THEORY__TRUST_NODE_H */