GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/callbacks.cpp Lines: 103 117 88.0 %
Date: 2021-09-29 Branches: 100 436 22.9 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Tim King, Haniel Barbosa, Mathias Preiner
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
 * [[ Add one-line brief description here ]]
14
 *
15
 * [[ Add lengthier description here ]]
16
 * \todo document this file
17
 */
18
19
#include "theory/arith/callbacks.h"
20
21
#include "expr/skolem_manager.h"
22
#include "proof/proof_node.h"
23
#include "theory/arith/theory_arith_private.h"
24
25
namespace cvc5 {
26
namespace theory {
27
namespace arith {
28
29
6271
SetupLiteralCallBack::SetupLiteralCallBack(TheoryArithPrivate& ta)
30
6271
  : d_arith(ta)
31
6271
{}
32
11882
void SetupLiteralCallBack::operator()(TNode lit){
33
23764
  TNode atom = (lit.getKind() == kind::NOT) ? lit[0] : lit;
34
11882
  if(!d_arith.isSetup(atom)){
35
11882
    d_arith.setupAtom(atom);
36
  }
37
11882
}
38
39
6271
DeltaComputeCallback::DeltaComputeCallback(const TheoryArithPrivate& ta)
40
6271
  : d_ta(ta)
41
6271
{}
42
19773
Rational DeltaComputeCallback::operator()() const{
43
19773
  return d_ta.deltaValueForTotalOrder();
44
}
45
46
25084
TempVarMalloc::TempVarMalloc(TheoryArithPrivate& ta)
47
25084
: d_ta(ta)
48
25084
{}
49
ArithVar TempVarMalloc::request(){
50
  NodeManager* nm = NodeManager::currentNM();
51
  SkolemManager* sm = nm->getSkolemManager();
52
  Node skolem = sm->mkDummySkolem("tmpVar", nm->realType());
53
  return d_ta.requestArithVar(skolem, false, true);
54
}
55
void TempVarMalloc::release(ArithVar v){
56
  d_ta.releaseArithVar(v);
57
}
58
59
6271
BasicVarModelUpdateCallBack::BasicVarModelUpdateCallBack(TheoryArithPrivate& ta)
60
6271
  : d_ta(ta)
61
6271
{}
62
3405583
void BasicVarModelUpdateCallBack::operator()(ArithVar x){
63
3405583
  d_ta.signal(x);
64
3405583
}
65
66
31355
RaiseConflict::RaiseConflict(TheoryArithPrivate& ta)
67
31355
  : d_ta(ta)
68
31355
{}
69
70
41940
void RaiseConflict::raiseConflict(ConstraintCP c, InferenceId id) const{
71
41940
  Assert(c->inConflict());
72
41940
  d_ta.raiseConflict(c, id);
73
41940
}
74
75
25084
FarkasConflictBuilder::FarkasConflictBuilder(bool produceProofs)
76
    : d_farkas(),
77
      d_constraints(),
78
      d_consequent(NullConstraint),
79
      d_consequentSet(false),
80
25084
      d_produceProofs(produceProofs)
81
{
82
25084
  reset();
83
25084
}
84
85
241519
bool FarkasConflictBuilder::underConstruction() const{
86
241519
  return d_consequent != NullConstraint;
87
}
88
89
41940
bool FarkasConflictBuilder::consequentIsSet() const{
90
41940
  return d_consequentSet;
91
}
92
93
67024
void FarkasConflictBuilder::reset(){
94
67024
  d_consequent = NullConstraint;
95
67024
  d_constraints.clear();
96
67024
  d_consequentSet = false;
97
67024
  if (d_produceProofs)
98
  {
99
953
    d_farkas.clear();
100
  }
101
67024
  Assert(!underConstruction());
102
67024
}
103
104
/* Adds a constraint to the constraint under construction. */
105
750994
void FarkasConflictBuilder::addConstraint(ConstraintCP c, const Rational& fc){
106
750994
  Assert(
107
      !d_produceProofs
108
      || (!underConstruction() && d_constraints.empty() && d_farkas.empty())
109
      || (underConstruction() && d_constraints.size() + 1 == d_farkas.size()));
110
750994
  Assert(d_produceProofs || d_farkas.empty());
111
750994
  Assert(c->isTrue());
112
113
750994
  if(d_consequent == NullConstraint){
114
41940
    d_consequent = c;
115
  } else {
116
709054
    d_constraints.push_back(c);
117
  }
118
750994
  if (d_produceProofs)
119
  {
120
3177
    d_farkas.push_back(fc);
121
  }
122
750994
  Assert(!d_produceProofs || d_constraints.size() + 1 == d_farkas.size());
123
750994
  Assert(d_produceProofs || d_farkas.empty());
124
750994
}
125
126
750994
void FarkasConflictBuilder::addConstraint(ConstraintCP c, const Rational& fc, const Rational& mult){
127
750994
  Assert(!mult.isZero());
128
750994
  if (d_produceProofs && !mult.isOne())
129
  {
130
2992
    Rational prod = fc * mult;
131
1496
    addConstraint(c, prod);
132
  }
133
  else
134
  {
135
749498
    addConstraint(c, fc);
136
  }
137
750994
}
138
139
41940
void FarkasConflictBuilder::makeLastConsequent(){
140
41940
  Assert(!d_consequentSet);
141
41940
  Assert(underConstruction());
142
143
41940
  if(d_constraints.empty()){
144
    // no-op
145
1826
    d_consequentSet = true;
146
  } else {
147
40114
    Assert(d_consequent != NullConstraint);
148
40114
    ConstraintCP last = d_constraints.back();
149
40114
    d_constraints.back() = d_consequent;
150
40114
    d_consequent = last;
151
40114
    if (d_produceProofs)
152
    {
153
366
      std::swap(d_farkas.front(), d_farkas.back());
154
    }
155
40114
    d_consequentSet = true;
156
  }
157
158
41940
  Assert(!d_consequent->negationHasProof());
159
41940
  Assert(d_consequentSet);
160
41940
}
161
162
/* Turns the vector under construction into a conflict */
163
41940
ConstraintCP FarkasConflictBuilder::commitConflict(){
164
41940
  Assert(underConstruction());
165
41940
  Assert(!d_constraints.empty());
166
41940
  Assert(
167
      !d_produceProofs
168
      || (!underConstruction() && d_constraints.empty() && d_farkas.empty())
169
      || (underConstruction() && d_constraints.size() + 1 == d_farkas.size()));
170
41940
  Assert(d_produceProofs || d_farkas.empty());
171
41940
  Assert(d_consequentSet);
172
173
41940
  ConstraintP not_c = d_consequent->getNegation();
174
41940
  RationalVectorCP coeffs = d_produceProofs ? &d_farkas : nullptr;
175
41940
  not_c->impliedByFarkas(d_constraints, coeffs, true );
176
177
41940
  reset();
178
41940
  Assert(!underConstruction());
179
41940
  Assert(not_c->inConflict());
180
41940
  Assert(!d_consequentSet);
181
41940
  return not_c;
182
}
183
184
6271
RaiseEqualityEngineConflict::RaiseEqualityEngineConflict(TheoryArithPrivate& ta)
185
6271
  : d_ta(ta)
186
6271
{}
187
188
/* If you are not an equality engine, don't use this! */
189
1103
void RaiseEqualityEngineConflict::raiseEEConflict(
190
    Node n, std::shared_ptr<ProofNode> pf) const
191
{
192
1103
  d_ta.raiseBlackBoxConflict(n, pf);
193
1103
}
194
195
6271
BoundCountingLookup::BoundCountingLookup(TheoryArithPrivate& ta)
196
6271
: d_ta(ta)
197
6271
{}
198
199
const BoundsInfo& BoundCountingLookup::boundsInfo(ArithVar basic) const{
200
  return d_ta.boundsInfo(basic);
201
}
202
203
BoundCounts BoundCountingLookup::atBounds(ArithVar basic) const{
204
  return boundsInfo(basic).atBounds();
205
}
206
BoundCounts BoundCountingLookup::hasBounds(ArithVar basic) const {
207
  return boundsInfo(basic).hasBounds();
208
}
209
210
}  // namespace arith
211
}  // namespace theory
212
22746
}  // namespace cvc5