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 sets term registry object. 11 : : */ 12 : : 13 : : #include "theory/sets/term_registry.h" 14 : : 15 : : #include "expr/emptyset.h" 16 : : #include "expr/skolem_manager.h" 17 : : 18 : : using namespace std; 19 : : using namespace cvc5::internal::kind; 20 : : 21 : : namespace cvc5::internal { 22 : : namespace theory { 23 : : namespace sets { 24 : : 25 : 51035 : TermRegistry::TermRegistry(Env& env, InferenceManager& im, SkolemCache& skc) 26 : : : EnvObj(env), 27 : 51035 : d_im(im), 28 : 51035 : d_skCache(skc), 29 : 51035 : d_proxy(userContext()), 30 : 51035 : d_proxy_to_term(userContext()), 31 : 61838 : d_epg( 32 [ + + ]: 51035 : env.isTheoryProofProducing() 33 : 10803 : ? new EagerProofGenerator(env, nullptr, "sets::TermRegistry::epg") 34 : 102070 : : nullptr) 35 : : { 36 : 51035 : } 37 : : 38 : 42281 : Node TermRegistry::getProxy(Node n) 39 : : { 40 : 42281 : Kind nk = n.getKind(); 41 [ + + ][ + + ]: 42281 : if (nk != Kind::SET_EMPTY && nk != Kind::SET_SINGLETON 42 [ + + ][ + + ]: 17853 : && nk != Kind::SET_INTER && nk != Kind::SET_MINUS && nk != Kind::SET_UNION [ + + ] 43 [ + + ][ + + ]: 6827 : && nk != Kind::SET_UNIVERSE && nk != Kind::SET_MAP) 44 : : { 45 : 5040 : return n; 46 : : } 47 : 37241 : NodeMap::const_iterator it = d_proxy.find(n); 48 [ + + ]: 37241 : if (it != d_proxy.end()) 49 : : { 50 : 30073 : return (*it).second; 51 : : } 52 : 7168 : NodeManager* nm = nodeManager(); 53 : 7168 : Node k = d_skCache.mkTypedSkolemCached( 54 : 14336 : n.getType(), n, SkolemCache::SK_PURIFY, "sp"); 55 : : 56 : 7168 : d_proxy[n] = k; 57 : 7168 : d_proxy_to_term[k] = n; 58 : 7168 : Node eq = k.eqNode(n); 59 : 7168 : sendSimpleLemmaInternal(eq, InferenceId::SETS_PROXY); 60 [ + + ]: 7168 : if (nk == Kind::SET_SINGLETON) 61 : : { 62 : 6776 : Node slem = nm->mkNode(Kind::SET_MEMBER, n[0], k); 63 : 3388 : sendSimpleLemmaInternal(slem, InferenceId::SETS_PROXY_SINGLETON); 64 : 3388 : } 65 : 7168 : return k; 66 : 7168 : } 67 : : 68 : 22133 : Node TermRegistry::getEmptySet(TypeNode tn) 69 : : { 70 : 22133 : std::map<TypeNode, Node>::iterator it = d_emptyset.find(tn); 71 [ + + ]: 22133 : if (it != d_emptyset.end()) 72 : : { 73 : 21956 : return it->second; 74 : : } 75 : 177 : Node n = nodeManager()->mkConst(EmptySet(tn)); 76 : 177 : d_emptyset[tn] = n; 77 : 177 : return n; 78 : 177 : } 79 : : 80 : 4949 : Node TermRegistry::getUnivSet(TypeNode tn) 81 : : { 82 : 4949 : std::map<TypeNode, Node>::iterator it = d_univset.find(tn); 83 [ + + ]: 4949 : if (it != d_univset.end()) 84 : : { 85 : 4709 : return it->second; 86 : : } 87 : 240 : NodeManager* nm = nodeManager(); 88 : 240 : Node n = nm->mkNullaryOperator(tn, Kind::SET_UNIVERSE); 89 : 240 : d_univset[tn] = n; 90 : 240 : return n; 91 : 240 : } 92 : : 93 : 25331 : void TermRegistry::debugPrintSet(Node s, const char* c) const 94 : : { 95 [ + + ]: 25331 : if (s.getNumChildren() == 0) 96 : : { 97 : 16445 : NodeMap::const_iterator it = d_proxy_to_term.find(s); 98 [ + + ]: 16445 : if (it != d_proxy_to_term.end()) 99 : : { 100 : 4135 : debugPrintSet((*it).second, c); 101 : : } 102 : : else 103 : : { 104 [ + - ]: 12310 : Trace(c) << s; 105 : : } 106 : : } 107 : : else 108 : : { 109 [ + - ][ - + ]: 8886 : Trace(c) << "(" << s.getOperator(); [ - - ] 110 [ + + ]: 25572 : for (const Node& sc : s) 111 : : { 112 [ + - ]: 16686 : Trace(c) << " "; 113 : 16686 : debugPrintSet(sc, c); 114 : 16686 : } 115 [ + - ]: 8886 : Trace(c) << ")"; 116 : : } 117 : 25331 : } 118 : : 119 : 10556 : void TermRegistry::sendSimpleLemmaInternal(Node n, InferenceId id) 120 : : { 121 [ + - ]: 10556 : Trace("sets-lemma") << "Sets::Lemma : " << n << " by " << id << std::endl; 122 [ + + ]: 10556 : if (d_epg.get() != nullptr) 123 : : { 124 : : TrustNode teq = 125 : 11619 : d_epg->mkTrustNode(n, ProofRule::MACRO_SR_PRED_INTRO, {}, {n}); 126 : 3873 : d_im.trustedLemma(teq, id); 127 : 3873 : } 128 : : else 129 : : { 130 : 6683 : d_im.lemma(n, id); 131 : : } 132 : 10556 : } 133 : : 134 : : } // namespace sets 135 : : } // namespace theory 136 : : } // namespace cvc5::internal