MCPcopy Create free account
hub / github.com/Z3Prover/z3 / evalExample1

Method evalExample1

examples/java/JavaGenericExample.java:1642–1678  ·  view source on GitHub ↗
(Context ctx)

Source from the content-addressed store, hash-verified

1640 // / Demonstrate how to use #Eval.
1641
1642 public void evalExample1(Context ctx)
1643 {
1644 System.out.println("EvalExample1");
1645 Log.append("EvalExample1");
1646
1647 IntExpr x = ctx.mkIntConst("x");
1648 IntExpr y = ctx.mkIntConst("y");
1649 IntNum two = ctx.mkInt(2);
1650
1651 Solver solver = ctx.mkSolver();
1652
1653 /* assert x < y */
1654 solver.add(ctx.mkLt(x, y));
1655
1656 /* assert x > 2 */
1657 solver.add(ctx.mkGt(x, two));
1658
1659 /* find model for the constraints above */
1660 Model model = null;
1661 if (Status.SATISFIABLE == solver.check())
1662 {
1663 model = solver.getModel();
1664 System.out.println(model);
1665 System.out.println("\nevaluating x+y");
1666 Expr<IntSort> v = model.evaluate(ctx.mkAdd(x, y), false);
1667 if (v != null)
1668 {
1669 System.out.printf("result = %s%n", v);
1670 } else
1671 {
1672 System.out.println("Failed to evaluate: x+y");
1673 }
1674 } else
1675 {
1676 System.out.println("BUG, the constraints are satisfiable.");
1677 }
1678 }
1679
1680 // / Demonstrate how to use #Eval on tuples.
1681

Callers 1

mainMethod · 0.95

Calls 11

appendMethod · 0.95
addMethod · 0.95
checkMethod · 0.95
getModelMethod · 0.95
evaluateMethod · 0.95
mkIntConstMethod · 0.80
mkIntMethod · 0.80
mkSolverMethod · 0.80
mkLtMethod · 0.80
mkGtMethod · 0.80
mkAddMethod · 0.80

Tested by

no test coverage detected