-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixedpoint.java
More file actions
331 lines (290 loc) · 9.54 KB
/
Fixedpoint.java
File metadata and controls
331 lines (290 loc) · 9.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/**
* This file was automatically generated from Fixedpoint.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.Z3_lbool;
/**
* Object for managing fixedpoints
**/
public class Fixedpoint extends Z3Object
{
/**
* A string that describes all available fixedpoint solver parameters.
**/
public String getHelp() throws Z3Exception
{
return Native.fixedpointGetHelp(getContext().nCtx(), getNativeObject());
}
/**
* Sets the fixedpoint solver parameters.
*
* @throws Z3Exception
**/
public void setParameters(Params value) throws Z3Exception
{
getContext().checkContextMatch(value);
Native.fixedpointSetParams(getContext().nCtx(), getNativeObject(),
value.getNativeObject());
}
/**
* Retrieves parameter descriptions for Fixedpoint solver.
*
* @throws Z3Exception
**/
public ParamDescrs getParameterDescriptions() throws Z3Exception
{
return new ParamDescrs(getContext(), Native.fixedpointGetParamDescrs(
getContext().nCtx(), getNativeObject()));
}
/**
* Assert a constraint (or multiple) into the fixedpoint solver.
*
* @throws Z3Exception
**/
public void add(BoolExpr ... constraints) throws Z3Exception
{
getContext().checkContextMatch(constraints);
for (BoolExpr a : constraints)
{
Native.fixedpointAssert(getContext().nCtx(), getNativeObject(),
a.getNativeObject());
}
}
/**
* Register predicate as recursive relation.
*
* @throws Z3Exception
**/
public void registerRelation(FuncDecl f) throws Z3Exception
{
getContext().checkContextMatch(f);
Native.fixedpointRegisterRelation(getContext().nCtx(), getNativeObject(),
f.getNativeObject());
}
/**
* Add rule into the fixedpoint solver.
*
* @throws Z3Exception
**/
public void addRule(BoolExpr rule, Symbol name) throws Z3Exception
{
getContext().checkContextMatch(rule);
Native.fixedpointAddRule(getContext().nCtx(), getNativeObject(),
rule.getNativeObject(), getNativeObject(name));
}
/**
* Add table fact to the fixedpoint solver.
*
* @throws Z3Exception
**/
public void addFact(FuncDecl pred, int ... args) throws Z3Exception
{
getContext().checkContextMatch(pred);
Native.fixedpointAddFact(getContext().nCtx(), getNativeObject(),
pred.getNativeObject(), (int) args.length, args);
}
/**
* Query the fixedpoint solver. A query is a conjunction of constraints. The
* constraints may include the recursively defined relations. The query is
* satisfiable if there is an instance of the query variables and a
* derivation for it. The query is unsatisfiable if there are no derivations
* satisfying the query variables.
*
* @throws Z3Exception
**/
public Status query(BoolExpr query) throws Z3Exception
{
getContext().checkContextMatch(query);
Z3_lbool r = Z3_lbool.fromInt(Native.fixedpointQuery(getContext().nCtx(),
getNativeObject(), query.getNativeObject()));
switch (r)
{
case Z3_L_TRUE:
return Status.SATISFIABLE;
case Z3_L_FALSE:
return Status.UNSATISFIABLE;
default:
return Status.UNKNOWN;
}
}
/**
* Query the fixedpoint solver. A query is an array of relations. The query
* is satisfiable if there is an instance of some relation that is
* non-empty. The query is unsatisfiable if there are no derivations
* satisfying any of the relations.
*
* @throws Z3Exception
**/
public Status query(FuncDecl[] relations) throws Z3Exception
{
getContext().checkContextMatch(relations);
Z3_lbool r = Z3_lbool.fromInt(Native.fixedpointQueryRelations(getContext()
.nCtx(), getNativeObject(), arrayLength(relations), arrayToNative(relations)));
switch (r)
{
case Z3_L_TRUE:
return Status.SATISFIABLE;
case Z3_L_FALSE:
return Status.UNSATISFIABLE;
default:
return Status.UNKNOWN;
}
}
/**
* Creates a backtracking point. <seealso cref="Pop"/>
**/
public void push() throws Z3Exception
{
Native.fixedpointPush(getContext().nCtx(), getNativeObject());
}
/**
* Backtrack one backtracking point. <remarks>Note that an exception is
* thrown if Pop is called without a corresponding <code>Push</code>
* </remarks> <seealso cref="Push"/>
**/
public void pop() throws Z3Exception
{
Native.fixedpointPop(getContext().nCtx(), getNativeObject());
}
/**
* Update named rule into in the fixedpoint solver.
*
* @throws Z3Exception
**/
public void updateRule(BoolExpr rule, Symbol name) throws Z3Exception
{
getContext().checkContextMatch(rule);
Native.fixedpointUpdateRule(getContext().nCtx(), getNativeObject(),
rule.getNativeObject(), getNativeObject(name));
}
/**
* Retrieve satisfying instance or instances of solver, or definitions for
* the recursive predicates that show unsatisfiability.
*
* @throws Z3Exception
**/
public Expr getAnswer() throws Z3Exception
{
long ans = Native.fixedpointGetAnswer(getContext().nCtx(), getNativeObject());
return (ans == 0) ? null : Expr.create(getContext(), ans);
}
/**
* Retrieve explanation why fixedpoint engine returned status Unknown.
**/
public String getReasonUnknown() throws Z3Exception
{
return Native.fixedpointGetReasonUnknown(getContext().nCtx(),
getNativeObject());
}
/**
* Retrieve the number of levels explored for a given predicate.
**/
public int getNumLevels(FuncDecl predicate) throws Z3Exception
{
return Native.fixedpointGetNumLevels(getContext().nCtx(), getNativeObject(),
predicate.getNativeObject());
}
/**
* Retrieve the cover of a predicate.
*
* @throws Z3Exception
**/
public Expr getCoverDelta(int level, FuncDecl predicate) throws Z3Exception
{
long res = Native.fixedpointGetCoverDelta(getContext().nCtx(),
getNativeObject(), level, predicate.getNativeObject());
return (res == 0) ? null : Expr.create(getContext(), res);
}
/**
* Add <tt>property</tt> about the <tt>predicate</tt>. The property is added
* at <tt>level</tt>.
**/
public void addCover(int level, FuncDecl predicate, Expr property)
throws Z3Exception
{
Native.fixedpointAddCover(getContext().nCtx(), getNativeObject(), level,
predicate.getNativeObject(), property.getNativeObject());
}
/**
* Retrieve internal string representation of fixedpoint object.
**/
public String toString()
{
try
{
return Native.fixedpointToString(getContext().nCtx(), getNativeObject(),
0, null);
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
/**
* Instrument the Datalog engine on which table representation to use for
* recursive predicate.
**/
public void setPredicateRepresentation(FuncDecl f, Symbol[] kinds) throws Z3Exception
{
Native.fixedpointSetPredicateRepresentation(getContext().nCtx(),
getNativeObject(), f.getNativeObject(), arrayLength(kinds),
arrayToNative(kinds));
}
/**
* Convert benchmark given as set of axioms, rules and queries to a string.
**/
public String toString(BoolExpr[] queries) throws Z3Exception
{
return Native.fixedpointToString(getContext().nCtx(), getNativeObject(),
arrayLength(queries), arrayToNative(queries));
}
/**
* Retrieve set of rules added to fixedpoint context.
*
* @throws Z3Exception
**/
public BoolExpr[] getRules() throws Z3Exception
{
ASTVector v = new ASTVector(getContext(), Native.fixedpointGetRules(
getContext().nCtx(), getNativeObject()));
int n = v.size();
BoolExpr[] res = new BoolExpr[n];
for (int i = 0; i < n; i++)
res[i] = new BoolExpr(getContext(), v.get(i).getNativeObject());
return res;
}
/**
* Retrieve set of assertions added to fixedpoint context.
*
* @throws Z3Exception
**/
public BoolExpr[] getAssertions() throws Z3Exception
{
ASTVector v = new ASTVector(getContext(), Native.fixedpointGetAssertions(
getContext().nCtx(), getNativeObject()));
int n = v.size();
BoolExpr[] res = new BoolExpr[n];
for (int i = 0; i < n; i++)
res[i] = new BoolExpr(getContext(), v.get(i).getNativeObject());
return res;
}
Fixedpoint(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
Fixedpoint(Context ctx) throws Z3Exception
{
super(ctx, Native.mkFixedpoint(ctx.nCtx()));
}
void incRef(long o) throws Z3Exception
{
getContext().fixedpoint_DRQ().incAndClear(getContext(), o);
super.incRef(o);
}
void decRef(long o) throws Z3Exception
{
getContext().fixedpoint_DRQ().add(o);
super.decRef(o);
}
}