Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Data Structures | Public Member Functions | Properties
Solver Class Reference

Solvers. More...

+ Inheritance diagram for Solver:

Data Structures

class  DecRefQueue
 

Public Member Functions

void Push ()
 Creates a backtracking point. More...
 
void Pop (uint n=1)
 Backtracks n backtracking points. More...
 
void Reset ()
 Resets the Solver. More...
 
void Assert (params BoolExpr[] constraints)
 Assert a constraint (or multiple) into the solver. More...
 
void Add (params BoolExpr[] constraints)
 Alias for Assert. More...
 
void AssertAndTrack (BoolExpr[] constraints, BoolExpr[] ps)
 Assert multiple constraints into the solver, and track them (in the unsat) core using the Boolean constants in ps. More...
 
void AssertAndTrack (BoolExpr constraint, BoolExpr p)
 Assert a constraint into the solver, and track it (in the unsat) core using the Boolean constant p. More...
 
Status Check (params Expr[] assumptions)
 Checks whether the assertions in the solver are consistent or not. More...
 
override string ToString ()
 A string representation of the solver. More...
 
- Public Member Functions inherited from Z3Object
void Dispose ()
 Disposes of the underlying native Z3 object. More...
 

Properties

string Help [get]
 A string that describes all available solver parameters. More...
 
Params Parameters [set]
 Sets the solver parameters. More...
 
ParamDescrs ParameterDescriptions [get]
 Retrieves parameter descriptions for solver. More...
 
uint NumScopes [get]
 The current number of backtracking points (scopes). More...
 
uint NumAssertions [get]
 The number of assertions in the solver. More...
 
BoolExpr[] Assertions [get]
 The set of asserted formulas. More...
 
Model Model [get]
 The model of the last Check. More...
 
Expr Proof [get]
 The proof of the last Check. More...
 
Expr[] UnsatCore [get]
 The unsat core of the last Check. More...
 
string ReasonUnknown [get]
 A brief justification of why the last call to Check returned UNKNOWN. More...
 
Statistics Statistics [get]
 Solver statistics. More...
 

Detailed Description

Solvers.

Definition at line 29 of file Solver.cs.

Member Function Documentation

void Add ( params BoolExpr[]  constraints)
inline

Alias for Assert.

Definition at line 123 of file Solver.cs.

124  {
125  Assert(constraints);
126  }
void Assert(params BoolExpr[] constraints)
Assert a constraint (or multiple) into the solver.
Definition: Solver.cs:108
void Assert ( params BoolExpr[]  constraints)
inline

Assert a constraint (or multiple) into the solver.

Definition at line 108 of file Solver.cs.

109  {
110  Contract.Requires(constraints != null);
111  Contract.Requires(Contract.ForAll(constraints, c => c != null));
112 
113  Context.CheckContextMatch(constraints);
114  foreach (BoolExpr a in constraints)
115  {
116  Native.Z3_solver_assert(Context.nCtx, NativeObject, a.NativeObject);
117  }
118  }
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.

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(BoolExpr[],BoolExpr[]) and the Boolean literals provided using Check with assumptions.

Definition at line 139 of file Solver.cs.

140  {
141  Contract.Requires(constraints != null);
142  Contract.Requires(Contract.ForAll(constraints, c => c != null));
143  Contract.Requires(Contract.ForAll(ps, c => c != null));
144  Context.CheckContextMatch(constraints);
145  Context.CheckContextMatch(ps);
146  if (constraints.Length != ps.Length)
147  throw new Z3Exception("Argument size mismatch");
148 
149  for (int i = 0 ; i < constraints.Length; i++)
150  Native.Z3_solver_assert_and_track(Context.nCtx, NativeObject, constraints[i].NativeObject, ps[i].NativeObject);
151  }
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.

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(BoolExpr[],BoolExpr[]) and the Boolean literals provided using Check with assumptions.

Definition at line 164 of file Solver.cs.

165  {
166  Contract.Requires(constraint != null);
167  Contract.Requires(p != null);
168  Context.CheckContextMatch(constraint);
169  Context.CheckContextMatch(p);
170 
171  Native.Z3_solver_assert_and_track(Context.nCtx, NativeObject, constraint.NativeObject, p.NativeObject);
172  }
Status Check ( params Expr[]  assumptions)
inline

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

See also
Model, UnsatCore, Proof

Definition at line 212 of file Solver.cs.

213  {
214  Z3_lbool r;
215  if (assumptions == null || assumptions.Length == 0)
216  r = (Z3_lbool)Native.Z3_solver_check(Context.nCtx, NativeObject);
217  else
218  r = (Z3_lbool)Native.Z3_solver_check_assumptions(Context.nCtx, NativeObject, (uint)assumptions.Length, AST.ArrayToNative(assumptions));
219  switch (r)
220  {
221  case Z3_lbool.Z3_L_TRUE: return Status.SATISFIABLE;
222  case Z3_lbool.Z3_L_FALSE: return Status.UNSATISFIABLE;
223  default: return Status.UNKNOWN;
224  }
225  }
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:135
Status
Status values.
Definition: Status.cs:27
Z3_lbool
Z3_lbool
Definition: Enumerations.cs:10
void Pop ( uint  n = 1)
inline

Backtracks n backtracking points.

Note that an exception is thrown if n is not smaller than NumScopes

See also
Push

Definition at line 91 of file Solver.cs.

92  {
93  Native.Z3_solver_pop(Context.nCtx, NativeObject, n);
94  }
void Push ( )
inline

Creates a backtracking point.

See also
Pop

Definition at line 81 of file Solver.cs.

82  {
83  Native.Z3_solver_push(Context.nCtx, NativeObject);
84  }
void Reset ( )
inline

Resets the Solver.

This removes all assertions from the solver.

Definition at line 100 of file Solver.cs.

101  {
102  Native.Z3_solver_reset(Context.nCtx, NativeObject);
103  }
override string ToString ( )
inline

A string representation of the solver.

Definition at line 317 of file Solver.cs.

318  {
319  return Native.Z3_solver_to_string(Context.nCtx, NativeObject);
320  }

Property Documentation

BoolExpr [] Assertions
get

The set of asserted formulas.

Definition at line 190 of file Solver.cs.

string Help
get

A string that describes all available solver parameters.

Definition at line 35 of file Solver.cs.

Model Model
get

The model of the last Check.

The result is null if Check was not invoked before, if its results was not SATISFIABLE, or if model production is not enabled.

Definition at line 235 of file Solver.cs.

uint NumAssertions
get

The number of assertions in the solver.

Definition at line 178 of file Solver.cs.

uint NumScopes
get

The current number of backtracking points (scopes).

See also
Pop, Push

Definition at line 73 of file Solver.cs.

ParamDescrs ParameterDescriptions
get

Retrieves parameter descriptions for solver.

Definition at line 62 of file Solver.cs.

Params Parameters
set

Sets the solver parameters.

Definition at line 48 of file Solver.cs.

Expr Proof
get

The proof of the last Check.

The result is null if Check was not invoked before, if its results was not UNSATISFIABLE, or if proof production is disabled.

Definition at line 254 of file Solver.cs.

string ReasonUnknown
get

A brief justification of why the last call to Check returned UNKNOWN.

Definition at line 292 of file Solver.cs.

Solver statistics.

Definition at line 305 of file Solver.cs.

Expr [] UnsatCore
get

The unsat core of the last Check.

The unsat core is a subset of Assertions The result is empty if Check was not invoked before, if its results was not UNSATISFIABLE, or if core production is disabled.

Definition at line 274 of file Solver.cs.