Z3
src/api/dotnet/InterpolationContext.cs
Go to the documentation of this file.
00001 
00002 /*++
00003 Copyright (c) 2015 Microsoft Corporation
00004 
00005 --*/
00006 
00007 using System;
00008 using System.Collections.Generic;
00009 using System.Linq;
00010 using System.Text;
00011 using System.Diagnostics.Contracts;
00012 using System.Runtime.InteropServices;
00013 
00014 namespace Microsoft.Z3
00015 {
00021     [ContractVerification(true)]
00022     public class InterpolationContext : Context
00023     {
00024 
00028         public InterpolationContext() : base() { }
00029 
00034         public InterpolationContext(Dictionary<string, string> settings) : base(settings) { }
00035 
00036         #region Terms
00037 
00038 
00039 
00040         public BoolExpr MkInterpolant(BoolExpr a)
00041         {
00042             Contract.Requires(a != null);
00043             Contract.Ensures(Contract.Result<BoolExpr>() != null);
00044 
00045             CheckContextMatch(a);
00046             return new BoolExpr(this, Native.Z3_mk_interpolant(nCtx, a.NativeObject));
00047         }
00048         #endregion
00049 
00056         public BoolExpr[] GetInterpolant(Expr pf, Expr pat, Params p)
00057         {
00058             Contract.Requires(pf != null);
00059             Contract.Requires(pat != null);
00060             Contract.Requires(p != null);
00061             Contract.Ensures(Contract.Result<Expr>() != null);
00062 
00063             CheckContextMatch(pf);
00064             CheckContextMatch(pat);
00065             CheckContextMatch(p);
00066 
00067             ASTVector seq = new ASTVector(this, Native.Z3_get_interpolant(nCtx, pf.NativeObject, pat.NativeObject, p.NativeObject));
00068             return seq.ToBoolExprArray();
00069         }
00070 
00077         public Z3_lbool ComputeInterpolant(Expr pat, Params p, out BoolExpr[] interp, out Model model)
00078         {
00079             Contract.Requires(pat != null);
00080             Contract.Requires(p != null);
00081             Contract.Ensures(Contract.ValueAtReturn(out interp) != null);
00082             Contract.Ensures(Contract.ValueAtReturn(out model) != null);
00083 
00084             CheckContextMatch(pat);
00085             CheckContextMatch(p);
00086 
00087             IntPtr i = IntPtr.Zero, m = IntPtr.Zero;
00088             int r = Native.Z3_compute_interpolant(nCtx, pat.NativeObject, p.NativeObject, ref i, ref m);
00089             interp = new ASTVector(this, i).ToBoolExprArray();
00090             model = new Model(this, m);
00091             return (Z3_lbool)r;
00092         }
00093 
00100         public string InterpolationProfile()
00101         {
00102             return Native.Z3_interpolation_profile(nCtx);
00103         }
00104 
00111         public int CheckInterpolant(Expr[] cnsts, uint[] parents, BoolExpr[] interps, out string error, Expr[] theory)
00112         {
00113             Contract.Requires(cnsts.Length == parents.Length);
00114             Contract.Requires(cnsts.Length == interps.Length + 1);
00115             IntPtr n_err_str;
00116             int r = Native.Z3_check_interpolant(nCtx,
00117                                                 (uint)cnsts.Length,
00118                                                 Expr.ArrayToNative(cnsts),
00119                                                 parents,
00120                                                 Expr.ArrayToNative(interps),
00121                                                 out n_err_str,
00122                                                 (uint)theory.Length,
00123                                                 Expr.ArrayToNative(theory));
00124             error = Marshal.PtrToStringAnsi(n_err_str);
00125             return r;
00126         }
00127 
00134         public int ReadInterpolationProblem(string filename, out Expr[] cnsts, out uint[] parents, out string error, out Expr[] theory)
00135         {
00136             uint num = 0, num_theory = 0;
00137             IntPtr[] n_cnsts;
00138             IntPtr[] n_theory;
00139             IntPtr n_err_str;
00140             int r = Native.Z3_read_interpolation_problem(nCtx, ref num, out n_cnsts, out parents, filename, out n_err_str, ref num_theory, out n_theory);
00141             error = Marshal.PtrToStringAnsi(n_err_str);
00142             cnsts = new Expr[num];
00143             parents = new uint[num];
00144             theory = new Expr[num_theory];
00145             for (int i = 0; i < num; i++)
00146                 cnsts[i] = Expr.Create(this, n_cnsts[i]);
00147             for (int i = 0; i < num_theory; i++)
00148                 theory[i] = Expr.Create(this, n_theory[i]);
00149             return r;
00150         }
00151 
00158         public void WriteInterpolationProblem(string filename, Expr[] cnsts, uint[] parents, Expr[] theory)
00159         {
00160             Contract.Requires(cnsts.Length == parents.Length);
00161             Native.Z3_write_interpolation_problem(nCtx, (uint)cnsts.Length, Expr.ArrayToNative(cnsts), parents, filename, (uint)theory.Length, Expr.ArrayToNative(theory));
00162         }
00163     }
00164 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines