(Context ctx)
| 1680 | // / Demonstrate how to use #Eval on tuples. |
| 1681 | |
| 1682 | @SuppressWarnings("unchecked") |
| 1683 | public void evalExample2(Context ctx) |
| 1684 | { |
| 1685 | System.out.println("EvalExample2"); |
| 1686 | Log.append("EvalExample2"); |
| 1687 | |
| 1688 | IntSort int_type = ctx.getIntSort(); |
| 1689 | TupleSort tuple = ctx.mkTupleSort(ctx.mkSymbol("mk_tuple"), // name of |
| 1690 | // tuple |
| 1691 | // constructor |
| 1692 | new Symbol[] { ctx.mkSymbol("first"), ctx.mkSymbol("second") }, // names |
| 1693 | // of |
| 1694 | // projection |
| 1695 | // operators |
| 1696 | new Sort[] { int_type, int_type } // types of projection |
| 1697 | // operators |
| 1698 | ); |
| 1699 | FuncDecl<IntSort> first = (FuncDecl<IntSort>) tuple.getFieldDecls()[0]; // declarations are for |
| 1700 | // projections |
| 1701 | FuncDecl<IntSort> second = (FuncDecl<IntSort>) tuple.getFieldDecls()[1]; |
| 1702 | Expr<TupleSort> tup1 = ctx.mkConst("t1", tuple); |
| 1703 | Expr<TupleSort> tup2 = ctx.mkConst("t2", tuple); |
| 1704 | |
| 1705 | Solver solver = ctx.mkSolver(); |
| 1706 | |
| 1707 | /* assert tup1 != tup2 */ |
| 1708 | solver.add(ctx.mkNot(ctx.mkEq(tup1, tup2))); |
| 1709 | /* assert first tup1 = first tup2 */ |
| 1710 | solver.add(ctx.mkEq(ctx.mkApp(first, tup1), ctx.mkApp(first, tup2))); |
| 1711 | |
| 1712 | /* find model for the constraints above */ |
| 1713 | Model model = null; |
| 1714 | if (Status.SATISFIABLE == solver.check()) |
| 1715 | { |
| 1716 | model = solver.getModel(); |
| 1717 | System.out.println(model); |
| 1718 | System.out.printf("evaluating tup1 %s%n", model.evaluate(tup1, false)); |
| 1719 | System.out.printf("evaluating tup2 %s%n", model.evaluate(tup2, false)); |
| 1720 | System.out.printf("evaluating second(tup2) %s%n", model.evaluate(ctx.mkApp(second, tup2), false)); |
| 1721 | } else |
| 1722 | { |
| 1723 | System.out.println("BUG, the constraints are satisfiable."); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | // / Demonstrate how to use <code>Push</code>and <code>Pop</code>to |
| 1728 | // / control the size of models. |
no test coverage detected