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 |
|
SkolemCache::SkolemCache() {} |
39 |
|
|
40 |
702 |
Node SkolemCache::getExtIndexSkolem(Node deq) |
41 |
|
{ |
42 |
702 |
Assert(deq.getKind() == NOT && deq[0].getKind() == EQUAL); |
43 |
1404 |
Node a = deq[0][0]; |
44 |
1404 |
Node b = deq[0][1]; |
45 |
702 |
Assert(a.getType().isArray()); |
46 |
702 |
Assert(b.getType() == a.getType()); |
47 |
|
|
48 |
702 |
NodeManager* nm = NodeManager::currentNM(); |
49 |
|
|
50 |
|
// get the reference index, which notice is deterministic for a, b in the |
51 |
|
// lifetime of the node manager |
52 |
1404 |
Node x = getExtIndexVar(deq); |
53 |
|
|
54 |
|
// make the axiom for x |
55 |
1404 |
Node as = nm->mkNode(SELECT, a, x); |
56 |
1404 |
Node bs = nm->mkNode(SELECT, b, x); |
57 |
1404 |
Node deqIndex = as.eqNode(bs).notNode(); |
58 |
1404 |
Node axiom = nm->mkNode(IMPLIES, deq, deqIndex); |
59 |
|
|
60 |
|
// make the skolem that witnesses the above axiom |
61 |
702 |
SkolemManager* sm = nm->getSkolemManager(); |
62 |
|
return sm->mkSkolem( |
63 |
|
x, |
64 |
|
axiom, |
65 |
|
"array_ext_index", |
66 |
1404 |
"an extensional lemma index variable from the theory of arrays"); |
67 |
|
} |
68 |
|
|
69 |
702 |
Node SkolemCache::getExtIndexVar(Node deq) |
70 |
|
{ |
71 |
1404 |
Node a = deq[0][0]; |
72 |
1404 |
TypeNode atn = a.getType(); |
73 |
702 |
Assert(atn.isArray()); |
74 |
702 |
Assert(atn == deq[0][1].getType()); |
75 |
1404 |
TypeNode atnIndex = atn.getArrayIndexType(); |
76 |
702 |
BoundVarManager* bvm = NodeManager::currentNM()->getBoundVarManager(); |
77 |
1404 |
return bvm->mkBoundVar<ExtIndexVarAttribute>(deq, atnIndex); |
78 |
|
} |
79 |
|
|
80 |
|
} // namespace arrays |
81 |
|
} // namespace theory |
82 |
27735 |
} // namespace cvc5 |