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 : : * expr_miner 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__QUANTIFIERS__EXPRESSION_MINER_H 16 : : #define CVC5__THEORY__QUANTIFIERS__EXPRESSION_MINER_H 17 : : 18 : : #include <map> 19 : : #include <memory> 20 : : #include <vector> 21 : : 22 : : #include "expr/node.h" 23 : : #include "smt/env_obj.h" 24 : : #include "theory/quantifiers/sygus_sampler.h" 25 : : #include "theory/smt_engine_subsolver.h" 26 : : 27 : : namespace cvc5::internal { 28 : : 29 : : class Env; 30 : : class SolverEngine; 31 : : 32 : : namespace theory { 33 : : namespace quantifiers { 34 : : 35 : : /** Expression miner 36 : : * 37 : : * This is a virtual base class for modules that "mines" certain information 38 : : * from (enumerated) expressions. This includes: 39 : : * - candidate rewrite rules (find-synth :rewrite) 40 : : * - unsound rewrite rules (find-synth :rewrite_unsound) 41 : : * - queries (find-synth :query) 42 : : */ 43 : : class ExprMiner : protected EnvObj 44 : : { 45 : : public: 46 : 619 : ExprMiner(Env& env) : EnvObj(env), d_sampler(nullptr) {} 47 : 598 : virtual ~ExprMiner() {} 48 : : /** initialize 49 : : * 50 : : * This initializes this expression miner. The argument vars indicates the 51 : : * free variables of terms that will be added to this class. The argument 52 : : * sampler gives an (optional) pointer to a sampler, which is used to 53 : : * sample tuples of valuations of these variables. 54 : : */ 55 : : virtual void initialize(const std::vector<Node>& vars, 56 : : SygusSampler* ss = nullptr); 57 : : /** add term 58 : : * 59 : : * This registers term n with this expression miner, and adds expressions 60 : : * found (e.g. rewrites, queries) to found. 61 : : */ 62 : : virtual bool addTerm(Node n, std::vector<Node>& found) = 0; 63 : : 64 : : protected: 65 : : /** the set of variables used by this class */ 66 : : std::vector<Node> d_vars; 67 : : /** 68 : : * The set of skolems corresponding to the above variables. These are 69 : : * used during initializeChecker so that query (which may contain free 70 : : * variables) is converted to a formula without free variables. 71 : : */ 72 : : std::vector<Node> d_skolems; 73 : : /** pointer to the sygus sampler object we are using */ 74 : : SygusSampler* d_sampler; 75 : : /** Maps to skolems for each free variable based on d_vars/d_skolems. */ 76 : : std::map<Node, Node> d_fv_to_skolem; 77 : : /** convert */ 78 : : Node convertToSkolem(Node n); 79 : : /** initialize checker 80 : : * 81 : : * This function initializes the smt engine smte to check the satisfiability 82 : : * of the argument "query", which is a formula whose free variables (of 83 : : * kind BOUND_VARIABLE) are a subset of d_vars. 84 : : */ 85 : : void initializeChecker(std::unique_ptr<SolverEngine>& checker, 86 : : Node query, 87 : : const SubsolverSetupInfo& info); 88 : : /** 89 : : * Run the satisfiability check on query and return the result 90 : : * (sat/unsat/unknown). 91 : : * 92 : : * In contrast to the above method, this call should be used for cases where 93 : : * the model for the query is not important. 94 : : */ 95 : : Result doCheck(Node query, const SubsolverSetupInfo& info); 96 : : }; 97 : : 98 : : /** Identity expression miner */ 99 : : class ExprMinerId : public ExprMiner 100 : : { 101 : : public: 102 : 36 : ExprMinerId(Env& env) : ExprMiner(env) {} 103 : 60 : virtual ~ExprMinerId() {} 104 : : /** Returns true and adds n to found */ 105 : : bool addTerm(Node n, std::vector<Node>& found) override; 106 : : }; 107 : : 108 : : } // namespace quantifiers 109 : : } // namespace theory 110 : : } // namespace cvc5::internal 111 : : 112 : : #endif /* CVC5__THEORY__QUANTIFIERS__EXPRESSION_MINER_H */