GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arrays/inference_manager.cpp Lines: 51 61 83.6 %
Date: 2021-11-05 Branches: 80 206 38.8 %

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/builtin/proof_checker.h"
20
#include "theory/theory.h"
21
#include "theory/theory_state.h"
22
#include "theory/uf/equality_engine.h"
23
24
using namespace cvc5::kind;
25
26
namespace cvc5 {
27
namespace theory {
28
namespace arrays {
29
30
15271
InferenceManager::InferenceManager(Env& env, Theory& t, TheoryState& state)
31
    : TheoryInferenceManager(env, t, state, "theory::arrays::", false),
32
15271
      d_lemmaPg(isProofEnabled()
33
5372
                    ? new EagerProofGenerator(env.getProofNodeManager(),
34
5372
                                              userContext(),
35
5372
                                              "ArrayLemmaProofGenerator")
36
41286
                    : nullptr)
37
{
38
15271
}
39
40
15462
bool InferenceManager::assertInference(TNode atom,
41
                                       bool polarity,
42
                                       InferenceId id,
43
                                       TNode reason,
44
                                       PfRule pfr)
45
{
46
30924
  Trace("arrays-infer") << "TheoryArrays::assertInference: "
47
30924
                        << (polarity ? Node(atom) : atom.notNode()) << " by "
48
15462
                        << reason << "; " << id << std::endl;
49
15462
  Assert(atom.getKind() == EQUAL);
50
  // if proofs are enabled, we determine which proof rule to add, otherwise
51
  // we simply assert the internal fact
52
15462
  if (isProofEnabled())
53
  {
54
1902
    Node fact = polarity ? Node(atom) : atom.notNode();
55
1902
    std::vector<Node> children;
56
1902
    std::vector<Node> args;
57
    // convert to proof rule application
58
951
    convert(pfr, fact, reason, children, args);
59
951
    return assertInternalFact(atom, polarity, id, pfr, children, args);
60
  }
61
14511
  return assertInternalFact(atom, polarity, id, reason);
62
}
63
64
5399
bool InferenceManager::arrayLemma(
65
    Node conc, InferenceId id, Node exp, PfRule pfr, LemmaProperty p)
66
{
67
10798
  Trace("arrays-infer") << "TheoryArrays::arrayLemma: " << conc << " by " << exp
68
5399
                        << "; " << id << std::endl;
69
5399
  NodeManager* nm = NodeManager::currentNM();
70
5399
  if (isProofEnabled())
71
  {
72
678
    std::vector<Node> children;
73
678
    std::vector<Node> args;
74
    // convert to proof rule application
75
339
    convert(pfr, conc, exp, children, args);
76
    // make the trusted lemma based on the eager proof generator and send
77
678
    TrustNode tlem = d_lemmaPg->mkTrustNode(conc, pfr, children, args);
78
339
    return trustedLemma(tlem, id, p);
79
  }
80
  // send lemma without proofs
81
10120
  Node lem = nm->mkNode(IMPLIES, exp, conc);
82
5060
  return lemma(lem, id, p);
83
}
84
85
1290
void InferenceManager::convert(PfRule& id,
86
                               Node conc,
87
                               Node exp,
88
                               std::vector<Node>& children,
89
                               std::vector<Node>& args)
90
{
91
  // note that children must contain something equivalent to exp,
92
  // regardless of the PfRule.
93
1290
  switch (id)
94
  {
95
72
    case PfRule::MACRO_SR_PRED_INTRO:
96
72
      Assert(exp.isConst());
97
72
      args.push_back(conc);
98
72
      break;
99
881
    case PfRule::ARRAYS_READ_OVER_WRITE:
100
881
      if (exp.isConst())
101
      {
102
        // Premise can be shown by rewriting, use standard predicate intro rule.
103
        // This is the case where we have 2 constant indices.
104
97
        id = PfRule::MACRO_SR_PRED_INTRO;
105
97
        args.push_back(conc);
106
      }
107
      else
108
      {
109
784
        children.push_back(exp);
110
784
        args.push_back(conc[0]);
111
      }
112
881
      break;
113
    case PfRule::ARRAYS_READ_OVER_WRITE_CONTRA: children.push_back(exp); break;
114
140
    case PfRule::ARRAYS_READ_OVER_WRITE_1:
115
140
      Assert(exp.isConst());
116
140
      args.push_back(conc[0]);
117
140
      break;
118
197
    case PfRule::ARRAYS_EXT: children.push_back(exp); break;
119
    default:
120
      if (id != PfRule::THEORY_INFERENCE)
121
      {
122
        Assert(false) << "Unknown rule " << id << "\n";
123
      }
124
      children.push_back(exp);
125
      args.push_back(conc);
126
      args.push_back(
127
          builtin::BuiltinProofRuleChecker::mkTheoryIdNode(THEORY_ARRAYS));
128
      id = PfRule::THEORY_INFERENCE;
129
      break;
130
  }
131
1290
}
132
133
}  // namespace arrays
134
}  // namespace theory
135
31125
}  // namespace cvc5