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

Method arrayExample1

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

Source from the content-addressed store, hash-verified

351 // / A simple array example.
352
353 void arrayExample1(Context ctx) throws TestFailedException
354 {
355 System.out.println("ArrayExample1");
356 Log.append("ArrayExample1");
357
358 Goal g = ctx.mkGoal(true, false, false);
359 ArraySort asort = ctx.mkArraySort(ctx.getIntSort(),
360 ctx.mkBitVecSort(32));
361 ArrayExpr aex = (ArrayExpr) ctx.mkConst(ctx.mkSymbol("MyArray"), asort);
362 Expr sel = ctx.mkSelect(aex, ctx.mkInt(0));
363 g.add(ctx.mkEq(sel, ctx.mkBV(42, 32)));
364 Symbol xs = ctx.mkSymbol("x");
365 IntExpr xc = (IntExpr) ctx.mkConst(xs, ctx.getIntSort());
366
367 Symbol fname = ctx.mkSymbol("f");
368 Sort[] domain = { ctx.getIntSort() };
369 FuncDecl fd = ctx.mkFuncDecl(fname, domain, ctx.getIntSort());
370 Expr[] fargs = { ctx.mkConst(xs, ctx.getIntSort()) };
371 IntExpr fapp = (IntExpr) ctx.mkApp(fd, fargs);
372
373 g.add(ctx.mkEq(ctx.mkAdd(xc, fapp), ctx.mkInt(123)));
374
375 Solver s = ctx.mkSolver();
376 for (BoolExpr a : g.getFormulas())
377 s.add(a);
378 System.out.println("Solver: " + s);
379
380 Status q = s.check();
381 System.out.println("Status: " + q);
382
383 if (q != Status.SATISFIABLE)
384 throw new TestFailedException();
385
386 System.out.println("Model = " + s.getModel());
387
388 System.out.println("Interpretation of MyArray:\n"
389 + s.getModel().getFuncInterp(aex.getFuncDecl()));
390 System.out.println("Interpretation of x:\n"
391 + s.getModel().getConstInterp(xc));
392 System.out.println("Interpretation of f:\n"
393 + s.getModel().getFuncInterp(fd));
394 System.out.println("Interpretation of MyArray as Term:\n"
395 + s.getModel().getFuncInterp(aex.getFuncDecl()));
396 }
397
398 // / Prove <tt>store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2
399 // = 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