GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/ext/ext_state.cpp Lines: 46 46 100.0 %
Date: 2021-11-07 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
9696
ExtState::ExtState(InferenceManager& im, NlModel& model, Env& env)
34
9696
    : d_im(im), d_model(model), d_env(env)
35
{
36
9696
  d_false = NodeManager::currentNM()->mkConst(false);
37
9696
  d_true = NodeManager::currentNM()->mkConst(true);
38
9696
  d_zero = NodeManager::currentNM()->mkConst(Rational(0));
39
9696
  d_one = NodeManager::currentNM()->mkConst(Rational(1));
40
9696
  d_neg_one = NodeManager::currentNM()->mkConst(Rational(-1));
41
9696
  if (d_env.isTheoryProofProducing())
42
  {
43
14043
    d_proof.reset(new CDProofSet<CDProof>(
44
9362
        d_env.getProofNodeManager(), d_env.getUserContext(), "nl-ext"));
45
  }
46
9696
}
47
48
4364
void ExtState::init(const std::vector<Node>& xts)
49
{
50
4364
  d_ms_vars.clear();
51
4364
  d_ms.clear();
52
4364
  d_mterms.clear();
53
4364
  d_tplane_refine.clear();
54
55
4364
  Trace("nl-ext-mv") << "Extended terms : " << std::endl;
56
  // for computing congruence
57
8728
  std::map<Kind, ArgTrie> argTrie;
58
38804
  for (unsigned i = 0, xsize = xts.size(); i < xsize; i++)
59
  {
60
68880
    Node a = xts[i];
61
34440
    d_model.computeConcreteModelValue(a);
62
34440
    d_model.computeAbstractModelValue(a);
63
34440
    d_model.printModelValue("nl-ext-mv", a);
64
34440
    Kind ak = a.getKind();
65
34440
    if (ak == Kind::NONLINEAR_MULT)
66
    {
67
25862
      d_ms.push_back(a);
68
69
      // context-independent registration
70
25862
      d_mdb.registerMonomial(a);
71
72
25862
      const std::vector<Node>& varList = d_mdb.getVariableList(a);
73
75598
      for (const Node& v : varList)
74
      {
75
49736
        if (std::find(d_ms_vars.begin(), d_ms_vars.end(), v) == d_ms_vars.end())
76
        {
77
24671
          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
4364
  d_mdb.registerMonomial(d_one);
86
87
  // register variables
88
4364
  Trace("nl-ext-mv") << "Variables in monomials : " << std::endl;
89
29035
  for (unsigned i = 0; i < d_ms_vars.size(); i++)
90
  {
91
49342
    Node v = d_ms_vars[i];
92
24671
    d_mdb.registerMonomial(v);
93
24671
    d_model.computeConcreteModelValue(v);
94
24671
    d_model.computeAbstractModelValue(v);
95
24671
    d_model.printModelValue("nl-ext-mv", v);
96
  }
97
98
4364
  Trace("nl-ext") << "We have " << d_ms.size() << " monomials." << std::endl;
99
4364
}
100
101
8999
bool ExtState::isProofEnabled() const { return d_proof.get() != nullptr; }
102
103
1157
CDProof* ExtState::getProof()
104
{
105
1157
  Assert(isProofEnabled());
106
1157
  return d_proof->allocateProof(d_env.getUserContext());
107
}
108
109
}  // namespace nl
110
}  // namespace arith
111
}  // namespace theory
112
31137
}  // namespace cvc5