GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/ext/ext_state.cpp Lines: 46 46 100.0 %
Date: 2021-05-22 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 "expr/proof.h"
22
#include "theory/arith/inference_manager.h"
23
#include "theory/arith/nl/ext/monomial.h"
24
#include "theory/arith/nl/nl_model.h"
25
#include "theory/arith/nl/nl_lemma_utils.h"
26
27
namespace cvc5 {
28
namespace theory {
29
namespace arith {
30
namespace nl {
31
32
4914
ExtState::ExtState(InferenceManager& im,
33
                   NlModel& model,
34
                   ProofNodeManager* pnm,
35
4914
                   context::UserContext* c)
36
4914
    : d_im(im), d_model(model), d_pnm(pnm), d_ctx(c)
37
{
38
4914
  d_false = NodeManager::currentNM()->mkConst(false);
39
4914
  d_true = NodeManager::currentNM()->mkConst(true);
40
4914
  d_zero = NodeManager::currentNM()->mkConst(Rational(0));
41
4914
  d_one = NodeManager::currentNM()->mkConst(Rational(1));
42
4914
  d_neg_one = NodeManager::currentNM()->mkConst(Rational(-1));
43
4914
  if (d_pnm != nullptr)
44
  {
45
543
    d_proof.reset(new CDProofSet<CDProof>(d_pnm, d_ctx, "nl-ext"));
46
  }
47
4914
}
48
49
2829
void ExtState::init(const std::vector<Node>& xts)
50
{
51
2829
  d_ms_vars.clear();
52
2829
  d_ms.clear();
53
2829
  d_mterms.clear();
54
2829
  d_tplane_refine.clear();
55
56
2829
  Trace("nl-ext-mv") << "Extended terms : " << std::endl;
57
  // for computing congruence
58
5658
  std::map<Kind, ArgTrie> argTrie;
59
24354
  for (unsigned i = 0, xsize = xts.size(); i < xsize; i++)
60
  {
61
43050
    Node a = xts[i];
62
21525
    d_model.computeConcreteModelValue(a);
63
21525
    d_model.computeAbstractModelValue(a);
64
21525
    d_model.printModelValue("nl-ext-mv", a);
65
21525
    Kind ak = a.getKind();
66
21525
    if (ak == Kind::NONLINEAR_MULT)
67
    {
68
14887
      d_ms.push_back(a);
69
70
      // context-independent registration
71
14887
      d_mdb.registerMonomial(a);
72
73
14887
      const std::vector<Node>& varList = d_mdb.getVariableList(a);
74
43641
      for (const Node& v : varList)
75
      {
76
28754
        if (std::find(d_ms_vars.begin(), d_ms_vars.end(), v) == d_ms_vars.end())
77
        {
78
13381
          d_ms_vars.push_back(v);
79
        }
80
      }
81
      // mark processed if has a "one" factor (will look at reduced monomial)?
82
    }
83
  }
84
85
  // register constants
86
2829
  d_mdb.registerMonomial(d_one);
87
88
  // register variables
89
2829
  Trace("nl-ext-mv") << "Variables in monomials : " << std::endl;
90
16210
  for (unsigned i = 0; i < d_ms_vars.size(); i++)
91
  {
92
26762
    Node v = d_ms_vars[i];
93
13381
    d_mdb.registerMonomial(v);
94
13381
    d_model.computeConcreteModelValue(v);
95
13381
    d_model.computeAbstractModelValue(v);
96
13381
    d_model.printModelValue("nl-ext-mv", v);
97
  }
98
99
2829
  Trace("nl-ext") << "We have " << d_ms.size() << " monomials." << std::endl;
100
2829
}
101
102
4856
bool ExtState::isProofEnabled() const { return d_proof.get() != nullptr; }
103
104
836
CDProof* ExtState::getProof()
105
{
106
836
  Assert(isProofEnabled());
107
836
  return d_proof->allocateProof(d_ctx);
108
}
109
110
}  // namespace nl
111
}  // namespace arith
112
}  // namespace theory
113
28191
}  // namespace cvc5