private Variable ConvertSet(MonaExpr set, MapStack <string, MonaParam> locals, out MSOFormula <BDD> psi)
        {
            if (set.NrOfSubexprs == 0)
            {
                return(ConvertEmptyset(out psi));
            }

            MSOFormula <BDD> disj = null;
            Variable         x    = MkNewVar1();
            Variable         X    = MkNewVar2();

            for (int i = 0; i < set.NrOfSubexprs; i++)
            {
                MonaExpr t = set[i];
                if (t.symbol.Kind == Tokens.RANGE)
                {
                    MSOFormula <BDD> from_psi;
                    Variable         from = ConvertTerm1(t[0], locals, out from_psi);
                    MSOFormula <BDD> to_psi;
                    Variable         to = ConvertTerm1(t[1], locals, out to_psi);

                    MSOFormula <BDD> range = AddConstraints(from_psi, from, to_psi, to,
                                                            new MSOAnd <BDD>(new MSOLe <BDD>(from, x), new MSOLe <BDD>(x, to)));

                    if (disj == null)
                    {
                        disj = range;
                    }
                    else
                    {
                        disj = new MSOOr <BDD>(disj, range);
                    }
                }
                else
                {
                    MSOFormula <BDD> y_psi;
                    Variable         y = ConvertTerm1(t, locals, out y_psi);

                    MSOFormula <BDD> elem = new MSOEq <BDD>(x, y);
                    if (y_psi != null)
                    {
                        elem = new MSOExists <BDD>(y, new MSOAnd <BDD>(y_psi, elem));
                    }

                    if (disj == null)
                    {
                        disj = elem;
                    }
                    else
                    {
                        disj = new MSOOr <BDD>(disj, elem);
                    }
                }
            }

            var pred = new MSOForall <BDD>(x, new MSOEquiv <BDD>(new MSOIn <BDD>(x, X), disj));

            psi = pred;
            return(X);
        }
Exemple #2
0
 public void TestMSO_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);
     MSOFormula<BDD> not_xLTy = new MSONot<BDD>(new MSOLt<BDD>(x,y));
     MSOFormula<BDD> xEQy = new MSOEq<BDD>(x, y);
     var xGTy = new MSOLt<BDD>(y, x);
     var xGEy = new MSOOr<BDD>(xEQy, xGTy);
     var aut_not_xLTy = not_xLTy.GetAutomaton(ca);
     var aut_xGEy = xGEy.GetAutomaton(ca);
     var c_aut_xLTy = (new MSOLt<BDD>(x,y)).GetAutomaton(ca).Complement().Determinize().Minimize();
     //c_aut_xLTy = c_aut_xLTy.Intersect(aut_fo, ca).Determinize(ca).Minimize(ca); //*
     //aut_not_xLTy.ShowGraph("aut_not_xLTy");
     //aut_xGEy.ShowGraph("aut_xGEy");
     //c_aut_xLTy.ShowGraph("c_aut_xLTy");
     var equiv1 = aut_not_xLTy.IsEquivalentWith(aut_xGEy);
     //var equiv2 = aut_not_xLTy.IsEquivalentWith(c_aut_xLTy, ca);
     Assert.IsTrue(equiv1);
     //Assert.IsTrue(equiv2);
 }
        private Variable ConvertSet(MonaExpr set, MapStack<string, MonaParam> locals, out MSOFormula<BDD> psi)
        {
            if (set.NrOfSubexprs == 0)
                return ConvertEmptyset(out psi);

            MSOFormula<BDD> disj = null;
            Variable x = MkNewVar1();
            Variable X = MkNewVar2();
            for (int i=0; i < set.NrOfSubexprs; i++)
            {
                MonaExpr t = set[i];
                if (t.symbol.Kind == Tokens.RANGE)
                {
                    MSOFormula<BDD> from_psi;
                    Variable from = ConvertTerm1(t[0], locals, out from_psi);
                    MSOFormula<BDD> to_psi;
                    Variable to = ConvertTerm1(t[1], locals, out to_psi);

                    MSOFormula<BDD> range = AddConstraints(from_psi, from, to_psi, to,
                        new MSOAnd<BDD>(new MSOLe<BDD>(from, x), new MSOLe<BDD>(x, to)));

                    if (disj == null)
                        disj = range;
                    else
                        disj = new MSOOr<BDD>(disj, range);
                }
                else
                {
                    MSOFormula<BDD> y_psi;
                    Variable y = ConvertTerm1(t, locals, out y_psi);

                    MSOFormula<BDD> elem = new MSOEq<BDD>(x, y);
                    if (y_psi != null)
                        elem = new MSOExists<BDD>(y, new MSOAnd<BDD>(y_psi, elem));

                    if (disj == null)
                        disj = elem;
                    else
                        disj = new MSOOr<BDD>(disj, elem);
                }
            }

            var pred = new MSOForall<BDD>(x, new MSOEquiv<BDD>(new MSOIn<BDD>(x, X), disj));
            psi = pred;
            return X;
        }
        private MSOFormula<BDD> ConvertPredApp(MonaPredApp predApp, MapStack<string, MonaParam> locals)
        {
            var predDef = predMap[predApp.symbol.text];
            var predDecl = (MonaPredDecl)globals[predApp.symbol.text];

            int k = predDecl.parameters.Count;
            if (k != predApp.NrOfSubexprs)
                throw new ArgumentException("invalid call of " + predDecl.name);

            if (k == 0)
                return predDef;

            var newVars = new Variable[k];
            Dictionary<string, Variable> substitution = new Dictionary<string, Variable>();

            var argPreds = new MSOFormula<BDD>[k];
            var argVars = new Variable[k];

            for (int i = 0; i < k; i++)
            {
                if (predDecl.parameters[i].kind != MonaParamKind.var1 && predDecl.parameters[i].kind != MonaParamKind.var2)
                    throw new NotImplementedException("parameter kind " + predDecl.parameters[i].kind.ToString());

                MSOFormula<BDD> argPreds_i;
                Variable argVars_i;
                if (predDecl.parameters[i].kind == MonaParamKind.var1)
                {
                    argVars_i = ConvertTerm1(predApp[i], locals, out argPreds_i);
                    if (argPreds_i == null)
                    {
                        var tmp1 = MkNewVar1();
                        argPreds_i = new MSOEq<BDD>(tmp1, argVars_i);
                        argVars_i = tmp1;
                    }
                }
                else
                {
                    argVars_i = ConvertTerm2(predApp[i], locals, out argPreds_i);
                    if (argPreds_i == null)
                    {
                        var tmp2 = MkNewVar2();
                        argPreds_i = new MSOEq<BDD>(tmp2, argVars_i);
                        argVars_i = tmp2;
                    }
                }
                argPreds[i] = argPreds_i;
                argVars[i] = argVars_i;
                substitution[predDecl.parameters[i].Token.text] = argVars_i;
            }

            MSOFormula<BDD> psi = predDef.SubstituteVariables(substitution);
            for (int i = k - 1; i >= 0; i--)
                psi = new MSOExists<BDD>(argVars[i], argPreds[i] & psi);

            return psi;
        }
Exemple #5
0
        private MSOFormula <BDD> ConvertPredApp(MonaPredApp predApp, MapStack <string, MonaParam> locals)
        {
            var predDef  = predMap[predApp.symbol.text];
            var predDecl = (MonaPredDecl)globals[predApp.symbol.text];

            int k = predDecl.parameters.Count;

            if (k != predApp.NrOfSubexprs)
            {
                throw new ArgumentException("invalid call of " + predDecl.name);
            }

            if (k == 0)
            {
                return(predDef);
            }

            var newVars = new Variable[k];
            Dictionary <string, Variable> substitution = new Dictionary <string, Variable>();

            var argPreds = new MSOFormula <BDD> [k];
            var argVars  = new Variable[k];

            for (int i = 0; i < k; i++)
            {
                if (predDecl.parameters[i].kind != MonaParamKind.var1 && predDecl.parameters[i].kind != MonaParamKind.var2)
                {
                    throw new NotImplementedException("parameter kind " + predDecl.parameters[i].kind.ToString());
                }

                MSOFormula <BDD> argPreds_i;
                Variable         argVars_i;
                if (predDecl.parameters[i].kind == MonaParamKind.var1)
                {
                    argVars_i = ConvertTerm1(predApp[i], locals, out argPreds_i);
                    if (argPreds_i == null)
                    {
                        var tmp1 = MkNewVar1();
                        argPreds_i = new MSOEq <BDD>(tmp1, argVars_i);
                        argVars_i  = tmp1;
                    }
                }
                else
                {
                    argVars_i = ConvertTerm2(predApp[i], locals, out argPreds_i);
                    if (argPreds_i == null)
                    {
                        var tmp2 = MkNewVar2();
                        argPreds_i = new MSOEq <BDD>(tmp2, argVars_i);
                        argVars_i  = tmp2;
                    }
                }
                argPreds[i] = argPreds_i;
                argVars[i]  = argVars_i;
                substitution[predDecl.parameters[i].Token.text] = argVars_i;
            }

            MSOFormula <BDD> psi = predDef.SubstituteVariables(substitution);

            for (int i = k - 1; i >= 0; i--)
            {
                psi = new MSOExists <BDD>(argVars[i], argPreds[i] & psi);
            }

            return(psi);
        }