Beispiel #1
0
        public void mod3inBinary()
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            //(number of 1's in even postion mod 3) is same as (number of 1's in odd position mod 3)
            int       i;
            PDLPosVar p   = new PDLPosVar("p");
            PDLPred   phi = new PDLFalse();

            for (i = 0; i < 3; i++)
            {
                phi = new PDLOr(phi, new PDLAnd(
                                    new PDLModSetEq(new PDLIntersect
                                                        (new PDLPredSet("p", new PDLAtPos('b', p)),
                                                        (new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 0)))), 3, i),
                                    new PDLModSetEq(new PDLIntersect
                                                        (new PDLPredSet("p", new PDLAtPos('b', p)),
                                                        (new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 1)))), 3, i)));
            }

            StringBuilder sb = new StringBuilder();

            phi.ToString(sb);
            System.Console.WriteLine(sb);
            //System.Console.WriteLine(Convert.ToString(43, 2));
            //System.Console.WriteLine(phi.Eval(Convert.ToString(57, 2), new Dictionary<string, int>()));

            var dfa = phi.GetDFA(al, solver);
            ////string file = "../../../TestPDL/DotFiles/mod3inBinary";
            ////solver.SaveAsDot(dfa, "aut", file);
        }
Beispiel #2
0
        public void size()
        {
            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 PDLAnd(new PDLIntEq(new PDLIndicesOf("ba"), 2), new PDLEndsWith("a"));

            Console.WriteLine(phi.GetFormulaSize());
            //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);
        }
Beispiel #3
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));
        }
Beispiel #4
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 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 Test35() // (ab)*
        {
            PDLPos  p   = new PDLPosVar("p");
            PDLPred phi = new PDLAnd(new PDLAtSet('a', new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 1))),
                                     new PDLAnd(new PDLAtSet('b', new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 0))),
                                                new PDLModSetEq(new PDLAllPos(), 2, 0)));

            PrintDFA(phi, "Test35", new List <char> {
                'a', 'b'
            });
        }
        public void Test29() // Contains a 'a', and # of 'b's appearing after the first a is odd
        {
            PDLPos  x   = new PDLPosVar("x");
            PDLPos  p   = new PDLPosVar("p");
            PDLPred phi = new PDLModSetEq(new PDLIntersect(new PDLIndicesOf("b"),
                                                           new PDLPredSet("p", new PDLExistsFO("x", new PDLAnd(new PDLAtPos('a', x),
                                                                                                               new PDLPosLe(x, p))))), 2, 0);

            PrintDFA(phi, "Test29", 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'
            });
        }
        public void Test14() // all strings whose value when interpreted as numbers in binary is divisible by 3
        {
            //(number of 1's in even postion mod 3) is same as (number of 1's in odd position mod 3)
            int       i;
            PDLPosVar p   = new PDLPosVar("p");
            PDLPred   phi = new PDLFalse();

            for (i = 0; i < 3; i++)
            {
                phi = new PDLOr(phi, new PDLAnd(
                                    new PDLModSetEq(new PDLIntersect
                                                        (new PDLPredSet("p", new PDLAtPos('b', p)),
                                                        (new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 0)))), 3, i),
                                    new PDLModSetEq(new PDLIntersect
                                                        (new PDLPredSet("p", new PDLAtPos('b', p)),
                                                        (new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 1)))), 3, i)));
            }

            PrintDFA(phi, "Test14", new List <char> {
                'a', 'b'
            });
        }
        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 void Test14() // all strings whose value when interpreted as numbers in binary is divisible by 3
        {
            //(number of 1's in even postion mod 3) is same as (number of 1's in odd position mod 3)
            int i;
            PDLPosVar p = new PDLPosVar("p");
            PDLPred phi = new PDLFalse();

            for (i = 0; i < 3; i++)
            {
                phi = new PDLOr(phi, new PDLAnd(
                    new PDLModSetEq(new PDLIntersect
                    (new PDLPredSet("p", new PDLAtPos('b', p)),
                    (new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 0)))), 3, i),
                    new PDLModSetEq(new PDLIntersect
                    (new PDLPredSet("p", new PDLAtPos('b', p)),
                    (new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 1)))), 3, i)));

            }

            PrintDFA(phi, "Test14", new List<char> { 'a', 'b' });

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

            //(number of 1's in even postion mod 3) is same as (number of 1's in odd position mod 3)
            int i;
            PDLPosVar p = new PDLPosVar("p");
            PDLPred phi = new PDLFalse();

            for(i=0;i<3;i++)
            {
                phi = new PDLOr(phi, new PDLAnd(
                    new PDLModSetEq(new PDLIntersect
                    (new PDLPredSet("p", new PDLAtPos('b', p)),
                    (new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 0)))), 3, i),
                    new PDLModSetEq(new PDLIntersect
                    (new PDLPredSet("p", new PDLAtPos('b', p)),
                    (new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 1)))), 3, i)));

            }

            StringBuilder sb = new StringBuilder();
            phi.ToString(sb);
            System.Console.WriteLine(sb);
            //System.Console.WriteLine(Convert.ToString(43, 2));
            //System.Console.WriteLine(phi.Eval(Convert.ToString(57, 2), new Dictionary<string, int>()));

            var dfa = phi.GetDFA(al, solver);
            ////string file = "../../../TestPDL/DotFiles/mod3inBinary";
            ////solver.SaveAsDot(dfa, "aut", file);

        }
        public void size()
        {
            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 PDLAnd(new PDLIntEq(new PDLIndicesOf("ba"),2),new PDLEndsWith("a"));

            Console.WriteLine(phi.GetFormulaSize());
            //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 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));
        }
        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 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 Test35() // (ab)*
 {
     PDLPos p = new PDLPosVar("p");
     PDLPred phi = new PDLAnd(new PDLAtSet('a', new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 1))),
                     new PDLAnd(new PDLAtSet('b', new PDLPredSet("p", new PDLModSetEq(new PDLAllPosUpto(p), 2, 0))),
                         new PDLModSetEq(new PDLAllPos(), 2, 0)));
     PrintDFA(phi, "Test35", 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 Test29() // Contains a 'a', and # of 'b's appearing after the first a is odd
        {
            PDLPos x = new PDLPosVar("x");
            PDLPos p = new PDLPosVar("p");
            PDLPred phi = new PDLModSetEq(new PDLIntersect(new PDLIndicesOf("b"),
                                            new PDLPredSet("p", new PDLExistsFO("x", new PDLAnd(new PDLAtPos('a', x),
                                                new PDLPosLe(x, p))))), 2, 0);

            PrintDFA(phi, "Test29", new List<char> { 'a', 'b' });
        }