GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/quantifiers_registry.cpp Lines: 74 95 77.9 %
Date: 2021-05-22 Branches: 84 228 36.8 %

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
9460
QuantifiersRegistry::QuantifiersRegistry()
27
    : d_quantAttr(),
28
18920
      d_quantBoundInf(options::fmfTypeCompletionThresh(),
29
18920
                      options::finiteModelFind())
30
{
31
9460
}
32
33
57418
void QuantifiersRegistry::registerQuantifier(Node q)
34
{
35
57418
  if (d_inst_constants.find(q) != d_inst_constants.end())
36
  {
37
32355
    return;
38
  }
39
25063
  NodeManager* nm = NodeManager::currentNM();
40
50126
  Debug("quantifiers-engine")
41
25063
      << "Instantiation constants for " << q << " : " << std::endl;
42
84055
  for (size_t i = 0, nvars = q[0].getNumChildren(); i < nvars; i++)
43
  {
44
58992
    d_vars[q].push_back(q[0][i]);
45
    // make instantiation constants
46
117984
    Node ic = nm->mkInstConstant(q[0][i].getType());
47
58992
    d_inst_constants_map[ic] = q;
48
58992
    d_inst_constants[q].push_back(ic);
49
58992
    Debug("quantifiers-engine") << "  " << ic << std::endl;
50
    // set the var number attribute
51
    InstVarNumAttribute ivna;
52
58992
    ic.setAttribute(ivna, i);
53
    InstConstantAttribute ica;
54
58992
    ic.setAttribute(ica, q);
55
  }
56
  // compute attributes
57
25063
  d_quantAttr.computeAttributes(q);
58
}
59
60
24825
bool QuantifiersRegistry::reset(Theory::Effort e) { return true; }
61
62
24825
std::string QuantifiersRegistry::identify() const
63
{
64
24825
  return "QuantifiersRegistry";
65
}
66
67
502770
QuantifiersModule* QuantifiersRegistry::getOwner(Node q) const
68
{
69
502770
  std::map<Node, QuantifiersModule*>::const_iterator it = d_owner.find(q);
70
502770
  if (it == d_owner.end())
71
  {
72
449678
    return nullptr;
73
  }
74
53092
  return it->second;
75
}
76
77
2865
void QuantifiersRegistry::setOwner(Node q,
78
                                   QuantifiersModule* m,
79
                                   int32_t priority)
80
{
81
2865
  QuantifiersModule* mo = getOwner(q);
82
2865
  if (mo == m)
83
  {
84
    return;
85
  }
86
2865
  if (mo != nullptr)
87
  {
88
    if (priority <= d_owner_priority[q])
89
    {
90
      Trace("quant-warn") << "WARNING: setting owner of " << q << " to "
91
                          << (m ? m->identify() : "null")
92
                          << ", but already has owner " << mo->identify()
93
                          << " with higher priority!" << std::endl;
94
      return;
95
    }
96
  }
97
2865
  d_owner[q] = m;
98
2865
  d_owner_priority[q] = priority;
99
}
100
101
445972
bool QuantifiersRegistry::hasOwnership(Node q, QuantifiersModule* m) const
102
{
103
445972
  QuantifiersModule* mo = getOwner(q);
104
445972
  return mo == m || mo == nullptr;
105
}
106
107
62523
Node QuantifiersRegistry::getInstantiationConstant(Node q, size_t i) const
108
{
109
  std::map<Node, std::vector<Node> >::const_iterator it =
110
62523
      d_inst_constants.find(q);
111
62523
  if (it != d_inst_constants.end())
112
  {
113
62523
    return it->second[i];
114
  }
115
  return Node::null();
116
}
117
118
26636
size_t QuantifiersRegistry::getNumInstantiationConstants(Node q) const
119
{
120
  std::map<Node, std::vector<Node> >::const_iterator it =
121
26636
      d_inst_constants.find(q);
122
26636
  if (it != d_inst_constants.end())
123
  {
124
26636
    return it->second.size();
125
  }
126
  return 0;
127
}
128
129
169504
Node QuantifiersRegistry::getInstConstantBody(Node q)
130
{
131
169504
  std::map<Node, Node>::const_iterator it = d_inst_const_body.find(q);
132
169504
  if (it == d_inst_const_body.end())
133
  {
134
46534
    Node n = substituteBoundVariablesToInstConstants(q[1], q);
135
23267
    d_inst_const_body[q] = n;
136
23267
    return n;
137
  }
138
146237
  return it->second;
139
}
140
141
32349
Node QuantifiersRegistry::substituteBoundVariablesToInstConstants(Node n,
142
                                                                  Node q)
143
{
144
32349
  registerQuantifier(q);
145
32349
  return n.substitute(d_vars[q].begin(),
146
32349
                      d_vars[q].end(),
147
32349
                      d_inst_constants[q].begin(),
148
129396
                      d_inst_constants[q].end());
149
}
150
151
Node QuantifiersRegistry::substituteInstConstantsToBoundVariables(Node n,
152
                                                                  Node q)
153
{
154
  registerQuantifier(q);
155
  return n.substitute(d_inst_constants[q].begin(),
156
                      d_inst_constants[q].end(),
157
                      d_vars[q].begin(),
158
                      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
69582
QuantAttributes& QuantifiersRegistry::getQuantAttributes()
184
{
185
69582
  return d_quantAttr;
186
}
187
188
26582
QuantifiersBoundInference& QuantifiersRegistry::getQuantifiersBoundInference()
189
{
190
26582
  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
37654
}  // namespace cvc5