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