GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/strings/regexp_solver.h Lines: 1 1 100.0 %
Date: 2021-11-07 Branches: 0 0 0.0 %

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