GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arrays/skolem_cache.cpp Lines: 23 24 95.8 %
Date: 2021-05-22 Branches: 56 176 31.8 %

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