Demonstrate how to use #Eval on tuples.
(Context ctx)
| 1779 | /// Demonstrate how to use #Eval on tuples. |
| 1780 | /// </summary> |
| 1781 | public static void EvalExample2(Context ctx) |
| 1782 | { |
| 1783 | Console.WriteLine("EvalExample2"); |
| 1784 | |
| 1785 | Sort int_type = ctx.IntSort; |
| 1786 | TupleSort tuple = ctx.MkTupleSort( |
| 1787 | ctx.MkSymbol("mk_tuple"), // name of tuple constructor |
| 1788 | new Symbol[] { ctx.MkSymbol("first"), ctx.MkSymbol("second") }, // names of projection operators |
| 1789 | new Sort[] { int_type, int_type } // types of projection operators |
| 1790 | ); |
| 1791 | FuncDecl first = tuple.FieldDecls[0]; // declarations are for projections |
| 1792 | FuncDecl second = tuple.FieldDecls[1]; |
| 1793 | Expr tup1 = ctx.MkConst("t1", tuple); |
| 1794 | Expr tup2 = ctx.MkConst("t2", tuple); |
| 1795 | |
| 1796 | Solver solver = ctx.MkSolver(); |
| 1797 | |
| 1798 | /* assert tup1 != tup2 */ |
| 1799 | solver.Assert(ctx.MkNot(ctx.MkEq(tup1, tup2))); |
| 1800 | /* assert first tup1 = first tup2 */ |
| 1801 | solver.Assert(ctx.MkEq(ctx.MkApp(first, tup1), ctx.MkApp(first, tup2))); |
| 1802 | |
| 1803 | /* find model for the constraints above */ |
| 1804 | Model model = null; |
| 1805 | if (Status.SATISFIABLE == solver.Check()) |
| 1806 | { |
| 1807 | model = solver.Model; |
| 1808 | Console.WriteLine("{0}", model); |
| 1809 | Console.WriteLine("evaluating tup1 {0}", (model.Evaluate(tup1))); |
| 1810 | Console.WriteLine("evaluating tup2 {0}", (model.Evaluate(tup2))); |
| 1811 | Console.WriteLine("evaluating second(tup2) {0}", |
| 1812 | (model.Evaluate(ctx.MkApp(second, tup2)))); |
| 1813 | } |
| 1814 | else |
| 1815 | { |
| 1816 | Console.WriteLine("BUG, the constraints are satisfiable."); |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | /// <summary> |
| 1821 | /// Demonstrate how to use <code>Push</code>and <code>Pop</code>to |