Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andrew Reynolds, Morgan Deters, Gereon Kremer 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 inst match class. 14 : : */ 15 : : 16 : : #include "theory/quantifiers/inst_match.h" 17 : : 18 : : #include "options/quantifiers_options.h" 19 : : #include "theory/quantifiers/quantifiers_state.h" 20 : : #include "theory/quantifiers/term_registry.h" 21 : : 22 : : namespace cvc5::internal { 23 : : namespace theory { 24 : : namespace quantifiers { 25 : : 26 : 106336 : InstMatch::InstMatch(Env& env, QuantifiersState& qs, TermRegistry& tr, TNode q) 27 : 106336 : : EnvObj(env), d_qs(qs), d_tr(tr), d_quant(q), d_ieval(nullptr) 28 : : { 29 : 106336 : d_vals.resize(q[0].getNumChildren()); 30 [ - + ][ - + ]: 106336 : Assert(!d_vals.empty()); [ - - ] 31 : : // resize must initialize with null nodes 32 [ - + ][ - + ]: 106336 : Assert(d_vals[0].isNull()); [ - - ] 33 : 106336 : } 34 : : 35 : 337396 : void InstMatch::setEvaluatorMode(ieval::TermEvaluatorMode tev) 36 : : { 37 : : // should only do this if we are empty 38 [ - + ][ - + ]: 337396 : Assert(empty()); [ - - ] 39 : : // get the instantiation evaluator and reset it 40 : 337396 : d_ieval = d_tr.getEvaluator(d_quant, tev); 41 [ + + ]: 337396 : if (d_ieval != nullptr) 42 : : { 43 : 336580 : d_ieval->resetAll(); 44 : : } 45 : 337396 : } 46 : : 47 : 0 : void InstMatch::debugPrint( const char* c ){ 48 [ - - ]: 0 : for (unsigned i = 0, size = d_vals.size(); i < size; i++) 49 : : { 50 [ - - ]: 0 : if( !d_vals[i].isNull() ){ 51 [ - - ]: 0 : Trace( c ) << " " << i << " -> " << d_vals[i] << std::endl; 52 : : } 53 : : } 54 : 0 : } 55 : : 56 : 0 : void InstMatch::toStream(std::ostream& out) const 57 : : { 58 : 0 : out << "INST_MATCH( "; 59 : 0 : bool printed = false; 60 [ - - ]: 0 : for (size_t i = 0, size = d_vals.size(); i < size; i++) 61 : : { 62 [ - - ]: 0 : if (!d_vals[i].isNull()) 63 : : { 64 [ - - ]: 0 : if (printed) 65 : : { 66 : 0 : out << ", "; 67 : : } 68 : 0 : out << i << " -> " << d_vals[i]; 69 : 0 : printed = true; 70 : : } 71 : : } 72 : 0 : out << " )"; 73 : 0 : } 74 : : 75 : 0 : bool InstMatch::isComplete() const 76 : : { 77 [ - - ]: 0 : for (const Node& v : d_vals) 78 : : { 79 [ - - ]: 0 : if (v.isNull()) 80 : : { 81 : 0 : return false; 82 : : } 83 : : } 84 : 0 : return true; 85 : : } 86 : : 87 : 337396 : bool InstMatch::empty() const 88 : : { 89 [ + + ]: 1209440 : for (const Node& v : d_vals) 90 : : { 91 [ - + ]: 872045 : if (!v.isNull()) 92 : : { 93 : 0 : return false; 94 : : } 95 : : } 96 : 337396 : return true; 97 : : } 98 : : 99 : 427212 : void InstMatch::resetAll() 100 : : { 101 [ + + ]: 1562740 : for (size_t i = 0, nvals = d_vals.size(); i < nvals; i++) 102 : : { 103 : 1135530 : d_vals[i] = Node::null(); 104 : : } 105 : : // clear information from the evaluator 106 [ + + ]: 427212 : if (d_ieval != nullptr) 107 : : { 108 : 397137 : d_ieval->resetAll(); 109 : : } 110 : 427212 : } 111 : : 112 : 9018950 : Node InstMatch::get(size_t i) const 113 : : { 114 [ - + ][ - + ]: 9018950 : Assert(i < d_vals.size()); [ - - ] 115 : 9018950 : return d_vals[i]; 116 : : } 117 : : 118 : 8049500 : bool InstMatch::set(size_t i, TNode n) 119 : : { 120 [ - + ][ - + ]: 8049500 : Assert(i < d_vals.size()); [ - - ] 121 [ + + ]: 8049500 : if (!d_vals[i].isNull()) 122 : : { 123 : : // if they are equal, we do nothing 124 : 2026160 : return d_qs.areEqual(d_vals[i], n); 125 : : } 126 [ + + ]: 6023340 : if (d_ieval != nullptr) 127 : : { 128 : : // if applicable, check if the instantiation evaluator is ok 129 [ + + ]: 5930410 : if (!d_ieval->push(d_quant[0][i], n)) 130 : : { 131 : 3112430 : return false; 132 : : } 133 : : // The above checks may also have triggered a conflict due to term 134 : : // indexing, we fail in this case as well. 135 [ + + ]: 2817980 : if (d_qs.isInConflict()) 136 : : { 137 : 73 : return false; 138 : : } 139 : : } 140 : : // otherwise, we update the value 141 : 2910840 : d_vals[i] = n; 142 : 2910840 : return true; 143 : : } 144 : : 145 : 2814400 : void InstMatch::reset(size_t i) 146 : : { 147 [ - + ][ - + ]: 2814400 : Assert(!d_vals[i].isNull()); [ - - ] 148 [ + + ]: 2814400 : if (d_ieval != nullptr) 149 : : { 150 : 2729080 : d_ieval->pop(); 151 : : } 152 : 2814400 : d_vals[i] = Node::null(); 153 : 2814400 : } 154 : : 155 : 48989 : const std::vector<Node>& InstMatch::get() const { return d_vals; } 156 : : 157 : : } // namespace quantifiers 158 : : } // namespace theory 159 : : } // namespace cvc5::internal