GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/ext/ext_state.cpp Lines: 46 46 100.0 %
Date: 2021-08-06 Branches: 82 166 49.4 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Gereon Kremer, Tim King
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
 * Common data shared by multiple checks.
14
 */
15
16
#include "theory/arith/nl/ext/ext_state.h"
17
18
#include <vector>
19
20
#include "expr/node.h"
21
#include "proof/proof.h"
22
#include "theory/arith/inference_manager.h"
23
#include "theory/arith/nl/ext/monomial.h"
24
#include "theory/arith/nl/nl_lemma_utils.h"
25
#include "theory/arith/nl/nl_model.h"
26
#include "util/rational.h"
27
28
namespace cvc5 {
29
namespace theory {
30
namespace arith {
31
namespace nl {
32
33
5145
ExtState::ExtState(InferenceManager& im,
34
                   NlModel& model,
35
                   ProofNodeManager* pnm,
36
5145
                   context::UserContext* c)
37
5145
    : d_im(im), d_model(model), d_pnm(pnm), d_ctx(c)
38
{
39
5145
  d_false = NodeManager::currentNM()->mkConst(false);
40
5145
  d_true = NodeManager::currentNM()->mkConst(true);
41
5145
  d_zero = NodeManager::currentNM()->mkConst(Rational(0));
42
5145
  d_one = NodeManager::currentNM()->mkConst(Rational(1));
43
5145
  d_neg_one = NodeManager::currentNM()->mkConst(Rational(-1));
44
5145
  if (d_pnm != nullptr)
45
  {
46
588
    d_proof.reset(new CDProofSet<CDProof>(d_pnm, d_ctx, "nl-ext"));
47
  }
48
5145
}
49
50
2803
void ExtState::init(const std::vector<Node>& xts)
51
{
52
2803
  d_ms_vars.clear();
53
2803
  d_ms.clear();
54
2803
  d_mterms.clear();
55
2803
  d_tplane_refine.clear();
56
57
2803
  Trace("nl-ext-mv") << "Extended terms : " << std::endl;
58
  // for computing congruence
59
5606
  std::map<Kind, ArgTrie> argTrie;
60
23041
  for (unsigned i = 0, xsize = xts.size(); i < xsize; i++)
61
  {
62
40476
    Node a = xts[i];
63
20238
    d_model.computeConcreteModelValue(a);
64
20238
    d_model.computeAbstractModelValue(a);
65
20238
    d_model.printModelValue("nl-ext-mv", a);
66
20238
    Kind ak = a.getKind();
67
20238
    if (ak == Kind::NONLINEAR_MULT)
68
    {
69
13504
      d_ms.push_back(a);
70
71
      // context-independent registration
72
13504
      d_mdb.registerMonomial(a);
73
74
13504
      const std::vector<Node>& varList = d_mdb.getVariableList(a);
75
39927
      for (const Node& v : varList)
76
      {
77
26423
        if (std::find(d_ms_vars.begin(), d_ms_vars.end(), v) == d_ms_vars.end())
78
        {
79
12425
          d_ms_vars.push_back(v);
80
        }
81
      }
82
      // mark processed if has a "one" factor (will look at reduced monomial)?
83
    }
84
  }
85
86
  // register constants
87
2803
  d_mdb.registerMonomial(d_one);
88
89
  // register variables
90
2803
  Trace("nl-ext-mv") << "Variables in monomials : " << std::endl;
91
15228
  for (unsigned i = 0; i < d_ms_vars.size(); i++)
92
  {
93
24850
    Node v = d_ms_vars[i];
94
12425
    d_mdb.registerMonomial(v);
95
12425
    d_model.computeConcreteModelValue(v);
96
12425
    d_model.computeAbstractModelValue(v);
97
12425
    d_model.printModelValue("nl-ext-mv", v);
98
  }
99
100
2803
  Trace("nl-ext") << "We have " << d_ms.size() << " monomials." << std::endl;
101
2803
}
102
103
4568
bool ExtState::isProofEnabled() const { return d_proof.get() != nullptr; }
104
105
796
CDProof* ExtState::getProof()
106
{
107
796
  Assert(isProofEnabled());
108
796
  return d_proof->allocateProof(d_ctx);
109
}
110
111
}  // namespace nl
112
}  // namespace arith
113
}  // namespace theory
114
29322
}  // namespace cvc5