Esempio n. 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 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));
        }
Esempio n. 2
0
        public void TestWS1S_SuccDef_GetAutomatonBDD()
        {
            var solver        = new CharSetSolver(BitWidth.BV7);
            var nrOfLabelBits = (int)BitWidth.BV7;
            var x             = new WS1SVariable <BDD>("x");
            var y             = new WS1SVariable <BDD>("y");
            var z             = new WS1SVariable <BDD>("z");
            var xLTy          = new WS1SLt <BDD>(x, y);
            var xLTzLTy       = (x < z) & (z < y);
            var Ez            = new WS1SExists <BDD>(z, xLTzLTy);
            var notEz         = new WS1SNot <BDD>(Ez);
            var xSyDef        = new WS1SAnd <BDD>(xLTy, notEz);

            var aut_xSyDef  = xSyDef.GetAutomatonBDD(solver, nrOfLabelBits, x, y);
            var aut_xLTzLTy = xLTzLTy.GetAutomatonBDD(solver, nrOfLabelBits, x, y, z);
            var aut_Ez      = Ez.GetAutomatonBDD(solver, nrOfLabelBits, x, y).Determinize(solver).Minimize(solver);
            var aut_notEz   = notEz.GetAutomatonBDD(solver, nrOfLabelBits, x, y);
            var aut_xLTy    = xLTy.GetAutomatonBDD(solver, nrOfLabelBits, x, y);

            //aut_xSyDef.ShowGraph("aut_xSyDEf");
            //aut_xLTzLTy.ShowGraph("aut_xLTzLTy");
            //aut_Ez.ShowGraph("aut_Ez");
            //aut_notEz.ShowGraph("aut_notEz");

            var xSyPrim     = new WS1SSuccN <BDD>(x, y, 1);
            var aut_xSyPrim = xSyPrim.GetAutomatonBDD(solver, nrOfLabelBits, x, y);
            var equiv       = aut_xSyPrim.IsEquivalentWith(aut_xSyDef, solver);

            Assert.IsTrue(equiv);
        }
Esempio n. 3
0
        public void TestWS1S_NotLt()
        {
            var solver = new CharSetSolver(BitWidth.BV7);
            var ca     = new CartesianAlgebraBDD <BDD>(solver);
            var x      = new WS1SVariable <BDD>("x", true);
            var y      = new WS1SVariable <BDD>("y", true);
            var fo     = !x & !y;
            var aut_fo = fo.GetAutomaton(ca, x, y);
            WS1SFormula <BDD> not_xLTy = new WS1SNot <BDD>(x < y);

            not_xLTy = new WS1SAnd <BDD>(not_xLTy, fo); //*
            WS1SFormula <BDD> xEQy = new WS1SEq <BDD>(x, y);

            xEQy = new WS1SAnd <BDD>(xEQy, fo); //*
            var yGTx         = new WS1SLt <BDD>(y, x);
            var xEQy_or_yGTx = new WS1SAnd <BDD>(new WS1SOr <BDD>(xEQy, yGTx), fo);
            var aut_not_xLTy = not_xLTy.GetAutomaton(ca, x, y);
            var B            = xEQy_or_yGTx.GetAutomaton(ca, x, y);
            var c_aut_xLTy   = (x < y).GetAutomaton(ca, x, y).Complement(ca).Determinize(ca).Minimize(ca);
            //c_aut_xLTy = c_aut_xLTy.Intersect(aut_fo, ca).Determinize(ca).Minimize(ca); //*
            //aut_not_xLTy.ShowGraph("aut_not_xLTy");
            //B.ShowGraph("x_geq_y");
            //c_aut_xLTy.ShowGraph("c_aut_xLTy");
            var equiv1 = aut_not_xLTy.IsEquivalentWith(B, ca);

            //var equiv2 = aut_not_xLTy.IsEquivalentWith(c_aut_xLTy, ca);
            Assert.IsTrue(equiv1);
            //Assert.IsTrue(equiv2);
        }
Esempio n. 4
0
        public void TestWS1S_SuccDef_GetAutomaton()
        {
            var solver      = new CharSetSolver(BitWidth.BV7);
            var x           = new WS1SVariable <BDD>("x");
            var y           = new WS1SVariable <BDD>("y");
            var z           = new WS1SVariable <BDD>("z");
            var xLTy        = new WS1SLt <BDD>(x, y);
            var xLTzLTy     = (x < z) & (z < y);
            var Ez          = new WS1SExists <BDD>(z, xLTzLTy);
            var notEz       = new WS1SNot <BDD>(Ez);
            var xSyDef      = new WS1SAnd <BDD>(xLTy, notEz);
            var ca          = new CartesianAlgebraBDD <BDD>(solver);
            var aut_xSyDef  = xSyDef.GetAutomaton(ca, x, y);
            var aut_xLTzLTy = xLTzLTy.GetAutomaton(ca, x, y, z);
            var aut_Ez      = Ez.GetAutomaton(ca, x, y);
            var aut_notEz   = notEz.GetAutomaton(ca, x, y);
            var aut_xLTy    = xLTy.GetAutomaton(ca, x, y);

            //aut_xSyDef.ShowGraph("aut_xSyDEf");
            //aut_xLTzLTy.ShowGraph("aut_xLTzLTy");
            //aut_Ez.ShowGraph("aut_Ez");
            //aut_notEz.ShowGraph("aut_notEz");

            var xSyPrim     = new WS1SSuccN <BDD>(x, y, 1);
            var aut_xSyPrim = xSyPrim.GetAutomaton(ca, x, y);
            var equiv       = aut_xSyPrim.IsEquivalentWith(aut_xSyDef, ca);

            Assert.IsTrue(equiv);
        }
Esempio n. 5
0
        public void BooleanAlgebraZ3_test2()
        {
            var ctx         = new Context();
            var sort        = ctx.IntSort;
            var solver      = new Z3BoolAlg(ctx, sort);
            var alg         = new BDDAlgebra <BoolExpr>(solver);
            var x           = new WS1SVariable <BoolExpr>("x");
            var y           = new WS1SVariable <BoolExpr>("y");
            var z           = new WS1SVariable <BoolExpr>("z");
            var xLTy        = x < y;
            var xLTzLTy     = (x < z) & (z < y);
            var Ez          = new WS1SExists <BoolExpr>(z, xLTzLTy);
            var notEz       = new WS1SNot <BoolExpr>(Ez);
            var xSyDef      = new WS1SAnd <BoolExpr>(xLTy, notEz);
            var aut_xSyDef  = xSyDef.GetAutomaton(alg, x, y);
            var aut_xLTzLTy = xLTzLTy.GetAutomaton(alg, x, y, z);
            var aut_Ez      = Ez.GetAutomaton(alg, x, y);
            var aut_notEz   = notEz.GetAutomaton(alg, x, y);
            var aut_xLTy    = xLTy.GetAutomaton(alg, x, y);

            //aut_xSyDef.ShowGraph("aut_xSyDEf");
            //aut_xLTzLTy.ShowGraph("aut_xLTzLTy");
            //aut_Ez.ShowGraph("aut_Ez");
            //aut_notEz.ShowGraph("aut_notEz");

            var xSyPrim     = new WS1SSuccN <BoolExpr>(x, y, 1);
            var aut_xSyPrim = xSyPrim.GetAutomaton(alg, x, y);
            var equiv       = aut_xSyPrim.IsEquivalentWith(aut_xSyDef, alg);

            Assert.IsTrue(equiv);
        }
Esempio n. 6
0
 public void TestWS1S_Label()
 {
     var solver  = new CharSetSolver(BitWidth.BV7);
     var x       = new WS1SVariable <BDD>("x");
     var pred    = new WS1SPred <BDD>(solver.MkCharConstraint('c'), x);
     var ca      = new CartesianAlgebraBDD <BDD>(solver);
     var lab     = pred & !x;
     var lab_aut = lab.GetAutomaton(ca, x);
     //lab_aut.ShowGraph("lab_aut");
 }
Esempio n. 7
0
 public void TestWS1S_Member()
 {
     var solver            = new CharSetSolver(BitWidth.BV7);
     var ca                = new CartesianAlgebraBDD <BDD>(solver);
     var x                 = new WS1SVariable <BDD>("x");
     var y                 = new WS1SVariable <BDD>("y");
     var fo_x              = !x;
     WS1SFormula <BDD> xSy = new WS1SSubset <BDD>(x, y);
     var mem               = new WS1SAnd <BDD>(xSy, fo_x);
     var aut_mem           = mem.GetAutomaton(ca, x, y);
     //aut_mem.ShowGraph("aut_mem");
 }
Esempio n. 8
0
 public void BooleanAlgebraZ3_test1()
 {
     var ctx    = new Context();
     var sort   = ctx.IntSort;
     var solver = new Z3BoolAlg(ctx, sort);
     var alg    = new BDDAlgebra <BoolExpr>(solver);
     var x      = new WS1SVariable <BDD>("x");
     var pred   = new MSOPredicate <BoolExpr>(ctx.MkEq(solver.x, ctx.MkNumeral(42, sort)), "x");
     MSOFormula <BoolExpr> phi = new MSOExistsFo <BoolExpr>("x", pred);
     var pred_aut = pred.GetAutomaton(alg, "x");
     //pred_aut.ShowGraph("pred_aut");
 }
Esempio n. 9
0
        public void TestWS1S_Forall_x_Exists_y_x_lt_y()
        {
            var triv = new TrivialBooleanAlgebra();
            var ca   = new BDDAlgebra <bool>(triv);
            var x    = new WS1SVariable <bool>("x");
            var y    = new WS1SVariable <bool>("y");
            // Forall x.Exists y.x < y
            var psi4 = ~(x ^ !x & ~(y ^ (x < y)));
            var aut  = psi4.GetAutomaton(ca, x, y);

            //aut.ShowGraph("aut");
            //accepts only the empty word
            Assert.IsTrue(aut.StateCount == 1 && aut.IsFinalState(aut.InitialState) && aut.MoveCount == 0);
        }
Esempio n. 10
0
        public void TestWS1S_Equal()
        {
            var solver             = new CharSetSolver(BitWidth.BV7);
            var ca                 = new CartesianAlgebraBDD <BDD>(solver);
            var x                  = new WS1SVariable <BDD>("x");
            var y                  = new WS1SVariable <BDD>("y");
            var fo_x               = !x;
            var fo_y               = !y;
            WS1SFormula <BDD> fo   = !x & !y;
            WS1SFormula <BDD> xSy  = new WS1SSubset <BDD>(x, y);
            WS1SFormula <BDD> ySx  = new WS1SSubset <BDD>(y, x);
            WS1SFormula <BDD> yEQx = xSy & ySx;

            yEQx = yEQx & fo;
            var aut_yEQx = yEQx.GetAutomaton(ca, x, y);
            //aut_yEQx.ShowGraph("aut_yEQx");
        }
Esempio n. 11
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>(IBoolAlgMinterm <T> solver, T isDigit, T isWordLetter, IRegexConverter <T> regexConverter)
        {
            var ca = new CartesianAlgebraBDD <T>(solver);
            var x  = new WS1SVariable <T>("x");
            var y  = new WS1SVariable <T>("y");
            var z  = new WS1SVariable <T>("z");
            var X  = new WS1SVariable <T>("X");
            //there are at least two distinct positions x and y
            var xy = new WS1SAnd <T>(new WS1SAnd <T>(new WS1SNot <T>(new WS1SEq <T>(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 phi = new WS1SExists <T>(X, new WS1SAnd <T>(
                                             new WS1SAnd <T>(new WS1SSubset <T>(x, X), new WS1SSubset <T>(y, X)),
                                             new WS1SNot <T>(new WS1SExists <T>(z, new WS1SNot <T>(
                                                                                    new WS1SOr <T>(new WS1SNot <T>(new WS1SAnd <T>(!z, new WS1SSubset <T>(z, X))),
                                                                                                   new WS1SPred <T>(isWordLetter, z)))))));

            var psi2        = new WS1SAnd <T>(xy, phi);
            var atLeast2wEE = new WS1SExists <T>(x, new WS1SExists <T>(y, psi2));
            var psi1        = new WS1SAnd <T>(!x, new WS1SPred <T>(isDigit, x));
            var aut_psi1    = psi1.GetAutomaton(ca, x);
            //aut_psi1.ShowGraph("SFA(psi1)");
            var atLeast1d = new WS1SExists <T>(x, psi1);
            var psi       = new WS1SAnd <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"), solver);

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

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

            Assert.IsTrue(equiv);

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

            var aut_psi2 = psi2.GetAutomaton(ca, x, y);
            // 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");
        }
Esempio n. 12
0
 public void TestWS1S_NotLabel()
 {
     var solver = new CharSetSolver(BitWidth.BV7);
     //var x1 = new WS1SVariable<BDD>("x1", false);
     var x    = new WS1SVariable <BDD>("x");
     var pred = new WS1SPred <BDD>(solver.MkCharConstraint('c'), x);
     var fo_x = !x;
     var ca   = new CartesianAlgebraBDD <BDD>(solver);
     var lab  = new WS1SAnd <BDD>(pred, fo_x);
     WS1SFormula <BDD> not_lab = new WS1SNot <BDD>(lab);
     var not_lab_actual        = new WS1SAnd <BDD>(not_lab, fo_x);
     var aut_not_lab           = not_lab_actual.GetAutomaton(ca, x);
     var aut_not_lab_prelim    = not_lab.GetAutomaton(ca, x);
     var c_aut_lab             = lab.GetAutomaton(ca, x).Complement(ca).Minimize(ca);
     //c_aut_lab.ShowGraph("c_aut_lab");
     //aut_not_lab.ShowGraph("aut_not_lab");
     //aut_not_lab_prelim.ShowGraph("aut_not_lab_prelim");
     //TBD: equivalence
 }