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

            PDLPred phi = new PDLModSetEq(new PDLIndicesOf("a"), 2, 1);
            phi = new PDLAnd(new PDLStartsWith("a"), phi);
            var dfa1 = phi.GetDFA(al, solver);

            var a = solver.MkCharConstraint(false, 'a');
            var b = solver.MkCharConstraint(false, 'b');
            var moves = new List<Move<BDD>>();

            moves.Add(new Move<BDD>(0, 0, a));
            moves.Add(new Move<BDD>(0, 5, a));
            moves.Add(new Move<BDD>(5, 0, a));
            moves.Add(new Move<BDD>(5, 5, b));

            var dfa2 = Automaton<BDD>.Create(0, new int[] { 5 }, moves);
            var feedbackGrade = DFAGrading.GetGrade(dfa1, dfa2, al, solver, timeout, 10, FeedbackLevel.Solution, true, false, false);
            var feedString = "<ul>";
            foreach (var feed in feedbackGrade.Second)
                feedString += string.Format("<li>{0}</li>", feed);
            feedString += "</ul>";

            Console.Write( string.Format("<div>Grade: {0} <br /> Feedback: {1}</div>", feedbackGrade.First, feedString));
        }
Beispiel #2
0
        public void a2b1() //atleast 2 a's and atmost one b
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPred phi = new PDLAnd(new PDLNot(new PDLIntLeq(new PDLIndicesOf("a"), 1)), new PDLIntLeq(new PDLIndicesOf("b"), 1));

            StringBuilder sb = new StringBuilder();

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

            System.Console.WriteLine(sb);

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


            var test = solver.Convert(@"^(aa+|baa+|aba+|aa+ba*)$");

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

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

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

            PDLPred 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())));

            StringBuilder sb = new StringBuilder();

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

            System.Console.WriteLine(sb);

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

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

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

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

            //solver.SaveAsDot(dfa, "aut", file);
        }
Beispiel #4
0
        public void contains_aa_notend_ab()
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            //new PDL

            PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0));
            PDLPred phi2 = (new PDLBelongs(new PDLPredecessor(new PDLLast()), new PDLIndicesOf("ab")));
            //PDLpred phi2 = new PDLAnd(new PDLatPos('a', new PDLprev(new PDLlast())), new PDLatPos('b', new PDLlast()));
            PDLPred phi = new PDLAnd(phi1, new PDLNot(phi2));
            //new PDLAnd(new PDLatPos('a', new PDLprev(new PDLlast())), new PDLatPos('b', new PDLlast())));

            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|b)*aa(((a|b)*(aa|ba|bb))|(a*))$");

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

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

            Assert.IsTrue(dfa.IsEquivalentWith(test, solver));
        }
Beispiel #5
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);
        }
        public void Test33() // All b's appear consecutively and string ends with a, alternately a*b*a*a
        {
            PDLPred phi = new PDLAnd(new PDLIntLeq(new PDLIndicesOf("ba"), 1), new PDLEndsWith("a"));

            PrintDFA(phi, "Test33", new List <char> {
                'a', 'b'
            });
        }
        public void Test20() //b*aaab*
        {
            PDLPred phi = new PDLAnd(new PDLIntEq(new PDLIndicesOf("aaa"), 1), new PDLIntEq(new PDLIndicesOf("a"), 3));

            PrintDFA(phi, "Test20", new List <char> {
                'a', 'b'
            });
        }
Beispiel #8
0
        public static Testcase createTestFormula8()
        {
            PDLPred language = new PDLAnd(
                new PDLModSetEq(new PDLIndicesOf("0"), 5, 0),
                new PDLModSetEq(new PDLIndicesOf("1"), 3, 0));

            return(new Testcase(8, createAlphabet10(), language));
        }
Beispiel #9
0
        public static Testcase createTestcase7()
        {
            PDLPred language = new PDLAnd(
                new PDLModSetEq(new PDLIndicesOf("0"), 5, 0),
                new PDLModSetEq(new PDLIndicesOf("1"), 3, 0));

            return(new Testcase(7, oneZeroAlphabet, language));
        }
Beispiel #10
0
        public static Testcase createTestcase16()
        {
            PDLPred language = new PDLAnd(
                new PDLIntGe(new PDLIndicesOf("a"), 0),
                new PDLIntGe(new PDLIndicesOf("b"), 0)
                );

            return(new Testcase(16, abAlphabet, language));
        }
Beispiel #11
0
        public static Testcase createTestFormula15()
        {
            PDLPred language = new PDLAnd(
                new PDLExistsFO("x", new PDLAtPos('a', new PDLPosVar("x"))),
                new PDLExistsFO("y", new PDLAtPos('b', new PDLPosVar("y")))
                );

            return(new Testcase(15, createAlphabetAB(), language));
        }
Beispiel #12
0
        public static Testcase createTestFormula17()
        {
            PDLPred language = new PDLAnd(
                new PDLIntGe(new PDLIndicesOf("a"), 0),
                new PDLIntGe(new PDLIndicesOf("b"), 0)
                );

            return(new Testcase(17, createAlphabetAB(), language));
        }
        public void Test11() // first symbol = last symbol
        {
            PDLPred 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())));

            PrintDFA(phi, "Test11", new List <char> {
                'a', 'b'
            });
        }
Beispiel #14
0
        public static Testcase createTestcase14()
        {
            PDLPred language = new PDLAnd(
                new PDLExistsFO("x", new PDLAtPos('a', new PDLPosVar("x"))),
                new PDLExistsFO("y", new PDLAtPos('b', new PDLPosVar("y")))
                );

            return(new Testcase(14, abAlphabet, language));
        }
        public void Test16() // string containing aa and ending with ab
        {
            PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0));
            PDLPred phi2 = new PDLAnd(new PDLAtPos('a', new PDLPredecessor(new PDLLast())), new PDLAtPos('b', new PDLLast()));
            PDLPred phi  = new PDLAnd(phi1, phi2);

            PrintDFA(phi, "Test16", new List <char> {
                'a', 'b'
            });
        }
        public void Test17() // string not containing aa but ends with ab
        {
            PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0));
            PDLPred phi2 = (new PDLBelongs(new PDLPredecessor(new PDLLast()), new PDLIndicesOf("ab")));
            PDLPred phi  = new PDLAnd(phi1, new PDLNot(phi2));

            PrintDFA(phi, "Test17", 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'
            });
        }
Beispiel #18
0
        public void Grade2DFAs()
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPred phi = new PDLAnd(new PDLIntGeq(new PDLIndicesOf("a"), 2), new PDLIntGeq(new PDLIndicesOf("b"), 2));

            //PDLPred phi2 = new PDLIf(new PDLStartsWith("b"), new PDLEndsWith("b"));
            var dfaCorr = phi.GetDFA(al, solver);

            var a     = solver.MkCharConstraint(false, 'a');
            var b     = solver.MkCharConstraint(false, 'b');
            var moves = new List <Move <BDD> >();

            moves.Add(new Move <BDD>(0, 1, a));
            moves.Add(new Move <BDD>(0, 1, b));
            moves.Add(new Move <BDD>(1, 2, a));
            moves.Add(new Move <BDD>(1, 2, b));
            moves.Add(new Move <BDD>(2, 3, a));
            moves.Add(new Move <BDD>(2, 3, b));
            moves.Add(new Move <BDD>(3, 3, a));
            moves.Add(new Move <BDD>(3, 3, b));
            //moves.Add(new Move<BDD>(3, 4, a));
            //moves.Add(new Move<BDD>(3, 2, b));
            //moves.Add(new Move<BDD>(4, 4, a));
            //moves.Add(new Move<BDD>(4, 5, b));
            //moves.Add(new Move<BDD>(5, 6, a));
            //moves.Add(new Move<BDD>(5, 4, b));
            //moves.Add(new Move<BDD>(6, 6, a));
            //moves.Add(new Move<BDD>(6, 6, b));

            var dfa2 = Automaton <BDD> .Create(0, new int[] { 3 }, moves);

            //Assert.IsTrue(phi2.GetDFA(al,solver).IsEquivalentWith(dfa2,solver));

            solver.SaveAsDot(dfaCorr, "aa", "corr");
            solver.SaveAsDot(dfa2, "aa", "wrong");

            //var v0 = DFADensity.GetDFADifferenceRatio(dfa1, dfa2, al, solver);
            //var v1 = PDLEditDistance.GetMinimalFormulaEditDistanceRatio(dfa1, dfa2, al, solver, timeout);
            //var v2 = DFAEditDistance.GetDFAOptimalEdit(dfa1, dfa2, al, solver, 4, new StringBuilder());
            //Console.WriteLine("density ratio: {0}; pdl edit distance: {1}; dfa edit distance: {2}", v0, v1, v2);

            var gr = DFAGrading.GetGrade(dfaCorr, dfa2, al, solver, 2000, 10, FeedbackLevel.Hint, true, true, true);

            Console.WriteLine(gr.First);
            foreach (var f in gr.Second)
            {
                Console.WriteLine(f.ToString());
            }
        }
Beispiel #19
0
        public static Testcase createTestcase9()
        {
            PDLPred language = new PDLAnd(
                new PDLIf(
                    new PDLAtPos('a', new PDLLast()),
                    new PDLNot(
                        new PDLExistsFO(
                            "x",
                            new PDLAnd(
                                new PDLPosLe(new PDLPosVar("x"), new PDLLast()),
                                new PDLAtPos('a', new PDLPosVar("x"))
                                )
                            )
                        )
                    ),
                new PDLAnd(
                    new PDLIf(
                        new PDLAtPos('b', new PDLLast()),
                        new PDLNot(
                            new PDLExistsFO(
                                "x",
                                new PDLAnd(
                                    new PDLPosLe(new PDLPosVar("x"), new PDLLast()),
                                    new PDLAtPos('b', new PDLPosVar("x"))
                                    )
                                )
                            )
                        ),
                    new PDLIf(
                        new PDLAtPos('c', new PDLLast()),
                        new PDLNot(
                            new PDLExistsFO(
                                "x",
                                new PDLAnd(
                                    new PDLPosLe(new PDLPosVar("x"), new PDLLast()),
                                    new PDLAtPos('c', new PDLPosVar("x"))
                                    )
                                )
                            )
                        )
                    )
                );

            return(new Testcase(9, new char[] { 'a', 'b', 'c' }, language));
        }
        public void SameFirstLast()
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPred 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())));


            StringBuilder sb = new StringBuilder();

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

            Output(sb, "SameFirstLast");
        }
Beispiel #21
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));
        }
        public void contains_aa_end_ab()
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            //new PDL

            PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0));
            PDLPred phi2 = new PDLAnd(new PDLAtPos('a', new PDLPredecessor(new PDLLast())), new PDLAtPos('b', new PDLLast()));
            PDLPred phi  = new PDLAnd(phi1, phi2);


            StringBuilder sb = new StringBuilder();

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

            Output(sb, "contains_aa_end_ab");
        }
Beispiel #23
0
        public void firstOcc()
        {
            var         solver = new CharSetSolver(BitWidth.BV64);
            List <char> alph   = new List <char> {
                'a', 'b', 'c'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPred phi = new PDLAnd(new PDLNot(new PDLIntLeq(new PDLIndicesOf("abc"), 0)),
                                     new PDLIntLeq(new PDLAllPosBefore(new PDLFirstOcc("abc")), 2));

            StringBuilder sb = new StringBuilder();

            phi.ToString(sb);
            System.Console.WriteLine(sb);

            System.Console.WriteLine(phi.Eval("acabc", new Dictionary <string, int>()));

            var dfa = phi.GetDFA(al, solver);
            //string file = "../../../TestPDL/DotFiles/firstOcc";
            //solver.SaveAsDot(dfa, "aut", file);
        }
Beispiel #24
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>()));
        }
Beispiel #25
0
        public void DileepTest1()
        {
            PDLEnumerator pdlEnumerator = new PDLEnumerator();
            var           solver        = new CharSetSolver(BitWidth.BV64);
            List <char>   alph          = new List <char> {
                'a', 'b'
            };
            HashSet <char> al = new HashSet <char>(alph);

            PDLPred phi = new PDLModSetEq(new PDLIndicesOf("a"), 2, 1);

            phi = new PDLAnd(new PDLStartsWith("a"), phi);
            var dfa1 = phi.GetDFA(al, solver);

            var a     = solver.MkCharConstraint(false, 'a');
            var b     = solver.MkCharConstraint(false, 'b');
            var moves = new List <Move <BDD> >();

            moves.Add(new Move <BDD>(0, 0, a));
            moves.Add(new Move <BDD>(0, 5, a));
            moves.Add(new Move <BDD>(5, 0, a));
            moves.Add(new Move <BDD>(5, 5, b));

            var dfa2 = Automaton <BDD> .Create(0, new int[] { 5 }, moves);

            var feedbackGrade = DFAGrading.GetGrade(dfa1, dfa2, al, solver, timeout, 10, FeedbackLevel.Solution, true, false, false);
            var feedString    = "<ul>";

            foreach (var feed in feedbackGrade.Second)
            {
                feedString += string.Format("<li>{0}</li>", feed);
            }
            feedString += "</ul>";

            Console.Write(string.Format("<div>Grade: {0} <br /> Feedback: {1}</div>", feedbackGrade.First, feedString));
        }
Beispiel #26
0
        public static Testcase createTestcase11()
        {
            PDLPred xInA     = new PDLBelongs(new PDLPosVar("x"), new PDLSetVar("A"));
            PDLPred xInB     = new PDLBelongs(new PDLPosVar("x"), new PDLSetVar("B"));
            PDLPred xInC     = new PDLBelongs(new PDLPosVar("x"), new PDLSetVar("C"));
            PDLPred yInA     = new PDLBelongs(new PDLPosVar("y"), new PDLSetVar("A"));
            PDLPred yInB     = new PDLBelongs(new PDLPosVar("y"), new PDLSetVar("B"));
            PDLPred yInC     = new PDLBelongs(new PDLPosVar("y"), new PDLSetVar("C"));
            PDLPred zInA     = new PDLBelongs(new PDLPosVar("z"), new PDLSetVar("A"));
            PDLPred zInB     = new PDLBelongs(new PDLPosVar("z"), new PDLSetVar("B"));
            PDLPred zInC     = new PDLBelongs(new PDLPosVar("z"), new PDLSetVar("C"));
            PDLPred xOnlyInA = new PDLAnd(xInA, new PDLAnd(new PDLNot(xInB), new PDLNot(xInC)));
            PDLPred xOnlyInB = new PDLAnd(new PDLNot(xInA), new PDLAnd(xInB, new PDLNot(xInC)));
            PDLPred xOnlyInC = new PDLAnd(new PDLNot(xInA), new PDLAnd(new PDLNot(xInB), xInC));

            PDLPred problem = new PDLForallSO("A", new PDLForallSO("B", new PDLForallSO("C",
                                                                                        new PDLIf(
                                                                                            new PDLForallFO("x",
                                                                                                            new PDLAnd(
                                                                                                                new PDLIf(new PDLAtPos('a', new PDLPosVar("x")), xOnlyInA),
                                                                                                                new PDLAnd(
                                                                                                                    new PDLIf(new PDLAtPos('b', new PDLPosVar("x")), xOnlyInB),
                                                                                                                    new PDLIf(new PDLAtPos('c', new PDLPosVar("x")), xOnlyInC)
                                                                                                                    ))
                                                                                                            ),
                                                                                            new PDLForallFO("x", new PDLForallFO("y",
                                                                                                                                 new PDLAnd(
                                                                                                                                     new PDLIf(new PDLAnd(xInA, yInB), new PDLPosLe(new PDLPosVar("x"), new PDLPosVar("y"))),
                                                                                                                                     new PDLIf(new PDLAnd(xInB, yInC), new PDLPosLe(new PDLPosVar("x"), new PDLPosVar("y")))
                                                                                                                                     )
                                                                                                                                 ))
                                                                                            )
                                                                                        )));

            return(new Testcase(11, new char[] { 'a', 'b', 'c' }, problem));
        }
        public static Testcase createTestFormula10()
        {
            PDLPred language = new PDLAnd(
                new PDLIf(
                    new PDLAtPos('a', new PDLLast()),
                    new PDLNot(
                        new PDLExistsFO(
                            "x",
                            new PDLAnd(
                                new PDLPosLe(new PDLPosVar("x"), new PDLLast()),
                                new PDLAtPos('a', new PDLPosVar("x"))
                            )
                        )
                    )
                ),
                new PDLAnd(
                    new PDLIf(
                        new PDLAtPos('b', new PDLLast()),
                        new PDLNot(
                            new PDLExistsFO(
                                "x",
                                new PDLAnd(
                                    new PDLPosLe(new PDLPosVar("x"), new PDLLast()),
                                    new PDLAtPos('b', new PDLPosVar("x"))
                                )
                            )
                        )
                    ),
                    new PDLIf(
                        new PDLAtPos('c', new PDLLast()),
                        new PDLNot(
                            new PDLExistsFO(
                                "x",
                                new PDLAnd(
                                    new PDLPosLe(new PDLPosVar("x"), new PDLLast()),
                                    new PDLAtPos('c', new PDLPosVar("x"))
                                )
                            )
                        )
                    )
                )
           );

            return new Testcase(10,new char[] { 'a', 'b', 'c' }, language);
        }
        public void a2b1() //atleast 2 a's and atmost one b
        {
            var solver = new CharSetSolver(BitWidth.BV64);
            List<char> alph = new List<char> { 'a', 'b' };
            HashSet<char> al = new HashSet<char>(alph);

            PDLPred phi = new PDLAnd(new PDLNot(new PDLIntLeq(new PDLIndicesOf("a"), 1)), new PDLIntLeq(new PDLIndicesOf("b"), 1));

            StringBuilder sb = new StringBuilder();

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

            System.Console.WriteLine(sb);

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

            var test = solver.Convert(@"^(aa+|baa+|aba+|aa+ba*)$");

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

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

            Assert.IsTrue(dfa.IsEquivalentWith(test, solver));
        }
        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 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 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 Grade2DFAs()
        {
            var solver = new CharSetSolver(BitWidth.BV64);
            List<char> alph = new List<char> { 'a', 'b' };
            HashSet<char> al = new HashSet<char>(alph);

            PDLPred phi = new PDLAnd(new PDLIntGeq(new PDLIndicesOf("a"), 2), new PDLIntGeq(new PDLIndicesOf("b"), 2));

            //PDLPred phi2 = new PDLIf(new PDLStartsWith("b"), new PDLEndsWith("b"));
            var dfaCorr = phi.GetDFA(al, solver);

            var a = solver.MkCharConstraint(false, 'a');
            var b = solver.MkCharConstraint(false, 'b');
            var moves = new List<Move<BDD>>();

            moves.Add(new Move<BDD>(0, 1, a));
            moves.Add(new Move<BDD>(0, 1, b));
            moves.Add(new Move<BDD>(1, 2, a));
            moves.Add(new Move<BDD>(1, 2, b));
            moves.Add(new Move<BDD>(2, 3, a));
            moves.Add(new Move<BDD>(2, 3, b));
            moves.Add(new Move<BDD>(3,3, a));
            moves.Add(new Move<BDD>(3, 3, b));
            //moves.Add(new Move<BDD>(3, 4, a));
            //moves.Add(new Move<BDD>(3, 2, b));
            //moves.Add(new Move<BDD>(4, 4, a));
            //moves.Add(new Move<BDD>(4, 5, b));
            //moves.Add(new Move<BDD>(5, 6, a));
            //moves.Add(new Move<BDD>(5, 4, b));
            //moves.Add(new Move<BDD>(6, 6, a));
            //moves.Add(new Move<BDD>(6, 6, b));

            var dfa2 = Automaton<BDD>.Create(0, new int[] { 3 }, moves);            
            //Assert.IsTrue(phi2.GetDFA(al,solver).IsEquivalentWith(dfa2,solver));

            solver.SaveAsDot(dfaCorr, "aa", "corr");
            solver.SaveAsDot(dfa2, "aa", "wrong");

            //var v0 = DFADensity.GetDFADifferenceRatio(dfa1, dfa2, al, solver);
            //var v1 = PDLEditDistance.GetMinimalFormulaEditDistanceRatio(dfa1, dfa2, al, solver, timeout);
            //var v2 = DFAEditDistance.GetDFAOptimalEdit(dfa1, dfa2, al, solver, 4, new StringBuilder());
            //Console.WriteLine("density ratio: {0}; pdl edit distance: {1}; dfa edit distance: {2}", v0, v1, v2);

            var gr = DFAGrading.GetGrade(dfaCorr, dfa2, al, solver, 2000, 10, FeedbackLevel.Hint, true, true, true);
            Console.WriteLine(gr.First);
            foreach (var f in gr.Second)
                Console.WriteLine(f.ToString());

        }
 public void Test33() // All b's appear consecutively and string ends with a, alternately a*b*a*a
 {
     PDLPred phi = new PDLAnd(new PDLIntLeq(new PDLIndicesOf("ba"), 1), new PDLEndsWith("a"));
     PrintDFA(phi, "Test33", new List<char> { 'a', 'b' });
 }
 public void Test11() // first symbol = last symbol
 {
     PDLPred 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())));
     PrintDFA(phi, "Test11", new List<char> { 'a', 'b' });
 }
        public static Testcase createTestcase21()
        {
            PDLPred language = new PDLAnd(
                new PDLModSetEq(new PDLIndicesOf("0"), 5, 0),
                new PDLModSetEq(new PDLIndicesOf("1"), 2, 0)
            );

            return new Testcase(21,oneZeroAlphabet, language);
        }
        public void Test17() // string not containing aa but ends with ab
        {
            PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0));
            PDLPred phi2 = (new PDLBelongs(new PDLPredecessor(new PDLLast()), new PDLIndicesOf("ab")));
            PDLPred phi = new PDLAnd(phi1, new PDLNot(phi2));

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

            PDLPred 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())));

            StringBuilder sb = new StringBuilder();

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

            System.Console.WriteLine(sb);

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

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

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

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

            //solver.SaveAsDot(dfa, "aut", file);
        }
        public void contains_aa_notend_ab()
        {
            var solver = new CharSetSolver(BitWidth.BV64);
            List<char> alph = new List<char> { 'a', 'b' };
            HashSet<char> al = new HashSet<char>(alph);

            //new PDL

            PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0));
            PDLPred phi2 = (new PDLBelongs(new PDLPredecessor(new PDLLast()), new PDLIndicesOf("ab")));
            //PDLpred phi2 = new PDLAnd(new PDLatPos('a', new PDLprev(new PDLlast())), new PDLatPos('b', new PDLlast()));
            PDLPred phi = new PDLAnd(phi1, new PDLNot(phi2));
            //new PDLAnd(new PDLatPos('a', new PDLprev(new PDLlast())), new PDLatPos('b', new PDLlast())));

            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|b)*aa(((a|b)*(aa|ba|bb))|(a*))$");

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

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

            Assert.IsTrue(dfa.IsEquivalentWith(test, solver));
        }
 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 static Testcase createTestFormula12()
        {
            PDLPred xInA = new PDLBelongs(new PDLPosVar("x"), new PDLSetVar("A"));
            PDLPred xInB = new PDLBelongs(new PDLPosVar("x"), new PDLSetVar("B"));
            PDLPred xInC = new PDLBelongs(new PDLPosVar("x"), new PDLSetVar("C"));
            PDLPred yInA = new PDLBelongs(new PDLPosVar("y"), new PDLSetVar("A"));
            PDLPred yInB = new PDLBelongs(new PDLPosVar("y"), new PDLSetVar("B"));
            PDLPred yInC = new PDLBelongs(new PDLPosVar("y"), new PDLSetVar("C"));
            PDLPred zInA = new PDLBelongs(new PDLPosVar("z"), new PDLSetVar("A"));
            PDLPred zInB = new PDLBelongs(new PDLPosVar("z"), new PDLSetVar("B"));
            PDLPred zInC = new PDLBelongs(new PDLPosVar("z"), new PDLSetVar("C"));
            PDLPred xOnlyInA = new PDLAnd(xInA, new PDLAnd(new PDLNot(xInB), new PDLNot(xInC)));
            PDLPred xOnlyInB = new PDLAnd(new PDLNot(xInA), new PDLAnd(xInB, new PDLNot(xInC)));
            PDLPred xOnlyInC = new PDLAnd(new PDLNot(xInA), new PDLAnd(new PDLNot(xInB), xInC));

            PDLPred problem = new PDLForallSO("A", new PDLForallSO("B", new PDLForallSO("C",
                new PDLIf(
                    new PDLForallFO("x",
                        new PDLAnd(
                            new PDLIf(new PDLAtPos('a', new PDLPosVar("x")), xOnlyInA),
                        new PDLAnd(
                            new PDLIf(new PDLAtPos('b', new PDLPosVar("x")), xOnlyInB),
                            new PDLIf(new PDLAtPos('c', new PDLPosVar("x")), xOnlyInC)
                        ) )
                    ),
                    new PDLForallFO("x", new PDLForallFO("y", 
                        new PDLAnd(
                            new PDLIf(new PDLAnd(xInA, yInB), new PDLPosLe(new PDLPosVar("x"), new PDLPosVar("y"))),
                            new PDLIf(new PDLAnd(xInB, yInC), new PDLPosLe(new PDLPosVar("x"), new PDLPosVar("y")))
                        )
                    ) )
                )
            ) ) );
            return new Testcase(12,new char[] { 'a','b','c' }, problem);
        }
        public static Testcase createTestFormula15()
        {
            PDLPred language = new PDLAnd(
                new PDLExistsFO("x", new PDLAtPos('a', new PDLPosVar("x"))),
                new PDLExistsFO("y", new PDLAtPos('b', new PDLPosVar("y")))
            );

            return new Testcase(15, createAlphabetAB(), language);
        }
        public static Testcase createTestFormula17()
        {
            PDLPred language = new PDLAnd(
                new PDLIntGe(new PDLIndicesOf("a"), 0),
                new PDLIntGe(new PDLIndicesOf("b"), 0)
            );

            return new Testcase(17, createAlphabetAB(), language);
        }
 public void Test20() //b*aaab*
 {
     PDLPred phi = new PDLAnd(new PDLIntEq(new PDLIndicesOf("aaa"), 1), new PDLIntEq(new PDLIndicesOf("a"), 3));
     PrintDFA(phi, "Test20", new List<char> { 'a', 'b' });
 }
        public static Testcase createTestFormula22()
        {
            PDLPred language = new PDLAnd(
                new PDLModSetEq(new PDLIndicesOf("0"), 5, 0),
                new PDLModSetEq(new PDLIndicesOf("1"), 2, 0)
            );

            return new Testcase(22,createAlphabet10(), language);
        }
        public static Testcase createTestcase14()
        {
            PDLPred language = new PDLAnd(
                new PDLExistsFO("x", new PDLAtPos('a', new PDLPosVar("x"))),
                new PDLExistsFO("y", new PDLAtPos('b', new PDLPosVar("y")))
            );

            return new Testcase(14, abAlphabet, language);
        }
        public void firstOcc()
        {
            var solver = new CharSetSolver(BitWidth.BV64);
            List<char> alph = new List<char> { 'a', 'b', 'c' };
            HashSet<char> al = new HashSet<char>(alph);

            PDLPred phi = new PDLAnd(new PDLNot(new PDLIntLeq(new PDLIndicesOf("abc"), 0)),
                new PDLIntLeq(new PDLAllPosBefore(new PDLFirstOcc("abc")), 2));

            StringBuilder sb = new StringBuilder();
            phi.ToString(sb);
            System.Console.WriteLine(sb);

            System.Console.WriteLine(phi.Eval("acabc", new Dictionary<string, int>()));

            var dfa = phi.GetDFA(al, solver);
            //string file = "../../../TestPDL/DotFiles/firstOcc";
            //solver.SaveAsDot(dfa, "aut", file);
        }
        public static Testcase createTestcase16()
        {
            PDLPred language = new PDLAnd(
                new PDLIntGe(new PDLIndicesOf("a"), 0),
                new PDLIntGe(new PDLIndicesOf("b"), 0)
            );

            return new Testcase(16, abAlphabet, language);
        }
        public void Test16() // string containing aa and ending with ab
        {
            PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0));
            PDLPred phi2 = new PDLAnd(new PDLAtPos('a', new PDLPredecessor(new PDLLast())), new PDLAtPos('b', new PDLLast()));
            PDLPred phi = new PDLAnd(phi1, phi2);

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