當前位置: 首頁>>代碼示例>>C#>>正文


C# Context.MkBoolSort方法代碼示例

本文整理匯總了C#中Microsoft.Z3.Context.MkBoolSort方法的典型用法代碼示例。如果您正苦於以下問題:C# Context.MkBoolSort方法的具體用法?C# Context.MkBoolSort怎麽用?C# Context.MkBoolSort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.Z3.Context的用法示例。


在下文中一共展示了Context.MkBoolSort方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Z3Context

        //Constructor
        public Z3Context()
        {
            //Initialize Config and Context
            _config = new Config();
            _config.SetParamValue("MODEL", "true"); // corresponds to /m switch
            _config.SetParamValue("MACRO_FINDER", "true");
            _context = new Context(_config);

            //Setup custom conversion method BoolToInt (boolean -> integer)----------------------------------------------------------------
            FuncDecl boolToInt = _context.MkFuncDecl("BoolToInt", _context.MkBoolSort(), _context.MkIntSort());
            Term i = _context.MkConst("i", _context.MkBoolSort());
            Term fDef = _context.MkIte(_context.MkEq(i, _context.MkTrue()), _context.MkIntNumeral(1), _context.MkIntNumeral(0)); // x == true => 1, x == false => 0
            Term fStatement = _context.MkForall(0, new Term[] { i }, null, _context.MkEq(_context.MkApp(boolToInt, i), fDef));
            _context.AssertCnstr(fStatement);

            //
            _functions.Add("BoolToInt", new Z3Function(boolToInt));
            //-----------------------------------------------------------------------------------------------------------------------------
        }
開發者ID:dswingle,項目名稱:openconfigurator,代碼行數:20,代碼來源:Z3Engine.cs

示例2: GetOrAddMemberAccessFunction

        internal static FuncDecl GetOrAddMemberAccessFunction(Context context, Environment environment, MemberInfo memberInfo)
        {
            FuncDecl memberFunc;
            if (!environment.Members.TryGetValue(memberInfo, out memberFunc))
            {
                Sort memberTypeSort;
                if (!environment.Types.TryGetValue(memberInfo.DeclaringType, out memberTypeSort))
                {
                    throw new KeyNotFoundException(memberInfo.DeclaringType + " could not be found at environment.Types");
                }

                Sort memberReturnTypeEnumSort;
                var propertyType = ((PropertyInfo)memberInfo).PropertyType;
                if (propertyType == typeof(bool))
                    memberReturnTypeEnumSort = context.MkBoolSort();
                else if (propertyType == typeof(int))
                    memberReturnTypeEnumSort = context.MkIntSort();
                else if (propertyType == typeof(long))
                    memberReturnTypeEnumSort = context.MkRealSort();
                else if (propertyType == typeof(string))
                    memberReturnTypeEnumSort = environment.PossibleStringValues;
                else
                {
                    if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
                    {
                        var listItemType = propertyType.GenericTypeArguments[0];

                        var listSort = context.MkSetSort(environment.Types[listItemType]);

                        memberReturnTypeEnumSort = listSort;

                        // TODO: add TryGetValue
                        environment.Types.Add(propertyType, listSort);
                    }
                    else if (propertyType.IsEnum)
                    {
                        EnumSort enumSort = context.MkEnumSort(propertyType.Name, Enum.GetNames(propertyType));

                        memberReturnTypeEnumSort = enumSort;

                        // TODO: add TryGetValue
                        environment.Types.Add(propertyType, enumSort);
                    }
                    else
                    {
                        // TODO throw exception if type is not supported
                        memberReturnTypeEnumSort = environment.Types[propertyType];
                    }
                }

                memberFunc = context.MkFuncDecl(memberInfo.Name, memberTypeSort, memberReturnTypeEnumSort);
                environment.Members.Add(memberInfo, memberFunc);
            }
            return memberFunc;
        }
開發者ID:RicardoNiepel,項目名稱:Z3.ObjectTheorem,代碼行數:55,代碼來源:LambdaExpressionToConstraintGenerator.cs

示例3: BasicTests

        /// <summary>
        /// Some basic tests.
        /// </summary>
        static void BasicTests(Context ctx)
        {
            Console.WriteLine("BasicTests");

            Symbol qi = ctx.MkSymbol(1);
            Symbol fname = ctx.MkSymbol("f");
            Symbol x = ctx.MkSymbol("x");
            Symbol y = ctx.MkSymbol("y");

            Sort bs = ctx.MkBoolSort();

            Sort[] domain = { bs, bs };
            FuncDecl f = ctx.MkFuncDecl(fname, domain, bs);
            Expr fapp = ctx.MkApp(f, ctx.MkConst(x, bs), ctx.MkConst(y, bs));

            Expr[] fargs2 = { ctx.MkFreshConst("cp", bs) };
            Sort[] domain2 = { bs };
            Expr fapp2 = ctx.MkApp(ctx.MkFreshFuncDecl("fp", domain2, bs), fargs2);

            BoolExpr trivial_eq = ctx.MkEq(fapp, fapp);
            BoolExpr nontrivial_eq = ctx.MkEq(fapp, fapp2);

            Goal g = ctx.MkGoal(true);
            g.Assert(trivial_eq);
            g.Assert(nontrivial_eq);
            Console.WriteLine("Goal: " + g);

            Solver solver = ctx.MkSolver();

            foreach (BoolExpr a in g.Formulas)
                solver.Assert(a);

            if (solver.Check() != Status.SATISFIABLE)
                throw new TestFailedException();

            ApplyResult ar = ApplyTactic(ctx, ctx.MkTactic("simplify"), g);
            if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat))
                throw new TestFailedException();

            ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g);
            if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat)
                throw new TestFailedException();

            g.Assert(ctx.MkEq(ctx.MkNumeral(1, ctx.MkBitVecSort(32)),
                                      ctx.MkNumeral(2, ctx.MkBitVecSort(32))));
            ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g);
            if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat)
                throw new TestFailedException();


            Goal g2 = ctx.MkGoal(true, true);
            ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2);
            if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat)
                throw new TestFailedException();

            g2 = ctx.MkGoal(true, true);
            g2.Assert(ctx.MkFalse());
            ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2);
            if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat)
                throw new TestFailedException();

            Goal g3 = ctx.MkGoal(true, true);
            Expr xc = ctx.MkConst(ctx.MkSymbol("x"), ctx.IntSort);
            Expr yc = ctx.MkConst(ctx.MkSymbol("y"), ctx.IntSort);
            g3.Assert(ctx.MkEq(xc, ctx.MkNumeral(1, ctx.IntSort)));
            g3.Assert(ctx.MkEq(yc, ctx.MkNumeral(2, ctx.IntSort)));
            BoolExpr constr = ctx.MkEq(xc, yc);
            g3.Assert(constr);
            ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g3);
            if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat)
                throw new TestFailedException();

            ModelConverterTest(ctx);

            // Real num/den test.
            RatNum rn = ctx.MkReal(42, 43);
            Expr inum = rn.Numerator;
            Expr iden = rn.Denominator;
            Console.WriteLine("Numerator: " + inum + " Denominator: " + iden);
            if (inum.ToString() != "42" || iden.ToString() != "43")
                throw new TestFailedException();

            if (rn.ToDecimalString(3) != "0.976?")
                throw new TestFailedException();

            BigIntCheck(ctx, ctx.MkReal("-1231231232/234234333"));
            BigIntCheck(ctx, ctx.MkReal("-123123234234234234231232/234234333"));
            BigIntCheck(ctx, ctx.MkReal("-234234333"));
            BigIntCheck(ctx, ctx.MkReal("234234333/2"));


            string bn = "1234567890987654321";

            if (ctx.MkInt(bn).BigInteger.ToString() != bn)
                throw new TestFailedException();

            if (ctx.MkBV(bn, 128).BigInteger.ToString() != bn)
//.........這裏部分代碼省略.........
開發者ID:perillaseed,項目名稱:z3,代碼行數:101,代碼來源:Program.cs

示例4: ArrayExample3

        /// <summary>
        /// Show that <code>distinct(a_0, ... , a_n)</code> is
        /// unsatisfiable when <code>a_i</code>'s are arrays from boolean to
        /// boolean and n > 4.
        /// </summary>
        /// <remarks>This example also shows how to use the <code>distinct</code> construct.</remarks>
        public static void ArrayExample3(Context ctx)
        {
            Console.WriteLine("ArrayExample3");

            for (int n = 2; n <= 5; n++)
            {
                Console.WriteLine("n = {0}", n);

                Sort bool_type = ctx.MkBoolSort();
                Sort array_type = ctx.MkArraySort(bool_type, bool_type);
                Expr[] a = new Expr[n];

                /* create arrays */
                for (int i = 0; i < n; i++)
                {
                    a[i] = ctx.MkConst(String.Format("array_{0}", i), array_type);
                }

                /* assert distinct(a[0], ..., a[n]) */
                BoolExpr d = ctx.MkDistinct(a);
                Console.WriteLine("{0}", (d));

                /* context is satisfiable if n < 5 */
                Model model = Check(ctx, d, n < 5 ? Status.SATISFIABLE : Status.UNSATISFIABLE);
                if (n < 5)
                {
                    for (int i = 0; i < n; i++)
                    {
                        Console.WriteLine("{0} = {1}",
                                          a[i],
                                          model.Evaluate(a[i]));
                    }
                }
            }
        }
開發者ID:perillaseed,項目名稱:z3,代碼行數:41,代碼來源:Program.cs

示例5: Run

    public void Run()
    {
        using (Context ctx = new Context())
        {
            this.ctx = ctx;
            ctx.UpdateParamValue("DL_GENERATE_EXPLANATIONS", "true");

            red_car = new Car(false, 2, 2, 3, "red");
            cars = new Car[]{
                new Car(true, 0, 3, 0, "yellow"),
                new Car(false, 3, 3, 0, "blue"),
                new Car(false, 5, 2, 0, "brown"),
                new Car(false, 0, 2, 1, "lgreen"),
                new Car(true,  1, 2, 1, "light blue"),
                new Car(true,  2, 2, 1, "pink"),
                new Car(true,  2, 2, 4, "dark green"),
                red_car,
                new Car(true,  3, 2, 3, "purple"),
                new Car(false, 5, 2, 3, "light yellow"),
                new Car(true,  4, 2, 0, "orange"),
                new Car(false, 4, 2, 4, "black"),
                new Car(true,  5, 3, 1, "light purple")
                };

            this.num_cars = cars.Length;
            this.B = ctx.MkBoolSort();
            this.bv3 = ctx.MkBitVecSort(3);
            List<Sort> domain = new List<Sort>();
            foreach (var c in cars) domain.Add(bv3);
            this.state = ctx.MkFuncDecl("state", domain.ToArray(), B);
            this.fp = ctx.MkFixedpoint();
            this.fp.RegisterRelation(state);

            // Initial state:

            Expr[] args = new Expr[num_cars];
            for (int i = 0; i < num_cars; ++i) args[i] = num(cars[i].start);
            fp.AddRule((BoolExpr)state[args]);

            // Transitions:
            for (int pos = 0; pos < num_cars; ++pos)
            {
                Car car = cars[pos];
                for (int i = 0; i < dimension; ++i)
                    if (car.is_vertical)
                    {
                        move_down(i, pos, car);
                        move_up(i, pos, car);
                    }
                    else
                    {
                        move_left(i, pos, car);
                        move_right(i, pos, car);
                    }
            }

            // Print the current context:
            Console.WriteLine("{0}", fp);

            // Prepare the query:
            for (int i = 0; i < num_cars; ++i) args[i] = (cars[i] == red_car) ? num(4) : bound(i);
            BoolExpr goal = (BoolExpr)state[args];
            fp.Query(goal);

            // Extract a path:
            get_instructions(fp.GetAnswer());
        }
    }
開發者ID:ahorn,項目名稱:z3test,代碼行數:68,代碼來源:fixedpoint.6.cs

示例6: Z3Context

        public Z3Context()
        {
            config = new Config();
            config.SetParamValue("MODEL", "true");
            config.SetParamValue("MODEL_V2", "true");
            config.SetParamValue("MODEL_COMPLETION", "true");
            config.SetParamValue("MBQI", "false");
            config.SetParamValue("TYPE_CHECK", "true");
            int timeout = 10000;    // timeout = 10 seconds
            config.SetParamValue("SOFT_TIMEOUT", timeout.ToString());

            context = new Context(config);
            intSort = context.MkIntSort();
            boolSort = context.MkBoolSort();
        }
開發者ID:Chenguang-Zhu,項目名稱:ICE-C5,代碼行數:15,代碼來源:ICEHoudini.cs


注:本文中的Microsoft.Z3.Context.MkBoolSort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。