1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Tianyi Liang, Andres Noetzli |
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 |
|
* Regular expression solver for the theory of strings. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__STRINGS__REGEXP_SOLVER_H |
19 |
|
#define CVC5__THEORY__STRINGS__REGEXP_SOLVER_H |
20 |
|
|
21 |
|
#include <map> |
22 |
|
|
23 |
|
#include "context/cdhashset.h" |
24 |
|
#include "context/cdlist.h" |
25 |
|
#include "context/context.h" |
26 |
|
#include "expr/node.h" |
27 |
|
#include "smt/env_obj.h" |
28 |
|
#include "theory/strings/extf_solver.h" |
29 |
|
#include "theory/strings/inference_manager.h" |
30 |
|
#include "theory/strings/regexp_operation.h" |
31 |
|
#include "theory/strings/sequences_stats.h" |
32 |
|
#include "theory/strings/skolem_cache.h" |
33 |
|
#include "theory/strings/solver_state.h" |
34 |
|
#include "util/string.h" |
35 |
|
|
36 |
|
namespace cvc5 { |
37 |
|
namespace theory { |
38 |
|
namespace strings { |
39 |
|
|
40 |
|
class RegExpSolver : protected EnvObj |
41 |
|
{ |
42 |
|
typedef context::CDList<Node> NodeList; |
43 |
|
typedef context::CDHashMap<Node, bool> NodeBoolMap; |
44 |
|
typedef context::CDHashMap<Node, int> NodeIntMap; |
45 |
|
typedef context::CDHashMap<Node, unsigned> NodeUIntMap; |
46 |
|
typedef context::CDHashMap<Node, Node> NodeNodeMap; |
47 |
|
typedef context::CDHashSet<Node> NodeSet; |
48 |
|
|
49 |
|
public: |
50 |
|
RegExpSolver(Env& env, |
51 |
|
SolverState& s, |
52 |
|
InferenceManager& im, |
53 |
|
SkolemCache* skc, |
54 |
|
CoreSolver& cs, |
55 |
|
ExtfSolver& es, |
56 |
|
SequencesStatistics& stats); |
57 |
9937 |
~RegExpSolver() {} |
58 |
|
|
59 |
|
/** check regular expression memberships |
60 |
|
* |
61 |
|
* This checks the satisfiability of all regular expression memberships |
62 |
|
* of the form (not) s in R. We use various heuristic techniques based on |
63 |
|
* unrolling, combined with techniques from Liang et al, "A Decision Procedure |
64 |
|
* for Regular Membership and Length Constraints over Unbounded Strings", |
65 |
|
* FroCoS 2015. |
66 |
|
*/ |
67 |
|
void checkMemberships(); |
68 |
|
|
69 |
|
private: |
70 |
|
/** check |
71 |
|
* |
72 |
|
* Tells this solver to check whether the regular expressions in mems |
73 |
|
* are consistent. If they are not, then this class will call the |
74 |
|
* sendInference method of its parent TheoryString object, indicating that |
75 |
|
* it requires a conflict or lemma to be processed. |
76 |
|
* |
77 |
|
* The argument mems maps representative string terms r to memberships of the |
78 |
|
* form (t in R) or ~(t in R), where t = r currently holds in the equality |
79 |
|
* engine of the theory of strings. |
80 |
|
*/ |
81 |
|
void check(const std::map<Node, std::vector<Node>>& mems); |
82 |
|
/** |
83 |
|
* Check memberships in equivalence class for regular expression |
84 |
|
* inclusion. |
85 |
|
* |
86 |
|
* This method returns false if it discovered a conflict for this set of |
87 |
|
* assertions, and true otherwise. It discovers a conflict e.g. if mems |
88 |
|
* contains str.in.re(xi, Ri) and ~str.in.re(xj, Rj) and Rj includes Ri. |
89 |
|
* |
90 |
|
* @param mems Vector of memberships of the form: (~)str.in.re(x1, R1) |
91 |
|
* ... (~)str.in.re(xn, Rn) where x1 = ... = xn in the |
92 |
|
* current context. The function removes elements from this |
93 |
|
* vector that were marked as reduced. |
94 |
|
* @param expForRe Additional explanations for regular expressions. |
95 |
|
* @return False if a conflict was detected, true otherwise |
96 |
|
*/ |
97 |
|
bool checkEqcInclusion(std::vector<Node>& mems); |
98 |
|
|
99 |
|
/** |
100 |
|
* Check memberships for equivalence class. |
101 |
|
* The vector mems is a vector of memberships of the form: |
102 |
|
* (~) (x1 in R1 ) ... (~) (xn in Rn) |
103 |
|
* where x1 = ... = xn in the current context. |
104 |
|
* |
105 |
|
* This method may add lemmas or conflicts via the inference manager. |
106 |
|
* |
107 |
|
* This method returns false if it discovered a conflict for this set of |
108 |
|
* assertions, and true otherwise. It discovers a conflict e.g. if mems |
109 |
|
* contains (xi in Ri) and (xj in Rj) and intersect(xi,xj) is empty. |
110 |
|
*/ |
111 |
|
bool checkEqcIntersect(const std::vector<Node>& mems); |
112 |
|
// Constants |
113 |
|
Node d_emptyString; |
114 |
|
Node d_emptyRegexp; |
115 |
|
Node d_true; |
116 |
|
Node d_false; |
117 |
|
/** The solver state of the parent of this object */ |
118 |
|
SolverState& d_state; |
119 |
|
/** the output channel of the parent of this object */ |
120 |
|
InferenceManager& d_im; |
121 |
|
/** reference to the core solver, used for certain queries */ |
122 |
|
CoreSolver& d_csolver; |
123 |
|
/** reference to the extended function solver of the parent */ |
124 |
|
ExtfSolver& d_esolver; |
125 |
|
/** Reference to the statistics for the theory of strings/sequences. */ |
126 |
|
SequencesStatistics& d_statistics; |
127 |
|
// check membership constraints |
128 |
|
Node mkAnd(Node c1, Node c2); |
129 |
|
/** |
130 |
|
* Check partial derivative |
131 |
|
* |
132 |
|
* Returns false if a lemma pertaining to checking the partial derivative |
133 |
|
* of x in r was added. In this case, addedLemma is updated to true. |
134 |
|
* |
135 |
|
* The argument atom is the assertion that explains x in r, which is the |
136 |
|
* normalized form of atom that may be modified using a substitution whose |
137 |
|
* explanation is nf_exp. |
138 |
|
*/ |
139 |
|
bool checkPDerivative( |
140 |
|
Node x, Node r, Node atom, bool& addedLemma, std::vector<Node>& nf_exp); |
141 |
|
Node getMembership(Node n, bool isPos, unsigned i); |
142 |
|
unsigned getNumMemberships(Node n, bool isPos); |
143 |
|
cvc5::String getHeadConst(Node x); |
144 |
|
bool deriveRegExp(Node x, Node r, Node atom, std::vector<Node>& ant); |
145 |
|
Node getNormalSymRegExp(Node r, std::vector<Node>& nf_exp); |
146 |
|
// regular expression memberships |
147 |
|
NodeSet d_regexp_ucached; |
148 |
|
NodeSet d_regexp_ccached; |
149 |
|
// semi normal forms for symbolic expression |
150 |
|
std::map<Node, Node> d_nf_regexps; |
151 |
|
std::map<Node, std::vector<Node> > d_nf_regexps_exp; |
152 |
|
// processed memberships |
153 |
|
NodeSet d_processed_memberships; |
154 |
|
/** regular expression operation module */ |
155 |
|
RegExpOpr d_regexp_opr; |
156 |
|
}; /* class TheoryStrings */ |
157 |
|
|
158 |
|
} // namespace strings |
159 |
|
} // namespace theory |
160 |
|
} // namespace cvc5 |
161 |
|
|
162 |
|
#endif /* CVC5__THEORY__STRINGS__THEORY_STRINGS_H */ |