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 Variable("x", false); var y = new Variable("y", false); var z = new Variable("z", false); var X = new Variable("X", false); //there are at least two distinct positions x and y var xy = (new WS1SNot <BDD>(new WS1SEq <BDD>(x, y)) & new WS1SSingleton <BDD>(x) & new WS1SSingleton <BDD>(y)); //there is a set X containing x and y and all positions z in X have characters that satisfy isWordLetter var x_sub_X = new WS1SSubset <BDD>(x, X); var y_sub_X = new WS1SSubset <BDD>(y, X); var z_sub_X = new WS1SSubset <BDD>(z, X); var isletter_z = new WS1SPred <BDD>(isLetter, z); var psi = new WS1SExists <BDD>(X, (x_sub_X & y_sub_X & ~(new WS1SExists <BDD>(z, ~(~(new WS1SSingleton <BDD>(z) & z_sub_X) | isletter_z))))); var atLeast2w = xy & psi; var atLeast2wEE = new WS1SExists <BDD>(x, (new WS1SExists <BDD>(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)); }
public void TestWS1S_Label() { var solver = new CharSetSolver(BitWidth.BV7); var x = new Variable("X", false); var pred = new WS1SPred <BDD>(solver.MkCharConstraint('c'), x); var ca = new CartesianAlgebraBDD <BDD>(solver); var lab = pred & new WS1SSingleton <BDD>(x); var lab_aut = lab.GetAutomaton(ca, x); //lab_aut.ShowGraph("lab_aut"); }
public void TestWS1S_NotLabel() { var solver = new CharSetSolver(BitWidth.BV7); //var x1 = new Variable("x1", false); var x = new Variable("x", false); var pred = new WS1SPred <BDD>(solver.MkCharConstraint('c'), x); var fo_x = new WS1SSingleton <BDD>(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 }
public static void MintermTest() { var sw = new Stopwatch(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\msomintermp1s1.txt")) { for (int size = 2; size < kminterm; size++) { // Tsolve no force var s1 = new CharSetSolver(BitWidth.BV64); var solver = new CartesianAlgebraBDD <BDD>(s1); WS1SFormula <BDD> phi = new WS1STrue <BDD>(); for (int k = 1; k < size; k++) { var leq = new WS1SLt <BDD>(new Variable <BDD>("x" + (k - 1)), new Variable <BDD>("x" + k)); phi = new WS1SAnd <BDD>(phi, leq); } for (int k = 0; k < size; k++) { var axk = new WS1SPred <BDD>(s1.MkBitTrue(k), new Variable <BDD>("x" + k)); phi = new WS1SAnd <BDD>(phi, axk); } for (int k = size - 1; k >= 0; k--) { phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi); } sw.Restart(); for (int t = 0; t < numTests; t++) { phi.GetAutomaton(solver); } sw.Stop(); var t1 = sw.ElapsedMilliseconds; file.WriteLine((double)t1 / numTests); Console.WriteLine((double)t1 / numTests); } } using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\msomintermp2s1.txt")) { for (int size = 2; size < kminterm; size++) { // Tsolve force var s1 = new CharSetSolver(BitWidth.BV64); var solver = new CartesianAlgebraBDD <BDD>(s1); WS1SFormula <BDD> phi = new WS1STrue <BDD>(); for (int k = 0; k < size; k++) { var axk = new WS1SPred <BDD>(s1.MkBitTrue(k), new Variable <BDD>("x" + k)); phi = new WS1SAnd <BDD>(phi, axk); } for (int k = size - 1; k >= 0; k--) { phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi); } var t1 = 60000L; if (size <= maxmint) { sw.Restart(); for (int t = 0; t < numTests; t++) { phi.GetAutomaton(solver); } sw.Stop(); t1 = sw.ElapsedMilliseconds; } file.WriteLine((double)t1 / numTests); Console.WriteLine((double)t1 / numTests); } } using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\msomintermp1s2.txt")) { for (int size = 2; size < kminterm; size++) { // Tsolve solver 2 var solver = new CharSetSolver(BitWidth.BV64); var alg = new BDDAlgebra <BDD>(solver); WS1SFormula <BDD> phi = new WS1STrue <BDD>(); for (int k = 1; k < size; k++) { var leq = new WS1SLt <BDD>(new Variable <BDD>("x" + (k - 1)), new Variable <BDD>("x" + k)); phi = new WS1SAnd <BDD>(phi, leq); } for (int k = 0; k < size; k++) { var axk = new WS1SPred <BDD>(solver.MkBitTrue(k), new Variable <BDD>("x" + k)); phi = new WS1SAnd <BDD>(phi, axk); } for (int k = size - 1; k >= 0; k--) { phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi); } var t1 = 60000L; sw.Restart(); for (int t = 0; t < numTests; t++) { phi.GetAutomaton(alg); } sw.Stop(); t1 = sw.ElapsedMilliseconds; file.WriteLine((double)t1 / numTests); Console.WriteLine((double)t1 / numTests); } } using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\msomintermp2s2.txt")) { for (int size = 2; size < kminterm; size++) { var solver = new CharSetSolver(BitWidth.BV64); var alg = new BDDAlgebra <BDD>(solver); //Tforce sol 2 WS1SFormula <BDD> phi = new WS1STrue <BDD>(); for (int k = 0; k < size; k++) { var axk = new WS1SPred <BDD>(solver.MkBitTrue(k), new Variable <BDD>("x" + k)); phi = new WS1SAnd <BDD>(phi, axk); } for (int k = size - 1; k >= 0; k--) { phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi); } var t1 = 60000L; if (size <= maxmint) { sw.Restart(); for (int t = 0; t < numTests; t++) { phi.GetAutomaton(alg); } sw.Stop(); t1 = sw.ElapsedMilliseconds; } file.WriteLine((double)t1 / numTests); Console.WriteLine((double)t1 / numTests); } } using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\msominterm.txt")) { for (int size = 2; size < kminterm; size++) { //Tminterm var solver = new CharSetSolver(BitWidth.BV64); BDD[] predicates = new BDD[size]; solver.GenerateMinterms(); for (int k = 0; k < size; k++) { predicates[k] = solver.MkBitTrue(k); } var t1 = 60000L * numTests; if (size <= maxmint) { sw.Restart(); for (int t = 0; t < numTests; t++) { var mint = solver.GenerateMinterms(predicates).ToList(); } sw.Stop(); t1 = sw.ElapsedMilliseconds; } file.WriteLine((double)t1 / numTests); Console.WriteLine((double)t1 / numTests); } } }
//public static void POPLTestsInt() //{ // var sw = new Stopwatch(); // using (System.IO.StreamWriter file = // new System.IO.StreamWriter(@"..\mso-int.txt")) // { // for (int to = 2; to < kpopl; to++) // { // // T1 // var ctx = new Context(); // var sort = ctx.IntSort; // var solver = new BooleanAlgebraZ3(ctx, sort); // var alg = new BDDAlgebra<BoolExpr>(solver); // var pred = new MSOPredicate<BoolExpr>(ctx.MkEq(solver.x, ctx.MkNumeral(42, sort)), "x"); // WS1SFormula<BoolExpr> phi = new WS1STrue<BoolExpr>(); // for (int k = 1; k < to; k++) // { // var leq = new WS1SLt<BoolExpr>(new Variable<BDD>("x" + (k - 1)), new Variable<BDD>("x" + k)); // phi = new WS1SAnd<BoolExpr>(phi, leq); // } // for (int k = to - 1; k >= 0; k--) // { // phi = new WS1SExists<BoolExpr>(new Variable<BDD>("x" + k), phi); // } // sw.Restart(); // for (int t = 0; t < numTests; t++) // { // phi.GetAutomaton(solver); // } // sw.Stop(); // var t1 = sw.ElapsedMilliseconds; // //T2 // ctx = new Context(); // sort = ctx.IntSort; // solver = new BooleanAlgebraZ3(ctx, sort); // alg = new BDDAlgebra<BoolExpr>(solver); // pred = new MSOPredicate<BoolExpr>(ctx.MkEq(solver.x, ctx.MkNumeral(42, sort)), "x"); // phi = new WS1STrue<BoolExpr>(); // for (int k = 1; k < to; k++) // { // var leq = new WS1SLt<BoolExpr>(new Variable<BDD>("x" + (k - 1)), new Variable<BDD>("x" + k)); // phi = new WS1SAnd<BoolExpr>(phi, leq); // } // for (int k = 0; k < to; k++) // { // var axk = new WS1SPred<BoolExpr>( // ctx.MkLe((IntExpr)solver.x, (IntExpr)ctx.MkNumeral(42+k, sort)), // "x" + k); // phi = new WS1SAnd<BoolExpr>(phi, axk); // } // for (int k = to - 1; k >= 0; k--) // { // phi = new WS1SExists<BoolExpr>(new Variable<BDD>("x" + k), phi); // } // sw.Restart(); // for (int t = 0; t < numTests; t++) // { // phi.GetAutomaton(solver); // } // sw.Stop(); // var t2 = sw.ElapsedMilliseconds; // // T3 // ctx = new Context(); // sort = ctx.IntSort; // solver = new BooleanAlgebraZ3(ctx, sort); // alg = new BDDAlgebra<BoolExpr>(solver); // pred = new MSOPredicate<BoolExpr>(ctx.MkEq(solver.x, ctx.MkNumeral(42, sort)), "x"); // phi = new WS1STrue<BoolExpr>(); // for (int k = 1; k < to; k++) // { // var leq = new WS1SLt<BoolExpr>(new Variable<BDD>("x" + (k - 1)), new Variable<BDD>("x" + k)); // phi = new WS1SAnd<BoolExpr>(phi, leq); // } // for (int k = 0; k < to; k++) // { // var axk = new WS1SPred<BoolExpr>(ctx.MkLe((IntExpr)solver.x, (IntExpr)ctx.MkNumeral(42+k, sort)), new Variable<BDD>("x" + k)); // phi = new WS1SAnd<BoolExpr>(phi, axk); // } // for (int k = to - 1; k >= 0; k--) // { // phi = new WS1SExists<BoolExpr>(new Variable<BDD>("x" + k), phi); // } // var exycy = new WS1SExists<BoolExpr>(new Variable<BDD>("y"), new WS1SPred<BoolExpr>( // ctx.MkLe((IntExpr)solver.x, (IntExpr)ctx.MkNumeral(1000, sort)), new Variable<BDD>("y"))); // phi = new WS1SAnd<BoolExpr>(phi, exycy); // sw.Restart(); // for (int t = 0; t < numTests; t++) // { // phi.GetAutomaton(solver); // } // sw.Stop(); // var t3 = sw.ElapsedMilliseconds; // //T4 // ctx = new Context(); // sort = ctx.IntSort; // solver = new BooleanAlgebraZ3(ctx, sort); // alg = new BDDAlgebra<BoolExpr>(solver); // pred = new MSOPredicate<BoolExpr>(ctx.MkEq(solver.x, ctx.MkNumeral(42, sort)), "x"); // phi = new WS1STrue<BoolExpr>(); // for (int k = 1; k < to; k++) // { // var leq = new WS1SLt<BoolExpr>(new Variable<BDD>("x" + (k - 1)), new Variable<BDD>("x" + k)); // var axk = new WS1SPred<BoolExpr>(ctx.MkLe((IntExpr)solver.x, (IntExpr)ctx.MkNumeral(42+k, sort)), new Variable<BDD>("x" + (k - 1))); // var cxk = new WS1SPred<BoolExpr>(ctx.MkLe((IntExpr)solver.x, (IntExpr)ctx.MkNumeral(1000, sort)), new Variable<BDD>("x" + (k - 1))); // var inter = new WS1SOr<BoolExpr>(new WS1SAnd<BoolExpr>(leq, axk), cxk); // phi = new WS1SAnd<BoolExpr>(phi, inter); // } // for (int k = to - 1; k >= 0; k--) // { // phi = new WS1SExists<BoolExpr>(new Variable<BDD>("x" + k), phi); // } // exycy = new WS1SExists<BoolExpr>(new Variable<BDD>("y"), new WS1SPred<BoolExpr>( // ctx.MkLe((IntExpr)solver.x, (IntExpr)ctx.MkNumeral(1000, sort)), // "y")); // phi = new WS1SAnd<BoolExpr>(phi, exycy); // var t4 = 60000L * numTests; // if (to <= maxmphipop) // { // sw.Restart(); // for (int t = 0; t < numTests; t++) // { // phi.GetAutomaton(solver); // } // sw.Stop(); // t4 = sw.ElapsedMilliseconds; // } // file.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests + "," + (double)t4 / numTests); // Console.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests + "," + (double)t4 / numTests); // } // } //} public static void POPLTestsOld() { var sw = new Stopwatch(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\msobddold.txt")) { for (int to = 2; to < kpopl; to++) { // T1 var s1 = new CharSetSolver(BitWidth.BV64); WS1SFormula phi = new WS1STrue(); for (int k = 1; k < to; k++) { var leq = new WS1SLt("x" + (k - 1), "x" + k); phi = new WS1SAnd(phi, leq); } for (int k = to - 1; k >= 0; k--) { phi = new WS1SExists("x" + k, phi); } sw.Restart(); for (int t = 0; t < numTests; t++) { phi.getAutomaton(s1); } sw.Stop(); var t1 = sw.ElapsedMilliseconds; //T2 s1 = new CharSetSolver(BitWidth.BV64); phi = new WS1STrue(); for (int k = 1; k < to; k++) { var leq = new WS1SLt("x" + (k - 1), ("x" + k)); phi = new WS1SAnd(phi, leq); } for (int k = 0; k < to; k++) { var axk = new WS1SPred(s1.MkCharConstraint('a', false), "x" + k); phi = new WS1SAnd(phi, axk); } for (int k = to - 1; k >= 0; k--) { phi = new WS1SExists("x" + k, phi); } sw.Restart(); for (int t = 0; t < numTests; t++) { phi.getAutomaton(s1); } sw.Stop(); var t2 = sw.ElapsedMilliseconds; // T3 s1 = new CharSetSolver(BitWidth.BV64); phi = new WS1STrue(); for (int k = 1; k < to; k++) { var leq = new WS1SLt("x" + (k - 1), ("x" + k)); phi = new WS1SAnd(phi, leq); } for (int k = 0; k < to; k++) { var axk = new WS1SPred(s1.MkCharConstraint('a', false), ("x" + k)); phi = new WS1SAnd(phi, axk); } for (int k = to - 1; k >= 0; k--) { phi = new WS1SExists(("x" + k), phi); } var exycy = new WS1SExists(("y"), new WS1SPred(s1.MkCharConstraint('c', false), ("y"))); phi = new WS1SAnd(phi, exycy); sw.Restart(); for (int t = 0; t < numTests; t++) { phi.getAutomaton(s1); } sw.Stop(); var t3 = sw.ElapsedMilliseconds; //T4 s1 = new CharSetSolver(BitWidth.BV64); phi = new WS1STrue(); for (int k = 1; k < to; k++) { var leq = new WS1SLt(("x" + (k - 1)), ("x" + k)); var axk = new WS1SPred(s1.MkCharConstraint('a', false), ("x" + (k - 1))); var cxk = new WS1SPred(s1.MkCharConstraint('c', false), ("x" + (k - 1))); var inter = new WS1SOr(new WS1SAnd(leq, axk), cxk); phi = new WS1SAnd(phi, inter); } for (int k = to - 1; k >= 0; k--) { phi = new WS1SExists(("x" + k), phi); } exycy = new WS1SExists(("y"), new WS1SPred(s1.MkCharConstraint('c', false), ("y"))); phi = new WS1SAnd(phi, exycy); var t4 = 60000L * numTests; if (to <= maxmphipopold) { sw.Restart(); for (int t = 0; t < numTests; t++) { phi.getAutomaton(s1); } sw.Stop(); t4 = sw.ElapsedMilliseconds; } file.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests + "," + (double)t4 / numTests); Console.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests + "," + (double)t4 / numTests); } } }