Go to the documentation of this file.00001
00018 package com.microsoft.z3;
00019
00020 import com.microsoft.z3.enumerations.Z3_goal_prec;
00021
00026 public class Goal extends Z3Object
00027 {
00036 public Z3_goal_prec getPrecision()
00037 {
00038 return Z3_goal_prec.fromInt(Native.goalPrecision(getContext().nCtx(),
00039 getNativeObject()));
00040 }
00041
00045 public boolean isPrecise()
00046 {
00047 return getPrecision() == Z3_goal_prec.Z3_GOAL_PRECISE;
00048 }
00049
00053 public boolean isUnderApproximation()
00054 {
00055 return getPrecision() == Z3_goal_prec.Z3_GOAL_UNDER;
00056 }
00057
00061 public boolean isOverApproximation()
00062 {
00063 return getPrecision() == Z3_goal_prec.Z3_GOAL_OVER;
00064 }
00065
00070 public boolean isGarbage()
00071 {
00072 return getPrecision() == Z3_goal_prec.Z3_GOAL_UNDER_OVER;
00073 }
00074
00080 public void add(BoolExpr ... constraints)
00081 {
00082 getContext().checkContextMatch(constraints);
00083 for (BoolExpr c : constraints)
00084 {
00085 Native.goalAssert(getContext().nCtx(), getNativeObject(),
00086 c.getNativeObject());
00087 }
00088 }
00089
00093 public boolean inconsistent()
00094 {
00095 return Native.goalInconsistent(getContext().nCtx(), getNativeObject());
00096 }
00097
00103 public int getDepth()
00104 {
00105 return Native.goalDepth(getContext().nCtx(), getNativeObject());
00106 }
00107
00111 public void reset()
00112 {
00113 Native.goalReset(getContext().nCtx(), getNativeObject());
00114 }
00115
00119 public int size()
00120 {
00121 return Native.goalSize(getContext().nCtx(), getNativeObject());
00122 }
00123
00129 public BoolExpr[] getFormulas()
00130 {
00131 int n = size();
00132 BoolExpr[] res = new BoolExpr[n];
00133 for (int i = 0; i < n; i++)
00134 res[i] = new BoolExpr(getContext(), Native.goalFormula(getContext()
00135 .nCtx(), getNativeObject(), i));
00136 return res;
00137 }
00138
00142 public int getNumExprs()
00143 {
00144 return Native.goalNumExprs(getContext().nCtx(), getNativeObject());
00145 }
00146
00151 public boolean isDecidedSat()
00152 {
00153 return Native.goalIsDecidedSat(getContext().nCtx(), getNativeObject());
00154 }
00155
00160 public boolean isDecidedUnsat()
00161 {
00162 return Native
00163 .goalIsDecidedUnsat(getContext().nCtx(), getNativeObject());
00164 }
00165
00171 public Goal translate(Context ctx)
00172 {
00173 return new Goal(ctx, Native.goalTranslate(getContext().nCtx(),
00174 getNativeObject(), ctx.nCtx()));
00175 }
00176
00182 public Goal simplify()
00183 {
00184 Tactic t = getContext().mkTactic("simplify");
00185 ApplyResult res = t.apply(this);
00186
00187 if (res.getNumSubgoals() == 0)
00188 throw new Z3Exception("No subgoals");
00189 else
00190 return res.getSubgoals()[0];
00191 }
00192
00198 public Goal simplify(Params p)
00199 {
00200 Tactic t = getContext().mkTactic("simplify");
00201 ApplyResult res = t.apply(this, p);
00202
00203 if (res.getNumSubgoals() == 0)
00204 throw new Z3Exception("No subgoals");
00205 else
00206 return res.getSubgoals()[0];
00207 }
00208
00214 public String toString()
00215 {
00216 try
00217 {
00218 return Native.goalToString(getContext().nCtx(), getNativeObject());
00219 } catch (Z3Exception e)
00220 {
00221 return "Z3Exception: " + e.getMessage();
00222 }
00223 }
00224
00230 public BoolExpr AsBoolExpr() {
00231 int n = size();
00232 if (n == 0)
00233 return getContext().mkTrue();
00234 else if (n == 1)
00235 return getFormulas()[0];
00236 else {
00237 return getContext().mkAnd(getFormulas());
00238 }
00239 }
00240
00241 Goal(Context ctx, long obj)
00242 {
00243 super(ctx, obj);
00244 }
00245
00246 Goal(Context ctx, boolean models, boolean unsatCores, boolean proofs)
00247
00248 {
00249 super(ctx, Native.mkGoal(ctx.nCtx(), (models) ? true : false,
00250 (unsatCores) ? true : false, (proofs) ? true : false));
00251 }
00252
00253 void incRef(long o)
00254 {
00255 getContext().getGoalDRQ().incAndClear(getContext(), o);
00256 super.incRef(o);
00257 }
00258
00259 void decRef(long o)
00260 {
00261 getContext().getGoalDRQ().add(o);
00262 super.decRef(o);
00263 }
00264
00265 }