GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/ext/ext_state.cpp Lines: 46 46 100.0 %
Date: 2021-09-16 Branches: 86 172 50.0 %

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
5203
ExtState::ExtState(InferenceManager& im, NlModel& model, Env& env)
34
5203
    : d_im(im), d_model(model), d_env(env)
35
{
36
5203
  d_false = NodeManager::currentNM()->mkConst(false);
37
5203
  d_true = NodeManager::currentNM()->mkConst(true);
38
5203
  d_zero = NodeManager::currentNM()->mkConst(Rational(0));
39
5203
  d_one = NodeManager::currentNM()->mkConst(Rational(1));
40
5203
  d_neg_one = NodeManager::currentNM()->mkConst(Rational(-1));
41
5203
  if (d_env.isTheoryProofProducing())
42
  {
43
1779
    d_proof.reset(new CDProofSet<CDProof>(
44
1186
        d_env.getProofNodeManager(), d_env.getUserContext(), "nl-ext"));
45
  }
46
5203
}
47
48
3990
void ExtState::init(const std::vector<Node>& xts)
49
{
50
3990
  d_ms_vars.clear();
51
3990
  d_ms.clear();
52
3990
  d_mterms.clear();
53
3990
  d_tplane_refine.clear();
54
55
3990
  Trace("nl-ext-mv") << "Extended terms : " << std::endl;
56
  // for computing congruence
57
7980
  std::map<Kind, ArgTrie> argTrie;
58
35044
  for (unsigned i = 0, xsize = xts.size(); i < xsize; i++)
59
  {
60
62108
    Node a = xts[i];
61
31054
    d_model.computeConcreteModelValue(a);
62
31054
    d_model.computeAbstractModelValue(a);
63
31054
    d_model.printModelValue("nl-ext-mv", a);
64
31054
    Kind ak = a.getKind();
65
31054
    if (ak == Kind::NONLINEAR_MULT)
66
    {
67
22456
      d_ms.push_back(a);
68
69
      // context-independent registration
70
22456
      d_mdb.registerMonomial(a);
71
72
22456
      const std::vector<Node>& varList = d_mdb.getVariableList(a);
73
65927
      for (const Node& v : varList)
74
      {
75
43471
        if (std::find(d_ms_vars.begin(), d_ms_vars.end(), v) == d_ms_vars.end())
76
        {
77
22772
          d_ms_vars.push_back(v);
78
        }
79
      }
80
      // mark processed if has a "one" factor (will look at reduced monomial)?
81
    }
82
  }
83
84
  // register constants
85
3990
  d_mdb.registerMonomial(d_one);
86
87
  // register variables
88
3990
  Trace("nl-ext-mv") << "Variables in monomials : " << std::endl;
89
26762
  for (unsigned i = 0; i < d_ms_vars.size(); i++)
90
  {
91
45544
    Node v = d_ms_vars[i];
92
22772
    d_mdb.registerMonomial(v);
93
22772
    d_model.computeConcreteModelValue(v);
94
22772
    d_model.computeAbstractModelValue(v);
95
22772
    d_model.printModelValue("nl-ext-mv", v);
96
  }
97
98
3990
  Trace("nl-ext") << "We have " << d_ms.size() << " monomials." << std::endl;
99
3990
}
100
101
7890
bool ExtState::isProofEnabled() const { return d_proof.get() != nullptr; }
102
103
1049
CDProof* ExtState::getProof()
104
{
105
1049
  Assert(isProofEnabled());
106
1049
  return d_proof->allocateProof(d_env.getUserContext());
107
}
108
109
}  // namespace nl
110
}  // namespace arith
111
}  // namespace theory
112
29577
}  // namespace cvc5