solver.go

Solver and Model API for SMT solving

Types

type Context

Context methods (receiver omitted for clarity)

Methods:

NewSolver

func (c *Context) NewSolver() *Solver

NewSolver creates a new solver for the given context.

NewSolverForLogic

func (c *Context) NewSolverForLogic(logic string) *Solver

NewSolverForLogic creates a solver for a specific logic.

type FuncInterp

FuncInterp represents a function interpretation in a model.

Methods:

GetArity

func (fi *FuncInterp) GetArity() uint

GetArity returns the arity of the function interpretation.

GetElse

func (fi *FuncInterp) GetElse() *Expr

GetElse returns the else value of the function interpretation.

NumEntries

func (fi *FuncInterp) NumEntries() uint

NumEntries returns the number of entries in the function interpretation.

type Model

Model represents a Z3 model (satisfying assignment).

Methods:

Eval

func (m *Model) Eval(expr *Expr, modelCompletion bool) (*Expr, bool)

Eval evaluates an expression in the model. If modelCompletion is true, Z3 will assign an interpretation for uninterpreted constants.

GetConstDecl

func (m *Model) GetConstDecl(i uint) *FuncDecl

GetConstDecl returns the i-th constant declaration in the model.

GetConstInterp

func (m *Model) GetConstInterp(decl *FuncDecl) *Expr

GetConstInterp returns the interpretation of a constant.

GetFuncDecl

func (m *Model) GetFuncDecl(i uint) *FuncDecl

GetFuncDecl returns the i-th function declaration in the model.

GetFuncInterp

func (m *Model) GetFuncInterp(decl *FuncDecl) *FuncInterp

GetFuncInterp returns the interpretation of a function.

NumConsts

func (m *Model) NumConsts() uint

NumConsts returns the number of constants in the model.

NumFuncs

func (m *Model) NumFuncs() uint

NumFuncs returns the number of function interpretations in the model.

SortUniverse

func (m *Model) SortUniverse(sort *Sort) []*Expr

SortUniverse returns the universe of values for an uninterpreted sort in the model. The universe is represented as a list of distinct expressions. Returns nil if the sort is not an uninterpreted sort in this model.

String

func (m *Model) String() string

String returns the string representation of the model.

type Solver

Solver represents a Z3 solver.

Methods:

Assert

func (s *Solver) Assert(constraint *Expr)

Assert adds a constraint to the solver.

AssertAndTrack

func (s *Solver) AssertAndTrack(constraint, track *Expr)

AssertAndTrack adds a constraint with a tracking literal.

Assertions

func (s *Solver) Assertions() []*Expr

Assertions returns the assertions in the solver.

Check

func (s *Solver) Check() Status

Check checks the satisfiability of the constraints.

CheckAssumptions

func (s *Solver) CheckAssumptions(assumptions ...*Expr) Status

CheckAssumptions checks satisfiability under assumptions.

CongruenceExplain

func (s *Solver) CongruenceExplain(a, b *Expr) *Expr

CongruenceExplain returns an explanation for why two expressions are congruent. The result is an expression that justifies the congruence between a and b. Note: This function works primarily with SimpleSolver. Terms and variables that are eliminated during pre-processing are not visible to the congruence closure.

CongruenceNext

func (s *Solver) CongruenceNext(expr *Expr) *Expr

CongruenceNext returns the next element in the congruence class of the given expression. This allows iteration through all elements in a congruence class. Note: This function works primarily with SimpleSolver. Terms and variables that are eliminated during pre-processing are not visible to the congruence closure.

CongruenceRoot

func (s *Solver) CongruenceRoot(expr *Expr) *Expr

CongruenceRoot returns the congruence class representative of the given expression. This returns the root element in the congruence closure for the term. Note: This function works primarily with SimpleSolver. Terms and variables that are eliminated during pre-processing are not visible to the congruence closure.

FromFile

func (s *Solver) FromFile(filename string)

FromFile parses and asserts SMT-LIB2 formulas from a file. The solver will contain the assertions from the file after this call.

FromString

func (s *Solver) FromString(str string)

FromString parses and asserts SMT-LIB2 formulas from a string. The solver will contain the assertions from the string after this call.

GetHelp

func (s *Solver) GetHelp() string

GetHelp returns a string describing all available solver parameters.

GetParamDescrs

func (s *Solver) GetParamDescrs() *ParamDescrs

GetParamDescrs returns parameter descriptions for the solver.

GetStatistics

func (s *Solver) GetStatistics() *Statistics

GetStatistics returns the statistics for the solver. Statistics include performance metrics, memory usage, and decision statistics.

Interrupt

func (s *Solver) Interrupt()

Interrupt interrupts the solver execution. This is useful for stopping long-running solver operations gracefully.

Model

func (s *Solver) Model() *Model

Model returns the model if the constraints are satisfiable.

NonUnits

func (s *Solver) NonUnits() []*Expr

NonUnits returns the non-unit clauses in the solver's current state. These are clauses that have not been reduced to unit clauses. This is useful for debugging and understanding solver behavior.

NumScopes

func (s *Solver) NumScopes() uint

NumScopes returns the number of backtracking points.

Pop

func (s *Solver) Pop(n uint)

Pop removes backtracking points.

Push

func (s *Solver) Push()

Push creates a backtracking point.

ReasonUnknown

func (s *Solver) ReasonUnknown() string

ReasonUnknown returns the reason why the result is unknown.

Reset

func (s *Solver) Reset()

Reset removes all assertions from the solver.

SetInitialValue

func (s *Solver) SetInitialValue(variable, value *Expr)

SetInitialValue provides an initial value hint for a variable to the solver. This can help guide the solver to find solutions more efficiently. The variable must be a constant or function application, and the value must be compatible with the variable's sort.

SetParams

func (s *Solver) SetParams(params *Params)

SetParams sets solver parameters. Parameters control solver behavior such as timeout, proof generation, etc.

String

func (s *Solver) String() string

String returns the string representation of the solver.

Trail

func (s *Solver) Trail() []*Expr

Trail returns the decision trail of the solver. The trail contains the sequence of literals assigned during search. This is useful for understanding the solver's decision history. Note: This function works primarily with SimpleSolver. For solvers created using tactics (e.g., NewSolver()), it may return an error.

TrailLevels

func (s *Solver) TrailLevels() []uint

TrailLevels returns the decision levels for each literal in the trail. The returned slice has the same length as the trail, where each element indicates the decision level at which the corresponding trail literal was assigned. This is useful for understanding the structure of the search tree. Note: This function works primarily with SimpleSolver. For solvers created using tactics (e.g., NewSolver()), it may return an error.

Units

func (s *Solver) Units() []*Expr

Units returns the unit clauses (literals) learned by the solver. Unit clauses are assertions that have been simplified to single literals. This is useful for debugging and understanding solver behavior.

UnsatCore

func (s *Solver) UnsatCore() []*Expr

UnsatCore returns the unsat core if the constraints are unsatisfiable.