LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/quantifiers - relevant_domain.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 10 11 90.9 %
Date: 2026-04-22 10:35:54 Functions: 4 5 80.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                 :            :  * Relevant domain class.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "cvc5_private.h"
      14                 :            : 
      15                 :            : #ifndef CVC5__THEORY__QUANTIFIERS__RELEVANT_DOMAIN_H
      16                 :            : #define CVC5__THEORY__QUANTIFIERS__RELEVANT_DOMAIN_H
      17                 :            : 
      18                 :            : #include "theory/quantifiers/first_order_model.h"
      19                 :            : #include "theory/quantifiers/quant_util.h"
      20                 :            : 
      21                 :            : namespace cvc5::internal {
      22                 :            : namespace theory {
      23                 :            : namespace quantifiers {
      24                 :            : 
      25                 :            : class QuantifiersState;
      26                 :            : class QuantifiersRegistry;
      27                 :            : class TermRegistry;
      28                 :            : 
      29                 :            : /** Relevant Domain
      30                 :            :  *
      31                 :            :  * This class computes the relevant domain of
      32                 :            :  * functions and quantified formulas based on
      33                 :            :  * techniques from "Complete Instantiation for Quantified
      34                 :            :  * Formulas in SMT" by Ge et al., CAV 2009.
      35                 :            :  *
      36                 :            :  * Calling compute() will compute a representation
      37                 :            :  * of relevant domain information, which be accessed
      38                 :            :  * by getRDomain(...) calls. It is intended to be called
      39                 :            :  * at full effort check, after we have initialized
      40                 :            :  * the term database.
      41                 :            :  */
      42                 :            : class RelevantDomain : public QuantifiersUtil
      43                 :            : {
      44                 :            :  public:
      45                 :            :   RelevantDomain(Env& env,
      46                 :            :                  QuantifiersState& qs,
      47                 :            :                  QuantifiersRegistry& qr,
      48                 :            :                  TermRegistry& tr);
      49                 :            :   virtual ~RelevantDomain();
      50                 :            :   /** Reset. */
      51                 :            :   bool reset(Theory::Effort e) override;
      52                 :            :   /** Register the quantified formula q */
      53                 :            :   void registerQuantifier(Node q) override;
      54                 :            :   /** identify */
      55                 :          0 :   std::string identify() const override { return "RelevantDomain"; }
      56                 :            :   /** Compute the relevant domain */
      57                 :            :   void compute();
      58                 :            :   /** Relevant domain representation.
      59                 :            :    *
      60                 :            :    * This data structure is inspired by the paper
      61                 :            :    * "Complete Instantiation for Quantified Formulas in SMT" by
      62                 :            :    * Ge et al., CAV 2009.
      63                 :            :    * Notice that relevant domains may be equated to one another,
      64                 :            :    * for example, if the quantified formula forall x. P( x, x )
      65                 :            :    * exists in the current context, then the relevant domain of
      66                 :            :    * arguments 1 and 2 of P are equated.
      67                 :            :    */
      68                 :            :   class RDomain
      69                 :            :   {
      70                 :            :    public:
      71                 :      10409 :     RDomain() : d_parent(nullptr) {}
      72                 :            :     /** the set of terms in this relevant domain */
      73                 :            :     std::vector<Node> d_terms;
      74                 :            :     /** reset this object */
      75                 :      18713 :     void reset()
      76                 :            :     {
      77                 :      18713 :       d_parent = nullptr;
      78                 :      18713 :       d_terms.clear();
      79                 :      18713 :     }
      80                 :            :     /** merge this with r
      81                 :            :      * This sets d_parent of this to r and
      82                 :            :      * copies the terms of this to r.
      83                 :            :      */
      84                 :            :     void merge(RDomain* r);
      85                 :            :     /** add term to the relevant domain */
      86                 :            :     void addTerm(Node t);
      87                 :            :     /** get the parent of this */
      88                 :            :     RDomain* getParent();
      89                 :            :     /** remove redundant terms for d_terms, removes
      90                 :            :      * duplicates modulo equality.
      91                 :            :      */
      92                 :            :     void removeRedundantTerms(QuantifiersState& qs);
      93                 :            :     /** is n in this relevant domain? */
      94                 :            :     bool hasTerm(Node n)
      95                 :            :     {
      96                 :            :       return std::find(d_terms.begin(), d_terms.end(), n) != d_terms.end();
      97                 :            :     }
      98                 :            : 
      99                 :            :    private:
     100                 :            :     /** the parent of this relevant domain */
     101                 :            :     RDomain* d_parent;
     102                 :            :   };
     103                 :            :   /** get the relevant domain
     104                 :            :    *
     105                 :            :    * Gets object representing the relevant domain of the i^th argument of n.
     106                 :            :    *
     107                 :            :    * If getParent is true, we return the representative
     108                 :            :    * of the equivalence class of relevant domain objects,
     109                 :            :    * which is computed as a union find (see RDomain::d_parent).
     110                 :            :    */
     111                 :            :   RDomain* getRDomain(Node n, size_t i, bool getParent = true);
     112                 :            : 
     113                 :            :  private:
     114                 :            :   /** the relevant domains for each quantified formula and function,
     115                 :            :    * for each variable # and argument #.
     116                 :            :    */
     117                 :            :   std::map<Node, std::map<size_t, RDomain*> > d_rel_doms;
     118                 :            :   /** Reference to the quantifiers state object */
     119                 :            :   QuantifiersState& d_qs;
     120                 :            :   /** Reference to the quantifiers registry */
     121                 :            :   QuantifiersRegistry& d_qreg;
     122                 :            :   /** Reference to the term registry */
     123                 :            :   TermRegistry& d_treg;
     124                 :            :   /** have we computed the relevant domain on this full effort check? */
     125                 :            :   bool d_is_computed;
     126                 :            :   /** relevant domain literal
     127                 :            :    * Caches the effect of literals on the relevant domain.
     128                 :            :    */
     129                 :            :   class RDomainLit
     130                 :            :   {
     131                 :            :    public:
     132                 :        895 :     RDomainLit() : d_merge(false)
     133                 :            :     {
     134                 :        895 :       d_rd[0] = nullptr;
     135                 :        895 :       d_rd[1] = nullptr;
     136                 :        895 :     }
     137                 :        895 :     ~RDomainLit() {}
     138                 :            :     /** whether this literal forces the merge of two relevant domains */
     139                 :            :     bool d_merge;
     140                 :            :     /** the relevant domains that are merged as a result
     141                 :            :      * of this literal
     142                 :            :      */
     143                 :            :     RDomain* d_rd[2];
     144                 :            :     /** the terms that are added to
     145                 :            :      * the relevant domain as a result of this literal
     146                 :            :      */
     147                 :            :     std::vector<Node> d_val;
     148                 :            :   };
     149                 :            :   /** Cache of the effect of literals on the relevant domain */
     150                 :            :   std::map<bool, std::map<bool, std::map<Node, RDomainLit> > > d_rel_dom_lit;
     151                 :            :   /** Compute the relevant domain for quantified formula q. */
     152                 :            :   void computeRelevantDomain(Node q);
     153                 :            :   /** Compute the relevant domain for a subformula n of q,
     154                 :            :    * whose polarity is given by hasPol/pol.
     155                 :            :    */
     156                 :            :   void computeRelevantDomainNode(Node q, Node n, bool hasPol, bool pol);
     157                 :            :   /** Compute the relevant domain when the term n
     158                 :            :    * is in a position to be included in relevant domain rf.
     159                 :            :    */
     160                 :            :   void computeRelevantDomainOpCh(RDomain* rf, Node n);
     161                 :            :   /** compute relevant domain for literal.
     162                 :            :    *
     163                 :            :    * Updates the relevant domains based on a literal n in quantified
     164                 :            :    * formula q whose polarity is given by hasPol/pol.
     165                 :            :    */
     166                 :            :   void computeRelevantDomainLit(Node q, bool hasPol, bool pol, Node n);
     167                 :            : }; /* class RelevantDomain */
     168                 :            : 
     169                 :            : }  // namespace quantifiers
     170                 :            : }  // namespace theory
     171                 :            : }  // namespace cvc5::internal
     172                 :            : 
     173                 :            : #endif /* CVC5__THEORY__QUANTIFIERS__RELEVANT_DOMAIN_H */

Generated by: LCOV version 1.14