GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/proof_node_updater.h Lines: 1 1 100.0 %
Date: 2021-05-21 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
 * A utility for updating proof nodes.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__EXPR__PROOF_NODE_UPDATER_H
19
#define CVC5__EXPR__PROOF_NODE_UPDATER_H
20
21
#include <map>
22
#include <memory>
23
24
#include "expr/node.h"
25
#include "expr/proof_node.h"
26
27
namespace cvc5 {
28
29
class CDProof;
30
class ProofNode;
31
class ProofNodeManager;
32
33
/**
34
 * A virtual callback class for updating ProofNode. An example use case of this
35
 * class is to eliminate a proof rule by expansion.
36
 */
37
class ProofNodeUpdaterCallback
38
{
39
 public:
40
  ProofNodeUpdaterCallback();
41
  virtual ~ProofNodeUpdaterCallback();
42
  /** Should proof pn be updated?
43
   *
44
   * @param pn the proof node that maybe should be updated
45
   * @param fa the assumptions in scope
46
   * @param continueUpdate whether we should continue recursively updating pn
47
   * @return whether we should run the update method on pn
48
   */
49
  virtual bool shouldUpdate(std::shared_ptr<ProofNode> pn,
50
                            const std::vector<Node>& fa,
51
                            bool& continueUpdate) = 0;
52
  /**
53
   * Update the proof rule application, store steps in cdp. Return true if
54
   * the proof changed. It can be assumed that cdp contains proofs of each
55
   * fact in children.
56
   *
57
   * If continueUpdate is set to false in this method, then the resulting
58
   * proof (the proof of res in cdp) is *not* called back to update by the
59
   * proof node updater, nor are its children recursed. Otherwise, by default,
60
   * the proof node updater will continue updating the resulting proof and will
61
   * recursively update its children. This is analogous to marking REWRITE_DONE
62
   * in a rewrite response.
63
   */
64
  virtual bool update(Node res,
65
                      PfRule id,
66
                      const std::vector<Node>& children,
67
                      const std::vector<Node>& args,
68
                      CDProof* cdp,
69
                      bool& continueUpdate);
70
};
71
72
/**
73
 * A generic class for updating ProofNode. It is parameterized by a callback
74
 * class. Its process method runs this callback on all subproofs of a provided
75
 * ProofNode application that meet some criteria
76
 * (ProofNodeUpdaterCallback::shouldUpdate)
77
 * and overwrites them based on the update procedure of the callback
78
 * (ProofNodeUpdaterCallback::update), which uses local CDProof objects that
79
 * should be filled in the callback for each ProofNode to update.
80
 */
81
8943
class ProofNodeUpdater
82
{
83
 public:
84
  /**
85
   * @param pnm The proof node manager we are using
86
   * @param cb The callback to apply to each node
87
   * @param mergeSubproofs Whether to automatically merge subproofs within
88
   * the same SCOPE that prove the same fact.
89
   * @param autoSym Whether intermediate CDProof objects passed to updater
90
   * callbacks automatically introduce SYMM steps.
91
   */
92
  ProofNodeUpdater(ProofNodeManager* pnm,
93
                   ProofNodeUpdaterCallback& cb,
94
                   bool mergeSubproofs = false,
95
                   bool autoSym = true);
96
  /**
97
   * Post-process, which performs the main post-processing technique described
98
   * above.
99
   */
100
  void process(std::shared_ptr<ProofNode> pf);
101
102
  /**
103
   * Set free assumptions to freeAssumps. This indicates that we expect
104
   * the proof we are processing to have free assumptions that are in
105
   * freeAssumps. This enables checking when this is violated, which is
106
   * expensive in general. It is not recommended that this method is called
107
   * by default.
108
   */
109
  void setDebugFreeAssumptions(const std::vector<Node>& freeAssumps);
110
111
 private:
112
  /** The proof node manager */
113
  ProofNodeManager* d_pnm;
114
  /** The callback */
115
  ProofNodeUpdaterCallback& d_cb;
116
  /**
117
   * Post-process, which performs the main post-processing technique described
118
   * above.
119
   *
120
   * @param pf The proof to process
121
   * @param fa The assumptions of the scope that fa is a subproof of with
122
   * respect to the original proof. For example, if (SCOPE P :args (A B)), we
123
   * may call this method on P with fa = { A, B }.
124
   * @param traversing The list of proof nodes we are currently traversing
125
   * beneath. This is used for checking for cycles in the overall proof.
126
   */
127
  void processInternal(std::shared_ptr<ProofNode> pf,
128
                       const std::vector<Node>& fa,
129
                       std::vector<std::shared_ptr<ProofNode>>& traversing);
130
  /**
131
   * Update proof node cur based on the callback. This modifies curr using
132
   * ProofNodeManager::updateNode based on the proof node constructed to
133
   * replace it by the callback. Return true if cur was updated. If
134
   * continueUpdate is updated to false, then cur is not updated further
135
   * and its children are not traversed.
136
   */
137
  bool runUpdate(std::shared_ptr<ProofNode> cur,
138
                 const std::vector<Node>& fa,
139
                 bool& continueUpdate);
140
  /**
141
   * Finalize the node cur. This is called at the moment that it is established
142
   * that cur will appear in the final proof. We do any final debug checking
143
   * and add it to the results cache resCache if we are merging subproofs.
144
   */
145
  void runFinalize(std::shared_ptr<ProofNode> cur,
146
                   const std::vector<Node>& fa,
147
                   std::map<Node, std::shared_ptr<ProofNode>>& resCache);
148
  /** Are we debugging free assumptions? */
149
  bool d_debugFreeAssumps;
150
  /** The initial free assumptions */
151
  std::vector<Node> d_freeAssumps;
152
  /** Whether we are merging subproofs */
153
  bool d_mergeSubproofs;
154
  /**
155
   * Whether intermediate CDProof objects passed to updater callbacks
156
   * automatically introduce SYMM steps.
157
   */
158
  bool d_autoSym;
159
};
160
161
}  // namespace cvc5
162
163
#endif