Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andrew Reynolds, Mathias Preiner 4 : : * 5 : : * This file is part of the cvc5 project. 6 : : * 7 : : * Copyright (c) 2009-2025 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 : : * Implementation of term enumeration utility. 14 : : */ 15 : : 16 : : #include "theory/quantifiers/term_enumeration.h" 17 : : 18 : : #include "theory/quantifiers/quant_bound_inference.h" 19 : : 20 : : using namespace cvc5::internal::kind; 21 : : 22 : : namespace cvc5::internal { 23 : : namespace theory { 24 : : namespace quantifiers { 25 : : 26 : 72747 : TermEnumeration::TermEnumeration(QuantifiersBoundInference* qbi) : d_qbi(qbi) {} 27 : : 28 : 309276 : Node TermEnumeration::getEnumerateTerm(TypeNode tn, unsigned index) 29 : : { 30 [ + - ]: 618552 : Trace("term-db-enum") << "Get enumerate term " << tn << " " << index 31 : 309276 : << std::endl; 32 : 309276 : std::unordered_map<TypeNode, size_t>::iterator it = d_typ_enum_map.find(tn); 33 : : size_t teIndex; 34 [ + + ]: 309276 : if (it == d_typ_enum_map.end()) 35 : : { 36 : 3155 : teIndex = d_typ_enum.size(); 37 : 3155 : d_typ_enum_map[tn] = teIndex; 38 : 3155 : d_typ_enum.push_back(TypeEnumerator(tn)); 39 : : } 40 : : else 41 : : { 42 : 306121 : teIndex = it->second; 43 : : } 44 [ + + ]: 318178 : while (index >= d_enum_terms[tn].size()) 45 : : { 46 [ + + ]: 25006 : if (d_typ_enum[teIndex].isFinished()) 47 : : { 48 : 16104 : return Node::null(); 49 : : } 50 : 8902 : d_enum_terms[tn].push_back(*d_typ_enum[teIndex]); 51 : 8902 : ++d_typ_enum[teIndex]; 52 : : } 53 : 293172 : return d_enum_terms[tn][index]; 54 : : } 55 : : 56 : 0 : bool TermEnumeration::getDomain(TypeNode tn, std::vector<Node>& dom) 57 : : { 58 : 0 : if (!d_qbi || !d_qbi->mayComplete(tn)) 59 : : { 60 : 0 : return false; 61 : : } 62 : 0 : Node curre; 63 : 0 : unsigned counter = 0; 64 : 0 : do 65 : : { 66 : 0 : curre = getEnumerateTerm(tn, counter); 67 : 0 : counter++; 68 [ - - ]: 0 : if (!curre.isNull()) 69 : : { 70 : 0 : dom.push_back(curre); 71 : : } 72 [ - - ]: 0 : } while (!curre.isNull()); 73 : 0 : return true; 74 : : } 75 : : 76 : : } // namespace quantifiers 77 : : } // namespace theory 78 : : } // namespace cvc5::internal