Demonstrate how to use #Eval.
(Context ctx)
| 1737 | /// Demonstrate how to use #Eval. |
| 1738 | /// </summary> |
| 1739 | public static void EvalExample1(Context ctx) |
| 1740 | { |
| 1741 | Console.WriteLine("EvalExample1"); |
| 1742 | |
| 1743 | IntExpr x = ctx.MkIntConst("x"); |
| 1744 | IntExpr y = ctx.MkIntConst("y"); |
| 1745 | IntExpr two = ctx.MkInt(2); |
| 1746 | |
| 1747 | Solver solver = ctx.MkSolver(); |
| 1748 | |
| 1749 | /* assert x < y */ |
| 1750 | solver.Assert(ctx.MkLt(x, y)); |
| 1751 | |
| 1752 | /* assert x > 2 */ |
| 1753 | solver.Assert(ctx.MkGt(x, two)); |
| 1754 | |
| 1755 | /* find model for the constraints above */ |
| 1756 | Model model = null; |
| 1757 | if (Status.SATISFIABLE == solver.Check()) |
| 1758 | { |
| 1759 | model = solver.Model; |
| 1760 | Console.WriteLine("{0}", model); |
| 1761 | Console.WriteLine("\nevaluating x+y"); |
| 1762 | Expr v = model.Evaluate(ctx.MkAdd(x, y)); |
| 1763 | if (v != null) |
| 1764 | { |
| 1765 | Console.WriteLine("result = {0}", (v)); |
| 1766 | } |
| 1767 | else |
| 1768 | { |
| 1769 | Console.WriteLine("Failed to evaluate: x+y"); |
| 1770 | } |
| 1771 | } |
| 1772 | else |
| 1773 | { |
| 1774 | Console.WriteLine("BUG, the constraints are satisfiable."); |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | /// <summary> |
| 1779 | /// Demonstrate how to use #Eval on tuples. |