Z3
 
Loading...
Searching...
No Matches
Goal.java
Go to the documentation of this file.
1
18package com.microsoft.z3;
19
20import com.microsoft.z3.enumerations.Z3_goal_prec;
21
22import java.lang.ref.ReferenceQueue;
23
28public class Goal extends Z3Object {
38 {
39 return Z3_goal_prec.fromInt(Native.goalPrecision(getContext().nCtx(),
40 getNativeObject()));
41 }
42
46 public boolean isPrecise()
47 {
48 return getPrecision() == Z3_goal_prec.Z3_GOAL_PRECISE;
49 }
50
54 public boolean isUnderApproximation()
55 {
56 return getPrecision() == Z3_goal_prec.Z3_GOAL_UNDER;
57 }
58
62 public boolean isOverApproximation()
63 {
64 return getPrecision() == Z3_goal_prec.Z3_GOAL_OVER;
65 }
66
71 public boolean isGarbage()
72 {
73 return getPrecision() == Z3_goal_prec.Z3_GOAL_UNDER_OVER;
74 }
75
81 @SafeVarargs
82 public final void add(Expr<BoolSort>... constraints)
83 {
84 getContext().checkContextMatch(constraints);
85 for (Expr<BoolSort> c : constraints)
86 {
87 Native.goalAssert(getContext().nCtx(), getNativeObject(),
88 c.getNativeObject());
89 }
90 }
91
95 public boolean inconsistent()
96 {
97 return Native.goalInconsistent(getContext().nCtx(), getNativeObject());
98 }
99
105 public int getDepth()
106 {
107 return Native.goalDepth(getContext().nCtx(), getNativeObject());
108 }
109
113 public void reset()
114 {
115 Native.goalReset(getContext().nCtx(), getNativeObject());
116 }
117
121 public int size()
122 {
123 return Native.goalSize(getContext().nCtx(), getNativeObject());
124 }
125
132 {
133 int n = size();
134 BoolExpr[] res = new BoolExpr[n];
135 for (int i = 0; i < n; i++)
136 res[i] = (BoolExpr) Expr.create(getContext(), Native.goalFormula(getContext().nCtx(), getNativeObject(), i));
137 return res;
138 }
139
143 public int getNumExprs()
144 {
145 return Native.goalNumExprs(getContext().nCtx(), getNativeObject());
146 }
147
152 public boolean isDecidedSat()
153 {
154 return Native.goalIsDecidedSat(getContext().nCtx(), getNativeObject());
155 }
156
161 public boolean isDecidedUnsat()
162 {
163 return Native
164 .goalIsDecidedUnsat(getContext().nCtx(), getNativeObject());
165 }
166
173 {
174 return new Goal(ctx, Native.goalTranslate(getContext().nCtx(),
175 getNativeObject(), ctx.nCtx()));
176 }
177
183 public Goal simplify()
184 {
185 Tactic t = getContext().mkTactic("simplify");
186 ApplyResult res = t.apply(this);
187
188 if (res.getNumSubgoals() == 0)
189 throw new Z3Exception("No subgoals");
190 else
191 return res.getSubgoals()[0];
192 }
193
200 {
201 Tactic t = getContext().mkTactic("simplify");
202 ApplyResult res = t.apply(this, p);
203
204 if (res.getNumSubgoals() == 0)
205 throw new Z3Exception("No subgoals");
206 else
207 return res.getSubgoals()[0];
208 }
209
215 public String toString() {
216 return Native.goalToString(getContext().nCtx(), getNativeObject());
217 }
218
225 int n = size();
226 if (n == 0) {
227 return getContext().mkTrue();
228 } else if (n == 1) {
229 return getFormulas()[0];
230 } else {
231 return getContext().mkAnd(getFormulas());
232 }
233 }
234
235 Goal(Context ctx, long obj)
236 {
237 super(ctx, obj);
238 }
239
240 Goal(Context ctx, boolean models, boolean unsatCores, boolean proofs) {
241 super(ctx, Native.mkGoal(ctx.nCtx(), (models),
242 (unsatCores), (proofs)));
243 }
244
253 {
254 return new Model(getContext(),
255 Native.goalConvertModel(getContext().nCtx(), getNativeObject(), m.getNativeObject()));
256 }
257
258
259
260 @Override
261 void incRef() {
262 Native.goalIncRef(getContext().nCtx(), getNativeObject());
263 }
264
265 @Override
266 void addToReferenceQueue() {
267 getContext().getReferenceQueue().storeReference(this, GoalRef::new);
268 }
269
270 private static class GoalRef extends Z3ReferenceQueue.Reference<Goal> {
271
272 private GoalRef(Goal referent, ReferenceQueue<Z3Object> q) {
273 super(referent, q);
274 }
275
276 @Override
277 void decRef(Context ctx, long z3Obj) {
278 Native.goalDecRef(ctx.nCtx(), z3Obj);
279 }
280 }
281}
Tactic mkTactic(String name)
final BoolExpr mkAnd(Expr< BoolSort >... t)
Definition Context.java:879
boolean isOverApproximation()
Definition Goal.java:62
boolean isUnderApproximation()
Definition Goal.java:54
boolean isGarbage()
Definition Goal.java:71
boolean isPrecise()
Definition Goal.java:46
BoolExpr AsBoolExpr()
Definition Goal.java:224
Z3_goal_prec getPrecision()
Definition Goal.java:37
final void add(Expr< BoolSort >... constraints)
Definition Goal.java:82
Goal translate(Context ctx)
Definition Goal.java:172
boolean isDecidedUnsat()
Definition Goal.java:161
Goal simplify(Params p)
Definition Goal.java:199
Model convertModel(Model m)
Definition Goal.java:252
BoolExpr[] getFormulas()
Definition Goal.java:131
boolean inconsistent()
Definition Goal.java:95
boolean isDecidedSat()
Definition Goal.java:152
ApplyResult apply(Goal g)
Definition Tactic.java:52
Z3_goal_prec
Z3 custom error handler (See Z3_set_error_handler).
Definition z3_api.h:1388