示例#1
0
        public void evenSpacingA() //any two a's are separated by even number of symbols
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPos px = new PDLPosVar("x");
            PDLPos py = new PDLPosVar("y");

            //TODO - is it possible to consider string as type PDLvar?
            PDLPred phi = new PDLForallFO("x", new PDLForallFO("y", new PDLIf(
                                                                   new PDLAnd(new PDLAnd(new PDLPosLe(px, py), new PDLAtPos('a', px)), new PDLAtPos('a', py)),
                                                                   new PDLModSetEq(new PDLIntersect(new PDLAllPosAfter(px), new PDLAllPosBefore(py)), 2, 0))));

            StringBuilder sb = new StringBuilder();

            phi.ToString(sb);

            System.Console.WriteLine(sb);

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

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

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

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

            Assert.IsTrue(dfa.IsEquivalentWith(test, solver));
        }
示例#2
0
        public void OddA()
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPred phi = new PDLForallFO("p", new PDLIf(new PDLModSetEq(
                                                             new PDLAllPosUpto(new PDLPosVar("p")), 2, 1), new PDLAtPos('a', new PDLPosVar("p"))));

            StringBuilder sb = new StringBuilder();

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

            System.Console.WriteLine(sb);

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

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

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

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

            //solver.SaveAsDot(dfa, "aut", file);
        }
        public void Test10() // all odd postions have 'a'
        {
            PDLPred phi = new PDLForallFO("p", new PDLIf(new PDLModSetEq(
                                                             new PDLAllPosBefore(new PDLPosVar("p")), 2, 1), new PDLAtPos('a', new PDLPosVar("p"))));

            PrintDFA(phi, "Test10", new List <char> {
                'a', 'b'
            });
        }
        public void Test34() // All b's appear in pairs only, a*bb(aa*bb)*a*,
        {
            var     x   = new PDLPosVar("x");
            PDLPred phi = new PDLForallFO("x", new PDLIf(new PDLAtPos('b', x),
                                                         new PDLIff(new PDLAtPos('b', new PDLSuccessor(x)), new PDLNot(new PDLAtPos('b', new PDLPredecessor(x))))));

            PrintDFA(phi, "Test34", new List <char> {
                'a', 'b'
            });
        }
        public void Test42() // #a's = #b's and Each even prefix has equal number of a's and b's, (ab+ba)*
        {
            var     x   = new PDLPosVar("x");
            var     y   = new PDLPosVar("y");
            PDLPred phi = new PDLForallFO("x", new PDLIf(new PDLModSetEq(new PDLAllPosUpto(x), 2, 1), new PDLExistsFO("y",
                                                                                                                      new PDLAnd(new PDLIsSuccessor(x, y), new PDLIff(new PDLAtPos('a', x), new PDLAtPos('b', y))))));

            PrintDFA(phi, "Test42", new List <char> {
                'a', 'b'
            });
        }
        public void Test19() //any two a's are separated by even number of symbols
        {
            PDLPos px = new PDLPosVar("x");
            PDLPos py = new PDLPosVar("y");
            //TODO - is it possible to consider string as type PDLvar?
            PDLPred phi = new PDLForallFO("x", new PDLForallFO("y", new PDLIf(
                                                                   new PDLAnd(new PDLAtPos('a', px), new PDLAtPos('a', py)),
                                                                   new PDLModSetEq(new PDLIntersect(new PDLAllPosAfter(px), new PDLAllPosBefore(py)), 2, 0))));

            PrintDFA(phi, "Test19", new List <char> {
                'a', 'b'
            });
        }
示例#7
0
        public static Testcase createTestFormula19()
        {
            PDLPred language = new PDLForallFO("x",
                                               new PDLForallFO("y",
                                                               new PDLIf(
                                                                   new PDLAnd(
                                                                       new PDLBelongs(new PDLPosVar("x"), new PDLIndicesOf("00")),
                                                                       new PDLBelongs(new PDLPosVar("y"), new PDLIndicesOf("11"))
                                                                       ),
                                                                   new PDLPosLe(new PDLPosVar("x"), new PDLPosVar("y"))
                                                                   )
                                                               ));

            return(new Testcase(19, createAlphabet10(), language));
        }
示例#8
0
        public static Testcase createTestcase18()
        {
            PDLPred language = new PDLForallFO("x",
                                               new PDLForallFO("y",
                                                               new PDLIf(
                                                                   new PDLAnd(
                                                                       new PDLBelongs(new PDLPosVar("x"), new PDLIndicesOf("00")),
                                                                       new PDLBelongs(new PDLPosVar("y"), new PDLIndicesOf("11"))
                                                                       ),
                                                                   new PDLPosLe(new PDLPosVar("x"), new PDLPosVar("y"))
                                                                   )
                                                               ));

            return(new Testcase(18, oneZeroAlphabet, language));
        }
示例#9
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");
            }
        }
        public void OddA()
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPred phi = new PDLForallFO("p", new PDLIf(new PDLModSetEq(
                                                             new PDLAllPosBefore(new PDLPosVar("p")), 2, 1), new PDLAtPos('a', new PDLPosVar("p"))));


            StringBuilder sb = new StringBuilder();

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

            Output(sb, "OddA");
        }
        public void TestMethod2()
        {
            var solver = new CharSetSolver(BitWidth.BV64);
            List<char> alph = new List<char> { 'a', 'b' };
            HashSet<char> al = new HashSet<char>(alph);

            PDLPred phi1 = new PDLForallFO("p", new PDLIf(new PDLModSetEq(
                new PDLAllPosBefore(new PDLPosVar("p")), 2, 1), new PDLAtPos('a', new PDLPosVar("p"))));
            var dfa1 = phi1.GetDFA(al, solver);

            PDLPred phi2 = new PDLForallFO("p", new PDLIf(new PDLModSetEq(
                new PDLAllPosBefore(new PDLPosVar("p")), 2, 1), new PDLAtPos('b', new PDLPosVar("p"))));
            var dfa2 = phi2.GetDFA(al, solver);

            StringBuilder sb = new StringBuilder();
            DFAEditDistance.GetDFAOptimalEdit(dfa1, dfa2, al, solver, 3000, sb);
            Console.WriteLine(sb);
        }
示例#12
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));
        }
示例#13
0
        public void TestMethod2()
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPred phi1 = new PDLForallFO("p", new PDLIf(new PDLModSetEq(
                                                              new PDLAllPosBefore(new PDLPosVar("p")), 2, 1), new PDLAtPos('a', new PDLPosVar("p"))));
            var dfa1 = phi1.GetDFA(al, solver);

            PDLPred phi2 = new PDLForallFO("p", new PDLIf(new PDLModSetEq(
                                                              new PDLAllPosBefore(new PDLPosVar("p")), 2, 1), new PDLAtPos('b', new PDLPosVar("p"))));
            var dfa2 = phi2.GetDFA(al, solver);

            StringBuilder sb = new StringBuilder();

            DFAEditDistance.GetDFAOptimalEdit(dfa1, dfa2, al, solver, 3000, sb);
            Console.WriteLine(sb);
        }
 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");
     }
 }
        public void Test19() //any two a's are separated by even number of symbols
        {
            PDLPos px = new PDLPosVar("x");
            PDLPos py = new PDLPosVar("y");
            //TODO - is it possible to consider string as type PDLvar?
            PDLPred phi = new PDLForallFO("x", new PDLForallFO("y", new PDLIf(
                new PDLAnd(new PDLAtPos('a', px), new PDLAtPos('a', py)),
                    new PDLModSetEq(new PDLIntersect(new PDLAllPosAfter(px), new PDLAllPosBefore(py)), 2, 0))));

            PrintDFA(phi, "Test19", new List<char> { 'a', 'b' });
        }
 public void Test34() // All b's appear in pairs only, a*bb(aa*bb)*a*,
 {
     var x = new PDLPosVar("x");
     PDLPred phi = new PDLForallFO("x", new PDLIf(new PDLAtPos('b', x),
                                         new PDLIff(new PDLAtPos('b', new PDLSuccessor(x)), new PDLNot(new PDLAtPos('b', new PDLPredecessor(x))))));
     PrintDFA(phi, "Test34", new List<char> { 'a', 'b' });
 }
        public void Test42() // #a's = #b's and Each even prefix has equal number of a's and b's, (ab+ba)*
        {
            var x = new PDLPosVar("x");
            var y = new PDLPosVar("y");
            PDLPred phi = new PDLForallFO("x", new PDLIf(new PDLModSetEq(new PDLAllPosUpto(x), 2, 1), new PDLExistsFO("y",
                new PDLAnd(new PDLIsSuccessor(x, y), new PDLIff(new PDLAtPos('a', x), new PDLAtPos('b', y))))));

            PrintDFA(phi, "Test42", new List<char> { 'a', 'b' });
        }
 public void Test10() // all odd postions have 'a'
 {
     PDLPred phi = new PDLForallFO("p", new PDLIf(new PDLModSetEq(
         new PDLAllPosBefore(new PDLPosVar("p")), 2, 1), new PDLAtPos('a', new PDLPosVar("p"))));
     PrintDFA(phi, "Test10", new List<char> { 'a', 'b' });
 }
        public void OddA()
        {
            var solver = new CharSetSolver(BitWidth.BV64);
            List<char> alph = new List<char> { 'a', 'b' };
            HashSet<char> al = new HashSet<char>(alph);

            PDLPred phi = new PDLForallFO("p", new PDLIf(new PDLModSetEq(
                new PDLAllPosUpto(new PDLPosVar("p")), 2, 1), new PDLAtPos('a', new PDLPosVar("p"))));

            StringBuilder sb = new StringBuilder();

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

            System.Console.WriteLine(sb);

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

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

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

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

            //solver.SaveAsDot(dfa, "aut", file);
        }
        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 createTestFormula19()
        {
            PDLPred language = new PDLForallFO("x",
            new PDLForallFO("y",
                new PDLIf(
                    new PDLAnd(
                        new PDLBelongs(new PDLPosVar("x"), new PDLIndicesOf("00")),
                        new PDLBelongs(new PDLPosVar("y"), new PDLIndicesOf("11"))
                    ),
                    new PDLPosLe(new PDLPosVar("x"), new PDLPosVar("y"))
                )
            ));

            return new Testcase(19, createAlphabet10(), language);
        }
        public static Testcase createTestcase18()
        {
            PDLPred language = new PDLForallFO("x",
            new PDLForallFO("y",
                new PDLIf(
                    new PDLAnd(
                        new PDLBelongs(new PDLPosVar("x"), new PDLIndicesOf("00")),
                        new PDLBelongs(new PDLPosVar("y"), new PDLIndicesOf("11"))
                    ),
                    new PDLPosLe(new PDLPosVar("x"), new PDLPosVar("y"))
                )
            ));

            return new Testcase(18, oneZeroAlphabet, language);
        }
        public void evenSpacingA() //any two a's are separated by even number of symbols
        {
            var solver = new CharSetSolver(BitWidth.BV64);
            List<char> alph = new List<char> { 'a', 'b' };
            HashSet<char> al = new HashSet<char>(alph);

            PDLPos px = new PDLPosVar("x");
            PDLPos py = new PDLPosVar("y");

            //TODO - is it possible to consider string as type PDLvar?
            PDLPred phi = new PDLForallFO("x", new PDLForallFO("y", new PDLIf(
                new PDLAnd(new PDLAnd(new PDLPosLe(px, py), new PDLAtPos('a', px)), new PDLAtPos('a', py)),
                    new PDLModSetEq(new PDLIntersect(new PDLAllPosAfter(px), new PDLAllPosBefore(py)), 2, 0))));

            StringBuilder sb = new StringBuilder();

            phi.ToString(sb);

            System.Console.WriteLine(sb);

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

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

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

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

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