summaryrefslogtreecommitdiff
path: root/src/theory/arrays/skolem_cache.cpp
blob: 19ab1aaae18c959160fda11c9878ab862417cc87 (plain)
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
/******************************************************************************
 * 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.
 * ****************************************************************************
 *
 * Arrays skolem cache.
 */

#include "theory/arrays/skolem_cache.h"

#include "expr/attribute.h"
#include "expr/bound_var_manager.h"
#include "expr/skolem_manager.h"
#include "expr/type_node.h"

using namespace cvc5::kind;

namespace cvc5 {
namespace theory {
namespace arrays {

/**
 * A bound variable corresponding to an index for witnessing the satisfiability
 * of array disequalities.
 */
struct ExtIndexVarAttributeId
{
};
typedef expr::Attribute<ExtIndexVarAttributeId, Node> ExtIndexVarAttribute;

SkolemCache::SkolemCache() {}

Node SkolemCache::getExtIndexSkolem(Node deq)
{
  Assert(deq.getKind() == NOT && deq[0].getKind() == EQUAL);
  Node a = deq[0][0];
  Node b = deq[0][1];
  Assert(a.getType().isArray());
  Assert(b.getType() == a.getType());

  NodeManager* nm = NodeManager::currentNM();

  // get the reference index, which notice is deterministic for a, b in the
  // lifetime of the node manager
  Node x = getExtIndexVar(deq);

  // make the axiom for x
  Node as = nm->mkNode(SELECT, a, x);
  Node bs = nm->mkNode(SELECT, b, x);
  Node deqIndex = as.eqNode(bs).notNode();
  Node axiom = nm->mkNode(IMPLIES, deq, deqIndex);

  // make the skolem that witnesses the above axiom
  SkolemManager* sm = nm->getSkolemManager();
  return sm->mkSkolem(
      x,
      axiom,
      "array_ext_index",
      "an extensional lemma index variable from the theory of arrays");
}

Node SkolemCache::getExtIndexVar(Node deq)
{
  Node a = deq[0][0];
  TypeNode atn = a.getType();
  Assert(atn.isArray());
  Assert(atn == deq[0][1].getType());
  TypeNode atnIndex = atn.getArrayIndexType();
  BoundVarManager* bvm = NodeManager::currentNM()->getBoundVarManager();
  return bvm->mkBoundVar<ExtIndexVarAttribute>(deq, atnIndex);
}

}  // namespace arrays
}  // namespace theory
}  // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback