internal DatatypeSort(Context ctx, Symbol name, Constructor[] constructors) : base(ctx, Native.Z3_mk_datatype(ctx.nCtx, name.NativeObject, (uint)constructors.Length, ArrayToNative(constructors))) { Contract.Requires(ctx != null); Contract.Requires(name != null); Contract.Requires(constructors != null); }
internal Quantifier(Context ctx, bool isForall, Expr[] bound, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) : base(ctx) { Contract.Requires(ctx != null); Contract.Requires(body != null); Contract.Requires(patterns == null || Contract.ForAll(patterns, p => p != null)); Contract.Requires(noPatterns == null || Contract.ForAll(noPatterns, np => np != null)); Contract.Requires(bound == null || Contract.ForAll(bound, n => n != null)); Context.CheckContextMatch(noPatterns); Context.CheckContextMatch(patterns); //Context.CheckContextMatch(bound); Context.CheckContextMatch(body); if (noPatterns == null && quantifierID == null && skolemID == null) { NativeObject = Native.Z3_mk_quantifier_const(ctx.nCtx, (isForall) ? 1 : 0, weight, AST.ArrayLength(bound), AST.ArrayToNative(bound), AST.ArrayLength(patterns), AST.ArrayToNative(patterns), body.NativeObject); } else { NativeObject = Native.Z3_mk_quantifier_const_ex(ctx.nCtx, (isForall) ? 1 : 0, weight, AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID), AST.ArrayLength(bound), AST.ArrayToNative(bound), AST.ArrayLength(patterns), AST.ArrayToNative(patterns), AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns), body.NativeObject); } }
internal ObjectTheoremResult(Context context, Environment environment, Solver solver, Microsoft.Z3.Status status) { _context = context; _environment = environment; _solver = solver; Status = (Status)status; }
internal ArraySort(Context ctx, Sort domain, Sort range) : base(ctx, Native.Z3_mk_array_sort(ctx.nCtx, domain.NativeObject, range.NativeObject)) { Contract.Requires(ctx != null); Contract.Requires(domain != null); Contract.Requires(range != null); }
public Context() { // TODO: Add configuration options if necessary this.context = new Microsoft.Z3.Context(); this.ExpressionConverter = new ExpressionConverter(this.context); }
protected override void AddControllerOverflow(Microsoft.Z3.Context ctx, Microsoft.Z3.Solver solver, string varName) { FixedPointNumber var = discreteVariablesByName[varName]; FixedPointNumber expr = assigns[varName]; solver.Assert(expr.overflow); }
/// <summary> /// Z3 expr to C# pretty printer /// </summary> public CSPrettyPrinter(Context z3) { this.charSort = z3.MkBitVecSort(16); this.tt = z3.MkBool(true); this.ff = z3.MkBool(false); this.encoding = 16; }
public static Expr EeAndGt(String left1, int left2, String right1, int right2) { using (Context ctx = new Context()) { Expr a = ctx.MkConst(left1, ctx.MkIntSort()); Expr b = ctx.MkNumeral(left2, ctx.MkIntSort()); Expr c = ctx.MkConst(right1, ctx.MkIntSort()); Expr d = ctx.MkNumeral(right2, ctx.MkIntSort()); Solver s = ctx.MkSolver(); s.Assert(ctx.MkAnd(ctx.MkEq((ArithExpr)a, (ArithExpr)b), ctx.MkGt((ArithExpr)c, (ArithExpr)d))); s.Check(); BoolExpr testing = ctx.MkAnd(ctx.MkEq((ArithExpr)a, (ArithExpr)b), ctx.MkGt((ArithExpr)c, (ArithExpr)d)); Model model = Check(ctx, testing, Status.SATISFIABLE); Expr result2; Model m2 = s.Model; foreach (FuncDecl d2 in m2.Decls) { result2 = m2.ConstInterp(d2); return result2; } } return null; }
/// <summary> /// Translates all ASTs in the vector to <paramref name="ctx"/>. /// </summary> /// <param name="ctx">A context</param> /// <returns>A new ASTVector</returns> public ASTVector Translate(Context ctx) { Contract.Requires(ctx != null); Contract.Ensures(Contract.Result<ASTVector>() != null); return new ASTVector(Context, Native.Z3_ast_vector_translate(Context.nCtx, NativeObject, ctx.nCtx)); }
/// <summary> /// Show that <code>distinct(a_0, ... , a_n)</code> is /// unsatisfiable when <code>a_i</code>'s are arrays from boolean to /// boolean and n > 4. /// </summary> /// <remarks>This example also shows how to use the <code>distinct</code> construct.</remarks> public static void ArrayExample3(Context ctx) { Console.WriteLine("ArrayExample3"); for (int n = 2; n <= 5; n++) { Console.WriteLine("n = {0}", n); Sort bool_type = ctx.MkBoolSort(); Sort array_type = ctx.MkArraySort(bool_type, bool_type); Expr[] a = new Expr[n]; /* create arrays */ for (int i = 0; i < n; i++) { a[i] = ctx.MkConst(String.Format("array_{0}", i), array_type); } /* assert distinct(a[0], ..., a[n]) */ BoolExpr d = ctx.MkDistinct(a); Console.WriteLine("{0}", (d)); /* context is satisfiable if n < 5 */ Model model = Check(ctx, d, n < 5 ? Status.SATISFIABLE : Status.UNSATISFIABLE); if (n < 5) { for (int i = 0; i < n; i++) { Console.WriteLine("{0} = {1}", a[i], model.Evaluate(a[i])); } } } }
internal FiniteDomainSort(Context ctx, Symbol name, ulong size) : base(ctx, Native.Z3_mk_finite_domain_sort(ctx.nCtx, name.NativeObject, size)) { Contract.Requires(ctx != null); Contract.Requires(name != null); }
/// <summary> /// Prove <tt>store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))</tt>. /// </summary> /// <remarks>This example demonstrates how to use the array theory.</remarks> public static void ArrayExample2(Context ctx) { Console.WriteLine("ArrayExample2"); Sort int_type = ctx.IntSort; Sort array_type = ctx.MkArraySort(int_type, int_type); ArrayExpr a1 = (ArrayExpr)ctx.MkConst("a1", array_type); ArrayExpr a2 = ctx.MkArrayConst("a2", int_type, int_type); Expr i1 = ctx.MkConst("i1", int_type); Expr i2 = ctx.MkConst("i2", int_type); Expr i3 = ctx.MkConst("i3", int_type); Expr v1 = ctx.MkConst("v1", int_type); Expr v2 = ctx.MkConst("v2", int_type); Expr st1 = ctx.MkStore(a1, i1, v1); Expr st2 = ctx.MkStore(a2, i2, v2); Expr sel1 = ctx.MkSelect(a1, i3); Expr sel2 = ctx.MkSelect(a2, i3); /* create antecedent */ BoolExpr antecedent = ctx.MkEq(st1, st2); /* create consequent: i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3) */ BoolExpr consequent = ctx.MkOr(new BoolExpr[] { ctx.MkEq(i1, i3), ctx.MkEq(i2, i3), ctx.MkEq(sel1, sel2) }); /* prove store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3)) */ BoolExpr thm = ctx.MkImplies(antecedent, consequent); Console.WriteLine("prove: store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))"); Console.WriteLine("{0}", (thm)); Prove(ctx, thm); }
internal void IncAndClear(Context ctx, IntPtr o) { Contract.Requires(ctx != null); IncRef(ctx, o); if (m_queue.Count >= m_move_limit) Clear(ctx); }
/// <summary> /// Checks whether the assertions in the context are consistent or not. /// </summary> public static Status Check(Context ctx, List<BoolExpr> core, ref Model model, ref Expr proof, params Expr[] assumptions) { Z3_lbool r; model = null; proof = null; if (assumptions == null || assumptions.Length == 0) r = (Z3_lbool)Native.Z3_check(ctx.nCtx); else { IntPtr mdl = IntPtr.Zero, prf = IntPtr.Zero; uint core_size = 0; IntPtr[] native_core = new IntPtr[assumptions.Length]; r = (Z3_lbool)Native.Z3_check_assumptions(ctx.nCtx, (uint)assumptions.Length, AST.ArrayToNative(assumptions), ref mdl, ref prf, ref core_size, native_core); for (uint i = 0; i < core_size; i++) core.Add((BoolExpr)Expr.Create(ctx, native_core[i])); if (mdl != IntPtr.Zero) { model = new Model(ctx, mdl); } if (prf != IntPtr.Zero) { proof = Expr.Create(ctx, prf); } } switch (r) { case Z3_lbool.Z3_L_TRUE: return Status.SATISFIABLE; case Z3_lbool.Z3_L_FALSE: return Status.UNSATISFIABLE; default: return Status.UNKNOWN; } }
internal Z3Object(Context ctx) { Contract.Requires(ctx != null); Interlocked.Increment(ref ctx.refCount); m_ctx = ctx; }
public Expression Visit(Expression exp) { using (Context ctx = new Context()) { if (exp == null) return exp; switch (exp.NodeType) { case ExpressionType.Or: // The VisitBinary method collects Z3 constraints by recursively walking the expression tree var binExpr = VisitBinary((BinaryExpression)exp); // When you get the results back, put them into a Z3 "or" expression //ctx.MkOr(binExpr[0], binExpr[1]); // TODO return the Z3 expression to be solved return null; case ExpressionType.LessThan: VisitBinary((BinaryExpression)exp); return null; case ExpressionType.Parameter: // parameter found return null; } } return exp; }
protected List<Microsoft.Z3.BoolExpr> VisitBinary(BinaryExpression b) { // Use recursion to generate Z3 constraints for each operand of the binary expression // left side -> create a Z3 expression representing the left side Expression left = Visit(b.Left); // right side -> creat a Z3 expression representing the right side Expression right = Visit(b.Right); // Put those into a Z3 format ExpressionType op = b.NodeType; using (Context ctx = new Context()) { if (op == ExpressionType.LessThan) { // ctx.MkLt(left, right); } } Console.WriteLine(b.ToString()); // TODO - return a Z3 expression return null; }
static void Prove(Z3.Context ctx, BoolExpr f, bool useMBQI = false, params BoolExpr[] assumptions) { Console.WriteLine("Proving: " + f); Solver s = ctx.MkSolver(); Params p = ctx.MkParams(); p.Add("mbqi", useMBQI); s.Parameters = p; foreach (BoolExpr a in assumptions) { s.Assert(a); } s.Assert(ctx.MkNot(f)); Status q = s.Check(); switch (q) { case Status.UNKNOWN: Console.WriteLine("Unknown because: " + s.ReasonUnknown); break; case Status.SATISFIABLE: throw new Exception("Test failed"); case Status.UNSATISFIABLE: Console.WriteLine("OK, proof: " + s.Proof); break; } }
internal Z3Object(Context ctx) { Contract.Requires(ctx != null); ctx.refCount++; m_ctx = ctx; }
/// <summary> /// Add controller code for output/memory variable 'var' /// </summary> /// <param name="ctx"></param> /// <param name="solver"></param> /// <param name="variable"></param> protected override void AddController(Microsoft.Z3.Context ctx, Microsoft.Z3.Solver solver, string varName) { FixedPointNumber var = discreteVariablesByName[varName]; FixedPointNumber expr = assigns[varName]; BoolExprWithOverflow assert = ctx.MkFPEq(var, expr); solver.Assert(assert.bv); }
internal ConstructorList(Context ctx, Constructor[] constructors) : base(ctx) { Contract.Requires(ctx != null); Contract.Requires(constructors != null); NativeObject = Native.Z3_mk_constructor_list(Context.nCtx, (uint)constructors.Length, Constructor.ArrayToNative(constructors)); }
internal Z3Object(Context ctx, IntPtr obj) { Contract.Requires(ctx != null); Interlocked.Increment(ref ctx.refCount); m_ctx = ctx; IncRef(obj); m_n_obj = obj; }
internal Z3Object(Context ctx, IntPtr obj) { Contract.Requires(ctx != null); ctx.refCount++; m_ctx = ctx; IncRef(obj); m_n_obj = obj; }
internal static FuncDecl GetOrAddMemberAccessFunction(Context context, Environment environment, MemberInfo memberInfo) { FuncDecl memberFunc; if (!environment.Members.TryGetValue(memberInfo, out memberFunc)) { Sort memberTypeSort; if (!environment.Types.TryGetValue(memberInfo.DeclaringType, out memberTypeSort)) { throw new KeyNotFoundException(memberInfo.DeclaringType + " could not be found at environment.Types"); } Sort memberReturnTypeEnumSort; var propertyType = ((PropertyInfo)memberInfo).PropertyType; if (propertyType == typeof(bool)) memberReturnTypeEnumSort = context.MkBoolSort(); else if (propertyType == typeof(int)) memberReturnTypeEnumSort = context.MkIntSort(); else if (propertyType == typeof(long)) memberReturnTypeEnumSort = context.MkRealSort(); else if (propertyType == typeof(string)) memberReturnTypeEnumSort = environment.PossibleStringValues; else { if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) { var listItemType = propertyType.GenericTypeArguments[0]; var listSort = context.MkSetSort(environment.Types[listItemType]); memberReturnTypeEnumSort = listSort; // TODO: add TryGetValue environment.Types.Add(propertyType, listSort); } else if (propertyType.IsEnum) { EnumSort enumSort = context.MkEnumSort(propertyType.Name, Enum.GetNames(propertyType)); memberReturnTypeEnumSort = enumSort; // TODO: add TryGetValue environment.Types.Add(propertyType, enumSort); } else { // TODO throw exception if type is not supported memberReturnTypeEnumSort = environment.Types[propertyType]; } } memberFunc = context.MkFuncDecl(memberInfo.Name, memberTypeSort, memberReturnTypeEnumSort); environment.Members.Add(memberInfo, memberFunc); } return memberFunc; }
internal void Clear(Context ctx) { Contract.Requires(ctx != null); lock (m_lock) { foreach (IntPtr o in m_queue) DecRef(ctx, o); m_queue.Clear(); } }
/// <summary> /// Assert a constraint (or multiple) into the solver. /// </summary> public static void Assert(Context ctx, params BoolExpr[] constraints) { Contract.Requires(constraints != null); Contract.Requires(Contract.ForAll(constraints, c => c != null)); ctx.CheckContextMatch(constraints); foreach (BoolExpr a in constraints) { Native.Z3_assert_cnstr(ctx.nCtx, a.NativeObject); } }
internal TupleSort(Context ctx, Symbol name, uint numFields, Symbol[] fieldNames, Sort[] fieldSorts) : base(ctx) { Contract.Requires(ctx != null); Contract.Requires(name != null); IntPtr t = IntPtr.Zero; NativeObject = Native.Z3_mk_tuple_sort(ctx.nCtx, name.NativeObject, numFields, Symbol.ArrayToNative(fieldNames), AST.ArrayToNative(fieldSorts), ref t, new IntPtr[numFields]); }
/// <summary> /// Create axiom: function f is injective in the i-th argument. /// </summary> /// <remarks> /// The following axiom is produced: /// <c> /// forall (x_0, ..., x_n) finv(f(x_0, ..., x_i, ..., x_{n-1})) = x_i /// </c> /// Where, <code>finv</code>is a fresh function declaration. /// </summary> public static BoolExpr InjAxiom(Context ctx, FuncDecl f, int i) { Sort[] domain = f.Domain; uint sz = f.DomainSize; if (i >= sz) { Console.WriteLine("failed to create inj axiom"); return null; } /* declare the i-th inverse of f: finv */ Sort finv_domain = f.Range; Sort finv_range = domain[i]; FuncDecl finv = ctx.MkFuncDecl("f_fresh", finv_domain, finv_range); /* allocate temporary arrays */ Expr[] xs = new Expr[sz]; Symbol[] names = new Symbol[sz]; Sort[] types = new Sort[sz]; /* fill types, names and xs */ for (uint j = 0; j < sz; j++) { types[j] = domain[j]; names[j] = ctx.MkSymbol(String.Format("x_{0}", j)); xs[j] = ctx.MkBound(j, types[j]); } Expr x_i = xs[i]; /* create f(x_0, ..., x_i, ..., x_{n-1}) */ Expr fxs = f[xs]; /* create f_inv(f(x_0, ..., x_i, ..., x_{n-1})) */ Expr finv_fxs = finv[fxs]; /* create finv(f(x_0, ..., x_i, ..., x_{n-1})) = x_i */ Expr eq = ctx.MkEq(finv_fxs, x_i); /* use f(x_0, ..., x_i, ..., x_{n-1}) as the pattern for the quantifier */ Pattern p = ctx.MkPattern(new Expr[] { fxs }); /* create & assert quantifier */ BoolExpr q = ctx.MkForall( types, /* types of quantified variables */ names, /* names of quantified variables */ eq, 1, new Pattern[] { p } /* patterns */); return q; }
internal EnumSort(Context ctx, Symbol name, Symbol[] enumNames) : base(ctx) { Contract.Requires(ctx != null); Contract.Requires(name != null); Contract.Requires(enumNames != null); int n = enumNames.Length; IntPtr[] n_constdecls = new IntPtr[n]; IntPtr[] n_testers = new IntPtr[n]; NativeObject = Native.Z3_mk_enumeration_sort(ctx.nCtx, name.NativeObject, (uint)n, Symbol.ArrayToNative(enumNames), n_constdecls, n_testers); }
internal static Symbol Create(Context ctx, IntPtr obj) { Contract.Requires(ctx != null); Contract.Ensures(Contract.Result<Symbol>() != null); switch ((Z3_symbol_kind)Native.Z3_get_symbol_kind(ctx.nCtx, obj)) { case Z3_symbol_kind.Z3_INT_SYMBOL: return new IntSymbol(ctx, obj); case Z3_symbol_kind.Z3_STRING_SYMBOL: return new StringSymbol(ctx, obj); default: throw new Z3Exception("Unknown symbol kind encountered"); } }
public static void CheckLessThan(int a, String b) { // Console.WriteLine("This test worked" + a + " " + b); using (Context ctx = new Context()) { // 3 < x Expr x = ctx.MkConst(b, ctx.MkIntSort()); Expr value = ctx.MkNumeral(a, ctx.MkIntSort()); BoolExpr test = ctx.MkLt((ArithExpr)value,(ArithExpr) x); Model model = Check(ctx, test, Status.SATISFIABLE); } }
/// <summary> /// Returns the Z3 term corresponding to the MSF rational number. /// </summary> /// <param name="rational">The MSF rational</param> /// <returns>The Z3 term</returns> public static ArithExpr GetNumeral(Context context, Rational rational, Sort sort = null) { try { sort = rational.IsInteger() ? ((Sort)context.IntSort) : (sort == null ? (Sort)context.RealSort : sort); return (ArithExpr)context.MkNumeral(rational.ToString(), sort); } catch (Z3Exception e) { Console.Error.WriteLine("Conversion of {0} failed:\n {1}", rational, e); throw new NotSupportedException(); } }
internal ListSort(Context ctx, Symbol name, Sort elemSort) : base(ctx) { Contract.Requires(ctx != null); Contract.Requires(name != null); Contract.Requires(elemSort != null); IntPtr inil = IntPtr.Zero, iisnil = IntPtr.Zero, icons = IntPtr.Zero, iiscons = IntPtr.Zero, ihead = IntPtr.Zero, itail = IntPtr.Zero; NativeObject = Native.Z3_mk_list_sort(ctx.nCtx, name.NativeObject, elemSort.NativeObject, ref inil, ref iisnil, ref icons, ref iiscons, ref ihead, ref itail); }
static Model Check(Context ctx, BoolExpr f, Status sat) { Solver s = ctx.MkSolver(); s.Assert(f); if (s.Check() != sat) { return null; }; if (sat == Status.SATISFIABLE) { Console.WriteLine("Data:" + s.Model); return s.Model; } else return null; }
internal Quantifier(Context ctx, bool isForall, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null ) : base(ctx) { Contract.Requires(ctx != null); Contract.Requires(sorts != null); Contract.Requires(names != null); Contract.Requires(body != null); Contract.Requires(sorts.Length == names.Length); Contract.Requires(Contract.ForAll(sorts, s => s != null)); Contract.Requires(Contract.ForAll(names, n => n != null)); Contract.Requires(patterns == null || Contract.ForAll(patterns, p => p != null)); Contract.Requires(noPatterns == null || Contract.ForAll(noPatterns, np => np != null)); Context.CheckContextMatch(patterns); Context.CheckContextMatch(noPatterns); Context.CheckContextMatch(sorts); Context.CheckContextMatch(names); Context.CheckContextMatch(body); if (sorts.Length != names.Length) throw new Z3Exception("Number of sorts does not match number of names"); IntPtr[] _patterns = AST.ArrayToNative(patterns); if (noPatterns == null && quantifierID == null && skolemID == null) { NativeObject = Native.Z3_mk_quantifier(ctx.nCtx, (isForall) ? 1 : 0, weight, AST.ArrayLength(patterns), AST.ArrayToNative(patterns), AST.ArrayLength(sorts), AST.ArrayToNative(sorts), Symbol.ArrayToNative(names), body.NativeObject); } else { NativeObject = Native.Z3_mk_quantifier_ex(ctx.nCtx, (isForall) ? 1 : 0, weight, AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID), AST.ArrayLength(patterns), AST.ArrayToNative(patterns), AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns), AST.ArrayLength(sorts), AST.ArrayToNative(sorts), Symbol.ArrayToNative(names), body.NativeObject); } }
static Model Check(Z3.Context ctx, BoolExpr f, Status sat) { Solver s = ctx.MkSolver(); s.Assert(f); if (s.Check() != sat) { throw new Exception("Test Failed"); } if (sat == Status.SATISFIABLE) { return(s.Model); } else { return(null); } }
/// <summary> /// Simple bit-vector example. /// </summary> /// <remarks> /// This example disproves that x - 10 <= 0 IFF x <= 10 for (32-bit) machine integers /// </remarks> public static void BitvectorExample1() { var ctx = new Z3.Context(); using var svc = Z3Api.Own(ctx); var bv_type = ctx.MkBitVecSort(32); var x = (BitVecExpr)ctx.MkConst("x", bv_type); var zero = (BitVecNum)ctx.MkNumeral("0", bv_type); BitVecNum ten = ctx.MkBV(10, 32); BitVecExpr x_minus_ten = ctx.MkBVSub(x, ten); /* bvsle is signed less than or equal to */ BoolExpr c1 = ctx.MkBVSLE(x, ten); BoolExpr c2 = ctx.MkBVSLE(x_minus_ten, zero); BoolExpr thm = ctx.MkIff(c1, c2); print("disprove: x - 10 <= 0 IFF x <= 10 for (32-bit) machine integers"); Disprove(ctx, thm); }
private Expr[,] prepareExpr(int numVertices, List <Tuple <uint, uint> > edges) { using (Microsoft.Z3.Context ctx = new Microsoft.Z3.Context()){ Expr[,] R = new Expr[numVertices, numVertices]; for (uint i = 0; i < numVertices; i++) { for (uint j = 0; j < numVertices; j++) { if (edges.Any(tuple => tuple.Item1 == i && tuple.Item2 == j)) { R[i, j] = ctx.MkInt(1); } else { R[i, j] = ctx.MkInt(0); } } } return(R); } }
public static Z3.Symbol[] Symbols(this Z3C ctx, params string[] names) => names.Select(n => ctx.Symbol(n)).ToArray();
public static Z3.Symbol Symbol(this Z3C ctx, int index) => ctx.MkSymbol(index);
/// <summary> /// Assumes ownership of an existing context as thus disposes of /// context when out-of-scope /// </summary> public static Z3Api Own(Z3.Context context) => new Z3Api(context, true);
/// <summary> /// Wraps an existing context but does not assume ownership /// and hence does not dispose of context /// </summary> public static Z3Api Share(Z3.Context context) => new Z3Api(context, false);
Z3Api(Z3.Context context, bool owns) { this.Context = context; this.OwnsContext = owns; }
public static void CreateBenchmark(Random random, int numberOfExamples, int componentNumbers = 5, int input_arg_limit = 2) { var context = new Microsoft.Z3.Context(new Dictionary <string, string>() { { "proof", "true" } }); var typeSpecs = TypeSpecBuilder.Build(Resources.path_typeSpec); var grammar = default(Grammar); var root = default(TreeNode <string>); var parameters = new List <Parameter>(); SetupNewProgram(ref root, ref grammar, typeSpecs, random, input_arg_limit, ref parameters); var programSpecs = new List <List <List <object> > >(); while (true) { grammar.Decide(root, new Lemmas(), context, grammar, null); if (root.IsConcrete) { root.Visualize(); var componentNodes = root.Where(x => !x.IsLeaf).ToList(); if (componentNodes.Count >= componentNumbers) { var programSpec = new List <List <object> >(); try { for (int i = 0; i < 500; i++) { var result = CreateRandomParamsAndExecuteProgram(root, random, parameters); programSpec.Add(result); if (programSpec.Count == numberOfExamples) { programSpecs.Add(programSpec); WriteBenchmark(root, programSpec, parameters, context); SetupNewProgram(ref root, ref grammar, typeSpecs, random, input_arg_limit, ref parameters); break; } } } catch (Exception exception) { SetupNewProgram(ref root, ref grammar, typeSpecs, random, input_arg_limit, ref parameters); } } else { SetupNewProgram(ref root, ref grammar, typeSpecs, random, input_arg_limit, ref parameters); } } if (programSpecs.Count == 100) { break; } } }
public static Z3.Symbol Symbol(this Z3C ctx, string name) => ctx.MkSymbol(name);
public ExpressionConverter(Microsoft.Z3.Context z3context) { this.context = z3context; }
/// <summary> /// Worker constructor taking a Z3 instance and a function to periodically /// check for aborts. /// </summary> /// <param name="z3">Z3 instance</param> /// <param name="queryAbortFunction">method to call to check for aborts</param> public AbortWorker(Context context, Func <bool> queryAbortFunction) { _context = context; _QueryAbortFunction = queryAbortFunction; }