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

Method arrayExample1

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

Source from the content-addressed store, hash-verified

336 // / A simple array example.
337
338 @SuppressWarnings("unchecked")
339 void arrayExample1(Context ctx) throws TestFailedException
340 {
341 System.out.println("ArrayExample1");
342 Log.append("ArrayExample1");
343
344 Goal g = ctx.mkGoal(true, false, false);
345 ArraySort<IntSort, BitVecSort> asort = ctx.mkArraySort(ctx.getIntSort(),
346 ctx.mkBitVecSort(32));
347 Expr<ArraySort<IntSort, BitVecSort>> aex = ctx.mkConst(ctx.mkSymbol("MyArray"), asort);
348 Expr<BitVecSort> sel = ctx.mkSelect(aex, ctx.mkInt(0));
349 g.add(ctx.mkEq(sel, ctx.mkBV(42, 32)));
350 Symbol xs = ctx.mkSymbol("x");
351 IntExpr xc = (IntExpr) ctx.mkConst(xs, ctx.getIntSort());
352
353 Symbol fname = ctx.mkSymbol("f");
354 Sort[] domain = { ctx.getIntSort() };
355 FuncDecl<IntSort> fd = ctx.mkFuncDecl(fname, domain, ctx.getIntSort());
356 Expr<?>[] fargs = { ctx.mkConst(xs, ctx.getIntSort()) };
357 Expr<IntSort> fapp = ctx.mkApp(fd, fargs);
358
359 g.add(ctx.mkEq(ctx.mkAdd(xc, fapp), ctx.mkInt(123)));
360
361 Solver s = ctx.mkSolver();
362 for (BoolExpr a : g.getFormulas())
363 s.add(a);
364 System.out.printf("Solver: %s%n", s);
365
366 Status q = s.check();
367 System.out.printf("Status: %s%n", q);
368
369 if (q != Status.SATISFIABLE)
370 throw new TestFailedException();
371
372 System.out.printf("Model = %s%n", s.getModel());
373
374 System.out.printf("Interpretation of MyArray:%n%s%n", s.getModel().getFuncInterp(aex.getFuncDecl()));
375 System.out.printf("Interpretation of x:%n%s%n", s.getModel().getConstInterp(xc));
376 System.out.printf("Interpretation of f:%n%s%n", s.getModel().getFuncInterp(fd));
377 System.out.printf("Interpretation of MyArray as Term:%n%s%n", s.getModel().getFuncInterp(aex.getFuncDecl()));
378 }
379
380 // / Prove <tt>store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2
381 // = i3 or select(a1, i3) = select(a2, i3))</tt>.

Callers 1

mainMethod · 0.95

Calls 15

appendMethod · 0.95
addMethod · 0.95
getFormulasMethod · 0.95
addMethod · 0.95
checkMethod · 0.95
getModelMethod · 0.95
mkGoalMethod · 0.80
mkArraySortMethod · 0.80
getIntSortMethod · 0.80
mkBitVecSortMethod · 0.80
mkConstMethod · 0.80
mkSymbolMethod · 0.80

Tested by

no test coverage detected