-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoal.java
More file actions
235 lines (208 loc) · 6.29 KB
/
Goal.java
File metadata and controls
235 lines (208 loc) · 6.29 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
/**
* This file was automatically generated from Goal.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.Z3_goal_prec;
/**
* A goal (aka problem). A goal is essentially a set of formulas, that can be
* solved and/or transformed using tactics and solvers.
**/
public class Goal extends Z3Object
{
/**
* The precision of the goal. <remarks> Goals can be transformed using over
* and under approximations. An under approximation is applied when the
* objective is to find a model for a given goal. An over approximation is
* applied when the objective is to find a proof for a given goal.
* </remarks>
**/
public Z3_goal_prec getPrecision() throws Z3Exception
{
return Z3_goal_prec.fromInt(Native.goalPrecision(getContext().nCtx(),
getNativeObject()));
}
/**
* Indicates whether the goal is precise.
**/
public boolean isPrecise() throws Z3Exception
{
return getPrecision() == Z3_goal_prec.Z3_GOAL_PRECISE;
}
/**
* Indicates whether the goal is an under-approximation.
**/
public boolean isUnderApproximation() throws Z3Exception
{
return getPrecision() == Z3_goal_prec.Z3_GOAL_UNDER;
}
/**
* Indicates whether the goal is an over-approximation.
**/
public boolean isOverApproximation() throws Z3Exception
{
return getPrecision() == Z3_goal_prec.Z3_GOAL_OVER;
}
/**
* Indicates whether the goal is garbage (i.e., the product of over- and
* under-approximations).
**/
public boolean isGarbage() throws Z3Exception
{
return getPrecision() == Z3_goal_prec.Z3_GOAL_UNDER_OVER;
}
/**
* Adds the <paramref name="constraints"/> to the given goal.
*
* @throws Z3Exception
**/
public void add(BoolExpr ... constraints) throws Z3Exception
{
getContext().checkContextMatch(constraints);
for (BoolExpr c : constraints)
{
Native.goalAssert(getContext().nCtx(), getNativeObject(),
c.getNativeObject());
}
}
/**
* Indicates whether the goal contains `false'.
**/
public boolean inconsistent() throws Z3Exception
{
return Native.goalInconsistent(getContext().nCtx(), getNativeObject());
}
/**
* The depth of the goal. <remarks> This tracks how many transformations
* were applied to it. </remarks>
**/
public int getDepth() throws Z3Exception
{
return Native.goalDepth(getContext().nCtx(), getNativeObject());
}
/**
* Erases all formulas from the given goal.
**/
public void reset() throws Z3Exception
{
Native.goalReset(getContext().nCtx(), getNativeObject());
}
/**
* The number of formulas in the goal.
**/
public int size() throws Z3Exception
{
return Native.goalSize(getContext().nCtx(), getNativeObject());
}
/**
* The formulas in the goal.
*
* @throws Z3Exception
**/
public BoolExpr[] getFormulas() throws Z3Exception
{
int n = size();
BoolExpr[] res = new BoolExpr[n];
for (int i = 0; i < n; i++)
res[i] = new BoolExpr(getContext(), Native.goalFormula(getContext()
.nCtx(), getNativeObject(), i));
return res;
}
/**
* The number of formulas, subformulas and terms in the goal.
**/
public int getNumExprs() throws Z3Exception
{
return Native.goalNumExprs(getContext().nCtx(), getNativeObject());
}
/**
* Indicates whether the goal is empty, and it is precise or the product of
* an under approximation.
**/
public boolean isDecidedSat() throws Z3Exception
{
return Native.goalIsDecidedSat(getContext().nCtx(), getNativeObject());
}
/**
* Indicates whether the goal contains `false', and it is precise or the
* product of an over approximation.
**/
public boolean isDecidedUnsat() throws Z3Exception
{
return Native
.goalIsDecidedUnsat(getContext().nCtx(), getNativeObject());
}
/**
* Translates (copies) the Goal to the target Context <paramref
* name="ctx"/>.
*
* @throws Z3Exception
**/
public Goal translate(Context ctx) throws Z3Exception
{
return new Goal(ctx, Native.goalTranslate(getContext().nCtx(),
getNativeObject(), ctx.nCtx()));
}
/**
* Simplifies the goal. <remarks>Essentially invokes the `simplify' tactic
* on the goal.</remarks>
**/
public Goal simplify() throws Z3Exception
{
Tactic t = getContext().mkTactic("simplify");
ApplyResult res = t.apply(this);
if (res.getNumSubgoals() == 0)
throw new Z3Exception("No subgoals");
else
return res.getSubgoals()[0];
}
/**
* Simplifies the goal. <remarks>Essentially invokes the `simplify' tactic
* on the goal.</remarks>
**/
public Goal simplify(Params p) throws Z3Exception
{
Tactic t = getContext().mkTactic("simplify");
ApplyResult res = t.apply(this, p);
if (res.getNumSubgoals() == 0)
throw new Z3Exception("No subgoals");
else
return res.getSubgoals()[0];
}
/**
* Goal to string conversion.
*
* @return A string representation of the Goal.
**/
public String toString()
{
try
{
return Native.goalToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
Goal(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
Goal(Context ctx, boolean models, boolean unsatCores, boolean proofs)
throws Z3Exception
{
super(ctx, Native.mkGoal(ctx.nCtx(), (models) ? true : false,
(unsatCores) ? true : false, (proofs) ? true : false));
}
void incRef(long o) throws Z3Exception
{
getContext().goal_DRQ().incAndClear(getContext(), o);
super.incRef(o);
}
void decRef(long o) throws Z3Exception
{
getContext().goal_DRQ().add(o);
super.decRef(o);
}
}