本文整理汇总了C#中Microsoft.Z3.Context.MkBVSub方法的典型用法代码示例。如果您正苦于以下问题:C# Context.MkBVSub方法的具体用法?C# Context.MkBVSub怎么用?C# Context.MkBVSub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Z3.Context
的用法示例。
在下文中一共展示了Context.MkBVSub方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" } };
using (Context ctx = new Context(cfg))
{
BitVecExpr x = ctx.MkBVConst("x", 32);
BitVecExpr[] powers = new BitVecExpr[32];
for (uint i = 0; i < 32; i++)
powers[i] = ctx.MkBVSHL(ctx.MkBV(1, 32), ctx.MkBV(i, 32));
BoolExpr step_zero = ctx.MkEq(ctx.MkBVAND(x, ctx.MkBVSub(x, ctx.MkBV(1, 32))), ctx.MkBV(0, 32));
BoolExpr fast = ctx.MkAnd(ctx.MkNot(ctx.MkEq(x, ctx.MkBV(0, 32))),
step_zero);
BoolExpr slow = ctx.MkFalse();
foreach (BitVecExpr p in powers)
slow = ctx.MkOr(slow, ctx.MkEq(x, p));
TestDriver.CheckString(fast, "(and (not (= x #x00000000)) (= (bvand x (bvsub x #x00000001)) #x00000000))");
Solver s = ctx.MkSolver();
s.Assert(ctx.MkNot(ctx.MkEq(fast, slow)));
TestDriver.CheckUNSAT(s.Check());
s = ctx.MkSolver();
s.Assert(ctx.MkNot(step_zero));
TestDriver.CheckSAT(s.Check());
}
}
示例2: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" } };
using (Context ctx = new Context(cfg))
{
BitVecExpr x = ctx.MkBVConst("x", 16);
BitVecExpr y = ctx.MkBVConst("y", 16);
Console.WriteLine(ctx.MkBVAdd(x, ctx.MkBV(2, 16)));
Console.WriteLine(ctx.MkBVSub(ctx.MkBVAdd(x, y), ctx.MkBV(1, 16)).Simplify());
BitVecExpr a = ctx.MkBV(-1, 16);
BitVecExpr b = ctx.MkBV(65535, 16);
Console.WriteLine(ctx.MkEq(a, b).Simplify());
a = ctx.MkBV(-1, 32);
b = ctx.MkBV(65535, 32);
Console.WriteLine(ctx.MkEq(a, b).Simplify());
}
}
示例3: BitvectorExample2
/// <summary>
/// Find x and y such that: x ^ y - 103 == x * y
/// </summary>
public static void BitvectorExample2(Context ctx)
{
Console.WriteLine("BitvectorExample2");
/* construct x ^ y - 103 == x * y */
Sort bv_type = ctx.MkBitVecSort(32);
BitVecExpr x = ctx.MkBVConst("x", 32);
BitVecExpr y = ctx.MkBVConst("y", 32);
BitVecExpr x_xor_y = ctx.MkBVXOR(x, y);
BitVecExpr c103 = (BitVecNum)ctx.MkNumeral("103", bv_type);
BitVecExpr lhs = ctx.MkBVSub(x_xor_y, c103);
BitVecExpr rhs = ctx.MkBVMul(x, y);
BoolExpr ctr = ctx.MkEq(lhs, rhs);
Console.WriteLine("find values of x and y, such that x ^ y - 103 == x * y");
/* find a model (i.e., values for x an y that satisfy the constraint */
Model m = Check(ctx, ctr, Status.SATISFIABLE);
Console.WriteLine(m);
}
示例4: BitvectorExample1
/// <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(Context ctx)
{
Console.WriteLine("BitvectorExample1");
Sort bv_type = ctx.MkBitVecSort(32);
BitVecExpr x = (BitVecExpr)ctx.MkConst("x", bv_type);
BitVecNum 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);
Console.WriteLine("disprove: x - 10 <= 0 IFF x <= 10 for (32-bit) machine integers");
Disprove(ctx, thm);
}