GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/quantifiers_registry.cpp Lines: 86 95 90.5 %
Date: 2021-09-07 Branches: 98 216 45.4 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Morgan Deters
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 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
 * The quantifiers registry.
14
 */
15
16
#include "theory/quantifiers/quantifiers_registry.h"
17
18
#include "options/quantifiers_options.h"
19
#include "theory/quantifiers/quant_module.h"
20
#include "theory/quantifiers/term_util.h"
21
22
namespace cvc5 {
23
namespace theory {
24
namespace quantifiers {
25
26
9926
QuantifiersRegistry::QuantifiersRegistry()
27
    : d_quantAttr(),
28
9926
      d_quantBoundInf(options::fmfTypeCompletionThresh(),
29
19852
                      options::finiteModelFind())
30
{
31
9926
}
32
33
76357
void QuantifiersRegistry::registerQuantifier(Node q)
34
{
35
76357
  if (d_inst_constants.find(q) != d_inst_constants.end())
36
  {
37
51305
    return;
38
  }
39
25052
  NodeManager* nm = NodeManager::currentNM();
40
50104
  Debug("quantifiers-engine")
41
25052
      << "Instantiation constants for " << q << " : " << std::endl;
42
84224
  for (size_t i = 0, nvars = q[0].getNumChildren(); i < nvars; i++)
43
  {
44
59172
    d_vars[q].push_back(q[0][i]);
45
    // make instantiation constants
46
118344
    Node ic = nm->mkInstConstant(q[0][i].getType());
47
59172
    d_inst_constants_map[ic] = q;
48
59172
    d_inst_constants[q].push_back(ic);
49
59172
    Debug("quantifiers-engine") << "  " << ic << std::endl;
50
    // set the var number attribute
51
    InstVarNumAttribute ivna;
52
59172
    ic.setAttribute(ivna, i);
53
    InstConstantAttribute ica;
54
59172
    ic.setAttribute(ica, q);
55
  }
56
  // compute attributes
57
25052
  d_quantAttr.computeAttributes(q);
58
}
59
60
28464
bool QuantifiersRegistry::reset(Theory::Effort e) { return true; }
61
62
28464
std::string QuantifiersRegistry::identify() const
63
{
64
28464
  return "QuantifiersRegistry";
65
}
66
67
504904
QuantifiersModule* QuantifiersRegistry::getOwner(Node q) const
68
{
69
504904
  std::map<Node, QuantifiersModule*>::const_iterator it = d_owner.find(q);
70
504904
  if (it == d_owner.end())
71
  {
72
451718
    return nullptr;
73
  }
74
53186
  return it->second;
75
}
76
77
2857
void QuantifiersRegistry::setOwner(Node q,
78
                                   QuantifiersModule* m,
79
                                   int32_t priority)
80
{
81
2857
  QuantifiersModule* mo = getOwner(q);
82
2857
  if (mo == m)
83
  {
84
    return;
85
  }
86
2857
  if (mo != nullptr)
87
  {
88
4
    if (priority <= d_owner_priority[q])
89
    {
90
8
      Trace("quant-warn") << "WARNING: setting owner of " << q << " to "
91
8
                          << (m ? m->identify() : "null")
92
8
                          << ", but already has owner " << mo->identify()
93
4
                          << " with higher priority!" << std::endl;
94
4
      return;
95
    }
96
  }
97
2853
  d_owner[q] = m;
98
2853
  d_owner_priority[q] = priority;
99
}
100
101
449393
bool QuantifiersRegistry::hasOwnership(Node q, QuantifiersModule* m) const
102
{
103
449393
  QuantifiersModule* mo = getOwner(q);
104
449393
  return mo == m || mo == nullptr;
105
}
106
107
62771
Node QuantifiersRegistry::getInstantiationConstant(Node q, size_t i) const
108
{
109
  std::map<Node, std::vector<Node> >::const_iterator it =
110
62771
      d_inst_constants.find(q);
111
62771
  if (it != d_inst_constants.end())
112
  {
113
62771
    return it->second[i];
114
  }
115
  return Node::null();
116
}
117
118
26628
size_t QuantifiersRegistry::getNumInstantiationConstants(Node q) const
119
{
120
  std::map<Node, std::vector<Node> >::const_iterator it =
121
26628
      d_inst_constants.find(q);
122
26628
  if (it != d_inst_constants.end())
123
  {
124
26628
    return it->second.size();
125
  }
126
  return 0;
127
}
128
129
161183
Node QuantifiersRegistry::getInstConstantBody(Node q)
130
{
131
161183
  std::map<Node, Node>::const_iterator it = d_inst_const_body.find(q);
132
161183
  if (it == d_inst_const_body.end())
133
  {
134
46784
    Node n = substituteBoundVariablesToInstConstants(q[1], q);
135
23392
    d_inst_const_body[q] = n;
136
23392
    return n;
137
  }
138
137791
  return it->second;
139
}
140
141
32665
Node QuantifiersRegistry::substituteBoundVariablesToInstConstants(Node n,
142
                                                                  Node q)
143
{
144
32665
  registerQuantifier(q);
145
32665
  return n.substitute(d_vars[q].begin(),
146
32665
                      d_vars[q].end(),
147
32665
                      d_inst_constants[q].begin(),
148
130660
                      d_inst_constants[q].end());
149
}
150
151
18634
Node QuantifiersRegistry::substituteInstConstantsToBoundVariables(Node n,
152
                                                                  Node q)
153
{
154
18634
  registerQuantifier(q);
155
18634
  return n.substitute(d_inst_constants[q].begin(),
156
18634
                      d_inst_constants[q].end(),
157
18634
                      d_vars[q].begin(),
158
74536
                      d_vars[q].end());
159
}
160
161
16
Node QuantifiersRegistry::substituteBoundVariables(Node n,
162
                                                   Node q,
163
                                                   std::vector<Node>& terms)
164
{
165
16
  registerQuantifier(q);
166
16
  Assert(d_vars[q].size() == terms.size());
167
  return n.substitute(
168
16
      d_vars[q].begin(), d_vars[q].end(), terms.begin(), terms.end());
169
}
170
171
Node QuantifiersRegistry::substituteInstConstants(Node n,
172
                                                  Node q,
173
                                                  std::vector<Node>& terms)
174
{
175
  registerQuantifier(q);
176
  Assert(d_inst_constants[q].size() == terms.size());
177
  return n.substitute(d_inst_constants[q].begin(),
178
                      d_inst_constants[q].end(),
179
                      terms.begin(),
180
                      terms.end());
181
}
182
183
79866
QuantAttributes& QuantifiersRegistry::getQuantAttributes()
184
{
185
79866
  return d_quantAttr;
186
}
187
188
28700
QuantifiersBoundInference& QuantifiersRegistry::getQuantifiersBoundInference()
189
{
190
28700
  return d_quantBoundInf;
191
}
192
193
34
Node QuantifiersRegistry::getNameForQuant(Node q) const
194
{
195
68
  Node name = d_quantAttr.getQuantName(q);
196
34
  if (!name.isNull())
197
  {
198
10
    return name;
199
  }
200
24
  return q;
201
}
202
203
34
bool QuantifiersRegistry::getNameForQuant(Node q, Node& name, bool req) const
204
{
205
34
  name = getNameForQuant(q);
206
  // if we have a name, or we did not require one
207
34
  return name != q || !req;
208
}
209
210
}  // namespace quantifiers
211
}  // namespace theory
212
29502
}  // namespace cvc5