本文整理汇总了C#中Microsoft.Z3.Context.MkIntSort方法的典型用法代码示例。如果您正苦于以下问题:C# Context.MkIntSort方法的具体用法?C# Context.MkIntSort怎么用?C# Context.MkIntSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Z3.Context
的用法示例。
在下文中一共展示了Context.MkIntSort方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: CheckLessThan
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);
}
}
示例3: Main
static void Main(string[] args)
{
using (Context ctx = new Context())
{
Expr x = ctx.MkConst("x", ctx.MkIntSort());
Expr zero = ctx.MkNumeral(0, ctx.MkIntSort());
Solver s = ctx.MkSolver();
s.Assert(ctx.MkLt((ArithExpr)zero, (ArithExpr)x)); // 0<x
Status result = s.Check();
Console.WriteLine(result);
}
}
示例4: 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;
}
示例5: Z3Context
//Constructor
public Z3Context()
{
//Initialize Config and Context
_config = new Config();
_config.SetParamValue("MODEL", "true"); // corresponds to /m switch
_config.SetParamValue("MACRO_FINDER", "true");
_context = new Context(_config);
//Setup custom conversion method BoolToInt (boolean -> integer)----------------------------------------------------------------
FuncDecl boolToInt = _context.MkFuncDecl("BoolToInt", _context.MkBoolSort(), _context.MkIntSort());
Term i = _context.MkConst("i", _context.MkBoolSort());
Term fDef = _context.MkIte(_context.MkEq(i, _context.MkTrue()), _context.MkIntNumeral(1), _context.MkIntNumeral(0)); // x == true => 1, x == false => 0
Term fStatement = _context.MkForall(0, new Term[] { i }, null, _context.MkEq(_context.MkApp(boolToInt, i), fDef));
_context.AssertCnstr(fStatement);
//
_functions.Add("BoolToInt", new Z3Function(boolToInt));
//-----------------------------------------------------------------------------------------------------------------------------
}
示例6: ListExample
/// <summary>
/// Create a list datatype.
/// </summary>
public static void ListExample(Context ctx)
{
Console.WriteLine("ListExample");
Sort int_ty;
ListSort int_list;
Expr nil, l1, l2, x, y, u, v;
BoolExpr fml, fml1;
int_ty = ctx.MkIntSort();
int_list = ctx.MkListSort(ctx.MkSymbol("int_list"), int_ty);
nil = ctx.MkConst(int_list.NilDecl);
l1 = ctx.MkApp(int_list.ConsDecl, ctx.MkInt(1), nil);
l2 = ctx.MkApp(int_list.ConsDecl, ctx.MkInt(2), nil);
/* nil != cons(1, nil) */
Prove(ctx, ctx.MkNot(ctx.MkEq(nil, l1)));
/* cons(2,nil) != cons(1, nil) */
Prove(ctx, ctx.MkNot(ctx.MkEq(l1, l2)));
/* cons(x,nil) = cons(y, nil) => x = y */
x = ctx.MkConst("x", int_ty);
y = ctx.MkConst("y", int_ty);
l1 = ctx.MkApp(int_list.ConsDecl, x, nil);
l2 = ctx.MkApp(int_list.ConsDecl, y, nil);
Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(x, y)));
/* cons(x,u) = cons(x, v) => u = v */
u = ctx.MkConst("u", int_list);
v = ctx.MkConst("v", int_list);
l1 = ctx.MkApp(int_list.ConsDecl, x, u);
l2 = ctx.MkApp(int_list.ConsDecl, y, v);
Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(u, v)));
Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(x, y)));
/* is_nil(u) or is_cons(u) */
Prove(ctx, ctx.MkOr((BoolExpr)ctx.MkApp(int_list.IsNilDecl, u),
(BoolExpr)ctx.MkApp(int_list.IsConsDecl, u)));
/* occurs check u != cons(x,u) */
Prove(ctx, ctx.MkNot(ctx.MkEq(u, l1)));
/* destructors: is_cons(u) => u = cons(head(u),tail(u)) */
fml1 = ctx.MkEq(u, ctx.MkApp(int_list.ConsDecl, ctx.MkApp(int_list.HeadDecl, u),
ctx.MkApp(int_list.TailDecl, u)));
fml = ctx.MkImplies((BoolExpr)ctx.MkApp(int_list.IsConsDecl, u), fml1);
Console.WriteLine("Formula {0}", fml);
Prove(ctx, fml);
Disprove(ctx, fml1);
}
示例7: ParserExample3
/// <summary>
/// Demonstrates how to initialize the parser symbol table.
/// </summary>
public static void ParserExample3(Context ctx)
{
Console.WriteLine("ParserExample3");
/* declare function g */
Sort I = ctx.MkIntSort();
FuncDecl g = ctx.MkFuncDecl("g", new Sort[] { I, I }, I);
BoolExpr ca = CommAxiom(ctx, g);
ctx.ParseSMTLIBString("(benchmark tst :formula (forall (x Int) (y Int) (implies (= x y) (= (gg x 0) (gg 0 y)))))",
null, null,
new Symbol[] { ctx.MkSymbol("gg") },
new FuncDecl[] { g });
BoolExpr thm = ctx.SMTLIBFormulas[0];
Console.WriteLine("formula: {0}", thm);
Prove(ctx, thm, false, ca);
}
示例8: ParserExample2
/// <summary>
/// Demonstrates how to initialize the parser symbol table.
/// </summary>
public static void ParserExample2(Context ctx)
{
Console.WriteLine("ParserExample2");
Symbol[] declNames = { ctx.MkSymbol("a"), ctx.MkSymbol("b") };
FuncDecl a = ctx.MkConstDecl(declNames[0], ctx.MkIntSort());
FuncDecl b = ctx.MkConstDecl(declNames[1], ctx.MkIntSort());
FuncDecl[] decls = new FuncDecl[] { a, b };
ctx.ParseSMTLIBString("(benchmark tst :formula (> a b))",
null, null, declNames, decls);
BoolExpr f = ctx.SMTLIBFormulas[0];
Console.WriteLine("formula: {0}", f);
Check(ctx, f, Status.SATISFIABLE);
}
示例9: Z3Context
public Z3Context()
{
config = new Config();
config.SetParamValue("MODEL", "true");
config.SetParamValue("MODEL_V2", "true");
config.SetParamValue("MODEL_COMPLETION", "true");
config.SetParamValue("MBQI", "false");
config.SetParamValue("TYPE_CHECK", "true");
int timeout = 10000; // timeout = 10 seconds
config.SetParamValue("SOFT_TIMEOUT", timeout.ToString());
context = new Context(config);
intSort = context.MkIntSort();
boolSort = context.MkBoolSort();
}
示例10: get_implied_equalities_example
// CMW: get_implied_equalities is deprecated.
///*!
// \brief Extract implied equalities.
//*/
public void get_implied_equalities_example()
{
if (this.z3 != null)
{
this.z3.Dispose();
}
Config p = new Config();
p.SetParam("ARITH_EQ_BOUNDS","true");
this.z3 = new Context(p);
Sort int_sort = z3.MkIntSort();
Expr a = mk_int_var("a");
Expr b = mk_int_var("b");
Expr c = mk_int_var("c");
Expr d = mk_int_var("d");
FuncDecl f = z3.MkFuncDecl("f", int_sort, int_sort);
Expr fa = z3.MkApp(f,a);
Expr fb = z3.MkApp(f,b);
Expr fc = z3.MkApp(f,c);
Expr[] Exprs = new Expr[]{ a, b, c, d, fa, fb, fc };
uint[] class_ids;
solver.Assert(z3.MkEq(a, b));
solver.Assert(z3.MkEq(b, c));
solver.Assert(z3.MkLe((ArithExpr)fc, (ArithExpr)a));
solver.Assert(z3.MkLe((ArithExpr)b, (ArithExpr)fb));
int num_Exprs = Exprs.Length;
z3.GetImpliedEqualities(Exprs, out class_ids);
for (int i = 0; i < num_Exprs; ++i) {
Console.WriteLine("Class {0} |-> {1}", Exprs[i], class_ids[i]);
}
}