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_Member() { var solver = new CharSetSolver(BitWidth.BV7); var ca = new CartesianAlgebraBDD <BDD>(solver); var x = new Variable("x", false); var y = new Variable("y", false); var fo_x = new WS1SSingleton <BDD>(x); WS1SFormula <BDD> xSy = new WS1SSubset <BDD>(x, y); var mem = new WS1SAnd <BDD>(xSy, fo_x); var aut_mem = mem.GetAutomaton(ca, x, y); //aut_mem.ShowGraph("aut_mem"); }
//Automaton<T> Restrict<T>(Automaton<IMonadicPredicate<BDD, T>> autom) //{ // List<Move<T>> moves = new List<Move<T>>(); // foreach (var move in autom.GetMoves()) // moves.Add(new Move<T>(move.SourceState, move.TargetState, move.Label.ProjectSecond())); // var res = Automaton<T>.Create(autom.InitialState, autom.GetFinalStates(), moves); // return res; //} public void TestWS1S_UseOfCharRangePreds <T>(IBoolAlgMinterm <T> solver, T isDigit, T isWordLetter, IRegexConverter <T> regexConverter) { var ca = new CartesianAlgebraBDD <T>(solver); 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 WS1SAnd <T>(new WS1SAnd <T>(new WS1SNot <T>(new WS1SEq <T>(x, y)), new WS1SSingleton <T>(x)), new WS1SSingleton <T>(y)); //there is a set X containing x and y and all positions z in X have characters that satisfy isWordLetter var phi = new WS1SExists <T>(X, new WS1SAnd <T>( new WS1SAnd <T>(new WS1SSubset <T>(x, X), new WS1SSubset <T>(y, X)), new WS1SNot <T>(new WS1SExists <T>(z, new WS1SNot <T>( new WS1SOr <T>(new WS1SNot <T>(new WS1SAnd <T>(new WS1SSingleton <T>(z), new WS1SSubset <T>(z, X))), new WS1SPred <T>(isWordLetter, z))))))); var psi2 = new WS1SAnd <T>(xy, phi); var atLeast2wEE = new WS1SExists <T>(x, new WS1SExists <T>(y, psi2)); var psi1 = new WS1SAnd <T>(new WS1SSingleton <T>(x), new WS1SPred <T>(isDigit, x)); var aut_psi1 = psi1.GetAutomaton(ca, x); //aut_psi1.ShowGraph("SFA(psi1)"); var atLeast1d = new WS1SExists <T>(x, psi1); var psi = new WS1SAnd <T>(atLeast2wEE, atLeast1d); var aut1 = psi.GetAutomaton(ca); //var aut_atLeast1d = atLeast1d.GetAutomaton(solver); var aut2 = regexConverter.Convert(@"\w.*\w", System.Text.RegularExpressions.RegexOptions.Singleline).Intersect(regexConverter.Convert(@"\d"), solver); //aut1.ShowGraph("aut1"); //aut2.ShowGraph("aut2"); bool equiv = aut2.IsEquivalentWith(BasicAutomata.Restrict(aut1), solver); Assert.IsTrue(equiv); //solver.ShowGraph(aut_atLeast1d, "aut_atLeast1d"); var aut_psi2 = psi2.GetAutomaton(ca, x, y); // var aut_atLeast2wEE = atLeast2wEE.GetAutomaton(ca, "x", "y"); // var aut_atLeast2wEE2 = atLeast2wEE.GetAutomaton(solver); //aut_psi2.ShowGraph("SFA(psi2)"); //aut_atLeast2wEE.ShowGraph("aut_atLeast2wEE"); //aut_atLeast2wEE2.ShowGraph("aut_atLeast2wEE2"); //solver.ShowGraph(aut_atLeast2wEE2, "aut_atLeast2wEE2"); }
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 POPLTestsNew() { var sw = new Stopwatch(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\msobdd.txt")) { for (int to = 2; to < kpopl; to++) { // T1 var s1 = new CharSetSolver(BitWidth.BV64); var solver = new CartesianAlgebraBDD <BDD>(s1); WS1SFormula <BDD> phi = new WS1STrue <BDD>(); for (int k = 1; k < to; 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 = to - 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; //T2 s1 = new CharSetSolver(BitWidth.BV64); solver = new CartesianAlgebraBDD <BDD>(s1); phi = new WS1STrue <BDD>(); for (int k = 1; k < to; 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 < to; k++) { var axk = new WS1SPred <BDD>( s1.MkCharConstraint('a', false), new Variable <BDD>("x" + k)); phi = new WS1SAnd <BDD>(phi, axk); } for (int k = to - 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 t2 = sw.ElapsedMilliseconds; // T3 s1 = new CharSetSolver(BitWidth.BV64); solver = new CartesianAlgebraBDD <BDD>(s1); phi = new WS1STrue <BDD>(); for (int k = 1; k < to; 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 < to; k++) { var axk = new WS1SPred <BDD>(s1.MkCharConstraint('a', false), new Variable <BDD>("x" + k)); phi = new WS1SAnd <BDD>(phi, axk); } for (int k = to - 1; k >= 0; k--) { phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi); } var exycy = new WS1SExists <BDD>(new Variable <BDD>("y"), new WS1SPred <BDD>(s1.MkCharConstraint('c', false), new Variable <BDD>("y"))); phi = new WS1SAnd <BDD>(phi, exycy); sw.Restart(); for (int t = 0; t < numTests; t++) { phi.GetAutomaton(solver); } sw.Stop(); var t3 = sw.ElapsedMilliseconds; //T4 s1 = new CharSetSolver(BitWidth.BV64); solver = new CartesianAlgebraBDD <BDD>(s1); phi = new WS1STrue <BDD>(); for (int k = 1; k < to; k++) { var leq = new WS1SLt <BDD>(new Variable <BDD>("x" + (k - 1)), new Variable <BDD>("x" + k)); var axk = new WS1SPred <BDD>(s1.MkCharConstraint('a', false), new Variable <BDD>("x" + (k - 1))); var cxk = new WS1SPred <BDD>(s1.MkCharConstraint('c', false), new Variable <BDD>("x" + (k - 1))); var inter = new WS1SOr <BDD>(new WS1SAnd <BDD>(leq, axk), cxk); phi = new WS1SAnd <BDD>(phi, inter); } for (int k = to - 1; k >= 0; k--) { phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi); } exycy = new WS1SExists <BDD>(new Variable <BDD>("y"), new WS1SPred <BDD>(s1.MkCharConstraint('c', false), new Variable <BDD>("y"))); phi = new WS1SAnd <BDD>(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); } } }