GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/equality_solver.cpp Lines: 40 57 70.2 %
Date: 2021-09-18 Branches: 46 138 33.3 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds
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
 * Arithmetic equality solver
14
 */
15
16
#include "theory/arith/equality_solver.h"
17
18
#include "theory/arith/inference_manager.h"
19
20
using namespace cvc5::kind;
21
22
namespace cvc5 {
23
namespace theory {
24
namespace arith {
25
26
39
EqualitySolver::EqualitySolver(Env& env,
27
                               ArithState& astate,
28
39
                               InferenceManager& aim)
29
    : EnvObj(env),
30
      d_astate(astate),
31
      d_aim(aim),
32
      d_notify(*this),
33
      d_ee(nullptr),
34
39
      d_propLits(context())
35
{
36
39
}
37
38
39
bool EqualitySolver::needsEqualityEngine(EeSetupInfo& esi)
39
{
40
39
  esi.d_notify = &d_notify;
41
39
  esi.d_name = "arith::ee";
42
39
  return true;
43
}
44
45
39
void EqualitySolver::finishInit()
46
{
47
39
  d_ee = d_astate.getEqualityEngine();
48
  // add the function kinds
49
39
  d_ee->addFunctionKind(kind::NONLINEAR_MULT);
50
39
  d_ee->addFunctionKind(kind::EXPONENTIAL);
51
39
  d_ee->addFunctionKind(kind::SINE);
52
39
  d_ee->addFunctionKind(kind::IAND);
53
39
  d_ee->addFunctionKind(kind::POW2);
54
39
}
55
56
2543
bool EqualitySolver::preNotifyFact(
57
    TNode atom, bool pol, TNode fact, bool isPrereg, bool isInternal)
58
{
59
2543
  if (atom.getKind() != EQUAL)
60
  {
61
    // finished processing, since not beneficial to add non-equality facts
62
1059
    return true;
63
  }
64
2968
  Trace("arith-eq-solver") << "EqualitySolver::preNotifyFact: " << fact
65
1484
                           << std::endl;
66
  // we will process
67
1484
  return false;
68
}
69
70
27
TrustNode EqualitySolver::explain(TNode lit)
71
{
72
27
  Trace("arith-eq-solver-debug") << "explain " << lit << "?" << std::endl;
73
  // check if we propagated it?
74
27
  if (d_propLits.find(lit) == d_propLits.end())
75
  {
76
27
    Trace("arith-eq-solver-debug") << "...did not propagate" << std::endl;
77
27
    return TrustNode::null();
78
  }
79
  Trace("arith-eq-solver-debug")
80
      << "...explain via inference manager" << std::endl;
81
  // if we did, explain with the arithmetic inference manager
82
  return d_aim.explainLit(lit);
83
}
84
186
bool EqualitySolver::propagateLit(Node lit)
85
{
86
  // if we've already propagated, ignore
87
186
  if (d_aim.hasPropagated(lit))
88
  {
89
28
    return true;
90
  }
91
  // notice this is only used when ee-mode=distributed
92
  // remember that this was a literal we propagated
93
158
  Trace("arith-eq-solver-debug") << "propagate lit " << lit << std::endl;
94
158
  d_propLits.insert(lit);
95
158
  return d_aim.propagateLit(lit);
96
}
97
void EqualitySolver::conflictEqConstantMerge(TNode a, TNode b)
98
{
99
  d_aim.conflictEqConstantMerge(a, b);
100
}
101
102
bool EqualitySolver::EqualitySolverNotify::eqNotifyTriggerPredicate(
103
    TNode predicate, bool value)
104
{
105
  Trace("arith-eq-solver") << "...propagate (predicate) " << predicate << " -> "
106
                           << value << std::endl;
107
  if (value)
108
  {
109
    return d_es.propagateLit(predicate);
110
  }
111
  return d_es.propagateLit(predicate.notNode());
112
}
113
114
186
bool EqualitySolver::EqualitySolverNotify::eqNotifyTriggerTermEquality(
115
    TheoryId tag, TNode t1, TNode t2, bool value)
116
{
117
372
  Trace("arith-eq-solver") << "...propagate (term eq) " << t1.eqNode(t2)
118
186
                           << " -> " << value << std::endl;
119
186
  if (value)
120
  {
121
132
    return d_es.propagateLit(t1.eqNode(t2));
122
  }
123
54
  return d_es.propagateLit(t1.eqNode(t2).notNode());
124
}
125
126
void EqualitySolver::EqualitySolverNotify::eqNotifyConstantTermMerge(TNode t1,
127
                                                                     TNode t2)
128
{
129
  Trace("arith-eq-solver") << "...conflict merge " << t1 << " " << t2
130
                           << std::endl;
131
  d_es.conflictEqConstantMerge(t1, t2);
132
}
133
134
}  // namespace arith
135
}  // namespace theory
136
29574
}  // namespace cvc5