GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/trust_node.h Lines: 3 3 100.0 %
Date: 2021-05-22 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Gereon Kremer
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
 * The trust node utility.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__TRUST_NODE_H
19
#define CVC5__THEORY__TRUST_NODE_H
20
21
#include "expr/node.h"
22
23
namespace cvc5 {
24
25
class ProofGenerator;
26
class ProofNode;
27
28
namespace theory {
29
30
/** A kind for trust nodes */
31
enum class TrustNodeKind : uint32_t
32
{
33
  CONFLICT,
34
  LEMMA,
35
  PROP_EXP,
36
  REWRITE,
37
  INVALID
38
};
39
/**
40
 * Converts a proof rule to a string. Note: This function is also used in
41
 * `safe_print()`. Changing this function name or signature will result in
42
 * `safe_print()` printing "<unsupported>" instead of the proper strings for
43
 * the enum values.
44
 *
45
 * Returns a string with static lifetime: it should not be freed.
46
 *
47
 * @param tnk The trust node kind
48
 * @return The name of the trust node kind
49
 */
50
const char* toString(TrustNodeKind tnk);
51
52
/**
53
 * Writes a trust node kind name to a stream.
54
 *
55
 * @param out The stream to write to
56
 * @param tnk The trust node kind to write to the stream
57
 * @return The stream
58
 */
59
std::ostream& operator<<(std::ostream& out, TrustNodeKind tnk);
60
61
/**
62
 * A trust node is a pair (F, G) where F is a formula and G is a proof
63
 * generator that can construct a proof for F if asked.
64
 *
65
 * More generally, a trust node is any node that can be used for a specific
66
 * purpose that requires justification, such as being passed to
67
 * OutputChannel::lemma. That justification is intended to be given by the
68
 * generator that is required to construct this object.
69
 *
70
 * They are intended to be constructed by ProofGenerator objects themselves (a
71
 * proof generator wraps itself in TrustNode it returns) and passed
72
 * to ProofOutputChannel by theory solvers.
73
 *
74
 * The static functions for constructing them check that the generator, if
75
 * provided, is capable of proving the given conflict or lemma, or an assertion
76
 * failure occurs. Otherwise an assertion error is given.
77
 *
78
 * While this is not enforced, a `TrustNode` generally encapsulates a **closed** proof
79
 * of the formula: one without free assumptions.
80
 */
81
9368920
class TrustNode
82
{
83
 public:
84
3252488
  TrustNode() : d_tnk(TrustNodeKind::INVALID), d_gen(nullptr) {}
85
  /** Make a proven node for conflict */
86
  static TrustNode mkTrustConflict(Node conf, ProofGenerator* g = nullptr);
87
  /** Make a proven node for lemma */
88
  static TrustNode mkTrustLemma(Node lem, ProofGenerator* g = nullptr);
89
  /** Make a proven node for explanation of propagated literal */
90
  static TrustNode mkTrustPropExp(TNode lit,
91
                                  Node exp,
92
                                  ProofGenerator* g = nullptr);
93
  /** Make a proven node for rewrite */
94
  static TrustNode mkTrustRewrite(TNode n,
95
                                  Node nr,
96
                                  ProofGenerator* g = nullptr);
97
  /** The null proven node */
98
  static TrustNode null();
99
18890083
  ~TrustNode() {}
100
  /** get kind */
101
  TrustNodeKind getKind() const;
102
  /** get node
103
   *
104
   * This is the node that is used in a common interface, either:
105
   * (1) A T-unsat conjunction conf to pass to OutputChannel::conflict,
106
   * (2) A valid T-formula lem to pass to OutputChannel::lemma,
107
   * (3) A conjunction of literals exp to return in Theory::explain(lit), or
108
   * (4) A result of rewriting a term n into an equivalent one nr.
109
   *
110
   * Notice that this node does not necessarily correspond to a valid formula.
111
   * The call getProven() below retrieves a valid formula corresponding to
112
   * the above calls.
113
   */
114
  Node getNode() const;
115
  /** get proven
116
   *
117
   * This is the corresponding formula that is proven by the proof generator
118
   * for the above cases:
119
   * (1) (not conf), for conflicts,
120
   * (2) lem, for lemmas,
121
   * (3) (=> exp lit), for propagations from explanations,
122
   * (4) (= n nr), for results of rewriting.
123
   *
124
   * When constructing this trust node, the proof generator should be able to
125
   * provide a proof for this fact.
126
   */
127
  Node getProven() const;
128
  /** get generator */
129
  ProofGenerator* getGenerator() const;
130
  /** is null? */
131
  bool isNull() const;
132
  /**
133
   * Gets the proof node for this trust node, which is obtained by
134
   * calling the generator's getProofFor method on the proven node.
135
   */
136
  std::shared_ptr<ProofNode> toProofNode() const;
137
138
  /** Get the proven formula corresponding to a conflict call */
139
  static Node getConflictProven(Node conf);
140
  /** Get the proven formula corresponding to a lemma call */
141
  static Node getLemmaProven(Node lem);
142
  /** Get the proven formula corresponding to explanations for propagation */
143
  static Node getPropExpProven(TNode lit, Node exp);
144
  /** Get the proven formula corresponding to a rewrite */
145
  static Node getRewriteProven(TNode n, Node nr);
146
  /** For debugging */
147
  std::string identifyGenerator() const;
148
149
  /**
150
   * debug check closed on Trace c, context ctx is string for debugging
151
   *
152
   * @param reqNullGen Whether we consider a null generator to be a failure.
153
   */
154
  void debugCheckClosed(const char* c, const char* ctx, bool reqNullGen = true);
155
156
 private:
157
  TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g = nullptr);
158
  /** The kind */
159
  TrustNodeKind d_tnk;
160
  /** The proven node */
161
  Node d_proven;
162
  /** The generator */
163
  ProofGenerator* d_gen;
164
};
165
166
/**
167
 * Writes a trust node to a stream.
168
 *
169
 * @param out The stream to write to
170
 * @param n The trust node to write to the stream
171
 * @return The stream
172
 */
173
std::ostream& operator<<(std::ostream& out, TrustNode n);
174
175
}  // namespace theory
176
}  // namespace cvc5
177
178
#endif /* CVC5__THEORY__TRUST_NODE_H */