当前位置: 首页>>代码示例>>C#>>正文


C# Z3Provider.MkNumeral方法代码示例

本文整理汇总了C#中Z3Provider.MkNumeral方法的典型用法代码示例。如果您正苦于以下问题:C# Z3Provider.MkNumeral方法的具体用法?C# Z3Provider.MkNumeral怎么用?C# Z3Provider.MkNumeral使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Z3Provider的用法示例。


在下文中一共展示了Z3Provider.MkNumeral方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HexProjTest2

 public void HexProjTest2()
 {
     Z3Provider z3p = new Z3Provider();
     Sort bv64 = z3p.MkBitVecSort(64);
     Sort bv16 = z3p.MkBitVecSort(16);
     Expr _0x654321 = z3p.MkNumeral((uint)0xF54321, bv64);
     Expr _6 = z3p.MkHexProj(5, _0x654321, bv16).Simplify();
     Expr _5 = z3p.MkHexProj(4, _0x654321, bv16).Simplify();
     Expr _4 = z3p.MkHexProj(3, _0x654321, bv16).Simplify();
     Expr _3 = z3p.MkHexProj(2, _0x654321, bv16).Simplify();
     Expr _2 = z3p.MkHexProj(1, _0x654321, bv16).Simplify();
     Expr _1 = z3p.MkHexProj(0, _0x654321, bv16).Simplify();
     int _6v = (int)z3p.GetNumeralInt(_6);
     int _5v = (int)z3p.GetNumeralInt(_5);
     int _4v = (int)z3p.GetNumeralInt(_4);
     int _3v = (int)z3p.GetNumeralInt(_3);
     int _2v = (int)z3p.GetNumeralInt(_2);
     int _1v = (int)z3p.GetNumeralInt(_1);
     Assert.AreEqual<int>(0xF, _6v);
     Assert.AreEqual<int>(5, _5v);
     Assert.AreEqual<int>(4, _4v);
     Assert.AreEqual<int>(3, _3v);
     Assert.AreEqual<int>(2, _2v);
     Assert.AreEqual<int>(1, _1v);
 }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:25,代码来源:UnitTest1.cs

示例2: MintermBlowupTestHelperMoore

        private static int MintermBlowupTestHelperMoore(int K)
        {
            var z3p = new Z3Provider(BitWidth.BV32);
            var x = z3p.CharVar;
            var zero = z3p.MkNumeral(0, z3p.CharSort);
            Func<int, Expr> gamma = k =>
            {
                int kth = 1 << k;
                Expr mask = z3p.MkNumeral(kth, z3p.CharSort);
                Expr cond = z3p.MkNot(z3p.MkEq(z3p.MkBvAnd(x, mask), zero));
                return cond;
            };
            var moves = new List<Move<Expr>>();
            for (int i = 0; i < K; i++)
                moves.Add(Move<Expr>.Create(i, i + 1, gamma(i)));
            for (int i = 0; i < K; i++)
                moves.Add(Move<Expr>.Create(i == 0 ? 0 : K + i, K + i + 1, i ==0 ? z3p.MkNot(gamma(i)) : gamma(i)));
            var aut = Automaton<Expr>.Create(z3p, 0, new int[] { K, 2 * K }, moves);

            var sfa = new SFA<FuncDecl, Expr, Sort>(z3p, z3p.CharSort, aut);
            sfa.Automaton.CheckDeterminism(true);

            int t = System.Environment.TickCount;
            var autmin = sfa.Automaton.MinimizeMoore();
            t = System.Environment.TickCount - t;

            return t;
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:28,代码来源:FiniteAutomataTests.cs

示例3: TestFastGeneration

        public void TestFastGeneration()
        {
            Z3Provider Z = new Z3Provider();

            Sort color = Z.MkEnumSort("Color", "blue", "green", "red");

            string enum_sort_name = color.Name.ToString();
            Assert.AreEqual<string>("Color", enum_sort_name);
            Assert.AreEqual<string>("green", Z.GetEnumElement("Color", "green").FuncDecl.Name.ToString());

            FuncDecl[] fields = new FuncDecl[5];
            FuncDecl mkTuple;
            Sort attrSort = Z.MkTupleSort("$", new string[] { "i", "b", "e", "s", "r" }, new Sort[] { Z.IntSort, Z.BoolSort, color, Z.StringSort, Z.RealSort }, out mkTuple, out fields);

            string tuple_sort_name = attrSort.Name.ToString();
            string tuple_contructor_name = mkTuple.Name.ToString();

            Assert.AreEqual<string>("$", tuple_sort_name);
            Assert.AreEqual<string>("$", tuple_contructor_name);

            Assert.AreEqual<string>("i", fields[0].Name.ToString());
            Assert.AreEqual<string>("b", fields[1].Name.ToString());
            Assert.AreEqual<string>("e", fields[2].Name.ToString());

            Assert.AreEqual<string>("Int", Z.GetRange(fields[0]).Name.ToString());
            Assert.AreEqual<string>("Bool", Z.GetRange(fields[1]).Name.ToString());
            Assert.AreEqual<string>("Color", Z.GetRange(fields[2]).Name.ToString());

            var A = (Z.TT.MkRankedAlphabet("A", attrSort, new string[] { "zero", "one", "two" }, new int[] { 0, 1, 2 }));

            Expr _i_plus_1 = Z.MkApp(mkTuple, Z.MkAdd(Z.MkProj(0, A.AttrVar), Z.MkInt(1)), Z.True,
                Z.MkIte(Z.MkGe(Z.MkProj(0, A.AttrVar), Z.MkInt(4)), Z.GetEnumElement("Color", "green"), Z.GetEnumElement("Color", "blue")), Z.MkProj(3, A.AttrVar), Z.MkAdd(Z.MkProj(4, A.AttrVar), Z.MkNumeral("9/3", Z.RealSort)));

            Expr _i_plus_1_foo = Z.MkApp(mkTuple, Z.MkAdd(Z.MkProj(0, A.AttrVar), Z.MkInt(1)), Z.True,
            Z.MkIte(Z.MkGe(Z.MkProj(0, A.AttrVar), Z.MkInt(4)), Z.GetEnumElement("Color", "green"), Z.GetEnumElement("Color", "blue")), Z.MkListFromString("foo", Z.CharacterSort), Z.MkNumeral("5.06", Z.RealSort));

            var proj = Z.GetTupleField(attrSort, 0);
            var proj_term = Z.MkApp(proj, _i_plus_1);

            var proj_term2 = Z.MkProj(0, _i_plus_1);

            var r1 = Z.TT.MkTreeRule(A, A, 0, "two", Z.MkGe(Z.MkProj(0, A.AttrVar), Z.MkInt(2)),
                A.MkTree("two", _i_plus_1, A.MkTree("one", _i_plus_1, A.MkTrans(A, 0, 1)),
                                           A.MkTree("two", _i_plus_1, A.MkTrans(A, 0, 2), A.MkTrans(A, 1, 2))));

            var r2 = Z.TT.MkTreeRule(A, A, 1, "two", Z.MkLe(Z.MkProj(0, A.AttrVar), Z.MkInt(5)),
               A.MkTree("two", _i_plus_1, A.MkTree("one", _i_plus_1, A.MkTrans(A, 0, 1)),
                                          A.MkTree("two", _i_plus_1, A.MkTrans(A, 0, 1), A.MkTrans(A, 1, 2))));

            var r3 = Z.TT.MkTreeRule(A, A, 1, "one", Z.True, A.MkTree("zero", _i_plus_1));

            var r4 = Z.TT.MkTreeRule(A, A, 0, "one", Z.True, A.MkTree("zero", _i_plus_1_foo));
            var r5 = Z.TT.MkTreeRule(A, A, 0, "zero", Z.True, A.MkTree("zero", _i_plus_1_foo));

            var T = Z.TT.MkTreeAutomaton(0, A, A, new TreeRule[] { r1, r2, r3, r4, r5 });

            var D = T.ComputeDomainAcceptor();

            var sb = new StringBuilder();
            var fastgen = new FastGen(Z);
            fastgen.ToFast(enum_sort_name, sb);
            fastgen.ToFast(A, sb);
            fastgen.ToFast("A", T, sb, false);
            fastgen.GetStateName = (x => "p_" + x);
            fastgen.ToFast("A", D, sb, true);

            Console.WriteLine(sb.ToString());
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:68,代码来源:FastTests.cs

示例4: TestSTbSimplify

        public void TestSTbSimplify()
        {
            string utf8decode_bek = @"
            function fuse(r,c) = ((r << 6) | (c & 0x3F));
            function one(c) = ((0 <= c) && (c <= 0x7F));
            function C2_DF(c) = ((0xC2 <= c) && (c <= 0xDF));
            function E1_EF(c) = ((0xE1 <= c) && (c <= 0xEF));
            function A0_BF(c) = ((0xA0 <= c) && (c <= 0xBF));
            function x80_BF(c) = ((0x80 <= c) && (c <= 0xBF));
            function x80_9F(c) = ((0x80 <= c) && (c <= 0x9F));
            program utf8decode(input){
              return iter(c in input)[q := 0; r := 0;]
              {
            case (q == 0):
              if (one(c))                  {yield (c);}
              else if (C2_DF(c))           {q := 2; r := (c & 0x1F);}    // ------ 2 bytes --------
              else if (c == 0xE0)          {q := 4; r := (c & 0x0F);}    // ------ 3 bytes --------
              else if (c == 0xED)          {q := 5; r := (c & 0x0F);}    // ------ 3 bytes --------
              else if (E1_EF(c))           {q := 3; r := (c & 0x0F);}    // ------ 3 bytes --------
              else {raise InvalidInput;}

            case (q == 2):
              if (x80_BF(c))                 {q := 0; yield(fuse(r,c)); r := 0;}
              else {raise InvalidInput;}

            case (q == 3):
              if (x80_BF(c))                 {q := 2; r := fuse(r,c);}
              else {raise InvalidInput;}

            case (q == 4):
              if (A0_BF(c))                  {q := 2; r := fuse(r,c);}
              else {raise InvalidInput;}

            case (q == 5):
              if (x80_9F(c))                 {q := 2; r := fuse(r,c);}
              else {raise InvalidInput;}

            end case (!(q == 0)):
              raise InvalidInput;
              };
            }
            ";

            Z3Provider solver = new Z3Provider(BitWidth.BV16);
            var dec = BekConverter.BekToSTb(solver, utf8decode_bek);
            var utf8decode = dec.ExploreBools();

            Sort bv32 = solver.MkBitVecSort(32);
            Sort outSort = solver.MkTupleSort(solver.StringSort, bv32);
            var initReg = solver.MkTuple(solver.GetNil(solver.StringSort), solver.MkNumeral(0,bv32));
            var regVar = solver.MkVar(1,outSort);
            var reg1 = solver.MkProj(1, regVar);
            var reg0 = solver.MkProj(0, regVar);
            STb<FuncDecl, Expr, Sort> parse = new STbModel(solver, "Parse", solver.CharacterSort, outSort, outSort, initReg, 0);

            var letter = solver.MkOr(//solver.MkAnd(solver.MkCharLe(solver.MkCharExpr('\xC0'), solver.CharVar),
                                     //                    solver.MkCharLe(solver.CharVar, solver.MkCharExpr('\xFF'))),
                                     solver.MkAnd(solver.MkCharLe(solver.MkCharExpr('a'), solver.CharVar),
                                                         solver.MkCharLe(solver.CharVar, solver.MkCharExpr('z'))),
                                     solver.MkAnd(solver.MkCharLe(solver.MkCharExpr('A'), solver.CharVar),
                                                         solver.MkCharLe(solver.CharVar, solver.MkCharExpr('Z'))));

            //var not_letter = solver.MkNot(letter);

            var digit = solver.MkAnd(solver.MkCharLe(solver.MkCharExpr('0'), solver.CharVar),
                                                         solver.MkCharLe(solver.CharVar, solver.MkCharExpr('9')));

            var nl = solver.MkEq(solver.CharVar, solver.MkCharExpr('\n'));

            var space = solver.MkEq(solver.CharVar, solver.MkCharExpr(' '));

            //var not_nl = solver.MkNot(nl);

            var _0 = solver.MkNumeral((int)'0', bv32);

            //var z = solver.Z3.MkFreshConst("z", solver.CharacterSort);

            //var constr = solver.MkNot(solver.Z3.MkExists(new Expr[] { z }, nl.Substitute(solver.CharVar, z)));
            ////var constr = nl.Substitute(solver.CharVar, z);

            //solver.Z3S.Push();
            //solver.Z3S.Assert((BoolExpr)solver.MkNot(constr));
            //var status = solver.Check();
            //var m = solver.Z3S.Model;
            //var zval = m.Evaluate(z, true);
            //solver.Z3S.Pop();

            var loop_0 = new BaseRule<Expr>(Sequence<Expr>.Empty, regVar, 0);
            var brule0_1 = new BaseRule<Expr>(Sequence<Expr>.Empty, solver.MkTuple(solver.MkListCons(solver.CharVar, reg0), reg1), 1);
            var rule0 = new IteRule<Expr>(letter, brule0_1, new IteRule<Expr>(space, loop_0, UndefRule<Expr>.Default));
            parse.AssignRule(0, rule0);

            var brule1_2 = new BaseRule<Expr>(Sequence<Expr>.Empty, solver.MkTuple(solver.MkListCons(solver.CharVar, reg0), reg1), 2);
            var brule_4 = new BaseRule<Expr>(Sequence<Expr>.Empty, regVar, 4);
            var rule1 = new IteRule<Expr>(letter, brule1_2, new IteRule<Expr>(space, brule_4, UndefRule<Expr>.Default));
            parse.AssignRule(1, rule1);

            var brule2_3 = new BaseRule<Expr>(Sequence<Expr>.Empty, solver.MkTuple(solver.MkListCons(solver.CharVar, reg0), reg1), 4);
            var rule2 = new IteRule<Expr>(letter, brule2_3, new IteRule<Expr>(space, brule_4, UndefRule<Expr>.Default));
            parse.AssignRule(2, rule2);
//.........这里部分代码省略.........
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:101,代码来源:STbTests.cs

示例5: TestCssCombinedCodepoint

        public void TestCssCombinedCodepoint()
        {
            var kkkk = 0x7FFF - 65532;
            Z3Provider solver = new Z3Provider();
            Sort bv64 = solver.MkBitVecSort(64);
            Sort bv16 = solver.CharacterSort;

            Expr hs = solver.MkConst("hs", bv16);
            Expr ls = solver.MkConst("ls", bv16);

            Expr res = solver.MkConst("res", bv64);

            Expr maxVal = solver.MkNumeral(0x10FFFF, bv64); //max 16 bit nr

            Expr x = solver.ConvertBitVector(hs, bv64);
            Expr y = solver.ConvertBitVector(ls, bv64);
            Expr _0x10000 = solver.MkNumeral(0x10000, bv64);
            Expr _0xD800 = solver.MkNumeral(0xD800, bv64);
            Expr _0x400 = solver.MkNumeral(0x400, bv64);
            Expr _0xDC00 = solver.MkNumeral(0xDC00, bv64);

            ushort tmpLS = ((ushort)0xdfff) - ((ushort)0xdc00);

            for (int i = 0xdc00; i <= 0xdfff; i++ )
            {
                int j = (i - 0xdc00) >> 8;
                int k = (i >> 8) & 3;
                Assert.AreEqual<int>(j, k);
            }

            int tmpHS = (((int)0xdbff) - ((int)0xd800)) * ((int)0x400);
            //int tmpHS = (((int)0xdbff) - ((int)0xd800)) << 10;

            int tmpHSLS = tmpLS + tmpHS;

            int maxcodepoint = tmpHSLS + 0x10000;

            Expr cp = solver.MkCharAdd(_0x10000,
                       solver.MkCharAdd(solver.MkCharMul(solver.MkCharSub(x, _0xD800), _0x400),
                                        solver.MkCharSub(y, _0xDC00)));

            Expr ls_is_lowSurrogate =
                solver.MkAnd(solver.MkCharGe(ls, solver.MkNumeral(0xdc00, bv16)),
                                solver.MkCharLe(ls, solver.MkNumeral(0xdfff, bv16)));

            Expr hs_is_highSurrogate =
                solver.MkAnd(solver.MkCharGe(hs, solver.MkNumeral(0xd800, bv16)),
                                solver.MkCharLe(hs, solver.MkNumeral(0xdbff, bv16)));

            Expr assert = solver.Simplify(solver.MkAnd(
                ls_is_lowSurrogate,
                hs_is_highSurrogate,
                solver.MkEq(res, cp)));

            //string s = solver.PrettyPrint(assert);

            solver.MainSolver.Assert(assert);

            var model = solver.MainSolver.GetModel(solver.MkCharLt(maxVal, res), hs, ls, res);

            Assert.IsNull(model);

            //if (model != null)
            //{
            //    int hsVal = solver.GetNumeralInt(model[hs].Value);
            //    int lsVal = solver.GetNumeralInt(model[ls].Value);
            //    long resval = solver.GetNumeralUInt(model[res].Value);
            //    Assert.AreEqual<long>(CssCombinedCodepoint(hsVal, lsVal), resval);
            //}
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:70,代码来源:UnitTest1.cs


注:本文中的Z3Provider.MkNumeral方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。