/// <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() { var ctx = new Z3.Context(); using var svc = Z3Api.Own(ctx); var bv_type = ctx.MkBitVecSort(32); var x = (BitVecExpr)ctx.MkConst("x", bv_type); var 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); print("disprove: x - 10 <= 0 IFF x <= 10 for (32-bit) machine integers"); Disprove(ctx, thm); }
/// <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); }