1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/******************************************************************************
* Top contributors (to current version):
* Andrew Reynolds, Aina Niemetz
*
* This file is part of the cvc5 project.
*
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
* in the top-level source directory and their institutional affiliations.
* All rights reserved. See the file COPYING in the top-level source
* directory for licensing information.
* ****************************************************************************
*
* Implementation of quantifiers bound inference.
*/
#include "theory/quantifiers/quant_bound_inference.h"
#include "theory/quantifiers/fmf/bounded_integers.h"
#include "theory/rewriter.h"
using namespace cvc5::kind;
namespace cvc5 {
namespace theory {
namespace quantifiers {
QuantifiersBoundInference::QuantifiersBoundInference(unsigned cardMax,
bool isFmf)
: d_cardMax(cardMax), d_isFmf(isFmf), d_bint(nullptr)
{
}
void QuantifiersBoundInference::finishInit(BoundedIntegers* b) { d_bint = b; }
bool QuantifiersBoundInference::mayComplete(TypeNode tn)
{
std::unordered_map<TypeNode, bool, TypeNodeHashFunction>::iterator it =
d_may_complete.find(tn);
if (it == d_may_complete.end())
{
// cache
bool mc = mayComplete(tn, d_cardMax);
d_may_complete[tn] = mc;
return mc;
}
return it->second;
}
bool QuantifiersBoundInference::mayComplete(TypeNode tn, unsigned maxCard)
{
bool mc = false;
if (tn.isClosedEnumerable() && tn.isInterpretedFinite())
{
Cardinality c = tn.getCardinality();
if (!c.isLargeFinite())
{
NodeManager* nm = NodeManager::currentNM();
Node card = nm->mkConst(Rational(c.getFiniteCardinality()));
// check if less than fixed upper bound
Node oth = nm->mkConst(Rational(maxCard));
Node eq = nm->mkNode(LEQ, card, oth);
eq = Rewriter::rewrite(eq);
mc = eq.isConst() && eq.getConst<bool>();
}
}
return mc;
}
bool QuantifiersBoundInference::isFiniteBound(Node q, Node v)
{
if (d_bint && d_bint->isBound(q, v))
{
return true;
}
TypeNode tn = v.getType();
if (tn.isSort() && d_isFmf)
{
return true;
}
else if (mayComplete(tn))
{
return true;
}
return false;
}
BoundVarType QuantifiersBoundInference::getBoundVarType(Node q, Node v)
{
if (d_bint)
{
return d_bint->getBoundVarType(q, v);
}
return isFiniteBound(q, v) ? BOUND_FINITE : BOUND_NONE;
}
void QuantifiersBoundInference::getBoundVarIndices(
Node q, std::vector<unsigned>& indices) const
{
Assert(indices.empty());
// we take the bounded variables first
if (d_bint)
{
d_bint->getBoundVarIndices(q, indices);
}
// then get the remaining ones
for (size_t i = 0, nvars = q[0].getNumChildren(); i < nvars; i++)
{
if (std::find(indices.begin(), indices.end(), i) == indices.end())
{
indices.push_back(i);
}
}
}
bool QuantifiersBoundInference::getBoundElements(
RepSetIterator* rsi,
bool initial,
Node q,
Node v,
std::vector<Node>& elements) const
{
if (d_bint)
{
return d_bint->getBoundElements(rsi, initial, q, v, elements);
}
return false;
}
} // namespace quantifiers
} // namespace theory
} // namespace cvc5
|