public MkBVXOR ( |
||
t1 | ||
t2 | ||
Результат |
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 y = ctx.MkBVConst("y", 32); BitVecExpr zero = ctx.MkBV(0, 32); BoolExpr trick = ctx.MkBVSLT(ctx.MkBVXOR(x, y), zero); BoolExpr opposite = ctx.MkOr(ctx.MkAnd(ctx.MkBVSLT(x, zero), ctx.MkBVSGE(y, zero)), ctx.MkAnd(ctx.MkBVSGE(x, zero), ctx.MkBVSLT(y, zero))); Solver s = ctx.MkSolver(); s.Assert(ctx.MkNot(ctx.MkEq(trick, opposite))); Console.WriteLine(s.Check()); } }
/// <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); }