(Context ctx)
| 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. |
no test coverage detected