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 : : * Higher-order term database class. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__QUANTIFIERS__HO_TERM_DATABASE_H 16 : : #define CVC5__THEORY__QUANTIFIERS__HO_TERM_DATABASE_H 17 : : 18 : : #include <map> 19 : : 20 : : #include "expr/node.h" 21 : : #include "theory/quantifiers/term_database.h" 22 : : 23 : : namespace cvc5::internal { 24 : : namespace theory { 25 : : namespace quantifiers { 26 : : 27 : : /** 28 : : * Higher-order term database, which extends the normal term database based on 29 : : * techniques from Barbosa et al CADE 2019. 30 : : */ 31 : : class HoTermDb : public TermDb 32 : : { 33 : : public: 34 : : HoTermDb(Env& env, QuantifiersState& qs, QuantifiersRegistry& qr); 35 : : ~HoTermDb(); 36 : : /** identify */ 37 : 0 : std::string identify() const override { return "HoTermDb"; } 38 : : /** get higher-order type match predicate 39 : : * 40 : : * This predicate is used to force certain functions f of type tn to appear as 41 : : * first-class representatives in the quantifier-free UF solver. For a typical 42 : : * use case, we call getHoTypeMatchPredicate which returns a fresh predicate 43 : : * P of type (tn -> Bool). Then, we add P( f ) as a lemma. 44 : : */ 45 : : static Node getHoTypeMatchPredicate(TypeNode tn); 46 : : 47 : : private: 48 : : /** Performs merging of term indices based on higher-order reasoning */ 49 : : bool finishResetInternal(Theory::Effort e) override; 50 : : /** add term higher-order 51 : : * 52 : : * This registers additional terms corresponding to (possibly multiple) 53 : : * purifications of a higher-order term n. 54 : : * 55 : : * Consider the example: 56 : : * g : Int -> Int, f : Int x Int -> Int 57 : : * constraints: (@ f 0) = g, (f 0 1) = (@ (@ f 0) 1) = 3 58 : : * pattern: (g x) 59 : : * where @ is HO_APPLY. 60 : : * We have that (g x){ x -> 1 } is an E-match for (@ (@ f 0) 1). 61 : : * With the standard registration in addTerm, we construct term indices for 62 : : * f, g, @ : Int x Int -> Int, @ : Int -> Int. 63 : : * However, to match (g x) with (@ (@ f 0) 1), we require that 64 : : * [1] -> (@ (@ f 0) 1) 65 : : * is an entry in the term index of g. To do this, we maintain a term 66 : : * index for a fresh variable pfun, the purification variable for 67 : : * (@ f 0). Thus, we register the term (pfun 1) in the call to this function 68 : : * for (@ (@ f 0) 1). This ensures that, when processing the equality 69 : : * (@ f 0) = g, we merge the term indices of g and pfun. Hence, the entry 70 : : * [1] -> (@ (@ f 0) 1) 71 : : * is added to the term index of g, assuming g is the representative of 72 : : * the equivalence class of g and pfun. 73 : : * 74 : : * Above, we additionally add the lemmas (@ f 0) = pfun and 75 : : * (pfun 1) = (@ (@ f 0) 1). 76 : : */ 77 : : void addTermInternal(Node n) override; 78 : : /** Get operators that we know are equivalent to f */ 79 : : void getOperatorsFor(TNode f, std::vector<TNode>& ops) override; 80 : : /** get the chosen representative for operator op */ 81 : : Node getOperatorRepresentative(TNode op) const override; 82 : : /** check if we are in conflict based on congruent terms a and b */ 83 : : bool checkCongruentDisequal(TNode a, 84 : : TNode b, 85 : : std::vector<Node>& exp) override; 86 : : //------------------------------higher-order term indexing 87 : : /** 88 : : * The set of terms that we have added higher-order term purification lemmas 89 : : * for. 90 : : */ 91 : : context::CDHashSet<Node> d_hoFunOpPurify; 92 : : /** a map from matchable operators to their representative */ 93 : : std::map<TNode, TNode> d_hoOpRep; 94 : : /** for each representative matchable operator, the list of other matchable 95 : : * operators in their equivalence class */ 96 : : std::map<TNode, std::vector<TNode> > d_hoOpSlaves; 97 : : }; 98 : : 99 : : } // namespace quantifiers 100 : : } // namespace theory 101 : : } // namespace cvc5::internal 102 : : 103 : : #endif /* CVC5__THEORY__QUANTIFIERS__HO_TERM_DATABASE_H */