GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arrays/inference_manager.cpp Lines: 49 57 86.0 %
Date: 2021-05-22 Branches: 78 202 38.6 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Gereon Kremer, 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 inference manager.
14
 */
15
16
#include "theory/arrays/inference_manager.h"
17
18
#include "options/smt_options.h"
19
#include "theory/theory.h"
20
#include "theory/theory_state.h"
21
#include "theory/uf/equality_engine.h"
22
23
using namespace cvc5::kind;
24
25
namespace cvc5 {
26
namespace theory {
27
namespace arrays {
28
29
9459
InferenceManager::InferenceManager(Theory& t,
30
                                   TheoryState& state,
31
9459
                                   ProofNodeManager* pnm)
32
    : TheoryInferenceManager(t, state, pnm, "theory::arrays::", false),
33
      d_lemmaPg(pnm ? new EagerProofGenerator(
34
2384
                    pnm, state.getUserContext(), "ArrayLemmaProofGenerator")
35
11843
                    : nullptr)
36
{
37
9459
}
38
39
12613
bool InferenceManager::assertInference(TNode atom,
40
                                       bool polarity,
41
                                       InferenceId id,
42
                                       TNode reason,
43
                                       PfRule pfr)
44
{
45
25226
  Trace("arrays-infer") << "TheoryArrays::assertInference: "
46
25226
                        << (polarity ? Node(atom) : atom.notNode()) << " by "
47
12613
                        << reason << "; " << id << std::endl;
48
12613
  Assert(atom.getKind() == EQUAL);
49
  // if proofs are enabled, we determine which proof rule to add, otherwise
50
  // we simply assert the internal fact
51
12613
  if (isProofEnabled())
52
  {
53
2426
    Node fact = polarity ? Node(atom) : atom.notNode();
54
2426
    std::vector<Node> children;
55
2426
    std::vector<Node> args;
56
    // convert to proof rule application
57
1213
    convert(pfr, fact, reason, children, args);
58
1213
    return assertInternalFact(atom, polarity, id, pfr, children, args);
59
  }
60
11400
  return assertInternalFact(atom, polarity, id, reason);
61
}
62
63
6484
bool InferenceManager::arrayLemma(
64
    Node conc, InferenceId id, Node exp, PfRule pfr, LemmaProperty p)
65
{
66
12968
  Trace("arrays-infer") << "TheoryArrays::arrayLemma: " << conc << " by " << exp
67
6484
                        << "; " << id << std::endl;
68
6484
  NodeManager* nm = NodeManager::currentNM();
69
6484
  if (isProofEnabled())
70
  {
71
894
    std::vector<Node> children;
72
894
    std::vector<Node> args;
73
    // convert to proof rule application
74
447
    convert(pfr, conc, exp, children, args);
75
    // make the trusted lemma based on the eager proof generator and send
76
894
    TrustNode tlem = d_lemmaPg->mkTrustNode(conc, pfr, children, args);
77
447
    return trustedLemma(tlem, id, p);
78
  }
79
  // send lemma without proofs
80
12074
  Node lem = nm->mkNode(IMPLIES, exp, conc);
81
6037
  return lemma(lem, id, p);
82
}
83
84
1660
void InferenceManager::convert(PfRule& id,
85
                               Node conc,
86
                               Node exp,
87
                               std::vector<Node>& children,
88
                               std::vector<Node>& args)
89
{
90
  // note that children must contain something equivalent to exp,
91
  // regardless of the PfRule.
92
1660
  switch (id)
93
  {
94
35
    case PfRule::MACRO_SR_PRED_INTRO:
95
35
      Assert(exp.isConst());
96
35
      args.push_back(conc);
97
35
      break;
98
1152
    case PfRule::ARRAYS_READ_OVER_WRITE:
99
1152
      if (exp.isConst())
100
      {
101
        // Premise can be shown by rewriting, use standard predicate intro rule.
102
        // This is the case where we have 2 constant indices.
103
21
        id = PfRule::MACRO_SR_PRED_INTRO;
104
21
        args.push_back(conc);
105
      }
106
      else
107
      {
108
1131
        children.push_back(exp);
109
1131
        args.push_back(conc[0]);
110
      }
111
1152
      break;
112
    case PfRule::ARRAYS_READ_OVER_WRITE_CONTRA: children.push_back(exp); break;
113
280
    case PfRule::ARRAYS_READ_OVER_WRITE_1:
114
280
      Assert(exp.isConst());
115
280
      args.push_back(conc[0]);
116
280
      break;
117
193
    case PfRule::ARRAYS_EXT: children.push_back(exp); break;
118
    default:
119
      if (id != PfRule::ARRAYS_TRUST)
120
      {
121
        Assert(false) << "Unknown rule " << id << "\n";
122
      }
123
      children.push_back(exp);
124
      args.push_back(conc);
125
      id = PfRule::ARRAYS_TRUST;
126
      break;
127
  }
128
1660
}
129
130
}  // namespace arrays
131
}  // namespace theory
132
28191
}  // namespace cvc5