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

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Haniel Barbosa, 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
 * Proof node manager utility.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__EXPR__PROOF_NODE_MANAGER_H
19
#define CVC5__EXPR__PROOF_NODE_MANAGER_H
20
21
#include <vector>
22
23
#include "expr/node.h"
24
#include "expr/proof_rule.h"
25
26
namespace cvc5 {
27
28
class ProofChecker;
29
class ProofNode;
30
31
/**
32
 * A manager for proof node objects. This is a trusted interface for creating
33
 * and updating ProofNode objects.
34
 *
35
 * In more detail, we say a ProofNode is "well-formed (with respect to checker
36
 * X)" if its d_proven field is non-null, and corresponds to the formula that
37
 * the ProofNode proves according to X. The ProofNodeManager class constructs
38
 * and update nodes that are well-formed with respect to its underlying checker.
39
 *
40
 * If no checker is provided, then the ProofNodeManager assigns the d_proven
41
 * field of ProofNode based on the provided "expected" argument in mkNode below,
42
 * which must be provided in this case.
43
 *
44
 * The ProofNodeManager is used as a trusted way of updating ProofNode objects
45
 * via updateNode below. In particular, this method leaves the d_proven field
46
 * unchanged and updates (if possible) the remaining content of a given proof
47
 * node.
48
 *
49
 * Notice that ProofNode objects are mutable, and hence this class does not
50
 * cache the results of mkNode. A version of this class that caches
51
 * immutable version of ProofNode objects could be built as an extension
52
 * or layer on top of this class.
53
 */
54
class ProofNodeManager
55
{
56
 public:
57
  ProofNodeManager(ProofChecker* pc = nullptr);
58
3600
  ~ProofNodeManager() {}
59
  /**
60
   * This constructs a ProofNode with the given arguments. The expected
61
   * argument, when provided, indicates the formula that the returned node
62
   * is expected to prove. If we find that it does not, based on the underlying
63
   * checker, this method returns nullptr.
64
   *
65
   * @param id The id of the proof node.
66
   * @param children The children of the proof node.
67
   * @param args The arguments of the proof node.
68
   * @param expected (Optional) the expected conclusion of the proof node.
69
   * @return the proof node, or nullptr if the given arguments do not
70
   * consistute a proof of the expected conclusion according to the underlying
71
   * checker, if both are provided. It also returns nullptr if neither the
72
   * checker nor the expected field is provided, since in this case the
73
   * conclusion is unknown.
74
   */
75
  std::shared_ptr<ProofNode> mkNode(
76
      PfRule id,
77
      const std::vector<std::shared_ptr<ProofNode>>& children,
78
      const std::vector<Node>& args,
79
      Node expected = Node::null());
80
  /**
81
   * Make the proof node corresponding to the assumption of fact.
82
   *
83
   * @param fact The fact to assume.
84
   * @return The ASSUME proof of fact.
85
   */
86
  std::shared_ptr<ProofNode> mkAssume(Node fact);
87
  /**
88
   * Make transitivity proof, where children contains one or more proofs of
89
   * equalities that form an ordered chain. In other words, the vector children
90
   * is a legal set of children for an application of TRANS.
91
   */
92
  std::shared_ptr<ProofNode> mkTrans(
93
      const std::vector<std::shared_ptr<ProofNode>>& children,
94
      Node expected = Node::null());
95
96
  /**
97
   * Make scope having body pf and arguments (assumptions-to-close) assumps.
98
   * If ensureClosed is true, then this method throws an assertion failure if
99
   * the returned proof is not closed. This is the case if a free assumption
100
   * of pf is missing from the vector assumps.
101
   *
102
   * For conveinence, the proof pf may be modified to ensure that the overall
103
   * result is closed. For instance, given input:
104
   *   pf = TRANS( ASSUME( x=y ), ASSUME( y=z ) )
105
   *   assumps = { y=x, y=z }
106
   * This method will modify pf to be:
107
   *   pf = TRANS( SYMM( ASSUME( y=x ) ), ASSUME( y=z ) )
108
   * so that y=x matches the free assumption. The returned proof is:
109
   *   SCOPE(TRANS( SYMM( ASSUME( y=x ) ), ASSUME( y=z ) ) :args { y=x, y=z })
110
   *
111
   * When ensureClosed is true, duplicates are eliminated from assumps. The
112
   * reason for this is due to performance, since in this method, assumps is
113
   * converted to an unordered_set to do the above check and hence it is a
114
   * convienient time to eliminate duplicate literals.
115
   *
116
   * Additionally, if both ensureClosed and doMinimize are true, assumps is
117
   * updated to contain exactly the free asumptions of pf. This also includes
118
   * having no duplicates. Furthermore, if assumps is empty after minimization,
119
   * this method is a no-op.
120
   *
121
   * In each case, the update vector assumps is passed as arguments to SCOPE.
122
   *
123
   * @param pf The body of the proof,
124
   * @param assumps The assumptions-to-close of the scope,
125
   * @param ensureClosed Whether to ensure that the proof is closed,
126
   * @param doMinimize Whether to minimize assumptions.
127
   * @param expected the node that the scope should prove.
128
   * @return The scoped proof.
129
   */
130
  std::shared_ptr<ProofNode> mkScope(std::shared_ptr<ProofNode> pf,
131
                                     std::vector<Node>& assumps,
132
                                     bool ensureClosed = true,
133
                                     bool doMinimize = false,
134
                                     Node expected = Node::null());
135
  /**
136
   * This method updates pn to be a proof of the form <id>( children, args ),
137
   * while maintaining its d_proven field. This method returns false if this
138
   * proof manager is using a checker, and we compute that the above proof
139
   * is not a proof of the fact that pn previously proved.
140
   *
141
   * @param pn The proof node to update.
142
   * @param id The updated id of the proof node.
143
   * @param children The updated children of the proof node.
144
   * @param args The updated arguments of the proof node.
145
   * @return true if the update was successful.
146
   *
147
   * Notice that updateNode always returns true if there is no underlying
148
   * checker.
149
   */
150
  bool updateNode(ProofNode* pn,
151
                  PfRule id,
152
                  const std::vector<std::shared_ptr<ProofNode>>& children,
153
                  const std::vector<Node>& args);
154
  /**
155
   * Update node pn to have the contents of pnr. It should be the case that
156
   * pn and pnr prove the same fact, otherwise false is returned and pn is
157
   * unchanged.
158
   */
159
  bool updateNode(ProofNode* pn, ProofNode* pnr);
160
  /** Get the underlying proof checker */
161
  ProofChecker* getChecker() const;
162
  /**
163
   * Clone a proof node, which creates a deep copy of pn and returns it. The
164
   * dag structure of pn is the same as that in the returned proof node.
165
   *
166
   * @param pn The proof node to clone
167
   * @return the cloned proof node.
168
   */
169
  std::shared_ptr<ProofNode> clone(std::shared_ptr<ProofNode> pn);
170
171
 private:
172
  /** The (optional) proof checker */
173
  ProofChecker* d_checker;
174
  /** the true node */
175
  Node d_true;
176
  /** Check internal
177
   *
178
   * This returns the result of proof checking a ProofNode with the provided
179
   * arguments with an expected conclusion, which may not null if there is
180
   * no expected conclusion.
181
   *
182
   * This throws an assertion error if we fail to check such a proof node, or
183
   * if expected is provided (non-null) and is different what is proven by the
184
   * other arguments.
185
   */
186
  Node checkInternal(PfRule id,
187
                     const std::vector<std::shared_ptr<ProofNode>>& children,
188
                     const std::vector<Node>& args,
189
                     Node expected);
190
  /**
191
   * Update node internal, return true if successful. This is called by
192
   * the update node methods above. The argument needsCheck is whether we
193
   * need to check the correctness of the rule application. This is false
194
   * for the updateNode routine where pnr is an (already checked) proof node.
195
   */
196
  bool updateNodeInternal(
197
      ProofNode* pn,
198
      PfRule id,
199
      const std::vector<std::shared_ptr<ProofNode>>& children,
200
      const std::vector<Node>& args,
201
      bool needsCheck);
202
};
203
204
}  // namespace cvc5
205
206
#endif /* CVC5__EXPR__PROOF_NODE_H */