Package org.smtlib.solvers
Class Solver_z3_4_3
java.lang.Object
org.smtlib.AbstractSolver
org.smtlib.solvers.Solver_z3_4_3
- All Implemented Interfaces:
ISolver
- Direct Known Subclasses:
Solver_z3_4_3_2
This class is an adapter that takes the SMT-LIB ASTs and translates them into Z3 commands
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.smtlib.AbstractSolver
AbstractSolver.Pending, AbstractSolver.Shape, AbstractSolver.StackChangeNested classes/interfaces inherited from interface org.smtlib.ISolver
ISolver.CreationException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String[]The command-line arguments for launching the Z3 solverprotected String[]protected String[]protected String[]protected booleanSet to true once a set-logic command has been executed.protected ParserThe parser that parses responses from the solverFields inherited from class org.smtlib.AbstractSolver
checkSatStatus, END_WAIT_MILLIS, endedByTimeLimit, isMac, isWindows, linesOffset, options, printSuccess, printSuccessResponse, smtConfig, SOLVER_EXITED, solverProcess -
Constructor Summary
ConstructorsConstructorDescriptionSolver_z3_4_3(SMT.Configuration smtConfig, String executable) Creates an instance of the Z3 solverSolver_z3_4_3(SMT.Configuration smtConfig, String[] command) Creates an instance of the Z3 solver -
Method Summary
Modifier and TypeMethodDescriptionassertExpr(IExpr sexpr) Adds the given expression to the current assertion-stack frame.Checks whether the current assertion set is satisfiable under the current logic.check_sat_assuming(IExpr... exprs) z3 4.3 answers unsupported for check-sat-assuming, so it is sent as z3's legacy (check-sat a1 ...Declares a new uninterpreted constant; returns success or an SMT error responseDeclares a new uninterpreted function (or constant); returns success or an SMT error responseDeclares a new uninterpreted sort; returns success or an SMT error responseDefines a named function or constant; returns success or an SMT error responseDefines a sort abbreviation; returns success or an SMT error responseecho(IExpr.IStringLiteral arg) z3 4.3 writes echo's text unquoted, so where it ends cannot be found (#136); the response to echo is its argumentexit()Terminates the solver; no further commands are permitted.voidTerminates the solver forcibly without sending commands (e.g.Not a correction: this adapter sends commands by its own means (z3 4.3 itself reports get-assertions without :produce-assertions, which set_option_impl sends as :interactive-mode)z3 4.3 answers get-assignment (with ()) when :produce-assignments is not enabled, which SMT-LIB makes an errorget_info(IExpr.IKeyword key) Not a correction: this adapter sends commands by its own means, so it scrubs run-dependent values for testing itself, as AbstractSolver.get_info doesThe :produce-models check corrects z3 4.3 answering get-model with that option at its (non-standard) default of true; z3 4.3 itself reports get-model when no model is availableget_option(IExpr.IKeyword key) Sent to the solver, except where z3 4.3's answer does not conform: it defaults :produce-models to true (SMT-LIB: false), writes the channel names unquoted, knows :produce-assertions only as :interactive-mode (see set_option_impl), and answers unsupported, not the default value, for a standard option it lacksz3 4.3 itself reports get-proof without :produce-proofs or when no proof is available; the checks here only give the same messages as the other adaptersz3 4.3 itself reports get-unsat-core without :produce-unsat-cores or when no core is available; the checks here only give the same messages as the other adaptersSee get_model: z3 4.3 defaults :produce-models to trueprotected booleanisTimeLimitResponse(String rawResponse) z3 answers 'timeout' (instead of a result) when its whole-run limit, -T, ends it, and then exitsPatterns matching the line numbers in this solver's messages about the command answered: group 1 is the text before the number, group 2 the number, group 3 the text after itprotected Stringname()The solver's display name for diagnostic logging.protected IResponseparseResponse(String response) Every command this adapter sends directly to the process ends here, so the solver's report that its whole-run limit ended it is recognized for all of them (see AbstractSolver#timeLimitResponse).booleanNever pipelined: this adapter sends and corrects commands by its own meanspop(int number) Removes the given number of assertion-stack frames from the solver state.push(int number) Adds the given number of empty assertion-stack frames to the solver state.reset()Resets the solver to the initial state, clearing all assertions, declarations, and options.z3-4.3 predates reset-assertions (added in SMT-LIB 2.5), and turns out to already handle that gracefully on its own: sent the literal, unrecognized command text, its SMT2 front-end replies with the literal token "unsupported" -- confirmed directly against a real z3-4.3.1 binary -- rather than erroring or crashing.sendCommand(String cmd) sendCommand(ICommand cmd) Translates the given command and sends it to the solver process, returning the parsed response.A set-logic the solver accepts ends sat or unsat mode; one it rejects (as SMT-LIB requires outside start mode) changes nothing.protected IResponseset_option_impl(IExpr.IKeyword key, IAttributeValue value) z3 4.3 accepts :interactive-mode, :produce-assertions and the other :produce- options after set-logic, which SMT-LIB forbids, so that is reported here; values are kept here for get_option.start()Starts the solver; this is not an SMT-LIB command, but it is convenient in some implementations to separate the starting and initialization from the construction of the solver instance.protected StringTranslates an S-expression into Z3 syntaxunsatCoreElements(List<IExpr> reply) Drops the assumptions z3 4.3 adds to the unsat core after check-sat-assumingMethods inherited from class org.smtlib.AbstractSolver
checkImmediateExit, checkPrintSuccess, checkSatStatus, checkShape, checkStatus, comment, correctResponse, declare_datatype, declare_datatypes, declare_sort_parameter, define_const, define_fun_rec, define_funs_rec, earlierSourceLine, errorStopsSolver, execute, executePipelined, exitedResponse, finishPipelined, get_unsat_assumptions, hasPending, inSatMode, interrupt, inUnsatMode, isFlatResponse, logSolverDiagnostics, modelResponse, nextSolverLine, normalizeForTesting, outOfStep, proofResponse, readPipelined, recordChange, reportsEarlierLines, reportSeedIgnored, requireNoChangeSinceCheck, requireOptionEnabled, requireSatOrUnknown, requireUnsat, responseEnd, selfReportsImmediateExit, sendChange, sendExitCommand, sendFailure, sendFailure, sendPipelined, sendScriptText, sendSeed, set_info, set_option, setSourceLine, shapeOf, smt, solverName, solverPrintsSuccess, successOrEmpty, timeLimitResponse, timeLimitResponseAfterExit, unsatAssumptionsElements, withSourceLinesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.smtlib.ISolver
checkSatStatus, comment, declare_datatype, declare_datatypes, declare_sort_parameter, define_const, define_fun_rec, define_funs_rec, execute, get_unsat_assumptions, set_info, set_option, setSourceLine, smt, solverName
-
Field Details
-
cmds
The command-line arguments for launching the Z3 solver -
cmds_win
-
cmds_mac
-
cmds_unix
-
responseParser
The parser that parses responses from the solver -
logicSet
protected boolean logicSetSet to true once a set-logic command has been executed. z3 4.3 accepts declarations, definitions, assert, push, pop and check-sat before set-logic, which SMT-LIB forbids, so those commands check this flag and report the error themselves.
-
-
Constructor Details
-
Solver_z3_4_3
Creates an instance of the Z3 solver -
Solver_z3_4_3
Creates an instance of the Z3 solver
-
-
Method Details
-
name
The solver's display name for diagnostic logging. A real, overridable method rather than a field -- a field here would be hidden, not overridden, by a subclass's own same-named field (Java fields aren't polymorphic), silently binding start()'s reference to this class's value regardless of which subclass is actually running. See issue #51. -
lineNumberPatterns
Description copied from class:AbstractSolverPatterns matching the line numbers in this solver's messages about the command answered: group 1 is the text before the number, group 2 the number, group 3 the text after it- Overrides:
lineNumberPatternsin classAbstractSolver
-
isTimeLimitResponse
z3 answers 'timeout' (instead of a result) when its whole-run limit, -T, ends it, and then exits- Overrides:
isTimeLimitResponsein classAbstractSolver
-
pipelines
Never pipelined: this adapter sends and corrects commands by its own means- Overrides:
pipelinesin classAbstractSolver
-
sendCommand
Description copied from class:AbstractSolverTranslates the given command and sends it to the solver process, returning the parsed response. This is the mechanism behind the default implementations below; a subclass may also call it directly to send a command built some other way.- Overrides:
sendCommandin classAbstractSolver
-
sendCommand
-
start
Description copied from interface:ISolverStarts the solver; this is not an SMT-LIB command, but it is convenient in some implementations to separate the starting and initialization from the construction of the solver instance.- Specified by:
startin interfaceISolver- Overrides:
startin classAbstractSolver- Returns:
- success or an SMT error response
- See Also:
-
exit
Description copied from interface:ISolverTerminates the solver; no further commands are permitted.- Specified by:
exitin interfaceISolver- Overrides:
exitin classAbstractSolver- Returns:
- success or an SMT error response
- See Also:
-
forceExit
public void forceExit()Description copied from interface:ISolverTerminates the solver forcibly without sending commands (e.g. by killing the process).- Specified by:
forceExitin interfaceISolver- Overrides:
forceExitin classAbstractSolver
-
translate
Translates an S-expression into Z3 syntax- Overrides:
translatein classAbstractSolver- Throws:
IVisitor.VisitorException
-
parseResponse
Every command this adapter sends directly to the process ends here, so the solver's report that its whole-run limit ended it is recognized for all of them (see AbstractSolver#timeLimitResponse). A command sent directly after that finds the process gone and gets an error; sendCommand returns the timeout response.- Overrides:
parseResponsein classAbstractSolver
-
assertExpr
Description copied from interface:ISolverAdds the given expression to the current assertion-stack frame. The SMT-LIB command name isassert; the Java method name differs to avoid the Java reserved word.- Specified by:
assertExprin interfaceISolver- Overrides:
assertExprin classAbstractSolver- Returns:
- success or an SMT error response
- See Also:
-
get_assertions
Not a correction: this adapter sends commands by its own means (z3 4.3 itself reports get-assertions without :produce-assertions, which set_option_impl sends as :interactive-mode)- Specified by:
get_assertionsin interfaceISolver- Overrides:
get_assertionsin classAbstractSolver- Returns:
- a sequence of asserted terms, unsupported, or an SMT error response
- See Also:
-
check_sat
Description copied from interface:ISolverChecks whether the current assertion set is satisfiable under the current logic.- Specified by:
check_satin interfaceISolver- Overrides:
check_satin classAbstractSolver- Returns:
- sat, unsat, unknown, or an SMT error response
- See Also:
-
check_sat_assuming
z3 4.3 answers unsupported for check-sat-assuming, so it is sent as z3's legacy (check-sat a1 ... an), which checks under the same assumptions; it is padded with spaces so z3's error columns match the check-sat-assuming text (see translate and Solver_z3_recent.legacyCheckSat). Its unsat core then includes the assumptions, which unsatCoreElements drops. Like check-sat, it is accepted before set-logic, which SMT-LIB forbids, so that is reported here.- Specified by:
check_sat_assumingin interfaceISolver- Overrides:
check_sat_assumingin classAbstractSolver- Returns:
- sat, unsat, unknown, or an SMT error response
- See Also:
-
unsatCoreElements
Drops the assumptions z3 4.3 adds to the unsat core after check-sat-assuming- Overrides:
unsatCoreElementsin classAbstractSolver
-
reset
Description copied from interface:ISolverResets the solver to the initial state, clearing all assertions, declarations, and options.- Specified by:
resetin interfaceISolver- Overrides:
resetin classAbstractSolver- Returns:
- success or an SMT error response
- See Also:
-
reset_assertions
z3-4.3 predates reset-assertions (added in SMT-LIB 2.5), and turns out to already handle that gracefully on its own: sent the literal, unrecognized command text, its SMT2 front-end replies with the literal token "unsupported" -- confirmed directly against a real z3-4.3.1 binary -- rather than erroring or crashing. That's the correct, honest answer for a solver that genuinely can't do this, so there is nothing for the adapter to improve on here: a from-jSMTLIB pop-to-base simulation was tried and reverted -- it silently claimed success while only partially honoring the contract (it can only clear pushed-frame state, not declarations, and per issue #53 discussion, non-global declarations are also supposed to be cleared by reset-assertions, which this adapter has no way to do without locally tracking every declaration), and it desynced the linesOffset bookkeeping used to translate Z3's own reported error positions back to the script's real line numbers, corrupting later error messages. See issue #53.- Specified by:
reset_assertionsin interfaceISolver- Overrides:
reset_assertionsin classAbstractSolver- Returns:
- success or an SMT error response
- See Also:
-
pop
Description copied from interface:ISolverRemoves the given number of assertion-stack frames from the solver state.- Specified by:
popin interfaceISolver- Overrides:
popin classAbstractSolver- Parameters:
number- non-negative number of frames to pop- Returns:
- success or an SMT error response
- See Also:
-
push
Description copied from interface:ISolverAdds the given number of empty assertion-stack frames to the solver state.- Specified by:
pushin interfaceISolver- Overrides:
pushin classAbstractSolver- Parameters:
number- non-negative number of frames to push- Returns:
- success or an SMT error response
- See Also:
-
set_logic
Description copied from class:AbstractSolverA set-logic the solver accepts ends sat or unsat mode; one it rejects (as SMT-LIB requires outside start mode) changes nothing.- Specified by:
set_logicin interfaceISolver- Overrides:
set_logicin classAbstractSolver- Parameters:
logicName- the name of the logicpos- source position used only for error messages; may be null- Returns:
- success or unsupported or an SMT error response
- See Also:
-
set_option_impl
z3 4.3 accepts :interactive-mode, :produce-assertions and the other :produce- options after set-logic, which SMT-LIB forbids, so that is reported here; values are kept here for get_option.- Overrides:
set_option_implin classAbstractSolver
-
get_option
Sent to the solver, except where z3 4.3's answer does not conform: it defaults :produce-models to true (SMT-LIB: false), writes the channel names unquoted, knows :produce-assertions only as :interactive-mode (see set_option_impl), and answers unsupported, not the default value, for a standard option it lacks- Specified by:
get_optionin interfaceISolver- Overrides:
get_optionin classAbstractSolver- Parameters:
key- the keyword naming the option- Returns:
- the option value, or unsupported, or an SMT error response
- See Also:
-
get_info
Not a correction: this adapter sends commands by its own means, so it scrubs run-dependent values for testing itself, as AbstractSolver.get_info does- Specified by:
get_infoin interfaceISolver- Overrides:
get_infoin classAbstractSolver- Parameters:
key- the info keyword- Returns:
- the info value, or unsupported, or an SMT error response
- See Also:
-
echo
z3 4.3 writes echo's text unquoted, so where it ends cannot be found (#136); the response to echo is its argument- Specified by:
echoin interfaceISolver- Overrides:
echoin classAbstractSolver- Returns:
- the argument as an IResponse
-
get_model
The :produce-models check corrects z3 4.3 answering get-model with that option at its (non-standard) default of true; z3 4.3 itself reports get-model when no model is available- Specified by:
get_modelin interfaceISolver- Overrides:
get_modelin classAbstractSolver- Returns:
- a model, unsupported, or an SMT error response
- See Also:
-
declare_const
Description copied from interface:ISolverDeclares a new uninterpreted constant; returns success or an SMT error response- Specified by:
declare_constin interfaceISolver- Overrides:
declare_constin classAbstractSolver- See Also:
-
declare_fun
Description copied from interface:ISolverDeclares a new uninterpreted function (or constant); returns success or an SMT error response- Specified by:
declare_funin interfaceISolver- Overrides:
declare_funin classAbstractSolver- See Also:
-
define_fun
Description copied from interface:ISolverDefines a named function or constant; returns success or an SMT error response- Specified by:
define_funin interfaceISolver- Overrides:
define_funin classAbstractSolver- See Also:
-
declare_sort
Description copied from interface:ISolverDeclares a new uninterpreted sort; returns success or an SMT error response- Specified by:
declare_sortin interfaceISolver- Overrides:
declare_sortin classAbstractSolver- See Also:
-
define_sort
Description copied from interface:ISolverDefines a sort abbreviation; returns success or an SMT error response- Specified by:
define_sortin interfaceISolver- Overrides:
define_sortin classAbstractSolver- See Also:
-
get_proof
z3 4.3 itself reports get-proof without :produce-proofs or when no proof is available; the checks here only give the same messages as the other adapters- Specified by:
get_proofin interfaceISolver- Overrides:
get_proofin classAbstractSolver- Returns:
- a proof, unsupported, or an SMT error response
- See Also:
-
get_unsat_core
z3 4.3 itself reports get-unsat-core without :produce-unsat-cores or when no core is available; the checks here only give the same messages as the other adapters- Specified by:
get_unsat_corein interfaceISolver- Overrides:
get_unsat_corein classAbstractSolver- Returns:
- a list of formula names, unsupported, or an SMT error response
- See Also:
-
get_assignment
z3 4.3 answers get-assignment (with ()) when :produce-assignments is not enabled, which SMT-LIB makes an error- Specified by:
get_assignmentin interfaceISolver- Overrides:
get_assignmentin classAbstractSolver- Returns:
- a list of name–Boolean pairs, unsupported, or an SMT error response
- See Also:
-
get_value
See get_model: z3 4.3 defaults :produce-models to true- Specified by:
get_valuein interfaceISolver- Overrides:
get_valuein classAbstractSolver- Parameters:
terms- expressions to evaluate- Returns:
- a list of term–value pairs, unsupported, or an SMT error response
- See Also:
-