public void TestMSO_Succ() { var solver = new CharSetSolver(BitWidth.BV32); MSOFormula <BDD> phi = new MSOForallFo <BDD>("x", new MSOIf <BDD>( new MSOPredicate <BDD>(solver.MkCharConstraint('c'), "x"), new MSOExistsFo <BDD>("y", new MSOAnd <BDD>( new MSOSucc <BDD>("x", "y"), 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, solver)); }
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 psi = new MSOIf <Expr>( new MSOPredicate <Expr>(isNeg, "x"), new MSOExistsFo <Expr>("y", new MSOAnd <Expr>( new MSOSucc <Expr>("x", "y"), new MSOPredicate <Expr>(isPos, "y") ) ) ); //all negative labels are immediately followed by a positive label MSOFormula <Expr> phi = new MSOForallFo <Expr>("x", psi); var ca = new CartesianAlgebraBDD <Expr>(solver); var aut_psi = psi.GetAutomaton(ca, "x").Determinize(ca).Minimize(ca); var aut_phi = phi.GetAutomaton(solver).Determinize(solver).Minimize(solver); Assert.IsFalse(aut_phi.IsEmpty); //aut_phi.ShowGraph("aut_phi"); //aut_psi.ShowGraph("aut_psi"); }
public void TestMSO_Forall() { var solver = new CharSetSolver(BitWidth.BV16); MSOFormula <BDD> phi = new MSOForallFo <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, solver)); }
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); }