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 |
|
* Attributes for the theory quantifiers. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__QUANTIFIERS__QUANTIFIERS_ATTRIBUTES_H |
19 |
|
#define CVC5__THEORY__QUANTIFIERS__QUANTIFIERS_ATTRIBUTES_H |
20 |
|
|
21 |
|
#include "expr/attribute.h" |
22 |
|
#include "expr/node.h" |
23 |
|
|
24 |
|
namespace cvc5 { |
25 |
|
namespace theory { |
26 |
|
|
27 |
|
/** Attribute true for function definition quantifiers */ |
28 |
|
struct FunDefAttributeId {}; |
29 |
|
typedef expr::Attribute< FunDefAttributeId, bool > FunDefAttribute; |
30 |
|
|
31 |
|
/** Attribute true for quantifiers that we are doing quantifier elimination on */ |
32 |
|
struct QuantElimAttributeId {}; |
33 |
|
typedef expr::Attribute< QuantElimAttributeId, bool > QuantElimAttribute; |
34 |
|
|
35 |
|
/** Attribute true for quantifiers that we are doing partial quantifier elimination on */ |
36 |
|
struct QuantElimPartialAttributeId {}; |
37 |
|
typedef expr::Attribute< QuantElimPartialAttributeId, bool > QuantElimPartialAttribute; |
38 |
|
|
39 |
|
/** Attribute true for quantifiers that are SyGus conjectures */ |
40 |
|
struct SygusAttributeId {}; |
41 |
|
typedef expr::Attribute< SygusAttributeId, bool > SygusAttribute; |
42 |
|
|
43 |
|
/**Attribute to give names to quantified formulas */ |
44 |
|
struct QuantNameAttributeId |
45 |
|
{ |
46 |
|
}; |
47 |
|
typedef expr::Attribute<QuantNameAttributeId, bool> QuantNameAttribute; |
48 |
|
|
49 |
|
struct InstLevelAttributeId |
50 |
|
{ |
51 |
|
}; |
52 |
|
typedef expr::Attribute<InstLevelAttributeId, uint64_t> InstLevelAttribute; |
53 |
|
|
54 |
|
/** Attribute for setting printing information for sygus variables |
55 |
|
* |
56 |
|
* For variable d of sygus datatype type, if |
57 |
|
* d.getAttribute(SygusPrintProxyAttribute) = t, then printing d will print t. |
58 |
|
*/ |
59 |
|
struct SygusPrintProxyAttributeId |
60 |
|
{ |
61 |
|
}; |
62 |
|
typedef expr::Attribute<SygusPrintProxyAttributeId, Node> |
63 |
|
SygusPrintProxyAttribute; |
64 |
|
|
65 |
|
/** Attribute for specifying a "side condition" for a sygus conjecture |
66 |
|
* |
67 |
|
* A sygus conjecture of the form exists f. forall x. P[f,x] whose side |
68 |
|
* condition is C[f] has the semantics exists f. C[f] ^ forall x. P[f,x]. |
69 |
|
*/ |
70 |
|
struct SygusSideConditionAttributeId |
71 |
|
{ |
72 |
|
}; |
73 |
|
typedef expr::Attribute<SygusSideConditionAttributeId, Node> |
74 |
|
SygusSideConditionAttribute; |
75 |
|
|
76 |
|
/** Attribute for indicating that a sygus variable encodes a term |
77 |
|
* |
78 |
|
* This is used, e.g., for abduction where the formal argument list of the |
79 |
|
* abduct-to-synthesize corresponds to the free variables of the sygus |
80 |
|
* problem. |
81 |
|
*/ |
82 |
|
struct SygusVarToTermAttributeId |
83 |
|
{ |
84 |
|
}; |
85 |
|
typedef expr::Attribute<SygusVarToTermAttributeId, Node> |
86 |
|
SygusVarToTermAttribute; |
87 |
|
|
88 |
|
/** |
89 |
|
* Attribute marked true for types that are used as abstraction types in |
90 |
|
* the finite model finding for function definitions algorithm. |
91 |
|
*/ |
92 |
|
struct AbsTypeFunDefAttributeId |
93 |
|
{ |
94 |
|
}; |
95 |
|
typedef expr::Attribute<AbsTypeFunDefAttributeId, bool> AbsTypeFunDefAttribute; |
96 |
|
|
97 |
|
namespace quantifiers { |
98 |
|
|
99 |
|
/** This struct stores attributes for a single quantified formula */ |
100 |
|
struct QAttributes |
101 |
|
{ |
102 |
|
public: |
103 |
202706 |
QAttributes() |
104 |
202706 |
: d_hasPattern(false), |
105 |
|
d_hasPool(false), |
106 |
|
d_sygus(false), |
107 |
|
d_qinstLevel(-1), |
108 |
|
d_quant_elim(false), |
109 |
|
d_quant_elim_partial(false), |
110 |
202706 |
d_isQuantBounded(false) |
111 |
|
{ |
112 |
202706 |
} |
113 |
202706 |
~QAttributes(){} |
114 |
|
/** does the quantified formula have a pattern? */ |
115 |
|
bool d_hasPattern; |
116 |
|
/** does the quantified formula have a pool? */ |
117 |
|
bool d_hasPool; |
118 |
|
/** if non-null, this quantified formula is a function definition for function |
119 |
|
* d_fundef_f */ |
120 |
|
Node d_fundef_f; |
121 |
|
/** is this formula marked as a sygus conjecture? */ |
122 |
|
bool d_sygus; |
123 |
|
/** side condition for sygus conjectures */ |
124 |
|
Node d_sygusSideCondition; |
125 |
|
/** stores the maximum instantiation level allowed for this quantified formula |
126 |
|
* (-1 means allow any) */ |
127 |
|
int64_t d_qinstLevel; |
128 |
|
/** is this formula marked for quantifier elimination? */ |
129 |
|
bool d_quant_elim; |
130 |
|
/** is this formula marked for partial quantifier elimination? */ |
131 |
|
bool d_quant_elim_partial; |
132 |
|
/** Is this formula internally generated and belonging to bounded integers? */ |
133 |
|
bool d_isQuantBounded; |
134 |
|
/** the instantiation pattern list for this quantified formula (its 3rd child) |
135 |
|
*/ |
136 |
|
Node d_ipl; |
137 |
|
/** The name of this quantified formula, used for :qid */ |
138 |
|
Node d_name; |
139 |
|
/** The (internal) quantifier id associated with this formula */ |
140 |
|
Node d_qid_num; |
141 |
|
/** is this quantified formula a function definition? */ |
142 |
1141912 |
bool isFunDef() const { return !d_fundef_f.isNull(); } |
143 |
|
/** |
144 |
|
* Is this a standard quantifier? A standard quantifier is one that we can |
145 |
|
* perform destructive updates (variable elimination, miniscoping, etc). |
146 |
|
* |
147 |
|
* A quantified formula is not standard if it is sygus, one for which |
148 |
|
* we are performing quantifier elimination, or is a function definition. |
149 |
|
*/ |
150 |
|
bool isStandard() const; |
151 |
|
}; |
152 |
|
|
153 |
|
/** This class caches information about attributes of quantified formulas |
154 |
|
* |
155 |
|
* It also has static utility functions used for determining attributes and |
156 |
|
* information about |
157 |
|
* quantified formulas. |
158 |
|
*/ |
159 |
|
class QuantAttributes |
160 |
|
{ |
161 |
|
public: |
162 |
|
QuantAttributes(); |
163 |
15266 |
~QuantAttributes(){} |
164 |
|
/** set user attribute |
165 |
|
* This function applies an attribute |
166 |
|
* This can be called when we mark expressions with attributes, e.g. (! q |
167 |
|
* :attribute attr [nodeValues]), |
168 |
|
* It can also be called internally in various ways (for SyGus, quantifier |
169 |
|
* elimination, etc.) |
170 |
|
*/ |
171 |
|
static void setUserAttribute(const std::string& attr, |
172 |
|
TNode q, |
173 |
|
const std::vector<Node>& nodeValues); |
174 |
|
|
175 |
|
/** compute quantifier attributes */ |
176 |
|
static void computeQuantAttributes(Node q, QAttributes& qa); |
177 |
|
/** compute the attributes for q */ |
178 |
|
void computeAttributes(Node q); |
179 |
|
|
180 |
|
/** is fun def */ |
181 |
|
static bool checkFunDef( Node q ); |
182 |
|
/** is fun def */ |
183 |
|
static bool checkFunDefAnnotation( Node ipl ); |
184 |
|
/** is sygus conjecture */ |
185 |
|
static bool checkSygusConjecture( Node q ); |
186 |
|
/** is sygus conjecture */ |
187 |
|
static bool checkSygusConjectureAnnotation( Node ipl ); |
188 |
|
/** get fun def body */ |
189 |
|
static Node getFunDefHead( Node q ); |
190 |
|
/** get fun def body */ |
191 |
|
static Node getFunDefBody( Node q ); |
192 |
|
/** is quant elim annotation */ |
193 |
|
static bool checkQuantElimAnnotation( Node ipl ); |
194 |
|
/** does q have a user-provided pattern? */ |
195 |
|
static bool hasPattern(Node q); |
196 |
|
|
197 |
|
/** is function definition */ |
198 |
|
bool isFunDef( Node q ); |
199 |
|
/** is sygus conjecture */ |
200 |
|
bool isSygus( Node q ); |
201 |
|
/** get instantiation level */ |
202 |
|
int64_t getQuantInstLevel(Node q); |
203 |
|
/** is quant elim */ |
204 |
|
bool isQuantElim( Node q ); |
205 |
|
/** is quant elim partial */ |
206 |
|
bool isQuantElimPartial( Node q ); |
207 |
|
/** is internal quantifier */ |
208 |
|
bool isQuantBounded(Node q) const; |
209 |
|
/** get quant name, which is used for :qid */ |
210 |
|
Node getQuantName(Node q) const; |
211 |
|
/** Print quantified formula q, possibly using its name, if it has one */ |
212 |
|
std::string quantToString(Node q) const; |
213 |
|
/** get (internal) quant id num */ |
214 |
|
int getQuantIdNum( Node q ); |
215 |
|
/** get (internal)quant id num */ |
216 |
|
Node getQuantIdNumNode( Node q ); |
217 |
|
|
218 |
|
/** set instantiation level attr */ |
219 |
|
static void setInstantiationLevelAttr(Node n, uint64_t level); |
220 |
|
/** set instantiation level attr */ |
221 |
|
static void setInstantiationLevelAttr(Node n, Node qn, uint64_t level); |
222 |
|
|
223 |
|
private: |
224 |
|
/** cache of attributes */ |
225 |
|
std::map< Node, QAttributes > d_qattr; |
226 |
|
/** function definitions */ |
227 |
|
std::map< Node, bool > d_fun_defs; |
228 |
|
}; |
229 |
|
|
230 |
|
} |
231 |
|
} |
232 |
|
} // namespace cvc5 |
233 |
|
|
234 |
|
#endif |