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