3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-29 20:05:51 +00:00

Interpolation API bugfixes

Signed-off-by: Christoph M. Wintersteiger <cwinter@microsoft.com>
This commit is contained in:
Christoph M. Wintersteiger 2014-10-09 18:08:07 +01:00
parent f0c63e56f3
commit 503ad78bf3
5 changed files with 126 additions and 255 deletions

View file

@ -89,47 +89,6 @@ namespace Microsoft.Z3
return (Z3_lbool)r;
}
/// <summary>
/// Computes an interpolant.
/// </summary>
/// <remarks>For more information on interpolation please refer
/// too the function Z3_compute_interpolant in the C/C++ API, which is
/// well documented.</remarks>
Z3_lbool Interpolate(Expr[] cnsts, uint[] parents, Params options, bool incremental, Expr[] theory, out Expr[] interps, out Model model)
{
Contract.Requires(cnsts != null);
Contract.Requires(parents != null);
Contract.Requires(cnsts.Length == parents.Length);
Contract.Ensures(Contract.ValueAtReturn(out interps) != null);
Contract.Ensures(Contract.ValueAtReturn(out model) != null);
CheckContextMatch(cnsts);
CheckContextMatch(theory);
uint sz = (uint)cnsts.Length;
IntPtr[] ni = new IntPtr[sz - 1];
IntPtr nm = IntPtr.Zero;
IntPtr z = IntPtr.Zero;
int r = Native.Z3_interpolate(nCtx,
sz, Expr.ArrayToNative(cnsts), parents,
options.NativeObject,
out ni,
ref nm,
ref z, // Z3_lterals are deprecated.
(uint)(incremental ? 1 : 0),
(uint)theory.Length, Expr.ArrayToNative(theory));
interps = new Expr[sz - 1];
for (uint i = 0; i < sz - 1; i++)
interps[i] = Expr.Create(this, ni[i]);
model = new Model(this, nm);
return (Z3_lbool)r;
}
/// <summary>
/// Return a string summarizing cumulative time used for interpolation.
/// </summary>
@ -150,7 +109,7 @@ namespace Microsoft.Z3
public int CheckInterpolant(Expr[] cnsts, uint[] parents, Expr[] interps, out string error, Expr[] theory)
{
Contract.Requires(cnsts.Length == parents.Length);
Contract.Requires(cnsts.Length == interps.Length+1);
Contract.Requires(cnsts.Length == interps.Length + 1);
IntPtr n_err_str;
int r = Native.Z3_check_interpolant(nCtx,
(uint)cnsts.Length,
@ -170,25 +129,27 @@ namespace Microsoft.Z3
/// <remarks>For more information on interpolation please refer
/// too the function Z3_read_interpolation_problem in the C/C++ API, which is
/// well documented.</remarks>
public int ReadInterpolationProblem(string filename, out Expr[] cnsts, out uint[] parents, out string error, out Expr[] theory)
public int ReadInterpolationProblem(string filename, out Expr[] cnsts, ref uint[] parents, out string error, out Expr[] theory)
{
uint num = 0, num_theory = 0;
IntPtr[] n_cnsts;
IntPtr[] n_theory;
IntPtr n_cnsts = new IntPtr();
IntPtr n_theory = new IntPtr();
IntPtr n_err_str;
uint[][] n_parents;
int r = Native.Z3_read_interpolation_problem(nCtx, ref num, out n_cnsts, out n_parents, filename, out n_err_str, ref num_theory, out n_theory);
int r = Native.Z3_read_interpolation_problem(nCtx, ref num, ref n_cnsts, out parents, filename, out n_err_str, ref num_theory, ref n_theory);
error = Marshal.PtrToStringAnsi(n_err_str);
cnsts = new Expr[num];
parents = new uint[num];
theory = new Expr[num_theory];
theory = new Expr[num_theory];
for (int i = 0; i < num; i++)
{
cnsts[i] = Expr.Create(this, n_cnsts[i]);
parents[i] = n_parents[0][i];
IntPtr ce = new IntPtr(n_cnsts.ToInt64() + (IntPtr.Size * i));
cnsts[i] = Expr.Create(this, ce);
}
for (int i = 0; i < num_theory; i++)
theory[i] = Expr.Create(this, n_theory[i]);
{
IntPtr te = new IntPtr(n_theory.ToInt64() + (IntPtr.Size * i));
theory[i] = Expr.Create(this, te);
}
return r;
}