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

Method findModelExample2

examples/java/JavaGenericExample.java:947–977  ·  view source on GitHub ↗
(Context ctx)

Source from the content-addressed store, hash-verified

945 // / Then, assert <tt>not(x = y)</tt>, and find another model.
946
947 public void findModelExample2(Context ctx) throws TestFailedException
948 {
949 System.out.println("FindModelExample2");
950 Log.append("FindModelExample2");
951
952 IntExpr x = ctx.mkIntConst("x");
953 IntExpr y = ctx.mkIntConst("y");
954 IntNum one = ctx.mkInt(1);
955 IntNum two = ctx.mkInt(2);
956
957 ArithExpr<IntSort> y_plus_one = ctx.mkAdd(y, one);
958
959 BoolExpr c1 = ctx.mkLt(x, y_plus_one);
960 BoolExpr c2 = ctx.mkGt(x, two);
961
962 BoolExpr q = ctx.mkAnd(c1, c2);
963
964 System.out.println("model for: x < y + 1, x > 2");
965 Model model = check(ctx, q, Status.SATISFIABLE);
966 System.out.printf("x = %s, y =%s%n", model.evaluate(x, false), model.evaluate(y, false));
967
968 /* assert not(x = y) */
969 BoolExpr x_eq_y = ctx.mkEq(x, y);
970 BoolExpr c3 = ctx.mkNot(x_eq_y);
971
972 q = ctx.mkAnd(q, c3);
973
974 System.out.println("model for: x < y + 1, x > 2, not(x = y)");
975 model = check(ctx, q, Status.SATISFIABLE);
976 System.out.printf("x = %s, y = %s%n", model.evaluate(x, false), model.evaluate(y, false));
977 }
978
979 // / Prove <tt>x = y implies g(x) = g(y)</tt>, and
980 // / disprove <tt>x = y implies g(g(x)) = g(y)</tt>.

Callers 1

mainMethod · 0.95

Calls 11

appendMethod · 0.95
checkMethod · 0.95
evaluateMethod · 0.95
mkIntConstMethod · 0.80
mkIntMethod · 0.80
mkAddMethod · 0.80
mkLtMethod · 0.80
mkGtMethod · 0.80
mkAndMethod · 0.80
mkEqMethod · 0.80
mkNotMethod · 0.80

Tested by

no test coverage detected