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 : : * Equality query class. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__QUANTIFIERS_EQUALITY_QUERY_H 16 : : #define CVC5__THEORY__QUANTIFIERS_EQUALITY_QUERY_H 17 : : 18 : : #include "context/cdo.h" 19 : : #include "context/context.h" 20 : : #include "expr/node.h" 21 : : #include "theory/quantifiers/quant_util.h" 22 : : 23 : : namespace cvc5::internal { 24 : : namespace theory { 25 : : namespace quantifiers { 26 : : 27 : : class FirstOrderModel; 28 : : class QuantifiersState; 29 : : 30 : : /** EqualityQuery class 31 : : * 32 : : * The main method of this class is the function 33 : : * getInternalRepresentative, which is used by instantiation-based methods 34 : : * that are agnostic with respect to choosing terms within an equivalence class. 35 : : * Examples of such methods are finite model finding and enumerative 36 : : * instantiation. Method getInternalRepresentative returns the "best" 37 : : * representative based on the internal heuristic, which is currently based on 38 : : * choosing the term that was previously chosen as a representative earliest. 39 : : */ 40 : : class EqualityQuery : public QuantifiersUtil 41 : : { 42 : : public: 43 : : EqualityQuery(Env& env, QuantifiersState& qs, FirstOrderModel* m); 44 : : virtual ~EqualityQuery(); 45 : : 46 : : /** reset */ 47 : : bool reset(Theory::Effort e) override; 48 : : /* Called for new quantifiers */ 49 : 54043 : void registerQuantifier(CVC5_UNUSED Node q) override {} 50 : : /** identify */ 51 : 0 : std::string identify() const override { return "EqualityQuery"; } 52 : : /** gets the current best representative in the equivalence 53 : : * class of a, based on some heuristic. Currently, the default heuristic 54 : : * chooses terms that were previously chosen as representatives 55 : : * on the earliest instantiation round. 56 : : * 57 : : * If q is non-null, then q/index is the quantified formula 58 : : * and variable position that we are choosing for instantiation. 59 : : * 60 : : * This function avoids certain terms that are "ineligible" for instantiation. 61 : : * If cbqi is active, we terms that contain instantiation constants 62 : : * are ineligible. As a result, this function may return 63 : : * Node::null() if all terms in the equivalence class of a 64 : : * are ineligible. 65 : : */ 66 : : Node getInternalRepresentative(Node a, Node q, size_t index); 67 : : 68 : : private: 69 : : /** the quantifiers state */ 70 : : QuantifiersState& d_qstate; 71 : : /** Pointer to the model */ 72 : : FirstOrderModel* d_model; 73 : : /** quantifiers equality inference */ 74 : : context::CDO<unsigned> d_eqi_counter; 75 : : /** internal representatives */ 76 : : std::map<TypeNode, std::map<Node, Node> > d_int_rep; 77 : : /** rep score */ 78 : : std::map<Node, int32_t> d_rep_score; 79 : : /** the number of times reset( e ) has been called */ 80 : : size_t d_reset_count; 81 : : /** processInferences : will merge equivalence classes in master equality 82 : : * engine, if possible */ 83 : : bool processInferences(Theory::Effort e); 84 : : /** node contains */ 85 : : Node getInstance(Node n, 86 : : const std::vector<Node>& eqc, 87 : : std::unordered_map<TNode, Node>& cache); 88 : : /** get score */ 89 : : int32_t getRepScore(Node n, TypeNode v_tn); 90 : : }; /* EqualityQuery */ 91 : : 92 : : } // namespace quantifiers 93 : : } // namespace theory 94 : : } // namespace cvc5::internal 95 : : 96 : : #endif /* CVC5__THEORY__QUANTIFIERS_EQUALITY_QUERY_H */