LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/quantifiers - candidate_rewrite_database.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2025-01-22 12:40:44 Functions: 2 2 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Top contributors (to current version):
       3                 :            :  *   Andrew Reynolds, Aina Niemetz, Abdalrhman Mohamed
       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                 :            :  * candidate_rewrite_database
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "cvc5_private.h"
      17                 :            : 
      18                 :            : #ifndef CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_DATABASE_H
      19                 :            : #define CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_DATABASE_H
      20                 :            : 
      21                 :            : #include <vector>
      22                 :            : 
      23                 :            : #include "options/options.h"
      24                 :            : #include "theory/quantifiers/candidate_rewrite_filter.h"
      25                 :            : #include "theory/quantifiers/expr_miner.h"
      26                 :            : #include "theory/quantifiers/sygus_sampler.h"
      27                 :            : 
      28                 :            : namespace cvc5::internal {
      29                 :            : namespace theory {
      30                 :            : namespace quantifiers {
      31                 :            : 
      32                 :            : /** CandidateRewriteDatabase
      33                 :            :  *
      34                 :            :  * This maintains the necessary data structures for generating a database
      35                 :            :  * of candidate rewrite rules (see Noetzli et al "Syntax-Guided Rewrite Rule
      36                 :            :  * Enumeration for SMT Solvers" SAT 2019). The primary responsibilities
      37                 :            :  * of this class are to perform the "equivalence checking" and "congruence
      38                 :            :  * and matching filtering" in Figure 1. The equivalence checking is done
      39                 :            :  * through a combination of the sygus sampler object owned by this class
      40                 :            :  * and the calls made to copies of the SolverEngine in ::addTerm. The rewrite
      41                 :            :  * rule filtering (based on congruence, matching, variable ordering) is also
      42                 :            :  * managed by the sygus sampler object.
      43                 :            :  */
      44                 :            : class CandidateRewriteDatabase : public ExprMiner
      45                 :            : {
      46                 :            :  public:
      47                 :            :   /**
      48                 :            :    * Constructor
      49                 :            :    * @param env Reference to the environment
      50                 :            :    * @param doCheck Whether to check rewrite rules using subsolvers.
      51                 :            :    * @param rewAccel Whether to construct symmetry breaking lemmas based on
      52                 :            :    * discovered rewrites (see option sygusRewSynthAccel()).
      53                 :            :    * @param filterPairs Whether to filter rewrite pairs using filtering
      54                 :            :    * techniques from the SAT 2019 paper above.
      55                 :            :    * @param rec Whether we are recursively finding rules for all subterms
      56                 :            :    * added to this class
      57                 :            :    */
      58                 :            :   CandidateRewriteDatabase(Env& env,
      59                 :            :                            bool doCheck,
      60                 :            :                            bool rewAccel = false,
      61                 :            :                            bool filterPairs = true,
      62                 :            :                            bool rec = false);
      63                 :        330 :   ~CandidateRewriteDatabase() {}
      64                 :            :   /**  Initialize this class */
      65                 :            :   void initialize(const std::vector<Node>& var, SygusSampler* ss) override;
      66                 :            :   /**  Initialize this class
      67                 :            :    *
      68                 :            :    * Serves the same purpose as the above function, but we will be using
      69                 :            :    * sygus to enumerate terms and generate samples.
      70                 :            :    *
      71                 :            :    * tds : pointer to sygus term database. We use the extended rewriter of this
      72                 :            :    * database when computing candidate rewrites,
      73                 :            :    * f : a term of some SyGuS datatype type whose values we will be
      74                 :            :    * testing under the free variables in the grammar of f. This is the
      75                 :            :    * "candidate variable" CegConjecture::d_candidates.
      76                 :            :    */
      77                 :            :   void initializeSygus(const std::vector<Node>& vars,
      78                 :            :                        TermDbSygus* tds,
      79                 :            :                        Node f,
      80                 :            :                        SygusSampler* ss);
      81                 :            :   /** add term
      82                 :            :    *
      83                 :            :    * Notifies this class that the solution sol was enumerated. This may
      84                 :            :    * cause a candidate-rewrite to be printed on the output stream out.
      85                 :            :    *
      86                 :            :    * @param sol The term to add to this class.
      87                 :            :    * @param rewrites The set of rewrite rules discovered on this call.
      88                 :            :    * @return A previous term eq_sol added to this class, such that sol is
      89                 :            :    * equivalent to eq_sol based on the criteria used by this class. We return
      90                 :            :    * only terms that are verified to be equivalent to sol.
      91                 :            :    */
      92                 :            :   Node addOrGetTerm(Node sol, std::vector<Node>& rewrites);
      93                 :            :   /**
      94                 :            :    * Same as above, returns true if the return value of addTerm was equal to
      95                 :            :    * sol, in other words, sol was a new unique term. This assumes false for
      96                 :            :    * the argument rec.
      97                 :            :    */
      98                 :            :   bool addTerm(Node sol, std::vector<Node>& rewrites) override;
      99                 :            :   /** Enable the (extended) rewriter for this class */
     100                 :            :   void enableExtendedRewriter();
     101                 :            :   /** Was the given rewrite verified? */
     102                 :            :   bool wasVerified(const Node& rewrite) const;
     103                 :            : 
     104                 :            :  private:
     105                 :            :   /** (required) pointer to the sygus term database of d_qe */
     106                 :            :   TermDbSygus* d_tds;
     107                 :            :   /** Whether we use the extended rewriter */
     108                 :            :   bool d_useExtRewriter;
     109                 :            :   /** the function-to-synthesize we are testing (if sygus) */
     110                 :            :   Node d_candidate;
     111                 :            :   /** whether we are checking equivalence using subsolver */
     112                 :            :   bool d_doCheck;
     113                 :            :   /**
     114                 :            :    * If true, we use acceleration for symmetry breaking rewrites (see option
     115                 :            :    * sygusRewSynthAccel()).
     116                 :            :    */
     117                 :            :   bool d_rewAccel;
     118                 :            :   /** if true, we silence the output of candidate rewrites */
     119                 :            :   bool d_silent;
     120                 :            :   /** if true, we filter pairs of terms to check equivalence */
     121                 :            :   bool d_filterPairs;
     122                 :            :   /** whether we are using sygus */
     123                 :            :   bool d_using_sygus;
     124                 :            :   /** Whether we check rewrite rules for all subterms added to this class */
     125                 :            :   bool d_rec;
     126                 :            :   /** candidate rewrite filter */
     127                 :            :   CandidateRewriteFilter d_crewrite_filter;
     128                 :            :   /** the cache for results of addTerm */
     129                 :            :   std::unordered_map<Node, Node> d_add_term_cache;
     130                 :            :   /** The options for subsolver calls */
     131                 :            :   Options d_subOptions;
     132                 :            :   /** The set of rewrites that succeeded verification */
     133                 :            :   std::unordered_set<Node> d_verified;
     134                 :            : };
     135                 :            : 
     136                 :            : }  // namespace quantifiers
     137                 :            : }  // namespace theory
     138                 :            : }  // namespace cvc5::internal
     139                 :            : 
     140                 :            : #endif /* CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_DATABASE_H */

Generated by: LCOV version 1.14