Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andrew Reynolds 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 : : * Conflict processor module 14 : : */ 15 : : 16 : : #include "cvc5_public.h" 17 : : 18 : : #ifndef CVC5__THEORY__CONFLICT_PROCESSOR_H 19 : : #define CVC5__THEORY__CONFLICT_PROCESSOR_H 20 : : 21 : : #include "expr/node.h" 22 : : #include "expr/subs.h" 23 : : #include "proof/trust_node.h" 24 : : #include "smt/env_obj.h" 25 : : #include "theory/substitutions.h" 26 : : #include "util/statistics_stats.h" 27 : : 28 : : namespace cvc5::internal { 29 : : 30 : : class TheoryEngine; 31 : : class Assigner; 32 : : 33 : : namespace theory { 34 : : 35 : : /** 36 : : * A utility for inferring when a theory lemma or conflict can be strengthened 37 : : * based on substitution + rewriting. 38 : : */ 39 : : class ConflictProcessor : protected EnvObj 40 : : { 41 : : public: 42 : : /** 43 : : * The constructor for this class. 44 : : * @param env The environment. 45 : : * @param useExtRewriter Whether we use the extended rewriter when evaluating substitutions below. 46 : : */ 47 : : ConflictProcessor(Env& env, bool useExtRewriter = false); 48 : 16 : ~ConflictProcessor() {} 49 : : 50 : : /** 51 : : * Attempt to rewrite a lemma to a stronger one. For example, the lemma 52 : : * (=> (= x a) (or B C)) may be replaced by (=> (= x a) B) if B[a/x] rewrites 53 : : * to true. We also may drop literals that rewrite to the same this under this 54 : : * substitution, or drop equalities from the lemma that are determined to be 55 : : * irrelevant based on this reasoning. 56 : : * This method also may minimize the antecedant corresponding to a 57 : : * substituion, e.g. (=> (and (= x a) (= y b)) B) may be replaced by 58 : : * (=> (= x a) B) if B[a/x] rewrites to true. 59 : : * 60 : : * @param lem The lemma. 61 : : * @return A trust node for a lemma that implies lem. 62 : : */ 63 : : TrustNode processLemma(const TrustNode& lem); 64 : : 65 : : private: 66 : : /** Common constants */ 67 : : Node d_true; 68 : : Node d_false; 69 : : Node d_nullNode; 70 : : /** Use the extended rewriter? */ 71 : : bool d_useExtRewriter; 72 : : /** Statistics about the conflict processor */ 73 : : struct Statistics 74 : : { 75 : : Statistics(StatisticsRegistry& sr); 76 : : /** Total number of lemmas given to this module */ 77 : : IntStat d_initLemmas; 78 : : /** Total number of lemmas for which we were able to decompose */ 79 : : IntStat d_lemmas; 80 : : /** Total number of minimized lemmas */ 81 : : IntStat d_minLemmas; 82 : : }; 83 : : Statistics d_stats; 84 : : /** 85 : : * Decompose lemma into a substitution and a remainder. For example, the 86 : : * lemma (or (not (= 0 x)) (= (* x y) 0)) is decomposed as follows: 87 : : * s = {x->0} 88 : : * varToExp = {x -> (= 0 x)} 89 : : * tgtLits = {(= (* x y) 0)} 90 : : * 91 : : * More generally, note that the lem is equivalent to 92 : : * (=> (and (= x_1 c_1) .... (= x_n c_n)) (or tgtLits[1] ... tgtLits[n])) 93 : : * where s = { x_1 -> c_1, ..., x_n -> c_n }. 94 : : * 95 : : * Any lemma that can be decomposed is a possible target for minimization, 96 : : * where we can recognize spurious or redundant literals, or spurious 97 : : * equalities in the substitution. 98 : : * 99 : : * @param lem The lemma. 100 : : * @param s The substitution that can be derived from lem. 101 : : * @param varToExp Maps variables in the domain of s to the literal that 102 : : * explains why they are equal to the range. 103 : : * @param tgtLits The literals that were not accounted for in the 104 : : * substitution. 105 : : */ 106 : : void decomposeLemma(const Node& lem, 107 : : SubstitutionMap& s, 108 : : std::map<Node, Node>& varToExp, 109 : : std::vector<Node>& tgtLits) const; 110 : : /** 111 : : * Evaluate substitution, which returns the result applying s to tgt and 112 : : * applying extended rewriting. If this is not equal to constant Boolean, 113 : : * we return the null node. The formula tgt may be an AND/OR, which we 114 : : * optimize for in this method. 115 : : * @param s The current substitution. 116 : : * @param tgt The target formula. 117 : : * @return The result of evaluating tgt under the substitution s. 118 : : */ 119 : : Node evaluateSubstitution(const SubstitutionMap& s, const Node& tgt) const; 120 : : /** 121 : : * Evaluate substitution for a literal. This is the same as the above method 122 : : * but tgtLit is guaranteed to be a theory literal. 123 : : * @param s The current substitution. 124 : : * @param tgtLit The target literal. 125 : : * @return The result of evaluating tgtLit under the substitution s. 126 : : */ 127 : : Node evaluateSubstitutionLit(const SubstitutionMap& s, 128 : : const Node& tgtLit) const; 129 : : /** 130 : : * Is assignment equality? Returns true if n is an equality from which 131 : : * a substitution can be inferred and added to s. It does not consider 132 : : * substitutions that induce cycles or are for variables that already have 133 : : * substitutions. For example, given current substitution s = {y->z}, 134 : : * (= x y) returns true with x -> y. 135 : : * (= x (f x)) return false. 136 : : * (= y 0) returns false, since y is already bound. 137 : : * (= z (f y)) returns false, since this would result in a cycle. 138 : : * @param s The current substitution. 139 : : * @param n The literal in question. 140 : : * @param v If this method returns true, this updates v to the variable of 141 : : * the new substitution. 142 : : * @param c If this method returns true, this updates c to the substitution 143 : : * for v. 144 : : */ 145 : : bool isAssignEq(const SubstitutionMap& s, 146 : : const Node& n, 147 : : Node& v, 148 : : Node& c) const; 149 : : }; 150 : : 151 : : } // namespace theory 152 : : } // namespace cvc5::internal 153 : : 154 : : #endif /* CVC5__ASSIGNER_H */