summaryrefslogtreecommitdiff
path: root/src/preprocessing/assertion_pipeline.h
blob: e555da299a27a11b721c4385b8e0a3613dbf4bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/******************************************************************************
 * Top contributors (to current version):
 *   Andres Noetzli, Andrew Reynolds, Morgan Deters
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * AssertionPipeline stores a list of assertions modified by
 * preprocessing passes.
 */

#include "cvc4_private.h"

#ifndef CVC5__PREPROCESSING__ASSERTION_PIPELINE_H
#define CVC5__PREPROCESSING__ASSERTION_PIPELINE_H

#include <vector>

#include "expr/node.h"
#include "theory/trust_node.h"

namespace cvc5 {

class ProofGenerator;
namespace smt {
class PreprocessProofGenerator;
}

namespace preprocessing {

using IteSkolemMap = std::unordered_map<size_t, Node>;

/**
 * Assertion Pipeline stores a list of assertions modified by preprocessing
 * passes. It is assumed that all assertions after d_realAssertionsEnd were
 * generated by ITE removal. Hence, d_iteSkolemMap maps into only these.
 */
class AssertionPipeline
{
 public:
  AssertionPipeline();

  size_t size() const { return d_nodes.size(); }

  void resize(size_t n) { d_nodes.resize(n); }

  /**
   * Clear the list of assertions and assumptions.
   */
  void clear();

  const Node& operator[](size_t i) const { return d_nodes[i]; }

  /**
   * Adds an assertion/assumption to be preprocessed.
   *
   * @param n The assertion/assumption
   * @param isAssumption If true, records that \p n is an assumption. Note that
   * all assumptions have to be added contiguously.
   * @param isInput If true, n is an input formula (an assumption in the main
   * body of the overall proof).
   * @param pg The proof generator who can provide a proof of n. The proof
   * generator is not required and is ignored if isInput is true.
   */
  void push_back(Node n,
                 bool isAssumption = false,
                 bool isInput = false,
                 ProofGenerator* pg = nullptr);
  /** Same as above, with TrustNode */
  void pushBackTrusted(theory::TrustNode trn);

  /**
   * Get the constant reference to the underlying assertions. It is only
   * possible to modify these via the replace methods below.
   */
  const std::vector<Node>& ref() const { return d_nodes; }

  std::vector<Node>::const_iterator begin() const { return d_nodes.cbegin(); }
  std::vector<Node>::const_iterator end() const { return d_nodes.cend(); }

  /*
   * Replaces assertion i with node n and records the dependency between the
   * original assertion and its replacement.
   *
   * @param i The position of the assertion to replace.
   * @param n The replacement assertion.
   * @param pg The proof generator who can provide a proof of d_nodes[i] == n,
   * where d_nodes[i] is the assertion at position i prior to this call.
   */
  void replace(size_t i, Node n, ProofGenerator* pg = nullptr);
  /**
   * Same as above, with TrustNode trn, which is of kind REWRITE and proves
   * d_nodes[i] = n for some n.
   */
  void replaceTrusted(size_t i, theory::TrustNode trn);

  IteSkolemMap& getIteSkolemMap() { return d_iteSkolemMap; }
  const IteSkolemMap& getIteSkolemMap() const { return d_iteSkolemMap; }

  size_t getRealAssertionsEnd() const { return d_realAssertionsEnd; }

  /** @return The index of the first assumption */
  size_t getAssumptionsStart() const { return d_assumptionsStart; }

  /** @return The number of assumptions */
  size_t getNumAssumptions() const { return d_numAssumptions; }

  void updateRealAssertionsEnd() { d_realAssertionsEnd = d_nodes.size(); }

  /**
   * Returns true if substitutions must be stored as assertions. This is for
   * example the case when we do incremental solving.
   */
  bool storeSubstsInAsserts() { return d_storeSubstsInAsserts; }

  /**
   * Enables storing substitutions as assertions.
   */
  void enableStoreSubstsInAsserts();

  /**
   * Disables storing substitutions as assertions.
   */
  void disableStoreSubstsInAsserts();

  /**
   * Adds a substitution node of the form (= lhs rhs) to the assertions.
   * This conjoins n to assertions at a distinguished index given by
   * d_substsIndex.
   *
   * @param n The substitution node
   * @param pg The proof generator that can provide a proof of n.
   */
  void addSubstitutionNode(Node n, ProofGenerator* pg = nullptr);

  /**
   * Conjoin n to the assertion vector at position i. This replaces
   * d_nodes[i] with the rewritten form of (AND d_nodes[i] n).
   *
   * @param i The assertion to replace
   * @param n The formula to conjoin at position i
   * @param pg The proof generator that can provide a proof of n
   */
  void conjoin(size_t i, Node n, ProofGenerator* pg = nullptr);

  /**
   * Checks whether the assertion at a given index represents substitutions.
   *
   * @param i The index in question
   */
  bool isSubstsIndex(size_t i)
  {
    return d_storeSubstsInAsserts && i == d_substsIndex;
  }
  //------------------------------------ for proofs
  /** Set proof generator */
  void setProofGenerator(smt::PreprocessProofGenerator* pppg);
  /** Is proof enabled? */
  bool isProofEnabled() const;
  //------------------------------------ end for proofs
 private:
  /** The list of current assertions */
  std::vector<Node> d_nodes;

  /**
   * Map from skolem variables to index in d_assertions containing
   * corresponding introduced Boolean ite
   */
  IteSkolemMap d_iteSkolemMap;

  /** Size of d_nodes when preprocessing starts */
  size_t d_realAssertionsEnd;

  /**
   * If true, we store the substitutions as assertions. This is necessary when
   * doing incremental solving because we cannot apply them to existing
   * assertions while preprocessing new assertions.
   */
  bool d_storeSubstsInAsserts;

  /**
   * The index of the assertions that holds the substitutions.
   *
   * TODO(#2473): replace by separate vector of substitution assertions.
   */
  size_t d_substsIndex;

  /** Index of the first assumption */
  size_t d_assumptionsStart;
  /** The number of assumptions */
  size_t d_numAssumptions;
  /** The proof generator, if one is provided */
  smt::PreprocessProofGenerator* d_pppg;
}; /* class AssertionPipeline */

}  // namespace preprocessing
}  // namespace cvc5

#endif /* CVC5__PREPROCESSING__ASSERTION_PIPELINE_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback