コード例 #1
0
        public void SimpleForAllWithTrigger()
        {
            var builder  = GetSimpleBuilder();
            var freeVarX = GetVariable("x", BasicType.Int);
            var xid      = new IdentifierExpr(Token.NoToken, freeVarX);

            var fb       = new FunctionCallBuilder();
            var funcCall = fb.CreateUninterpretedFunctionCall("f", BPLType.Int, new List <BPLType>()
            {
                BPLType.Int
            });
            var body = builder.Gt(builder.UFC(funcCall, xid), xid);

            // Single trigger
            var triggers = new Microsoft.Boogie.Trigger(Token.NoToken,
                                                        /*positive=*/ true,
                                                        new List <Expr>()
            {
                builder.UFC(funcCall, xid)
            }, null);

            var result = builder.ForAll(new List <Variable>()
            {
                freeVarX
            }, body, triggers);

            Assert.AreEqual("(forall x: int :: { f(x) } f(x) > x)", result.ToString());
            CheckIsBoolType(result);
        }
コード例 #2
0
        public void NoFold()
        {
            var pair     = GetSimpleAndConstantFoldingBuilder();
            var sb       = pair.Item1;
            var cfb      = pair.Item2;
            var xPair    = GetBoundVarAndIdExpr("x", BasicType.Int);
            var freeVarX = xPair.Item1;
            var x        = xPair.Item2;

            var yPair    = GetBoundVarAndIdExpr("y", BasicType.Int);
            var freeVarY = yPair.Item1;
            var y        = yPair.Item2;

            var fb        = new FunctionCallBuilder();
            var dummyFunc = fb.CreateCachedUninterpretedFunctionCall("f", BPLType.Bool,
                                                                     new List <BPLType>()
            {
                BPLType.Int, BPLType.Int
            });

            var triggerExpr = sb.UFC(dummyFunc, x, y);
            var trigger     = new Trigger(Token.NoToken,
                                          /*pos=*/ true,
                                          new List <Expr>()
            {
                triggerExpr
            },
                                          null);

            var foldedResult = cfb.ForAll(new List <Variable>()
            {
                freeVarX, freeVarY
            }, cfb.Lt(x, y), trigger);
            var simpleResult = sb.ForAll(new List <Variable>()
            {
                freeVarX, freeVarY
            }, sb.Lt(x, y), trigger);

            CheckIsBoolType(foldedResult);
            CheckIsBoolType(simpleResult);
            Assert.AreEqual(simpleResult, foldedResult);

            // FIXME: Equals() currently doesn't check triggers, so do it manually
            Assert.IsInstanceOf <ForallExpr>(foldedResult);
            Assert.IsInstanceOf <ForallExpr>(simpleResult);
            var foldedResultAsForAll = foldedResult as ForallExpr;
            var simpleResultAsForAll = simpleResult as ForallExpr;

            Assert.IsNotNull(foldedResultAsForAll.Triggers);
            Assert.IsNull(foldedResultAsForAll.Triggers.Next);
            Assert.IsNotNull(simpleResultAsForAll.Triggers);
            Assert.IsNull(simpleResultAsForAll.Triggers.Next);
            Assert.AreSame(foldedResultAsForAll.Triggers, simpleResultAsForAll.Triggers);

            // Use this gross Boogie API too
            Assert.IsTrue(BinderExpr.EqualWithAttributesAndTriggers(simpleResult, foldedResult));
        }
コード例 #3
0
        public void simpleUF()
        {
            var builder = GetSimpleBuilder();
            var FCB     = new FunctionCallBuilder();
            var func    = FCB.CreateUninterpretedFunctionCall("foo", BasicType.Bool, new List <Microsoft.Boogie.Type>()
            {
                BasicType.Real,
                BasicType.Int,
                BasicType.GetBvType(8)
            });
            var root = builder.UFC(func, builder.ConstantReal("0.0"), builder.ConstantInt(5), builder.ConstantBV(5, 8));

            Assert.AreEqual("foo(0e0, 5, 5bv8)", root.ToString());
            DuplicateAndCheck(root, builder);
        }
コード例 #4
0
ファイル: Quantifiers.cs プロジェクト: shipeng331/symbooglix
        private Expr buildQuant(bool isForAll, SetupTriggersDeligate sutd)
        {
            var builder = MkBuilder();

            Assert.IsNotNull(builder);
            var xPair = GetVarAndIdExpr("x", BasicType.Int, /*isBound=*/ true);
            var xVar  = xPair.Item1;
            var xId   = xPair.Item2;
            var yPair = GetVarAndIdExpr("y", BasicType.Int, /*isBound=*/ true);
            var yId   = yPair.Item2;
            var yVar  = yPair.Item1;

            var fcb      = new FunctionCallBuilder();
            var funcCall = fcb.CreateCachedUninterpretedFunctionCall("f",
                                                                     BPLType.Int,
                                                                     new List <BPLType>()
            {
                BPLType.Int, BPLType.Int
            });

            // get triggers
            var triggers = sutd(builder, funcCall, xId, yId);

            var body = builder.Gt(builder.UFC(funcCall, xId, yId), xId);

            Expr result = null;

            if (isForAll)
            {
                result = builder.ForAll(new List <Variable>()
                {
                    xVar, yVar
                }, body, triggers);
            }
            else
            {
                result = builder.Exists(new List <Variable>()
                {
                    xVar, yVar
                }, body, triggers);
            }

            return(result);
        }
コード例 #5
0
        public void TestCase()
        {
            var FCB = new FunctionCallBuilder();

            var functionCall = FCB.CreateUninterpretedFunctionCall("uf", Microsoft.Boogie.Type.Bool, new List <Microsoft.Boogie.Type>()
            {
                Microsoft.Boogie.Type.Int,
                Microsoft.Boogie.Type.Real
            });


            var e = SEB.UFC(functionCall, SEB.ConstantInt(5), SEB.ConstantReal("5.5"));

            // FIXME: This needs to be factored out
            using (var writer = new StringWriter())
            {
                var printer = GetPrinter(writer);
                printer.AddDeclarations(e);
                printer.PrintFunctionDeclarations();
                printer.PrintExpr(e);
                Assert.AreEqual("(declare-fun uf (Int Real ) Bool)" + Environment.NewLine + "(uf 5 5.5  )", writer.ToString());
            }
        }
コード例 #6
0
        public void simpleForallWithTrigger()
        {
            var            builder   = GetSimpleBuilder();
            var            free0Pair = GetVarAndIdExpr("x", BasicType.Int);
            var            free1Pair = GetVarAndIdExpr("y", BasicType.Int);
            Variable       free0Var  = free0Pair.Item1;
            Variable       free1Var  = free1Pair.Item1;
            IdentifierExpr x         = free0Pair.Item2;
            IdentifierExpr y         = free1Pair.Item2;

            var fb        = new FunctionCallBuilder();
            var dummyFunc = fb.CreateCachedUninterpretedFunctionCall("f", BPLType.Bool,
                                                                     new List <BPLType>()
            {
                BPLType.Int, BPLType.Int
            });

            var triggerExpr = builder.UFC(dummyFunc, x, y);
            var trigger     = new Trigger(Token.NoToken,
                                          /*pos=*/ true,
                                          new List <Expr>()
            {
                triggerExpr
            },
                                          null);

            var root = builder.ForAll(new List <Variable>()
            {
                free0Var, free1Var
            },
                                      builder.Gt(builder.Add(x, y),
                                                 builder.Sub(x, y)), trigger);

            Assert.AreEqual("(forall x: int, y: int :: { f(x, y) } x + y > x - y)", root.ToString());
            DuplicateAndCheck(root, builder);
        }
コード例 #7
0
        public void RemoveOneConstraintBasedOnVarsAndFunctions()
        {
            IConstraintManager CM = new ConstraintManager();
            var builder           = GetBuilder();

            // Dummy Boogie variable
            var bv8Type      = Microsoft.Boogie.Type.GetBvType(8);
            var bv8TypeIdent = new TypedIdent(Token.NoToken, "bv8", bv8Type);
            var dummyVarBv   = new GlobalVariable(Token.NoToken, bv8TypeIdent);

            // dummyVar needs a programLocation, otherwise SymbolicVariable constructor raises an exception
            var progLoc = new ProgramLocation(dummyVarBv);

            dummyVarBv.SetMetadata <ProgramLocation>((int)Symbooglix.Annotation.AnnotationIndex.PROGRAM_LOCATION, progLoc);

            var s0 = new SymbolicVariable("s0", dummyVarBv).Expr;
            var s1 = new SymbolicVariable("s1", dummyVarBv).Expr;
            var s2 = new SymbolicVariable("s2", dummyVarBv).Expr;

            // Construct some constraints
            Expr c0 = builder.Eq(builder.BVAND(s0, s1), builder.ConstantBV(0, 8));
            Expr c1 = builder.Eq(s2, builder.ConstantBV(1, 8));

            var FCB        = new FunctionCallBuilder();
            var foobarFunc = FCB.CreateUninterpretedFunctionCall("foobar", bv8Type, new List <Microsoft.Boogie.Type>()
            {
                bv8Type
            });
            // foobar(0bv8) == 0bv8
            Expr c2 = builder.Eq(builder.UFC(foobarFunc, builder.ConstantBV(0, 8)), builder.ConstantBV(0, 8));

            CM.AddConstraint(c0, progLoc);
            CM.AddConstraint(c1, progLoc);
            CM.AddConstraint(c2, progLoc);

            var mockSolver      = new MockSolver();
            var indepenceSolver = new Symbooglix.Solver.ConstraintIndependenceSolver(mockSolver);

            // The query expression does not use the "foobar" function so we don't need to keep constraints on that function
            Expr queryExpr = builder.Eq(builder.BVAND(s1, s2), builder.ConstantBV(0, 8));


            indepenceSolver.ComputeSatisfiability(new Solver.Query(CM, new Constraint(queryExpr)));

            // Check no constraints were removed
            Assert.AreEqual(2, mockSolver.Constraints.Count);
            Assert.AreSame(queryExpr, mockSolver.QueryExpr);

            bool c0Found = false;
            bool c1Found = false;

            foreach (var constraint in mockSolver.Constraints)
            {
                if (c0 == constraint.Condition)
                {
                    c0Found = true;
                }

                if (c1 == constraint.Condition)
                {
                    c1Found = true;
                }
            }

            Assert.IsTrue(c0Found);
            Assert.IsTrue(c1Found);
        }