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

Method arrayExample2

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

Source from the content-addressed store, hash-verified

383 // / <remarks>This example demonstrates how to use the array
384 // theory.</remarks>
385 public void arrayExample2(Context ctx) throws TestFailedException
386 {
387 System.out.println("ArrayExample2");
388 Log.append("ArrayExample2");
389
390 IntSort int_type = ctx.getIntSort();
391 ArraySort<IntSort, IntSort> array_type = ctx.mkArraySort(int_type, int_type);
392
393 Expr<ArraySort<IntSort, IntSort>> a1 = ctx.mkConst("a1", array_type);
394 ArrayExpr<IntSort, IntSort> a2 = ctx.mkArrayConst("a2", int_type, int_type);
395 Expr<IntSort> i1 = ctx.mkConst("i1", int_type);
396 Expr<IntSort> i2 = ctx.mkConst("i2", int_type);
397 Expr<IntSort> i3 = ctx.mkConst("i3", int_type);
398 Expr<IntSort> v1 = ctx.mkConst("v1", int_type);
399 Expr<IntSort> v2 = ctx.mkConst("v2", int_type);
400
401 ArrayExpr<IntSort, IntSort> st1 = ctx.mkStore(a1, i1, v1);
402 ArrayExpr<IntSort, IntSort> st2 = ctx.mkStore(a2, i2, v2);
403
404 Expr<IntSort> sel1 = ctx.mkSelect(a1, i3);
405 Expr<IntSort> sel2 = ctx.mkSelect(a2, i3);
406
407 /* create antecedent */
408 BoolExpr antecedent = ctx.mkEq(st1, st2);
409
410 /*
411 * create consequent: i1 = i3 or i2 = i3 or select(a1, i3) = select(a2,
412 * i3)
413 */
414 BoolExpr consequent = ctx.mkOr(ctx.mkEq(i1, i3), ctx.mkEq(i2, i3), ctx.mkEq(sel1, sel2));
415
416 /*
417 * prove store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 =
418 * i3 or select(a1, i3) = select(a2, i3))
419 */
420 BoolExpr thm = ctx.mkImplies(antecedent, consequent);
421 System.out.println("prove: store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))");
422 System.out.println(thm);
423 prove(ctx, thm, false);
424 }
425
426 // / Show that <code>distinct(a_0, ... , a_n)</code> is
427 // / unsatisfiable when <code>a_i</code>'s are arrays from boolean to

Callers 1

mainMethod · 0.95

Calls 11

appendMethod · 0.95
proveMethod · 0.95
getIntSortMethod · 0.80
mkArraySortMethod · 0.80
mkConstMethod · 0.80
mkArrayConstMethod · 0.80
mkStoreMethod · 0.80
mkSelectMethod · 0.80
mkEqMethod · 0.80
mkOrMethod · 0.80
mkImpliesMethod · 0.80

Tested by

no test coverage detected