.. index:: single: smt_protocol
.. _smt_protocol/0:

.. rst-class:: right

**protocol**

``smt_protocol``
================

Protocol for process-backed Z3, cvc5, Bitwuzla, and Yices 2 CLI solving, SMT-LIB 2 source generation, and collected result inspection.

| **Availability:** 
|    ``logtalk_load(smt(loader))``

| **Author:** Paulo Moura
| **Version:** 1:0:0
| **Date:** 2026-11-11

| **Compilation flags:**
|    ``static``


| **Dependencies:**
|   (none)


| **Remarks:**
|    (none)

| **Inherited public predicates:**
|    (none)

.. contents::
   :local:
   :backlinks: top

Public predicates
-----------------

.. index:: solve/2
.. _smt_protocol/0::solve/2:

``solve/2``
^^^^^^^^^^^

Solves a source with default options using the external SMT solver CLI and returns a collected result per ``check-sat`` command, in script order, after cleanup. Valid sources are ``object(Object)``, ``terms(Statements)``, ``codes(Codes)``, and ``file(Path)``.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``solve(Source,Results)``
| **Mode and number of proofs:**
|    ``solve(+compound,-list(compound))`` - ``one_or_error``

| **Exceptions:**
|    ``Source`` is not a ground term:
|        ``instantiation_error``
|    ``Source`` is ground but not a supported source, or is ``object(Object)`` where ``Object`` does not implement ``smt_problem_protocol``:
|        ``domain_error(smt_source,Source)``
|    ``Statements`` is ground but not a list:
|        ``type_error(list,Statements)``
|    A statement enumerated by the provider object is not a valid statement:
|        ``domain_error(smt_statement,Statement)``
|    An origin enumerated by the provider object is invalid, or its origins and statements differ in length:
|        ``domain_error(smt_origins,Origins)``
|    ``Codes`` is ground but not a list of character codes:
|        ``type_error(codes,Codes)``
|    An element ``Code`` of the list ``Codes`` is ground but not an integer:
|        ``type_error(integer,Code)``
|    An element ``Code`` of the list ``Codes`` is an integer but not a valid character code:
|        ``domain_error(character_code,Code)``
|    ``Path`` is ground but not an atom:
|        ``type_error(atom,Path)``
|    ``Path`` does not exist:
|        ``existence_error(source_sink,Path)``
|    ``Path`` cannot be opened for reading:
|        ``permission_error(open,source_sink,Path)``
|    A launcher argument contains a null character:
|        ``domain_error(smt_shell_argument,Argument)``
|    The selected solver executable or a shell dependency does not exist:
|        ``existence_error(command,Command)``
|    An owned directory cannot be found during cleanup:
|        ``existence_error(directory,Directory)``
|    An owned file or directory cannot be removed:
|        ``permission_error(delete,source_sink,Path)``
|    A character sequence is not valid UTF-8:
|        ``representation_error(utf_8)``
|    A launcher operation fails:
|        ``smt_transport(Stage,Status,Details)``
|    Solver output is invalid or inconsistent with its exit status:
|        ``smt_solver_error(Formal,Status,Diagnostics,SourceMap)``


------------

.. index:: solve/3
.. _smt_protocol/0::solve/3:

``solve/3``
^^^^^^^^^^^

Solves a source using ``solver/1``, ``executable/1``, and ``time_limit/1`` options. Repeated options use the first occurrence. Valid sources are ``object(Object)``, ``terms(Statements)``, ``codes(Codes)``, and ``file(Path)``.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``solve(Source,Results,Options)``
| **Mode and number of proofs:**
|    ``solve(+compound,-list(compound),+list(compound))`` - ``one_or_error``

| **Exceptions:**
|    ``Source`` is not a ground term:
|        ``instantiation_error``
|    ``Source`` is ground but not a supported source, or is ``object(Object)`` where ``Object`` does not implement ``smt_problem_protocol``:
|        ``domain_error(smt_source,Source)``
|    ``Statements`` is ground but not a list:
|        ``type_error(list,Statements)``
|    A statement enumerated by the provider object is not a valid statement:
|        ``domain_error(smt_statement,Statement)``
|    An origin enumerated by the provider object is invalid, or its origins and statements differ in length:
|        ``domain_error(smt_origins,Origins)``
|    ``Codes`` is ground but not a list of character codes:
|        ``type_error(codes,Codes)``
|    An element ``Code`` of the list ``Codes`` is ground but not an integer:
|        ``type_error(integer,Code)``
|    An element ``Code`` of the list ``Codes`` is an integer but not a valid character code:
|        ``domain_error(character_code,Code)``
|    ``Path`` is ground but not an atom:
|        ``type_error(atom,Path)``
|    ``Path`` does not exist:
|        ``existence_error(source_sink,Path)``
|    ``Path`` cannot be opened for reading:
|        ``permission_error(open,source_sink,Path)``
|    ``Options`` is a variable:
|        ``instantiation_error``
|    ``Options`` is neither a variable nor a list:
|        ``type_error(list,Options)``
|    An element ``Option`` of the list ``Options`` is a variable:
|        ``instantiation_error``
|    An element ``Option`` of the list ``Options`` is neither a variable nor a compound term:
|        ``type_error(compound,Option)``
|    An element ``Option`` of the list ``Options`` is a compound term but not a valid option:
|        ``domain_error(option,Option)``
|    A launcher argument contains a null character:
|        ``domain_error(smt_shell_argument,Argument)``
|    The selected solver executable or a shell dependency does not exist:
|        ``existence_error(command,Command)``
|    An owned directory cannot be found during cleanup:
|        ``existence_error(directory,Directory)``
|    An owned file or directory cannot be removed:
|        ``permission_error(delete,source_sink,Path)``
|    A character sequence is not valid UTF-8:
|        ``representation_error(utf_8)``
|    A launcher operation fails:
|        ``smt_transport(Stage,Status,Details)``
|    Solver output is invalid or inconsistent with its exit status:
|        ``smt_solver_error(Formal,Status,Diagnostics,SourceMap)``


------------

.. index:: program/1
.. _smt_protocol/0::program/1:

``program/1``
^^^^^^^^^^^^^

Generates and prints SMT-LIB 2 source to the current output, equivalent to ``program/2`` followed by ``print_program/1``, without invoking the solver.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``program(Source)``
| **Mode and number of proofs:**
|    ``program(+compound)`` - ``one_or_error``

| **Exceptions:**
|    ``Source`` is not a ground term:
|        ``instantiation_error``
|    ``Source`` is ground but not a supported source, or is ``object(Object)`` where ``Object`` does not implement ``smt_problem_protocol``:
|        ``domain_error(smt_source,Source)``
|    ``Statements`` is ground but not a list:
|        ``type_error(list,Statements)``
|    A statement enumerated by the provider object is not a valid statement:
|        ``domain_error(smt_statement,Statement)``
|    An origin enumerated by the provider object is invalid, or its origins and statements differ in length:
|        ``domain_error(smt_origins,Origins)``
|    ``Codes`` is ground but not a list of character codes:
|        ``type_error(codes,Codes)``
|    An element ``Code`` of the list ``Codes`` is ground but not an integer:
|        ``type_error(integer,Code)``
|    An element ``Code`` of the list ``Codes`` is an integer but not a valid character code:
|        ``domain_error(character_code,Code)``
|    ``Path`` is ground but not an atom:
|        ``type_error(atom,Path)``
|    ``Path`` does not exist:
|        ``existence_error(source_sink,Path)``
|    ``Path`` cannot be opened for reading:
|        ``permission_error(open,source_sink,Path)``
|    The current output stream does not allow writing:
|        ``permission_error(output,stream,Stream)``


------------

.. index:: program/2
.. _smt_protocol/0::program/2:

``program/2``
^^^^^^^^^^^^^

Returns SMT-LIB 2 source codes from ``object(Object)``, ``terms(Statements)``, ``codes(Codes)``, or ``file(Path)`` without invoking the solver.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``program(Source,Codes)``
| **Mode and number of proofs:**
|    ``program(+compound,-list(integer))`` - ``one_or_error``

| **Exceptions:**
|    ``Source`` is not a ground term:
|        ``instantiation_error``
|    ``Source`` is ground but not a supported source, or is ``object(Object)`` where ``Object`` does not implement ``smt_problem_protocol``:
|        ``domain_error(smt_source,Source)``
|    ``Statements`` is ground but not a list:
|        ``type_error(list,Statements)``
|    A statement enumerated by the provider object is not a valid statement:
|        ``domain_error(smt_statement,Statement)``
|    An origin enumerated by the provider object is invalid, or its origins and statements differ in length:
|        ``domain_error(smt_origins,Origins)``
|    ``Codes`` is ground but not a list of character codes:
|        ``type_error(codes,Codes)``
|    An element ``Code`` of the list ``Codes`` is ground but not an integer:
|        ``type_error(integer,Code)``
|    An element ``Code`` of the list ``Codes`` is an integer but not a valid character code:
|        ``domain_error(character_code,Code)``
|    ``Path`` is ground but not an atom:
|        ``type_error(atom,Path)``
|    ``Path`` does not exist:
|        ``existence_error(source_sink,Path)``
|    ``Path`` cannot be opened for reading:
|        ``permission_error(open,source_sink,Path)``


------------

.. index:: print_program/1
.. _smt_protocol/0::print_program/1:

``print_program/1``
^^^^^^^^^^^^^^^^^^^

Prints SMT-LIB 2 character codes to the current output without adding a newline or invoking the solver.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``print_program(Codes)``
| **Mode and number of proofs:**
|    ``print_program(+list(integer))`` - ``one_or_error``

| **Exceptions:**
|    ``Codes`` is not a ground term:
|        ``instantiation_error``
|    ``Codes`` is ground but not a list of character codes:
|        ``type_error(codes,Codes)``
|    An element ``Code`` of the list ``Codes`` is ground but not an integer:
|        ``type_error(integer,Code)``
|    An element ``Code`` of the list ``Codes`` is an integer but not a valid character code:
|        ``domain_error(character_code,Code)``
|    The current output stream does not allow writing:
|        ``permission_error(output,stream,Stream)``


------------

.. index:: status/2
.. _smt_protocol/0::status/2:

``status/2``
^^^^^^^^^^^^

Returns the collected status (``satisfiable``, ``unsatisfiable``, or ``unknown``) of a single ``check-sat`` result.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``status(Result,Status)``
| **Mode and number of proofs:**
|    ``status(+compound,-atom)`` - ``one_or_error``

| **Exceptions:**
|    ``Result`` is not a ground term:
|        ``instantiation_error``
|    ``Result`` is not a valid collected SMT solver result:
|        ``domain_error(smt_result,Result)``


------------

.. index:: model_binding/2
.. _smt_protocol/0::model_binding/2:

``model_binding/2``
^^^^^^^^^^^^^^^^^^^

Enumerates, by backtracking, the collected model bindings (``Symbol-Value`` pairs) without starting a process. Fails when the result has no model.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``model_binding(Result,Binding)``
| **Mode and number of proofs:**
|    ``model_binding(+compound,-pair)`` - ``zero_or_more``

| **Exceptions:**
|    ``Result`` is not a ground term:
|        ``instantiation_error``
|    ``Result`` is not a valid collected SMT solver result:
|        ``domain_error(smt_result,Result)``


------------

.. index:: model_value/3
.. _smt_protocol/0::model_value/3:

``model_value/3``
^^^^^^^^^^^^^^^^^

Looks up the collected model value bound to ``Symbol``. Fails when the result has no model or no binding for ``Symbol``.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``model_value(Result,Symbol,Value)``
| **Mode and number of proofs:**
|    ``model_value(+compound,+atom,-term)`` - ``zero_or_one``

| **Exceptions:**
|    ``Result`` or ``Symbol`` is a variable:
|        ``instantiation_error``
|    ``Symbol`` is neither a variable nor an atom:
|        ``type_error(atom,Symbol)``
|    ``Result`` is not a valid collected SMT solver result:
|        ``domain_error(smt_result,Result)``


------------

.. index:: unsat_core_name/2
.. _smt_protocol/0::unsat_core_name/2:

``unsat_core_name/2``
^^^^^^^^^^^^^^^^^^^^^

Enumerates, by backtracking, the named assertions in the collected unsatisfiable core without starting a process. Fails when the result has no core.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``unsat_core_name(Result,Name)``
| **Mode and number of proofs:**
|    ``unsat_core_name(+compound,-atom)`` - ``zero_or_more``

| **Exceptions:**
|    ``Result`` is not a ground term:
|        ``instantiation_error``
|    ``Result`` is not a valid collected SMT solver result:
|        ``domain_error(smt_result,Result)``


------------

.. index:: result_property/2
.. _smt_protocol/0::result_property/2:

``result_property/2``
^^^^^^^^^^^^^^^^^^^^^

Enumerates, by backtracking, ``status(Status)`` and the stored result properties.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``result_property(Result,Property)``
| **Mode and number of proofs:**
|    ``result_property(+compound,?compound)`` - ``zero_or_more``

| **Exceptions:**
|    ``Result`` is not a ground term:
|        ``instantiation_error``
|    ``Result`` is not a valid collected SMT solver result:
|        ``domain_error(smt_result,Result)``


------------

.. index:: print_result/1
.. _smt_protocol/0::print_result/1:

``print_result/1``
^^^^^^^^^^^^^^^^^^

Prints a single collected result (status and, when present, model bindings and unsat core names) to the current output, without invoking the solver.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``print_result(Result)``
| **Mode and number of proofs:**
|    ``print_result(+compound)`` - ``one_or_error``

| **Exceptions:**
|    ``Result`` is not a ground term:
|        ``instantiation_error``
|    ``Result`` is not a valid collected SMT solver result:
|        ``domain_error(smt_result,Result)``
|    The current output stream does not allow writing:
|        ``permission_error(output,stream,Stream)``


------------

.. index:: print_results/1
.. _smt_protocol/0::print_results/1:

``print_results/1``
^^^^^^^^^^^^^^^^^^^

Prints each collected result in ``Results``, in order, separating consecutive results with a blank line.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``print_results(Results)``
| **Mode and number of proofs:**
|    ``print_results(+list(compound))`` - ``one_or_error``

| **Exceptions:**
|    ``Results`` is not a ground term:
|        ``instantiation_error``
|    ``Results`` is ground but not a list:
|        ``type_error(list,Results)``
|    An element of the list ``Results`` is not a valid collected SMT solver result:
|        ``domain_error(smt_result,Result)``
|    The current output stream does not allow writing:
|        ``permission_error(output,stream,Stream)``


------------

.. index:: capability/2
.. _smt_protocol/0::capability/2:

``capability/2``
^^^^^^^^^^^^^^^^

Enumerates, by backtracking, advisory ``Solver``-``Feature`` capability pairs. Purely informational: the library does not enforce these pairs and a solver call may still succeed, fail, or report ``unknown`` for a feature outside this table.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``capability(Solver,Feature)``
| **Mode and number of proofs:**
|    ``capability(?atom,?atom)`` - ``zero_or_more``

| **Remarks:**

    - Feature: One of ``quantifiers``, ``strings``, ``linear_arithmetic``, ``non_linear_arithmetic``, ``unsat_cores``, ``incremental``, ``bit_vectors``, ``arrays``, ``floating_point``, or ``algebraic_datatypes``.


------------

Protected predicates
--------------------

(none)

Private predicates
------------------

(none)

Operators
---------

(none)

