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

Method ArrayExample1

examples/dotnet/Program.cs:333–370  ·  view source on GitHub ↗

A simple array example.

(Context ctx)

Source from the content-addressed store, hash-verified

331 /// </summary>
332 /// <param name="ctx"></param>
333 static void ArrayExample1(Context ctx)
334 {
335 Console.WriteLine("ArrayExample1");
336
337 Goal g = ctx.MkGoal(true);
338 ArraySort asort = ctx.MkArraySort(ctx.IntSort, ctx.MkBitVecSort(32));
339 ArrayExpr aex = (ArrayExpr)ctx.MkConst(ctx.MkSymbol("MyArray"), asort);
340 Expr sel = ctx.MkSelect(aex, ctx.MkInt(0));
341 g.Assert(ctx.MkEq(sel, ctx.MkBV(42, 32)));
342 Symbol xs = ctx.MkSymbol("x");
343 IntExpr xc = (IntExpr)ctx.MkConst(xs, ctx.IntSort);
344
345 Symbol fname = ctx.MkSymbol("f");
346 Sort[] domain = { ctx.IntSort };
347 FuncDecl fd = ctx.MkFuncDecl(fname, domain, ctx.IntSort);
348 Expr[] fargs = { ctx.MkConst(xs, ctx.IntSort) };
349 IntExpr fapp = (IntExpr)ctx.MkApp(fd, fargs);
350
351 g.Assert(ctx.MkEq(ctx.MkAdd(xc, fapp), ctx.MkInt(123)));
352
353 Solver s = ctx.MkSolver();
354 foreach (BoolExpr a in g.Formulas)
355 s.Assert(a);
356 Console.WriteLine("Solver: " + s);
357
358 Status q = s.Check();
359 Console.WriteLine("Status: " + q);
360
361 if (q != Status.SATISFIABLE)
362 throw new TestFailedException();
363
364 Console.WriteLine("Model = " + s.Model);
365
366 Console.WriteLine("Interpretation of MyArray:\n" + s.Model.ConstInterp(aex.FuncDecl));
367 Console.WriteLine("Interpretation of x:\n" + s.Model.ConstInterp(xc));
368 Console.WriteLine("Interpretation of f:\n" + s.Model.FuncInterp(fd));
369 Console.WriteLine("Interpretation of MyArray as Term:\n" + s.Model.ConstInterp(aex.FuncDecl));
370 }
371
372 /// <summary>
373 /// Prove <tt>store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))</tt>.

Callers

nothing calls this directly

Calls 15

MkBitVecSortMethod · 0.80
MkSymbolMethod · 0.80
MkSolverMethod · 0.80
MkGoalMethod · 0.45
MkArraySortMethod · 0.45
MkConstMethod · 0.45
MkSelectMethod · 0.45
MkIntMethod · 0.45
AssertMethod · 0.45
MkEqMethod · 0.45
MkBVMethod · 0.45
MkFuncDeclMethod · 0.45

Tested by

no test coverage detected