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); Params p = ctx.MkParams(); p.Add(":mul2concat", true); Tactic t = ctx.Then(ctx.UsingParams(ctx.MkTactic("simplify"), p), ctx.MkTactic("solve-eqs"), ctx.MkTactic("bit-blast"), ctx.MkTactic("aig"), ctx.MkTactic("sat")); Solver s = ctx.MkSolver(t); s.Assert(ctx.MkEq(ctx.MkBVAdd(ctx.MkBVMul(x, ctx.MkBV(32, 16)), y), ctx.MkBV(13, 16))); s.Assert(ctx.MkBVSLT(ctx.MkBVAND(x, y), ctx.MkBV(10, 16))); s.Assert(ctx.MkBVSGT(y, ctx.MkBV(-100, 16))); Console.WriteLine(s.Check()); Model m = s.Model; Console.WriteLine(m); Console.WriteLine(ctx.MkBVAdd(ctx.MkBVMul(x, ctx.MkBV(32, 16)), y) + " == " + m.Evaluate(ctx.MkBVAdd(ctx.MkBVMul(x, ctx.MkBV(32, 16)), y))); Console.WriteLine(ctx.MkBVAND(x, y) + " == " + m.Evaluate(ctx.MkBVAND(x, y)) ); } }
/// <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); }