GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/sets/solver_state.h Lines: 2 2 100.0 %
Date: 2021-05-22 Branches: 3 4 75.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mudathir Mohamed
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
 * Sets state object.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__SETS__THEORY_SOLVER_STATE_H
19
#define CVC5__THEORY__SETS__THEORY_SOLVER_STATE_H
20
21
#include <map>
22
#include <vector>
23
24
#include "theory/sets/skolem_cache.h"
25
#include "theory/theory_state.h"
26
#include "theory/uf/equality_engine.h"
27
28
namespace cvc5 {
29
namespace theory {
30
namespace sets {
31
32
class TheorySetsPrivate;
33
34
/** Sets state
35
 *
36
 * The purpose of this class is to maintain information concerning the current
37
 * set of assertions during a full effort check.
38
 *
39
 * During a full effort check, the solver for theory of sets should call:
40
 *   reset; ( registerEqc | registerTerm )*
41
 * to initialize the information in this class regarding full effort checks.
42
 * Other query calls are then valid for the remainder of the full effort check.
43
 */
44
9460
class SolverState : public TheoryState
45
{
46
  typedef context::CDHashMap<Node, size_t> NodeIntMap;
47
48
 public:
49
  SolverState(context::Context* c,
50
              context::UserContext* u,
51
              Valuation val,
52
              SkolemCache& skc);
53
  //-------------------------------- initialize per check
54
  /** reset, clears the data structures maintained by this class. */
55
  void reset();
56
  /** register equivalence class whose type is tn */
57
  void registerEqc(TypeNode tn, Node r);
58
  /** register term n of type tnn in the equivalence class of r */
59
  void registerTerm(Node r, TypeNode tnn, Node n);
60
  //-------------------------------- end initialize per check
61
  /** add equality to explanation
62
   *
63
   * This adds a = b to exp if a and b are syntactically disequal. The equality
64
   * a = b should hold in the current context.
65
   */
66
  void addEqualityToExp(Node a, Node b, std::vector<Node>& exp) const;
67
  /** Is formula n entailed to have polarity pol in the current context? */
68
  bool isEntailed(Node n, bool pol) const;
69
  /**
70
   * Is the disequality between sets s and t entailed in the current context?
71
   */
72
  bool isSetDisequalityEntailed(Node s, Node t) const;
73
  /**
74
   * Get the equivalence class of the empty set of type tn, or null if it does
75
   * not exist as a term in the current context.
76
   */
77
  Node getEmptySetEqClass(TypeNode tn) const;
78
  /**
79
   * Get the equivalence class of the universe set of type tn, or null if it
80
   * does not exist as a term in the current context.
81
   */
82
  Node getUnivSetEqClass(TypeNode tn) const;
83
  /**
84
   * Get the singleton set in the equivalence class of representative r if it
85
   * exists, or null if none exists.
86
   */
87
  Node getSingletonEqClass(Node r) const;
88
  /** get binary operator term (modulo equality)
89
   *
90
   * This method returns a non-null node n if and only if a term n that is
91
   * congruent to <k>(r1,r2) exists in the current context.
92
   */
93
  Node getBinaryOpTerm(Kind k, Node r1, Node r2) const;
94
  /**
95
   * Returns a term that is congruent to n in the current context.
96
   *
97
   * To ensure that inferences and processing is not redundant,
98
   * this class computes congruence over all terms that exist in the current
99
   * context. If a set of terms f( t1 ), ... f( tn ) are pairwise congruent
100
   * (call this a "congruence class"), it selects one of these terms as a
101
   * representative. All other terms return the representative term from
102
   * its congruence class.
103
   */
104
  Node getCongruent(Node n) const;
105
  /**
106
   * This method returns true if n is not the representative of its congruence
107
   * class.
108
   */
109
  bool isCongruent(Node n) const;
110
111
  /** Get the list of all equivalence classes of set terms */
112
27421
  const std::vector<Node>& getSetsEqClasses() const { return d_set_eqc; }
113
  /** Get the list of all equivalence classes of set terms that have element
114
   * type t */
115
  const std::vector<Node> getSetsEqClasses(const TypeNode& t) const;
116
117
  /**
118
   * Get the list of non-variable sets that exists in the equivalence class
119
   * whose representative is r.
120
   */
121
  const std::vector<Node>& getNonVariableSets(Node r) const;
122
  /**
123
   * Get a variable set in the equivalence class with representative r, or null
124
   * if none exist.
125
   */
126
  Node getVariableSet(Node r) const;
127
  /** Get comprehension sets in equivalence class with representative r */
128
  const std::vector<Node>& getComprehensionSets(Node r) const;
129
  /** Get (positive) members of the set equivalence class r
130
   *
131
   * The members are return as a map, which maps members to their explanation.
132
   * For example, if x = y, (member 5 y), (member 6 x), then getMembers(x)
133
   * returns the map [ 5 -> (member 5 y), 6 -> (member 6 x)].
134
   */
135
  const std::map<Node, Node>& getMembers(Node r) const;
136
  /** Get negative members of the set equivalence class r, similar to above */
137
  const std::map<Node, Node>& getNegativeMembers(Node r) const;
138
  /** Is the (positive) members list of set equivalence class r non-empty? */
139
  bool hasMembers(Node r) const;
140
  /** Get binary operator index
141
   *
142
   * This returns a mapping from binary operator kinds (INTERSECT, SETMINUS,
143
   * UNION) to index of terms of that kind. Each kind k maps to a map whose
144
   * entries are of the form [r1 -> r2 -> t], where t is a term in the current
145
   * context, and t is of the form <k>(t1,t2) where t1=r1 and t2=r2 hold in the
146
   * current context. The term t is the representative of its congruence class.
147
   */
148
  const std::map<Kind, std::map<Node, std::map<Node, Node> > >&
149
  getBinaryOpIndex() const;
150
151
  /** Get binary operator index
152
   *
153
   * This returns the binary operator index of the given kind.
154
   * See getBinaryOpIndex() above.
155
   */
156
  const std::map<Node, std::map<Node, Node> >& getBinaryOpIndex(Kind k);
157
  /** get operator list
158
   *
159
   * This returns a mapping from set kinds to a list of terms of that kind
160
   * that exist in the current context. Each of the terms in the range of this
161
   * map is a representative of its congruence class.
162
   */
163
  const std::map<Kind, std::vector<Node> >& getOperatorList() const;
164
  /** Get the list of all comprehension sets in the current context */
165
  const std::vector<Node>& getComprehensionSets() const;
166
167
  /**
168
   * Is x entailed to be a member of set s in the current context?
169
   */
170
  bool isMember(TNode x, TNode s) const;
171
  /**
172
   * Add member, called when atom is of the form (member x s) where s is in the
173
   * equivalence class of r.
174
   */
175
  void addMember(TNode r, TNode atom);
176
  /**
177
   * Called when equivalence classes t1 and t2 merge. This updates the
178
   * membership lists, adding members of t2 into t1.
179
   *
180
   * If cset is non-null, then this is a singleton or empty set in the
181
   * equivalence class of t1 where moreover t2 has no singleton or empty sets.
182
   * When this is the case, notice that all members of t2 should be made equal
183
   * to the element that cset contains, or we are in conflict if cset is the
184
   * empty set. These conclusions are added to facts.
185
   *
186
   * This method returns false if a (single) conflict was added to facts, and
187
   * true otherwise.
188
   */
189
  bool merge(TNode t1, TNode t2, std::vector<Node>& facts, TNode cset);
190
191
 private:
192
  /** constants */
193
  Node d_true;
194
  Node d_false;
195
  /** the empty vector and map */
196
  std::vector<Node> d_emptyVec;
197
  std::map<Node, Node> d_emptyMap;
198
  /** Reference to skolem cache */
199
  SkolemCache& d_skCache;
200
  /** The list of all equivalence classes of type set in the current context */
201
  std::vector<Node> d_set_eqc;
202
  /** Maps types to the equivalence class containing empty set of that type */
203
  std::map<TypeNode, Node> d_eqc_emptyset;
204
  /** Maps types to the equivalence class containing univ set of that type */
205
  std::map<TypeNode, Node> d_eqc_univset;
206
  /** Maps equivalence classes to a singleton set that exists in it. */
207
  std::map<Node, Node> d_eqc_singleton;
208
  /** Map from terms to the representative of their congruence class */
209
  std::map<Node, Node> d_congruent;
210
  /** Map from equivalence classes to the list of non-variable sets in it */
211
  std::map<Node, std::vector<Node> > d_nvar_sets;
212
  /** Map from equivalence classes to the list of comprehension sets in it */
213
  std::map<Node, std::vector<Node> > d_compSets;
214
  /** Map from equivalence classes to a variable sets in it */
215
  std::map<Node, Node> d_var_set;
216
  /** polarity memberships
217
   *
218
   * d_pol_mems[0] maps equivalence class to their positive membership list
219
   * with explanations (see getMembers), d_pol_mems[1] maps equivalence classes
220
   * to their negative memberships.
221
   */
222
  std::map<Node, std::map<Node, Node> > d_pol_mems[2];
223
  // -------------------------------- term indices
224
  /** Term index for MEMBER
225
   *
226
   * A term index maps equivalence class representatives to the representative
227
   * of their congruence class.
228
   *
229
   * For example, the term index for member may contain an entry
230
   * [ r1 -> r2 -> (member t1 t2) ] where r1 and r2 are representatives of their
231
   * equivalence classes, (member t1 t2) is the representative of its congruence
232
   * class, and r1=t1 and r2=t2 hold in the current context.
233
   */
234
  std::map<Node, std::map<Node, Node> > d_members_index;
235
  /** Term index for SINGLETON */
236
  std::map<Node, Node> d_singleton_index;
237
  /** Indices for the binary kinds INTERSECT, SETMINUS and UNION. */
238
  std::map<Kind, std::map<Node, std::map<Node, Node> > > d_bop_index;
239
  /** A list of comprehension sets */
240
  std::vector<Node> d_allCompSets;
241
  // -------------------------------- end term indices
242
  /** List of operators per kind */
243
  std::map<Kind, std::vector<Node> > d_op_list;
244
  //--------------------------------- SAT-context-dependent member list
245
  /**
246
   * Map from representatives r of set equivalence classes to atoms of the form
247
   * (member x s) where s is in the equivalence class of r.
248
   */
249
  std::map<Node, std::vector<Node> > d_members_data;
250
  /** A (SAT-context-dependent) number of members in the above map */
251
  NodeIntMap d_members;
252
  //--------------------------------- end
253
  /** is set disequality entailed internal
254
   *
255
   * This returns true if disequality between sets a and b is entailed in the
256
   * current context. We use an incomplete test based on equality and membership
257
   * information.
258
   *
259
   * re is the representative of the equivalence class of the empty set
260
   * whose type is the same as a and b.
261
   */
262
  bool isSetDisequalityEntailedInternal(Node a, Node b, Node re) const;
263
  /**
264
   * Get members internal, returns the positive members if i=0, or negative
265
   * members if i=1.
266
   */
267
  const std::map<Node, Node>& getMembersInternal(Node r, unsigned i) const;
268
}; /* class TheorySetsPrivate */
269
270
}  // namespace sets
271
}  // namespace theory
272
}  // namespace cvc5
273
274
#endif /* CVC5__THEORY__SETS__THEORY_SOLVER_STATE_H */