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

Method evalExample1

examples/java/JavaExample.java:1837–1873  ·  view source on GitHub ↗
(Context ctx)

Source from the content-addressed store, hash-verified

1835 // / Demonstrate how to use #Eval.
1836
1837 public void evalExample1(Context ctx)
1838 {
1839 System.out.println("EvalExample1");
1840 Log.append("EvalExample1");
1841
1842 IntExpr x = ctx.mkIntConst("x");
1843 IntExpr y = ctx.mkIntConst("y");
1844 IntExpr two = ctx.mkInt(2);
1845
1846 Solver solver = ctx.mkSolver();
1847
1848 /* assert x < y */
1849 solver.add(ctx.mkLt(x, y));
1850
1851 /* assert x > 2 */
1852 solver.add(ctx.mkGt(x, two));
1853
1854 /* find model for the constraints above */
1855 Model model = null;
1856 if (Status.SATISFIABLE == solver.check())
1857 {
1858 model = solver.getModel();
1859 System.out.println(model);
1860 System.out.println("\nevaluating x+y");
1861 Expr v = model.evaluate(ctx.mkAdd(x, y), false);
1862 if (v != null)
1863 {
1864 System.out.println("result = " + (v));
1865 } else
1866 {
1867 System.out.println("Failed to evaluate: x+y");
1868 }
1869 } else
1870 {
1871 System.out.println("BUG, the constraints are not satisfiable.");
1872 }
1873 }
1874
1875 // / Demonstrate how to use #Eval on tuples.
1876

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