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

Method quantifierExample1

examples/java/JavaExample.java:597–633  ·  view source on GitHub ↗
(Context ctx)

Source from the content-addressed store, hash-verified

595 // / A basic example of how to use quantifiers.
596
597 void quantifierExample1(Context ctx)
598 {
599 System.out.println("QuantifierExample");
600 Log.append("QuantifierExample");
601
602 IntSort[] types = new IntSort[3];
603 IntExpr[] xs = new IntExpr[3];
604 Symbol[] names = new Symbol[3];
605 IntExpr[] vars = new IntExpr[3];
606
607 for (int j = 0; j < 3; j++)
608 {
609 types[j] = ctx.getIntSort();
610 names[j] = ctx.mkSymbol("x_" + Integer.toString(j));
611 xs[j] = (IntExpr) ctx.mkConst(names[j], types[j]);
612 vars[j] = (IntExpr) ctx.mkBound(2 - j, types[j]); // <-- vars
613 // reversed!
614 }
615
616 Expr body_vars = ctx.mkAnd(
617 ctx.mkEq(ctx.mkAdd(vars[0], ctx.mkInt(1)), ctx.mkInt(2)),
618 ctx.mkEq(ctx.mkAdd(vars[1], ctx.mkInt(2)),
619 ctx.mkAdd(vars[2], ctx.mkInt(3))));
620
621 Expr body_const = ctx.mkAnd(
622 ctx.mkEq(ctx.mkAdd(xs[0], ctx.mkInt(1)), ctx.mkInt(2)),
623 ctx.mkEq(ctx.mkAdd(xs[1], ctx.mkInt(2)),
624 ctx.mkAdd(xs[2], ctx.mkInt(3))));
625
626 Expr x = ctx.mkForall(types, names, body_vars, 1, null, null,
627 ctx.mkSymbol("Q1"), ctx.mkSymbol("skid1"));
628 System.out.println("Quantifier X: " + x.toString());
629
630 Expr y = ctx.mkForall(xs, body_const, 1, null, null,
631 ctx.mkSymbol("Q2"), ctx.mkSymbol("skid2"));
632 System.out.println("Quantifier Y: " + y.toString());
633 }
634
635 void quantifierExample2(Context ctx)
636 {

Callers 1

mainMethod · 0.95

Calls 12

appendMethod · 0.95
toStringMethod · 0.95
getIntSortMethod · 0.80
mkSymbolMethod · 0.80
mkConstMethod · 0.80
mkBoundMethod · 0.80
mkAndMethod · 0.80
mkEqMethod · 0.80
mkAddMethod · 0.80
mkIntMethod · 0.80
mkForallMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected