本文整理汇总了C#中Microsoft.Z3.Context类的典型用法代码示例。如果您正苦于以下问题:C# Context类的具体用法?C# Context怎么用?C# Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于Microsoft.Z3命名空间,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Quantifier
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);
}
}
示例2: EeAndGt
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;
}
示例3: Check
/// <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;
}
}
示例4: DatatypeSort
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);
}
示例5: ArrayExample3
/// <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]));
}
}
}
}
示例6: Visit
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;
}
示例7: Translate
/// <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));
}
示例8: FiniteDomainSort
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);
}
示例9: IncAndClear
internal void IncAndClear(Context ctx, IntPtr o)
{
Contract.Requires(ctx != null);
IncRef(ctx, o);
if (m_queue.Count >= m_move_limit) Clear(ctx);
}
示例10: Z3Object
internal Z3Object(Context ctx)
{
Contract.Requires(ctx != null);
Interlocked.Increment(ref ctx.refCount);
m_ctx = ctx;
}
示例11: Z3Object
internal Z3Object(Context ctx)
{
Contract.Requires(ctx != null);
ctx.refCount++;
m_ctx = ctx;
}
示例12: VisitBinary
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;
}
示例13: ArraySort
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);
}
示例14: CSPrettyPrinter
/// <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;
}
示例15: ArrayExample2
/// <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);
}