00001
00018 package com.microsoft.z3;
00019
00020 import java.util.Map;
00021 import java.lang.String;
00022
00023 import com.microsoft.z3.enumerations.Z3_lbool;
00024
00031 public class InterpolationContext extends Context
00032 {
00036 public InterpolationContext()
00037 {
00038 m_ctx = Native.mkInterpolationContext(0);
00039 initContext();
00040 }
00041
00049 public InterpolationContext(Map<String, String> settings)
00050 {
00051 long cfg = Native.mkConfig();
00052 for (Map.Entry<String, String> kv : settings.entrySet())
00053 Native.setParamValue(cfg, kv.getKey(), kv.getValue());
00054 m_ctx = Native.mkInterpolationContext(cfg);
00055 Native.delConfig(cfg);
00056 initContext();
00057 }
00058
00063 public BoolExpr MkInterpolant(BoolExpr a)
00064 {
00065 checkContextMatch(a);
00066 return new BoolExpr(this, Native.mkInterpolant(nCtx(), a.getNativeObject()));
00067 }
00068
00076 public BoolExpr[] GetInterpolant(Expr pf, Expr pat, Params p)
00077 {
00078 checkContextMatch(pf);
00079 checkContextMatch(pat);
00080 checkContextMatch(p);
00081
00082 ASTVector seq = new ASTVector(this, Native.getInterpolant(nCtx(), pf.getNativeObject(), pat.getNativeObject(), p.getNativeObject()));
00083 return seq.ToBoolExprArray();
00084 }
00085
00086 public class ComputeInterpolantResult
00087 {
00088 public Z3_lbool status = Z3_lbool.Z3_L_UNDEF;
00089 public BoolExpr[] interp = null;
00090 public Model model = null;
00091 };
00092
00100 public ComputeInterpolantResult ComputeInterpolant(Expr pat, Params p)
00101 {
00102 checkContextMatch(pat);
00103 checkContextMatch(p);
00104
00105 ComputeInterpolantResult res = new ComputeInterpolantResult();
00106 Native.LongPtr n_i = new Native.LongPtr();
00107 Native.LongPtr n_m = new Native.LongPtr();
00108 res.status = Z3_lbool.fromInt(Native.computeInterpolant(nCtx(), pat.getNativeObject(), p.getNativeObject(), n_i, n_m));
00109 if (res.status == Z3_lbool.Z3_L_FALSE)
00110 res.interp = (new ASTVector(this, n_i.value)).ToBoolExprArray();
00111 if (res.status == Z3_lbool.Z3_L_TRUE)
00112 res.model = new Model(this, n_m.value);
00113 return res;
00114 }
00115
00122 public String InterpolationProfile()
00123 {
00124 return Native.interpolationProfile(nCtx());
00125 }
00126
00127 public class CheckInterpolantResult
00128 {
00129 public int return_value = 0;
00130 public String error = null;
00131 }
00132
00139 public CheckInterpolantResult CheckInterpolant(Expr[] cnsts, int[] parents, BoolExpr[] interps, String error, Expr[] theory)
00140 {
00141 CheckInterpolantResult res = new CheckInterpolantResult();
00142 Native.StringPtr n_err_str = new Native.StringPtr();
00143 res.return_value = Native.checkInterpolant(nCtx(),
00144 cnsts.length,
00145 Expr.arrayToNative(cnsts),
00146 parents,
00147 Expr.arrayToNative(interps),
00148 n_err_str,
00149 theory.length,
00150 Expr.arrayToNative(theory));
00151 res.error = n_err_str.value;
00152 return res;
00153 }
00154
00155 public class ReadInterpolationProblemResult
00156 {
00157 public int return_value = 0;
00158 public Expr[] cnsts;
00159 public int[] parents;
00160 public String error;
00161 public Expr[] theory;
00162 };
00163
00170 public ReadInterpolationProblemResult ReadInterpolationProblem(String filename, Expr[] cnsts, int[] parents, String error, Expr[] theory)
00171 {
00172 ReadInterpolationProblemResult res = new ReadInterpolationProblemResult();
00173
00174 Native.IntPtr n_num = new Native.IntPtr();
00175 Native.IntPtr n_num_theory = new Native.IntPtr();
00176 Native.ObjArrayPtr n_cnsts = new Native.ObjArrayPtr();
00177 Native.UIntArrayPtr n_parents = new Native.UIntArrayPtr();
00178 Native.ObjArrayPtr n_theory = new Native.ObjArrayPtr();
00179 Native.StringPtr n_err_str = new Native.StringPtr();
00180 res.return_value = Native.readInterpolationProblem(nCtx(), n_num, n_cnsts, n_parents, filename, n_err_str, n_num_theory, n_theory);
00181 int num = n_num.value;
00182 int num_theory = n_num_theory.value;
00183 res.error = n_err_str.value;
00184 res.cnsts = new Expr[num];
00185 res.parents = new int[num];
00186 theory = new Expr[num_theory];
00187 for (int i = 0; i < num; i++)
00188 {
00189 res.cnsts[i] = Expr.create(this, n_cnsts.value[i]);
00190 res.parents[i] = n_parents.value[i];
00191 }
00192 for (int i = 0; i < num_theory; i++)
00193 res.theory[i] = Expr.create(this, n_theory.value[i]);
00194 return res;
00195 }
00196
00203 public void WriteInterpolationProblem(String filename, Expr[] cnsts, int[] parents, String error, Expr[] theory)
00204 {
00205 Native.writeInterpolationProblem(nCtx(), cnsts.length, Expr.arrayToNative(cnsts), parents, filename, theory.length, Expr.arrayToNative(theory));
00206 }
00207 }