GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arrays/inference_manager.cpp Lines: 49 57 86.0 %
Date: 2021-08-20 Branches: 78 200 39.0 %

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
9856
InferenceManager::InferenceManager(Theory& t,
30
                                   TheoryState& state,
31
9856
                                   ProofNodeManager* pnm)
32
    : TheoryInferenceManager(t, state, pnm, "theory::arrays::", false),
33
      d_lemmaPg(pnm ? new EagerProofGenerator(
34
2492
                    pnm, state.getUserContext(), "ArrayLemmaProofGenerator")
35
12348
                    : nullptr)
36
{
37
9856
}
38
39
15506
bool InferenceManager::assertInference(TNode atom,
40
                                       bool polarity,
41
                                       InferenceId id,
42
                                       TNode reason,
43
                                       PfRule pfr)
44
{
45
31012
  Trace("arrays-infer") << "TheoryArrays::assertInference: "
46
31012
                        << (polarity ? Node(atom) : atom.notNode()) << " by "
47
15506
                        << reason << "; " << id << std::endl;
48
15506
  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
15506
  if (isProofEnabled())
52
  {
53
1796
    Node fact = polarity ? Node(atom) : atom.notNode();
54
1796
    std::vector<Node> children;
55
1796
    std::vector<Node> args;
56
    // convert to proof rule application
57
898
    convert(pfr, fact, reason, children, args);
58
898
    return assertInternalFact(atom, polarity, id, pfr, children, args);
59
  }
60
14608
  return assertInternalFact(atom, polarity, id, reason);
61
}
62
63
5905
bool InferenceManager::arrayLemma(
64
    Node conc, InferenceId id, Node exp, PfRule pfr, LemmaProperty p)
65
{
66
11810
  Trace("arrays-infer") << "TheoryArrays::arrayLemma: " << conc << " by " << exp
67
5905
                        << "; " << id << std::endl;
68
5905
  NodeManager* nm = NodeManager::currentNM();
69
5905
  if (isProofEnabled())
70
  {
71
662
    std::vector<Node> children;
72
662
    std::vector<Node> args;
73
    // convert to proof rule application
74
331
    convert(pfr, conc, exp, children, args);
75
    // make the trusted lemma based on the eager proof generator and send
76
662
    TrustNode tlem = d_lemmaPg->mkTrustNode(conc, pfr, children, args);
77
331
    return trustedLemma(tlem, id, p);
78
  }
79
  // send lemma without proofs
80
11148
  Node lem = nm->mkNode(IMPLIES, exp, conc);
81
5574
  return lemma(lem, id, p);
82
}
83
84
1229
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
1229
  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
818
    case PfRule::ARRAYS_READ_OVER_WRITE:
99
818
      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
767
        children.push_back(exp);
109
767
        args.push_back(conc[0]);
110
      }
111
818
      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
172
    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
1229
}
129
130
}  // namespace arrays
131
}  // namespace theory
132
29358
}  // namespace cvc5