GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/relevant_domain.h Lines: 12 12 100.0 %
Date: 2021-05-22 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(QuantifiersState& qs,
49
                 QuantifiersRegistry& qr,
50
                 TermRegistry& tr);
51
  virtual ~RelevantDomain();
52
  /** Reset. */
53
  bool reset(Theory::Effort e) override;
54
  /** Register the quantified formula q */
55
  void registerQuantifier(Node q) override;
56
  /** identify */
57
1085
  std::string identify() const override { return "RelevantDomain"; }
58
  /** Compute the relevant domain */
59
  void compute();
60
  /** Relevant domain representation.
61
   *
62
   * This data structure is inspired by the paper
63
   * "Complete Instantiation for Quantified Formulas in SMT" by
64
   * Ge et al., CAV 2009.
65
   * Notice that relevant domains may be equated to one another,
66
   * for example, if the quantified formula forall x. P( x, x )
67
   * exists in the current context, then the relevant domain of
68
   * arguments 1 and 2 of P are equated.
69
   */
70
5132
  class RDomain
71
  {
72
  public:
73
5132
    RDomain() : d_parent( NULL ) {}
74
    /** the set of terms in this relevant domain */
75
    std::vector< Node > d_terms;
76
    /** reset this object */
77
9683
    void reset()
78
    {
79
9683
      d_parent = NULL;
80
9683
      d_terms.clear();
81
9683
    }
82
    /** merge this with r
83
     * This sets d_parent of this to r and
84
     * copies the terms of this to r.
85
     */
86
    void merge( RDomain * r );
87
    /** add term to the relevant domain */
88
    void addTerm( Node t );
89
    /** get the parent of this */
90
    RDomain * getParent();
91
    /** remove redundant terms for d_terms, removes
92
     * duplicates modulo equality.
93
     */
94
    void removeRedundantTerms(QuantifiersState& qs);
95
    /** is n in this relevant domain? */
96
    bool hasTerm( Node n ) { return std::find( d_terms.begin(), d_terms.end(), n )!=d_terms.end(); }
97
98
   private:
99
    /** the parent of this relevant domain */
100
    RDomain* d_parent;
101
  };
102
  /** get the relevant domain
103
   *
104
   * Gets object representing the relevant domain of the i^th argument of n.
105
   *
106
   * If getParent is true, we return the representative
107
   * of the equivalence class of relevant domain objects,
108
   * which is computed as a union find (see RDomain::d_parent).
109
   */
110
  RDomain* getRDomain(Node n, int i, bool getParent = true);
111
112
 private:
113
  /** the relevant domains for each quantified formula and function,
114
   * for each variable # and argument #.
115
   */
116
  std::map< Node, std::map< int, RDomain * > > d_rel_doms;
117
  /** stores the function or quantified formula associated with
118
   * each relevant domain object.
119
   */
120
  std::map< RDomain *, Node > d_rn_map;
121
  /** stores the argument or variable number associated with
122
   * each relevant domain object.
123
   */
124
  std::map< RDomain *, int > d_ri_map;
125
  /** Reference to the quantifiers state object */
126
  QuantifiersState& d_qs;
127
  /** Reference to the quantifiers registry */
128
  QuantifiersRegistry& d_qreg;
129
  /** Reference to the term registry */
130
  TermRegistry& d_treg;
131
  /** have we computed the relevant domain on this full effort check? */
132
  bool d_is_computed;
133
  /** relevant domain literal
134
   * Caches the effect of literals on the relevant domain.
135
   */
136
  class RDomainLit {
137
  public:
138
416
    RDomainLit() : d_merge(false){
139
416
      d_rd[0] = NULL;
140
416
      d_rd[1] = NULL;
141
416
    }
142
416
    ~RDomainLit(){}
143
    /** whether this literal forces the merge of two relevant domains */
144
    bool d_merge;
145
    /** the relevant domains that are merged as a result
146
     * of this literal
147
     */
148
    RDomain * d_rd[2];
149
    /** the terms that are added to
150
     * the relevant domain as a result of this literal
151
     */
152
    std::vector< Node > d_val;
153
  };
154
  /** Cache of the effect of literals on the relevant domain */
155
  std::map< bool, std::map< bool, std::map< Node, RDomainLit > > > d_rel_dom_lit;
156
  /** Compute the relevant domain for quantified formula q. */
157
  void computeRelevantDomain(Node q);
158
  /** Compute the relevant domain for a subformula n of q,
159
   * whose polarity is given by hasPol/pol.
160
   */
161
  void computeRelevantDomainNode(Node q, Node n, bool hasPol, bool pol);
162
  /** Compute the relevant domain when the term n
163
   * is in a position to be included in relevant domain rf.
164
   */
165
  void computeRelevantDomainOpCh(RDomain* rf, Node n);
166
  /** compute relevant domain for literal.
167
   *
168
   * Updates the relevant domains based on a literal n in quantified
169
   * formula q whose polarity is given by hasPol/pol.
170
   */
171
  void computeRelevantDomainLit( Node q, bool hasPol, bool pol, Node n );
172
};/* class RelevantDomain */
173
174
}  // namespace quantifiers
175
}  // namespace theory
176
}  // namespace cvc5
177
178
#endif /* CVC5__THEORY__QUANTIFIERS__RELEVANT_DOMAIN_H */