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

Method injAxiomAbs

examples/java/JavaGenericExample.java:101–139  ·  view source on GitHub ↗
(Context ctx, FuncDecl<R> f, int i)

Source from the content-addressed store, hash-verified

99 // / Where, <code>finv</code>is a fresh function declaration.
100
101 public <R extends Sort> BoolExpr injAxiomAbs(Context ctx, FuncDecl<R> f, int i)
102 {
103 Sort[] domain = f.getDomain();
104 int sz = f.getDomainSize();
105
106 if (i >= sz)
107 {
108 System.out.println("failed to create inj axiom");
109 return null;
110 }
111
112 /* declare the i-th inverse of f: finv */
113 R finv_domain = f.getRange();
114 Sort finv_range = domain[i];
115 FuncDecl<Sort> finv = ctx.mkFuncDecl("f_fresh", finv_domain, finv_range);
116
117 /* allocate temporary arrays */
118 List<Expr<Sort>> xs = IntStream.range(0, sz).mapToObj(j -> ctx.mkConst(String.format("x_%d", j), domain[j])).collect(Collectors.toList());
119
120 /* fill types, names and xs */
121 Expr<Sort> x_i = xs.get(i);
122
123 /* create f(x_0, ..., x_i, ..., x_{n-1}) */
124 Expr<R> fxs = f.apply(xs.toArray(new Expr[0]));
125
126 /* create f_inv(f(x_0, ..., x_i, ..., x_{n-1})) */
127 Expr<Sort> finv_fxs = finv.apply(fxs);
128
129 /* create finv(f(x_0, ..., x_i, ..., x_{n-1})) = x_i */
130 BoolExpr eq = ctx.mkEq(finv_fxs, x_i);
131
132 /* use f(x_0, ..., x_i, ..., x_{n-1}) as the pattern for the quantifier */
133 Pattern p = ctx.mkPattern(fxs);
134
135 /* create & assert quantifier */
136 return ctx.mkForall(xs.toArray(new Expr[0]), /* types of quantified variables */
137 eq, /* names of quantified variables */
138 1, new Pattern[] { p } /* patterns */, null, null, null);
139 }
140
141 // / Assert the axiom: function f is commutative.
142

Callers 1

quantifierExample4Method · 0.95

Calls 12

getDomainSizeMethod · 0.80
mkFuncDeclMethod · 0.80
mkConstMethod · 0.80
mkEqMethod · 0.80
mkPatternMethod · 0.80
mkForallMethod · 0.80
rangeMethod · 0.65
getMethod · 0.65
applyMethod · 0.65
getDomainMethod · 0.45
getRangeMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected