public MkBVAND ( |
||
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", 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)) ); } }
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()); } }
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); BoolExpr q = ctx.MkAnd(ctx.MkEq(ctx.MkBVAdd(x, y), ctx.MkBV(2, 32)), ctx.MkBVSGT(x, ctx.MkBV(0, 32)), ctx.MkBVSGT(y, ctx.MkBV(0, 32))); Console.WriteLine(q); Solver s = ctx.MkSolver(); s.Assert(q); Console.WriteLine(s.Check()); Console.WriteLine(s.Model); q = ctx.MkEq(ctx.MkBVAND(x, y), ctx.MkBVNeg(y)); Console.WriteLine(q); s = ctx.MkSolver(); s.Assert(q); Console.WriteLine(s.Check()); Console.WriteLine(s.Model); q = ctx.MkBVSLT(x, ctx.MkBV(0, 32)); Console.WriteLine(q); s = ctx.MkSolver(); s.Assert(q); Console.WriteLine(s.Check()); Console.WriteLine(s.Model); q = ctx.MkBVULT(x, ctx.MkBV(0, 32)); Console.WriteLine(q); s = ctx.MkSolver(); s.Assert(q); Console.WriteLine(s.Check()); } }
public void Run() { using (Context ctx = new Context()) { var s = ctx.MkFixedpoint(); BoolSort B = ctx.BoolSort; Sort BV8 = ctx.MkBitVecSort(8); FuncDecl f = ctx.MkFuncDecl("f", BV8, B); FuncDecl g = ctx.MkFuncDecl("g", BV8, B); BitVecExpr b0 = (BitVecExpr)ctx.MkBound(0,BV8); s.RegisterRelation(f); s.RegisterRelation(g); s.AddRule((BoolExpr)f[b0]); BitVecExpr mask0 = ctx.MkBV(0xFE,8); BoolExpr even = ctx.MkEq(b0,ctx.MkBVAND(b0,mask0)); s.AddRule(ctx.MkImplies(ctx.MkAnd((BoolExpr)f[b0],even), (BoolExpr)g[b0])); Console.WriteLine(s.Query((BoolExpr)g[b0])); Console.WriteLine(s.GetAnswer()); } }
public void TestBitVectorOps() { Context z3 = new Context(); var bv16 = z3.MkBitVecSort(16); var c = (BitVecExpr)z3.MkConst("c",bv16); var _3 = (BitVecExpr)z3.MkNumeral(3, bv16); var _7 = (BitVecExpr)z3.MkNumeral(7, bv16); var _1 = (BitVecExpr)z3.MkNumeral(1, bv16); var c_and_7 = z3.MkBVAND(c, _7); //((1 + (c & 7)) & 3) var t = z3.MkBVAND(z3.MkBVAdd(_1, c_and_7), _3); var s = t.Simplify(); //comes out as: (1 + (c & 3)) var t_neq_s = z3.MkNot(z3.MkEq(t, s)); var solv =z3.MkSolver(); solv.Assert(t_neq_s); Assert.AreEqual(Status.UNSATISFIABLE, solv.Check()); }