Beispiel #1
0
        public void TestWS1S_GetAutomatonBDD_eq_GetAutomaton()
        {
            var solver = new CharSetSolver(BitWidth.BV7);
            //var nrOfLabelBits = (int)BitWidth.BV7;
            var isDigit  = solver.MkCharSetFromRegexCharClass(@"\d");
            var isLetter = solver.MkCharSetFromRegexCharClass(@"(c|C)");
            var x        = new Variable("x", false);
            var y        = new Variable("y", false);
            var z        = new Variable("z", false);
            var X        = new Variable("X", false);
            //there are at least two distinct positions x and y
            var xy = new MSOAnd <BDD>(new MSONot <BDD>(new MSOEq <BDD>(x, y)), new MSOAnd <BDD>(new MSOIsSingleton <BDD>(x), new MSOIsSingleton <BDD>(y)));
            //there is a set X containing x and y and all positions z in X have characters that satisfy isWordLetter
            var x_sub_X    = new MSOSubset <BDD>(x, X);
            var y_sub_X    = new MSOSubset <BDD>(y, X);
            var z_sub_X    = new MSOSubset <BDD>(z, X);
            var isletter_z = new MSOPredicate <BDD>(isLetter, z);
            var psi        = new MSOExists <BDD>(X, (x_sub_X & y_sub_X & ~(new MSOExists <BDD>(z, ~((~((new MSOIsSingleton <BDD>(z)) & z_sub_X)) | isletter_z)))));

            var atLeast2w   = xy & psi;
            var atLeast2wEE = new MSOExists <BDD>(x, (new MSOExists <BDD>(y, atLeast2w)));
            var autBDD      = atLeast2w.GetAutomaton(solver);
            var ca          = new CartesianAlgebraBDD <BDD>(solver);
            var autPROD     = atLeast2w.GetAutomaton(ca);
            //autBDD.ShowGraph("autBDD");
            //autPROD.ShowGraph("autPROD");
            var aut_atLeast2wEE1 = BasicAutomata.Restrict(atLeast2wEE.GetAutomaton(ca));
            var aut_atLeast2wEE2 = atLeast2wEE.GetAutomaton(solver);

            //aut_atLeast2wEE1.ShowGraph("aut_atLeast2wEE1");
            //aut_atLeast2wEE2.ShowGraph("aut_atLeast2wEE2");
            Assert.IsTrue(aut_atLeast2wEE1.IsEquivalentWith(aut_atLeast2wEE2));
        }
Beispiel #2
0
        public void TestWS1S_GetAutomatonBDD_eq_GetAutomaton()
        {
            var solver        = new CharSetSolver(BitWidth.BV7);
            var nrOfLabelBits = (int)BitWidth.BV7;
            var isDigit       = solver.MkCharSetFromRegexCharClass(@"\d");
            var isLetter      = solver.MkCharSetFromRegexCharClass(@"(c|C)");
            var x             = new WS1SVariable <BDD>("x");
            var y             = new WS1SVariable <BDD>("y");
            var z             = new WS1SVariable <BDD>("z");
            var X             = new WS1SVariable <BDD>("X");
            //there are at least two distinct positions x and y
            var xy = (x != y) & !x & !y;
            //there is a set X containing x and y and all positions z in X have characters that satisfy isWordLetter
            var psi = X ^ ((x <= X) & (y <= X) & ~(z ^ ~(~(!z & z <= X) | isLetter % z)));

            var atLeast2w   = xy & psi;
            var atLeast2wEE = x ^ (y ^ atLeast2w);
            var autBDD      = atLeast2w.GetAutomatonBDD(solver, nrOfLabelBits, x, y);
            var ca          = new CartesianAlgebraBDD <BDD>(solver);
            var autPROD     = atLeast2w.GetAutomaton(ca, x, y);
            //autBDD.ShowGraph("autBDD");
            //autPROD.ShowGraph("autPROD");
            var aut_atLeast2wEE1 = BasicAutomata.Restrict(atLeast2wEE.GetAutomaton(ca));
            var aut_atLeast2wEE2 = atLeast2wEE.GetAutomatonBDD(solver, nrOfLabelBits);

            //aut_atLeast2wEE1.ShowGraph("aut_atLeast2wEE1");
            //aut_atLeast2wEE2.ShowGraph("aut_atLeast2wEE2");
            Assert.IsTrue(aut_atLeast2wEE1.IsEquivalentWith(aut_atLeast2wEE2, solver));
        }
Beispiel #3
0
        //Automaton<T> Restrict<T>(Automaton<IMonadicPredicate<BDD, T>> autom)
        //{
        //    List<Move<T>> moves = new List<Move<T>>();
        //    foreach (var move in autom.GetMoves())
        //        moves.Add(new Move<T>(move.SourceState, move.TargetState, move.Label.ProjectSecond()));
        //    var res = Automaton<T>.Create(autom.InitialState, autom.GetFinalStates(), moves);
        //    return res;
        //}

        public void TestWS1S_UseOfCharRangePreds <T>(IBooleanAlgebra <T> solver, T isDigit, T isWordLetter, IRegexConverter <T> regexConverter)
        {
            var ca = new CartesianAlgebraBDD <T>(solver);
            var x  = new Variable("x", false);
            var y  = new Variable("y", false);
            var z  = new Variable("z", false);
            var X  = new Variable("X", false);
            //there are at least two distinct positions x and y
            var xy = new MSOAnd <T>(new MSOAnd <T>(new MSONot <T>(new MSOEq <T>(x, y)), new MSOIsSingleton <T>(x)), new MSOIsSingleton <T>(y));
            //there is a set X containing x and y and all positions z in X have characters that satisfy isWordLetter
            var phi = new MSOExists <T>(X, new MSOAnd <T>(
                                            new MSOAnd <T>(new MSOSubset <T>(x, X), new MSOSubset <T>(y, X)),
                                            new MSONot <T>(new MSOExists <T>(z, new MSONot <T>(
                                                                                 new MSOOr <T>(new MSONot <T>(new MSOAnd <T>(new MSOIsSingleton <T>(z), new MSOSubset <T>(z, X))),
                                                                                               new MSOPredicate <T>(isWordLetter, z)))))));

            var psi2        = new MSOAnd <T>(xy, phi);
            var atLeast2wEE = new MSOExists <T>(x, new MSOExists <T>(y, psi2));
            var psi1        = new MSOAnd <T>(new MSOIsSingleton <T>(x), new MSOPredicate <T>(isDigit, x));
            var aut_psi1    = psi1.GetAutomaton(ca);
            //aut_psi1.ShowGraph("SFA(psi1)");
            var atLeast1d = new MSOExists <T>(x, psi1);
            var psi       = new MSOAnd <T>(atLeast2wEE, atLeast1d);
            var aut1      = psi.GetAutomaton(ca);
            //var aut_atLeast1d = atLeast1d.GetAutomaton(solver);

            var aut2 = regexConverter.Convert(@"\w.*\w", System.Text.RegularExpressions.RegexOptions.Singleline).Intersect(regexConverter.Convert(@"\d"));

            //aut1.ShowGraph("aut1");
            //aut2.ShowGraph("aut2");

            bool equiv = aut2.IsEquivalentWith(BasicAutomata.Restrict(aut1));

            Assert.IsTrue(equiv);

            //solver.ShowGraph(aut_atLeast1d, "aut_atLeast1d");

            var aut_psi2 = psi2.GetAutomaton(ca);
            // var aut_atLeast2wEE = atLeast2wEE.GetAutomaton(ca, "x", "y");
            // var aut_atLeast2wEE2 = atLeast2wEE.GetAutomaton(solver);
            //aut_psi2.ShowGraph("SFA(psi2)");
            //aut_atLeast2wEE.ShowGraph("aut_atLeast2wEE");
            //aut_atLeast2wEE2.ShowGraph("aut_atLeast2wEE2");
            //solver.ShowGraph(aut_atLeast2wEE2, "aut_atLeast2wEE2");
        }