Example #1
0
        /// <summary>
        /// Find x and y such that: x ^ y - 103 == x * y
        /// </summary>
        public static void BitvectorExample2()
        {
            print("BitvectorExample2");
            using var svc = Z3Api.Create();

            var bvSize = default(N32);
            /* construct x ^ y - 103 == x * y */
            var x       = svc.BvConst("x", bvSize);
            var y       = svc.BvConst("y", bvSize);
            var x_xor_y = svc.XOr(x, y);
            var c103    = svc.BvNumeral("103", bvSize);
            var lhs     = svc.Sub(x_xor_y, c103);
            var rhs     = svc.Mul(x, y);
            var ctr     = svc.Eq(lhs, rhs);

            print("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(svc, ctr, Status.SATISFIABLE);

            foreach (var e in m.Consts)
            {
                print($"{e.Key.Name}:{e.Key.ASTKind} = {e.Value}");
            }
        }
Example #2
0
        public static void BvExample1()
        {
            using var svc = Z3Api.Create();
            var x    = svc.BvVal(3);
            var y    = svc.BvVal(5);
            var z    = svc.Or(x, y);
            var eval = z.Simplify();

            inform($"{z.SExpr()} = {eval}:{eval.ASTKind}");
        }
Example #3
0
        public static void EnumExamples()
        {
            using var svc = Z3Api.Create();
            var choices = svc.Enum("Choices", "ChoiceA", "ChoiceB", "ChoiceC");

            for (var i = 0u; i < choices.Consts.Length; i++)
            {
                inform($"Choice {i} = {choices.Const(i)}");
            }
        }