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

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner, Abdalrhman Mohamed
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
 * candidate_rewrite_database
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_DATABASE_H
19
#define CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_DATABASE_H
20
21
#include <vector>
22
23
#include "theory/quantifiers/candidate_rewrite_filter.h"
24
#include "theory/quantifiers/expr_miner.h"
25
#include "theory/quantifiers/sygus_sampler.h"
26
27
namespace cvc5 {
28
namespace theory {
29
namespace quantifiers {
30
31
/** CandidateRewriteDatabase
32
 *
33
 * This maintains the necessary data structures for generating a database
34
 * of candidate rewrite rules (see Noetzli et al "Syntax-Guided Rewrite Rule
35
 * Enumeration for SMT Solvers" SAT 2019). The primary responsibilities
36
 * of this class are to perform the "equivalence checking" and "congruence
37
 * and matching filtering" in Figure 1. The equivalence checking is done
38
 * through a combination of the sygus sampler object owned by this class
39
 * and the calls made to copies of the SmtEngine in ::addTerm. The rewrite
40
 * rule filtering (based on congruence, matching, variable ordering) is also
41
 * managed by the sygus sampler object.
42
 */
43
class CandidateRewriteDatabase : public ExprMiner
44
{
45
 public:
46
  /**
47
   * Constructor
48
   * @param env Reference to the environment
49
   * @param doCheck Whether to check rewrite rules using subsolvers.
50
   * @param rewAccel Whether to construct symmetry breaking lemmas based on
51
   * discovered rewrites (see option sygusRewSynthAccel()).
52
   * @param silent Whether to silence the output of rewrites discovered by this
53
   * class.
54
   * @param filterPairs Whether to filter rewrite pairs using filtering
55
   * techniques from the SAT 2019 paper above.
56
   */
57
  CandidateRewriteDatabase(Env& env,
58
                           bool doCheck,
59
                           bool rewAccel = false,
60
                           bool silent = false,
61
                           bool filterPairs = true);
62
115
  ~CandidateRewriteDatabase() {}
63
  /**  Initialize this class */
64
  void initialize(const std::vector<Node>& var, SygusSampler* ss) override;
65
  /**  Initialize this class
66
   *
67
   * Serves the same purpose as the above function, but we will be using
68
   * sygus to enumerate terms and generate samples.
69
   *
70
   * tds : pointer to sygus term database. We use the extended rewriter of this
71
   * database when computing candidate rewrites,
72
   * f : a term of some SyGuS datatype type whose values we will be
73
   * testing under the free variables in the grammar of f. This is the
74
   * "candidate variable" CegConjecture::d_candidates.
75
   */
76
  void initializeSygus(const std::vector<Node>& vars,
77
                       TermDbSygus* tds,
78
                       Node f,
79
                       SygusSampler* ss);
80
  /** add term
81
   *
82
   * Notifies this class that the solution sol was enumerated. This may
83
   * cause a candidate-rewrite to be printed on the output stream out.
84
   *
85
   * @param sol The term to add to this class.
86
   * @param rec If true, then we also recursively add all subterms of sol
87
   * to this class as well.
88
   * @param out The stream to output rewrite rules on.
89
   * @param rew_print Set to true if this class printed a rewrite involving sol.
90
   * @return A previous term eq_sol added to this class, such that sol is
91
   * equivalent to eq_sol based on the criteria used by this class.
92
   */
93
  Node addTerm(Node sol, bool rec, std::ostream& out, bool& rew_print);
94
  Node addTerm(Node sol, bool rec, std::ostream& out);
95
  /**
96
   * Same as above, returns true if the return value of addTerm was equal to
97
   * sol, in other words, sol was a new unique term. This assumes false for
98
   * the argument rec.
99
   */
100
  bool addTerm(Node sol, std::ostream& out) override;
101
  /** sets whether this class should output candidate rewrites it finds */
102
  void setSilent(bool flag);
103
  /** Enable the (extended) rewriter for this class */
104
  void enableExtendedRewriter();
105
106
 private:
107
  /** (required) pointer to the sygus term database of d_qe */
108
  TermDbSygus* d_tds;
109
  /** Whether we use the extended rewriter */
110
  bool d_useExtRewriter;
111
  /** the function-to-synthesize we are testing (if sygus) */
112
  Node d_candidate;
113
  /** whether we are checking equivalence using subsolver */
114
  bool d_doCheck;
115
  /**
116
   * If true, we use acceleration for symmetry breaking rewrites (see option
117
   * sygusRewSynthAccel()).
118
   */
119
  bool d_rewAccel;
120
  /** if true, we silence the output of candidate rewrites */
121
  bool d_silent;
122
  /** if true, we filter pairs of terms to check equivalence */
123
  bool d_filterPairs;
124
  /** whether we are using sygus */
125
  bool d_using_sygus;
126
  /** candidate rewrite filter */
127
  CandidateRewriteFilter d_crewrite_filter;
128
  /** the cache for results of addTerm */
129
  std::unordered_map<Node, Node> d_add_term_cache;
130
};
131
132
}  // namespace quantifiers
133
}  // namespace theory
134
}  // namespace cvc5
135
136
#endif /* CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_DATABASE_H */