GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/cegqi/vts_term_cache.h Lines: 1 1 100.0 %
Date: 2021-05-22 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds
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
 * Virtual term substitution term cache.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__QUANTIFIERS__CEGQI__VTS_TERM_CACHE_H
19
#define CVC5__THEORY__QUANTIFIERS__CEGQI__VTS_TERM_CACHE_H
20
21
#include <map>
22
#include "expr/attribute.h"
23
#include "expr/node.h"
24
25
namespace cvc5 {
26
namespace theory {
27
28
/** Attribute to mark Skolems as virtual terms */
29
struct VirtualTermSkolemAttributeId
30
{
31
};
32
typedef expr::Attribute<VirtualTermSkolemAttributeId, bool>
33
    VirtualTermSkolemAttribute;
34
35
namespace quantifiers {
36
37
class QuantifiersInferenceManager;
38
39
/** Virtual term substitution term cache
40
 *
41
 * This class stores skolems corresponding to virtual terms (e.g. delta and
42
 * infinity) and has methods for performing virtual term substitution.
43
 *
44
 * In detail, there are three kinds of virtual terms:
45
 * (1) delta, of Real type, representing a infinitesimally small real value,
46
 * (2) infinity, of Real type, representing an infinitely large real value,
47
 * (3) infinity, of Int type, representing an infinitely large integer value.
48
 *
49
 * For each of the above three virtual terms, we have 2 variants.
50
 *
51
 * The first variant we simply call "virtual terms". These terms are intended
52
 * to never appear in assertions and are simply used by algorithms e.g. CEGQI
53
 * for specifying instantiations. They are eliminated by the standard rules of
54
 * virtual term substitution, e.g.:
55
 *   t < s + delta ---> t <=s
56
 *   t <= s + delta ---> t <= s
57
 *   t < s - delta ----> t < s
58
 *   t <= s - delta -----> t < s
59
 *   t <= s + inf ----> true
60
 *   t <= s - inf ----> false
61
 *
62
 * The second variant we call "free virtual terms". These terms are intended
63
 * to appear in assertions and are constrained to have the semantics of the
64
 * above virtual terms, e.g.:
65
 *   0 < delta_free
66
 *   forall x. x < inf_free
67
 * We use free virtual terms for some instantiation strategies, e.g. those
68
 * that combine instantiating quantified formulas with nested quantifiers
69
 * with terms containing virtual terms.
70
 */
71
class VtsTermCache
72
{
73
 public:
74
  VtsTermCache(QuantifiersInferenceManager& qim);
75
6323
  ~VtsTermCache() {}
76
  /**
77
   * Get vts delta. The argument isFree indicates if we are getting the
78
   * free variant of delta. If create is false, this method returns Node::null
79
   * if the requested delta has not already been created.
80
   */
81
  Node getVtsDelta(bool isFree = false, bool create = true);
82
  /**
83
   * Get vts infinity of type tn, where tn should be Int or Real.
84
   * The argument isFree indicates if we are getting the free variant of
85
   * infinity. If create is false, this method returns Node::null if the
86
   * requested infinity has not already been created.
87
   */
88
  Node getVtsInfinity(TypeNode tn, bool isFree = false, bool create = true);
89
  /**
90
   * Get all vts terms and add them to vector t.
91
   * If the argument isFree is true, we return the free variant of all virtual
92
   * terms. If create is false, we do not add virtual terms that have not
93
   * already been created. If inc_delta is false, we do not include delta.
94
   */
95
  void getVtsTerms(std::vector<Node>& t,
96
                   bool isFree = false,
97
                   bool create = true,
98
                   bool inc_delta = true);
99
  /**
100
   * Rewrite virtual terms in node n. This returns the rewritten form of n
101
   * after virtual term substitution.
102
   *
103
   * This method ensures that the returned node is equivalent to n and does
104
   * not contain free occurrences of the virtual terms.
105
   */
106
  Node rewriteVtsSymbols(Node n);
107
  /**
108
   * This method returns true iff n contains a virtual term. If isFree is true,
109
   * if returns true iff n contains a free virtual term.
110
   */
111
  bool containsVtsTerm(Node n, bool isFree = false);
112
  /**
113
   * This method returns true iff any term in vector n contains a virtual term.
114
   * If isFree is true, if returns true iff any term in vector n contains a
115
   * free virtual term.
116
   */
117
  bool containsVtsTerm(std::vector<Node>& n, bool isFree = false);
118
  /**
119
   * This method returns true iff n contains an occurence of the virtual term
120
   * infinity. If isFree is true, if returns true iff n contains the free
121
   * virtual term infinity.
122
   */
123
  bool containsVtsInfinity(Node n, bool isFree = false);
124
125
 private:
126
  /** Reference to the quantifiers inference manager */
127
  QuantifiersInferenceManager& d_qim;
128
  /** constants */
129
  Node d_zero;
130
  /** The virtual term substitution delta */
131
  Node d_vts_delta;
132
  /** The virtual term substitution "free delta" */
133
  Node d_vts_delta_free;
134
  /** The virtual term substitution infinities for int/real types */
135
  std::map<TypeNode, Node> d_vts_inf;
136
  /** The virtual term substitution "free infinities" for int/real types */
137
  std::map<TypeNode, Node> d_vts_inf_free;
138
  /** substitute vts terms with their corresponding vts free terms */
139
  Node substituteVtsFreeTerms(Node n);
140
}; /* class TermUtil */
141
142
}  // namespace quantifiers
143
}  // namespace theory
144
}  // namespace cvc5
145
146
#endif /* CVC5__THEORY__QUANTIFIERS__CEGQI__VTS_TERM_CACHE_H */