MkDiv() public method

Create an expression representing t1 / t2.
public MkDiv ( ArithExpr t1, ArithExpr t2 ) : ArithExpr
t1 ArithExpr
t2 ArithExpr
return ArithExpr
Esempio n. 1
0
File: tst2.cs Progetto: ahorn/z3test
    public void Run()
    {
        using (Context ctx = new Context())
        {
            BoolExpr p = ctx.MkBoolConst("p");
            Console.WriteLine(ctx.MkNot(p));
            Console.WriteLine(ctx.MkNot(p));
            IntExpr x = ctx.MkIntConst("x");
            IntExpr y = ctx.MkIntConst("y");

            Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)));
            Console.WriteLine(ctx.MkAdd(ctx.MkInt(1), x));
            Console.WriteLine(ctx.MkAdd(x, y));
            Console.WriteLine(ctx.MkMul(ctx.MkInt(2), x));
            Console.WriteLine(ctx.MkMul(x, ctx.MkInt(2)));
            Console.WriteLine(ctx.MkMul(x, y));
            Console.WriteLine(ctx.MkDiv(x, y));
            Console.WriteLine(ctx.MkMod(x, y));
            Console.WriteLine(ctx.MkEq(x, y));
            Console.WriteLine(ctx.MkDistinct(x, y, x));
            Console.WriteLine(ctx.MkNot(ctx.MkEq(x, y)));
            Console.WriteLine(ctx.MkEq(x, y));
            Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)));
            Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)));

            BoolExpr q = ctx.MkBoolConst("q");
            Console.WriteLine(ctx.MkNot(p));
            Console.WriteLine(ctx.MkNot(p));
            Console.WriteLine(ctx.MkAnd(p, q));
            Console.WriteLine(ctx.MkAnd(p, q));
            Console.WriteLine(ctx.MkEq(x, y));
        }
    }
Esempio n. 2
0
    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" } };

        using (Context ctx = new Context(cfg))
        {
            RealExpr d = ctx.MkRealConst("d");
            RealExpr a = ctx.MkRealConst("a");
            RealExpr t = ctx.MkRealConst("t");
            RealExpr v_i = ctx.MkRealConst("v_i");
            RealExpr v_f = ctx.MkRealConst("v_f");

            BoolExpr[] equations = new BoolExpr[] {
                ctx.MkEq(d, ctx.MkAdd(ctx.MkMul(v_i, t),
                                      ctx.MkDiv(ctx.MkMul(a, ctx.MkPower(t, ctx.MkReal(2))),
                                                ctx.MkReal(2)))),
                ctx.MkEq(v_f, ctx.MkAdd(v_i, ctx.MkMul(a, t)))
            };

            Console.WriteLine("Kinematic equations: ");
            foreach (BoolExpr e in equations)
                Console.WriteLine(e);

            BoolExpr[] problem = new BoolExpr[] {
                ctx.MkEq(v_i, ctx.MkReal(0)),
                ctx.MkEq(t, ctx.MkReal("4.10")),
                ctx.MkEq(a, ctx.MkReal(6))
            };

            Console.WriteLine("Problem: ");
            foreach (BoolExpr p in problem)
                Console.WriteLine(p);

            Solver s = ctx.MkSolver();
            s.Assert(equations);
            s.Assert(problem);

            if (s.Check() != Status.SATISFIABLE)
                throw new Exception("BUG");

            Console.WriteLine("Solution: ");
            Console.WriteLine(s.Model);

            Console.WriteLine("Decimal Solution: ");
            foreach (FuncDecl f in s.Model.ConstDecls)
                Console.WriteLine(f.Name + " = " + ((RatNum)s.Model.ConstInterp(f)).ToDecimalString(10));
        }
    }
Esempio n. 3
0
    public void Run()
    {
        using (Context ctx = new Context())
        {
            RealExpr x = ctx.MkRealConst("x");
            RealExpr y = ctx.MkRealConst("y");
            RealExpr z = ctx.MkRealConst("z");

            IntExpr a = ctx.MkIntConst("a");
            IntExpr b = ctx.MkIntConst("b");
            IntExpr c = ctx.MkIntConst("c");

            ctx.UpdateParamValue(":pp-flat-assoc", "false");

            Console.WriteLine(ctx.MkAdd(x, y, ctx.MkInt2Real(a)));
            Console.WriteLine(ctx.MkAdd(x, ctx.MkReal(1)));
            Console.WriteLine(ctx.MkAdd(ctx.MkReal(2), y));
            Console.WriteLine(ctx.MkMul(x, y));
            Console.WriteLine(ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3)));
            Console.WriteLine(ctx.MkMul(ctx.MkReal(2), x));
            Console.WriteLine(ctx.MkAdd(ctx.MkInt2Real((IntExpr)ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3))), x));
            Console.WriteLine(ctx.MkAdd((RealExpr)ctx.MkInt2Real((IntExpr)ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3))).Simplify(), x));
            Console.WriteLine(ctx.MkAdd(a, b, ctx.MkInt(1)));
            Console.WriteLine(ctx.MkDiv(x, y));
            Console.WriteLine(ctx.MkDiv(x, ctx.MkReal(2)));
            Console.WriteLine(ctx.MkDiv(ctx.MkReal(2), y));
            Console.WriteLine(ctx.MkDiv(a, ctx.MkInt(2)));
            Console.WriteLine(ctx.MkDiv(ctx.MkAdd(a, b), ctx.MkInt(2)));
            Console.WriteLine(ctx.MkDiv(ctx.MkInt(3), a));
            Console.WriteLine(ctx.MkMod(a, b));
            Console.WriteLine(ctx.MkMod(a, ctx.MkInt(2)));
            Console.WriteLine(ctx.MkMod(ctx.MkInt(3), a));
            Console.WriteLine(ctx.MkSub(a, ctx.MkInt(2)));
            Console.WriteLine(ctx.MkUnaryMinus(a));
            Console.WriteLine(ctx.MkUnaryMinus(x));
            Console.WriteLine(ctx.MkSub(a, b));

            Console.WriteLine(a.IsAdd);
            Console.WriteLine(ctx.MkAdd(a, b).IsAdd);
            Console.WriteLine(ctx.MkSub(a, b).IsAdd);
            Console.WriteLine(ctx.MkInt(10).IsAdd);
            Console.WriteLine(ctx.MkMul(a, b).IsMul);
            Console.WriteLine(ctx.MkMul(x, ctx.MkInt2Real(b)).IsMul);
            Console.WriteLine(ctx.MkAdd(a, b).IsMul);
            Console.WriteLine(ctx.MkDiv(a, ctx.MkInt(2)).IsDiv);
            Console.WriteLine(ctx.MkDiv(ctx.MkReal(3), x).IsDiv);
            Console.WriteLine(ctx.MkDiv(x,y).IsDiv);
            Console.WriteLine(ctx.MkDiv(a, ctx.MkInt(2)).IsIDiv);
            Console.WriteLine(ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3)).Simplify().IsAdd);

            Console.WriteLine();
            Console.WriteLine(a is ArithExpr);
            Console.WriteLine(ctx.MkInt(2) is ArithExpr);
            Console.WriteLine(ctx.MkAdd(a, b) is ArithExpr);
            Console.WriteLine(ctx.MkBoolConst("p") is ArithExpr);
            Console.WriteLine(ctx.MkInt(2) is IntNum);
            Console.WriteLine(ctx.MkInt(2) is RatNum);
            Console.WriteLine(ctx.MkReal(2, 3));
            Console.WriteLine(ctx.MkReal(2, 3).IsReal);
            Console.WriteLine(ctx.MkReal(2, 3) is ArithExpr);
            Console.WriteLine(ctx.MkReal(2, 3).IsConst);
            Console.WriteLine(ctx.MkReal(2, 3).Simplify() is RatNum);
            Console.WriteLine(ctx.MkReal(2, 3).Simplify().IsRatNum);
            Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).Simplify().IsAlgebraicNumber);
            Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).Simplify() is AlgebraicNum);
            Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).IsAlgebraicNumber);
            Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)) is AlgebraicNum);
            Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)));
            Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 3)));
        }
    }