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


C# Z3Provider.MkInt方法代码示例

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


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

示例1: RunTestForGivenSize

        private static void RunTestForGivenSize(int K)
        {
            Console.WriteLine(K);
            Z3Provider Z = new Z3Provider();
            var A = (Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zero", "two" }, new int[] { 0, 2 }));

            Func<int, Expr> beta = (i => Z.MkEq(Z.MkInt(1), Z.MkMod(Z.MkDiv(A.AttrVar, Z.MkInt(1 << (i%32))), Z.MkInt(2))));

            Expr e1 = Z.MkEq(Z.MkInt(1), A.AttrVar);
            Expr e2 = Z.MkEq(Z.MkInt(2), A.AttrVar);
            Expr e3 = Z.MkEq(Z.MkInt(3), A.AttrVar);

            var r1 = Z.TT.MkTreeAcceptorRule(A, 0, "zero", e1);
            var r2 = Z.TT.MkTreeAcceptorRule(A, 1, "zero", e2);
            var r3 = Z.TT.MkTreeAcceptorRule(A, 2, "zero", e3);
            var rules = new List<TreeRule>();

            rules.Add(r1);
            rules.Add(r2);
            rules.Add(r3);

            for (int i = 0; i < K; i++)
            {
                rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 3, "two", beta(i), 3 * i, 3 * i + 2));
                rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 4, "two", beta(i), 3 * i + 1, 3 * i + 2));
                rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 5, "two", beta(i), 3 * i + 2, 3 * i + 2));
            }

            var T = Z.TT.MkTreeAutomaton(new int[] { 3 * K , 3 * K +1 }, A, A, rules);
            var comp = T.Complete();

            Util.RunAllAlgorithms(T, comp, K.ToString(), Program.largeAlphabetFile);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:33,代码来源:LargeAlphabetExperiment.cs

示例2: getAutomata

        internal override Automaton<Expr> getAutomata(Z3Provider z3p, List<string> variables, Expr universe, Expr var, Sort sort)
        {            
            //var bit1 = z3p.Z3.MkInt2Bv(1,
            //        z3p.MkInt(1));
            var bit1 = z3p.Z3.MkInt2BV(BVConst.BVSIZE, (IntExpr)z3p.MkInt(1));

            //Sort for pairs (input theory, BV)
            var bv = z3p.Z3.MkBitVecSort(BVConst.BVSIZE);
            var pairSort = z3p.MkTupleSort(sort, bv);

            //Add the representation of the existential variable to the list of variables
            var newVariables = variables.ToArray().ToList();
            newVariables.Insert(0, variable);

            //Compute the DFA for the formula phi
            var phiDfa = phi.getAutomata(z3p, newVariables, universe, var, sort);

            //Compute the new moves by dropping the last bit of every element in the phiMoves
            var newMoves = Automaton<Expr>.Empty.GetMoves().ToList();
            foreach (var oldMove in phiDfa.GetMoves())
            {
                var oldCond = oldMove.Label;                               

                var t = z3p.MkProj(1,var);
                //Compute the new conditions
                var newCond0 = z3p.ApplySubstitution(oldCond, t,
                        z3p.Z3.MkBVSHL((BitVecExpr)t, (BitVecExpr)bit1));
                var newCond1 = z3p.ApplySubstitution(oldCond, t, 
                    z3p.MkBvAdd(
                        z3p.Z3.MkBVSHL((BitVecExpr)t, (BitVecExpr)bit1),
                        bit1));
                
                //Update the new set of moves
                newMoves.Add(new Move<Expr>(oldMove.SourceState, oldMove.TargetState, z3p.MkOr(z3p.Simplify(newCond0),z3p.Simplify(newCond1))));
            }

            //Build the new dfa with the new moves
            return Automaton<Expr>.Create(phiDfa.InitialState, phiDfa.GetFinalStates(), newMoves);
                //.Determinize(z3p).MinimizeClassical(z3p, int.MaxValue,false);            
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:40,代码来源:WS1SZ3.cs

示例3: TestComposition1

        public void TestComposition1()
        {
            Z3Provider Z = new Z3Provider();
            var A = (Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zeroA", "oneA", "twoA" }, new int[] { 0, 1, 2 }));
            var B = (Z.TT.MkRankedAlphabet("B", Z.IntSort, new string[] { "zeroB", "oneB", "twoB" }, new int[] { 0, 1, 2 }));
            var C = (Z.TT.MkRankedAlphabet("C", Z.IntSort, new string[] { "zeroC", "oneC", "twoC" }, new int[] { 0, 1, 2 }));

            //(two (plus 1 x0) (one (plus 1 x0) (q x1)) (one (plus 2 x0) (q x2)))
            var b = Z.MkApp(B["twoB"],
                        Z.MkAdd(Z.MkInt(1), A.AttrVar),
                        B.MkTree("oneB", Z.MkAdd(Z.MkInt(1), A.AttrVar), A.MkTrans(B, 0, 1)),
                        B.MkTree("oneB", Z.MkAdd(Z.MkInt(2), A.AttrVar), A.MkTrans(B, 0, 2)));

            //(two (plus 1 x0) (zero x0) (one (plus 100 x0) (q x2)))
            var b2 = Z.MkApp(B["twoB"],
                        Z.MkAdd(Z.MkInt(1), A.AttrVar),
                        B.MkTree("zeroB", A.AttrVar),
                        B.MkTree("oneB", Z.MkAdd(Z.MkInt(9), A.AttrVar), A.MkTrans(B, 0, 2)));

            var rule0 = Z.TT.MkTreeRule(A, B, 0, "zeroA", Z.True, B.MkTree("zeroB", A.AttrVar));
            var rule1 = Z.TT.MkTreeRule(A, B, 0, "twoA", Z.MkGt(A.AttrVar, Z.MkInt(0)), b);
            var rule2 = Z.TT.MkTreeRule(A, B, 0, "twoA", Z.MkGt(A.AttrVar, Z.MkInt(0)), b2);
            var rule3 = Z.TT.MkTreeRule(A, B, 0, "oneA", Z.MkGt(A.AttrVar, Z.MkInt(0)), B.MkTree("oneB", A.AttrVar, A.MkTrans(B, 0, 1)));

            var trans1 = Z.TT.MkTreeAutomaton(0, A, B, new TreeRule[] { rule0, rule1, rule2, rule3 });

            //(two x0 (one (plus 1 x0) (p x1)) (one (plus 2 x0) (p x2)))
            var a = A.MkTree("twoA", C.AttrVar,
             A.MkTree("oneA", Z.MkAdd(Z.MkInt(1), C.AttrVar), C.MkTrans(A, 1, 1)),
             A.MkTree("oneA", Z.MkAdd(Z.MkInt(2), C.AttrVar), C.MkTrans(A, 1, 2)));

            var a2 = A.MkTree("zeroA", C.AttrVar);

            var rule4 = Z.TT.MkTreeRule(C, A, 1, "twoC", Z.MkGt(C.AttrVar, Z.MkInt(-2)), a);
            var rule5 = Z.TT.MkTreeRule(C, A, 1, "zeroC", Z.MkGt(C.AttrVar, Z.MkInt(-3)), a2);

            var trans2 = Z.TT.MkTreeAutomaton(1, C, A, new TreeRule[] { rule4, rule5 });

            var trans12 = trans2.Compose(trans1);

            var rulesOut = trans12.GetRules(trans12.Root, C["twoC"]);
            Assert.AreEqual<int>(2, rulesOut.Count);

            var rulesOut2 = trans12.GetRules(trans12.Root, C["zeroC"]);
            Assert.AreEqual<int>(1, rulesOut2.Count);

            var tin = C.MkTree("twoC", Z.MkInt(55), C.MkTree("zeroC", Z.MkInt(66)), C.MkTree("zeroC", Z.MkInt(77)));
            var res = trans12[tin];
            Assert.AreEqual<int>(2, res.Length);
            Assert.AreEqual<int>(3, trans12.RuleCount);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:51,代码来源:TreeTransducerTests.cs

示例4: TestMinimization

        private static void TestMinimization(int K)
        {
            Z3Provider Z = new Z3Provider();
            var A = (Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zero", "two" }, new int[] { 0, 2 }));

            Func<int, Expr> beta = (i => Z.MkEq(Z.MkInt(1), Z.MkMod(Z.MkDiv(A.AttrVar, Z.MkInt(1 << i)), Z.MkInt(2))));

            var r0 = Z.TT.MkTreeAcceptorRule(A, 0, "zero", beta(0));
            var r1 = Z.TT.MkTreeAcceptorRule(A, 1, "zero", beta(1));
            var rules = new List<TreeRule>();
            rules.Add(r0);
            rules.Add(r1);
            for (int i = 0; i < K; i++)
                rules.Add(Z.TT.MkTreeAcceptorRule(A, i + 1, "two", beta(i + 1), i, i));

            var T = Z.TT.MkTreeAutomaton(K, A, A, rules);

            var T1 = T.Determinize();
            var T2 = T1.RemoveUselessStates();

            var Tmin = T2.Minimize();

            Assert.AreNotEqual(T1.StateCount, Tmin.StateCount);

            Console.WriteLine("k = {0}, |Q| = {1}, |Delta| = {2}, |Q_d| = {3}, |Delta_d| = {4}, |Q_u| = {5}, |Delta_u| = {6},|Q_m| = {7}, |Delta_m| = {8},",
                K, T.StateCount, T.RuleCount, T1.StateCount, T1.RuleCount, T2.StateCount, T2.RuleCount, Tmin.StateCount, Tmin.RuleCount);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:27,代码来源:TreeTransducerTests.cs

示例5: TestTreeAutomataMinimization

        public void TestTreeAutomataMinimization()
        {
            Z3Provider Z = new Z3Provider();
            var A = (Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zero", "two" }, new int[] { 0, 2 }));

            Func<int,Expr> beta = (i => Z.MkEq(Z.MkInt(1), Z.MkMod(Z.MkDiv(A.AttrVar,Z.MkInt(1<<i)), Z.MkInt(2))));

            var r0 = Z.TT.MkTreeAcceptorRule(A, 0, "zero", beta(0));
            var r1 = Z.TT.MkTreeAcceptorRule(A, 1, "two", beta(1), 0 ,0 );
            var r2 = Z.TT.MkTreeAcceptorRule(A, 2, "two", beta(2), 1, 1);

            var T = Z.TT.MkTreeAutomaton(2, A, A, new TreeRule[] { r0, r1, r2 });

            var Tmin = T.Minimize();

            Assert.AreEqual(T.StateCount, Tmin.StateCount);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:17,代码来源:TreeTransducerTests.cs

示例6: TestRegularLookaheadComposition3

        public void TestRegularLookaheadComposition3()
        {
            Z3Provider Z = new Z3Provider();
            var A = (Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "z", "u", "b" }, new int[] { 0, 1, 2 }));
            var B = (Z.TT.MkRankedAlphabet("B", Z.IntSort, new string[] { "z", "u", "b" }, new int[] { 0, 1, 2 }));
            var C = (Z.TT.MkRankedAlphabet("C", Z.IntSort, new string[] { "z", "u", "b" }, new int[] { 0, 1, 2 }));

            var _0 = Z.MkInt(0);
            var _1 = Z.MkInt(1);
            var _2 = Z.MkInt(2);
            var _7 = Z.MkInt(7);

            var AB_r0 = Z.TT.MkTreeRule(A, B, 0, "u", Z.MkLe(_0, A.AttrVar), B.MkTree("u", Z.MkAdd(_1, A.AttrVar), A.MkTrans(B, 1, 1)), new int[][] { new int[] { 3, 1 } });
            var AB_r1 = Z.TT.MkTreeRule(A, B, 1, "u", Z.MkLe(_1, A.AttrVar), B.MkTree("u", Z.MkAdd(_1, A.AttrVar), A.MkTrans(B, 0, 1)), new int[][] { new int[] { 2, 0 } });
            var AB_r2 = Z.TT.MkTreeRule(A, B, 1, "u", Z.MkEq(_2, A.AttrVar), B.MkTree("z", Z.MkAdd(_1, A.AttrVar)));

            var AB_q2 = Z.TT.MkTreeRule(A, B, 2, "u", Z.MkGe(_0, A.AttrVar), null, new int[][] { new int[] { 3 } });
            var AB_q3a = Z.TT.MkTreeRule(A, B, 3, "u", Z.MkGe(_1, A.AttrVar), null, new int[][] { new int[] { 2 } });
            var AB_q3b = Z.TT.MkTreeRule(A, B, 3, "u", Z.MkEq(_2, A.AttrVar), null);

            //just accept the input if the attribute is 1, delete the child subtree and return zeroC(1)
            var BC_r0 = Z.TT.MkTreeRule(B, C, 0, "u", Z.MkEq(_1, B.AttrVar), C.MkTree("z", Z.MkAdd(_7, B.AttrVar)));

            var AB = Z.TT.MkTreeAutomaton(0, A, B, new TreeRule[] { AB_r0, AB_r1, AB_r2, AB_q2, AB_q3a, AB_q3b });
            var BC = Z.TT.MkTreeAutomaton(0, B, C, new TreeRule[] { BC_r0 });

            var AC = TreeTransducer.ComposeR(AB, BC);

            Assert.AreEqual<int>(5, AC.RuleCount);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:30,代码来源:TreeTransducerTests.cs

示例7: TestLanguageIntersection

        public void TestLanguageIntersection()
        {
            Z3Provider Z = new Z3Provider();
            var A = (Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zero", "one", "two" }, new int[] { 0, 1, 2 }));
            var B = A;
            var C = A;

            var a_rule2 = A.MkAcceptorRule(0, "two", Z.MkGe(A.AttrVar, Z.MkInt(2)), 0, 0);
            var a_rule1 = A.MkAcceptorRule(0, "one", Z.MkGe(A.AttrVar, Z.MkInt(1)), 0);
            var a_rule0 = A.MkAcceptorRule(0, "zero", Z.MkGe(A.AttrVar, Z.MkInt(0)));

            var b_rule2 = A.MkAcceptorRule(0, "two", Z.MkLe(A.AttrVar, Z.MkInt(2)), 0, 0);
            var b_rule1 = A.MkAcceptorRule(0, "one", Z.MkLt(A.AttrVar, Z.MkInt(1)), 0);
            var b_rule0 = A.MkAcceptorRule(0, "zero", Z.MkLe(A.AttrVar, Z.MkInt(0)));

            var a = A.MkTreeAcceptor(a_rule2, a_rule1, a_rule0);
            var b = A.MkTreeAcceptor(b_rule2, b_rule1, b_rule0);

            //all two-nodes have attribute 2, all zero-nodes have attribute 0 and no one-node is possible because the guards conflict
            var ab = a.Intersect(b);

            var t = A.MkTree("two", Z.MkInt(2), A.MkTree("two", Z.MkInt(2), A.MkTree("zero", Z.MkInt(0)), A.MkTree("zero", Z.MkInt(0))), A.MkTree("zero", Z.MkInt(0)));

            var t_out = ab[t];
            Assert.AreEqual<int>(1, t_out.Length);
            Assert.AreEqual<Expr>(null, t_out[0]);

            var t2 = A.MkTree("two", Z.MkInt(2), A.MkTree("two", Z.MkInt(3), A.MkTree("zero", Z.MkInt(0)), A.MkTree("zero", Z.MkInt(0))), A.MkTree("zero", Z.MkInt(0)));

            var t_out2 = ab[t2];
            Assert.AreEqual<int>(0, t_out2.Length);

            var t_a = a[t2];
            Assert.AreEqual<int>(1, t_a.Length);
            Assert.AreEqual<Expr>(null, t_a[0]);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:36,代码来源:TreeTransducerTests.cs

示例8: TestInvalidAcceptorStateInStart

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

            Func<int, int, Expr> q = (state, var) => { return A.MkTrans(A, state, var); };

            //two(1+x0,one(x1),one(x2))
            var b = A.MkTree("two",
                        Z.MkAdd(Z.MkInt(1), A.AttrVar),
                        A.MkTree("one", Z.MkAdd(Z.MkInt(1), A.AttrVar), q(0, 1)),
                        A.MkTree("one", Z.MkAdd(Z.MkInt(2), A.AttrVar), q(0, 2)));

            var rule0 = Z.TT.MkTreeRule(A, A, 0, "zero", Z.True, A.MkTree("zero", A.AttrVar));
            var rule1 = Z.TT.MkTreeRule(A, A, 0, "one", Z.True, A.MkTree("one", A.AttrVar, q(0, 1)));
            var rule2 = Z.TT.MkTreeRule(A, A, 0, "two", Z.True, A.MkTree("two", A.AttrVar, q(0, 2), q(0, 1)));
            var rule3 = Z.TT.MkTreeRule(A, A, 1, "two", Z.True, null, new int[] { 1 }, new int[] { 1 });
            var rule4 = Z.TT.MkTreeRule(A, A, 1, "zero", Z.True, A.MkTree("zero", A.AttrVar));

            try
            {
                var F = Z.TT.MkTreeAutomaton(0, A, A, new TreeRule[] { rule0, rule1, rule2, rule3, rule4 });
            }
            catch (AutomataException e)
            {
                Assert.AreEqual(AutomataExceptionKind.TreeTransducer_InvalidUseOfAcceptorState, e.kind);
            }
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:28,代码来源:TreeTransducerTests.cs

示例9: TestErrorCases

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

            //two(1+x0,one(x1),one(x2))
            var b = A.MkTree("two",
                        Z.MkAdd(Z.MkInt(1), A.AttrVar),
                        A.MkTree("one", Z.MkAdd(Z.MkInt(1), A.AttrVar), A.ChildVar(1)),
                        A.MkTree("one", Z.MkAdd(Z.MkInt(2), A.AttrVar), A.ChildVar(2)));

            //add 100 to the attribute of a zero-node
            var rule0 = Z.TT.MkTreeRule(A, A, 0, "zero", Z.True, A.MkTree("zero", Z.MkAdd(Z.MkInt(100), A.AttrVar)));
            //keep one-nodes unchanged
            var rule1 = Z.TT.MkTreeRule(A, A, 0, "one", Z.True, A.MkTree("one", A.AttrVar, A.ChildVar(1)));
            //apply transformation to the second child and swap it with the first child
            var rule2 = Z.TT.MkTreeRule(A, A, 0, "two", Z.True, A.MkTree("two", A.AttrVar, A.MkTrans(A, 1, 2), A.ChildVar(1)));

            try
            {
                var F = Z.TT.MkTreeAutomaton(0, A, A, new TreeRule[] { rule0, rule1, rule2 });
                Assert.IsTrue(false, "must not reach this line");
            }
            catch (AutomataException e)
            {
                Assert.AreEqual(AutomataExceptionKind.TreeTransducer_InvalidStateId, e.kind);
            }

            try
            {
                var rule2b = Z.TT.MkTreeRule(A, A, 0, "two", Z.True, A.MkTree("two", A.AttrVar, A.MkTrans(A, 0, 3), A.ChildVar(1)));
                var F = Z.TT.MkTreeAutomaton(0, A, A, new TreeRule[] { rule0, rule1, rule2b });
                Assert.IsTrue(false, "must not reach this line");
            }
            catch (AutomataException e)
            {
                Assert.AreEqual(AutomataExceptionKind.RankedAlphabet_ChildAccessorIsOutOufBounds, e.kind);
            }
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:39,代码来源:TreeTransducerTests.cs

示例10: TestDomainAutomatonCreation

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

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

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

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

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

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

            var D = T.ComputeDomainAcceptor();

            Assert.AreEqual<int>(2, T.StateCount);
            Assert.AreEqual<int>(2, D.StateCount);
            Assert.AreEqual<int>(5, D.RuleCount);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:26,代码来源:TreeTransducerTests.cs

示例11: TestCompositionCornerCase2

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

            var q0 = Z.MkInt(0);
            Func<int, int, Expr> q = (state, var) =>
            {
                return A.MkTrans(A, state, var);
            };

            //two(1+x0,one(x1),one(x2))
            var b = A.MkTree("two",
                        Z.MkAdd(Z.MkInt(1), A.AttrVar),
                        A.MkTree("one", Z.MkAdd(Z.MkInt(1), A.AttrVar), q(0,1)),
                        A.MkTree("one", Z.MkAdd(Z.MkInt(2), A.AttrVar), q(0,1)));

            //add 100 to the attribute of a zero-node
            var rule00 = Z.TT.MkTreeRule(A, A, 0, "zero", Z.True, A.MkTree("zero", Z.MkAdd(Z.MkInt(100),A.AttrVar)));
            //keep one-nodes unchanged
            var rule01 = Z.TT.MkTreeRule(A, A, 0, "one", Z.True, A.MkTree("one", A.AttrVar, q(1,1)));
            //apply transformation to the second child and swap it with the first child
            var rule02 = Z.TT.MkTreeRule(A, A, 0, "two", Z.True, A.MkTree("two", A.AttrVar, A.MkTrans(A, 0, 2), q(1,1)));

            //identity mapping
            var rule10 = Z.TT.MkTreeRule(A, A, 1, "zero", Z.True, A.MkTree("zero", A.AttrVar));
            var rule11 = Z.TT.MkTreeRule(A, A, 0, "one", Z.True, A.MkTree("one", A.AttrVar, q(1, 1)));
            var rule12 = Z.TT.MkTreeRule(A, A, 0, "two", Z.True, A.MkTree("two", A.AttrVar, q(1, 1), q(1, 2)));

            var F = Z.TT.MkTreeAutomaton(0, A, A, new TreeRule[] { rule00, rule01, rule02, rule10, rule11, rule12 });
            var FF = F.Compose(F);

            var t1 = A.MkTree("two", Z.MkInt(22), A.MkTree("zero", Z.MkInt(5)), A.MkTree("zero", Z.MkInt(6)));
            var t2 = A.MkTree("two", Z.MkInt(22), A.MkTree("zero", Z.MkInt(106)), A.MkTree("zero", Z.MkInt(5)));
            var t3 = A.MkTree("two", Z.MkInt(22), A.MkTree("zero", Z.MkInt(105)), A.MkTree("zero", Z.MkInt(106)));
            var t4 = A.MkTree("two", Z.MkInt(22), A.MkTree("zero", Z.MkInt(206)), A.MkTree("zero", Z.MkInt(105)));

            var FFF = FF.Compose(F);
            //Assert.AreEqual(3, FFF.Rules.Count);

            var s2 = F[t1][0];
            var s3 = FF[t1][0];
            var s4 = FFF[t1][0];

            Assert.AreEqual<Expr>(t2, s2);
            Assert.AreEqual<Expr>(t3, s3);
            Assert.AreEqual<Expr>(t4, s4);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:48,代码来源:TreeTransducerTests.cs

示例12: TestCompositionCornerCase1

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

            var q0 = Z.MkInt(0);
            Func<int, int, Expr> q = (state,var) =>
                {
                    return A.MkTrans(A, state, var);
                };

            //two(1+x0,one(x1),one(x2))
            var b = A.MkTree("two",
                        Z.MkAdd(Z.MkInt(1), A.AttrVar),
                        A.MkTree("one", Z.MkAdd(Z.MkInt(1), A.AttrVar), q(0,1)),
                        A.MkTree("one", Z.MkAdd(Z.MkInt(2), A.AttrVar), q(0,2)));

            var rule0 = Z.TT.MkTreeRule(A, A, 0, "zero", Z.True, A.MkTree("zero", A.AttrVar));
            var rule1 = Z.TT.MkTreeRule(A, A, 0, "one", Z.True, A.MkTree("one", A.AttrVar, q(0,1)));
            var rule2 = Z.TT.MkTreeRule(A, A, 0, "two", Z.True, A.MkTree("two", A.AttrVar, q(0,2), q(0,1)));

            var F = Z.TT.MkTreeAutomaton(0, A, A, new TreeRule[] { rule0, rule1, rule2 });
            var FF = F.Compose(F);

            var t1 = A.MkTree("two", Z.MkInt(22), A.MkTree("zero", Z.MkInt(5)), A.MkTree("zero", Z.MkInt(6)));
            var t2 = A.MkTree("two", Z.MkInt(22), A.MkTree("zero", Z.MkInt(6)), A.MkTree("zero", Z.MkInt(5)));

            var FFF = FF.Compose(F);
            Assert.AreEqual(3, FFF.RuleCount);

            var s1 = F[t1][0];
            var s2 = FF[t1][0];
            var s3 = FFF[t1][0];

            Assert.AreEqual<Expr>(t2, s1);
            Assert.AreEqual<Expr>(t1, s2);
            Assert.AreEqual<Expr>(t2, s3);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:38,代码来源:TreeTransducerTests.cs

示例13: 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

示例14: TestRegularLookaheadComposition2

        public void TestRegularLookaheadComposition2()
        {
            Z3Provider Z = new Z3Provider();
            var A = (Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zeroA", "oneA", "twoA" }, new int[] { 0, 1, 2 }));
            var B = (Z.TT.MkRankedAlphabet("B", Z.IntSort, new string[] { "zeroB", "oneB", "twoB" }, new int[] { 0, 1, 2 }));
            var C = (Z.TT.MkRankedAlphabet("C", Z.IntSort, new string[] { "zeroC", "oneC", "twoC" }, new int[] { 0, 1, 2 }));

            var _0 = Z.MkInt(0);
            var _1 = Z.MkInt(1);
            var _2 = Z.MkInt(2);

            var AB_r0 = Z.TT.MkTreeRule(A, B, 0, "oneA", Z.MkEq(_0, A.AttrVar), B.MkTree("oneB", Z.MkAdd(_1, A.AttrVar), A.MkTrans(B, 1, 1)), new int[][] { new int[] { 1 } });
            var AB_r1 = Z.TT.MkTreeRule(A, B, 1, "oneA", Z.MkEq(_1, A.AttrVar), B.MkTree("oneB", Z.MkAdd(_1, A.AttrVar), A.MkTrans(B, 0, 1)), new int[][] { new int[] { 0 } });
            var AB_r2 = Z.TT.MkTreeRule(A, B, 1, "oneA", Z.MkEq(_2, A.AttrVar), B.MkTree("zeroB", Z.MkAdd(_1, A.AttrVar)));

            //just accept the input if the attribute is 1 and delete the child subtree
            var BC_r0 = Z.TT.MkTreeRule(B, C, 0, "oneB", Z.MkEq(_1, B.AttrVar), C.MkTree("zeroC", B.AttrVar));

            var AB = Z.TT.MkTreeAutomaton(0, A, B, new TreeRule[] { AB_r0, AB_r1, AB_r2});
            var BC = Z.TT.MkTreeAutomaton(0, B, C, new TreeRule[] { BC_r0 });

            var AC = TreeTransducer.ComposeR(AB, BC);

            Assert.AreEqual<int>(4, AC.RuleCount);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:25,代码来源:TreeTransducerTests.cs

示例15: TupleTest

 public void TupleTest()
 {
     Z3Provider z3p = new Z3Provider();
     //create the tuple sort for mouth
     FuncDecl mouth;
     FuncDecl[] mouth_accessors;
     var MOUTH = z3p.MkTupleSort("MOUTH", new string[] { "open", "teeth" }, new Sort[] { z3p.BoolSort, z3p.IntSort }, out mouth, out mouth_accessors);
     Func<Expr,Expr,Expr> mk_mouth = ((o,t) => z3p.MkApp(mouth, o, t));
     Func<Expr,Expr> get_open = (m => z3p.MkApp(mouth_accessors[0], m));
     Func<Expr,Expr> get_teeth = (m => z3p.MkApp(mouth_accessors[1], m));
     //create the tuple sort for nose
     FuncDecl nose;
     FuncDecl[] nose_accessors;
     var NOSE = z3p.MkTupleSort("NOSE", new string[] { "size" }, new Sort[] { z3p.IntSort }, out nose, out nose_accessors);
     Func<Expr,Expr> mk_nose = (s => z3p.MkApp(nose, s));
     Func<Expr,Expr> get_size = (n => z3p.MkApp(nose_accessors[0], n));
     //create the tuple sort for head
     FuncDecl head;
     FuncDecl[] head_accessors;
     var HEAD = z3p.MkTupleSort("HEAD", new string[] { "bald", "nose", "mouth" }, new Sort[] { z3p.BoolSort, NOSE, MOUTH }, out head, out head_accessors);
     Func<Expr,Expr,Expr,Expr> mk_head = ((b,n,m) => z3p.MkApp(head, b,n,m));
     Func<Expr,Expr> get_bald = (h => z3p.MkApp(head_accessors[0], h));
     Func<Expr,Expr> get_nose = (h => z3p.MkApp(head_accessors[1], h));
     Func<Expr,Expr> get_mouth = (h => z3p.MkApp(head_accessors[2], h));
     //------------------------
     // create a transformation "punch" from HEAD tp HEAD that removes k teeth, k is  the second parameter of the transformation
     var punch = z3p.MkFuncDecl("punch", new Sort[]{HEAD, z3p.IntSort}, HEAD);
     var x = z3p.MkVar(0, HEAD);        // <-- this is the input HEAD
     var y = z3p.MkVar(1, z3p.IntSort); // <-- this is the n parameter
     //this is the actual transformation of x that removes one tooth
     var new_mouth = mk_mouth(get_open(get_mouth(x)), z3p.MkSub(get_teeth(get_mouth(x)), y));
     var old_nose = get_nose(x);
     var old_bald = get_bald(x);
     var punch_def = mk_head(old_bald, old_nose,new_mouth);
     var punch_axiom = z3p.MkEqForall(z3p.MkApp(punch, x , y), punch_def, x, y);
     Func<Expr,Expr,Expr> punch_app = ((h,k) => z3p.MkApp(punch, h,k));
     z3p.MainSolver.Assert(punch_axiom);
     //------------------------
     // create a transformation "hit" from HEAD tp HEAD that doubles the size of the nose
     var hit = z3p.MkFuncDecl("hit", HEAD, HEAD);
     var hit_def = mk_head(get_bald(x), mk_nose(z3p.MkMul(z3p.MkInt(2),get_size(get_nose(x)))), get_mouth(x));
     var hit_axiom = z3p.MkEqForall(z3p.MkApp(hit, x), hit_def, x);
     Func<Expr,Expr> hit_app = (h => z3p.MkApp(hit, h));
     z3p.MainSolver.Assert(hit_axiom);
     //-------------------------------
     // Analysis
     var H = z3p.MkConst("H", HEAD);
     var N = z3p.MkConst("N", z3p.IntSort);
     // check that hit and punch commute
     z3p.MainSolver.Push();
     z3p.MainSolver.Assert(z3p.MkNeq(punch_app(hit_app(H), N), hit_app(punch_app(H, N))));
     Status status = z3p.Check(); //here status must be UNSATISFIABLE
     z3p.MainSolver.Pop(); //remove the temporary context
     //check that hit is not idempotent
     z3p.MainSolver.Push();
     z3p.MainSolver.Assert(z3p.MkNeq(hit_app(hit_app(H)), hit_app(H)));
     status = z3p.Check(); //here status must not be UNSATISFIABLE (it is UNKNOWN due to use of axioms)
     var model1 = z3p.Z3S.Model;
     var witness1 = model1.Evaluate(H, true);   //a concrete instance of HEAD that shows when hitting twice is not the same as hitting once
     z3p.MainSolver.Pop();
     //but it is possible that hitting twice does no harm (when nose has size 0)
     z3p.MainSolver.Push();
     z3p.MainSolver.Assert(z3p.MkEq(hit_app(hit_app(H)), hit_app(H)));
     status = z3p.Check();
     var model2 = z3p.Z3S.Model;
     var witness2 = model2.Evaluate(H, true);
     z3p.MainSolver.Pop();
 }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:68,代码来源:UnitTest1.cs


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