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

Method arrayExample3

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

Source from the content-addressed store, hash-verified

450 // / <remarks>This example also shows how to use the <code>distinct</code>
451 // construct.</remarks>
452 public void arrayExample3(Context ctx) throws TestFailedException
453 {
454 System.out.println("ArrayExample3");
455 Log.append("ArrayExample2");
456
457 for (int n = 2; n <= 5; n++)
458 {
459 System.out.println("n = " + Integer.toString(n));
460
461 Sort bool_type = ctx.mkBoolSort();
462 Sort array_type = ctx.mkArraySort(bool_type, bool_type);
463 Expr[] a = new Expr[n];
464
465 /* create arrays */
466 for (int i = 0; i < n; i++)
467 {
468 a[i] = ctx.mkConst("array_" + Integer.toString(i), array_type);
469 }
470
471 /* assert distinct(a[0], ..., a[n]) */
472 BoolExpr d = ctx.mkDistinct(a);
473 System.out.println(d);
474
475 /* context is satisfiable if n < 5 */
476 Model model = check(ctx, d, n < 5 ? Status.SATISFIABLE
477 : Status.UNSATISFIABLE);
478 if (n < 5)
479 {
480 for (int i = 0; i < n; i++)
481 {
482 System.out.println(a[i].toString() + " = "
483 + model.evaluate(a[i], false));
484 }
485 }
486 }
487 }
488
489 // / Sudoku solving example.
490

Callers 1

mainMethod · 0.95

Calls 8

appendMethod · 0.95
checkMethod · 0.95
evaluateMethod · 0.95
mkBoolSortMethod · 0.80
mkArraySortMethod · 0.80
mkConstMethod · 0.80
mkDistinctMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected