Ejemplo n.º 1
0
        public void TestIntZ3()
        {
            var solver = new Z3Provider();
            var isNeg  = solver.MkLt(solver.MkVar(0, solver.IntSort), solver.MkInt(0));
            var isPos  = solver.MkLt(solver.MkInt(0), solver.MkVar(0, solver.IntSort));

            var sort = solver.CharacterSort;
            //if x has a negative label then x has successor y with a nonnegative label
            var x   = new Variable("x", true);
            var y   = new Variable("y", true);
            var psi = new MSOImplies <Expr>(
                new MSOPredicate <Expr>(isNeg, x),
                new MSOExists <Expr>(y,
                                     new MSOAnd <Expr>(
                                         new MSOSuccN <Expr>(x, y, 1),
                                         new MSOPredicate <Expr>(isPos, y)
                                         )
                                     )
                );
            //all negative labels are immediately followed by a positive label
            MSOFormula <Expr> phi = new MSOForall <Expr>(x, psi);
            var ca      = new CartesianAlgebraBDD <Expr>(solver);
            var aut_psi = psi.GetAutomaton(ca).Determinize().Minimize();
            var aut_phi = phi.GetAutomaton(solver).Determinize().Minimize();

            Assert.IsFalse(aut_phi.IsEmpty);
            //aut_phi.ShowGraph("aut_phi");
            //aut_psi.ShowGraph("aut_psi");
        }
Ejemplo n.º 2
0
        public void TestMSO_Succ()
        {
            var solver           = new CharSetSolver(BitWidth.BV32);
            var x                = new Variable("x", true);
            var y                = new Variable("y", true);
            MSOFormula <BDD> phi = new MSOForall <BDD>(x,
                                                       new MSOImplies <BDD>(
                                                           new MSOPredicate <BDD>(solver.MkCharConstraint('c'), x),
                                                           new MSOExists <BDD>(y,
                                                                               new MSOAnd <BDD>(
                                                                                   new MSOSuccN <BDD>(x, y, 1),
                                                                                   new MSOPredicate <BDD>(solver.MkCharConstraint('a'), y)
                                                                                   )
                                                                               )
                                                           )
                                                       );

            var aut = phi.GetAutomaton(solver);

            for (int i = 0; i < 10; i++)
            {
                var s = solver.GenerateMember(aut);
                Assert.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(s, "^(ca|[^c])*$"));
            }
            var aut2 = solver.RegexConverter.Convert("^(ca|[^c])*$");

            Assert.IsTrue(aut2.IsEquivalentWith(aut));
        }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
        public void TestMSO_Forall()
        {
            var solver = new CharSetSolver(BitWidth.BV16);
            var x = new Variable("x", true);
            MSOFormula<BDD> phi = new MSOForall<BDD>(x, new MSOPredicate<BDD>(solver.MkCharConstraint('c',true), x));

            var aut = phi.GetAutomaton(solver);
            //aut.ShowGraph("aut");
            for (int i = 0; i < 10; i++)
            {
                TestContext.WriteLine(solver.GenerateMember(aut));
            }
            var aut2 = solver.RegexConverter.Convert("^(c|C)*$");
            //aut2.ShowGraph("aut2");
            Assert.IsTrue(aut2.IsEquivalentWith(aut));
        }
Ejemplo n.º 5
0
        public void TestMSO_Or()
        {
            var solver = new CharSetSolver(BitWidth.BV32);
            MSOFormula<BDD> phi = new MSOForall<BDD>(V1("x"),
                    new MSOOr<BDD>(
                        new MSOPredicate<BDD>(solver.MkCharConstraint( 'c'), V1("x")),
                        new MSOPredicate<BDD>(solver.MkCharConstraint( 'a'), V1("x"))
                    )
                );

            var aut = phi.GetAutomaton(solver);
            for (int i = 0; i < 10; i++)
            {
                var s = solver.GenerateMember(aut);
                Assert.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(s, "^[ac]*$"));
            }
            var aut2 = solver.RegexConverter.Convert("^[ac]*$");
            Assert.IsTrue(aut2.IsEquivalentWith(aut));
        }