Z3
Public Member Functions
Solver Class Reference
+ Inheritance diagram for Solver:

Public Member Functions

String getHelp ()
 
void setParameters (Params value)
 
ParamDescrs getParameterDescriptions ()
 
int getNumScopes ()
 
void push ()
 
void pop ()
 
void pop (int n)
 
void reset ()
 
void add (BoolExpr...constraints)
 
void assertAndTrack (BoolExpr[] constraints, BoolExpr[] ps)
 
void assertAndTrack (BoolExpr constraint, BoolExpr p)
 
int getNumAssertions ()
 
BoolExpr[] getAssertions ()
 
Status check (Expr...assumptions)
 
Status check ()
 
Model getModel ()
 
Expr getProof ()
 
BoolExpr[] getUnsatCore ()
 
String getReasonUnknown ()
 
Statistics getStatistics ()
 
String toString ()
 
- Public Member Functions inherited from Z3Object
void dispose ()
 
- Public Member Functions inherited from IDisposable
void dispose ()
 

Additional Inherited Members

- Protected Member Functions inherited from Z3Object
void finalize ()
 

Detailed Description

Solvers.

Definition at line 25 of file Solver.java.

Member Function Documentation

void add ( BoolExpr...  constraints)
inline

Assert a multiple constraints into the solver.

Exceptions
Z3Exception

Definition at line 114 of file Solver.java.

115  {
116  getContext().checkContextMatch(constraints);
117  for (BoolExpr a : constraints)
118  {
119  Native.solverAssert(getContext().nCtx(), getNativeObject(),
120  a.getNativeObject());
121  }
122  }
void assertAndTrack ( BoolExpr[]  constraints,
BoolExpr[]  ps 
)
inline

Assert multiple constraints into the solver, and track them (in the unsat) core using the Boolean constants in ps.

Remarks: This API is an alternative to Check with assumptions for extracting unsat cores. Both APIs can be used in the same solver. The unsat core will contain a combination of the Boolean variables provided using AssertAndTrack and the Boolean literals provided using Check with assumptions.

Definition at line 138 of file Solver.java.

139  {
140  getContext().checkContextMatch(constraints);
141  getContext().checkContextMatch(ps);
142  if (constraints.length != ps.length)
143  throw new Z3Exception("Argument size mismatch");
144 
145  for (int i = 0; i < constraints.length; i++)
146  Native.solverAssertAndTrack(getContext().nCtx(), getNativeObject(),
147  constraints[i].getNativeObject(), ps[i].getNativeObject());
148  }
void assertAndTrack ( BoolExpr  constraint,
BoolExpr  p 
)
inline

Assert a constraint into the solver, and track it (in the unsat) core using the Boolean constant p.

Remarks: This API is an alternative to Check with assumptions for extracting unsat cores. Both APIs can be used in the same solver. The unsat core will contain a combination of the Boolean variables provided using AssertAndTrack and the Boolean literals provided using Check with assumptions.

Definition at line 163 of file Solver.java.

164  {
165  getContext().checkContextMatch(constraint);
166  getContext().checkContextMatch(p);
167 
168  Native.solverAssertAndTrack(getContext().nCtx(), getNativeObject(),
169  constraint.getNativeObject(), p.getNativeObject());
170  }
Status check ( Expr...  assumptions)
inline

Checks whether the assertions in the solver are consistent or not. Remarks:

See also
getModel
getUnsatCore
getProof

Definition at line 201 of file Solver.java.

202  {
203  Z3_lbool r;
204  if (assumptions == null)
205  r = Z3_lbool.fromInt(Native.solverCheck(getContext().nCtx(),
206  getNativeObject()));
207  else
208  r = Z3_lbool.fromInt(Native.solverCheckAssumptions(getContext()
209  .nCtx(), getNativeObject(), (int) assumptions.length, AST
210  .arrayToNative(assumptions)));
211  switch (r)
212  {
213  case Z3_L_TRUE:
214  return Status.SATISFIABLE;
215  case Z3_L_FALSE:
216  return Status.UNSATISFIABLE;
217  default:
218  return Status.UNKNOWN;
219  }
220  }
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:143
Status
Status values.
Definition: Status.cs:27
Status check ( )
inline

Checks whether the assertions in the solver are consistent or not. Remarks:

See also
getModel
getUnsatCore
getProof

Definition at line 229 of file Solver.java.

230  {
231  return check((Expr[]) null);
232  }
BoolExpr [] getAssertions ( )
inline

The set of asserted formulas.

Exceptions
Z3Exception

Definition at line 188 of file Solver.java.

189  {
190  ASTVector assrts = new ASTVector(getContext(), Native.solverGetAssertions(getContext().nCtx(), getNativeObject()));
191  return assrts.ToBoolExprArray();
192  }
String getHelp ( )
inline

A string that describes all available solver parameters.

Definition at line 30 of file Solver.java.

31  {
32  return Native.solverGetHelp(getContext().nCtx(), getNativeObject());
33  }
Model getModel ( )
inline

The model of the last

Check

. Remarks: The result is

null

if

Check

was not invoked before, if its results was not

, or if model production is not enabled.

Exceptions
Z3Exception

Definition at line 243 of file Solver.java.

244  {
245  long x = Native.solverGetModel(getContext().nCtx(), getNativeObject());
246  if (x == 0)
247  return null;
248  else
249  return new Model(getContext(), x);
250  }
int getNumAssertions ( )
inline

The number of assertions in the solver.

Exceptions
Z3Exception

Definition at line 177 of file Solver.java.

178  {
179  ASTVector assrts = new ASTVector(getContext(), Native.solverGetAssertions(getContext().nCtx(), getNativeObject()));
180  return assrts.size();
181  }
int getNumScopes ( )
inline

The current number of backtracking points (scopes).

See also
pop
push

Definition at line 63 of file Solver.java.

64  {
65  return Native
66  .solverGetNumScopes(getContext().nCtx(), getNativeObject());
67  }
ParamDescrs getParameterDescriptions ( )
inline

Retrieves parameter descriptions for solver.

Exceptions
Z3Exception

Definition at line 52 of file Solver.java.

53  {
54  return new ParamDescrs(getContext(), Native.solverGetParamDescrs(
55  getContext().nCtx(), getNativeObject()));
56  }
Expr getProof ( )
inline

The proof of the last

Check

. Remarks: The result is

null

if

Check

was not invoked before, if its results was not

, or if proof production is disabled.

Exceptions
Z3Exception

Definition at line 261 of file Solver.java.

262  {
263  long x = Native.solverGetProof(getContext().nCtx(), getNativeObject());
264  if (x == 0)
265  return null;
266  else
267  return Expr.create(getContext(), x);
268  }
String getReasonUnknown ( )
inline

A brief justification of why the last call to

Check

returned

.

Definition at line 290 of file Solver.java.

291  {
292  return Native.solverGetReasonUnknown(getContext().nCtx(),
293  getNativeObject());
294  }
Statistics getStatistics ( )
inline

Solver statistics.

Exceptions
Z3Exception

Definition at line 301 of file Solver.java.

302  {
303  return new Statistics(getContext(), Native.solverGetStatistics(
304  getContext().nCtx(), getNativeObject()));
305  }
BoolExpr [] getUnsatCore ( )
inline

The unsat core of the last

Check

. Remarks: The unsat core is a subset of

Assertions

The result is empty if

Check

was not invoked before, if its results was not

, or if core production is disabled.

Exceptions
Z3Exception

Definition at line 279 of file Solver.java.

280  {
281 
282  ASTVector core = new ASTVector(getContext(), Native.solverGetUnsatCore(getContext().nCtx(), getNativeObject()));
283  return core.ToBoolExprArray();
284  }
void pop ( )
inline

Backtracks one backtracking point. Remarks: .

Definition at line 82 of file Solver.java.

83  {
84  pop(1);
85  }
void pop ( int  n)
inline

Backtracks

n

backtracking points. Remarks: Note that an exception is thrown if

n

is not smaller than

NumScopes
See also
push

Definition at line 94 of file Solver.java.

95  {
96  Native.solverPop(getContext().nCtx(), getNativeObject(), n);
97  }
void push ( )
inline

Creates a backtracking point.

See also
pop

Definition at line 73 of file Solver.java.

74  {
75  Native.solverPush(getContext().nCtx(), getNativeObject());
76  }
void reset ( )
inline

Resets the Solver. Remarks: This removes all assertions from the solver.

Definition at line 104 of file Solver.java.

105  {
106  Native.solverReset(getContext().nCtx(), getNativeObject());
107  }
void setParameters ( Params  value)
inline

Sets the solver parameters.

Exceptions
Z3Exception

Definition at line 40 of file Solver.java.

41  {
42  getContext().checkContextMatch(value);
43  Native.solverSetParams(getContext().nCtx(), getNativeObject(),
44  value.getNativeObject());
45  }
String toString ( )
inline

A string representation of the solver.

Definition at line 310 of file Solver.java.

311  {
312  try
313  {
314  return Native
315  .solverToString(getContext().nCtx(), getNativeObject());
316  } catch (Z3Exception e)
317  {
318  return "Z3Exception: " + e.getMessage();
319  }
320  }