GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/relevant_domain.h Lines: 12 12 100.0 %
Date: 2021-09-10 Branches: 1 2 50.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner
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
 * Relevant domain class.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__QUANTIFIERS__RELEVANT_DOMAIN_H
19
#define CVC5__THEORY__QUANTIFIERS__RELEVANT_DOMAIN_H
20
21
#include "theory/quantifiers/first_order_model.h"
22
#include "theory/quantifiers/quant_util.h"
23
24
namespace cvc5 {
25
namespace theory {
26
namespace quantifiers {
27
28
class QuantifiersState;
29
class QuantifiersRegistry;
30
class TermRegistry;
31
32
/** Relevant Domain
33
 *
34
 * This class computes the relevant domain of
35
 * functions and quantified formulas based on
36
 * techniques from "Complete Instantiation for Quantified
37
 * Formulas in SMT" by Ge et al., CAV 2009.
38
 *
39
 * Calling compute() will compute a representation
40
 * of relevant domain information, which be accessed
41
 * by getRDomain(...) calls. It is intended to be called
42
 * at full effort check, after we have initialized
43
 * the term database.
44
 */
45
class RelevantDomain : public QuantifiersUtil
46
{
47
 public:
48
  RelevantDomain(Env& env,
49
                 QuantifiersState& qs,
50
                 QuantifiersRegistry& qr,
51
                 TermRegistry& tr);
52
  virtual ~RelevantDomain();
53
  /** Reset. */
54
  bool reset(Theory::Effort e) override;
55
  /** Register the quantified formula q */
56
  void registerQuantifier(Node q) override;
57
  /** identify */
58
1187
  std::string identify() const override { return "RelevantDomain"; }
59
  /** Compute the relevant domain */
60
  void compute();
61
  /** Relevant domain representation.
62
   *
63
   * This data structure is inspired by the paper
64
   * "Complete Instantiation for Quantified Formulas in SMT" by
65
   * Ge et al., CAV 2009.
66
   * Notice that relevant domains may be equated to one another,
67
   * for example, if the quantified formula forall x. P( x, x )
68
   * exists in the current context, then the relevant domain of
69
   * arguments 1 and 2 of P are equated.
70
   */
71
5161
  class RDomain
72
  {
73
  public:
74
5161
    RDomain() : d_parent( NULL ) {}
75
    /** the set of terms in this relevant domain */
76
    std::vector< Node > d_terms;
77
    /** reset this object */
78
8994
    void reset()
79
    {
80
8994
      d_parent = NULL;
81
8994
      d_terms.clear();
82
8994
    }
83
    /** merge this with r
84
     * This sets d_parent of this to r and
85
     * copies the terms of this to r.
86
     */
87
    void merge( RDomain * r );
88
    /** add term to the relevant domain */
89
    void addTerm( Node t );
90
    /** get the parent of this */
91
    RDomain * getParent();
92
    /** remove redundant terms for d_terms, removes
93
     * duplicates modulo equality.
94
     */
95
    void removeRedundantTerms(QuantifiersState& qs);
96
    /** is n in this relevant domain? */
97
    bool hasTerm( Node n ) { return std::find( d_terms.begin(), d_terms.end(), n )!=d_terms.end(); }
98
99
   private:
100
    /** the parent of this relevant domain */
101
    RDomain* d_parent;
102
  };
103
  /** get the relevant domain
104
   *
105
   * Gets object representing the relevant domain of the i^th argument of n.
106
   *
107
   * If getParent is true, we return the representative
108
   * of the equivalence class of relevant domain objects,
109
   * which is computed as a union find (see RDomain::d_parent).
110
   */
111
  RDomain* getRDomain(Node n, int i, bool getParent = true);
112
113
 private:
114
  /** the relevant domains for each quantified formula and function,
115
   * for each variable # and argument #.
116
   */
117
  std::map< Node, std::map< int, RDomain * > > d_rel_doms;
118
  /** stores the function or quantified formula associated with
119
   * each relevant domain object.
120
   */
121
  std::map< RDomain *, Node > d_rn_map;
122
  /** stores the argument or variable number associated with
123
   * each relevant domain object.
124
   */
125
  std::map< RDomain *, int > d_ri_map;
126
  /** Reference to the quantifiers state object */
127
  QuantifiersState& d_qs;
128
  /** Reference to the quantifiers registry */
129
  QuantifiersRegistry& d_qreg;
130
  /** Reference to the term registry */
131
  TermRegistry& d_treg;
132
  /** have we computed the relevant domain on this full effort check? */
133
  bool d_is_computed;
134
  /** relevant domain literal
135
   * Caches the effect of literals on the relevant domain.
136
   */
137
  class RDomainLit {
138
  public:
139
359
    RDomainLit() : d_merge(false){
140
359
      d_rd[0] = NULL;
141
359
      d_rd[1] = NULL;
142
359
    }
143
359
    ~RDomainLit(){}
144
    /** whether this literal forces the merge of two relevant domains */
145
    bool d_merge;
146
    /** the relevant domains that are merged as a result
147
     * of this literal
148
     */
149
    RDomain * d_rd[2];
150
    /** the terms that are added to
151
     * the relevant domain as a result of this literal
152
     */
153
    std::vector< Node > d_val;
154
  };
155
  /** Cache of the effect of literals on the relevant domain */
156
  std::map< bool, std::map< bool, std::map< Node, RDomainLit > > > d_rel_dom_lit;
157
  /** Compute the relevant domain for quantified formula q. */
158
  void computeRelevantDomain(Node q);
159
  /** Compute the relevant domain for a subformula n of q,
160
   * whose polarity is given by hasPol/pol.
161
   */
162
  void computeRelevantDomainNode(Node q, Node n, bool hasPol, bool pol);
163
  /** Compute the relevant domain when the term n
164
   * is in a position to be included in relevant domain rf.
165
   */
166
  void computeRelevantDomainOpCh(RDomain* rf, Node n);
167
  /** compute relevant domain for literal.
168
   *
169
   * Updates the relevant domains based on a literal n in quantified
170
   * formula q whose polarity is given by hasPol/pol.
171
   */
172
  void computeRelevantDomainLit( Node q, bool hasPol, bool pol, Node n );
173
};/* class RelevantDomain */
174
175
}  // namespace quantifiers
176
}  // namespace theory
177
}  // namespace cvc5
178
179
#endif /* CVC5__THEORY__QUANTIFIERS__RELEVANT_DOMAIN_H */