public void TestMSO_FirstC() { var solver = new CharSetSolver(BitWidth.BV32); //var phi = new MSOTrue(); MSOFormula <BDD> phi = new MSOExistsFo <BDD>("x", new MSOAnd <BDD>(new MSOPredicate <BDD>(solver.MkCharConstraint('C'), "x"), new MSOFirst <BDD>("x"))); var aut = phi.GetAutomaton(solver); var aut2 = solver.RegexConverter.Convert("^C"); Assert.IsTrue(aut2.IsEquivalentWith(aut, solver)); }
public void TestIntExZ3() { var solver = new Z3Provider(); var sort = solver.CharacterSort; //var phi = new MSOTrue(); MSOFormula <Expr> phi = new MSOExistsFo <Expr>("x", new MSOPredicate <Expr>(solver.MkLe(solver.MkVar(0, solver.IntSort), solver.MkInt(0)), "x") ); var aut = phi.GetAutomaton(solver); }
public void TestMSO_Eq() { var solver = new CharSetSolver(BitWidth.BV16); //var phi = new MSOTrue(); MSOFormula <BDD> phi = new MSOExistsFo <BDD>("x", new MSOExistsFo <BDD>("y", new MSONot <BDD>(new MSOEq <BDD>("x", "y")))); var aut = phi.GetAutomaton(solver); var aut2 = solver.RegexConverter.Convert(".{2,}", System.Text.RegularExpressions.RegexOptions.Singleline); Assert.IsTrue(aut.IsEquivalentWith(aut2, solver)); }
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"); }
public void TestMSO_FirstLastZ3() { var solver = new CharSetSolver(BitWidth.BV16); MSOFormula <BDD> phi = new MSOExistsFo <BDD>("x", new MSOAnd <BDD>(new MSOFirst <BDD>("x"), new MSOLast <BDD>("x"))); var aut = phi.GetAutomaton(solver); var res = solver.Convert("^[\0-\uFFFF]$"); //solver.ShowGraph(res,"res"); //solver.SaveAsDgml(res, "res"); var eq = aut.IsEquivalentWith(res, solver); Assert.IsTrue(eq); }
static Automaton <T> CreateAutomaton1 <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 MSOFalse <T>(); for (int index = 0; index < bitWidth; index++) { var phi1 = pred(index, "var"); phi = new MSOOr <T>(phi, phi1); } phi = new MSOExistsFo <T>("var", phi); var aut = phi.GetAutomaton(Z); return(aut); }
public void TestCountNoProduct2() { int maxvars = 13; var solver = new CharSetSolver(BitWidth.BV7); Stopwatch sw = new Stopwatch(); var tries = 1; var times = new long[maxvars - 1]; for (int k = 0; k < tries; k++) { for (int vars = 8; vars <= maxvars; vars++) { MSOFormula <BDD> phi = new MSOTrue <BDD>(); for (int i = 1; i < vars; i++) { phi = new MSOAnd <BDD>(phi, new MSOLt <BDD>("x" + i, "x" + (i + 1))); phi = new MSOAnd <BDD>(phi, new MSOPredicate <BDD>(solver.MkCharConstraint('a'), "x" + i)); phi = new MSOOr <BDD>(phi, new MSOPredicate <BDD>(solver.MkCharConstraint('k'), "x" + i)); } phi = new MSOAnd <BDD>(phi, new MSOPredicate <BDD>(solver.MkCharConstraint('a'), "x" + vars)); phi = new MSOOr <BDD>(phi, new MSOExistsFo <BDD>("y", new MSOPredicate <BDD>(solver.MkCharConstraint('c'), "y"))); for (int i = vars; i >= 1; i--) { phi = new MSOExistsFo <BDD>("x" + i, phi); } sw.Restart(); //var aut1 = phi.GetAutomaton(new CartesianAlgebraBDD<BDD>(solver)); var aut1 = phi.GetAutomaton(solver); sw.Stop(); times[vars - 2] += sw.ElapsedMilliseconds; //Console.WriteLine("States {0} Trans {1}",aut1.StateCount,aut1.MoveCount); if (k == tries - 1) { TestContext.WriteLine(string.Format("{0} variables; {1} ms", vars, times[vars - 2] / tries)); } //solver.ShowGraph(aut1, "a"+vars); } } }
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); }
public void TestMSO_Pred() { var solver = new CharSetSolver(BitWidth.BV16); var pred = new MSOPredicate <BDD>(solver.MkCharConstraint('c'), "x"); MSOFormula <BDD> phi = new MSOExistsFo <BDD>("x", pred); var ca = new CartesianAlgebraBDD <BDD>(solver); var pred_aut = pred.GetAutomaton(ca, "x"); //pred_aut.ShowGraph("pred_aut"); 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, "c"), "regex mismatch"); } var aut2 = solver.RegexConverter.Convert("c", System.Text.RegularExpressions.RegexOptions.Singleline); //aut2.ShowGraph("aut2"); //aut.ShowGraph("aut"); Assert.IsTrue(aut2.IsEquivalentWith(aut, solver), "automata not equialent"); }