GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/callbacks.cpp Lines: 103 117 88.0 %
Date: 2021-11-06 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
15272
SetupLiteralCallBack::SetupLiteralCallBack(TheoryArithPrivate& ta)
30
15272
  : d_arith(ta)
31
15272
{}
32
22333
void SetupLiteralCallBack::operator()(TNode lit){
33
44666
  TNode atom = (lit.getKind() == kind::NOT) ? lit[0] : lit;
34
22333
  if(!d_arith.isSetup(atom)){
35
22333
    d_arith.setupAtom(atom);
36
  }
37
22333
}
38
39
15272
DeltaComputeCallback::DeltaComputeCallback(const TheoryArithPrivate& ta)
40
15272
  : d_ta(ta)
41
15272
{}
42
57394
Rational DeltaComputeCallback::operator()() const{
43
57394
  return d_ta.deltaValueForTotalOrder();
44
}
45
46
61088
TempVarMalloc::TempVarMalloc(TheoryArithPrivate& ta)
47
61088
: d_ta(ta)
48
61088
{}
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
15272
BasicVarModelUpdateCallBack::BasicVarModelUpdateCallBack(TheoryArithPrivate& ta)
60
15272
  : d_ta(ta)
61
15272
{}
62
8255193
void BasicVarModelUpdateCallBack::operator()(ArithVar x){
63
8255193
  d_ta.signal(x);
64
8255193
}
65
66
76360
RaiseConflict::RaiseConflict(TheoryArithPrivate& ta)
67
76360
  : d_ta(ta)
68
76360
{}
69
70
83080
void RaiseConflict::raiseConflict(ConstraintCP c, InferenceId id) const{
71
83080
  Assert(c->inConflict());
72
83080
  d_ta.raiseConflict(c, id);
73
83080
}
74
75
61088
FarkasConflictBuilder::FarkasConflictBuilder(bool produceProofs)
76
    : d_farkas(),
77
      d_constraints(),
78
      d_consequent(NullConstraint),
79
      d_consequentSet(false),
80
61088
      d_produceProofs(produceProofs)
81
{
82
61088
  reset();
83
61088
}
84
85
935556
bool FarkasConflictBuilder::underConstruction() const{
86
935556
  return d_consequent != NullConstraint;
87
}
88
89
83080
bool FarkasConflictBuilder::consequentIsSet() const{
90
83080
  return d_consequentSet;
91
}
92
93
144168
void FarkasConflictBuilder::reset(){
94
144168
  d_consequent = NullConstraint;
95
144168
  d_constraints.clear();
96
144168
  d_consequentSet = false;
97
144168
  if (d_produceProofs)
98
  {
99
58104
    d_farkas.clear();
100
  }
101
144168
  Assert(!underConstruction());
102
144168
}
103
104
/* Adds a constraint to the constraint under construction. */
105
1083399
void FarkasConflictBuilder::addConstraint(ConstraintCP c, const Rational& fc){
106
1083399
  Assert(
107
      !d_produceProofs
108
      || (!underConstruction() && d_constraints.empty() && d_farkas.empty())
109
      || (underConstruction() && d_constraints.size() + 1 == d_farkas.size()));
110
1083399
  Assert(d_produceProofs || d_farkas.empty());
111
1083399
  Assert(c->isTrue());
112
113
1083399
  if(d_consequent == NullConstraint){
114
83080
    d_consequent = c;
115
  } else {
116
1000319
    d_constraints.push_back(c);
117
  }
118
1083399
  if (d_produceProofs)
119
  {
120
216456
    d_farkas.push_back(fc);
121
  }
122
1083399
  Assert(!d_produceProofs || d_constraints.size() + 1 == d_farkas.size());
123
1083399
  Assert(d_produceProofs || d_farkas.empty());
124
1083399
}
125
126
1083399
void FarkasConflictBuilder::addConstraint(ConstraintCP c, const Rational& fc, const Rational& mult){
127
1083399
  Assert(!mult.isZero());
128
1083399
  if (d_produceProofs && !mult.isOne())
129
  {
130
200770
    Rational prod = fc * mult;
131
100385
    addConstraint(c, prod);
132
  }
133
  else
134
  {
135
983014
    addConstraint(c, fc);
136
  }
137
1083399
}
138
139
83080
void FarkasConflictBuilder::makeLastConsequent(){
140
83080
  Assert(!d_consequentSet);
141
83080
  Assert(underConstruction());
142
143
83080
  if(d_constraints.empty()){
144
    // no-op
145
3779
    d_consequentSet = true;
146
  } else {
147
79301
    Assert(d_consequent != NullConstraint);
148
79301
    ConstraintCP last = d_constraints.back();
149
79301
    d_constraints.back() = d_consequent;
150
79301
    d_consequent = last;
151
79301
    if (d_produceProofs)
152
    {
153
25376
      std::swap(d_farkas.front(), d_farkas.back());
154
    }
155
79301
    d_consequentSet = true;
156
  }
157
158
83080
  Assert(!d_consequent->negationHasProof());
159
83080
  Assert(d_consequentSet);
160
83080
}
161
162
/* Turns the vector under construction into a conflict */
163
83080
ConstraintCP FarkasConflictBuilder::commitConflict(){
164
83080
  Assert(underConstruction());
165
83080
  Assert(!d_constraints.empty());
166
83080
  Assert(
167
      !d_produceProofs
168
      || (!underConstruction() && d_constraints.empty() && d_farkas.empty())
169
      || (underConstruction() && d_constraints.size() + 1 == d_farkas.size()));
170
83080
  Assert(d_produceProofs || d_farkas.empty());
171
83080
  Assert(d_consequentSet);
172
173
83080
  ConstraintP not_c = d_consequent->getNegation();
174
83080
  RationalVectorCP coeffs = d_produceProofs ? &d_farkas : nullptr;
175
83080
  not_c->impliedByFarkas(d_constraints, coeffs, true );
176
177
83080
  reset();
178
83080
  Assert(!underConstruction());
179
83080
  Assert(not_c->inConflict());
180
83080
  Assert(!d_consequentSet);
181
83080
  return not_c;
182
}
183
184
15272
RaiseEqualityEngineConflict::RaiseEqualityEngineConflict(TheoryArithPrivate& ta)
185
15272
  : d_ta(ta)
186
15272
{}
187
188
/* If you are not an equality engine, don't use this! */
189
2279
void RaiseEqualityEngineConflict::raiseEEConflict(
190
    Node n, std::shared_ptr<ProofNode> pf) const
191
{
192
2279
  d_ta.raiseBlackBoxConflict(n, pf);
193
2279
}
194
195
15272
BoundCountingLookup::BoundCountingLookup(TheoryArithPrivate& ta)
196
15272
: d_ta(ta)
197
15272
{}
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
31137
}  // namespace cvc5