1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Aina Niemetz |
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 |
|
* Arrays skolem cache. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/arrays/skolem_cache.h" |
17 |
|
|
18 |
|
#include "expr/attribute.h" |
19 |
|
#include "expr/bound_var_manager.h" |
20 |
|
#include "expr/skolem_manager.h" |
21 |
|
#include "expr/type_node.h" |
22 |
|
|
23 |
|
using namespace cvc5::kind; |
24 |
|
|
25 |
|
namespace cvc5 { |
26 |
|
namespace theory { |
27 |
|
namespace arrays { |
28 |
|
|
29 |
|
/** |
30 |
|
* A bound variable corresponding to an index for witnessing the satisfiability |
31 |
|
* of array disequalities. |
32 |
|
*/ |
33 |
|
struct ExtIndexVarAttributeId |
34 |
|
{ |
35 |
|
}; |
36 |
|
typedef expr::Attribute<ExtIndexVarAttributeId, Node> ExtIndexVarAttribute; |
37 |
|
|
38 |
|
/** |
39 |
|
* A bound variable corresponding to the index used in the eqrange expansion. |
40 |
|
*/ |
41 |
|
struct EqRangeVarAttributeId |
42 |
|
{ |
43 |
|
}; |
44 |
|
typedef expr::Attribute<EqRangeVarAttributeId, Node> EqRangeVarAttribute; |
45 |
|
|
46 |
|
SkolemCache::SkolemCache() {} |
47 |
|
|
48 |
583 |
Node SkolemCache::getExtIndexSkolem(Node deq) |
49 |
|
{ |
50 |
583 |
Assert(deq.getKind() == NOT && deq[0].getKind() == EQUAL); |
51 |
1166 |
Node a = deq[0][0]; |
52 |
1166 |
Node b = deq[0][1]; |
53 |
583 |
Assert(a.getType().isArray()); |
54 |
583 |
Assert(b.getType() == a.getType()); |
55 |
|
|
56 |
583 |
NodeManager* nm = NodeManager::currentNM(); |
57 |
|
|
58 |
|
// get the reference index, which notice is deterministic for a, b in the |
59 |
|
// lifetime of the node manager |
60 |
1166 |
Node x = getExtIndexVar(deq); |
61 |
|
|
62 |
|
// make the axiom for x |
63 |
1166 |
Node as = nm->mkNode(SELECT, a, x); |
64 |
1166 |
Node bs = nm->mkNode(SELECT, b, x); |
65 |
1166 |
Node deqIndex = as.eqNode(bs).notNode(); |
66 |
1166 |
Node axiom = nm->mkNode(IMPLIES, deq, deqIndex); |
67 |
|
|
68 |
|
// make the skolem that witnesses the above axiom |
69 |
583 |
SkolemManager* sm = nm->getSkolemManager(); |
70 |
|
return sm->mkSkolem( |
71 |
|
x, |
72 |
|
axiom, |
73 |
|
"array_ext_index", |
74 |
1166 |
"an extensional lemma index variable from the theory of arrays"); |
75 |
|
} |
76 |
|
|
77 |
23 |
Node SkolemCache::getEqRangeVar(TNode eqr) |
78 |
|
{ |
79 |
23 |
Assert(eqr.getKind() == kind::EQ_RANGE); |
80 |
23 |
BoundVarManager* bvm = NodeManager::currentNM()->getBoundVarManager(); |
81 |
23 |
return bvm->mkBoundVar<EqRangeVarAttribute>(eqr, eqr[2].getType()); |
82 |
|
} |
83 |
|
|
84 |
583 |
Node SkolemCache::getExtIndexVar(Node deq) |
85 |
|
{ |
86 |
1166 |
Node a = deq[0][0]; |
87 |
1166 |
TypeNode atn = a.getType(); |
88 |
583 |
Assert(atn.isArray()); |
89 |
583 |
Assert(atn == deq[0][1].getType()); |
90 |
1166 |
TypeNode atnIndex = atn.getArrayIndexType(); |
91 |
583 |
BoundVarManager* bvm = NodeManager::currentNM()->getBoundVarManager(); |
92 |
1166 |
return bvm->mkBoundVar<ExtIndexVarAttribute>(deq, atnIndex); |
93 |
|
} |
94 |
|
|
95 |
|
} // namespace arrays |
96 |
|
} // namespace theory |
97 |
29502 |
} // namespace cvc5 |