本文整理汇总了C#中Microsoft.Z3.Context类的典型用法代码示例。如果您正苦于以下问题:C# Context类的具体用法?C# Context怎么用?C# Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于Microsoft.Z3命名空间,在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:sslab-gatech,项目名称:juxta,代码行数:32,代码来源:Quantifier.cs
示例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;
}
开发者ID:izmaxx,项目名称:VBADataGenerator,代码行数:26,代码来源:Program.cs
示例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;
}
}
开发者ID:killbug2004,项目名称:Snippets,代码行数:35,代码来源:Deprecated.cs
示例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);
}
开发者ID:sslab-gatech,项目名称:juxta,代码行数:7,代码来源:DatatypeSort.cs
示例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]));
}
}
}
}
开发者ID:sslab-gatech,项目名称:juxta,代码行数:41,代码来源:Program.cs
示例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;
}
开发者ID:izmaxx,项目名称:VBADataGenerator,代码行数:26,代码来源:Z3ExprVisitor.cs
示例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));
}
开发者ID:abhishekudupa,项目名称:z3-4.3.1,代码行数:12,代码来源:ASTVector.cs
示例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);
}
开发者ID:perillaseed,项目名称:z3,代码行数:7,代码来源:FiniteDomainSort.cs
示例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);
}
开发者ID:perillaseed,项目名称:z3,代码行数:7,代码来源:IDecRefQueue.cs
示例10: Z3Object
internal Z3Object(Context ctx)
{
Contract.Requires(ctx != null);
Interlocked.Increment(ref ctx.refCount);
m_ctx = ctx;
}
开发者ID:martin-neuhaeusser,项目名称:z3,代码行数:7,代码来源:Z3Object.cs
示例11: Z3Object
internal Z3Object(Context ctx)
{
Contract.Requires(ctx != null);
ctx.refCount++;
m_ctx = ctx;
}
开发者ID:abhishekudupa,项目名称:z3-4.3.1,代码行数:7,代码来源:Z3Object.cs
示例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;
}
开发者ID:izmaxx,项目名称:VBADataGenerator,代码行数:26,代码来源:Z3ExprVisitor.cs
示例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);
}
开发者ID:annachen368,项目名称:HadoopStreamingTester,代码行数:7,代码来源:Sort.cs
示例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;
}
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:10,代码来源:TermPrettyPrinter.cs
示例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);
}
开发者ID:sslab-gatech,项目名称:juxta,代码行数:37,代码来源:Program.cs
示例16: ConstructorList
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));
}
开发者ID:sslab-gatech,项目名称:juxta,代码行数:8,代码来源:ConstructorList.cs
示例17: GetOrAddMemberAccessFunction
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;
}
开发者ID:RicardoNiepel,项目名称:Z3.ObjectTheorem,代码行数:55,代码来源:LambdaExpressionToConstraintGenerator.cs
示例18: TupleSort
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]);
}
开发者ID:kayceesrk,项目名称:Z3,代码行数:11,代码来源:TupleSort.cs
示例19: Assert
/// <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);
}
}
开发者ID:killbug2004,项目名称:Snippets,代码行数:14,代码来源:Deprecated.cs
示例20: Clear
internal void Clear(Context ctx)
{
Contract.Requires(ctx != null);
lock (m_lock)
{
foreach (IntPtr o in m_queue)
DecRef(ctx, o);
m_queue.Clear();
}
}
开发者ID:perillaseed,项目名称:z3,代码行数:11,代码来源:IDecRefQueue.cs
注:本文中的Microsoft.Z3.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论