Fix regression option (#4680)
[cvc5.git] / src / theory / trust_node.h
1 /********************* */
2 /*! \file trust_node.h
3 ** \verbatim
4 ** Top contributors (to current version):
5 ** Andrew Reynolds
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
11 **
12 ** \brief The trust node utility
13 **/
14
15 #include "cvc4_private.h"
16
17 #ifndef CVC4__THEORY__TRUST_NODE_H
18 #define CVC4__THEORY__TRUST_NODE_H
19
20 #include "expr/node.h"
21
22 namespace CVC4 {
23
24 class ProofGenerator;
25
26 namespace theory {
27
28 /** A kind for trust nodes */
29 enum class TrustNodeKind : uint32_t
30 {
31 CONFLICT,
32 LEMMA,
33 PROP_EXP,
34 REWRITE,
35 INVALID
36 };
37 /**
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
41 * the enum values.
42 *
43 * Returns a string with static lifetime: it should not be freed.
44 *
45 * @param tnk The trust node kind
46 * @return The name of the trust node kind
47 */
48 const char* toString(TrustNodeKind tnk);
49
50 /**
51 * Writes a trust node kind name to a stream.
52 *
53 * @param out The stream to write to
54 * @param tnk The trust node kind to write to the stream
55 * @return The stream
56 */
57 std::ostream& operator<<(std::ostream& out, TrustNodeKind tnk);
58
59 /**
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.
62 *
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.
67 *
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.
71 *
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.
75 *
76 * While this is not enforced, a `TrustNode` generally encapsulates a **closed** proof
77 * of the formula: one without free assumptions.
78 */
79 class TrustNode
80 {
81 public:
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,
89 Node exp,
90 ProofGenerator* g = nullptr);
91 /** Make a proven node for rewrite */
92 static TrustNode mkTrustRewrite(TNode n,
93 Node nr,
94 ProofGenerator* g = nullptr);
95 /** The null proven node */
96 static TrustNode null();
97 ~TrustNode() {}
98 /** get kind */
99 TrustNodeKind getKind() const;
100 /** get node
101 *
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.
107 *
108 * Notice that this node does not necessarily correspond to a valid formula.
109 * The call getProven() below retrieves a valid formula corresponding to
110 * the above calls.
111 */
112 Node getNode() const;
113 /** get proven
114 *
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.
121 *
122 * When constructing this trust node, the proof generator should be able to
123 * provide a proof for this fact.
124 */
125 Node getProven() const;
126 /** get generator */
127 ProofGenerator* getGenerator() const;
128 /** is null? */
129 bool isNull() const;
130
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);
139
140 private:
141 TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g = nullptr);
142 /** The kind */
143 TrustNodeKind d_tnk;
144 /** The proven node */
145 Node d_proven;
146 /** The generator */
147 ProofGenerator* d_gen;
148 };
149
150 /**
151 * Writes a trust node to a stream.
152 *
153 * @param out The stream to write to
154 * @param n The trust node to write to the stream
155 * @return The stream
156 */
157 std::ostream& operator<<(std::ostream& out, TrustNode n);
158
159 } // namespace theory
160 } // namespace CVC4
161
162 #endif /* CVC4__THEORY__TRUST_NODE_H */