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 MSOLt <BDD>(x, y); var xLTzLTy = new MSOAnd <BDD>(new MSOLt <BDD>(x, z), new MSOLt <BDD>(z, y)); var Ez = new MSOExists <BDD>(z, xLTzLTy); var notEz = new MSONot <BDD>(Ez); var xSyDef = new MSOAnd <BDD>(xLTy, notEz); var aut_xSyDef = xSyDef.GetAutomaton(solver); var aut_xLTzLTy = xLTzLTy.GetAutomaton(solver); var aut_Ez = Ez.GetAutomaton(solver).Determinize().Minimize(); var aut_notEz = notEz.GetAutomaton(solver); var aut_xLTy = xLTy.GetAutomaton(solver); //aut_xSyDef.ShowGraph("aut_xSyDEf"); //aut_xLTzLTy.ShowGraph("aut_xLTzLTy"); //aut_Ez.ShowGraph("aut_Ez"); //aut_notEz.ShowGraph("aut_notEz"); var xSyPrim = new MSOSuccN <BDD>(x, y, 1); var aut_xSyPrim = xSyPrim.GetAutomaton(solver); var equiv = aut_xSyPrim.IsEquivalentWith(aut_xSyDef); 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 MSOLt <BDD>(x, y); var xLTzLTy = new MSOAnd <BDD>(new MSOLt <BDD>(x, z), new MSOLt <BDD>(z, y)); var Ez = new MSOExists <BDD>(z, xLTzLTy); var notEz = new MSONot <BDD>(Ez); var xSyDef = new MSOAnd <BDD>(xLTy, notEz); var ca = new CartesianAlgebraBDD <BDD>(solver); var aut_xSyDef = xSyDef.GetAutomaton(ca); var aut_xLTzLTy = xLTzLTy.GetAutomaton(ca); var aut_Ez = Ez.GetAutomaton(ca); var aut_notEz = notEz.GetAutomaton(ca); var aut_xLTy = xLTy.GetAutomaton(ca); //aut_xSyDef.ShowGraph("aut_xSyDEf"); //aut_xLTzLTy.ShowGraph("aut_xLTzLTy"); //aut_Ez.ShowGraph("aut_Ez"); //aut_notEz.ShowGraph("aut_notEz"); var xSyPrim = new MSOSuccN <BDD>(x, y, 1); var aut_xSyPrim = xSyPrim.GetAutomaton(ca); var equiv = aut_xSyPrim.IsEquivalentWith(aut_xSyDef); Assert.IsTrue(equiv); }
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 MSOLt <BoolExpr>(x, y); var xLTzLTy = new MSOAnd <BoolExpr>((new MSOLt <BoolExpr>(x, z)), (new MSOLt <BoolExpr>(z, y))); var Ez = new MSOExists <BoolExpr>(z, xLTzLTy); var notEz = new MSONot <BoolExpr>(Ez); var xSyDef = new MSOAnd <BoolExpr>(xLTy, notEz); var aut_xSyDef = xSyDef.GetAutomaton(alg); var aut_xLTzLTy = xLTzLTy.GetAutomaton(alg); var aut_Ez = Ez.GetAutomaton(alg); var aut_notEz = notEz.GetAutomaton(alg); var aut_xLTy = xLTy.GetAutomaton(alg); //aut_xSyDef.ShowGraph("aut_xSyDEf"); //aut_xLTzLTy.ShowGraph("aut_xLTzLTy"); //aut_Ez.ShowGraph("aut_Ez"); //aut_notEz.ShowGraph("aut_notEz"); var xSyPrim = new MSOSuccN <BoolExpr>(x, y, 1); var aut_xSyPrim = xSyPrim.GetAutomaton(alg); var equiv = aut_xSyPrim.IsEquivalentWith(aut_xSyDef); Assert.IsTrue(equiv); }
public void TestMSO_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 MSOIsSingleton <BDD>(x); MSOFormula <BDD> xSy = new MSOSubset <BDD>(x, y); var mem = new MSOAnd <BDD>(xSy, fo_x); var aut_mem = mem.GetAutomaton(ca); //aut_mem.ShowGraph("aut_mem"); }
public void TestMSO_Equal() { 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 MSOIsSingleton<BDD>(x) ; var fo_y = new MSOIsSingleton<BDD>(y); MSOFormula<BDD> fo = new MSOAnd<BDD>(fo_x, fo_y); MSOFormula<BDD> xSy = new MSOSubset<BDD>(x, y); MSOFormula<BDD> ySx = new MSOSubset<BDD>(y, x); MSOFormula<BDD> yEQx = new MSOAnd<BDD>(xSy, ySx); yEQx = new MSOAnd<BDD>(yEQx, fo); var aut_yEQx = yEQx.GetAutomaton(ca); //aut_yEQx.ShowGraph("aut_yEQx"); }
//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>(IBooleanAlgebra <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 MSOAnd <T>(new MSOAnd <T>(new MSONot <T>(new MSOEq <T>(x, y)), new MSOIsSingleton <T>(x)), new MSOIsSingleton <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 MSOExists <T>(X, new MSOAnd <T>( new MSOAnd <T>(new MSOSubset <T>(x, X), new MSOSubset <T>(y, X)), new MSONot <T>(new MSOExists <T>(z, new MSONot <T>( new MSOOr <T>(new MSONot <T>(new MSOAnd <T>(new MSOIsSingleton <T>(z), new MSOSubset <T>(z, X))), new MSOPredicate <T>(isWordLetter, z))))))); var psi2 = new MSOAnd <T>(xy, phi); var atLeast2wEE = new MSOExists <T>(x, new MSOExists <T>(y, psi2)); var psi1 = new MSOAnd <T>(new MSOIsSingleton <T>(x), new MSOPredicate <T>(isDigit, x)); var aut_psi1 = psi1.GetAutomaton(ca); //aut_psi1.ShowGraph("SFA(psi1)"); var atLeast1d = new MSOExists <T>(x, psi1); var psi = new MSOAnd <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")); //aut1.ShowGraph("aut1"); //aut2.ShowGraph("aut2"); bool equiv = aut2.IsEquivalentWith(BasicAutomata.Restrict(aut1)); Assert.IsTrue(equiv); //solver.ShowGraph(aut_atLeast1d, "aut_atLeast1d"); var aut_psi2 = psi2.GetAutomaton(ca); // 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 MSOPredicate <BDD>(solver.MkCharConstraint('c'), x); var fo_x = new MSOIsSingleton <BDD>(x); var ca = new CartesianAlgebraBDD <BDD>(solver); var lab = new MSOAnd <BDD>(pred, fo_x); MSOFormula <BDD> not_lab = new MSONot <BDD>(lab); var not_lab_actual = new MSOAnd <BDD>(not_lab, fo_x); var aut_not_lab = not_lab_actual.GetAutomaton(ca); var aut_not_lab_prelim = not_lab.GetAutomaton(ca); var c_aut_lab = lab.GetAutomaton(ca).Complement().Minimize(); //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 }