GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/uf/theory_uf.h Lines: 18 19 94.7 %
Date: 2021-05-22 Branches: 30 62 48.4 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Morgan Deters, 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
 * This is the interface to TheoryUF implementations
14
 *
15
 * All implementations of TheoryUF should inherit from this class.
16
 */
17
18
#include "cvc5_private.h"
19
20
#ifndef CVC5__THEORY__UF__THEORY_UF_H
21
#define CVC5__THEORY__UF__THEORY_UF_H
22
23
#include "expr/node.h"
24
#include "expr/node_trie.h"
25
#include "theory/theory.h"
26
#include "theory/theory_eq_notify.h"
27
#include "theory/theory_state.h"
28
#include "theory/uf/proof_checker.h"
29
#include "theory/uf/symmetry_breaker.h"
30
#include "theory/uf/theory_uf_rewriter.h"
31
32
namespace cvc5 {
33
namespace theory {
34
namespace uf {
35
36
class CardinalityExtension;
37
class HoExtension;
38
39
class TheoryUF : public Theory {
40
 public:
41
9460
  class NotifyClass : public TheoryEqNotifyClass
42
  {
43
   public:
44
9460
    NotifyClass(TheoryInferenceManager& im, TheoryUF& uf)
45
9460
        : TheoryEqNotifyClass(im), d_uf(uf)
46
    {
47
9460
    }
48
49
248750
    void eqNotifyNewClass(TNode t) override
50
    {
51
497500
      Debug("uf-notify") << "NotifyClass::eqNotifyNewClass(" << t << ")"
52
248750
                         << std::endl;
53
248750
      d_uf.eqNotifyNewClass(t);
54
248750
    }
55
56
4527887
    void eqNotifyMerge(TNode t1, TNode t2) override
57
    {
58
9055774
      Debug("uf-notify") << "NotifyClass::eqNotifyMerge(" << t1 << ", " << t2
59
4527887
                         << ")" << std::endl;
60
4527887
      d_uf.eqNotifyMerge(t1, t2);
61
4527887
    }
62
63
827127
    void eqNotifyDisequal(TNode t1, TNode t2, TNode reason) override
64
    {
65
827127
      Debug("uf-notify") << "NotifyClass::eqNotifyDisequal(" << t1 << ", " << t2 << ", " << reason << ")" << std::endl;
66
827127
      d_uf.eqNotifyDisequal(t1, t2, reason);
67
827127
    }
68
69
   private:
70
    /** Reference to the parent theory */
71
    TheoryUF& d_uf;
72
  };/* class TheoryUF::NotifyClass */
73
74
private:
75
  /** The associated cardinality extension (or nullptr if it does not exist) */
76
  std::unique_ptr<CardinalityExtension> d_thss;
77
  /** the higher-order solver extension (or nullptr if it does not exist) */
78
  std::unique_ptr<HoExtension> d_ho;
79
80
  /** node for true */
81
  Node d_true;
82
83
  /** All the function terms that the theory has seen */
84
  context::CDList<TNode> d_functionsTerms;
85
86
  /** Symmetry analyzer */
87
  SymmetryBreaker d_symb;
88
89
  /** called when a new equivalance class is created */
90
  void eqNotifyNewClass(TNode t);
91
92
  /** called when two equivalance classes have merged */
93
  void eqNotifyMerge(TNode t1, TNode t2);
94
95
  /** called when two equivalence classes are made disequal */
96
  void eqNotifyDisequal(TNode t1, TNode t2, TNode reason);
97
98
 public:
99
100
  /** Constructs a new instance of TheoryUF w.r.t. the provided context.*/
101
  TheoryUF(context::Context* c,
102
           context::UserContext* u,
103
           OutputChannel& out,
104
           Valuation valuation,
105
           const LogicInfo& logicInfo,
106
           ProofNodeManager* pnm = nullptr,
107
           std::string instanceName = "");
108
109
  ~TheoryUF();
110
111
  //--------------------------------- initialization
112
  /** get the official theory rewriter of this theory */
113
  TheoryRewriter* getTheoryRewriter() override;
114
  /** get the proof checker of this theory */
115
  ProofRuleChecker* getProofChecker() override;
116
  /**
117
   * Returns true if we need an equality engine. If so, we initialize the
118
   * information regarding how it should be setup. For details, see the
119
   * documentation in Theory::needsEqualityEngine.
120
   */
121
  bool needsEqualityEngine(EeSetupInfo& esi) override;
122
  /** finish initialization */
123
  void finishInit() override;
124
  //--------------------------------- end initialization
125
126
  //--------------------------------- standard check
127
  /** Do we need a check call at last call effort? */
128
  bool needsCheckLastEffort() override;
129
  /** Post-check, called after the fact queue of the theory is processed. */
130
  void postCheck(Effort level) override;
131
  /** Pre-notify fact, return true if processed. */
132
  bool preNotifyFact(TNode atom,
133
                     bool pol,
134
                     TNode fact,
135
                     bool isPrereg,
136
                     bool isInternal) override;
137
  /** Notify fact */
138
  void notifyFact(TNode atom, bool pol, TNode fact, bool isInternal) override;
139
  //--------------------------------- end standard check
140
141
  /** Collect model values in m based on the relevant terms given by termSet */
142
  bool collectModelValues(TheoryModel* m,
143
                          const std::set<Node>& termSet) override;
144
145
  TrustNode ppRewrite(TNode node, std::vector<SkolemLemma>& lems) override;
146
  void preRegisterTerm(TNode term) override;
147
  TrustNode explain(TNode n) override;
148
149
  void ppStaticLearn(TNode in, NodeBuilder& learned) override;
150
  void presolve() override;
151
152
  void computeCareGraph() override;
153
154
  EqualityStatus getEqualityStatus(TNode a, TNode b) override;
155
156
  std::string identify() const override { return "THEORY_UF"; }
157
 private:
158
  /** Explain why this literal is true by building an explanation */
159
  void explain(TNode literal, Node& exp);
160
161
  bool areCareDisequal(TNode x, TNode y);
162
  void addCarePairs(const TNodeTrie* t1,
163
                    const TNodeTrie* t2,
164
                    unsigned arity,
165
                    unsigned depth);
166
  /**
167
   * Is t a higher order type? A higher-order type is a function type having
168
   * an argument type that is also a function type. This is used for checking
169
   * logic exceptions.
170
   */
171
  bool isHigherOrderType(TypeNode tn);
172
  TheoryUfRewriter d_rewriter;
173
  /** Proof rule checker */
174
  UfProofRuleChecker d_checker;
175
  /** A (default) theory state object */
176
  TheoryState d_state;
177
  /** A (default) inference manager */
178
  TheoryInferenceManager d_im;
179
  /** The notify class */
180
  NotifyClass d_notify;
181
  /** Cache for isHigherOrderType */
182
  std::map<TypeNode, bool> d_isHoType;
183
};/* class TheoryUF */
184
185
}  // namespace uf
186
}  // namespace theory
187
}  // namespace cvc5
188
189
#endif /* CVC5__THEORY__UF__THEORY_UF_H */