Example #1
0
 public void Run()
 {
     using (Context ctx = new Context()) {
         var        s    = ctx.MkFixedpoint();
         BoolSort   B    = ctx.BoolSort;
         Sort       BV8  = ctx.MkBitVecSort(8);
         FuncDecl   edge = ctx.MkFuncDecl("edge", new Sort[] { BV8, BV8 }, B);
         FuncDecl   path = ctx.MkFuncDecl("path", new Sort[] { BV8, BV8 }, B);
         BitVecExpr x    = (BitVecExpr)ctx.MkBound(0, BV8);
         BitVecExpr y    = (BitVecExpr)ctx.MkBound(1, BV8);
         BitVecExpr z    = (BitVecExpr)ctx.MkBound(2, BV8);
         s.RegisterRelation(edge);
         s.RegisterRelation(path);
         s.AddRule(ctx.MkImplies((BoolExpr)edge[x, y], (BoolExpr)path[x, y]));
         s.AddRule(ctx.MkImplies(ctx.MkAnd((BoolExpr)path[x, y], (BoolExpr)path[y, z]),
                                 (BoolExpr)path[x, z]));
         for (uint i = 0; i < 128; ++i)
         {
             s.AddFact(edge, i, i + 1);
         }
         Console.WriteLine(s.Query((BoolExpr)path[ctx.MkBV(0, 8), ctx.MkBV(129, 8)]));
         Console.WriteLine(s.GetAnswer());
         Console.WriteLine(s.Query((BoolExpr)path[ctx.MkBV(0, 8), ctx.MkBV(128, 8)]));
         Console.WriteLine(s.GetAnswer());
         Console.WriteLine(s.Query((BoolExpr)path[x, ctx.MkBV(20, 8)]));
         Console.WriteLine(s.GetAnswer());
         Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)path[x, y],
                                             (BoolExpr)path[y, ctx.MkBV(20, 8)])));
         Console.WriteLine(s.GetAnswer());
     }
 }
Example #2
0
    public void Run()
    {
        using (Context ctx = new Context()) {
            ctx.UpdateParamValue("DL_ENGINE", "1");
            ctx.UpdateParamValue("DL_PDR_USE_FARKAS", "true");
//          ctx.UpdateParamValue("VERBOSE","2");
            var       s  = ctx.MkFixedpoint();
            BoolSort  B  = ctx.BoolSort;
            IntSort   I  = ctx.IntSort;
            FuncDecl  mc = ctx.MkFuncDecl("mc", new Sort[] { I, I }, B);
            ArithExpr x  = (ArithExpr)ctx.MkBound(0, I);
            ArithExpr y  = (ArithExpr)ctx.MkBound(1, I);
            ArithExpr z  = (ArithExpr)ctx.MkBound(2, I);
            s.RegisterRelation(mc);
            BoolExpr gt = ctx.MkGt(x, ctx.MkInt(100));
            s.AddRule(ctx.MkImplies(gt, (BoolExpr)mc[x, ctx.MkSub(x, ctx.MkInt(10))]));
            s.AddRule(ctx.MkImplies(ctx.MkAnd(ctx.MkNot(gt),
                                              (BoolExpr)mc[ctx.MkAdd(x, ctx.MkInt(11)), y],
                                              (BoolExpr)mc[y, z]),
                                    (BoolExpr)mc[x, z]));
            Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)mc[x, y], ctx.MkGt(y, ctx.MkInt(100)))));
            Console.WriteLine(s.GetAnswer());

            Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)mc[x, y], ctx.MkLt(y, ctx.MkInt(91)))));
            Console.WriteLine(s.GetAnswer());
        }
    }
Example #3
0
 public void Run()
 {
     using (Context ctx = new Context()) {
         var        s   = ctx.MkFixedpoint();
         BoolSort   B   = ctx.BoolSort;
         Sort       BV8 = ctx.MkBitVecSort(8);
         FuncDecl   f   = ctx.MkFuncDecl("f", BV8, B);
         FuncDecl   g   = ctx.MkFuncDecl("g", BV8, B);
         BitVecExpr b0  = (BitVecExpr)ctx.MkBound(0, BV8);
         s.RegisterRelation(f);
         s.RegisterRelation(g);
         s.AddRule((BoolExpr)f[b0]);
         BitVecExpr mask0 = ctx.MkBV(0xFE, 8);
         BoolExpr   even  = ctx.MkEq(b0, ctx.MkBVAND(b0, mask0));
         s.AddRule(ctx.MkImplies(ctx.MkAnd((BoolExpr)f[b0], even), (BoolExpr)g[b0]));
         Console.WriteLine(s.Query((BoolExpr)g[b0]));
         Console.WriteLine(s.GetAnswer());
     }
 }
        public static bool isFlowChart(int n, int startIndex, Expr[,] R)
        {
            Trace.WriteLine("-----------------------------");
            Trace.WriteLine($"In 'isFlowChart', n:{n}, startIndex:{startIndex}");

            using (Context ctx = new Context())
            {
                var        s = ctx.MkFixedpoint();
                BoolSort   B = ctx.BoolSort;
                BitVecSort V = ctx.MkBitVecSort(S_BITVEC_SIZE);


                //Function declarations
                FuncDecl edge = ctx.MkFuncDecl("edge", new Sort[] { V, V }, B);
                FuncDecl path = ctx.MkFuncDecl("path", new Sort[] { V, V }, B);


                var x = (BitVecExpr)ctx.MkBound(0, V);
                var y = (BitVecExpr)ctx.MkBound(1, V);
                var z = (BitVecExpr)ctx.MkBound(2, V);

                s.RegisterRelation(edge);
                s.RegisterRelation(path);

                //Recursive reachability rules - edge and path
                //edge[x,y] => path[x,y]
                //path[x,y] && path[y,z] => path[x,z]
                s.AddRule(ctx.MkImplies((BoolExpr)edge[x, y], (BoolExpr)path[x, y]));
                s.AddRule(ctx.MkImplies(ctx.MkAnd((BoolExpr)path[x, y], (BoolExpr)path[y, z]),
                                        (BoolExpr)path[x, z]));

                //Add a edge fact if R[i,j] == 1,
                for (uint i = 0; i < n; i++)
                {
                    for (uint j = 0; j < n; j++)
                    {
                        if (R[i, j].ToString().Equals("1"))
                        {
                            s.AddFact(edge, i, j);
                        }
                    }
                }

                //For every vertex other than startIndex, there
                //should be a path from startIndex to vertex
                BoolExpr start_c = ctx.MkTrue();
                for (int i = 0; i < n; i++)
                {
                    if (i != startIndex)
                    {
                        start_c = ctx.MkAnd((BoolExpr)path[ctx.MkBV(startIndex, S_BITVEC_SIZE), ctx.MkBV(i, S_BITVEC_SIZE)], start_c);
                    }
                }

                Trace.WriteLine(s.ToString());
                Trace.WriteLine(start_c.ToString());
                Trace.WriteLine("-----------------------------");

                var status = s.Query(start_c);
                if (status == Status.SATISFIABLE)
                {
                    return(true);
                }
                else
                {
                    Trace.WriteLine(s.GetAnswer());
                    Trace.WriteLine("fail");
                    return(false);
                }
            }
        }