LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory - conflict_processor.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2026-04-21 10:32:34 Functions: 2 2 100.0 %
Branches: 0 0 -

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

Generated by: LCOV version 1.14