Пример #1
0
        public void succ2()
        {
            var solver = new CharSetSolver(BitWidth.BV64);

            List <char> alph = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPos f = new PDLFirst();
            PDLPos l = new PDLLast();
            PDLPos p = new PDLPosVar("x");

            PDLPred phi = new PDLExistsFO("x", new PDLAnd(new PDLIsSuccessor(f, p), new PDLIsSuccessor(p, l)));

            StringBuilder sb = new StringBuilder();

            phi.ToMSO(new FreshGen()).ToString(sb);

            System.Console.WriteLine(sb);

            var dfa = phi.GetDFA(al, solver);

            //string file = "../../../TestPDL/DotFiles/succ2";

            //solver.SaveAsDot(dfa, "aut", file);
        }
Пример #2
0
        public static Testcase createTestcase10()
        {
            PDLPred language = new PDLExistsFO("x",
                                               new PDLAnd(
                                                   new PDLAtPos('0', new PDLPosVar("x")),
                                                   new PDLForallSO("X",
                                                                   new PDLIf(
                                                                       new PDLAnd(
                                                                           new PDLBelongs(new PDLPosVar("x"), new PDLSetVar("X")),
                                                                           new PDLForallFO("y",
                                                                                           new PDLIf(
                                                                                               new PDLBelongs(new PDLPosVar("y"), new PDLSetVar("X")),
                                                                                               new PDLBelongs(posPlusN(new PDLPosVar("y"), 4), new PDLSetVar("X"))
                                                                                               )
                                                                                           )
                                                                           ),
                                                                       new PDLExistsFO("y",
                                                                                       new PDLAnd(
                                                                                           new PDLNot(new PDLPosEq(new PDLPosVar("x"), new PDLPosVar("y"))),
                                                                                           new PDLAnd(
                                                                                               new PDLAtPos('0', new PDLPosVar("y")),
                                                                                               new PDLBelongs(new PDLPosVar("y"), new PDLSetVar("X"))
                                                                                               )
                                                                                           )
                                                                                       )
                                                                       )
                                                                   )
                                                   )
                                               );

            return(new Testcase(10, oneZeroAlphabet, language));
        }
        public void Test1() // exists 'a'
        {
            PDLPred phi = new PDLExistsFO("x", new PDLAtPos('a', new PDLPosVar("x")));

            PrintDFA(phi, "Test1", new List <Char> {
                'a', 'b'
            });
        }
Пример #4
0
        public static Testcase createTestFormula14()
        {
            PDLPred language = new PDLExistsFO("x",
                                               new PDLAnd(
                                                   new PDLAtPos('1', new PDLPosVar("x")),
                                                   new PDLPosGeq(
                                                       new PDLPosVar("x"),
                                                       posMinusN(new PDLLast(), 9)
                                                       )
                                                   )
                                               );

            return(new Testcase(14, createAlphabet10(), language));
        }
Пример #5
0
        public static Testcase createTestcase13()
        {
            PDLPred language = new PDLExistsFO("x",
                                               new PDLAnd(
                                                   new PDLAtPos('1', new PDLPosVar("x")),
                                                   new PDLPosGeq(
                                                       new PDLPosVar("x"),
                                                       posMinusN(new PDLLast(), 9)
                                                       )
                                                   )
                                               );

            return(new Testcase(13, oneZeroAlphabet, language));
        }
        public void Exists()
        {
            PDLPred phi = new PDLExistsFO("x", new PDLAtPos('a', new PDLPosVar("x")));

            List <char> alph = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            StringBuilder sb = new StringBuilder();

            List <Pair <int, Pair <PDLPred, long> > > pairs = SynthTimer(phi, al, sb);

            Output(sb, "Exists");
        }
        public static Testcase createTestcase1()
        {
            // 0@x
            PDLPred zeroAtX = new PDLAtPos('0', new PDLPosVar("x"));
            // 0@x+1
            PDLPred zeroAtXPlus1 = new PDLAtPos('0', new PDLSuccessor(new PDLPosVar("x")));
            // 0@x+2
            PDLPred zeroAtXPlus2 = new PDLAtPos('0', new PDLSuccessor(new PDLSuccessor(new PDLPosVar("x"))));

            // \exists x. 0@x && 0@x+1 && 0@x+2
            PDLPred language = new PDLExistsFO("x",
                new PDLAnd(zeroAtX, new PDLAnd(zeroAtXPlus1, zeroAtXPlus2))
            );

            return new Testcase(1,oneZeroAlphabet, language);
        }
Пример #8
0
        public static Testcase createTestcase2()
        {
            // 0@x
            PDLPred zeroAtX = new PDLAtPos('0', new PDLPosVar("x"));
            // 1@x+1
            PDLPred zeroAtXPlus1 = new PDLAtPos('1', new PDLSuccessor(new PDLPosVar("x")));
            // 1@x+2
            PDLPred zeroAtXPlus2 = new PDLAtPos('1', new PDLSuccessor(new PDLSuccessor(new PDLPosVar("x"))));

            // \exists x. 0@x && 1@x+1 && 1@x+2
            PDLPred language = new PDLExistsFO("x",
                                               new PDLAnd(zeroAtX, new PDLAnd(zeroAtXPlus1, zeroAtXPlus2))
                                               );

            return(new Testcase(2, oneZeroAlphabet, language));
        }
        public static Testcase createTestFormula3()
        {
            // 0@x
            PDLPred zeroAtX = new PDLAtPos('0', new PDLPosVar("x"));
            // 1@x+1
            PDLPred zeroAtXPlus1 = new PDLAtPos('1', new PDLSuccessor(new PDLPosVar("x")));
            // 1@x+2
            PDLPred zeroAtXPlus2 = new PDLAtPos('1', new PDLSuccessor(new PDLSuccessor(new PDLPosVar("x"))));

            // \exists x. 0@x && 1@x+1 && 1@x+2
            PDLPred language = new PDLExistsFO("x",
                new PDLAnd(zeroAtX, new PDLAnd(zeroAtXPlus1, zeroAtXPlus2))
            );

            return new Testcase(3,createAlphabet10(), language);
        }
Пример #10
0
        public override PDLPred ToPDL(List <MonaMacro> macros, Dictionary <string, string> sub)
        {
            switch (q)
            {
            case MonaQuantifier.ExistsFO:
            {
                var ret = phi.ToPDL(macros, sub);
                foreach (var v in vars)
                {
                    return(ret = new PDLExistsFO(v, ret));
                }
                return(ret);
            }

            case MonaQuantifier.ExistsSO:
            {
                var ret = phi.ToPDL(macros, sub);
                foreach (var v in vars)
                {
                    return(ret = new PDLExistsSO(v, ret));
                }
                return(ret);
            }

            case MonaQuantifier.ForallFO:
            {
                var ret = phi.ToPDL(macros, sub);
                foreach (var v in vars)
                {
                    return(ret = new PDLForallFO(v, ret));
                }
                return(ret);
            }

            case MonaQuantifier.ForallSO:
            {
                var ret = phi.ToPDL(macros, sub);
                foreach (var v in vars)
                {
                    return(ret = new PDLForallSO(v, ret));
                }
                return(ret);
            }

            default: throw new MonaException("Quantifier undefined");
            }
        }
Пример #11
0
        public static Testcase createTestcase4()
        {
            PDLPos  lastMinusFour     = posMinusN(new PDLLast(), 4);
            PDLPred xLeqLastMinusFour = new PDLPosLeq(new PDLPosVar("x"), lastMinusFour);

            PDLPred xLeqY            = new PDLPosLeq(new PDLPosVar("x"), new PDLPosVar("y"));
            PDLPred xLeqZ            = new PDLPosLeq(new PDLPosVar("x"), new PDLPosVar("z"));
            PDLPred yLeqXPlusFour    = new PDLPosLeq(new PDLPosVar("y"), posPlusN(new PDLPosVar("x"), 4));
            PDLPred zLeqXPlusFour    = new PDLPosLeq(new PDLPosVar("z"), posPlusN(new PDLPosVar("x"), 4));
            PDLPred yNeqZ            = new PDLNot(new PDLPosEq(new PDLPosVar("y"), new PDLPosVar("z")));
            PDLPred zeroAtY          = new PDLAtPos('0', new PDLPosVar("y"));
            PDLPred zeroAtZ          = new PDLAtPos('0', new PDLPosVar("z"));
            PDLPred consequence      = new PDLAnd(xLeqY, new PDLAnd(xLeqZ, new PDLAnd(yLeqXPlusFour, new PDLAnd(zLeqXPlusFour, new PDLAnd(yNeqZ, new PDLAnd(zeroAtY, zeroAtZ))))));
            PDLPred quantConsequence = new PDLExistsFO("y", new PDLExistsFO("z", consequence));

            PDLPred language = new PDLForallFO("x", new PDLIf(xLeqLastMinusFour, quantConsequence));

            return(new Testcase(4, oneZeroAlphabet, language));
        }
Пример #12
0
        public void Exists()
        {
            var solver = new CharSetSolver(BitWidth.BV64);

            List<char> alph = new List<char> { 'a', 'b' };
            HashSet<char> al = new HashSet<char>(alph);

            PDLPred phi = new PDLExistsFO("x", new PDLAtPos('a', new PDLPosVar("x")));

            var dfa = phi.GetDFA(al, solver);

            var test = solver.Convert(@"^b*a(a|b)*$");

            Assert.IsTrue(dfa.IsEquivalentWith(test, solver));

            ////string file = "../../../TestPDL/DotFiles/exists";

            ////solver.SaveAsDot(dfa, "aut", file);

        }
Пример #13
0
        public void Exists()
        {
            var solver = new CharSetSolver(BitWidth.BV64);

            List <char> alph = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPred phi = new PDLExistsFO("x", new PDLAtPos('a', new PDLPosVar("x")));

            var dfa = phi.GetDFA(al, solver);

            var test = solver.Convert(@"^b*a(a|b)*$");

            Assert.IsTrue(dfa.IsEquivalentWith(test, solver));

            ////string file = "../../../TestPDL/DotFiles/exists";

            ////solver.SaveAsDot(dfa, "aut", file);
        }
Пример #14
0
        public void checkEval()
        {
            PDLPred phi = new PDLIntEq(new PDLIndicesOf("aaa"), 1);

            System.Console.WriteLine("Exactly once aaa:");
            System.Console.WriteLine(phi.Eval("baaaabbb", new Dictionary <string, int>()));

            PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0));
            PDLPred phi2 = (new PDLBelongs(new PDLPredecessor(new PDLLast()), new PDLIndicesOf("ab")));

            //System.Console.WriteLine("prevLast " + (new PDLprev(new PDLlast())).Eval("aaabbccab", new Dictionary<string, int>()));
            //System.Console.WriteLine("indab " + (new PDLindicesOf("ab")).Eval("aaabbccab", new Dictionary<string, int>()));


            //System.Console.WriteLine("phi2 " + phi2.Eval("aaabbccab", new Dictionary<string, int>()));

            phi = new PDLAnd(phi1, new PDLNot(phi2));
            System.Console.WriteLine("Contains aa and not end ab:");
            System.Console.WriteLine(phi.Eval("aaabbccabc", new Dictionary <string, int>()));

            phi = new PDLAnd(new PDLIf(new PDLAtPos('a', new PDLFirst()), new PDLAtPos('a', new PDLLast())),
                             new PDLIf(new PDLAtPos('b', new PDLFirst()), new PDLAtPos('b', new PDLLast())));
            System.Console.WriteLine("Same First Last:");
            System.Console.WriteLine(phi.Eval("abbba", new Dictionary <string, int>()));

            phi = new PDLExistsFO("x0", new PDLAtPos('a', new PDLPosVar("x0")));
            System.Console.WriteLine("exists a:");
            System.Console.WriteLine(phi.Eval("ab", new Dictionary <string, int>()));

            phi = new PDLEndsWith("abc");
            System.Console.WriteLine("ends with abc:");
            System.Console.WriteLine(phi.Eval("bc", new Dictionary <string, int>()));

            phi = new PDLStartsWith("abc");
            System.Console.WriteLine("starts with abc:");
            System.Console.WriteLine(phi.Eval("abcababcccabc", new Dictionary <string, int>()));
        }
 public void Test1() // exists 'a'
 {
     PDLPred phi = new PDLExistsFO("x", new PDLAtPos('a', new PDLPosVar("x")));
     PrintDFA(phi, "Test1", new List<Char> { 'a', 'b' });
 }
        public static Testcase createTestFormula5()
        {
            PDLPos lastMinusFour = posMinusN(new PDLLast(), 4);
            PDLPred xLeqLastMinusFour = new PDLPosLeq(new PDLPosVar("x"), lastMinusFour);

            PDLPred xLeqY = new PDLPosLeq(new PDLPosVar("x"), new PDLPosVar("y"));
            PDLPred xLeqZ = new PDLPosLeq(new PDLPosVar("x"), new PDLPosVar("z"));
            PDLPred yLeqXPlusFour = new PDLPosLeq(new PDLPosVar("y"), posPlusN(new PDLPosVar("x"), 4));
            PDLPred zLeqXPlusFour = new PDLPosLeq(new PDLPosVar("z"), posPlusN(new PDLPosVar("x"), 4));
            PDLPred yNeqZ = new PDLNot(new PDLPosEq(new PDLPosVar("y"), new PDLPosVar("z")));
            PDLPred zeroAtY = new PDLAtPos('0', new PDLPosVar("y"));
            PDLPred zeroAtZ = new PDLAtPos('0', new PDLPosVar("z"));
            PDLPred consequence = new PDLAnd(xLeqY, new PDLAnd(xLeqZ, new PDLAnd(yLeqXPlusFour, new PDLAnd(zLeqXPlusFour, new PDLAnd(yNeqZ, new PDLAnd(zeroAtY, zeroAtZ))))));
            PDLPred quantConsequence = new PDLExistsFO("y", new PDLExistsFO("z", consequence));

            PDLPred language = new PDLForallFO("x", new PDLIf(xLeqLastMinusFour, quantConsequence));
            return new Testcase(5,createAlphabet10(), language);
        }
        public static Testcase createTestFormula14()
        {
            PDLPred language = new PDLExistsFO("x",
                new PDLAnd(
                    new PDLAtPos('1', new PDLPosVar("x")),
                    new PDLPosGeq(
                        new PDLPosVar("x"),
                        posMinusN(new PDLLast(), 9)
                    )
                )
            );

            return new Testcase(14, createAlphabet10(), language);
        }
Пример #18
0
        public void succ2()
        {
            var solver = new CharSetSolver(BitWidth.BV64);

            List<char> alph = new List<char> { 'a', 'b' };
            HashSet<char> al = new HashSet<char>(alph);

            PDLPos f = new PDLFirst();
            PDLPos l = new PDLLast();
            PDLPos p = new PDLPosVar("x");

            PDLPred phi = new PDLExistsFO("x", new PDLAnd(new PDLIsSuccessor(f, p), new PDLIsSuccessor(p, l)));

            StringBuilder sb = new StringBuilder();

            phi.ToMSO(new FreshGen()).ToString(sb);

            System.Console.WriteLine(sb);

            var dfa = phi.GetDFA(al, solver);

            //string file = "../../../TestPDL/DotFiles/succ2";

            //solver.SaveAsDot(dfa, "aut", file);
        }
        public static Testcase createTestcase13()
        {
            PDLPred language = new PDLExistsFO("x",
                new PDLAnd(
                    new PDLAtPos('1', new PDLPosVar("x")),
                    new PDLPosGeq(
                        new PDLPosVar("x"),
                        posMinusN(new PDLLast(), 9)
                    )
                )
            );

            return new Testcase(13, oneZeroAlphabet, language);
        }
Пример #20
0
        public void checkEval()
        {
            PDLPred phi = new PDLIntEq(new PDLIndicesOf("aaa"), 1);
            System.Console.WriteLine("Exactly once aaa:");
            System.Console.WriteLine(phi.Eval("baaaabbb", new Dictionary<string, int>()));

            PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0));
            PDLPred phi2 = (new PDLBelongs(new PDLPredecessor(new PDLLast()), new PDLIndicesOf("ab")));
            //System.Console.WriteLine("prevLast " + (new PDLprev(new PDLlast())).Eval("aaabbccab", new Dictionary<string, int>()));
            //System.Console.WriteLine("indab " + (new PDLindicesOf("ab")).Eval("aaabbccab", new Dictionary<string, int>()));


            //System.Console.WriteLine("phi2 " + phi2.Eval("aaabbccab", new Dictionary<string, int>()));

            phi = new PDLAnd(phi1, new PDLNot(phi2));
            System.Console.WriteLine("Contains aa and not end ab:");
            System.Console.WriteLine(phi.Eval("aaabbccabc", new Dictionary<string, int>()));

            phi = new PDLAnd(new PDLIf(new PDLAtPos('a', new PDLFirst()), new PDLAtPos('a', new PDLLast())),
                new PDLIf(new PDLAtPos('b', new PDLFirst()), new PDLAtPos('b', new PDLLast())));
            System.Console.WriteLine("Same First Last:");
            System.Console.WriteLine(phi.Eval("abbba", new Dictionary<string, int>()));

            phi = new PDLExistsFO("x0", new PDLAtPos('a', new PDLPosVar("x0")));
            System.Console.WriteLine("exists a:");
            System.Console.WriteLine(phi.Eval("ab", new Dictionary<string, int>()));

            phi = new PDLEndsWith("abc");
            System.Console.WriteLine("ends with abc:");
            System.Console.WriteLine(phi.Eval("bc", new Dictionary<string, int>()));

            phi = new PDLStartsWith("abc");
            System.Console.WriteLine("starts with abc:");
            System.Console.WriteLine(phi.Eval("abcababcccabc", new Dictionary<string, int>()));


        }
        public static Testcase createTestFormula11()
        {
            PDLPred language = new PDLExistsFO("x",
                new PDLAnd(
                    new PDLAtPos('0', new PDLPosVar("x")),
                    new PDLForallSO("X",
                        new PDLIf(
                            new PDLAnd(
                                new PDLBelongs(new PDLPosVar("x"), new PDLSetVar("X")),
                                new PDLForallFO("y",
                                    new PDLIf(
                                        new PDLBelongs(new PDLPosVar("y"), new PDLSetVar("X")),
                                        new PDLBelongs(posPlusN(new PDLPosVar("y"), 4), new PDLSetVar("X"))
                                    )
                                )
                            ),
                            new PDLExistsFO("y",
                                new PDLAnd(
                                    new PDLNot(new PDLPosEq(new PDLPosVar("x"), new PDLPosVar("y"))),
                                    new PDLAnd(
                                        new PDLAtPos('0', new PDLPosVar("y")),
                                        new PDLBelongs(new PDLPosVar("y"), new PDLSetVar("X"))
                                    )
                                )
                            )
                        )
                    )
                )
            );

            return new Testcase(11,createAlphabet10(), language);
        }
 public override PDLPred ToPDL(List<MonaMacro> macros, Dictionary<string, string> sub)
 {
     switch (q)
     {
         case MonaQuantifier.ExistsFO:
             {
                 var ret = phi.ToPDL(macros, sub);
                 foreach(var v in vars)
                     return ret =  new PDLExistsFO(v, ret);
                 return ret;
             }
         case MonaQuantifier.ExistsSO:
             {
                 var ret = phi.ToPDL(macros, sub);
                 foreach (var v in vars)
                     return ret = new PDLExistsSO(v, ret);
                 return ret;
             }
         case MonaQuantifier.ForallFO:
             {
                 var ret = phi.ToPDL(macros, sub);
                 foreach (var v in vars)
                     return ret = new PDLForallFO(v, ret);
                 return ret;
             }
         case MonaQuantifier.ForallSO:
             {
                 var ret = phi.ToPDL(macros, sub);
                 foreach (var v in vars)
                     return ret = new PDLForallSO(v, ret);
                 return ret;
             }
         default: throw new MonaException("Quantifier undefined");
     }
 }