GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/bv/bv_subtheory_core.h Lines: 8 8 100.0 %
Date: 2021-05-22 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Liana Hadarean, 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
 * Algebraic solver.
14
 */
15
16
#include "cvc5_private.h"
17
18
#pragma once
19
20
#include <unordered_map>
21
#include <unordered_set>
22
23
#include "context/cdhashset.h"
24
#include "theory/bv/bv_subtheory.h"
25
#include "theory/ext_theory.h"
26
27
namespace cvc5 {
28
namespace theory {
29
namespace bv {
30
31
class Base;
32
33
/** An extended theory callback used by the core solver */
34
9403
class CoreSolverExtTheoryCallback : public ExtTheoryCallback
35
{
36
 public:
37
9403
  CoreSolverExtTheoryCallback() : d_equalityEngine(nullptr) {}
38
  /** Get current substitution based on the underlying equality engine. */
39
  bool getCurrentSubstitution(int effort,
40
                              const std::vector<Node>& vars,
41
                              std::vector<Node>& subs,
42
                              std::map<Node, std::vector<Node> >& exp) override;
43
  /** Get reduction. */
44
  bool getReduction(int effort, Node n, Node& nr, bool& satDep) override;
45
  /** The underlying equality engine */
46
  eq::EqualityEngine* d_equalityEngine;
47
};
48
49
/**
50
 * Bitvector equality solver
51
 */
52
class CoreSolver : public SubtheorySolver {
53
  typedef std::unordered_map<TNode, Node> ModelValue;
54
  typedef std::unordered_map<TNode, bool> TNodeBoolMap;
55
  typedef std::unordered_set<TNode> TNodeSet;
56
57
  struct Statistics {
58
    IntStat d_numCallstoCheck;
59
    Statistics();
60
  };
61
62
  // NotifyClass: handles call-back from congruence closure module
63
9403
  class NotifyClass : public eq::EqualityEngineNotify {
64
    CoreSolver& d_solver;
65
66
  public:
67
9403
    NotifyClass(CoreSolver& solver): d_solver(solver) {}
68
    bool eqNotifyTriggerPredicate(TNode predicate, bool value) override;
69
    bool eqNotifyTriggerTermEquality(TheoryId tag,
70
                                     TNode t1,
71
                                     TNode t2,
72
                                     bool value) override;
73
    void eqNotifyConstantTermMerge(TNode t1, TNode t2) override;
74
190208
    void eqNotifyNewClass(TNode t) override {}
75
1468149
    void eqNotifyMerge(TNode t1, TNode t2) override {}
76
193194
    void eqNotifyDisequal(TNode t1, TNode t2, TNode reason) override {}
77
  };
78
79
80
  /** The notify class for d_equalityEngine */
81
  NotifyClass d_notify;
82
83
  /** Store a propagation to the bv solver */
84
  bool storePropagation(TNode literal);
85
86
  /** Store a conflict from merging two constants */
87
  void conflict(TNode a, TNode b);
88
89
  context::CDO<bool> d_isComplete;
90
  unsigned d_lemmaThreshold;
91
92
  bool d_preregisterCalled;
93
  bool d_checkCalled;
94
95
  /** Pointer to the parent theory solver that owns this */
96
  BVSolverLazy* d_bv;
97
  /** Pointer to the equality engine of the parent */
98
  eq::EqualityEngine* d_equalityEngine;
99
  /** The extended theory callback */
100
  CoreSolverExtTheoryCallback d_extTheoryCb;
101
  /** Extended theory module, for context-dependent simplification. */
102
  std::unique_ptr<ExtTheory> d_extTheory;
103
104
  /** To make sure we keep the explanations */
105
  context::CDHashSet<Node> d_reasons;
106
  ModelValue d_modelValues;
107
  void buildModel();
108
  bool assertFactToEqualityEngine(TNode fact, TNode reason);
109
  bool isCompleteForTerm(TNode term, TNodeBoolMap& seen);
110
  Statistics d_statistics;
111
112
  /** Whether we need a last call effort check */
113
  bool d_needsLastCallCheck;
114
  /** For extended functions */
115
  context::CDHashSet<Node> d_extf_range_infer;
116
  context::CDHashSet<Node> d_extf_collapse_infer;
117
118
  /** do extended function inferences
119
   *
120
   * This method adds lemmas on the output channel of TheoryBV based on
121
   * reasoning about extended functions, such as bv2nat and int2bv. Examples
122
   * of lemmas added by this method include:
123
   *   0 <= ((_ int2bv w) x) < 2^w
124
   *   ((_ int2bv w) (bv2nat x)) = x
125
   *   (bv2nat ((_ int2bv w) x)) == x + k*2^w
126
   * The purpose of these lemmas is to recognize easy conflicts before fully
127
   * reducing extended functions based on their full semantics.
128
   */
129
  bool doExtfInferences(std::vector<Node>& terms);
130
  /** do extended function reductions
131
   *
132
   * This method adds lemmas on the output channel of TheoryBV based on
133
   * reducing all extended function applications that are preregistered to
134
   * this theory and have not already been reduced by context-dependent
135
   * simplification (see theory/ext_theory.h). Examples of lemmas added by
136
   * this method include:
137
   *   (bv2nat x) = (ite ((_ extract w w-1) x) 2^{w-1} 0) + ... +
138
   *                (ite ((_ extract 1 0) x) 1 0)
139
   */
140
  bool doExtfReductions(std::vector<Node>& terms);
141
142
 public:
143
  CoreSolver(context::Context* c, BVSolverLazy* bv);
144
  ~CoreSolver();
145
  bool needsEqualityEngine(EeSetupInfo& esi);
146
  void finishInit();
147
280207
  bool isComplete() override { return d_isComplete; }
148
  void preRegister(TNode node) override;
149
  bool check(Theory::Effort e) override;
150
  void explain(TNode literal, std::vector<TNode>& assumptions) override;
151
  bool collectModelValues(TheoryModel* m,
152
                          const std::set<Node>& termSet) override;
153
  Node getModelValue(TNode var) override;
154
  EqualityStatus getEqualityStatus(TNode a, TNode b) override;
155
  bool hasTerm(TNode node) const;
156
  void addTermToEqualityEngine(TNode node);
157
  /** check extended functions at the given effort */
158
  void checkExtf(Theory::Effort e);
159
  bool needsCheckLastEffort() const;
160
};
161
162
}
163
}
164
}  // namespace cvc5