Ejemplo n.º 1
0
        public void Mona2AutomatonTest3(bool singletonSetSemantics)
        {
            BDDAlgebra solver = new BDDAlgebra();

            string      source1 = @"
m2l-str;
var1 x,y;
y = x + 2;
";
            string      source2 = @"
m2l-str;
var1 x,y;
ex1 z: x<z & z<y;
x < y & ~ex1 z1,z2: x<z1 & z1<y & x<z2 & z2<y & z1 ~= z2;
";
            MonaProgram pgm1    = MonaParser.Parse(source1);
            var         mso1    = pgm1.ToMSO();
            var         aut1    = mso1.GetAutomaton(solver, 0, singletonSetSemantics);

            //aut1.ShowGraph("aut1");

            MonaProgram pgm2 = MonaParser.Parse(source2);
            var         mso2 = pgm2.ToMSO();
            var         aut2 = mso2.GetAutomaton(solver, 0, singletonSetSemantics);

            //aut2.ShowGraph("aut2");

            Assert.IsTrue(aut1.IsEquivalentWith(aut2));
        }
Ejemplo n.º 2
0
        public void Mona2AutomatonTest_pred1(bool useSingletonSetSemantics)
        {
            BDDAlgebra solver = new BDDAlgebra();

            string source1 =
                @"m2l-str;
pred succ(var1 x,y) = x < y & ~ex1 z:(x < z & z < y);
var1 x,y,z;
succ(x,y) & succ(y,z);
";

            string source2 =
                @"m2l-str;
var1 x,y,z;
y = x+1 & z = y + 1;
";

            MonaProgram pgm1 = MonaParser.Parse(source1);
            var         mso1 = pgm1.ToMSO();
            var         aut1 = mso1.GetAutomaton(solver, 0, useSingletonSetSemantics);

            MonaProgram pgm2 = MonaParser.Parse(source2);
            var         mso2 = pgm2.ToMSO();
            var         aut2 = mso2.GetAutomaton(solver, 0, useSingletonSetSemantics);

            Assert.IsTrue(aut1.IsEquivalentWith(aut2));
        }
Ejemplo n.º 3
0
        public void Mona2AutomatonTest2()
        {
            BDDAlgebra solver = new BDDAlgebra();

            string      source1 = @"
m2l-str;
var1 x,y;
y = x + 1;
";
            string      source2 = @"
m2l-str;
var1 x,y;
x < y & ~ex1 z: x<z & z<y;
";
            MonaProgram pgm1    = MonaParser.Parse(source1);
            var         mso1    = pgm1.ToMSO();
            var         aut1    = mso1.GetAutomaton(solver);

            //aut1.ShowGraph("aut1");

            MonaProgram pgm2 = MonaParser.Parse(source2);
            var         mso2 = pgm2.ToMSO();
            var         aut2 = mso2.GetAutomaton(solver);

            //aut2.ShowGraph("aut2");

            Assert.IsTrue(aut1.IsEquivalentWith(aut2));
        }
Ejemplo n.º 4
0
        public void Mona2AutomatonTest_pred3()
        {
            BDDAlgebra solver = new BDDAlgebra();

            string source1 =
                @"m2l-str;
pred belongs(var1 x, var2 X) = x in X;
pred subs(var2 X, Y) = all1 x: belongs(x,X) => belongs(x,Y);
pred equal(var2 X,Y) = subs(X,Y) & subs(Y,X);
var2 X, Y;
equal(X,Y);
";

            string source2 =
                @"m2l-str;
var2 Y, X;
Y = X;
";

            MonaProgram pgm1 = MonaParser.Parse(source1);
            var         mso1 = pgm1.ToMSO();
            var         aut1 = mso1.GetAutomaton(solver);

            MonaProgram pgm2 = MonaParser.Parse(source2);
            var         mso2 = pgm2.ToMSO();
            var         aut2 = mso2.GetAutomaton(solver);

            Assert.IsTrue(aut1.IsEquivalentWith(aut2));
        }
Ejemplo n.º 5
0
        //LTL over finite traces
        private static void AutomatarkMsoFormulasTest(string inputDir, string outFile)
        {
            Console.WriteLine("fileName , generic-bdd, product");
            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(outFile))
            {
                var files = new List <string>(Directory.EnumerateFiles(inputDir, "*.mona", SearchOption.AllDirectories));
                files.Sort((s1, s2) => cmp(s1, s2));
                foreach (string fileName in files)
                {
                    string      contents = File.ReadAllText(fileName);
                    MonaProgram pgm1     = MonaParser.Parse(contents);
                    phi = pgm1.ToMSO();

                    var bv7 = new CharSetSolver(BitWidth.BV7);
                    bddSolver = new BDDAlgebra <BDD>(bv7);
                    var sw = new Stopwatch();
                    sw.Restart();
                    Thread t = new Thread(BDDSolver);
                    t.Start();
                    long t1 = 5000;
                    if (!t.Join(TimeSpan.FromSeconds(5)))
                    {
                        t.Abort();
                        t1 = 5000;
                    }
                    else
                    {
                        sw.Stop();
                        t1 = sw.ElapsedMilliseconds;
                    }

                    bv7        = new CharSetSolver(BitWidth.BV7);
                    cartSolver = new CartesianAlgebraBDD <BDD>(bv7);

                    sw.Restart();
                    t = new Thread(CartesianSolver);
                    t.Start();
                    long t2 = 5000;
                    if (!t.Join(TimeSpan.FromSeconds(5)))
                    {
                        t.Abort();
                        t2 = 5000;
                    }
                    else
                    {
                        sw.Stop();
                        t2 = sw.ElapsedMilliseconds;
                    }

                    //if (t2 > 5000)
                    //    t2 = 5000;

                    file.WriteLine(fileName + "," + (double)t1 / numTests + "," + (double)t2 / numTests);
                    Console.WriteLine(fileName + "," + (double)t1 / numTests + "," + (double)t2 / numTests);
                }
            }
        }
Ejemplo n.º 6
0
        public void MonaTestIn()
        {
            string      input = @"
0x3 in {1,2,3};
4 notin {1,...,3,6};
";
            MonaProgram pgm   = MonaParser.Parse(input);

            Assert.IsTrue(pgm.declarations.Count == 2);
        }
Ejemplo n.º 7
0
        public void MonaTestVar0decl()
        {
            string      input = @"
var0 a, b ; # Boolean vars a and b
";
            MonaProgram pgm   = MonaParser.Parse(input);

            Assert.AreEqual <int>(1, pgm.declarations.Count);
            Assert.AreEqual <string>("var0 a,b;", pgm.ToString().Trim());
        }
Ejemplo n.º 8
0
        public void MonaTestAllpos()
        {
            string      input = @"
var2 q;
allpos q; 
";
            MonaProgram pgm   = MonaParser.Parse(input);

            Assert.IsTrue(pgm.declarations.Count == 2);
        }
Ejemplo n.º 9
0
        public void MonaTestPred()
        {
            string      input = @"
var1 p, q;
var2 Qe, Q1, Q2;
pred is0(var1 p, var2 Qe, Q1, Q2) = p in Qe & p notin Q1 & p notin Q2;
is0(p, Qe, Q1, Q2) & ~is0(q, Qe, Q1, Q2);  
";
            MonaProgram pgm   = MonaParser.Parse(input);

            Assert.IsTrue(pgm.declarations.Count == 4);
        }
Ejemplo n.º 10
0
        public void MonaTestDefaultWhereDecl()
        {
            string      input = @"
defaultwhere1(p) = p < 10;
";
            MonaProgram pgm   = MonaParser.Parse(input);

            Assert.AreEqual <int>(1, pgm.declarations.Count);
            Assert.IsTrue(pgm.declarations[0] is MonaDefaultWhereDecl);
            Assert.IsFalse((pgm.declarations[0] as MonaDefaultWhereDecl).isSecondOrder);
            Assert.IsTrue((pgm.declarations[0] as MonaDefaultWhereDecl).kind == MonaDeclKind.defaultwhere1);
        }
Ejemplo n.º 11
0
        public void MonaTest3()
        {
            string  input = @"
pred is0(var1 p, var2 Qe, Q1, Q2) = p in Qe & p notin Q1 & p notin Q2;
(is0(p, Qe, Q1, Q2) & ~is0(q, Qe, Q1, Q2));  
3 in {1,2,3};
X = {1};
7 in {2,3,4} + 3;
";
            Program pgm   = MonaParser.Parse(input);

            Assert.IsTrue(pgm.declarations.Count > 0);
        }
Ejemplo n.º 12
0
        public void MonaTestQ1()
        {
            string      input = @"
const zero = 0;
pred lt(var1 x,y) = x < y + zero;
macro psi(var2 Y, var1 x,y) = (ex1 z: lt(x,z) & lt(z,y)) & (all2 X: X sub Y => X = Y); 
";
            MonaProgram pgm   = MonaParser.Parse(input);

            Assert.AreEqual <int>(3, pgm.declarations.Count);
            Assert.IsTrue(pgm.declarations[0] is MonaConstDecl);
            Assert.IsTrue(pgm.declarations[1] is MonaPredDecl);
            Assert.IsTrue(pgm.declarations[2] is MonaPredDecl);
            var zero = pgm.declarations[0] as MonaConstDecl;

            Assert.IsTrue(zero.name.text == "zero");
            var lt = pgm.declarations[1] as MonaPredDecl;

            Assert.IsFalse(lt.isMacro);
            Assert.IsTrue(lt.name.text == "lt");
            var pred = pgm.declarations[2] as MonaPredDecl;

            Assert.IsTrue(pred.isMacro);
            Assert.IsTrue(pred.name.text == "psi");
            Assert.IsTrue(pred.formula.type == MonaExprType.BOOL);
            Assert.IsTrue(pred.formula is MonaBinaryBooleanFormula);
            MonaBinaryBooleanFormula phi = pred.formula as MonaBinaryBooleanFormula;

            Assert.IsTrue(phi.op == MonaBinaryBooleanOp.AND);
            Assert.IsTrue(phi.arg1.type == MonaExprType.BOOL);
            Assert.IsTrue(phi.arg2.type == MonaExprType.BOOL);
            Assert.IsTrue(phi.arg1 is MonaQFormula);
            Assert.IsTrue(phi.arg2 is MonaQFormula);
            var psi1 = phi.arg1 as MonaQFormula;
            var psi2 = phi.arg2 as MonaQFormula;

            Assert.IsTrue(psi1.symbol.Kind == Tokens.EX1);
            Assert.IsTrue(psi2.symbol.Kind == Tokens.ALL2);
            Assert.IsTrue(psi2.formula.type == MonaExprType.BOOL);
            Assert.IsTrue(psi2.formula is MonaBinaryBooleanFormula);
            var psi3 = psi2.formula as MonaBinaryBooleanFormula;

            Assert.IsTrue(psi3.op == MonaBinaryBooleanOp.IMPLIES);
            Assert.IsTrue(psi3.arg1 is MonaBinaryAtom);
            var lhs = psi3.arg1 as MonaBinaryAtom;

            Assert.IsTrue(lhs.symbol.Kind == Tokens.SUBSET);
            var rhs = psi3.arg2 as MonaBinaryAtom;

            Assert.IsTrue(rhs.symbol.Kind == Tokens.EQ);
        }
Ejemplo n.º 13
0
        public void Mona2AutomatonTest4()
        {
            BDDAlgebra solver = new BDDAlgebra();

            string source1 = @"
m2l-str;
var2 X,Y;
Y = X;
";
            string source2 = @"
m2l-str;
var2 X,Y;
all1 z: z in X <=> z in Y;
";

            string source3 = @"
m2l-str;
var2 X,Y;
Y sub X & X sub Y;
";

            string      source4 = @"
m2l-str;
var2 X,Y;
Y\X = empty & X\Y = empty;
";
            MonaProgram pgm1    = MonaParser.Parse(source1);
            var         mso1    = pgm1.ToMSO();
            var         aut1    = mso1.GetAutomaton(solver);

            //aut1.ShowGraph("aut1");

            MonaProgram pgm2 = MonaParser.Parse(source2);
            var         mso2 = pgm2.ToMSO();
            var         aut2 = mso2.GetAutomaton(solver);

            //aut2.ShowGraph("aut2");

            MonaProgram pgm3 = MonaParser.Parse(source3);
            var         mso3 = pgm3.ToMSO();
            var         aut3 = mso3.GetAutomaton(solver);

            MonaProgram pgm4 = MonaParser.Parse(source4);
            var         mso4 = pgm4.ToMSO();
            var         aut4 = mso4.GetAutomaton(solver);

            Assert.IsTrue(aut1.IsEquivalentWith(aut2));
            Assert.IsTrue(aut1.IsEquivalentWith(aut3));
            Assert.IsTrue(aut1.IsEquivalentWith(aut4));
        }
Ejemplo n.º 14
0
        public void Mona2AutomatonTest1()
        {
            string      source = @"
m2l-str;
var1 x,y;
x < y;
";
            MonaProgram pgm    = MonaParser.Parse(source);
            var         mso    = pgm.ToMSO();
            BDDAlgebra  solver = new BDDAlgebra();
            var         aut    = mso.GetAutomaton(solver);

            //aut.ShowGraph();
            Assert.IsTrue(aut.StateCount == 3);
        }
Ejemplo n.º 15
0
        public void MonaTestUnivDecl()
        {
            string      input = @"
m2l-tree;
universe U1, U2:110101, U3:foo; # sample universes
";
            MonaProgram pgm   = MonaParser.Parse(input);

            Assert.AreEqual <int>(1, pgm.declarations.Count);
            Assert.IsTrue(pgm.declarations[0] is MonaUnivDecls);
            var univdecl = pgm.declarations[0] as MonaUnivDecls;

            Assert.IsTrue(univdecl.args.Count == 3);
            Assert.IsTrue(univdecl.args[1] is MonaUnivArgWithSucc);
            Assert.IsTrue(univdecl.args[2] is MonaUnivArgWithType);
        }
Ejemplo n.º 16
0
        public void MonaTestMacroDecl2_error()
        {
            string input = @"
macro bar(var2 P, R, Q, var1 Q, var0 e) = q in P;
";

            try
            {
                Program pgm = MonaParser.Parse(input);
            }
            catch (MonaParseException e)
            {
                return;
            }
            Assert.Fail("expected MonaParseException");
        }
Ejemplo n.º 17
0
        public void MonaTestAllpos_error1()
        {
            string input = @"
allpos q; 
";

            try
            {
                MonaProgram pgm = MonaParser.Parse(input);
            }
            catch (MonaParseException e)
            {
                Assert.AreEqual(e.Kind, MonaParseExceptionKind.UndeclaredIdentifier);
                return;
            }
            Assert.Fail("expecting " + MonaParseExceptionKind.UndeclaredIdentifier.ToString());
        }
Ejemplo n.º 18
0
        public void MonaTestMacroDecl2_error()
        {
            string input = @"
macro bar(var2 P, R, Q, var1 Q, var0 e) = q in P;
";

            try
            {
                MonaProgram pgm = MonaParser.Parse(input);
            }
            catch (MonaParseException e)
            {
                Assert.AreEqual(MonaParseExceptionKind.DuplicateDeclaration, e.Kind);
                return;
            }
            Assert.Fail("expected " + MonaParseExceptionKind.DuplicateDeclaration.ToString());
        }
Ejemplo n.º 19
0
        public void MonaTestMacroDecl1()
        {
            string      input = @"
macro bar(var2 P,Q) = 1 in P;
";
            MonaProgram pgm   = MonaParser.Parse(input);

            Assert.AreEqual <int>(1, pgm.declarations.Count);
            Assert.IsTrue(pgm.declarations[0] is MonaPredDecl);
            var bar = pgm.declarations[0] as MonaPredDecl;

            Assert.IsTrue(bar.isMacro);
            Assert.AreEqual <string>("bar", bar.name.text);
            Assert.IsTrue(bar.parameters.Count == 2);
            Assert.IsTrue(bar.parameters[0].kind == MonaParamKind.var2);
            Assert.IsTrue(bar.parameters[1].kind == MonaParamKind.var2);
        }
Ejemplo n.º 20
0
        public void MonaTestConstDecl_error()
        {
            string input = @"
const a = 23 + 2;
const b = a + (2 - c);
";

            try
            {
                MonaProgram pgm = MonaParser.Parse(input);
            }
            catch (MonaParseException e)
            {
                Assert.IsTrue(e.Kind == MonaParseExceptionKind.UndeclaredConstant);
                return;
            }
            Assert.Fail("expecting " + MonaParseExceptionKind.UndeclaredConstant.ToString());
        }
Ejemplo n.º 21
0
        public void MonaTestConstDecl()
        {
            string      input = @"
const a = 23 + 2;
const b = a + (2 - a);
";
            MonaProgram pgm   = MonaParser.Parse(input);

            Assert.AreEqual <int>(2, pgm.declarations.Count);
            Assert.IsTrue(pgm.declarations[0] is MonaConstDecl);
            Assert.IsTrue(pgm.declarations[1] is MonaConstDecl);
            var a = pgm.declarations[0] as MonaConstDecl;

            Assert.IsTrue(a.name.text == "a");
            var b = pgm.declarations[1] as MonaConstDecl;

            Assert.IsTrue(b.name.text == "b");
        }
Ejemplo n.º 22
0
        public void MonaTestUnivDecl_error()
        {
            string input = @"
m2l-tree;
universe U1, U2:110201, U3:foo; # sample universes
";

            try
            {
                MonaProgram pgm = MonaParser.Parse(input);
            }
            catch (MonaParseException e)
            {
                Assert.AreEqual(MonaParseExceptionKind.InvalidUniverseDeclaration, e.Kind);
                return;
            }
            Assert.Fail("expecting " + MonaParseExceptionKind.InvalidUniverseDeclaration.ToString());
        }
Ejemplo n.º 23
0
        public void MonaTestVar0decl_error()
        {
            string input = @"
var1 a; # variable a 
var0 a; # variable a again
";

            try
            {
                MonaProgram pgm = MonaParser.Parse(input);
            }
            catch (MonaParseException e)
            {
                Assert.AreEqual(MonaParseExceptionKind.DuplicateDeclaration, e.Kind);
                return;
            }
            Assert.Fail("expected " + MonaParseExceptionKind.DuplicateDeclaration.ToString());
        }
Ejemplo n.º 24
0
        public void MonaTestAllpos_error2()
        {
            string input = @"
var1 q;
allpos q; 
";

            try
            {
                MonaProgram pgm = MonaParser.Parse(input);
            }
            catch (MonaParseException e)
            {
                Assert.AreEqual(e.Kind, MonaParseExceptionKind.TypeMismatch);
                return;
            }
            Assert.Fail("expecting " + MonaParseExceptionKind.TypeMismatch.ToString());
        }
Ejemplo n.º 25
0
        public void MonaTestVar0decl_error()
        {
            string input = @"
var1 a; # variable a 
var0 a; # variable a again
";

            try
            {
                Program pgm = MonaParser.Parse(input);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is MonaParseException);
                return;
            }
            Assert.IsTrue(false, "expected MonaParseException");
        }
Ejemplo n.º 26
0
        public void MonaTestLet1_error()
        {
            string input = @"
var2 c;
let1 x=3,y=c in x < y;
";

            try
            {
                MonaProgram pgm = MonaParser.Parse(input);
            }
            catch (MonaParseException e)
            {
                Assert.IsTrue(e.Kind == MonaParseExceptionKind.TypeMismatch);
                return;
            }
            Assert.Fail("expecting " + MonaParseExceptionKind.TypeMismatch.ToString());
        }
Ejemplo n.º 27
0
        public void MonaTestConstDecl_error()
        {
            string input = @"
const a = 23 + 2;
const b = a + (2 - c);
";

            try
            {
                Program pgm = MonaParser.Parse(input);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is MonaParseException);
                return;
            }
            Assert.IsTrue(false, "expecting MonaParseException");
            return;
        }
Ejemplo n.º 28
0
        public void MonaTestDecl_error()
        {
            string input = @"
const a = 23 + 2;
pred P = 1 = 1;
const b = a + (2 - P);
";

            try
            {
                MonaProgram pgm = MonaParser.Parse(input);
            }
            catch (MonaParseException e)
            {
                Assert.AreEqual(MonaParseExceptionKind.IdentifierIsNotDeclaredConstant, e.Kind);
                return;
            }
            Assert.Fail("expecting " + MonaParseExceptionKind.IdentifierIsNotDeclaredConstant.ToString());
        }
Ejemplo n.º 29
0
        public void MonaTestUnivDecl_error()
        {
            string input = @"
m2l-tree;
universe U1, U2:110201, U3:foo; # sample universes
";

            try
            {
                Program pgm = MonaParser.Parse(input);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is MonaParseException);
                return;
            }
            Assert.IsTrue(false, "expecting MonaParseException");
            return;
        }
Ejemplo n.º 30
0
        public void MonaTestLet0()
        {
            string      input = @"
const t = 42;
let0 x=(t=t),y=(true) in (x <=> y);
";
            MonaProgram pgm   = MonaParser.Parse(input);

            Assert.AreEqual <int>(2, pgm.declarations.Count);
            Assert.IsTrue(pgm.declarations[0] is MonaConstDecl);
            Assert.IsTrue(pgm.declarations[1] is MonaFormulaDecl);
            var let = (pgm.declarations[1] as MonaFormulaDecl).formula as MonaLet;

            Assert.IsTrue(let != null && let.Kind == MonaLetKind.let0);
            Assert.IsTrue(let.let_vars.Count == 2);
            foreach (var kv in let.let_vars)
            {
                Assert.IsTrue(kv.Value.kind == MonaParamKind.var0);
            }
        }