GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arrays/inference_manager.cpp Lines: 49 57 86.0 %
Date: 2021-08-06 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
9853
InferenceManager::InferenceManager(Theory& t,
30
                                   TheoryState& state,
31
9853
                                   ProofNodeManager* pnm)
32
    : TheoryInferenceManager(t, state, pnm, "theory::arrays::", false),
33
      d_lemmaPg(pnm ? new EagerProofGenerator(
34
2490
                    pnm, state.getUserContext(), "ArrayLemmaProofGenerator")
35
12343
                    : nullptr)
36
{
37
9853
}
38
39
15534
bool InferenceManager::assertInference(TNode atom,
40
                                       bool polarity,
41
                                       InferenceId id,
42
                                       TNode reason,
43
                                       PfRule pfr)
44
{
45
31068
  Trace("arrays-infer") << "TheoryArrays::assertInference: "
46
31068
                        << (polarity ? Node(atom) : atom.notNode()) << " by "
47
15534
                        << reason << "; " << id << std::endl;
48
15534
  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
15534
  if (isProofEnabled())
52
  {
53
1830
    Node fact = polarity ? Node(atom) : atom.notNode();
54
1830
    std::vector<Node> children;
55
1830
    std::vector<Node> args;
56
    // convert to proof rule application
57
915
    convert(pfr, fact, reason, children, args);
58
915
    return assertInternalFact(atom, polarity, id, pfr, children, args);
59
  }
60
14619
  return assertInternalFact(atom, polarity, id, reason);
61
}
62
63
5935
bool InferenceManager::arrayLemma(
64
    Node conc, InferenceId id, Node exp, PfRule pfr, LemmaProperty p)
65
{
66
11870
  Trace("arrays-infer") << "TheoryArrays::arrayLemma: " << conc << " by " << exp
67
5935
                        << "; " << id << std::endl;
68
5935
  NodeManager* nm = NodeManager::currentNM();
69
5935
  if (isProofEnabled())
70
  {
71
686
    std::vector<Node> children;
72
686
    std::vector<Node> args;
73
    // convert to proof rule application
74
343
    convert(pfr, conc, exp, children, args);
75
    // make the trusted lemma based on the eager proof generator and send
76
686
    TrustNode tlem = d_lemmaPg->mkTrustNode(conc, pfr, children, args);
77
343
    return trustedLemma(tlem, id, p);
78
  }
79
  // send lemma without proofs
80
11184
  Node lem = nm->mkNode(IMPLIES, exp, conc);
81
5592
  return lemma(lem, id, p);
82
}
83
84
1258
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
1258
  switch (id)
93
  {
94
119
    case PfRule::MACRO_SR_PRED_INTRO:
95
119
      Assert(exp.isConst());
96
119
      args.push_back(conc);
97
119
      break;
98
829
    case PfRule::ARRAYS_READ_OVER_WRITE:
99
829
      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
51
        id = PfRule::MACRO_SR_PRED_INTRO;
104
51
        args.push_back(conc);
105
      }
106
      else
107
      {
108
778
        children.push_back(exp);
109
778
        args.push_back(conc[0]);
110
      }
111
829
      break;
112
    case PfRule::ARRAYS_READ_OVER_WRITE_CONTRA: children.push_back(exp); break;
113
120
    case PfRule::ARRAYS_READ_OVER_WRITE_1:
114
120
      Assert(exp.isConst());
115
120
      args.push_back(conc[0]);
116
120
      break;
117
190
    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
1258
}
129
130
}  // namespace arrays
131
}  // namespace theory
132
29322
}  // namespace cvc5