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 : : * Implementation of term enumeration utility. 11 : : */ 12 : : 13 : : #include "theory/quantifiers/term_enumeration.h" 14 : : 15 : : #include "theory/quantifiers/quant_bound_inference.h" 16 : : 17 : : using namespace cvc5::internal::kind; 18 : : 19 : : namespace cvc5::internal { 20 : : namespace theory { 21 : : namespace quantifiers { 22 : : 23 : 68824 : TermEnumeration::TermEnumeration(QuantifiersBoundInference* qbi) : d_qbi(qbi) {} 24 : : 25 : 100849 : Node TermEnumeration::getEnumerateTerm(TypeNode tn, unsigned index) 26 : : { 27 [ + - ]: 201698 : Trace("term-db-enum") << "Get enumerate term " << tn << " " << index 28 : 100849 : << std::endl; 29 : 100849 : std::unordered_map<TypeNode, size_t>::iterator it = d_typ_enum_map.find(tn); 30 : : size_t teIndex; 31 [ + + ]: 100849 : if (it == d_typ_enum_map.end()) 32 : : { 33 : 3088 : teIndex = d_typ_enum.size(); 34 : 3088 : d_typ_enum_map[tn] = teIndex; 35 : 3088 : d_typ_enum.push_back(TypeEnumerator(tn)); 36 : : } 37 : : else 38 : : { 39 : 97761 : teIndex = it->second; 40 : : } 41 [ + + ]: 108782 : while (index >= d_enum_terms[tn].size()) 42 : : { 43 [ + + ]: 9646 : if (d_typ_enum[teIndex].isFinished()) 44 : : { 45 : 1713 : return Node::null(); 46 : : } 47 : 7933 : d_enum_terms[tn].push_back(*d_typ_enum[teIndex]); 48 : 7933 : ++d_typ_enum[teIndex]; 49 : : } 50 : 99136 : return d_enum_terms[tn][index]; 51 : : } 52 : : 53 : 0 : bool TermEnumeration::getDomain(TypeNode tn, std::vector<Node>& dom) 54 : : { 55 : 0 : if (!d_qbi || !d_qbi->mayComplete(tn)) 56 : : { 57 : 0 : return false; 58 : : } 59 : 0 : Node curre; 60 : 0 : unsigned counter = 0; 61 : : do 62 : : { 63 : 0 : curre = getEnumerateTerm(tn, counter); 64 : 0 : counter++; 65 [ - - ]: 0 : if (!curre.isNull()) 66 : : { 67 : 0 : dom.push_back(curre); 68 : : } 69 [ - - ]: 0 : } while (!curre.isNull()); 70 : 0 : return true; 71 : 0 : } 72 : : 73 : : } // namespace quantifiers 74 : : } // namespace theory 75 : : } // namespace cvc5::internal