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 : : * Theory proof step buffer utility. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__PROOF__THEORY_PROOF_STEP_BUFFER_H 16 : : #define CVC5__PROOF__THEORY_PROOF_STEP_BUFFER_H 17 : : 18 : : #include <vector> 19 : : 20 : : #include "expr/node.h" 21 : : #include "proof/proof_step_buffer.h" 22 : : #include "theory/builtin/proof_checker.h" 23 : : 24 : : namespace cvc5::internal { 25 : : /** 26 : : * Class used to speculatively try and buffer a set of proof steps before 27 : : * sending them to a proof object, extended with theory-specfic proof rule 28 : : * utilities. 29 : : */ 30 : : class TheoryProofStepBuffer : public ProofStepBuffer 31 : : { 32 : : public: 33 : : TheoryProofStepBuffer(ProofChecker* pc = nullptr, 34 : : bool ensureUnique = false, 35 : : bool autoSym = true); 36 : 3789681 : ~TheoryProofStepBuffer() {} 37 : : //---------------------------- utilities builtin proof rules 38 : : /** 39 : : * Apply equality introduction. If this method returns true, it adds proof 40 : : * step(s) to the buffer that conclude (= src tgt) from premises exp. In 41 : : * particular, it may attempt to apply the rule MACRO_SR_EQ_INTRO. This 42 : : * method should be applied when tgt is equivalent to src assuming exp. 43 : : * 44 : : * @param useExpected If true, we pass (= src tgt) as expected to tryStep. 45 : : * When true, this method will always succeed if proof checking is 46 : : * disabled. 47 : : */ 48 : : bool applyEqIntro(Node src, 49 : : Node tgt, 50 : : const std::vector<Node>& exp, 51 : : MethodId ids = MethodId::SB_DEFAULT, 52 : : MethodId ida = MethodId::SBA_SEQUENTIAL, 53 : : MethodId idr = MethodId::RW_REWRITE, 54 : : bool useExpected = false); 55 : : /** 56 : : * Apply predicate transform. If this method returns true, it adds (at most 57 : : * one) proof step to the buffer that conclude tgt from premises src, exp. In 58 : : * particular, it may attempt to apply MACRO_SR_PRED_TRANSFORM. This method 59 : : * should be applied when src and tgt are equivalent formulas assuming exp. 60 : : * 61 : : * @param useExpected If true, we pass tgt as expected to tryStep. 62 : : * When true, this method will always succeed if proof checking is 63 : : * disabled. 64 : : */ 65 : : bool applyPredTransform(Node src, 66 : : Node tgt, 67 : : const std::vector<Node>& exp, 68 : : MethodId ids = MethodId::SB_DEFAULT, 69 : : MethodId ida = MethodId::SBA_SEQUENTIAL, 70 : : MethodId idr = MethodId::RW_REWRITE, 71 : : bool useExpected = false); 72 : : /** 73 : : * Apply predicate introduction. If this method returns true, it adds proof 74 : : * step(s) to the buffer that conclude tgt from premises exp. In particular, 75 : : * it may attempt to apply the rule MACRO_SR_PRED_INTRO. This method should be 76 : : * applied when tgt is equivalent to true assuming exp. 77 : : * 78 : : * @param useExpected If true, we pass tgt as expected to tryStep. 79 : : * When true, this method will always succeed if proof checking is 80 : : * disabled. 81 : : */ 82 : : bool applyPredIntro(Node tgt, 83 : : const std::vector<Node>& exp, 84 : : MethodId ids = MethodId::SB_DEFAULT, 85 : : MethodId ida = MethodId::SBA_SEQUENTIAL, 86 : : MethodId idr = MethodId::RW_REWRITE, 87 : : bool useExpected = false); 88 : : /** 89 : : * Apply predicate elimination. This method returns the result of applying 90 : : * the rule MACRO_SR_PRED_ELIM on src, exp. The returned formula is equivalent 91 : : * to src assuming exp. If the return value is equivalent to src, then no 92 : : * proof step is added to this buffer, since this step is a no-op in this 93 : : * case. 94 : : * 95 : : * Notice that in contrast to the other rules above, predicate elimination 96 : : * never fails and proves a formula that is not explicitly given as an 97 : : * argument tgt. Thus, the return value of this method is Node not bool. 98 : : */ 99 : : Node applyPredElim(Node src, 100 : : const std::vector<Node>& exp, 101 : : MethodId ids = MethodId::SB_DEFAULT, 102 : : MethodId ida = MethodId::SBA_SEQUENTIAL, 103 : : MethodId idr = MethodId::RW_REWRITE); 104 : : //---------------------------- end utilities builtin proof rules 105 : : 106 : : //---------------------------- utility methods for normalizing clauses 107 : : /** 108 : : * Normalizes a non-unit clause (an OR node) according to factoring and 109 : : * reordering, i.e. removes duplicates and reorders literals (according to 110 : : * node ids). Moreover it eliminates double negations, which can be done also 111 : : * for unit clauses (a arbitrary Boolean node). All normalization steps are 112 : : * tracked via proof steps added to this proof step buffer. 113 : : * 114 : : * @param n the clause to be normalized 115 : : * @return the normalized clause node 116 : : */ 117 : : Node factorReorderElimDoubleNeg(Node n); 118 : : 119 : : /** 120 : : * Eliminates double negation of a literal if it has the form 121 : : * (not (not t)) 122 : : * If the elimination happens, a step is added to this proof step buffer. 123 : : * 124 : : * @param n the node to have the top-level double negation eliminated 125 : : * @return the normalized clause node 126 : : */ 127 : : Node elimDoubleNegLit(Node n); 128 : : }; 129 : : 130 : : } // namespace cvc5::internal 131 : : 132 : : #endif /* CVC5__PROOF__THEORY_PROOF_STEP_BUFFER_H */