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 WS1SLt <BDD>(x, y); var xLTzLTy = (new WS1SLt <BDD>(x, z)) & (new WS1SLt <BDD>(z, y)); var Ez = new WS1SExists <BDD>(z, xLTzLTy); var notEz = new WS1SNot <BDD>(Ez); var xSyDef = new WS1SAnd <BDD>(xLTy, notEz); var aut_xSyDef = xSyDef.GetAutomatonBDD(solver, nrOfLabelBits, x, y); var aut_xLTzLTy = xLTzLTy.GetAutomatonBDD(solver, nrOfLabelBits, x, y, z); var aut_Ez = Ez.GetAutomatonBDD(solver, nrOfLabelBits, x, y).Determinize(solver).Minimize(solver); var aut_notEz = notEz.GetAutomatonBDD(solver, nrOfLabelBits, x, y); var aut_xLTy = xLTy.GetAutomatonBDD(solver, nrOfLabelBits, x, y); //aut_xSyDef.ShowGraph("aut_xSyDEf"); //aut_xLTzLTy.ShowGraph("aut_xLTzLTy"); //aut_Ez.ShowGraph("aut_Ez"); //aut_notEz.ShowGraph("aut_notEz"); var xSyPrim = new WS1SSuccN <BDD>(x, y, 1); var aut_xSyPrim = xSyPrim.GetAutomatonBDD(solver, nrOfLabelBits, x, y); var equiv = aut_xSyPrim.IsEquivalentWith(aut_xSyDef, solver); Assert.IsTrue(equiv); }
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 WS1SLt <BDD>(x, y); var xLTzLTy = (new WS1SLt <BDD>(x, z)) & (new WS1SLt <BDD>(z, y)); var Ez = new WS1SExists <BDD>(z, xLTzLTy); var notEz = new WS1SNot <BDD>(Ez); var xSyDef = new WS1SAnd <BDD>(xLTy, notEz); var ca = new CartesianAlgebraBDD <BDD>(solver); var aut_xSyDef = xSyDef.GetAutomaton(ca, x, y); var aut_xLTzLTy = xLTzLTy.GetAutomaton(ca, x, y, z); var aut_Ez = Ez.GetAutomaton(ca, x, y); var aut_notEz = notEz.GetAutomaton(ca, x, y); var aut_xLTy = xLTy.GetAutomaton(ca, x, y); //aut_xSyDef.ShowGraph("aut_xSyDEf"); //aut_xLTzLTy.ShowGraph("aut_xLTzLTy"); //aut_Ez.ShowGraph("aut_Ez"); //aut_notEz.ShowGraph("aut_notEz"); var xSyPrim = new WS1SSuccN <BDD>(x, y, 1); var aut_xSyPrim = xSyPrim.GetAutomaton(ca, x, y); var equiv = aut_xSyPrim.IsEquivalentWith(aut_xSyDef, ca); Assert.IsTrue(equiv); }
public void TestWS1S_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); var fo = new WS1SSingleton <BDD>(x) & new WS1SSingleton <BDD>(y); var aut_fo = fo.GetAutomaton(ca, x, y); WS1SFormula <BDD> not_xLTy = new WS1SNot <BDD>(new WS1SLt <BDD>(x, y)); not_xLTy = new WS1SAnd <BDD>(not_xLTy, fo); //* WS1SFormula <BDD> xEQy = new WS1SEq <BDD>(x, y); xEQy = new WS1SAnd <BDD>(xEQy, fo); //* var yGTx = new WS1SLt <BDD>(y, x); var xEQy_or_yGTx = new WS1SAnd <BDD>(new WS1SOr <BDD>(xEQy, yGTx), fo); var aut_not_xLTy = not_xLTy.GetAutomaton(ca, x, y); var B = xEQy_or_yGTx.GetAutomaton(ca, x, y); var c_aut_xLTy = (new WS1SLt <BDD>(x, y)).GetAutomaton(ca, x, y).Complement(ca).Determinize(ca).Minimize(ca); //c_aut_xLTy = c_aut_xLTy.Intersect(aut_fo, ca).Determinize(ca).Minimize(ca); //* //aut_not_xLTy.ShowGraph("aut_not_xLTy"); //B.ShowGraph("x_geq_y"); //c_aut_xLTy.ShowGraph("c_aut_xLTy"); var equiv1 = aut_not_xLTy.IsEquivalentWith(B, ca); //var equiv2 = aut_not_xLTy.IsEquivalentWith(c_aut_xLTy, ca); Assert.IsTrue(equiv1); //Assert.IsTrue(equiv2); }
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 WS1SLt <BoolExpr>(x, y); var xLTzLTy = (new WS1SLt <BoolExpr>(x, z)) & (new WS1SLt <BoolExpr>(z, y)); var Ez = new WS1SExists <BoolExpr>(z, xLTzLTy); var notEz = new WS1SNot <BoolExpr>(Ez); var xSyDef = new WS1SAnd <BoolExpr>(xLTy, notEz); var aut_xSyDef = xSyDef.GetAutomaton(alg, x, y); var aut_xLTzLTy = xLTzLTy.GetAutomaton(alg, x, y, z); var aut_Ez = Ez.GetAutomaton(alg, x, y); var aut_notEz = notEz.GetAutomaton(alg, x, y); var aut_xLTy = xLTy.GetAutomaton(alg, x, y); //aut_xSyDef.ShowGraph("aut_xSyDEf"); //aut_xLTzLTy.ShowGraph("aut_xLTzLTy"); //aut_Ez.ShowGraph("aut_Ez"); //aut_notEz.ShowGraph("aut_notEz"); var xSyPrim = new WS1SSuccN <BoolExpr>(x, y, 1); var aut_xSyPrim = xSyPrim.GetAutomaton(alg, x, y); var equiv = aut_xSyPrim.IsEquivalentWith(aut_xSyDef, alg); Assert.IsTrue(equiv); }
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", false); var y = new Variable("y", false); var x_lt_y = new WS1SLt <bool>(x, y); var psi4 = ~(new WS1SExists <bool>(x, new WS1SSingleton <bool>(x) & ~(new WS1SExists <bool>(y, new WS1SSingleton <bool>(y) & (x_lt_y))))); var aut = psi4.GetAutomaton(ca, x, y); //aut.ShowGraph("aut"); //accepts only the empty word Assert.IsTrue(aut.StateCount == 1 && aut.IsFinalState(aut.InitialState) && aut.MoveCount == 0); }
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); } } }