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