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

Method quantifierExample2

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

Source from the content-addressed store, hash-verified

633 }
634
635 void quantifierExample2(Context ctx)
636 {
637
638 System.out.println("QuantifierExample2");
639 Log.append("QuantifierExample2");
640
641 Expr q1, q2;
642 FuncDecl f = ctx.mkFuncDecl("f", ctx.getIntSort(), ctx.getIntSort());
643 FuncDecl g = ctx.mkFuncDecl("g", ctx.getIntSort(), ctx.getIntSort());
644
645 // Quantifier with Exprs as the bound variables.
646 {
647 Expr x = ctx.mkConst("x", ctx.getIntSort());
648 Expr y = ctx.mkConst("y", ctx.getIntSort());
649 Expr f_x = ctx.mkApp(f, x);
650 Expr f_y = ctx.mkApp(f, y);
651 Expr g_y = ctx.mkApp(g, y);
652 @SuppressWarnings("unused")
653 Pattern[] pats = new Pattern[] { ctx.mkPattern(f_x, g_y) };
654 Expr[] no_pats = new Expr[] { f_y };
655 Expr[] bound = new Expr[] { x, y };
656 Expr body = ctx.mkAnd(ctx.mkEq(f_x, f_y), ctx.mkEq(f_y, g_y));
657
658 q1 = ctx.mkForall(bound, body, 1, null, no_pats, ctx.mkSymbol("q"),
659 ctx.mkSymbol("sk"));
660
661 System.out.println(q1);
662 }
663
664 // Quantifier with de-Bruijn indices.
665 {
666 Expr x = ctx.mkBound(1, ctx.getIntSort());
667 Expr y = ctx.mkBound(0, ctx.getIntSort());
668 Expr f_x = ctx.mkApp(f, x);
669 Expr f_y = ctx.mkApp(f, y);
670 Expr g_y = ctx.mkApp(g, y);
671 @SuppressWarnings("unused")
672 Pattern[] pats = new Pattern[] { ctx.mkPattern(f_x, g_y) };
673 Expr[] no_pats = new Expr[] { f_y };
674 Symbol[] names = new Symbol[] { ctx.mkSymbol("x"),
675 ctx.mkSymbol("y") };
676 Sort[] sorts = new Sort[] { ctx.getIntSort(), ctx.getIntSort() };
677 Expr body = ctx.mkAnd(ctx.mkEq(f_x, f_y), ctx.mkEq(f_y, g_y));
678
679 q2 = ctx.mkForall(sorts, names, body, 1, null, // pats,
680 no_pats, ctx.mkSymbol("q"), ctx.mkSymbol("sk"));
681 System.out.println(q2);
682 }
683
684 System.out.println(q1.equals(q2));
685 }
686
687 // / Prove that <tt>f(x, y) = f(w, v) implies y = v</tt> when
688 // / <code>f</code> is injective in the second argument. <seealso

Callers 1

mainMethod · 0.95

Calls 12

appendMethod · 0.95
mkFuncDeclMethod · 0.80
getIntSortMethod · 0.80
mkConstMethod · 0.80
mkAppMethod · 0.80
mkPatternMethod · 0.80
mkAndMethod · 0.80
mkEqMethod · 0.80
mkForallMethod · 0.80
mkSymbolMethod · 0.80
mkBoundMethod · 0.80
equalsMethod · 0.45

Tested by

no test coverage detected