GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/sets/theory_sets_private.h Lines: 2 3 66.7 %
Date: 2021-09-17 Branches: 0 2 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Kshitij Bansal, 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 theory implementation.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__SETS__THEORY_SETS_PRIVATE_H
19
#define CVC5__THEORY__SETS__THEORY_SETS_PRIVATE_H
20
21
#include "context/cdhashset.h"
22
#include "context/cdqueue.h"
23
#include "expr/node_trie.h"
24
#include "smt/env_obj.h"
25
#include "theory/sets/cardinality_extension.h"
26
#include "theory/sets/inference_manager.h"
27
#include "theory/sets/solver_state.h"
28
#include "theory/sets/term_registry.h"
29
#include "theory/sets/theory_sets_rels.h"
30
#include "theory/sets/theory_sets_rewriter.h"
31
#include "theory/theory.h"
32
#include "theory/uf/equality_engine.h"
33
34
namespace cvc5 {
35
namespace theory {
36
namespace sets {
37
38
/** Internal classes, forward declared here */
39
class TheorySets;
40
41
class TheorySetsPrivate : protected EnvObj
42
{
43
  typedef context::CDHashMap<Node, bool> NodeBoolMap;
44
  typedef context::CDHashSet<Node> NodeSet;
45
46
 public:
47
  void eqNotifyNewClass(TNode t);
48
  void eqNotifyMerge(TNode t1, TNode t2);
49
  void eqNotifyDisequal(TNode t1, TNode t2, TNode reason);
50
51
 private:
52
  /** Are a and b trigger terms in the equality engine that may be disequal? */
53
  bool areCareDisequal(Node a, Node b);
54
  /**
55
   * Invoke the decision procedure for this theory, which is run at
56
   * full effort. This will either send a lemma or conflict on the output
57
   * channel of this class, or otherwise the current set of constraints is
58
   * satisfiable w.r.t. the theory of sets.
59
   */
60
  void fullEffortCheck();
61
  /**
62
   * Reset the information for a full effort check.
63
   */
64
  void fullEffortReset();
65
  /**
66
   * This implements an inference schema based on the "downwards closure" of
67
   * set membership. This roughly corresponds to the rules UNION DOWN I and II,
68
   * INTER DOWN I and II from Bansal et al IJCAR 2016, as well as rules for set
69
   * difference.
70
   */
71
  void checkDownwardsClosure();
72
  /**
73
   * This implements an inference schema based on the "upwards closure" of
74
   * set membership. This roughly corresponds to the rules UNION UP, INTER
75
   * UP I and II from Bansal et al IJCAR 2016, as well as rules for set
76
   * difference.
77
   */
78
  void checkUpwardsClosure();
79
  /**
80
   * This implements a strategy for splitting for set disequalities which
81
   * roughly corresponds the SET DISEQUALITY rule from Bansal et al IJCAR 2016.
82
   */
83
  void checkDisequalities();
84
  /**
85
   * Check comprehensions. This adds reduction lemmas for all set comprehensions
86
   * in the current context.
87
   */
88
  void checkReduceComprehensions();
89
90
  void addCarePairs(TNodeTrie* t1,
91
                    TNodeTrie* t2,
92
                    unsigned arity,
93
                    unsigned depth,
94
                    unsigned& n_pairs);
95
96
  Node d_true;
97
  Node d_false;
98
  Node d_zero;
99
  NodeBoolMap d_deq;
100
  /**
101
   * The set of terms that we have reduced via a lemma in the current user
102
   * context.
103
   */
104
  NodeSet d_termProcessed;
105
106
  //propagation
107
  class EqcInfo
108
  {
109
  public:
110
    EqcInfo( context::Context* c );
111
4891
    ~EqcInfo(){}
112
    // singleton or emptyset equal to this eqc
113
    context::CDO< Node > d_singleton;
114
  };
115
  /** information necessary for equivalence classes */
116
  std::map< Node, EqcInfo* > d_eqc_info;
117
  /** get or make eqc info */
118
  EqcInfo* getOrMakeEqcInfo( TNode n, bool doMake = false );
119
120
  /** full check incomplete
121
   *
122
   * This flag is set to true during a full effort check if this theory
123
   * is incomplete for some reason (for instance, if we combine cardinality
124
   * with a relation or extended function kind).
125
   */
126
  bool d_fullCheckIncomplete;
127
  /** The reason we set the above flag to true */
128
  IncompleteId d_fullCheckIncompleteId;
129
  std::map< Node, TypeNode > d_most_common_type;
130
  std::map< Node, Node > d_most_common_type_term;
131
132
 public:
133
134
  /**
135
   * Constructs a new instance of TheorySetsPrivate w.r.t. the provided
136
   * contexts.
137
   */
138
  TheorySetsPrivate(Env& env,
139
                    TheorySets& external,
140
                    SolverState& state,
141
                    InferenceManager& im,
142
                    SkolemCache& skc,
143
                    ProofNodeManager* pnm);
144
145
  ~TheorySetsPrivate();
146
147
9942
  TheoryRewriter* getTheoryRewriter() { return &d_rewriter; }
148
149
  /** Get the solver state */
150
  SolverState* getSolverState() { return &d_state; }
151
152
  /**
153
   * Finish initialize, called after the equality engine of theory sets has
154
   * been determined.
155
   */
156
  void finishInit();
157
158
  //--------------------------------- standard check
159
  /** Post-check, called after the fact queue of the theory is processed. */
160
  void postCheck(Theory::Effort level);
161
  /** Notify new fact */
162
  void notifyFact(TNode atom, bool polarity, TNode fact);
163
  //--------------------------------- end standard check
164
165
  /** Collect model values in m based on the relevant terms given by termSet */
166
  void addSharedTerm(TNode);
167
  bool collectModelValues(TheoryModel* m, const std::set<Node>& termSet);
168
169
  void computeCareGraph();
170
171
  Node explain(TNode);
172
173
  void preRegisterTerm(TNode node);
174
175
  /** ppRewrite, which expands choose and is_singleton.  */
176
  TrustNode ppRewrite(Node n, std::vector<SkolemLemma>& lems);
177
178
  void presolve();
179
180
  /** get the valuation */
181
  Valuation& getValuation();
182
 private:
183
  TheorySets& d_external;
184
  /** The state of the sets solver at full effort */
185
  SolverState& d_state;
186
  /** The inference manager of the sets solver */
187
  InferenceManager& d_im;
188
  /** Reference to the skolem cache */
189
  SkolemCache& d_skCache;
190
  /** The term registry */
191
  TermRegistry d_treg;
192
193
  /** Pointer to the equality engine of theory of sets */
194
  eq::EqualityEngine* d_equalityEngine;
195
196
  bool isCareArg( Node n, unsigned a );
197
198
 public:
199
  /** Is formula n entailed to have polarity pol in the current context? */
200
  bool isEntailed(Node n, bool pol) { return d_state.isEntailed(n, pol); }
201
202
 private:
203
  /** get choose function
204
   *
205
   * Returns the existing uninterpreted function for the choose operator for the
206
   * given set type, or creates a new one if it does not exist.
207
   */
208
  Node getChooseFunction(const TypeNode& setType);
209
  /** expand the definition of the choose operator */
210
  TrustNode expandChooseOperator(const Node& node,
211
                                 std::vector<SkolemLemma>& lems);
212
  /** expand the definition of is_singleton operator */
213
  TrustNode expandIsSingletonOperator(const Node& node);
214
  /** subtheory solver for the theory of relations */
215
  std::unique_ptr<TheorySetsRels> d_rels;
216
  /** subtheory solver for the theory of sets with cardinality */
217
  std::unique_ptr<CardinalityExtension> d_cardSolver;
218
  /** are relations enabled?
219
   *
220
   * This flag is set to true during a full effort check if any constraint
221
   * involving relational constraints is asserted to this theory.
222
   */
223
  bool d_rels_enabled;
224
  /** is cardinality enabled?
225
   *
226
   * This flag is set to true during a full effort check if any constraint
227
   * involving cardinality constraints is asserted to this theory.
228
   */
229
  bool d_card_enabled;
230
231
  /** The theory rewriter for this theory. */
232
  TheorySetsRewriter d_rewriter;
233
234
  /** a map that stores the choose functions for set types */
235
  std::map<TypeNode, Node> d_chooseFunctions;
236
237
  /** a map that maps each set to an existential quantifier generated for
238
   * operator is_singleton */
239
  std::map<Node, Node> d_isSingletonNodes;
240
}; /* class TheorySetsPrivate */
241
242
}  // namespace sets
243
}  // namespace theory
244
}  // namespace cvc5
245
246
#endif /* CVC5__THEORY__SETS__THEORY_SETS_PRIVATE_H */