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

Method arrayExample3

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

Source from the content-addressed store, hash-verified

430 // / <remarks>This example also shows how to use the <code>distinct</code>
431 // construct.</remarks>
432 @SuppressWarnings("unchecked")
433 public void arrayExample3(Context ctx) throws TestFailedException
434 {
435 System.out.println("ArrayExample3");
436 Log.append("ArrayExample2");
437
438 for (int n = 2; n <= 5; n++)
439 {
440 System.out.printf("n = %d%n", n);
441
442 BoolSort bool_type = ctx.mkBoolSort();
443 ArraySort<BoolSort, BoolSort> array_type = ctx.mkArraySort(bool_type, bool_type);
444 List<Expr<ArraySort<BoolSort, BoolSort>>> a = IntStream.range(0, n).mapToObj(i -> ctx.mkConst(String.format("array_%d", i), array_type)).collect(Collectors.toList());
445
446 /* create arrays */
447
448 /* assert distinct(a[0], ..., a[n]) */
449 BoolExpr d = ctx.mkDistinct(a.toArray(new Expr[0]));
450 System.out.println(d);
451
452 /* context is satisfiable if n < 5 */
453 Model model = check(ctx, d, n < 5 ? Status.SATISFIABLE : Status.UNSATISFIABLE);
454 if (n < 5)
455 {
456 for (int i = 0; i < n; i++)
457 {
458 System.out.printf("%s = %s%n", a.get(i), model.evaluate(a.get(i), false));
459 }
460 }
461 }
462 }
463
464 // / Sudoku solving example.
465

Callers 1

mainMethod · 0.95

Calls 10

appendMethod · 0.95
checkMethod · 0.95
evaluateMethod · 0.95
mkBoolSortMethod · 0.80
mkArraySortMethod · 0.80
mkConstMethod · 0.80
mkDistinctMethod · 0.80
rangeMethod · 0.65
getMethod · 0.65
collectMethod · 0.45

Tested by

no test coverage detected