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 ()
 
Expr[] 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 207 of file Solver.java.

208  {
209  Z3_lbool r;
210  if (assumptions == null)
211  r = Z3_lbool.fromInt(Native.solverCheck(getContext().nCtx(),
212  getNativeObject()));
213  else
214  r = Z3_lbool.fromInt(Native.solverCheckAssumptions(getContext()
215  .nCtx(), getNativeObject(), (int) assumptions.length, AST
216  .arrayToNative(assumptions)));
217  switch (r)
218  {
219  case Z3_L_TRUE:
220  return Status.SATISFIABLE;
221  case Z3_L_FALSE:
222  return Status.UNSATISFIABLE;
223  default:
224  return Status.UNKNOWN;
225  }
226  }
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:135
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 235 of file Solver.java.

236  {
237  return check((Expr[]) null);
238  }
BoolExpr [] getAssertions ( )
inline

The set of asserted formulas.

Exceptions
Z3Exception

Definition at line 189 of file Solver.java.

190  {
191  ASTVector assrts = new ASTVector(getContext(), Native.solverGetAssertions(
192  getContext().nCtx(), getNativeObject()));
193  int n = assrts.size();
194  BoolExpr[] res = new BoolExpr[n];
195  for (int i = 0; i < n; i++)
196  res[i] = new BoolExpr(getContext(), assrts.get(i).getNativeObject());
197  return res;
198  }
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 249 of file Solver.java.

250  {
251  long x = Native.solverGetModel(getContext().nCtx(), getNativeObject());
252  if (x == 0)
253  return null;
254  else
255  return new Model(getContext(), x);
256  }
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(
180  getContext().nCtx(), getNativeObject()));
181  return assrts.size();
182  }
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 267 of file Solver.java.

268  {
269  long x = Native.solverGetProof(getContext().nCtx(), getNativeObject());
270  if (x == 0)
271  return null;
272  else
273  return Expr.create(getContext(), x);
274  }
String getReasonUnknown ( )
inline

A brief justification of why the last call to

Check

returned

.

Definition at line 301 of file Solver.java.

302  {
303  return Native.solverGetReasonUnknown(getContext().nCtx(),
304  getNativeObject());
305  }
Statistics getStatistics ( )
inline

Solver statistics.

Exceptions
Z3Exception

Definition at line 312 of file Solver.java.

313  {
314  return new Statistics(getContext(), Native.solverGetStatistics(
315  getContext().nCtx(), getNativeObject()));
316  }
Expr [] 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 285 of file Solver.java.

286  {
287 
288  ASTVector core = new ASTVector(getContext(), Native.solverGetUnsatCore(
289  getContext().nCtx(), getNativeObject()));
290  int n = core.size();
291  Expr[] res = new Expr[n];
292  for (int i = 0; i < n; i++)
293  res[i] = Expr.create(getContext(), core.get(i).getNativeObject());
294  return res;
295  }
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 321 of file Solver.java.

322  {
323  try
324  {
325  return Native
326  .solverToString(getContext().nCtx(), getNativeObject());
327  } catch (Z3Exception e)
328  {
329  return "Z3Exception: " + e.getMessage();
330  }
331  }