summaryrefslogtreecommitdiff
path: root/src/theory/bags/inference_generator.h
blob: d6fc184c780a01e4cb5d2bde6e65194adbd03615 (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
/*********************                                                        */
/*! \file inference_generator.h
 ** \verbatim
 ** Top contributors (to current version):
 **   Mudathir Mohamed, Andrew Reynolds
 ** This file is part of the CVC4 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.\endverbatim
 **
 ** \brief Inference generator utility
 **/

#include "cvc4_private.h"

#ifndef CVC4__THEORY__BAGS__INFERENCE_GENERATOR_H
#define CVC4__THEORY__BAGS__INFERENCE_GENERATOR_H

#include <map>
#include <vector>

#include "expr/node.h"
#include "infer_info.h"
#include "theory/bags/inference_manager.h"
#include "theory/bags/solver_state.h"

namespace CVC4 {
namespace theory {
namespace bags {

/**
 * An inference generator class. This class is used by the core solver to
 * generate lemmas
 */
class InferenceGenerator
{
 public:
  InferenceGenerator(SolverState* state, InferenceManager* im);

  /**
   * @param A is a bag of type (Bag E)
   * @param e is a node of type E
   * @return an inference that represents the following implication
   * (=>
   *   true
   *   (>= (bag.count e A) 0)
   */
  InferInfo nonNegativeCount(Node n, Node e);

  /**
   * @param n is (bag x c) of type (Bag E)
   * @param e is a node of type E
   * @return an inference that represents the following implication
   * (=>
   *   true
   *   (= (bag.count e skolem) c))
   *   if e is exactly node x. Node skolem is a fresh variable equals (bag x c).
   *   Otherwise the following inference is returned
   * (=>
   *   true
   *   (= (bag.count e skolem) (ite (= e x) c 0)))
   */
  InferInfo mkBag(Node n, Node e);
  /**
   * @param n is (= A B) where A, B are bags of type (Bag E), and
   * (not (= A B)) is an assertion in the equality engine
   * @return an inference that represents the following implication
   * (=>
   *   (not (= A B))
   *   (not (= (count e A) (count e B))))
   *   where e is a fresh skolem of type E.
   */
  InferInfo bagDisequality(Node n);
  /**
   * @param n is (as emptybag (Bag E))
   * @param e is a node of Type E
   * @return an inference that represents the following implication
   * (=>
   *   true
   *   (= 0 (count e skolem)))
   *   where skolem = (as emptybag (Bag String))
   */
  InferInfo empty(Node n, Node e);
  /**
   * @param n is (union_disjoint A B) where A, B are bags of type (Bag E)
   * @param e is a node of Type E
   * @return an inference that represents the following implication
   * (=>
   *   true
   *   (= (count e skolem)
   *      (+ (count e A) (count e B))))
   *  where skolem is a fresh variable equals (union_disjoint A B)
   */
  InferInfo unionDisjoint(Node n, Node e);
  /**
   * @param n is (union_disjoint A B) where A, B are bags of type (Bag E)
   * @param e is a node of Type E
   * @return an inference that represents the following implication
   * (=>
   *   true
   *   (=
   *     (count e skolem)
   *     (ite
   *       (> (count e A) (count e B))
   *       (count e A)
   *       (count e B)))))
   * where skolem is a fresh variable equals (union_max A B)
   */
  InferInfo unionMax(Node n, Node e);
  /**
   * @param n is (intersection_min A B) where A, B are bags of type (Bag E)
   * @param e is a node of Type E
   * @return an inference that represents the following implication
   * (=>
   *   true
   *   (=
   *     (count e skolem)
   *     (ite(
   *       (< (count e A) (count e B))
   *       (count e A)
   *       (count e B)))))
   * where skolem is a fresh variable equals (intersection_min A B)
   */
  InferInfo intersection(Node n, Node e);
  /**
   * @param n is (difference_subtract A B) where A, B are bags of type (Bag E)
   * @param e is a node of Type E
   * @return an inference that represents the following implication
   * (=>
   *   true
   *   (=
   *     (count e skolem)
   *     (ite
   *       (>= (count e A) (count e B))
   *       (- (count e A) (count e B))
   *       0))))
   * where skolem is a fresh variable equals (difference_subtract A B)
   */
  InferInfo differenceSubtract(Node n, Node e);
  /**
   * @param n is (difference_remove A B) where A, B are bags of type (Bag E)
   * @param e is a node of Type E
   * @return an inference that represents the following implication
   * (=>
   *   true
   *   (=
   *     (count e skolem)
   *     (ite
   *       (= (count e B) 0)
   *       (count e A)
   *       0))))
   * where skolem is a fresh variable equals (difference_remove A B)
   */
  InferInfo differenceRemove(Node n, Node e);
  /**
   * @param n is (duplicate_removal A) where A is a bag of type (Bag E)
   * @param e is a node of Type E
   * @return an inference that represents the following implication
   * (=>
   *   true
   *   (=
   *    (count e skolem)
   *    (ite (>= (count e A) 1) 1 0))))
   * where skolem is a fresh variable equals (duplicate_removal A)
   */
  InferInfo duplicateRemoval(Node n, Node e);

  /**
   * @param element of type T
   * @param bag of type (bag T)
   * @return  a count term (bag.count element bag)
   */
  Node getMultiplicityTerm(Node element, Node bag);

 private:
  /** generate skolem variable for node n and add it to inferInfo */
  Node getSkolem(Node& n, InferInfo& inferInfo);

  NodeManager* d_nm;
  SkolemManager* d_sm;
  SolverState* d_state;
  /** Pointer to the inference manager */
  InferenceManager* d_im;
  /** Commonly used constants */
  Node d_true;
  Node d_zero;
  Node d_one;
};

}  // namespace bags
}  // namespace theory
}  // namespace CVC4

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