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

Method evalExample2

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

Source from the content-addressed store, hash-verified

1875 // / Demonstrate how to use #Eval on tuples.
1876
1877 public void evalExample2(Context ctx)
1878 {
1879 System.out.println("EvalExample2");
1880 Log.append("EvalExample2");
1881
1882 Sort int_type = ctx.getIntSort();
1883 TupleSort tuple = ctx.mkTupleSort(ctx.mkSymbol("mk_tuple"), // name of
1884 // tuple
1885 // constructor
1886 new Symbol[] { ctx.mkSymbol("first"), ctx.mkSymbol("second") }, // names
1887 // of
1888 // projection
1889 // operators
1890 new Sort[] { int_type, int_type } // types of projection
1891 // operators
1892 );
1893 FuncDecl first = tuple.getFieldDecls()[0]; // declarations are for
1894 // projections
1895 FuncDecl second = tuple.getFieldDecls()[1];
1896 Expr tup1 = ctx.mkConst("t1", tuple);
1897 Expr tup2 = ctx.mkConst("t2", tuple);
1898
1899 Solver solver = ctx.mkSolver();
1900
1901 /* assert tup1 != tup2 */
1902 solver.add(ctx.mkNot(ctx.mkEq(tup1, tup2)));
1903 /* assert first tup1 = first tup2 */
1904 solver.add(ctx.mkEq(ctx.mkApp(first, tup1), ctx.mkApp(first, tup2)));
1905
1906 /* find model for the constraints above */
1907 Model model = null;
1908 if (Status.SATISFIABLE == solver.check())
1909 {
1910 model = solver.getModel();
1911 System.out.println(model);
1912 System.out.println("evaluating tup1 "
1913 + (model.evaluate(tup1, false)));
1914 System.out.println("evaluating tup2 "
1915 + (model.evaluate(tup2, false)));
1916 System.out.println("evaluating second(tup2) "
1917 + (model.evaluate(ctx.mkApp(second, tup2), false)));
1918 } else
1919 {
1920 System.out.println("BUG, the constraints are satisfiable.");
1921 }
1922 }
1923
1924 // / Demonstrate how to use <code>Push</code>and <code>Pop</code>to
1925 // / control the size of models.

Callers 1

mainMethod · 0.95

Calls 14

appendMethod · 0.95
getFieldDeclsMethod · 0.95
addMethod · 0.95
checkMethod · 0.95
getModelMethod · 0.95
evaluateMethod · 0.95
getIntSortMethod · 0.80
mkTupleSortMethod · 0.80
mkSymbolMethod · 0.80
mkConstMethod · 0.80
mkSolverMethod · 0.80
mkNotMethod · 0.80

Tested by

no test coverage detected