GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/relevance_manager.h Lines: 1 1 100.0 %
Date: 2021-09-10 Branches: 0 0 0.0 %

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
 * Relevance manager.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__RELEVANCE_MANAGER__H
19
#define CVC5__THEORY__RELEVANCE_MANAGER__H
20
21
#include <unordered_map>
22
#include <unordered_set>
23
24
#include "context/cdlist.h"
25
#include "expr/node.h"
26
#include "theory/valuation.h"
27
28
namespace cvc5 {
29
namespace theory {
30
31
/**
32
 * This class manages queries related to relevance of asserted literals.
33
 * In particular, note the following definition:
34
 *
35
 * Let F be a formula, and let L = { l_1, ..., l_n } be a set of
36
 * literals that propositionally entail it. A "relevant selection of L with
37
 * respect to F" is a subset of L that also propositionally entails F.
38
 *
39
 * This class computes a relevant selection of the current assertion stack
40
 * at FULL effort with respect to the input formula + theory lemmas that are
41
 * critical to justify (see LemmaProperty::NEEDS_JUSTIFY). By default, theory
42
 * lemmas are not critical to justify; in fact, all T-valid theory lemmas
43
 * are not critical to justify, since they are guaranteed to be satisfied in
44
 * all inputs. However, some theory lemmas that introduce skolems need
45
 * justification.
46
 *
47
 * As an example of such a lemma, take the example input formula:
48
 *   (and (exists ((x Int)) (P x)) (not (P 0)))
49
 * A skolemization lemma like the following needs justification:
50
 *   (=> (exists ((x Int)) (P x)) (P k))
51
 * Intuitively, this is because the satisfiability of the existential above is
52
 * being deferred to the satisfiability of (P k) where k is fresh. Thus,
53
 * a relevant selection must include both (exists ((x Int)) (P x)) and (P k)
54
 * in this example.
55
 *
56
 * Theories are responsible for marking such lemmas using the NEEDS_JUSTIFY
57
 * property when calling OutputChannel::lemma.
58
 *
59
 * Notice that this class has some relation to the justification decision
60
 * heuristic (--decision=justification), which constructs a relevant selection
61
 * of the input formula by construction. This class is orthogonal to this
62
 * method, since it computes relevant selection *after* a full assignment. Thus
63
 * its main advantage with respect to decision=justification is that it can be
64
 * used in combination with any SAT decision heuristic.
65
 *
66
 * Internally, this class stores the input assertions and can be asked if an
67
 * asserted literal is part of the current relevant selection. The relevant
68
 * selection is computed lazily, i.e. only when someone asks if a literal is
69
 * relevant, and only at most once per FULL effort check.
70
 */
71
18
class RelevanceManager
72
{
73
  typedef context::CDList<Node> NodeList;
74
75
 public:
76
  RelevanceManager(context::UserContext* userContext, Valuation val);
77
  /**
78
   * Notify (preprocessed) assertions. This is called for input formulas or
79
   * lemmas that need justification that have been fully processed, just before
80
   * adding them to the PropEngine.
81
   */
82
  void notifyPreprocessedAssertions(const std::vector<Node>& assertions);
83
  /** Singleton version of above */
84
  void notifyPreprocessedAssertion(Node n);
85
  /**
86
   * Reset round, called at the beginning of a full effort check in
87
   * TheoryEngine.
88
   */
89
  void resetRound();
90
  /**
91
   * Is lit part of the current relevant selection? This computes the set of
92
   * relevant assertions if not already done so. This call is valid during a
93
   * full effort check in TheoryEngine, or after TheoryEngine has terminated
94
   * with "sat". This means that theories can query this during FULL or
95
   * LAST_CALL efforts, through the Valuation class.
96
   */
97
  bool isRelevant(Node lit);
98
  /**
99
   * Get the current relevant selection (see above). This computes this set
100
   * if not already done so. This call is valid during a full effort check in
101
   * TheoryEngine, or after TheoryEngine has terminated with "sat". This method
102
   * sets the flag success to false if we failed to compute relevant
103
   * assertions, which can occur if
104
   *
105
   * The value of this return is only valid if success was not updated to false.
106
   */
107
  const std::unordered_set<TNode>& getRelevantAssertions(bool& success);
108
109
 private:
110
  /**
111
   * Add the set of assertions to the formulas known to this class. This
112
   * method handles optimizations such as breaking apart top-level applications
113
   * of and.
114
   */
115
  void addAssertionsInternal(std::vector<Node>& toProcess);
116
  /** compute the relevant selection */
117
  void computeRelevance();
118
  /**
119
   * Justify formula n. To "justify" means we have added literals to our
120
   * relevant selection set (d_rset) whose current values ensure that n
121
   * evaluates to true or false.
122
   *
123
   * This method returns 1 if we justified n to be true, -1 means
124
   * justified n to be false, 0 means n could not be justified.
125
   */
126
  int justify(TNode n, std::unordered_map<TNode, int>& cache);
127
  /** Is the top symbol of cur a Boolean connective? */
128
  bool isBooleanConnective(TNode cur);
129
  /**
130
   * Update justify last child. This method is a helper function for justify,
131
   * which is called at the moment that Boolean connective formula cur
132
   * has a new child that has been computed in the justify cache.
133
   *
134
   * @param cur The Boolean connective formula
135
   * @param childrenJustify The values of the previous children (not including
136
   * the current one)
137
   * @param cache The justify cache
138
   * @return True if we wish to visit the next child. If this is the case, then
139
   * the justify value of the current child is added to childrenJustify.
140
   */
141
  bool updateJustifyLastChild(TNode cur,
142
                              std::vector<int>& childrenJustify,
143
                              std::unordered_map<TNode, int>& cache);
144
  /** The valuation object, used to query current value of theory literals */
145
  Valuation d_val;
146
  /** The input assertions */
147
  NodeList d_input;
148
  /** The current relevant selection. */
149
  std::unordered_set<TNode> d_rset;
150
  /** Have we computed the relevant selection this round? */
151
  bool d_computed;
152
  /**
153
   * Did we succeed in computing the relevant selection? If this is false, there
154
   * was a syncronization issue between the input formula and the satisfying
155
   * assignment since this class found that the input formula was not satisfied
156
   * by the assignment. This should never happen, but if it does, this class
157
   * aborts and indicates that all literals are relevant.
158
   */
159
  bool d_success;
160
};
161
162
}  // namespace theory
163
}  // namespace cvc5
164
165
#endif /* CVC5__THEORY__RELEVANCE_MANAGER__H */