LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/arith/nl - equality_substitution.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 3 100.0 %
Date: 2024-12-30 14:24:00 Functions: 3 3 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Top contributors (to current version):
       3                 :            :  *   Gereon Kremer
       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                 :            :  * CAD-based solver based on https://arxiv.org/pdf/2003.05633.pdf.
      14                 :            :  */
      15                 :            : 
      16                 :            : #ifndef CVC5__THEORY__ARITH__NL__EQUALITY_SUBSTITUTION_H
      17                 :            : #define CVC5__THEORY__ARITH__NL__EQUALITY_SUBSTITUTION_H
      18                 :            : 
      19                 :            : #include <vector>
      20                 :            : 
      21                 :            : #include "context/context.h"
      22                 :            : #include "expr/node.h"
      23                 :            : #include "expr/node_algorithm.h"
      24                 :            : #include "smt/env_obj.h"
      25                 :            : #include "theory/substitutions.h"
      26                 :            : #include "theory/theory.h"
      27                 :            : 
      28                 :            : namespace cvc5::internal {
      29                 :            : namespace theory {
      30                 :            : namespace arith {
      31                 :            : namespace nl {
      32                 :            : 
      33                 :            : /**
      34                 :            :  * This class is a general utility to eliminate variables from a set of
      35                 :            :  * assertions.
      36                 :            :  */
      37                 :            : class EqualitySubstitution : protected EnvObj
      38                 :            : {
      39                 :            :  public:
      40                 :            :   EqualitySubstitution(Env& env);
      41                 :            :   /** Reset this object */
      42                 :            :   void reset();
      43                 :            : 
      44                 :            :   /**
      45                 :            :    * Eliminate variables using equalities from the set of assertions.
      46                 :            :    * Returns a set of assertions where some variables may have been eliminated.
      47                 :            :    * Substitutions for the eliminated variables can be obtained from
      48                 :            :    * getSubstitutions().
      49                 :            :    */
      50                 :            :   std::vector<Node> eliminateEqualities(const std::vector<Node>& assertions);
      51                 :            :   /**
      52                 :            :    * Can be called after eliminateEqualities(). Returns the substitutions that
      53                 :            :    * were found and eliminated.
      54                 :            :    */
      55                 :         87 :   const SubstitutionMap& getSubstitutions() const { return *d_substitutions; }
      56                 :            :   /**
      57                 :            :    * Can be called after eliminateEqualities(). Checks whether a direct conflict
      58                 :            :    * was found, that is an assertion simplified to false during
      59                 :            :    * eliminateEqualities().
      60                 :            :    */
      61                 :        121 :   bool hasConflict() const { return !d_conflict.empty(); }
      62                 :            :   /**
      63                 :            :    * Return the conflict found in eliminateEqualities() as a set of assertions
      64                 :            :    * that is a subset of the input assertions provided to eliminateEqualities().
      65                 :            :    */
      66                 :         10 :   const std::vector<Node>& getConflict() const { return d_conflict; }
      67                 :            :   /**
      68                 :            :    * Postprocess a conflict found in the result of eliminateEqualities.
      69                 :            :    * Replaces assertions within the conflict by their origins, i.e. the input
      70                 :            :    * assertions and the assertions that gave rise to the substitutions being
      71                 :            :    * used.
      72                 :            :    */
      73                 :            :   void postprocessConflict(std::vector<Node>& conflict) const;
      74                 :            : 
      75                 :            :  private:
      76                 :            :   /** Utility method for addToConflictMap. Checks for n in d_conflictMap */
      77                 :            :   void insertOrigins(std::set<Node>& dest, const Node& n) const;
      78                 :            :   /** Add n -> { orig, *tracker } to the conflict map. The tracked nodes are
      79                 :            :    * first resolved using d_trackOrigin, and everything is run through
      80                 :            :    * insertOrigins to make sure that all origins are input assertions. */
      81                 :            :   void addToConflictMap(const Node& n,
      82                 :            :                         const Node& orig,
      83                 :            :                         const std::set<TNode>& tracker);
      84                 :            : 
      85                 :            :   // The SubstitutionMap
      86                 :            :   std::unique_ptr<SubstitutionMap> d_substitutions;
      87                 :            :   // conflicting assertions, if a conflict was found
      88                 :            :   std::vector<Node> d_conflict;
      89                 :            :   // Maps a simplified assertion to the original assertion + set of original
      90                 :            :   // assertions used for substitutions
      91                 :            :   std::map<Node, std::vector<Node>> d_conflictMap;
      92                 :            :   // Maps substituted terms (what will end up in the tracker) to the equality
      93                 :            :   // from which the substitution was derived.
      94                 :            :   std::map<Node, Node> d_trackOrigin;
      95                 :            : };
      96                 :            : 
      97                 :            : }  // namespace nl
      98                 :            : }  // namespace arith
      99                 :            : }  // namespace theory
     100                 :            : }  // namespace cvc5::internal
     101                 :            : 
     102                 :            : #endif /* CVC5__THEORY__ARITH__NL__EQUALITY_SUBSTITUTION_H */

Generated by: LCOV version 1.14