Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andrew Reynolds, Hans-Joerg Schurr, Gereon Kremer 4 : : * 5 : : * This file is part of the cvc5 project. 6 : : * 7 : : * Copyright (c) 2009-2025 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 step and proof step buffer utilities. 14 : : */ 15 : : 16 : : #include "cvc5_private.h" 17 : : 18 : : #ifndef CVC5__PROOF__PROOF_STEP_BUFFER_H 19 : : #define CVC5__PROOF__PROOF_STEP_BUFFER_H 20 : : 21 : : #include <vector> 22 : : 23 : : #include "cvc5/cvc5_proof_rule.h" 24 : : #include "expr/node.h" 25 : : #include "proof/trust_id.h" 26 : : 27 : : namespace cvc5::internal { 28 : : 29 : : class ProofChecker; 30 : : 31 : : /** 32 : : * Information for constructing a step in a CDProof. Notice that the conclusion 33 : : * of the proof step is intentionally not included in this data structure. 34 : : * Instead, it is intended that conclusions may be associated with proof steps 35 : : * based on e.g. the result of proof checking. 36 : : */ 37 : : class ProofStep 38 : : { 39 : : public: 40 : : ProofStep(); 41 : : ProofStep(ProofRule r, 42 : : const std::vector<Node>& children, 43 : : const std::vector<Node>& args); 44 : : /** The proof rule */ 45 : : ProofRule d_rule; 46 : : /** The proof children */ 47 : : std::vector<Node> d_children; 48 : : /** The proof arguments */ 49 : : std::vector<Node> d_args; 50 : : }; 51 : : std::ostream& operator<<(std::ostream& out, ProofStep step); 52 : : 53 : : /** 54 : : * Class used to speculatively try and buffer a set of proof steps before 55 : : * sending them to a proof object. 56 : : */ 57 : : class ProofStepBuffer 58 : : { 59 : : public: 60 : : /** 61 : : * @param pc The proof checker we are using 62 : : * @param ensureUnique Whether we ensure that the conclusions of steps 63 : : * added to this buffer are unique. Later steps with the same conclusion as 64 : : * a previous one are discarded. 65 : : * @param autoSym Whether this proof step buffer is considering symmetry 66 : : * automatically. For example, this should be true if the steps of this buffer 67 : : * are being added to a CDProof with automatic symmetry. This impacts 68 : : * uniqueness of conclusions and whether certain steps are necessary. 69 : : */ 70 : : ProofStepBuffer(ProofChecker* pc = nullptr, 71 : : bool ensureUnique = false, 72 : : bool autoSym = true); 73 : 4111200 : ~ProofStepBuffer() {} 74 : : /** 75 : : * Returns the conclusion of the proof step, as determined by the proof 76 : : * checker of the given proof. If this is non-null, then the given step 77 : : * is added to the buffer maintained by this class. 78 : : * 79 : : * If expected is non-null, then this method returns null if the result of 80 : : * checking is not equal to expected. Furthermore note that if proof 81 : : * checking is set to none, this method will always successfully return 82 : : * expected. 83 : : */ 84 : : Node tryStep(ProofRule id, 85 : : const std::vector<Node>& children, 86 : : const std::vector<Node>& args, 87 : : Node expected = Node::null()); 88 : : /** Same as try step, but tracks whether a step was added */ 89 : : Node tryStep(bool& added, 90 : : ProofRule id, 91 : : const std::vector<Node>& children, 92 : : const std::vector<Node>& args, 93 : : Node expected = Node::null()); 94 : : /** 95 : : * Same as above, without checking 96 : : * @return true if a step was added. This may return false if e.g. expected 97 : : * was a duplicate conclusion. 98 : : */ 99 : : bool addStep(ProofRule id, 100 : : const std::vector<Node>& children, 101 : : const std::vector<Node>& args, 102 : : Node expected); 103 : : /** Add trusted step */ 104 : : bool addTrustedStep(TrustId id, 105 : : const std::vector<Node>& children, 106 : : const std::vector<Node>& args, 107 : : Node conc); 108 : : /** Multi-step version */ 109 : : void addSteps(ProofStepBuffer& psb); 110 : : /** pop step */ 111 : : void popStep(); 112 : : /** Get num steps */ 113 : : size_t getNumSteps() const; 114 : : /** Get steps */ 115 : : const std::vector<std::pair<Node, ProofStep>>& getSteps() const; 116 : : /** Clear */ 117 : : void clear(); 118 : : 119 : : protected: 120 : : /** 121 : : * Whether this proof step buffer is being added to a CDProof with automatic 122 : : * symmetry. This impacts uniqueness of conclusions and whether certain 123 : : * steps are necessary. 124 : : */ 125 : : bool d_autoSym; 126 : : 127 : : private: 128 : : /** The proof checker*/ 129 : : ProofChecker* d_checker; 130 : : /** the queued proof steps */ 131 : : std::vector<std::pair<Node, ProofStep>> d_steps; 132 : : /** Whether we are ensuring the conclusions in the buffer are unique */ 133 : : bool d_ensureUnique; 134 : : /** The set of conclusions in steps */ 135 : : std::unordered_set<Node> d_allSteps; 136 : : }; 137 : : 138 : : } // namespace cvc5::internal 139 : : 140 : : #endif /* CVC5__PROOF__PROOF_STEP_BUFFER_H */