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

Method arrayExample2

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

Source from the content-addressed store, hash-verified

401 // / <remarks>This example demonstrates how to use the array
402 // theory.</remarks>
403 public void arrayExample2(Context ctx) throws TestFailedException
404 {
405 System.out.println("ArrayExample2");
406 Log.append("ArrayExample2");
407
408 Sort int_type = ctx.getIntSort();
409 Sort array_type = ctx.mkArraySort(int_type, int_type);
410
411 ArrayExpr a1 = (ArrayExpr) ctx.mkConst("a1", array_type);
412 ArrayExpr a2 = ctx.mkArrayConst("a2", int_type, int_type);
413 Expr i1 = ctx.mkConst("i1", int_type);
414 Expr i2 = ctx.mkConst("i2", int_type);
415 Expr i3 = ctx.mkConst("i3", int_type);
416 Expr v1 = ctx.mkConst("v1", int_type);
417 Expr v2 = ctx.mkConst("v2", int_type);
418
419 Expr st1 = ctx.mkStore(a1, i1, v1);
420 Expr st2 = ctx.mkStore(a2, i2, v2);
421
422 Expr sel1 = ctx.mkSelect(a1, i3);
423 Expr sel2 = ctx.mkSelect(a2, i3);
424
425 /* create antecedent */
426 BoolExpr antecedent = ctx.mkEq(st1, st2);
427
428 /*
429 * create consequent: i1 = i3 or i2 = i3 or select(a1, i3) = select(a2,
430 * i3)
431 */
432 BoolExpr consequent = ctx.mkOr(ctx.mkEq(i1, i3), ctx.mkEq(i2, i3),
433 ctx.mkEq(sel1, sel2));
434
435 /*
436 * prove store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 =
437 * i3 or select(a1, i3) = select(a2, i3))
438 */
439 BoolExpr thm = ctx.mkImplies(antecedent, consequent);
440 System.out
441 .println("prove: store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))");
442 System.out.println(thm);
443 prove(ctx, thm, false);
444 }
445
446 // / Show that <code>distinct(a_0, ... , a_n)</code> is
447 // / 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