GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/proof_node.h Lines: 3 3 100.0 %
Date: 2021-05-22 Branches: 2 4 50.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Haniel Barbosa, Alex Ozdemir
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
 * Proof node utility.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__EXPR__PROOF_NODE_H
19
#define CVC5__EXPR__PROOF_NODE_H
20
21
#include <vector>
22
23
#include "expr/node.h"
24
#include "expr/proof_rule.h"
25
26
namespace cvc5 {
27
28
class ProofNodeManager;
29
class ProofNode;
30
31
// Alias for shared pointer to a proof node
32
using Pf = std::shared_ptr<ProofNode>;
33
34
struct ProofNodeHashFunction
35
{
36
  inline size_t operator()(std::shared_ptr<ProofNode> pfn) const;
37
}; /* struct ProofNodeHashFunction */
38
39
/** A node in a proof
40
 *
41
 * A ProofNode represents a single step in a proof. It contains:
42
 * (1) d_id, an identifier indicating the kind of inference,
43
 * (2) d_children, the child ProofNode objects indicating its premises,
44
 * (3) d_args, additional arguments used to determine the conclusion,
45
 * (4) d_proven, cache of the formula that this ProofNode proves.
46
 *
47
 * Overall, a ProofNode and its children form a directed acyclic graph.
48
 *
49
 * A ProofNode is partially mutable in that (1), (2) and (3) can be
50
 * modified. A motivating example of when this is useful is when a ProofNode
51
 * is established to be a "hole" for something to be proven later. On the other
52
 * hand, (4) is intended to be immutable.
53
 *
54
 * The method setValue is private and can be called by objects that manage
55
 * ProofNode objects in trusted ways that ensure that the node maintains
56
 * the invariant above. Furthermore, notice that this class is not responsible
57
 * for setting d_proven; this is done externally by a ProofNodeManager class.
58
 *
59
 * Notice that all fields of ProofNode are stored in ***Skolem form***. Their
60
 * correctness is checked in ***witness form*** (for details on this
61
 * terminology, see expr/skolem_manager.h). As a simple example, say a
62
 * theory solver has a term t, and wants to introduce a unit lemma (= k t)
63
 * where k is a fresh Skolem variable. It creates this variable via:
64
 *   k = SkolemManager::mkPurifySkolem(t,"k");
65
 * A checked ProofNode for the fact (= k t) then may have fields:
66
 *   d_rule := MACRO_SR_PRED_INTRO,
67
 *   d_children := {},
68
 *   d_args := {(= k t)}
69
 *   d_proven := (= k t).
70
 * Its justification via the rule MACRO_SR_PRED_INTRO (see documentation
71
 * in theory/builtin/proof_kinds) is in terms of the witness form of the
72
 * argument:
73
 *   (= (witness ((z T)) (= z t)) t)
74
 * which, by that rule's side condition, is such that:
75
 *   Rewriter::rewrite((= (witness ((z T)) (= z t)) t)) = true.
76
 * Notice that the correctness of the rule is justified here by rewriting
77
 * the witness form of (= k t). The conversion to/from witness form is
78
 * managed by ProofRuleChecker::check.
79
 *
80
 * An external proof checker is expected to formalize the ProofNode only in
81
 * terms of *witness* forms.
82
 *
83
 * However, the rest of cvc5 sees only the *Skolem* form of arguments and
84
 * conclusions in ProofNode, since this is what is used throughout cvc5.
85
 */
86
class ProofNode
87
{
88
  friend class ProofNodeManager;
89
90
 public:
91
  ProofNode(PfRule id,
92
            const std::vector<std::shared_ptr<ProofNode>>& children,
93
            const std::vector<Node>& args);
94
20369316
  ~ProofNode() {}
95
  /** get the rule of this proof node */
96
  PfRule getRule() const;
97
  /** Get children */
98
  const std::vector<std::shared_ptr<ProofNode>>& getChildren() const;
99
  /** Get arguments */
100
  const std::vector<Node>& getArguments() const;
101
  /** get what this node proves, or the null node if this is an invalid proof */
102
  Node getResult() const;
103
  /**
104
   * Returns true if this is a closed proof (i.e. it has no free assumptions).
105
   */
106
  bool isClosed();
107
  /** Print debug on output strem os */
108
  void printDebug(std::ostream& os) const;
109
110
 private:
111
  /**
112
   * Set value, called to overwrite the contents of this ProofNode with the
113
   * given arguments.
114
   */
115
  void setValue(PfRule id,
116
                const std::vector<std::shared_ptr<ProofNode>>& children,
117
                const std::vector<Node>& args);
118
  /** The proof rule */
119
  PfRule d_rule;
120
  /** The children of this proof node */
121
  std::vector<std::shared_ptr<ProofNode>> d_children;
122
  /** arguments of this node */
123
  std::vector<Node> d_args;
124
  /** The cache of the fact that has been proven, modifiable by ProofChecker */
125
  Node d_proven;
126
};
127
128
2589939
inline size_t ProofNodeHashFunction::operator()(
129
    std::shared_ptr<ProofNode> pfn) const
130
{
131
2589939
  return pfn->getResult().getId() + static_cast<unsigned>(pfn->getRule());
132
}
133
134
/**
135
 * Serializes a given proof node to the given stream.
136
 *
137
 * @param out the output stream to use
138
 * @param pn the proof node to output to the stream
139
 * @return the stream
140
 */
141
std::ostream& operator<<(std::ostream& out, const ProofNode& pn);
142
143
}  // namespace cvc5
144
145
#endif /* CVC5__EXPR__PROOF_NODE_H */