Exemplo n.º 1
0
        public void TestWS1S_SuccDef_GetAutomatonBDD()
        {
            var solver        = new CharSetSolver(BitWidth.BV7);
            var nrOfLabelBits = (int)BitWidth.BV7;
            var x             = new Variable("x", true);
            var y             = new Variable("y", true);
            var z             = new Variable("z", true);
            var xLTy          = new MSOLt <BDD>(x, y);
            var xLTzLTy       = new MSOAnd <BDD>(new MSOLt <BDD>(x, z), new MSOLt <BDD>(z, y));
            var Ez            = new MSOExists <BDD>(z, xLTzLTy);
            var notEz         = new MSONot <BDD>(Ez);
            var xSyDef        = new MSOAnd <BDD>(xLTy, notEz);

            var aut_xSyDef  = xSyDef.GetAutomaton(solver);
            var aut_xLTzLTy = xLTzLTy.GetAutomaton(solver);
            var aut_Ez      = Ez.GetAutomaton(solver).Determinize().Minimize();
            var aut_notEz   = notEz.GetAutomaton(solver);
            var aut_xLTy    = xLTy.GetAutomaton(solver);

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

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

            Assert.IsTrue(equiv);
        }
Exemplo n.º 2
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 Variable("x", true);
            var y           = new Variable("y", true);
            var z           = new Variable("z", true);
            var xLTy        = new MSOLt <BoolExpr>(x, y);
            var xLTzLTy     = new MSOAnd <BoolExpr>((new MSOLt <BoolExpr>(x, z)), (new MSOLt <BoolExpr>(z, y)));
            var Ez          = new MSOExists <BoolExpr>(z, xLTzLTy);
            var notEz       = new MSONot <BoolExpr>(Ez);
            var xSyDef      = new MSOAnd <BoolExpr>(xLTy, notEz);
            var aut_xSyDef  = xSyDef.GetAutomaton(alg);
            var aut_xLTzLTy = xLTzLTy.GetAutomaton(alg);
            var aut_Ez      = Ez.GetAutomaton(alg);
            var aut_notEz   = notEz.GetAutomaton(alg);
            var aut_xLTy    = xLTy.GetAutomaton(alg);

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

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

            Assert.IsTrue(equiv);
        }
Exemplo n.º 3
0
        public void TestWS1S_SuccDef_GetAutomaton()
        {
            var solver      = new CharSetSolver(BitWidth.BV7);
            var x           = new Variable("x", true);
            var y           = new Variable("y", true);
            var z           = new Variable("z", true);
            var xLTy        = new MSOLt <BDD>(x, y);
            var xLTzLTy     = new MSOAnd <BDD>(new MSOLt <BDD>(x, z), new MSOLt <BDD>(z, y));
            var Ez          = new MSOExists <BDD>(z, xLTzLTy);
            var notEz       = new MSONot <BDD>(Ez);
            var xSyDef      = new MSOAnd <BDD>(xLTy, notEz);
            var ca          = new CartesianAlgebraBDD <BDD>(solver);
            var aut_xSyDef  = xSyDef.GetAutomaton(ca);
            var aut_xLTzLTy = xLTzLTy.GetAutomaton(ca);
            var aut_Ez      = Ez.GetAutomaton(ca);
            var aut_notEz   = notEz.GetAutomaton(ca);
            var aut_xLTy    = xLTy.GetAutomaton(ca);

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

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

            Assert.IsTrue(equiv);
        }
Exemplo n.º 4
0
        Automaton<T> CreateAutomaton3<T>(Func<int, T> f, int bitWidth, IBooleanAlgebra<T> Z)
        {

            Func<int, Variable, MSOPredicate<T>> pred = (i, s) => new MSOPredicate<T>(f(i), s);

            MSOFormula<T> phi = new MSOTrue<T>();

            // x1<x2<x3<x4...
            for (int index = 1; index < bitWidth; index++)
            {
                MSOFormula<T> phi1 = new MSOLt<T>(V1("x" + (index - 1)), V1("x" + index));
                phi = new MSOAnd<T>(phi, phi1);
            }

            // bi(xi)
            for (int index = 0; index < bitWidth; index++)
            {
                MSOFormula<T> phi1 = pred(index, V1("x" + index));
                phi = new MSOAnd<T>(phi, phi1);
            }

            // exists forall...
            for (int index = 0; index < bitWidth; index++)
            {
                if (index % 2 == 0)
                    phi = new MSOExists<T>(V1("x" + index), phi);
                else
                    phi = new MSOForall<T>(V1("x" + index), phi);
            }
            var aut = phi.GetAutomaton(Z);
            return aut;
        }
Exemplo n.º 5
0
 public void TestWS1S_Forall_x_Exists_y_x_lt_y() 
 {
     var triv = new TrivialBooleanAlgebra();
     var ca = new BDDAlgebra<bool>(triv); 
     var x = new Variable("x", true);
     var y = new Variable("y", true);
     var x_lt_y = new MSOLt<bool>(x, y);
     var aut_x_lt_y = x_lt_y.GetAutomaton(ca);
     //aut_x_lt_y.ShowGraph("aut_x_lt_y");
     var psi4 = new MSOForall<bool>(x, new MSOExists<bool>(y, (x_lt_y)));
     var aut = psi4.GetAutomaton(ca);
     //accepts only the empty word
     Assert.IsTrue(aut.StateCount == 1 && aut.IsFinalState(aut.InitialState) && aut.MoveCount == 0);
 }
Exemplo n.º 6
0
 public void TestMSO_NotLt()
 {
     var solver = new CharSetSolver(BitWidth.BV7);
     var ca = new CartesianAlgebraBDD<BDD>(solver);
     var x = new Variable("x", true);
     var y = new Variable("y", true);
     MSOFormula<BDD> not_xLTy = new MSONot<BDD>(new MSOLt<BDD>(x,y));
     MSOFormula<BDD> xEQy = new MSOEq<BDD>(x, y);
     var xGTy = new MSOLt<BDD>(y, x);
     var xGEy = new MSOOr<BDD>(xEQy, xGTy);
     var aut_not_xLTy = not_xLTy.GetAutomaton(ca);
     var aut_xGEy = xGEy.GetAutomaton(ca);
     var c_aut_xLTy = (new MSOLt<BDD>(x,y)).GetAutomaton(ca).Complement().Determinize().Minimize();
     //c_aut_xLTy = c_aut_xLTy.Intersect(aut_fo, ca).Determinize(ca).Minimize(ca); //*
     //aut_not_xLTy.ShowGraph("aut_not_xLTy");
     //aut_xGEy.ShowGraph("aut_xGEy");
     //c_aut_xLTy.ShowGraph("c_aut_xLTy");
     var equiv1 = aut_not_xLTy.IsEquivalentWith(aut_xGEy);
     //var equiv2 = aut_not_xLTy.IsEquivalentWith(c_aut_xLTy, ca);
     Assert.IsTrue(equiv1);
     //Assert.IsTrue(equiv2);
 }
Exemplo n.º 7
0
        Automaton <T> CreateAutomaton3 <T>(Func <int, T> f, int bitWidth, IBooleanAlgebra <T> Z)
        {
            Func <int, string, MSOPredicate <T> > pred = (i, s) => new MSOPredicate <T>(f(i), s);

            MSOFormula <T> phi = new MSOTrue <T>();

            // x1<x2<x3<x4...
            for (int index = 1; index < bitWidth; index++)
            {
                MSOFormula <T> phi1 = new MSOLt <T>("x" + (index - 1), "x" + index);
                phi = new MSOAnd <T>(phi, phi1);
            }

            // bi(xi)
            for (int index = 0; index < bitWidth; index++)
            {
                MSOFormula <T> phi1 = pred(index, "x" + index);
                phi = new MSOAnd <T>(phi, phi1);
            }

            // exists forall...
            for (int index = 0; index < bitWidth; index++)
            {
                if (index % 2 == 0)
                {
                    phi = new MSOExistsFo <T>("x" + index, phi);
                }
                else
                {
                    phi = new MSOForallFo <T>("x" + index, phi);
                }
            }

            Assert.IsTrue(phi.IsWellFormedFormula());
            var aut = phi.GetAutomaton(Z);

            return(aut);
        }
Exemplo n.º 8
0
        static Automaton <T> CreateAutomaton3 <T>(Func <int, T> f, int bitWidth, IBooleanAlgebra <T> Z)
        {
            Func <int, string, MSOPredicate <T> > pred = (i, s) => new MSOPredicate <T>(f(i), new Variable(s, true));

            MSOFormula <T> phi = new MSOTrue <T>();

            // x1<x2<x3<x4...
            for (int index = 1; index < bitWidth; index++)
            {
                MSOFormula <T> phi1 = new MSOLt <T>(new Variable("x" + (index - 1), true), new Variable("x" + index, true));
                phi = new MSOAnd <T>(phi, phi1);
            }

            // bi(xi)
            for (int index = 0; index < bitWidth; index++)
            {
                MSOFormula <T> phi1 = pred(index, "x" + index);
                phi = new MSOAnd <T>(phi, phi1);
            }

            // exists forall...
            for (int index = 0; index < bitWidth; index++)
            {
                if (index % 2 == 0)
                {
                    phi = new MSOExists <T>(new Variable("x" + index, true), phi);
                }
                else
                {
                    phi = new MSOForall <T>(new Variable("x" + index, true), phi);
                }
            }

            var aut = phi.GetAutomaton(Z);

            return(aut);
        }
Exemplo n.º 9
0
        public static void RunPOPLTests()
        {
            //// all x1...xn. xi<xi+1
            List <Pair <MSOFormula <BDD>, CharSetSolver> > phis = new List <Pair <MSOFormula <BDD>, CharSetSolver> >();

            for (int to = 2; to < kpopl; to++)
            {
                var solver           = new CharSetSolver();
                MSOFormula <BDD> phi = new MSOTrue <BDD>();

                for (int k = 1; k < to; k++)
                {
                    var leq = new MSOLt <BDD>(new Variable("x" + (k - 1), true), new Variable("x" + k, true));
                    phi = new MSOAnd <BDD>(phi, leq);
                }
                for (int k = to - 1; k >= 0; k--)
                {
                    phi = new MSOExists <BDD>(new Variable("x" + k, true), phi);
                }

                phis.Add(new Pair <MSOFormula <BDD>, CharSetSolver>(phi, solver));
            }

            RunTest(new StreamWriter(@"..\popl14-1.csv"), phis);


            // all x1...xn. xi<xi+1 and a(xi)
            phis = new List <Pair <MSOFormula <BDD>, CharSetSolver> >();
            for (int to = 2; to < kpopl; to++)
            {
                var solver           = new CharSetSolver(BitWidth.BV64);
                MSOFormula <BDD> phi = new MSOTrue <BDD>();

                for (int k = 1; k < to; k++)
                {
                    var leq = new MSOLt <BDD>(new Variable("x" + (k - 1), true), new Variable("x" + k, true));
                    phi = new MSOAnd <BDD>(phi, leq);
                }
                for (int k = 0; k < to; k++)
                {
                    var axk = new MSOPredicate <BDD>(
                        solver.MkCharConstraint('a', false), new Variable("x" + k, true));
                    phi = new MSOAnd <BDD>(phi, axk);
                }
                for (int k = to - 1; k >= 0; k--)
                {
                    phi = new MSOExists <BDD>(new Variable("x" + k, true), phi);
                }
                phis.Add(new Pair <MSOFormula <BDD>, CharSetSolver>(phi, solver));
            }
            RunTest(new StreamWriter(@"..\popl14-2.csv"), phis);

            // all x1...xn. (xi<xi+1 and a(xi)) and ex y. c(y)
            phis = new List <Pair <MSOFormula <BDD>, CharSetSolver> >();
            for (int to = 2; to < kpopl; to++)
            {
                var solver           = new CharSetSolver(BitWidth.BV64);
                MSOFormula <BDD> phi = new MSOTrue <BDD>();

                for (int k = 1; k < to; k++)
                {
                    var leq = new MSOLt <BDD>(new Variable("x" + (k - 1), true), new Variable("x" + k, true));
                    phi = new MSOAnd <BDD>(phi, leq);
                }
                for (int k = 0; k < to; k++)
                {
                    var axk = new MSOPredicate <BDD>(solver.MkCharConstraint('a', false), new Variable("x" + k, true));
                    phi = new MSOAnd <BDD>(phi, axk);
                }
                for (int k = to - 1; k >= 0; k--)
                {
                    phi = new MSOExists <BDD>(new Variable("x" + k, true), phi);
                }

                var exycy = new MSOExists <BDD>(new Variable("y", true), new MSOPredicate <BDD>(solver.MkCharConstraint('c', false), new Variable("y", true)));
                phi = new MSOAnd <BDD>(phi, exycy);

                phis.Add(new Pair <MSOFormula <BDD>, CharSetSolver>(phi, solver));
            }

            RunTest(new StreamWriter(@"..\popl14-3.csv"), phis);

            // all x1...xn. (xi<xi+1 and a(xi) \/ c(xi))

            phis = new List <Pair <MSOFormula <BDD>, CharSetSolver> >();
            for (int to = 2; to < kpopl; to++)
            {
                var solver           = new CharSetSolver(BitWidth.BV64);
                MSOFormula <BDD> phi = new MSOTrue <BDD>();

                for (int k = 1; k < to; k++)
                {
                    var leq   = new MSOLt <BDD>(new Variable("x" + (k - 1), true), new Variable("x" + k, true));
                    var axk   = new MSOPredicate <BDD>(solver.MkCharConstraint('a', false), new Variable("x" + (k - 1), true));
                    var cxk   = new MSOPredicate <BDD>(solver.MkCharConstraint('c', false), new Variable("x" + (k - 1), true));
                    var inter = new MSOOr <BDD>(new MSOAnd <BDD>(leq, axk), cxk);
                    phi = new MSOAnd <BDD>(phi, inter);
                }
                for (int k = to - 1; k >= 0; k--)
                {
                    phi = new MSOExists <BDD>(new Variable("x" + k, true), phi);
                }

                MSOFormula <BDD> exycy = new MSOExists <BDD>(new Variable("y", true), new MSOPredicate <BDD>(solver.MkCharConstraint('c', false), new Variable("y", true)));
                phi = new MSOAnd <BDD>(phi, exycy);

                phis.Add(new Pair <MSOFormula <BDD>, CharSetSolver>(phi, solver));
            }

            RunTest(new StreamWriter(@"..\popl14-4.csv"), phis, 10, 10, 11);
        }
Exemplo n.º 10
0
        public static void RunPOPLTests()
        {
            //// all x1...xn. xi<xi+1
            List<Pair<MSOFormula<BDD>, CharSetSolver>> phis = new List<Pair<MSOFormula<BDD>, CharSetSolver>>();

            for (int to = 2; to < kpopl; to++)
            {
                var solver = new CharSetSolver();
                MSOFormula<BDD> phi = new MSOTrue<BDD>();

                for (int k = 1; k < to; k++)
                {
                    var leq = new MSOLt<BDD>(new Variable("x" + (k - 1), true), new Variable("x" + k, true));
                    phi = new MSOAnd<BDD>(phi, leq);

                }
                for (int k = to - 1; k >= 0; k--)
                {
                    phi = new MSOExists<BDD>(new Variable("x" + k, true), phi);
                }

                phis.Add(new Pair<MSOFormula<BDD>, CharSetSolver>(phi, solver));
            }

            RunTest(new StreamWriter(@"popl14-1.csv"), phis);

            // all x1...xn. xi<xi+1 and a(xi)
            phis = new List<Pair<MSOFormula<BDD>, CharSetSolver>>();
            for (int to = 2; to < kpopl; to++)
            {
                var solver = new CharSetSolver(BitWidth.BV64);
                MSOFormula<BDD> phi = new MSOTrue<BDD>();

                for (int k = 1; k < to; k++)
                {
                    var leq = new MSOLt<BDD>(new Variable("x" + (k - 1), true), new Variable("x" + k, true));
                    phi = new MSOAnd<BDD>(phi, leq);

                }
                for (int k = 0; k < to; k++)
                {
                    var axk = new MSOPredicate<BDD>(
                        solver.MkCharConstraint('a', false), new Variable("x" + k, true));
                    phi = new MSOAnd<BDD>(phi, axk);

                }
                for (int k = to - 1; k >= 0; k--)
                {
                    phi = new MSOExists<BDD>(new Variable("x" + k, true), phi);
                }
                phis.Add(new Pair<MSOFormula<BDD>, CharSetSolver>(phi, solver));
            }
            RunTest(new StreamWriter(@"popl14-2.csv"), phis);

            // all x1...xn. (xi<xi+1 and a(xi)) and ex y. c(y)
            phis = new List<Pair<MSOFormula<BDD>, CharSetSolver>>();
            for (int to = 2; to < kpopl; to++)
            {
                var solver = new CharSetSolver(BitWidth.BV64);
                MSOFormula<BDD> phi = new MSOTrue<BDD>();

                for (int k = 1; k < to; k++)
                {
                    var leq = new MSOLt<BDD>(new Variable("x" + (k - 1), true), new Variable("x" + k, true));
                    phi = new MSOAnd<BDD>(phi, leq);

                }
                for (int k = 0; k < to; k++)
                {
                    var axk = new MSOPredicate<BDD>(solver.MkCharConstraint('a', false), new Variable("x" + k, true));
                    phi = new MSOAnd<BDD>(phi, axk);

                }
                for (int k = to - 1; k >= 0; k--)
                {
                    phi = new MSOExists<BDD>(new Variable("x" + k, true), phi);
                }

                var exycy = new MSOExists<BDD>(new Variable("y", true), new MSOPredicate<BDD>(solver.MkCharConstraint('c', false), new Variable("y", true)));
                phi = new MSOAnd<BDD>(phi, exycy);

                phis.Add(new Pair<MSOFormula<BDD>, CharSetSolver>(phi, solver));
            }

            RunTest(new StreamWriter(@"popl14-3.csv"), phis);

            // all x1...xn. (xi<xi+1 and a(xi) \/ c(xi))

            phis = new List<Pair<MSOFormula<BDD>, CharSetSolver>>();
            for (int to = 2; to < kpopl; to++)
            {
                var solver = new CharSetSolver(BitWidth.BV64);
                MSOFormula<BDD> phi = new MSOTrue<BDD>();

                for (int k = 1; k < to; k++)
                {
                    var leq = new MSOLt<BDD>(new Variable("x" + (k - 1), true), new Variable("x" + k, true));
                    var axk = new MSOPredicate<BDD>(solver.MkCharConstraint('a', false), new Variable("x" + (k - 1), true));
                    var cxk = new MSOPredicate<BDD>(solver.MkCharConstraint('c', false), new Variable("x" + (k - 1), true));
                    var inter = new MSOOr<BDD>(new MSOAnd<BDD>(leq, axk), cxk);
                    phi = new MSOAnd<BDD>(phi, inter);

                }
                for (int k = to - 1; k >= 0; k--)
                {
                    phi = new MSOExists<BDD>(new Variable("x" + k, true), phi);
                }

                MSOFormula<BDD> exycy = new MSOExists<BDD>(new Variable("y", true), new MSOPredicate<BDD>(solver.MkCharConstraint('c', false), new Variable("y", true)));
                phi = new MSOAnd<BDD>(phi, exycy);

                phis.Add(new Pair<MSOFormula<BDD>, CharSetSolver>(phi, solver));
            }

            RunTest(new StreamWriter(@"popl14-4.csv"), phis, 11, 11, 11);
        }