API reference

Safe Handle & Context API Reference (Z3 5.3.3)

This reference covers all 29 safe RAII handle structs and 769 C-API bindings generated directly from api/z3-api.json for Z3 5.3.3. For Pythonic free functions, operators, and callback traits, see Pythonic API. For direct 1-to-1 Z3_* C functions, see Low-Level C API.

Handle Types & Ownership

Mojo Struct Z3 C Handle Ownership Destructor / Refcount
App Z3_app context_managed Owned by Context (Z3_del_context)
ApplyResult Z3_apply_result refcounted Z3_apply_result_inc_ref / Z3_apply_result_dec_ref
Ast Z3_ast context_managed Owned by Context (Z3_del_context)
AstMap Z3_ast_map refcounted Z3_ast_map_inc_ref / Z3_ast_map_dec_ref
AstVector Z3_ast_vector refcounted Z3_ast_vector_inc_ref / Z3_ast_vector_dec_ref
Config Z3_config explicit_del Z3_del_config
Constructor Z3_constructor explicit_del Z3_del_constructor
ConstructorList Z3_constructor_list explicit_del Z3_del_constructor_list
Context Z3_context explicit_del Z3_del_context
Fixedpoint Z3_fixedpoint refcounted Z3_fixedpoint_inc_ref / Z3_fixedpoint_dec_ref
FuncDecl Z3_func_decl context_managed Owned by Context (Z3_del_context)
FuncEntry Z3_func_entry refcounted Z3_func_entry_inc_ref / Z3_func_entry_dec_ref
FuncInterp Z3_func_interp refcounted Z3_func_interp_inc_ref / Z3_func_interp_dec_ref
Goal Z3_goal refcounted Z3_goal_inc_ref / Z3_goal_dec_ref
Model Z3_model refcounted Z3_model_inc_ref / Z3_model_dec_ref
Optimize Z3_optimize refcounted Z3_optimize_inc_ref / Z3_optimize_dec_ref
ParamDescrs Z3_param_descrs refcounted Z3_param_descrs_inc_ref / Z3_param_descrs_dec_ref
Params Z3_params refcounted Z3_params_inc_ref / Z3_params_dec_ref
ParserContext Z3_parser_context refcounted Z3_parser_context_inc_ref / Z3_parser_context_dec_ref
Pattern Z3_pattern context_managed Owned by Context (Z3_del_context)
Probe Z3_probe refcounted Z3_probe_inc_ref / Z3_probe_dec_ref
RcfNum Z3_rcf_num explicit_del Z3_rcf_del
Simplifier Z3_simplifier refcounted Z3_simplifier_inc_ref / Z3_simplifier_dec_ref
Solver Z3_solver refcounted Z3_solver_inc_ref / Z3_solver_dec_ref
SolverCallback Z3_solver_callback borrowed Borrowed inside Z3 callback
Sort Z3_sort context_managed Owned by Context (Z3_del_context)
Stats Z3_stats refcounted Z3_stats_inc_ref / Z3_stats_dec_ref
Symbol Z3_symbol context_managed Owned by Context (Z3_del_context)
Tactic Z3_tactic refcounted Z3_tactic_inc_ref / Z3_tactic_dec_ref

Global Functions

Re-exported at the package root (from z3_mojo import ...).

append_log

def append_log(string: String) raises

Append user-defined string to interaction log.

The interaction log is opened using Z3_open_log. It contains the formulas that are checked using Z3. You can use this command to append comments, for instance.

See also: open_log, close_log

C API: Z3_append_log (z3_api.h, auto)

close_log

def close_log() raises

Close interaction log.

See also: open_log, append_log

C API: Z3_close_log (z3_api.h, auto)

disable_trace

def disable_trace(tag: String) raises

Disable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise

See also: enable_trace

C API: Z3_disable_trace (z3_api.h, auto)

enable_trace

def enable_trace(tag: String) raises

Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise

See also: disable_trace

C API: Z3_enable_trace (z3_api.h, auto)

finalize_memory

def finalize_memory() raises

Destroy all allocated resources.

Any pointers previously returned by the API become invalid. Can be used for memory leak detection.

C API: Z3_finalize_memory (z3_api.h, auto)

get_estimated_alloc_size

def get_estimated_alloc_size() raises -> UInt64

Return the estimated allocated memory in bytes.

C API: Z3_get_estimated_alloc_size (z3_api.h, auto)

get_full_version

def get_full_version() raises -> String

Return a string that fully describes the version of Z3 in use.

See also: get_version

C API: Z3_get_full_version (z3_api.h, manual)

get_version

def get_version() raises -> Tuple[UInt32, UInt32, UInt32, UInt32]

Return Z3 version number information.

See also: get_full_version

C API: Z3_get_version (z3_api.h, manual)

global_param_get

def global_param_get(param_id: String) raises -> Optional[String]

Get a global (or module) parameter.

Returns false if the parameter value does not exist.

Note: This function cannot be invoked simultaneously from different threads without synchronization. The result string stored in param_value is stored in shared location.

See also: global_param_reset_all, global_param_set

C API: Z3_global_param_get (z3_api.h, manual)

global_param_reset_all

def global_param_reset_all() raises

Restore the value of all global (and module) parameters. This command will not affect already created objects (such as tactics and solvers).

See also: global_param_get, global_param_set

C API: Z3_global_param_reset_all (z3_api.h, auto)

global_param_set

def global_param_set(param_id: String, param_value: String) raises

Set a global (or module) parameter. This setting is shared by all Z3 contexts.

When a Z3 module is initialized it will use the value of these parameters when Z3_params objects are not provided.

The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. The character '.' is a delimiter (more later).

The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION".

This function can be used to set parameters for a specific Z3 module. This can be done by using <module-name>.<parameter-name>. For example: Z3_global_param_set('pp.decimal', 'true') will set the parameter "decimal" in the module "pp" to true.

See also: global_param_get, global_param_reset_all

C API: Z3_global_param_set (z3_api.h, auto)

open_log

def open_log(filename: String) raises -> Bool

Log interaction to a file.

See also: append_log, close_log

C API: Z3_open_log (z3_api.h, auto)

reset_memory

def reset_memory() raises

Reset all allocated resources.

Use this facility on out-of memory errors. It allows discharging the previous state and resuming afresh. Any pointers previously returned by the API become invalid.

C API: Z3_reset_memory (z3_api.h, auto)

toggle_warning_messages

def toggle_warning_messages(enabled: Bool) raises

Enable/disable printing warning messages to the console.

Warnings are printed after passing true, warning messages are suppressed after calling this method with false.

C API: Z3_toggle_warning_messages (z3_api.h, auto)

Context

var ctx = Context()
var x = ctx.mk_int_const("x")
var f = ctx.mk_eq(ctx.mk_add(x, ctx.mk_int(1)), ctx.mk_int(5))

Commonly used Context methods:

Method Purpose
int_sort Create the integer type.
real_sort Create the real type.
bool_sort Create the Boolean type.
bv_sort Create a bit-vector type of the given size.
string_sort Create a sort for unicode strings.
mk_int_const Create an Int constant (variable) named name.
mk_real_const Create a Real constant (variable) named name.
mk_const Declare and create a constant.
mk_add Create an AST node representing args[0] + ... + args[num_args-1].
mk_and Create an AST node representing args[0] and ... and args[num_args-1].
mk_eq Create an AST node representing l = r.
mk_ite Create an AST node representing an if-then-else: ite(t1, t2, t3).
mk_forall Create a universal quantifier using a list of constants that will form the set of bound variables.
mk_bvadd Standard two's complement addition.
mk_select Array read. The argument a is the array and i is the index of the array that gets read.
mk_store Array update.
mk_seq_concat Concatenate sequences.

Exposes 510 Z3 C API bindings plus 9 ergonomic Mojo helpers, organized by Z3 topic group:

Convenience Constructors & Helpers (9)

from_config

def from_config(cfg: Config) raises -> Context

Create a Context from an explicit Config.

mk_bool

def mk_bool(self, val: Bool) raises -> Ast

Create a Boolean literal (true or false) from val.

mk_bool_const

def mk_bool_const(self, name: String) raises -> Ast

Create a Bool constant (variable) named name.

mk_bv

def mk_bv(self, val: Int, width: Int) raises -> Ast

Create a BitVec numeral of bit-width width from Int.

mk_bv_const

def mk_bv_const(self, name: String, width: Int) raises -> Ast

Create a BitVec constant (variable) of bit-width width named name.

mk_int_const

def mk_int_const(self, name: String) raises -> Ast

Create an Int constant (variable) named name.

mk_integer

def mk_integer(self, val: Integer) raises -> Ast

Create an arbitrary-precision Int numeral from apn_mojo.Integer.

mk_real_const

def mk_real_const(self, name: String) raises -> Ast

Create a Real constant (variable) named name.

version

def version(self) raises -> String

Return the full Z3 version string (Z3_get_full_version).

Context and AST Reference Counting (5)

__init__

def __init__(out self) raises

Create a context using the given configuration.

After a context is created, the configuration cannot be changed, although some parameters can be changed using Z3_update_param_value. All main interaction with Z3 happens in the context of a Z3_context.

In contrast to Z3_mk_context_rc the life time of Z3_ast objects persists with the life time of the context.

Note that all other reference counted objects, including Z3_model, Z3_solver, Z3_func_interp have to be managed by the caller. Their reference counts are not handled by the context.

Notes:

  • Thread safety: objects created using a given context should not be accessed from different threads without synchronization. In other words, operations on a context are not thread safe. To use Z3 from different threads create separate context objects. The Z3_translate, Z3_solver_translate, Z3_model_translate, Z3_goal_translate methods are exposed to allow copying state from one context to another.
    • Z3_sort, Z3_func_decl, Z3_app, Z3_pattern are Z3_ast's. - Z3 uses hash-consing, i.e., when the same Z3_ast is created twice, Z3 will return the same pointer twice.

See also: Z3_del_context, Z3_set_error_handler

C API: Z3_mk_context (z3_api.h, manual)

enable_concurrent_dec_ref

def enable_concurrent_dec_ref(self) raises

use concurrency control for dec-ref. Reference counting decrements are allowed in separate threads from the context. If this setting is not invoked, reference counting decrements are not going to be thread safe.

C API: Z3_enable_concurrent_dec_ref (z3_api.h, auto)

get_global_param_descrs

def get_global_param_descrs(self) raises -> ParamDescrs

Retrieve description of global parameters.

C API: Z3_get_global_param_descrs (z3_api.h, auto)

interrupt

def interrupt(self) raises

Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers, simplifiers and tactics.

C API: Z3_interrupt (z3_api.h, auto)

update_param

def update_param(self, key: String, val: String) raises

Set a value of a context parameter.

See also: global_param_set

C API: Z3_update_param_value (z3_api.h, manual)

Symbols (2)

mk_int_symbol

def mk_int_symbol(self, i: Int) raises -> Symbol

Create a Z3 symbol using an integer.

Symbols are used to name several term and type constructors.

NB. Not all integers can be passed to this function. The legal range of unsigned integers is 0 to 2^30-1.

See also: Context.get_symbol_int, Context.mk_symbol

C API: Z3_mk_int_symbol (z3_api.h, manual)

mk_symbol

def mk_symbol(self, name: String) raises -> Symbol

Create a Z3 symbol using a C string.

Symbols are used to name several term and type constructors.

Sorts (29)

array_sort

def array_sort(self, domain: Sort, range_: Sort) raises -> Sort

Create an array type.

We usually represent the array type as: [domain -> range]. Arrays are usually used to model the heap/memory in software verification.

See also: Context.mk_select, Context.mk_store

C API: Z3_mk_array_sort (z3_api.h, manual)

bool_sort

def bool_sort(self) raises -> Sort

Create the Boolean type.

This type is used to create propositional variables and predicates.

C API: Z3_mk_bool_sort (z3_api.h, manual)

bv_sort

def bv_sort(self, width: Int) raises -> Sort

Create a bit-vector type of the given size.

This type can also be seen as a machine integer.

Note: The size of the bit-vector type must be greater than zero.

C API: Z3_mk_bv_sort (z3_api.h, manual)

get_finite_field_sort_size

def get_finite_field_sort_size(self, s: Sort) raises -> String

Return the decimal modulus of a finite-field sort.

C API: Z3_get_finite_field_sort_size (z3_api.h, auto)

int_sort

def int_sort(self) raises -> Sort

Create the integer type.

This type is not the int type found in programming languages. A machine integer can be represented using bit-vectors. The function Z3_mk_bv_sort creates a bit-vector type.

See also: Context.bv_sort

C API: Z3_mk_int_sort (z3_api.h, manual)

mk_array_sort_n

def mk_array_sort_n(self, domain: List[Sort], range_: Sort) raises -> Sort

Create an array type with N arguments

See also: Context.mk_select_n, Context.mk_store_n

C API: Z3_mk_array_sort_n (z3_api.h, auto)

mk_complex

def mk_complex(self, re: Ast, im: Ast) raises -> Ast

Create a complex number with the given real and imaginary components. Integer components are coerced to Real.

C API: Z3_mk_complex (z3_api.h, auto)

mk_complex_sort

def mk_complex_sort(self) raises -> Sort

Create the Complex sort. Complex numbers are pairs of Reals.

Use Z3_mk_complex to construct values and Z3_mk_real_part and Z3_mk_imag_part to access their components. The arithmetic APIs for addition, subtraction, multiplication, negation, and division accept Complex expressions. Ordering and exponentiation do not.

C API: Z3_mk_complex_sort (z3_api.h, auto)

mk_constructor

def mk_constructor(self, name: Symbol, recognizer: Symbol, field_names: List[Symbol], sorts: List[Sort], sort_refs: List[UInt32]) raises -> Constructor

Create a constructor.

Parameters:

  • c — logical context.
  • name — constructor name.
  • recognizer — name of recognizer function.
  • num_fields — number of fields in constructor.
  • field_names — names of the constructor fields.
  • sorts — field sorts, 0 if the field sort refers to a recursive sort.
  • sort_refs — reference to datatype sort that is an argument to the constructor; if the corresponding sort reference is 0, then the value in sort_refs should be an index referring to one of the recursive datatypes that is declared.

See also: Z3_del_constructor, Context.mk_constructor_list, Context.query_constructor

C API: Z3_mk_constructor (z3_api.h, auto)

mk_constructor_list

def mk_constructor_list(self, constructors: List[Constructor]) raises -> ConstructorList

Create list of constructors.

Parameters:

  • c — logical context.
  • num_constructors — number of constructors in list.
  • constructors — list of constructors.

See also: Z3_del_constructor_list, Context.mk_constructor

C API: Z3_mk_constructor_list (z3_api.h, auto)

mk_datatype

def mk_datatype(self, name: Symbol, constructors: List[Constructor]) raises -> Sort

Create datatype, such as lists, trees, records, enumerations or unions of records. The datatype may be recursive. Return the datatype sort.

Parameters:

  • c — logical context.
  • name — name of datatype.
  • num_constructors — number of constructors passed in.
  • constructors — array of constructor containers.

See also: Context.mk_constructor, Context.mk_constructor_list, Context.mk_datatypes

C API: Z3_mk_datatype (z3_api.h, manual)

mk_datatype_sort

def mk_datatype_sort(self, name: Symbol, params: List[Sort]) raises -> Sort

create a forward reference to a recursive datatype being declared. The forward reference can be used in a nested occurrence: the range of an array or as element sort of a sequence. The forward reference should only be used when used in an accessor for a recursive datatype that gets declared.

Forward references can replace the use sort references, that are unsigned integers in the Z3_mk_constructor call

Parameters:

  • c — logical context
  • name — name of the datatype
  • num_params — number of sort parameters
  • params — array of sort parameters

C API: Z3_mk_datatype_sort (z3_api.h, auto)

mk_datatypes

def mk_datatypes(self, sort_names: List[Symbol], constructor_lists: List[ConstructorList]) raises -> List[Sort]

Create mutually recursive datatypes.

Parameters:

  • c — logical context.
  • num_sorts — number of datatype sorts.
  • sort_names — names of datatype sorts.
  • sorts — array of datatype sorts.
  • constructor_lists — list of constructors, one list per sort.

See also: Context.mk_constructor, Context.mk_constructor_list, Context.mk_datatype

C API: Z3_mk_datatypes (z3_api.h, manual)

mk_enumeration_sort

def mk_enumeration_sort(self, name: Symbol, enum_names: List[Symbol]) raises -> Tuple[Sort, List[FuncDecl], List[FuncDecl]]

Create a enumeration sort.

An enumeration sort with n elements. This function will also declare the functions corresponding to the enumerations.

For example, if this function is called with three symbols A, B, C and the name S, then s is a sort whose name is S, and the function returns three terms corresponding to A, B, C in enum_consts. The array enum_testers has three predicates of type (s -> Bool). The first predicate (corresponding to A) is true when applied to A, and false otherwise. Similarly for the other predicates.

Parameters:

  • c — logical context
  • name — name of the enumeration sort.
  • n — number of elements in enumeration sort.
  • enum_names — names of the enumerated elements.
  • enum_consts — constants corresponding to the enumerated elements.
  • enum_testers — predicates testing if terms of the enumeration sort correspond to an enumeration.

C API: Z3_mk_enumeration_sort (z3_api.h, manual)

mk_ff_add

def mk_ff_add(self, args: List[Ast]) raises -> Ast

Sum at least two elements of the same prime field.

C API: Z3_mk_ff_add (z3_api.h, auto)

mk_ff_bitsum

def mk_ff_bitsum(self, args: List[Ast]) raises -> Ast

Weighted sum a0 + 2a1 + 4a2 + ... (does not constrain arguments to bits).

C API: Z3_mk_ff_bitsum (z3_api.h, auto)

mk_ff_mul

def mk_ff_mul(self, args: List[Ast]) raises -> Ast

Multiply at least two elements of the same prime field.

C API: Z3_mk_ff_mul (z3_api.h, auto)

mk_ff_neg

def mk_ff_neg(self, a: Ast) raises -> Ast

Additive inverse in a prime field.

C API: Z3_mk_ff_neg (z3_api.h, auto)

mk_finite_domain_sort

def mk_finite_domain_sort(self, name: Symbol, size: UInt64) raises -> Sort

Create a named finite domain sort.

To create constants that belong to the finite domain, use the APIs for creating numerals and pass a numeric constant together with the sort returned by this call. The numeric constant should be between 0 and the less than the size of the domain.

mk_finite_field_sort

def mk_finite_field_sort(self, prime: String) raises -> Sort

Create a prime-field sort. Large moduli undergo probable-prime screening.

C API: Z3_mk_finite_field_sort (z3_api.h, auto)

mk_imag_part

def mk_imag_part(self, z: Ast) raises -> Ast

Return the imaginary component of a Complex expression.

C API: Z3_mk_imag_part (z3_api.h, auto)

mk_list_sort

def mk_list_sort(self, name: Symbol, elem_sort: Sort) raises -> Tuple[Sort, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl, FuncDecl]

Create a list sort

A list sort over elem_sort This function declares the corresponding constructors and testers for lists.

Parameters:

  • c — logical context
  • name — name of the list sort.
  • elem_sort — sort of list elements.
  • nil_decl — declaration for the empty list.
  • is_nil_decl — test for the empty list.
  • cons_decl — declaration for a cons cell.
  • is_cons_decl — cons cell test.
  • head_decl — list head.
  • tail_decl — list tail.

C API: Z3_mk_list_sort (z3_api.h, manual)

mk_polymorphic_datatype

def mk_polymorphic_datatype(self, name: Symbol, parameters: List[Sort], constructors: List[Constructor]) raises -> Sort

Create a parametric datatype with explicit type parameters.

This function is similar to Z3_mk_datatype, except it takes an explicit set of type parameters. The parameters can be type variables created with Z3_mk_type_variable, allowing the definition of polymorphic datatypes that can be instantiated with different concrete types.

Parameters:

  • c — logical context
  • name — name of the datatype
  • num_parameters — number of type parameters (can be 0)
  • parameters — array of type parameters (type variables or concrete sorts)
  • num_constructors — number of constructors
  • constructors — array of constructor specifications

See also: Context.mk_datatype, Context.mk_type_variable, Context.mk_datatype_sort

C API: Z3_mk_polymorphic_datatype (z3_api.h, manual)

mk_real_part

def mk_real_part(self, z: Ast) raises -> Ast

Return the real component of a Complex expression.

C API: Z3_mk_real_part (z3_api.h, auto)

mk_tuple_sort

def mk_tuple_sort(self, name: Symbol, field_names: List[Symbol], field_sorts: List[Sort]) raises -> Tuple[Sort, FuncDecl, List[FuncDecl]]

Create a tuple type.

A tuple with n fields has a constructor and n projections. This function will also declare the constructor and projection functions.

Parameters:

  • c — logical context
  • mk_tuple_name — name of the constructor function associated with the tuple type.
  • num_fields — number of fields in the tuple type.
  • field_names — name of the projection functions.
  • field_sorts — type of the tuple fields.
  • mk_tuple_decl — output parameter that will contain the constructor declaration.
  • proj_decl — output parameter that will contain the projection function declarations. This field must be a buffer of size num_fields allocated by the user.

C API: Z3_mk_tuple_sort (z3_api.h, manual)

mk_type_variable

def mk_type_variable(self, s: Symbol) raises -> Sort

Create a type variable.

Functions using type variables can be applied to instantiations that match the signature of the function. Assertions using type variables correspond to assertions over all possible instantiations.

C API: Z3_mk_type_variable (z3_api.h, auto)

query_constructor

def query_constructor(self, constr: Constructor, num_fields: Int) raises -> Tuple[FuncDecl, FuncDecl, List[FuncDecl]]

Query constructor for declared functions.

Parameters:

  • c — logical context.
  • constr — constructor container. The container must have been passed into a Z3_mk_datatype call.
  • num_fields — number of accessor fields in the constructor.
  • constructor — constructor function declaration, allocated by user.
  • tester — constructor test function declaration, allocated by user.
  • accessors — array of accessor function declarations allocated by user. The array must contain num_fields elements.

See also: Context.mk_constructor

C API: Z3_query_constructor (z3_api.h, manual)

real_sort

def real_sort(self) raises -> Sort

Create the real type.

Note that this type is not a floating point number.

C API: Z3_mk_real_sort (z3_api.h, manual)

uninterpreted_sort

def uninterpreted_sort(self, name: String) raises -> Sort

Create a free (uninterpreted) type using the given name (symbol).

Two free types are considered the same iff the have the same name.

C API: Z3_mk_uninterpreted_sort (z3_api.h, manual)

Constants and Applications (7)

add_rec_def

def add_rec_def(self, f: FuncDecl, args: List[Ast], body: Ast) raises

Define the body of a recursive function.

After declaring a recursive function or a collection of mutually recursive functions, use this function to provide the definition for the recursive function.

Parameters:

  • c — logical context.
  • f — function declaration.
  • n — number of arguments to the function
  • args — constants that are used as arguments to the recursive function in the definition.
  • body — body of the recursive function

See also: Context.mk_rec_func_decl

C API: Z3_add_rec_def (z3_api.h, auto)

mk_app

def mk_app(self, decl: FuncDecl, args: List[Ast]) raises -> Ast

Create a constant or function application.

mk_const

def mk_const(self, name: String, sort: Sort) raises -> Ast

Declare and create a constant.

This function is a shorthand for:

Z3_func_decl d = Z3_mk_func_decl(c, s, 0, 0, ty);
Z3_ast n            = Z3_mk_app(c, d, 0, 0);

mk_fresh_const

def mk_fresh_const(self, prefix: String, ty: Sort) raises -> Ast

Declare and create a fresh constant.

This function is a shorthand for:

Z3_func_decl d = Z3_mk_fresh_func_decl(c, prefix, 0, 0, ty); Z3_ast n = Z3_mk_app(c, d, 0, 0);

Note: If prefix is NULL, then it is assumed to be the empty string.

See also: Context.mk_app, Context.mk_const, Context.mk_fresh_func_decl, Context.mk_func_decl

C API: Z3_mk_fresh_const (z3_api.h, auto)

mk_fresh_func_decl

def mk_fresh_func_decl(self, prefix: String, domain: List[Sort], range_: Sort) raises -> FuncDecl

Declare a fresh constant or function.

Z3 will generate an unique name for this function declaration. If prefix is different from NULL, then the name generate by Z3 will start with prefix.

Note: If prefix is NULL, then it is assumed to be the empty string.

See also: Context.mk_func_decl

C API: Z3_mk_fresh_func_decl (z3_api.h, auto)

mk_func_decl

def mk_func_decl(self, name: String, domain: List[Sort], range_: Sort) raises -> FuncDecl

Declare a constant or function.

After declaring a constant or function, the function Z3_mk_app can be used to create a constant or function application.

Parameters:

  • c — logical context.
  • s — name of the constant or function.
  • domain_size — number of arguments. It is 0 when declaring a constant.
  • domain — array containing the sort of each argument. The array must contain domain_size elements. It is 0 when declaring a constant.
  • range — sort of the constant or the return sort of the function.

See also: Context.mk_app, Context.mk_fresh_func_decl, Context.mk_rec_func_decl

C API: Z3_mk_func_decl (z3_api.h, manual)

mk_rec_func_decl

def mk_rec_func_decl(self, s: Symbol, domain: List[Sort], range_: Sort) raises -> FuncDecl

Declare a recursive function

After declaring recursive function, it should be associated with a recursive definition Z3_add_rec_def. The function Z3_mk_app can be used to create a constant or function application.

Parameters:

  • c — logical context.
  • s — name of the function.
  • domain_size — number of arguments. It should be greater than 0.
  • domain — array containing the sort of each argument. The array must contain domain_size elements.
  • range — sort of the constant or the return sort of the function.

See also: Context.add_rec_def, Context.mk_app, Context.mk_func_decl

C API: Z3_mk_rec_func_decl (z3_api.h, auto)

Propositional Logic and Equality (11)

mk_and

def mk_and(self, a: Ast, b: Ast) raises -> Ast
def mk_and(self, args: List[Ast]) raises -> Ast

Create an AST node representing args[0] and ... and args[num_args-1].

The array args must have num_args elements. All arguments must have Boolean sort.

Note: The number of arguments must be greater than zero.

C API: Z3_mk_and (z3_api.h, manual)

mk_distinct

def mk_distinct(self, args: List[Ast]) raises -> Ast

Create an AST node representing distinct(args[0], ..., args[num_args-1]).

The distinct construct is used for declaring the arguments pairwise distinct. That is, Forall 0 <= i < j < num_args. not args[i] = args[j].

All arguments must have the same sort.

Note: The number of arguments of a distinct construct must be greater than one.

C API: Z3_mk_distinct (z3_api.h, manual)

mk_eq

def mk_eq(self, a: Ast, b: Ast) raises -> Ast

Create an AST node representing l = r.

The nodes l and r must have the same type.

C API: Z3_mk_eq (z3_api.h, manual)

mk_false

def mk_false(self) raises -> Ast

Create an AST node representing false.

C API: Z3_mk_false (z3_api.h, manual)

mk_iff

def mk_iff(self, a: Ast, b: Ast) raises -> Ast

Create an AST node representing t1 iff t2.

The nodes t1 and t2 must have Boolean sort.

C API: Z3_mk_iff (z3_api.h, manual)

mk_implies

def mk_implies(self, a: Ast, b: Ast) raises -> Ast

Create an AST node representing t1 implies t2.

The nodes t1 and t2 must have Boolean sort.

C API: Z3_mk_implies (z3_api.h, manual)

mk_ite

def mk_ite(self, cond: Ast, then_t: Ast, else_t: Ast) raises -> Ast

Create an AST node representing an if-then-else: ite(t1, t2, t3).

The node t1 must have Boolean sort, t2 and t3 must have the same sort. The sort of the new node is equal to the sort of t2 and t3.

C API: Z3_mk_ite (z3_api.h, manual)

mk_not

def mk_not(self, a: Ast) raises -> Ast

Create an AST node representing not(a).

The node a must have Boolean sort.

C API: Z3_mk_not (z3_api.h, manual)

mk_or

def mk_or(self, a: Ast, b: Ast) raises -> Ast
def mk_or(self, args: List[Ast]) raises -> Ast

Create an AST node representing args[0] or ... or args[num_args-1].

The array args must have num_args elements. All arguments must have Boolean sort.

Note: The number of arguments must be greater than zero.

C API: Z3_mk_or (z3_api.h, manual)

mk_true

def mk_true(self) raises -> Ast

Create an AST node representing true.

C API: Z3_mk_true (z3_api.h, manual)

mk_xor

def mk_xor(self, a: Ast, b: Ast) raises -> Ast

Create an AST node representing t1 xor t2.

The nodes t1 and t2 must have Boolean sort.

C API: Z3_mk_xor (z3_api.h, manual)

Integers and Reals (17)

mk_abs

def mk_abs(self, arg: Ast) raises -> Ast

Take the absolute value of an integer

C API: Z3_mk_abs (z3_api.h, auto)

mk_add

def mk_add(self, a: Ast, b: Ast) raises -> Ast
def mk_add(self, args: List[Ast]) raises -> Ast

Create an AST node representing args[0] + ... + args[num_args-1].

The array args must have num_args elements. All arguments must have Int, Real, or Complex sort.

Note: The number of arguments must be greater than zero.

C API: Z3_mk_add (z3_api.h, manual)

mk_div

def mk_div(self, a: Ast, b: Ast) raises -> Ast

Create an AST node representing arg1 div arg2.

The arguments must have Int, Real, or Complex sort. Int arguments use integer division. Real and Complex arguments use their respective division operations, with Int embedded in Real and Int/Real embedded in Complex. Complex division is lowered to Real component division; at a zero Complex denominator, both components are the same totalized Real 0/0 value.

C API: Z3_mk_div (z3_api.h, manual)

mk_divides

def mk_divides(self, t1: Ast, t2: Ast) raises -> Ast

Create division predicate.

The nodes t1 and t2 must be of integer sort. The predicate is true when t1 divides t2. For the predicate to be part of linear integer arithmetic, the first argument t1 must be a non-zero integer.

C API: Z3_mk_divides (z3_api.h, auto)

mk_ge

def mk_ge(self, a: Ast, b: Ast) raises -> Ast

Create greater than or equal to.

The nodes t1 and t2 must have the same sort, and must be int or real.

C API: Z3_mk_ge (z3_api.h, manual)

mk_gt

def mk_gt(self, a: Ast, b: Ast) raises -> Ast

Create greater than.

The nodes t1 and t2 must have the same sort, and must be int or real.

C API: Z3_mk_gt (z3_api.h, manual)

mk_int2real

def mk_int2real(self, a: Ast) raises -> Ast

Coerce an integer to a real.

There is also a converse operation exposed. It follows the semantics prescribed by the SMT-LIB standard.

You can take the floor of a real by creating an auxiliary integer constant k and and asserting mk_int2real(k) <= t1 < mk_int2real(k)+1.

The node t1 must have sort integer.

See also: Context.mk_real2int, Context.mk_is_int

C API: Z3_mk_int2real (z3_api.h, manual)

mk_is_int

def mk_is_int(self, a: Ast) raises -> Ast

Check if a real number is an integer.

See also: Context.mk_int2real, Context.mk_real2int

C API: Z3_mk_is_int (z3_api.h, manual)

mk_le

def mk_le(self, a: Ast, b: Ast) raises -> Ast

Create less than or equal to.

The nodes t1 and t2 must have the same sort, and must be int or real.

C API: Z3_mk_le (z3_api.h, manual)

mk_lt

def mk_lt(self, a: Ast, b: Ast) raises -> Ast

Create less than.

The nodes t1 and t2 must have the same sort, and must be int or real.

C API: Z3_mk_lt (z3_api.h, manual)

mk_mod

def mk_mod(self, a: Ast, b: Ast) raises -> Ast

Create an AST node representing arg1 mod arg2.

The arguments must have int type.

C API: Z3_mk_mod (z3_api.h, manual)

mk_mul

def mk_mul(self, a: Ast, b: Ast) raises -> Ast
def mk_mul(self, args: List[Ast]) raises -> Ast

Create an AST node representing args[0] * ... * args[num_args-1].

The array args must have num_args elements. All arguments must have Int, Real, or Complex sort.

Notes:

  • Z3 has limited support for non-linear arithmetic.
  • The number of arguments must be greater than zero.

C API: Z3_mk_mul (z3_api.h, manual)

mk_neg

def mk_neg(self, a: Ast) raises -> Ast

Create an AST node representing - arg.

The argument must have Int, Real, or Complex sort.

C API: Z3_mk_unary_minus (z3_api.h, manual)

mk_pow

def mk_pow(self, base: Ast, exp: Ast) raises -> Ast

Create an AST node representing arg1 ^ arg2.

The arguments must have int or real type.

C API: Z3_mk_power (z3_api.h, manual)

mk_real2int

def mk_real2int(self, a: Ast) raises -> Ast

Coerce a real to an integer.

The semantics of this function follows the SMT-LIB standard for the function to_int

See also: Context.mk_int2real, Context.mk_is_int

C API: Z3_mk_real2int (z3_api.h, manual)

mk_rem

def mk_rem(self, a: Ast, b: Ast) raises -> Ast

Create an AST node representing arg1 rem arg2.

The arguments must have int type.

C API: Z3_mk_rem (z3_api.h, manual)

mk_sub

def mk_sub(self, a: Ast, b: Ast) raises -> Ast

Create an AST node representing args[0] - ... - args[num_args - 1].

The array args must have num_args elements. All arguments must have Int, Real, or Complex sort.

Note: The number of arguments must be greater than zero.

C API: Z3_mk_sub (z3_api.h, manual)

Bit-vectors (49)

mk_bit2bool

def mk_bit2bool(self, i: UInt32, t1: Ast) raises -> Ast

Extracts the bit at position i of a bit-vector and yields a boolean.

The node t1 must have a bit-vector sort.

C API: Z3_mk_bit2bool (z3_api.h, auto)

mk_bv2int

def mk_bv2int(self, t1: Ast, is_signed: Bool) raises -> Ast

Create an integer from the bit-vector argument t1. If is_signed is false, then the bit-vector t1 is treated as unsigned. So the result is non-negative and in the range [0..2^N-1], where N are the number of bits in t1. If is_signed is true, t1 is treated as a signed bit-vector.

The node t1 must have a bit-vector sort.

C API: Z3_mk_bv2int (z3_api.h, auto)

mk_bvadd

def mk_bvadd(self, a: Ast, b: Ast) raises -> Ast

Standard two's complement addition.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvadd (z3_api.h, manual)

mk_bvadd_no_overflow

def mk_bvadd_no_overflow(self, t1: Ast, t2: Ast, is_signed: Bool) raises -> Ast

Create a predicate that checks that the bit-wise addition of t1 and t2 does not overflow.

The nodes t1 and t2 must have the same bit-vector sort. The returned node is of sort Bool.

C API: Z3_mk_bvadd_no_overflow (z3_api.h, auto)

mk_bvadd_no_underflow

def mk_bvadd_no_underflow(self, t1: Ast, t2: Ast) raises -> Ast

Create a predicate that checks that the bit-wise signed addition of t1 and t2 does not underflow.

The nodes t1 and t2 must have the same bit-vector sort. The returned node is of sort Bool.

C API: Z3_mk_bvadd_no_underflow (z3_api.h, auto)

mk_bvand

def mk_bvand(self, a: Ast, b: Ast) raises -> Ast

Bitwise and.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvand (z3_api.h, manual)

mk_bvashr

def mk_bvashr(self, t1: Ast, t2: Ast) raises -> Ast

Arithmetic shift right.

It is like logical shift right except that the most significant bits of the result always copy the most significant bit of the second argument.

The semantics of shift operations varies between environments. This definition does not necessarily capture directly the semantics of the programming language or assembly architecture you are modeling.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvashr (z3_api.h, auto)

mk_bvlshr

def mk_bvlshr(self, t1: Ast, t2: Ast) raises -> Ast

Logical shift right.

It is equivalent to unsigned division by 2^x where x is the value of the third argument.

NB. The semantics of shift operations varies between environments. This definition does not necessarily capture directly the semantics of the programming language or assembly architecture you are modeling.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvlshr (z3_api.h, auto)

mk_bvmul

def mk_bvmul(self, a: Ast, b: Ast) raises -> Ast

Standard two's complement multiplication.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvmul (z3_api.h, manual)

mk_bvmul_no_overflow

def mk_bvmul_no_overflow(self, t1: Ast, t2: Ast, is_signed: Bool) raises -> Ast

Create a predicate that checks that the bit-wise multiplication of t1 and t2 does not overflow.

The nodes t1 and t2 must have the same bit-vector sort. The returned node is of sort Bool.

C API: Z3_mk_bvmul_no_overflow (z3_api.h, auto)

mk_bvmul_no_underflow

def mk_bvmul_no_underflow(self, t1: Ast, t2: Ast) raises -> Ast

Create a predicate that checks that the bit-wise signed multiplication of t1 and t2 does not underflow.

The nodes t1 and t2 must have the same bit-vector sort. The returned node is of sort Bool.

C API: Z3_mk_bvmul_no_underflow (z3_api.h, auto)

mk_bvnand

def mk_bvnand(self, t1: Ast, t2: Ast) raises -> Ast

Bitwise nand.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvnand (z3_api.h, auto)

mk_bvneg

def mk_bvneg(self, a: Ast) raises -> Ast

Standard two's complement unary minus.

The node t1 must have bit-vector sort.

C API: Z3_mk_bvneg (z3_api.h, manual)

mk_bvneg_no_overflow

def mk_bvneg_no_overflow(self, t1: Ast) raises -> Ast

Check that bit-wise negation does not overflow when t1 is interpreted as a signed bit-vector.

The node t1 must have bit-vector sort. The returned node is of sort Bool.

C API: Z3_mk_bvneg_no_overflow (z3_api.h, auto)

mk_bvnor

def mk_bvnor(self, t1: Ast, t2: Ast) raises -> Ast

Bitwise nor.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvnor (z3_api.h, auto)

mk_bvnot

def mk_bvnot(self, a: Ast) raises -> Ast

Bitwise negation.

The node t1 must have a bit-vector sort.

C API: Z3_mk_bvnot (z3_api.h, manual)

mk_bvor

def mk_bvor(self, a: Ast, b: Ast) raises -> Ast

Bitwise or.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvor (z3_api.h, manual)

mk_bvredand

def mk_bvredand(self, t1: Ast) raises -> Ast

Take conjunction of bits in vector, return vector of length 1.

The node t1 must have a bit-vector sort.

C API: Z3_mk_bvredand (z3_api.h, auto)

mk_bvredor

def mk_bvredor(self, t1: Ast) raises -> Ast

Take disjunction of bits in vector, return vector of length 1.

The node t1 must have a bit-vector sort.

C API: Z3_mk_bvredor (z3_api.h, auto)

mk_bvsdiv

def mk_bvsdiv(self, t1: Ast, t2: Ast) raises -> Ast

Two's complement signed division.

It is defined in the following way:

  • The floor of t1/t2 if t2 is different from zero, and t1*t2 >= 0.

  • The ceiling of t1/t2 if t2 is different from zero, and t1*t2 < 0.

If t2 is zero, then the result is undefined.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvsdiv (z3_api.h, auto)

mk_bvsdiv_no_overflow

def mk_bvsdiv_no_overflow(self, t1: Ast, t2: Ast) raises -> Ast

Create a predicate that checks that the bit-wise signed division of t1 and t2 does not overflow.

The nodes t1 and t2 must have the same bit-vector sort. The returned node is of sort Bool.

C API: Z3_mk_bvsdiv_no_overflow (z3_api.h, auto)

mk_bvsge

def mk_bvsge(self, t1: Ast, t2: Ast) raises -> Ast

Two's complement signed greater than or equal to.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvsge (z3_api.h, auto)

mk_bvsgt

def mk_bvsgt(self, t1: Ast, t2: Ast) raises -> Ast

Two's complement signed greater than.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvsgt (z3_api.h, auto)

mk_bvshl

def mk_bvshl(self, t1: Ast, t2: Ast) raises -> Ast

Shift left.

It is equivalent to multiplication by 2^x where x is the value of the third argument.

NB. The semantics of shift operations varies between environments. This definition does not necessarily capture directly the semantics of the programming language or assembly architecture you are modeling.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvshl (z3_api.h, auto)

mk_bvsle

def mk_bvsle(self, a: Ast, b: Ast) raises -> Ast

Two's complement signed less than or equal to.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvsle (z3_api.h, manual)

mk_bvslt

def mk_bvslt(self, a: Ast, b: Ast) raises -> Ast

Two's complement signed less than.

It abbreviates:

(or (and (= (extract[|m-1|:|m-1|] t1) bit1)
        (= (extract[|m-1|:|m-1|] t2) bit0))
    (and (= (extract[|m-1|:|m-1|] t1) (extract[|m-1|:|m-1|] t2))
        (bvult t1 t2)))

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvslt (z3_api.h, manual)

mk_bvsmod

def mk_bvsmod(self, t1: Ast, t2: Ast) raises -> Ast

Two's complement signed remainder (sign follows divisor).

If t2 is zero, then the result is undefined.

The nodes t1 and t2 must have the same bit-vector sort.

See also: Context.mk_bvsrem

C API: Z3_mk_bvsmod (z3_api.h, auto)

mk_bvsrem

def mk_bvsrem(self, t1: Ast, t2: Ast) raises -> Ast

Two's complement signed remainder (sign follows dividend).

It is defined as t1 - (t1 /s t2) * t2, where /s represents signed division. The most significant bit (sign) of the result is equal to the most significant bit of t1.

If t2 is zero, then the result is undefined.

The nodes t1 and t2 must have the same bit-vector sort.

See also: Context.mk_bvsmod

C API: Z3_mk_bvsrem (z3_api.h, auto)

mk_bvsub

def mk_bvsub(self, a: Ast, b: Ast) raises -> Ast

Standard two's complement subtraction.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvsub (z3_api.h, manual)

mk_bvsub_no_overflow

def mk_bvsub_no_overflow(self, t1: Ast, t2: Ast) raises -> Ast

Create a predicate that checks that the bit-wise signed subtraction of t1 and t2 does not overflow.

The nodes t1 and t2 must have the same bit-vector sort. The returned node is of sort Bool.

C API: Z3_mk_bvsub_no_overflow (z3_api.h, auto)

mk_bvsub_no_underflow

def mk_bvsub_no_underflow(self, t1: Ast, t2: Ast, is_signed: Bool) raises -> Ast

Create a predicate that checks that the bit-wise subtraction of t1 and t2 does not underflow.

The nodes t1 and t2 must have the same bit-vector sort. The returned node is of sort Bool.

C API: Z3_mk_bvsub_no_underflow (z3_api.h, auto)

mk_bvudiv

def mk_bvudiv(self, t1: Ast, t2: Ast) raises -> Ast

Unsigned division.

It is defined as the floor of t1/t2 if t2 is different from zero. If t2 is zero, then the result is undefined.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvudiv (z3_api.h, auto)

mk_bvuge

def mk_bvuge(self, t1: Ast, t2: Ast) raises -> Ast

Unsigned greater than or equal to.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvuge (z3_api.h, auto)

mk_bvugt

def mk_bvugt(self, t1: Ast, t2: Ast) raises -> Ast

Unsigned greater than.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvugt (z3_api.h, auto)

mk_bvule

def mk_bvule(self, a: Ast, b: Ast) raises -> Ast

Unsigned less than or equal to.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvule (z3_api.h, manual)

mk_bvult

def mk_bvult(self, a: Ast, b: Ast) raises -> Ast

Unsigned less than.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvult (z3_api.h, manual)

mk_bvurem

def mk_bvurem(self, t1: Ast, t2: Ast) raises -> Ast

Unsigned remainder.

It is defined as t1 - (t1 /u t2) * t2, where /u represents unsigned division.

If t2 is zero, then the result is undefined.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvurem (z3_api.h, auto)

mk_bvxnor

def mk_bvxnor(self, t1: Ast, t2: Ast) raises -> Ast

Bitwise xnor.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvxnor (z3_api.h, auto)

mk_bvxor

def mk_bvxor(self, a: Ast, b: Ast) raises -> Ast

Bitwise exclusive-or.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_bvxor (z3_api.h, manual)

mk_concat

def mk_concat(self, a: Ast, b: Ast) raises -> Ast

Concatenate the given bit-vectors.

The nodes t1 and t2 must have (possibly different) bit-vector sorts

The result is a bit-vector of size n1+n2, where n1 (n2) is the size of t1 (t2).

C API: Z3_mk_concat (z3_api.h, manual)

mk_ext_rotate_left

def mk_ext_rotate_left(self, t1: Ast, t2: Ast) raises -> Ast

Rotate bits of t1 to the left t2 times.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_ext_rotate_left (z3_api.h, auto)

mk_ext_rotate_right

def mk_ext_rotate_right(self, t1: Ast, t2: Ast) raises -> Ast

Rotate bits of t1 to the right t2 times.

The nodes t1 and t2 must have the same bit-vector sort.

C API: Z3_mk_ext_rotate_right (z3_api.h, auto)

mk_extract

def mk_extract(self, high: Int, low: Int, a: Ast) raises -> Ast

Extract the bits high down to low from a bit-vector of size m to yield a new bit-vector of size n, where n = high - low + 1.

The node t1 must have a bit-vector sort.

C API: Z3_mk_extract (z3_api.h, manual)

mk_int2bv

def mk_int2bv(self, n: UInt32, t1: Ast) raises -> Ast

Create an n bit bit-vector from the integer argument t1.

The resulting bit-vector has n bits, where the i'th bit (counting from 0 to n-1) is 1 if (t1 div 2^i) mod 2 is 1.

The node t1 must have integer sort.

C API: Z3_mk_int2bv (z3_api.h, auto)

mk_repeat

def mk_repeat(self, i: UInt32, t1: Ast) raises -> Ast

Repeat the given bit-vector up length i.

The node t1 must have a bit-vector sort.

C API: Z3_mk_repeat (z3_api.h, auto)

mk_rotate_left

def mk_rotate_left(self, i: UInt32, t1: Ast) raises -> Ast

Rotate bits of t1 to the left i times.

The node t1 must have a bit-vector sort.

C API: Z3_mk_rotate_left (z3_api.h, auto)

mk_rotate_right

def mk_rotate_right(self, i: UInt32, t1: Ast) raises -> Ast

Rotate bits of t1 to the right i times.

The node t1 must have a bit-vector sort.

C API: Z3_mk_rotate_right (z3_api.h, auto)

mk_sign_ext

def mk_sign_ext(self, i: UInt32, t1: Ast) raises -> Ast

Sign-extend of the given bit-vector to the (signed) equivalent bit-vector of size m+i, where m is the size of the given bit-vector.

The node t1 must have a bit-vector sort.

C API: Z3_mk_sign_ext (z3_api.h, auto)

mk_zero_ext

def mk_zero_ext(self, i: UInt32, t1: Ast) raises -> Ast

Extend the given bit-vector with zeros to the (unsigned) equivalent bit-vector of size m+i, where m is the size of the given bit-vector.

The node t1 must have a bit-vector sort.

C API: Z3_mk_zero_ext (z3_api.h, auto)

Arrays (8)

mk_array_default

def mk_array_default(self, array: Ast) raises -> Ast

Access the array default value. Produces the default range value, for arrays that can be represented as finite maps with a default range value.

Parameters:

  • c — logical context.
  • array — array value whose default range value is accessed.

C API: Z3_mk_array_default (z3_api.h, auto)

mk_as_array

def mk_as_array(self, f: FuncDecl) raises -> Ast

Create array with the same interpretation as a function. The array satisfies the property (f x) = (select (_ as-array f) x) for every argument x.

C API: Z3_mk_as_array (z3_api.h, auto)

mk_const_array

def mk_const_array(self, domain: Sort, v: Ast) raises -> Ast

Create the constant array.

The resulting term is an array, such that a select on an arbitrary index produces the value v.

Parameters:

  • c — logical context.
  • domain — domain sort for the array.
  • v — value that the array maps to.

C API: Z3_mk_const_array (z3_api.h, auto)

mk_map

def mk_map(self, f: FuncDecl, args: List[Ast]) raises -> Ast

Map f on the argument arrays.

The n nodes args must be of array sorts [domain_i -> range_i]. The function declaration f must have type range_1 .. range_n -> range. v must have sort range. The sort of the result is [domain_i -> range].

See also: Context.array_sort, Context.mk_store, Context.mk_select

C API: Z3_mk_map (z3_api.h, auto)

mk_select

def mk_select(self, arr: Ast, idx: Ast) raises -> Ast

Array read. The argument a is the array and i is the index of the array that gets read.

The node a must have an array sort [domain -> range], and i must have the sort domain. The sort of the result is range.

See also: Context.array_sort, Context.mk_store

C API: Z3_mk_select (z3_api.h, manual)

mk_select_n

def mk_select_n(self, a: Ast, idxs: List[Ast]) raises -> Ast

n-ary Array read. The argument a is the array and idxs are the indices of the array that gets read.

C API: Z3_mk_select_n (z3_api.h, auto)

mk_store

def mk_store(self, arr: Ast, idx: Ast, val: Ast) raises -> Ast

Array update.

The node a must have an array sort [domain -> range], i must have sort domain, v must have sort range. The sort of the result is [domain -> range]. The semantics of this function is given by the theory of arrays described in the SMT-LIB standard. See http://smtlib.org for more details. The result of this function is an array that is equal to a (with respect to select) on all indices except for i, where it maps to v (and the select of a with respect to i may be a different value).

See also: Context.array_sort, Context.mk_select

C API: Z3_mk_store (z3_api.h, manual)

mk_store_n

def mk_store_n(self, a: Ast, idxs: List[Ast], v: Ast) raises -> Ast

n-ary Array update.

C API: Z3_mk_store_n (z3_api.h, auto)

Sets (12)

mk_array_ext

def mk_array_ext(self, arg1: Ast, arg2: Ast) raises -> Ast

Create array extensionality index given two arrays with the same sort. The meaning is given by the axiom: (=> (= (select A (array-ext A B)) (select B (array-ext A B))) (= A B))

C API: Z3_mk_array_ext (z3_api.h, auto)

mk_empty_set

def mk_empty_set(self, domain: Sort) raises -> Ast

Create the empty set.

C API: Z3_mk_empty_set (z3_api.h, auto)

mk_full_set

def mk_full_set(self, domain: Sort) raises -> Ast

Create the full set.

C API: Z3_mk_full_set (z3_api.h, auto)

mk_set_add

def mk_set_add(self, set: Ast, elem: Ast) raises -> Ast

Add an element to a set.

The first argument must be a set, the second an element.

C API: Z3_mk_set_add (z3_api.h, auto)

mk_set_complement

def mk_set_complement(self, arg: Ast) raises -> Ast

Take the complement of a set.

C API: Z3_mk_set_complement (z3_api.h, auto)

mk_set_del

def mk_set_del(self, set: Ast, elem: Ast) raises -> Ast

Remove an element to a set.

The first argument must be a set, the second an element.

C API: Z3_mk_set_del (z3_api.h, auto)

mk_set_difference

def mk_set_difference(self, arg1: Ast, arg2: Ast) raises -> Ast

Take the set difference between two sets.

C API: Z3_mk_set_difference (z3_api.h, auto)

mk_set_intersect

def mk_set_intersect(self, args: List[Ast]) raises -> Ast

Take the intersection of a list of sets.

C API: Z3_mk_set_intersect (z3_api.h, auto)

mk_set_member

def mk_set_member(self, elem: Ast, set: Ast) raises -> Ast

Check for set membership.

The first argument should be an element type of the set.

C API: Z3_mk_set_member (z3_api.h, auto)

mk_set_sort

def mk_set_sort(self, ty: Sort) raises -> Sort

Create Set type.

C API: Z3_mk_set_sort (z3_api.h, auto)

mk_set_subset

def mk_set_subset(self, arg1: Ast, arg2: Ast) raises -> Ast

Check for subsetness of sets.

C API: Z3_mk_set_subset (z3_api.h, auto)

mk_set_union

def mk_set_union(self, args: List[Ast]) raises -> Ast

Take the union of a list of sets.

C API: Z3_mk_set_union (z3_api.h, auto)

Finite Sets (14)

get_finite_set_sort_basis

def get_finite_set_sort_basis(self, s: Sort) raises -> Sort

Get the element sort of a finite set sort.

C API: Z3_get_finite_set_sort_basis (z3_api.h, auto)

is_finite_set_sort

def is_finite_set_sort(self, s: Sort) raises -> Bool

Check if a sort is a finite set sort.

C API: Z3_is_finite_set_sort (z3_api.h, auto)

mk_finite_set_difference

def mk_finite_set_difference(self, s1: Ast, s2: Ast) raises -> Ast

Create the set difference of two finite sets.

C API: Z3_mk_finite_set_difference (z3_api.h, auto)

mk_finite_set_empty

def mk_finite_set_empty(self, set_sort: Sort) raises -> Ast

Create an empty finite set of the given sort.

C API: Z3_mk_finite_set_empty (z3_api.h, auto)

mk_finite_set_filter

def mk_finite_set_filter(self, f: Ast, set: Ast) raises -> Ast

Filter a finite set using a predicate.

C API: Z3_mk_finite_set_filter (z3_api.h, auto)

mk_finite_set_intersect

def mk_finite_set_intersect(self, s1: Ast, s2: Ast) raises -> Ast

Create the intersection of two finite sets.

C API: Z3_mk_finite_set_intersect (z3_api.h, auto)

mk_finite_set_map

def mk_finite_set_map(self, f: Ast, set: Ast) raises -> Ast

Apply a function to all elements of a finite set.

C API: Z3_mk_finite_set_map (z3_api.h, auto)

mk_finite_set_member

def mk_finite_set_member(self, elem: Ast, set: Ast) raises -> Ast

Check if an element is a member of a finite set.

C API: Z3_mk_finite_set_member (z3_api.h, auto)

mk_finite_set_range

def mk_finite_set_range(self, low: Ast, high: Ast) raises -> Ast

Create a finite set of integers in the range [low, high].

C API: Z3_mk_finite_set_range (z3_api.h, auto)

mk_finite_set_singleton

def mk_finite_set_singleton(self, elem: Ast) raises -> Ast

Create a singleton finite set.

C API: Z3_mk_finite_set_singleton (z3_api.h, auto)

mk_finite_set_size

def mk_finite_set_size(self, set: Ast) raises -> Ast

Get the size (cardinality) of a finite set.

C API: Z3_mk_finite_set_size (z3_api.h, auto)

mk_finite_set_sort

def mk_finite_set_sort(self, elem_sort: Sort) raises -> Sort

Create a finite set sort.

C API: Z3_mk_finite_set_sort (z3_api.h, auto)

mk_finite_set_subset

def mk_finite_set_subset(self, s1: Ast, s2: Ast) raises -> Ast

Check if one finite set is a subset of another.

C API: Z3_mk_finite_set_subset (z3_api.h, auto)

mk_finite_set_union

def mk_finite_set_union(self, s1: Ast, s2: Ast) raises -> Ast

Create the union of two finite sets.

C API: Z3_mk_finite_set_union (z3_api.h, auto)

Numerals (8)

Z3_mk_int

def Z3_mk_int(self, v: Int32, ty: Sort) raises -> Ast

Create a numeral of an int, bit-vector, or finite-domain sort.

This function can be used to create numerals that fit in a machine integer. It is slightly faster than Z3_mk_numeral since it is not necessary to parse a string.

See also: Context.mk_numeral

C API: Z3_mk_int (z3_api.h, auto)

mk_bv_numeral

def mk_bv_numeral(self, bits: List[Bool]) raises -> Ast

create a bit-vector numeral from a vector of Booleans.

See also: Context.mk_numeral

C API: Z3_mk_bv_numeral (z3_api.h, auto)

mk_int

def mk_int(self, val: Int) raises -> Ast

Create a numeral of a int, bit-vector, or finite-domain sort.

This function can be used to create numerals that fit in a machine int64_t integer. It is slightly faster than Z3_mk_numeral since it is not necessary to parse a string.

See also: Context.mk_numeral

C API: Z3_mk_int64 (z3_api.h, manual)

mk_numeral

def mk_numeral(self, numeral: String, sort: Sort) raises -> Ast

Create a numeral of a given sort.

Parameters:

  • c — logical context.
  • numeral — A string representing the numeral value in decimal notation. The string may be of the form [num]*[.[num]*][E[+|-][num]+]. If the given sort is a real, then the numeral can be a rational, that is, a string of the form [num]* / [num]* .
  • ty — The sort of the numeral. In the current implementation, the given sort can be an int, real, finite-domain, or bit-vectors of arbitrary size.

See also: Context.Z3_mk_int, Context.mk_unsigned_int

C API: Z3_mk_numeral (z3_api.h, manual)

mk_real

def mk_real(self, val: Int) raises -> Ast
def mk_real(self, val: Rational) raises -> Ast

Create a real from a fraction of int64.

Create an exact arbitrary-precision Z3 Real numeral from apn_mojo.Rational.

See also: Context.mk_real_frac

C API: Z3_mk_real_int64 (z3_api.h, manual)

mk_real_frac

def mk_real_frac(self, num: Int, den: Int) raises -> Ast

Create a real from a fraction.

Parameters:

  • c — logical context.
  • num — numerator of rational.
  • den — denominator of rational.

Precondition: den != 0

See also: Context.mk_numeral, Context.Z3_mk_int, Context.mk_real, Context.mk_unsigned_int

C API: Z3_mk_real (z3_api.h, manual)

mk_unsigned_int

def mk_unsigned_int(self, v: UInt32, ty: Sort) raises -> Ast

Create a numeral of a int, bit-vector, or finite-domain sort.

This function can be used to create numerals that fit in a machine unsigned integer. It is slightly faster than Z3_mk_numeral since it is not necessary to parse a string.

See also: Context.mk_numeral

C API: Z3_mk_unsigned_int (z3_api.h, auto)

mk_unsigned_int64

def mk_unsigned_int64(self, v: UInt64, ty: Sort) raises -> Ast

Create a numeral of a int, bit-vector, or finite-domain sort.

This function can be used to create numerals that fit in a machine uint64_t integer. It is slightly faster than Z3_mk_numeral since it is not necessary to parse a string.

See also: Context.mk_numeral

C API: Z3_mk_unsigned_int64 (z3_api.h, auto)

Sequences and regular expressions (69)

get_lstring

def get_lstring(self, s: Ast) raises -> List[UInt8]

Retrieve the string constant stored in s. The string can contain escape sequences. Characters in the range 1 to 255 are literal. Characters in the range 0, and 256 above are escaped.

Precondition: Z3_is_string(c, s)

C API: Z3_get_lstring (z3_api.h, manual)

get_re_sort_basis

def get_re_sort_basis(self, s: Sort) raises -> Sort

Retrieve basis sort for regex sort.

C API: Z3_get_re_sort_basis (z3_api.h, auto)

get_seq_sort_basis

def get_seq_sort_basis(self, s: Sort) raises -> Sort

Retrieve basis sort for sequence sort.

C API: Z3_get_seq_sort_basis (z3_api.h, auto)

get_string

def get_string(self, s: Ast) raises -> String

Retrieve the string constant stored in s. Characters outside the basic printable ASCII range are escaped.

Precondition: Z3_is_string(c, s)

C API: Z3_get_string (z3_api.h, auto)

get_string_contents

def get_string_contents(self, s: Ast) raises -> List[UInt32]

Retrieve the unescaped string constant stored in s.

Preconditions:

  • Z3_is_string(c, s)
  • length contains the number of characters in s

C API: Z3_get_string_contents (z3_api.h, manual)

get_string_length

def get_string_length(self, s: Ast) raises -> UInt32

Retrieve the length of the unescaped string constant stored in s.

Precondition: Z3_is_string(c, s)

C API: Z3_get_string_length (z3_api.h, auto)

is_char_sort

def is_char_sort(self, s: Sort) raises -> Bool

Check if s is a character sort.

C API: Z3_is_char_sort (z3_api.h, auto)

is_re_sort

def is_re_sort(self, s: Sort) raises -> Bool

Check if s is a regular expression sort.

C API: Z3_is_re_sort (z3_api.h, auto)

is_seq_sort

def is_seq_sort(self, s: Sort) raises -> Bool

Check if s is a sequence sort.

C API: Z3_is_seq_sort (z3_api.h, auto)

is_string

def is_string(self, s: Ast) raises -> Bool

Determine if s is a string constant.

C API: Z3_is_string (z3_api.h, auto)

is_string_sort

def is_string_sort(self, s: Sort) raises -> Bool

Check if s is a string sort.

C API: Z3_is_string_sort (z3_api.h, auto)

mk_char

def mk_char(self, ch: UInt32) raises -> Ast

Create a character literal

C API: Z3_mk_char (z3_api.h, auto)

mk_char_from_bv

def mk_char_from_bv(self, bv: Ast) raises -> Ast

Create a character from a bit-vector (code point).

C API: Z3_mk_char_from_bv (z3_api.h, auto)

mk_char_is_digit

def mk_char_is_digit(self, ch: Ast) raises -> Ast

Create a check if the character is a digit.

C API: Z3_mk_char_is_digit (z3_api.h, auto)

mk_char_le

def mk_char_le(self, ch1: Ast, ch2: Ast) raises -> Ast

Create less than or equal to between two characters.

C API: Z3_mk_char_le (z3_api.h, auto)

mk_char_sort

def mk_char_sort(self) raises -> Sort

Create a sort for unicode characters.

The sort for characters can be changed to ASCII by setting the global parameter encoding to ascii, or alternative to 16 bit characters by setting encoding to bmp.

C API: Z3_mk_char_sort (z3_api.h, auto)

mk_char_to_bv

def mk_char_to_bv(self, ch: Ast) raises -> Ast

Create a bit-vector (code point) from character.

C API: Z3_mk_char_to_bv (z3_api.h, auto)

mk_char_to_int

def mk_char_to_int(self, ch: Ast) raises -> Ast

Create an integer (code point) from character.

C API: Z3_mk_char_to_int (z3_api.h, auto)

mk_int_to_str

def mk_int_to_str(self, s: Ast) raises -> Ast

Integer to string conversion.

C API: Z3_mk_int_to_str (z3_api.h, auto)

mk_lstring

def mk_lstring(self, len_: UInt32, s: String) raises -> Ast

Create a string constant out of the string that is passed in It takes the length of the string as well to take into account 0 characters. The string is treated as if it is unescaped so a sequence of characters \u{0} is treated as 5 characters and not the character 0.

C API: Z3_mk_lstring (z3_api.h, auto)

mk_re_allchar

def mk_re_allchar(self, regex_sort: Sort) raises -> Ast

Create a regular expression that accepts all singleton sequences of the regular expression sort

C API: Z3_mk_re_allchar (z3_api.h, auto)

mk_re_complement

def mk_re_complement(self, re: Ast) raises -> Ast

Create the complement of the regular language re.

C API: Z3_mk_re_complement (z3_api.h, auto)

mk_re_concat

def mk_re_concat(self, args: List[Ast]) raises -> Ast

Create the concatenation of the regular languages.

Precondition: n > 0

C API: Z3_mk_re_concat (z3_api.h, auto)

mk_re_diff

def mk_re_diff(self, re1: Ast, re2: Ast) raises -> Ast

Create the difference of regular expressions.

C API: Z3_mk_re_diff (z3_api.h, auto)

mk_re_empty

def mk_re_empty(self, re: Sort) raises -> Ast

Create an empty regular expression of sort re.

Precondition: re is a regular expression sort.

C API: Z3_mk_re_empty (z3_api.h, auto)

mk_re_full

def mk_re_full(self, re: Sort) raises -> Ast

Create an universal regular expression of sort re.

Precondition: re is a regular expression sort.

C API: Z3_mk_re_full (z3_api.h, auto)

mk_re_intersect

def mk_re_intersect(self, args: List[Ast]) raises -> Ast

Create the intersection of the regular languages.

Precondition: n > 0

C API: Z3_mk_re_intersect (z3_api.h, auto)

mk_re_loop

def mk_re_loop(self, r: Ast, lo: UInt32, hi: UInt32) raises -> Ast

Create a regular expression loop. The supplied regular expression r is repeated between lo and hi times. The lo should be below hi with one exception: when supplying the value hi as 0, the meaning is to repeat the argument r at least lo number of times, and with an unbounded upper bound.

C API: Z3_mk_re_loop (z3_api.h, auto)

mk_re_option

def mk_re_option(self, re: Ast) raises -> Ast

Create the regular language [re].

C API: Z3_mk_re_option (z3_api.h, auto)

mk_re_plus

def mk_re_plus(self, re: Ast) raises -> Ast

Create the regular language re+.

C API: Z3_mk_re_plus (z3_api.h, auto)

mk_re_power

def mk_re_power(self, re: Ast, n: UInt32) raises -> Ast

Create a power regular expression.

C API: Z3_mk_re_power (z3_api.h, auto)

mk_re_range

def mk_re_range(self, lo: Ast, hi: Ast) raises -> Ast

Create the range regular expression over two sequences of length 1.

C API: Z3_mk_re_range (z3_api.h, auto)

mk_re_sort

def mk_re_sort(self, seq: Sort) raises -> Sort

Create a regular expression sort out of a sequence sort.

C API: Z3_mk_re_sort (z3_api.h, auto)

mk_re_star

def mk_re_star(self, re: Ast) raises -> Ast

Create the regular language re*.

C API: Z3_mk_re_star (z3_api.h, auto)

mk_re_union

def mk_re_union(self, args: List[Ast]) raises -> Ast

Create the union of the regular languages.

Precondition: n > 0

C API: Z3_mk_re_union (z3_api.h, auto)

mk_sbv_to_str

def mk_sbv_to_str(self, s: Ast) raises -> Ast

Signed bit-vector to string conversion.

C API: Z3_mk_sbv_to_str (z3_api.h, auto)

mk_seq_at

def mk_seq_at(self, s: Ast, index: Ast) raises -> Ast

Retrieve from s the unit sequence positioned at position index. The sequence is empty if the index is out of bounds.

C API: Z3_mk_seq_at (z3_api.h, auto)

mk_seq_concat

def mk_seq_concat(self, args: List[Ast]) raises -> Ast

Concatenate sequences.

Precondition: n > 0

C API: Z3_mk_seq_concat (z3_api.h, auto)

mk_seq_contains

def mk_seq_contains(self, container: Ast, containee: Ast) raises -> Ast

Check if container contains containee.

Precondition: container and containee are the same sequence sorts.

C API: Z3_mk_seq_contains (z3_api.h, auto)

mk_seq_empty

def mk_seq_empty(self, seq: Sort) raises -> Ast

Create an empty sequence of the sequence sort seq.

Precondition: s is a sequence sort.

C API: Z3_mk_seq_empty (z3_api.h, auto)

mk_seq_extract

def mk_seq_extract(self, s: Ast, offset: Ast, length: Ast) raises -> Ast

Extract subsequence starting at offset of length.

C API: Z3_mk_seq_extract (z3_api.h, auto)

mk_seq_foldl

def mk_seq_foldl(self, f: Ast, a: Ast, s: Ast) raises -> Ast

Create a fold of the function f over the sequence s with accumulator a.

C API: Z3_mk_seq_foldl (z3_api.h, auto)

mk_seq_foldli

def mk_seq_foldli(self, f: Ast, i: Ast, a: Ast, s: Ast) raises -> Ast

Create a fold with index tracking of the function f over the sequence s with accumulator a starting at index i.

C API: Z3_mk_seq_foldli (z3_api.h, auto)

mk_seq_in_re

def mk_seq_in_re(self, seq: Ast, re: Ast) raises -> Ast

Check if seq is in the language generated by the regular expression re.

C API: Z3_mk_seq_in_re (z3_api.h, auto)

mk_seq_index

def mk_seq_index(self, s: Ast, substr: Ast, offset: Ast) raises -> Ast

Return index of the first occurrence of substr in s starting from offset offset. If s does not contain substr, then the value is -1, if offset is the length of s, then the value is -1 as well. The value is -1 if offset is negative or larger than the length of s.

C API: Z3_mk_seq_index (z3_api.h, auto)

mk_seq_last_index

def mk_seq_last_index(self, s: Ast, substr: Ast) raises -> Ast

Return index of the last occurrence of substr in s. If s does not contain substr, then the value is -1,

C API: Z3_mk_seq_last_index (z3_api.h, auto)

mk_seq_length

def mk_seq_length(self, s: Ast) raises -> Ast

Return the length of the sequence s.

C API: Z3_mk_seq_length (z3_api.h, auto)

mk_seq_map

def mk_seq_map(self, f: Ast, s: Ast) raises -> Ast

Create a map of the function f over the sequence s.

C API: Z3_mk_seq_map (z3_api.h, auto)

mk_seq_mapi

def mk_seq_mapi(self, f: Ast, i: Ast, s: Ast) raises -> Ast

Create a map of the function f over the sequence s starting at index i.

C API: Z3_mk_seq_mapi (z3_api.h, auto)

mk_seq_nth

def mk_seq_nth(self, s: Ast, index: Ast) raises -> Ast

Retrieve from s the element positioned at position index. The function is under-specified if the index is out of bounds.

C API: Z3_mk_seq_nth (z3_api.h, auto)

mk_seq_power

def mk_seq_power(self, s: Ast, n: Ast) raises -> Ast

Create the sequence s concatenated n times with itself. The result is the empty sequence when n is not positive.

C API: Z3_mk_seq_power (z3_api.h, auto)

mk_seq_prefix

def mk_seq_prefix(self, prefix: Ast, s: Ast) raises -> Ast

Check if prefix is a prefix of s.

Precondition: prefix and s are the same sequence sorts.

C API: Z3_mk_seq_prefix (z3_api.h, auto)

mk_seq_replace

def mk_seq_replace(self, s: Ast, src: Ast, dst: Ast) raises -> Ast

Replace the first occurrence of src with dst in s.

C API: Z3_mk_seq_replace (z3_api.h, auto)

mk_seq_replace_all

def mk_seq_replace_all(self, s: Ast, src: Ast, dst: Ast) raises -> Ast

Replace all occurrences of src with dst in s.

C API: Z3_mk_seq_replace_all (z3_api.h, auto)

mk_seq_replace_re

def mk_seq_replace_re(self, s: Ast, re: Ast, dst: Ast) raises -> Ast

Replace the first occurrence of regular expression re with dst in s.

C API: Z3_mk_seq_replace_re (z3_api.h, auto)

mk_seq_replace_re_all

def mk_seq_replace_re_all(self, s: Ast, re: Ast, dst: Ast) raises -> Ast

Replace all occurrences of regular expression re with dst in s.

C API: Z3_mk_seq_replace_re_all (z3_api.h, auto)

mk_seq_sort

def mk_seq_sort(self, s: Sort) raises -> Sort

Create a sequence sort out of the sort for the elements.

C API: Z3_mk_seq_sort (z3_api.h, auto)

mk_seq_suffix

def mk_seq_suffix(self, suffix: Ast, s: Ast) raises -> Ast

Check if suffix is a suffix of s.

Precondition: suffix and s are the same sequence sorts.

C API: Z3_mk_seq_suffix (z3_api.h, auto)

mk_seq_to_re

def mk_seq_to_re(self, seq: Ast) raises -> Ast

Create a regular expression that accepts the sequence seq.

C API: Z3_mk_seq_to_re (z3_api.h, auto)

mk_seq_unit

def mk_seq_unit(self, a: Ast) raises -> Ast

Create a unit sequence of a.

C API: Z3_mk_seq_unit (z3_api.h, auto)

mk_str_le

def mk_str_le(self, prefix: Ast, s: Ast) raises -> Ast

Check if s1 is equal or lexicographically strictly less than s2.

Precondition: s1 and s2 are strings

C API: Z3_mk_str_le (z3_api.h, auto)

mk_str_lt

def mk_str_lt(self, prefix: Ast, s: Ast) raises -> Ast

Check if s1 is lexicographically strictly less than s2.

Precondition: s1 and s2 are strings

C API: Z3_mk_str_lt (z3_api.h, auto)

mk_str_to_int

def mk_str_to_int(self, s: Ast) raises -> Ast

Convert string to integer.

C API: Z3_mk_str_to_int (z3_api.h, auto)

mk_string

def mk_string(self, s: String) raises -> Ast

Create a string constant out of the string that is passed in The string may contain escape encoding for non-printable characters or characters outside of the basic printable ASCII range. For example, the escape encoding \u{0} represents the character 0 and the encoding \u{100} represents the character 256.

C API: Z3_mk_string (z3_api.h, auto)

mk_string_from_code

def mk_string_from_code(self, a: Ast) raises -> Ast

Code to string conversion.

C API: Z3_mk_string_from_code (z3_api.h, auto)

mk_string_to_code

def mk_string_to_code(self, a: Ast) raises -> Ast

String to code conversion.

C API: Z3_mk_string_to_code (z3_api.h, auto)

mk_u32string

def mk_u32string(self, chars: List[UInt32]) raises -> Ast

Create a string constant out of the string that is passed in It takes the length of the string as well to take into account 0 characters. The string is unescaped.

C API: Z3_mk_u32string (z3_api.h, auto)

mk_ubv_to_str

def mk_ubv_to_str(self, s: Ast) raises -> Ast

Unsigned bit-vector to string conversion.

C API: Z3_mk_ubv_to_str (z3_api.h, auto)

string_sort

def string_sort(self) raises -> Sort

Create a sort for unicode strings.

The sort for characters can be changed to ASCII by setting the global parameter encoding to ascii, or alternative to 16 bit characters by setting encoding to bmp.

C API: Z3_mk_string_sort (z3_api.h, manual)

Special relations (5)

mk_linear_order

def mk_linear_order(self, a: Sort, id: UInt32) raises -> FuncDecl

create a linear ordering relation over signature a. The relation is identified by the index id.

C API: Z3_mk_linear_order (z3_api.h, auto)

mk_partial_order

def mk_partial_order(self, a: Sort, id: UInt32) raises -> FuncDecl

create a partial ordering relation over signature a and index id.

C API: Z3_mk_partial_order (z3_api.h, auto)

mk_piecewise_linear_order

def mk_piecewise_linear_order(self, a: Sort, id: UInt32) raises -> FuncDecl

create a piecewise linear ordering relation over signature a and index id.

C API: Z3_mk_piecewise_linear_order (z3_api.h, auto)

mk_transitive_closure

def mk_transitive_closure(self, f: FuncDecl) raises -> FuncDecl

create transitive closure of binary relation.

The resulting relation f+ represents the transitive closure of f.

Precondition: f is a binary relation, such that the two arguments have the same sorts.

C API: Z3_mk_transitive_closure (z3_api.h, auto)

mk_tree_order

def mk_tree_order(self, a: Sort, id: UInt32) raises -> FuncDecl

create a tree ordering relation over signature a identified using index id.

C API: Z3_mk_tree_order (z3_api.h, auto)

Quantifiers (12)

Z3_mk_exists

def Z3_mk_exists(self, weight: UInt32, patterns: List[Pattern], sorts: List[Sort], decl_names: List[Symbol], body: Ast) raises -> Ast

Create an exists formula. Similar to Z3_mk_forall.

Z3_mk_forall

def Z3_mk_forall(self, weight: UInt32, patterns: List[Pattern], sorts: List[Sort], decl_names: List[Symbol], body: Ast) raises -> Ast

Create a forall formula. It takes an expression body that contains bound variables of the same sorts as the sorts listed in the array sorts. The bound variables are de-Bruijn indices created using Z3_mk_bound. The array decl_names contains the names that the quantified formula uses for the bound variables. Z3 applies the convention that the last element in the decl_names and sorts array refers to the variable with index 0, the second to last element of decl_names and sorts refers to the variable with index 1, etc.

Parameters:

  • c — logical context.
  • weight — quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0.
  • num_patterns — number of patterns.
  • patterns — array containing the patterns created using Z3_mk_pattern.
  • num_decls — number of variables to be bound.
  • sorts — the sorts of the bound variables.
  • decl_names — names of the bound variables
  • body — the body of the quantifier.

See also: Context.mk_pattern, Context.mk_bound, Context.Z3_mk_exists

C API: Z3_mk_forall (z3_api.h, auto)

mk_bound

def mk_bound(self, index: UInt32, ty: Sort) raises -> Ast

Create a variable.

Variables are intended to be bound by a scope created by a quantifier. So we call them bound variables even if they appear as free variables in the expression produced by Z3_mk_bound.

Bound variables are indexed by de-Bruijn indices. It is perhaps easiest to explain the meaning of de-Bruijn indices by indicating the compilation process from non-de-Bruijn formulas to de-Bruijn format.

abs(forall (x1) phi) = forall (x1) abs1(phi, x1, 0)
abs(forall (x1, x2) phi) = abs(forall (x1) abs(forall (x2) phi))
abs1(x, x, n) = b_n
abs1(y, x, n) = y
abs1(f(t1,...,tn), x, n) = f(abs1(t1,x,n), ..., abs1(tn,x,n))
abs1(forall (x1) phi, x, n) = forall (x1) (abs1(phi, x, n+1))

The last line is significant: the index of a bound variable is different depending on the scope in which it appears. The deeper x appears, the higher is its index.

Parameters:

  • c — logical context
  • index — de-Bruijn index
  • ty — sort of the bound variable

See also: Context.Z3_mk_forall, Context.Z3_mk_exists

C API: Z3_mk_bound (z3_api.h, auto)

mk_exists

def mk_exists(self, bound_consts: List[Ast], body: Ast) raises -> Ast

Similar to Z3_mk_forall_const.

Create an existential quantifier using a list of constants that will form the set of bound variables.

Parameters:

  • c — logical context.
  • weight — quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0.
  • num_bound — number of constants to be abstracted into bound variables.
  • bound — array of constants to be abstracted into bound variables.
  • num_patterns — number of patterns.
  • patterns — array containing the patterns created using Z3_mk_pattern.
  • body — the body of the quantifier.

See also: Context.mk_pattern, Context.mk_forall

C API: Z3_mk_exists_const (z3_api.h, manual)

mk_forall

def mk_forall(self, bound_consts: List[Ast], body: Ast) raises -> Ast

Create a universal quantifier using a list of constants that will form the set of bound variables.

Parameters:

  • c — logical context.
  • weight — quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0.
  • num_bound — number of constants to be abstracted into bound variables.
  • bound — array of constants to be abstracted into bound variables.
  • num_patterns — number of patterns.
  • patterns — array containing the patterns created using Z3_mk_pattern.
  • body — the body of the quantifier.

See also: Context.mk_pattern, Context.mk_exists

C API: Z3_mk_forall_const (z3_api.h, manual)

mk_lambda

def mk_lambda(self, sorts: List[Sort], decl_names: List[Symbol], body: Ast) raises -> Ast

Create a lambda expression. It takes an expression body that contains bound variables of the same sorts as the sorts listed in the array sorts. The bound variables are de-Bruijn indices created using Z3_mk_bound. The array decl_names contains the names that the quantified formula uses for the bound variables. Z3 applies the convention that the last element in the decl_names and sorts array refers to the variable with index 0, the second to last element of decl_names and sorts refers to the variable with index 1, etc. The sort of the resulting expression is (Array sorts range) where range is the sort of body. For example, if the lambda binds two variables of sort Int and Bool, and the body has sort Real, the sort of the expression is (Array Int Bool Real).

Parameters:

  • c — logical context
  • num_decls — number of variables to be bound.
  • sorts — the sorts of the bound variables.
  • decl_names — names of the bound variables
  • body — the body of the lambda expression.

See also: Context.mk_bound, Context.Z3_mk_forall, Context.mk_lambda_const

C API: Z3_mk_lambda (z3_api.h, auto)

mk_lambda_const

def mk_lambda_const(self, bound: List[App], body: Ast) raises -> Ast

Create a lambda expression using a list of constants that form the set of bound variables

Parameters:

  • c — logical context.
  • num_bound — number of constants to be abstracted into bound variables.
  • bound — array of constants to be abstracted into bound variables.
  • body — the body of the lambda expression.

See also: Context.mk_bound, Context.Z3_mk_forall, Context.mk_lambda

C API: Z3_mk_lambda_const (z3_api.h, auto)

mk_pattern

def mk_pattern(self, terms: List[Ast]) raises -> Pattern

Create a pattern for quantifier instantiation.

Z3 uses pattern matching to instantiate quantifiers. If a pattern is not provided for a quantifier, then Z3 will automatically compute a set of patterns for it. However, for optimal performance, the user should provide the patterns.

Patterns comprise a list of terms. The list should be non-empty. If the list comprises of more than one term, it is a called a multi-pattern.

In general, one can pass in a list of (multi-)patterns in the quantifier constructor.

See also: Context.Z3_mk_forall, Context.Z3_mk_exists

C API: Z3_mk_pattern (z3_api.h, auto)

mk_quantifier

def mk_quantifier(self, is_forall: Bool, weight: UInt32, patterns: List[Pattern], sorts: List[Sort], decl_names: List[Symbol], body: Ast) raises -> Ast

Create a quantifier - universal or existential, with pattern hints. See the documentation for Z3_mk_forall for an explanation of the parameters.

Parameters:

  • c — logical context.
  • is_forall — flag to indicate if this is a universal or existential quantifier.
  • weight — quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0.
  • num_patterns — number of patterns.
  • patterns — array containing the patterns created using Z3_mk_pattern.
  • num_decls — number of variables to be bound.
  • sorts — array of sorts of the bound variables.
  • decl_names — names of the bound variables.
  • body — the body of the quantifier.

See also: Context.mk_pattern, Context.mk_bound, Context.Z3_mk_forall, Context.Z3_mk_exists

C API: Z3_mk_quantifier (z3_api.h, auto)

mk_quantifier_const

def mk_quantifier_const(self, is_forall: Bool, weight: UInt32, bound: List[App], patterns: List[Pattern], body: Ast) raises -> Ast

Create a universal or existential quantifier using a list of constants that will form the set of bound variables.

C API: Z3_mk_quantifier_const (z3_api.h, auto)

mk_quantifier_const_ex

def mk_quantifier_const_ex(self, is_forall: Bool, weight: UInt32, quantifier_id: Symbol, skolem_id: Symbol, bound: List[App], patterns: List[Pattern], no_patterns: List[Ast], body: Ast) raises -> Ast

Create a universal or existential quantifier using a list of constants that will form the set of bound variables.

C API: Z3_mk_quantifier_const_ex (z3_api.h, auto)

mk_quantifier_ex

def mk_quantifier_ex(self, is_forall: Bool, weight: UInt32, quantifier_id: Symbol, skolem_id: Symbol, patterns: List[Pattern], no_patterns: List[Ast], sorts: List[Sort], decl_names: List[Symbol], body: Ast) raises -> Ast

Create a quantifier - universal or existential, with pattern hints, no patterns, and attributes

Parameters:

  • c — logical context.
  • is_forall — flag to indicate if this is a universal or existential quantifier.
  • quantifier_id — identifier to identify quantifier
  • skolem_id — identifier to identify skolem constants introduced by quantifier.
  • weight — quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0.
  • num_patterns — number of patterns.
  • patterns — array containing the patterns created using Z3_mk_pattern.
  • num_no_patterns — number of no_patterns.
  • no_patterns — array containing subexpressions to be excluded from inferred patterns.
  • num_decls — number of variables to be bound.
  • sorts — array of sorts of the bound variables.
  • decl_names — names of the bound variables.
  • body — the body of the quantifier.

See also: Context.mk_pattern, Context.mk_bound, Context.Z3_mk_forall, Context.Z3_mk_exists

C API: Z3_mk_quantifier_ex (z3_api.h, auto)

Accessors (102)

app_to_ast

def app_to_ast(self, a: App) raises -> Ast

Convert a Z3_app into Z3_ast. This is just type casting.

C API: Z3_app_to_ast (z3_api.h, auto)

datatype_update_field

def datatype_update_field(self, field_access: FuncDecl, t: Ast, value: Ast) raises -> Ast

Update record field with a value.

This corresponds to the 'with' construct in OCaml. It has the effect of updating a record field with a given value. The remaining fields are left unchanged. It is the record equivalent of an array store (see Z3_mk_store). If the datatype has more than one constructor, then the update function behaves as identity if there is a mismatch between the accessor and constructor. For example ((_ update-field car) nil 1) is nil, while ((_ update-field car) (cons 2 nil) 1) is (cons 1 nil).

Preconditions:

  • Z3_get_sort_kind(Z3_get_sort(c, t)) == Z3_get_domain(c, field_access, 1) == Z3_DATATYPE_SORT
  • Z3_get_sort(c, value) == Z3_get_range(c, field_access)

See also: Context.mk_store

C API: Z3_datatype_update_field (z3_api.h, auto)

func_decl_to_ast

def func_decl_to_ast(self, f: FuncDecl) raises -> Ast

Convert a Z3_func_decl into Z3_ast. This is just type casting.

C API: Z3_func_decl_to_ast (z3_api.h, auto)

get_algebraic_number_lower

def get_algebraic_number_lower(self, a: Ast, precision: UInt32) raises -> Ast

Return a lower bound for the given real algebraic number. The interval isolating the number is smaller than 1/10^precision. The result is a numeral AST of sort Real.

Precondition: Z3_is_algebraic_number(c, a)

C API: Z3_get_algebraic_number_lower (z3_api.h, auto)

get_algebraic_number_upper

def get_algebraic_number_upper(self, a: Ast, precision: UInt32) raises -> Ast

Return a upper bound for the given real algebraic number. The interval isolating the number is smaller than 1/10^precision. The result is a numeral AST of sort Real.

Precondition: Z3_is_algebraic_number(c, a)

C API: Z3_get_algebraic_number_upper (z3_api.h, auto)

get_app_arg

def get_app_arg(self, a: App, i: UInt32) raises -> Ast

Return the i-th argument of the given application.

Precondition: i < Z3_get_app_num_args(c, a)

See also: Context.get_app_num_args

C API: Z3_get_app_arg (z3_api.h, auto)

get_app_decl

def get_app_decl(self, a: App) raises -> FuncDecl

Return the declaration of a constant or function application.

C API: Z3_get_app_decl (z3_api.h, auto)

get_app_num_args

def get_app_num_args(self, a: App) raises -> UInt32

Return the number of argument of an application. If t is an constant, then the number of arguments is 0.

See also: Context.get_app_arg

C API: Z3_get_app_num_args (z3_api.h, auto)

get_arity

def get_arity(self, d: FuncDecl) raises -> UInt32

Alias for Z3_get_domain_size.

See also: Context.get_domain_size

C API: Z3_get_arity (z3_api.h, auto)

get_array_arity

def get_array_arity(self, s: Sort) raises -> UInt32

Return the arity (number of dimensions) of the given array sort.

Precondition: Z3_get_sort_kind(s) == Z3_ARRAY_SORT

See also: Context.get_array_sort_domain_n

C API: Z3_get_array_arity (z3_api.h, auto)

get_array_sort_domain

def get_array_sort_domain(self, t: Sort) raises -> Sort

Return the domain of the given array sort. In the case of a multi-dimensional array, this function returns the sort of the first dimension.

Precondition: Z3_get_sort_kind(c, t) == Z3_ARRAY_SORT

See also: Context.array_sort, Context.get_sort_kind, Context.get_array_sort_domain_n

C API: Z3_get_array_sort_domain (z3_api.h, auto)

get_array_sort_domain_n

def get_array_sort_domain_n(self, t: Sort, idx: UInt32) raises -> Sort

Return the i'th domain sort of an n-dimensional array.

Precondition: Z3_get_sort_kind(c, t) == Z3_ARRAY_SORT

See also: Context.array_sort, Context.get_sort_kind, Context.get_array_sort_domain

C API: Z3_get_array_sort_domain_n (z3_api.h, auto)

get_array_sort_range

def get_array_sort_range(self, t: Sort) raises -> Sort

Return the range of the given array sort.

Precondition: Z3_get_sort_kind(c, t) == Z3_ARRAY_SORT

See also: Context.array_sort, Context.get_sort_kind

C API: Z3_get_array_sort_range (z3_api.h, auto)

get_ast_hash

def get_ast_hash(self, a: Ast) raises -> UInt32

Return a hash code for the given AST. The hash code is structural but two different AST objects can map to the same hash. The result of Z3_get_ast_id returns an identifier that is unique over the set of live AST objects.

C API: Z3_get_ast_hash (z3_api.h, auto)

get_ast_id

def get_ast_id(self, t: Ast) raises -> UInt32

Return a unique identifier for t. The identifier is unique up to structural equality. Thus, two ast nodes created by the same context and having the same children and same function symbols have the same identifiers. Ast nodes created in the same context, but having different children or different functions have different identifiers. Variables and quantifiers are also assigned different identifiers according to their structure.

C API: Z3_get_ast_id (z3_api.h, auto)

get_ast_kind

def get_ast_kind(self, a: Ast) raises -> AstKind

Return the kind of the given AST.

C API: Z3_get_ast_kind (z3_api.h, auto)

get_bool_value

def get_bool_value(self, a: Ast) raises -> Lbool

Return Z3_L_TRUE if a is true, Z3_L_FALSE if it is false, and Z3_L_UNDEF otherwise.

C API: Z3_get_bool_value (z3_api.h, auto)

get_bv_sort_size

def get_bv_sort_size(self, t: Sort) raises -> UInt32

Return the size of the given bit-vector sort.

Precondition: Z3_get_sort_kind(c, t) == Z3_BV_SORT

See also: Context.bv_sort, Context.get_sort_kind

C API: Z3_get_bv_sort_size (z3_api.h, auto)

get_datatype_sort_constructor

def get_datatype_sort_constructor(self, t: Sort, idx: UInt32) raises -> FuncDecl

Return idx'th constructor.

Preconditions:

  • Z3_get_sort_kind(t) == Z3_DATATYPE_SORT
  • idx < Z3_get_datatype_sort_num_constructors(c, t)

See also: Context.get_datatype_sort_num_constructors, Context.get_datatype_sort_recognizer, Context.get_datatype_sort_constructor_accessor

C API: Z3_get_datatype_sort_constructor (z3_api.h, auto)

get_datatype_sort_constructor_accessor

def get_datatype_sort_constructor_accessor(self, t: Sort, idx_c: UInt32, idx_a: UInt32) raises -> FuncDecl

Return idx_a'th accessor for the idx_c'th constructor.

Preconditions:

  • Z3_get_sort_kind(t) == Z3_DATATYPE_SORT
  • idx_c < Z3_get_datatype_sort_num_constructors(c, t)
  • idx_a < Z3_get_domain_size(c, Z3_get_datatype_sort_constructor(c, idx_c))

See also: Context.get_datatype_sort_num_constructors, Context.get_datatype_sort_constructor, Context.get_datatype_sort_recognizer

C API: Z3_get_datatype_sort_constructor_accessor (z3_api.h, auto)

get_datatype_sort_num_constructors

def get_datatype_sort_num_constructors(self, t: Sort) raises -> UInt32

Return number of constructors for datatype.

get_datatype_sort_recognizer

def get_datatype_sort_recognizer(self, t: Sort, idx: UInt32) raises -> FuncDecl

Return idx'th recognizer.

Preconditions:

  • Z3_get_sort_kind(t) == Z3_DATATYPE_SORT
  • idx < Z3_get_datatype_sort_num_constructors(c, t)

See also: Context.get_datatype_sort_num_constructors, Context.get_datatype_sort_constructor, Context.get_datatype_sort_constructor_accessor

C API: Z3_get_datatype_sort_recognizer (z3_api.h, auto)

get_decl_ast_parameter

def get_decl_ast_parameter(self, d: FuncDecl, idx: UInt32) raises -> Ast

Return the expression value associated with an expression parameter.

Precondition: Z3_get_decl_parameter_kind(c, d, idx) == Z3_PARAMETER_AST

C API: Z3_get_decl_ast_parameter (z3_api.h, auto)

get_decl_double_parameter

def get_decl_double_parameter(self, d: FuncDecl, idx: UInt32) raises -> Float64

Return the double value associated with an double parameter.

Precondition: Z3_get_decl_parameter_kind(c, d, idx) == Z3_PARAMETER_DOUBLE

C API: Z3_get_decl_double_parameter (z3_api.h, auto)

get_decl_func_decl_parameter

def get_decl_func_decl_parameter(self, d: FuncDecl, idx: UInt32) raises -> FuncDecl

Return the expression value associated with an expression parameter.

Precondition: Z3_get_decl_parameter_kind(c, d, idx) == Z3_PARAMETER_FUNC_DECL

C API: Z3_get_decl_func_decl_parameter (z3_api.h, auto)

get_decl_int_parameter

def get_decl_int_parameter(self, d: FuncDecl, idx: UInt32) raises -> Int32

Return the integer value associated with an integer parameter.

Precondition: Z3_get_decl_parameter_kind(c, d, idx) == Z3_PARAMETER_INT

C API: Z3_get_decl_int_parameter (z3_api.h, auto)

get_decl_kind

def get_decl_kind(self, d: FuncDecl) raises -> DeclKind

Return declaration kind corresponding to declaration.

C API: Z3_get_decl_kind (z3_api.h, auto)

get_decl_name

def get_decl_name(self, d: FuncDecl) raises -> Symbol

Return the constant declaration name as a symbol.

C API: Z3_get_decl_name (z3_api.h, auto)

get_decl_num_parameters

def get_decl_num_parameters(self, d: FuncDecl) raises -> UInt32

Return the number of parameters associated with a declaration.

C API: Z3_get_decl_num_parameters (z3_api.h, auto)

get_decl_parameter_kind

def get_decl_parameter_kind(self, d: FuncDecl, idx: UInt32) raises -> ParameterKind

Return the parameter type associated with a declaration.

Parameters:

  • c — the context
  • d — the function declaration
  • idx — is the index of the named parameter it should be between 0 and the number of parameters.

C API: Z3_get_decl_parameter_kind (z3_api.h, auto)

get_decl_rational_parameter

def get_decl_rational_parameter(self, d: FuncDecl, idx: UInt32) raises -> String

Return the rational value, as a string, associated with a rational parameter.

Precondition: Z3_get_decl_parameter_kind(c, d, idx) == Z3_PARAMETER_RATIONAL

C API: Z3_get_decl_rational_parameter (z3_api.h, auto)

get_decl_sort_parameter

def get_decl_sort_parameter(self, d: FuncDecl, idx: UInt32) raises -> Sort

Return the sort value associated with a sort parameter.

Precondition: Z3_get_decl_parameter_kind(c, d, idx) == Z3_PARAMETER_SORT

C API: Z3_get_decl_sort_parameter (z3_api.h, auto)

get_decl_symbol_parameter

def get_decl_symbol_parameter(self, d: FuncDecl, idx: UInt32) raises -> Symbol

Return the double value associated with an double parameter.

Precondition: Z3_get_decl_parameter_kind(c, d, idx) == Z3_PARAMETER_SYMBOL

C API: Z3_get_decl_symbol_parameter (z3_api.h, auto)

get_denominator

def get_denominator(self, a: Ast) raises -> Ast

Return the denominator (as a numeral AST) of a numeral AST of sort Real.

Precondition: Z3_get_ast_kind(c, a) == Z3_NUMERAL_AST

C API: Z3_get_denominator (z3_api.h, auto)

get_depth

def get_depth(self, a: Ast) raises -> UInt32

Safe wrapper for Z3_get_depth.

C API: Z3_get_depth (z3_api.h, auto)

get_domain

def get_domain(self, d: FuncDecl, i: UInt32) raises -> Sort

Return the sort of the i-th parameter of the given function declaration.

Precondition: i < Z3_get_domain_size(d)

See also: Context.get_domain_size

C API: Z3_get_domain (z3_api.h, auto)

get_domain_size

def get_domain_size(self, d: FuncDecl) raises -> UInt32

Return the number of parameters of the given declaration.

See also: Context.get_arity

C API: Z3_get_domain_size (z3_api.h, auto)

get_finite_domain_sort_size

def get_finite_domain_sort_size(self, s: Sort) raises -> Optional[UInt64]

Store the size of the sort in r. Return false if the call failed. That is, Z3_get_sort_kind(s) == Z3_FINITE_DOMAIN_SORT

C API: Z3_get_finite_domain_sort_size (z3_api.h, auto)

get_func_decl_id

def get_func_decl_id(self, f: FuncDecl) raises -> UInt32

Return a unique identifier for f.

C API: Z3_get_func_decl_id (z3_api.h, auto)

get_index_value

def get_index_value(self, a: Ast) raises -> UInt32

Return index of de-Bruijn bound variable.

Precondition: Z3_get_ast_kind(a) == Z3_VAR_AST

C API: Z3_get_index_value (z3_api.h, auto)

get_numeral_binary_string

def get_numeral_binary_string(self, a: Ast) raises -> String

Return numeral value, as a binary string of a numeric constant term

Preconditions:

  • Z3_get_ast_kind(c, a) == Z3_NUMERAL_AST
  • a represents a non-negative integer

C API: Z3_get_numeral_binary_string (z3_api.h, auto)

get_numeral_decimal_string

def get_numeral_decimal_string(self, a: Ast, precision: UInt32) raises -> String

Return numeral as a string in decimal notation. The result has at most precision decimal places.

Precondition: Z3_get_ast_kind(c, a) == Z3_NUMERAL_AST || Z3_is_algebraic_number(c, a)

C API: Z3_get_numeral_decimal_string (z3_api.h, auto)

get_numeral_double

def get_numeral_double(self, a: Ast) raises -> Float64

Return numeral as a double.

Precondition: Z3_get_ast_kind(c, a) == Z3_NUMERAL_AST || Z3_is_algebraic_number(c, a)

C API: Z3_get_numeral_double (z3_api.h, auto)

get_numeral_int

def get_numeral_int(self, v: Ast) raises -> Optional[Int32]

Similar to Z3_get_numeral_string, but only succeeds if the value can fit in a machine int. Return true if the call succeeded.

Precondition: Z3_get_ast_kind(c, v) == Z3_NUMERAL_AST

See also: Context.get_numeral_string

C API: Z3_get_numeral_int (z3_api.h, auto)

get_numeral_int64

def get_numeral_int64(self, v: Ast) raises -> Optional[Int64]

Similar to Z3_get_numeral_string, but only succeeds if the value can fit in a machine int64_t int. Return true if the call succeeded.

Precondition: Z3_get_ast_kind(c, v) == Z3_NUMERAL_AST

See also: Context.get_numeral_string

C API: Z3_get_numeral_int64 (z3_api.h, auto)

get_numeral_rational_int64

def get_numeral_rational_int64(self, v: Ast) raises -> Optional[Tuple[Int64, Int64]]

Similar to Z3_get_numeral_string, but only succeeds if the value can fit as a rational number as machine int64_t int. Return true if the call succeeded.

Precondition: Z3_get_ast_kind(c, v) == Z3_NUMERAL_AST

See also: Context.get_numeral_string

C API: Z3_get_numeral_rational_int64 (z3_api.h, auto)

get_numeral_small

def get_numeral_small(self, a: Ast) raises -> Optional[Tuple[Int64, Int64]]

Return numeral value, as a pair of 64 bit numbers if the representation fits.

Return true if the numeral value fits in 64 bit numerals, false otherwise.

Equivalent to Z3_get_numeral_rational_int64 except that for unsupported expression arguments Z3_get_numeral_small signals an error while Z3_get_numeral_rational_int64 returns false.

Parameters:

  • c — logical context.
  • a — term.
  • num — numerator.
  • den — denominator.

Precondition: Z3_get_ast_kind(a) == Z3_NUMERAL_AST

C API: Z3_get_numeral_small (z3_api.h, auto)

get_numeral_string

def get_numeral_string(self, a: Ast) raises -> String

Return numeral value, as a decimal string of a numeric constant term

Precondition: Z3_get_ast_kind(c, a) == Z3_NUMERAL_AST

C API: Z3_get_numeral_string (z3_api.h, auto)

get_numeral_uint

def get_numeral_uint(self, v: Ast) raises -> Optional[UInt32]

Similar to Z3_get_numeral_string, but only succeeds if the value can fit in a machine unsigned int. Return true if the call succeeded.

Precondition: Z3_get_ast_kind(c, v) == Z3_NUMERAL_AST

See also: Context.get_numeral_string

C API: Z3_get_numeral_uint (z3_api.h, auto)

get_numeral_uint64

def get_numeral_uint64(self, v: Ast) raises -> Optional[UInt64]

Similar to Z3_get_numeral_string, but only succeeds if the value can fit in a machine uint64_t int. Return true if the call succeeded.

Precondition: Z3_get_ast_kind(c, v) == Z3_NUMERAL_AST

See also: Context.get_numeral_string

C API: Z3_get_numeral_uint64 (z3_api.h, auto)

get_numerator

def get_numerator(self, a: Ast) raises -> Ast

Return the numerator (as a numeral AST) of a numeral AST of sort Real.

Precondition: Z3_get_ast_kind(c, a) == Z3_NUMERAL_AST

C API: Z3_get_numerator (z3_api.h, auto)

get_pattern

def get_pattern(self, p: Pattern, idx: UInt32) raises -> Ast

Return i'th ast in pattern.

C API: Z3_get_pattern (z3_api.h, auto)

get_pattern_num_terms

def get_pattern_num_terms(self, p: Pattern) raises -> UInt32

Return number of terms in pattern.

C API: Z3_get_pattern_num_terms (z3_api.h, auto)

get_quantifier_body

def get_quantifier_body(self, a: Ast) raises -> Ast

Return body of quantifier.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_body (z3_api.h, auto)

get_quantifier_bound_name

def get_quantifier_bound_name(self, a: Ast, i: UInt32) raises -> Symbol

Return symbol of the i'th bound variable.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_bound_name (z3_api.h, auto)

get_quantifier_bound_sort

def get_quantifier_bound_sort(self, a: Ast, i: UInt32) raises -> Sort

Return sort of the i'th bound variable.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_bound_sort (z3_api.h, auto)

get_quantifier_id

def get_quantifier_id(self, a: Ast) raises -> Symbol

Obtain id of quantifier.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_id (z3_api.h, auto)

get_quantifier_no_pattern_ast

def get_quantifier_no_pattern_ast(self, a: Ast, i: UInt32) raises -> Ast

Return i'th no_pattern.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_no_pattern_ast (z3_api.h, auto)

get_quantifier_num_bound

def get_quantifier_num_bound(self, a: Ast) raises -> UInt32

Return number of bound variables of quantifier.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_num_bound (z3_api.h, auto)

get_quantifier_num_no_patterns

def get_quantifier_num_no_patterns(self, a: Ast) raises -> UInt32

Return number of no_patterns used in quantifier.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_num_no_patterns (z3_api.h, auto)

get_quantifier_num_patterns

def get_quantifier_num_patterns(self, a: Ast) raises -> UInt32

Return number of patterns used in quantifier.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_num_patterns (z3_api.h, auto)

get_quantifier_pattern_ast

def get_quantifier_pattern_ast(self, a: Ast, i: UInt32) raises -> Pattern

Return i'th pattern.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_pattern_ast (z3_api.h, auto)

get_quantifier_skolem_id

def get_quantifier_skolem_id(self, a: Ast) raises -> Symbol

Obtain skolem id of quantifier.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_skolem_id (z3_api.h, auto)

get_quantifier_weight

def get_quantifier_weight(self, a: Ast) raises -> UInt32

Obtain weight of quantifier.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_get_quantifier_weight (z3_api.h, auto)

get_range

def get_range(self, d: FuncDecl) raises -> Sort

Return the range of the given declaration.

If d is a constant (i.e., has zero arguments), then this function returns the sort of the constant.

C API: Z3_get_range (z3_api.h, auto)

get_relation_arity

def get_relation_arity(self, s: Sort) raises -> UInt32

Return arity of relation.

Precondition: Z3_get_sort_kind(s) == Z3_RELATION_SORT

See also: Context.get_relation_column

C API: Z3_get_relation_arity (z3_api.h, auto)

get_relation_column

def get_relation_column(self, s: Sort, col: UInt32) raises -> Sort

Return sort at i'th column of relation sort.

Preconditions:

  • Z3_get_sort_kind(c, s) == Z3_RELATION_SORT
  • col < Z3_get_relation_arity(c, s)

See also: Context.get_relation_arity

C API: Z3_get_relation_column (z3_api.h, auto)

get_sort

def get_sort(self, a: Ast) raises -> Sort

Return the sort of an AST node.

The AST node must be a constant, application, numeral, bound variable, or quantifier.

C API: Z3_get_sort (z3_api.h, auto)

get_sort_id

def get_sort_id(self, s: Sort) raises -> UInt32

Return a unique identifier for s.

C API: Z3_get_sort_id (z3_api.h, auto)

get_sort_kind

def get_sort_kind(self, t: Sort) raises -> SortKind

Return the sort kind (e.g., array, tuple, int, bool, etc).

See also: Z3_sort_kind

C API: Z3_get_sort_kind (z3_api.h, auto)

get_sort_name

def get_sort_name(self, d: Sort) raises -> Symbol

Return the sort name as a symbol.

C API: Z3_get_sort_name (z3_api.h, auto)

get_symbol_int

def get_symbol_int(self, s: Symbol) raises -> Int32

Return the symbol int value.

Precondition: Z3_get_symbol_kind(s) == Z3_INT_SYMBOL

See also: Context.mk_int_symbol

C API: Z3_get_symbol_int (z3_api.h, auto)

get_symbol_kind

def get_symbol_kind(self, s: Symbol) raises -> SymbolKind

Return Z3_INT_SYMBOL if the symbol was constructed using Z3_mk_int_symbol, and Z3_STRING_SYMBOL if the symbol was constructed using Z3_mk_string_symbol.

C API: Z3_get_symbol_kind (z3_api.h, auto)

get_symbol_string

def get_symbol_string(self, s: Symbol) raises -> String

Return the symbol name.

Precondition: Z3_get_symbol_kind(s) == Z3_STRING_SYMBOL

Warning: The returned buffer is statically allocated by Z3. It will be automatically deallocated when Z3_del_context is invoked. So, the buffer is invalidated in the next call to Z3_get_symbol_string.

See also: Context.mk_symbol

C API: Z3_get_symbol_string (z3_api.h, auto)

get_tuple_sort_field_decl

def get_tuple_sort_field_decl(self, t: Sort, i: UInt32) raises -> FuncDecl

Return the i-th field declaration (i.e., projection function declaration) of the given tuple sort.

Preconditions:

  • Z3_get_sort_kind(t) == Z3_DATATYPE_SORT
  • i < Z3_get_tuple_sort_num_fields(c, t)

See also: Context.mk_tuple_sort, Context.get_sort_kind

C API: Z3_get_tuple_sort_field_decl (z3_api.h, auto)

get_tuple_sort_mk_decl

def get_tuple_sort_mk_decl(self, t: Sort) raises -> FuncDecl

Return the constructor declaration of the given tuple sort.

Precondition: Z3_get_sort_kind(c, t) == Z3_DATATYPE_SORT

See also: Context.mk_tuple_sort, Context.get_sort_kind

C API: Z3_get_tuple_sort_mk_decl (z3_api.h, auto)

get_tuple_sort_num_fields

def get_tuple_sort_num_fields(self, t: Sort) raises -> UInt32

Return the number of fields of the given tuple sort.

Precondition: Z3_get_sort_kind(c, t) == Z3_DATATYPE_SORT

See also: Context.mk_tuple_sort, Context.get_sort_kind

C API: Z3_get_tuple_sort_num_fields (z3_api.h, auto)

is_algebraic_number

def is_algebraic_number(self, a: Ast) raises -> Bool

Return true if the given AST is a real algebraic number.

C API: Z3_is_algebraic_number (z3_api.h, auto)

is_app

def is_app(self, a: Ast) raises -> Bool

Safe wrapper for Z3_is_app.

C API: Z3_is_app (z3_api.h, auto)

is_eq_ast

def is_eq_ast(self, t1: Ast, t2: Ast) raises -> Bool

Compare terms.

C API: Z3_is_eq_ast (z3_api.h, auto)

is_eq_func_decl

def is_eq_func_decl(self, f1: FuncDecl, f2: FuncDecl) raises -> Bool

Compare terms.

C API: Z3_is_eq_func_decl (z3_api.h, auto)

is_eq_sort

def is_eq_sort(self, s1: Sort, s2: Sort) raises -> Bool

compare sorts.

C API: Z3_is_eq_sort (z3_api.h, auto)

is_ground

def is_ground(self, a: Ast) raises -> Bool

Safe wrapper for Z3_is_ground.

C API: Z3_is_ground (z3_api.h, auto)

is_lambda

def is_lambda(self, a: Ast) raises -> Bool

Determine if ast is a lambda expression.

Precondition: Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST

C API: Z3_is_lambda (z3_api.h, auto)

is_numeral_ast

def is_numeral_ast(self, a: Ast) raises -> Bool

Safe wrapper for Z3_is_numeral_ast.

C API: Z3_is_numeral_ast (z3_api.h, auto)

is_quantifier_exists

def is_quantifier_exists(self, a: Ast) raises -> Bool

Determine if ast is an existential quantifier.

C API: Z3_is_quantifier_exists (z3_api.h, auto)

is_quantifier_forall

def is_quantifier_forall(self, a: Ast) raises -> Bool

Determine if an ast is a universal quantifier.

C API: Z3_is_quantifier_forall (z3_api.h, auto)

is_recursive_datatype_sort

def is_recursive_datatype_sort(self, s: Sort) raises -> Bool

Check if s is a recursive datatype sort.

C API: Z3_is_recursive_datatype_sort (z3_api.h, auto)

is_well_sorted

def is_well_sorted(self, t: Ast) raises -> Bool

Return true if the given expression t is well sorted.

C API: Z3_is_well_sorted (z3_api.h, auto)

mk_atleast

def mk_atleast(self, args: List[Ast], k: UInt32) raises -> Ast

Pseudo-Boolean relations.

Encode p1 + p2 + ... + pn >= k

C API: Z3_mk_atleast (z3_api.h, auto)

mk_atmost

def mk_atmost(self, args: List[Ast], k: UInt32) raises -> Ast

Pseudo-Boolean relations.

Encode p1 + p2 + ... + pn <= k

C API: Z3_mk_atmost (z3_api.h, auto)

mk_pbeq

def mk_pbeq(self, args: List[Ast], coeffs: List[Int32], k: Int32) raises -> Ast

Pseudo-Boolean relations.

Encode k1p1 + k2p2 + ... + kn*pn = k

C API: Z3_mk_pbeq (z3_api.h, auto)

mk_pbge

def mk_pbge(self, args: List[Ast], coeffs: List[Int32], k: Int32) raises -> Ast

Pseudo-Boolean relations.

Encode k1p1 + k2p2 + ... + kn*pn >= k

C API: Z3_mk_pbge (z3_api.h, auto)

mk_pble

def mk_pble(self, args: List[Ast], coeffs: List[Int32], k: Int32) raises -> Ast

Pseudo-Boolean relations.

Encode k1p1 + k2p2 + ... + kn*pn <= k

C API: Z3_mk_pble (z3_api.h, auto)

pattern_to_ast

def pattern_to_ast(self, p: Pattern) raises -> Ast

Convert a Z3_pattern into Z3_ast. This is just type casting.

C API: Z3_pattern_to_ast (z3_api.h, auto)

simplify

def simplify(self, a: Ast) raises -> Ast

Interface to simplifier.

Provides an interface to the AST simplifier used by Z3. It returns an AST object which is equal to the argument. The returned AST is simplified using algebraic simplification rules, such as constant propagation (propagating true/false over logical connectives).

See also: Context.simplify_ex

C API: Z3_simplify (z3_api.h, auto)

simplify_ex

def simplify_ex(self, a: Ast, p: Params) raises -> Ast

Interface to simplifier.

Provides an interface to the AST simplifier used by Z3. This procedure is similar to Z3_simplify, but the behavior of the simplifier can be configured using the given parameter set.

simplify_get_help

def simplify_get_help(self) raises -> String

Return a string describing all available parameters.

simplify_get_param_descrs

def simplify_get_param_descrs(self) raises -> ParamDescrs

Return the parameter description set for the simplify procedure.

sort_to_ast

def sort_to_ast(self, s: Sort) raises -> Ast

Convert a Z3_sort into Z3_ast. This is just type casting.

C API: Z3_sort_to_ast (z3_api.h, auto)

to_app

def to_app(self, a: Ast) raises -> App

Convert an ast into an APP_AST. This is just type casting.

Precondition: Z3_get_ast_kind(c, a) == \c Z3_APP_AST

C API: Z3_to_app (z3_api.h, auto)

to_func_decl

def to_func_decl(self, a: Ast) raises -> FuncDecl

Convert an AST into a FUNC_DECL_AST. This is just type casting.

Precondition: Z3_get_ast_kind(c, a) == Z3_FUNC_DECL_AST

C API: Z3_to_func_decl (z3_api.h, auto)

Modifiers (5)

substitute

def substitute(self, a: Ast, from_: List[Ast], to: List[Ast]) raises -> Ast

Substitute every occurrence of from[i] in a with to[i], for i smaller than num_exprs. The result is the new AST. The arrays from and to must have size num_exprs. For every i smaller than num_exprs, we must have that sort of from[i] must be equal to sort of to[i].

C API: Z3_substitute (z3_api.h, auto)

substitute_funs

def substitute_funs(self, a: Ast, from_: List[FuncDecl], to: List[Ast]) raises -> Ast

Substitute functions in from with new expressions in to.

The expressions in to can have free variables. The free variable in to at index 0 refers to the first argument of from, the free variable at index 1 corresponds to the second argument.

C API: Z3_substitute_funs (z3_api.h, auto)

substitute_vars

def substitute_vars(self, a: Ast, to: List[Ast]) raises -> Ast

Substitute the variables in a with the expressions in to. For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. Note that a variable is created using the function Z3_mk_bound.

C API: Z3_substitute_vars (z3_api.h, auto)

translate

def translate(self, a: Ast, target: Context) raises -> Ast

Translate/Copy the AST a from context source to context target. AST a must have been created using context source.

Precondition: source != target

C API: Z3_translate (z3_api.h, auto)

update_term

def update_term(self, a: Ast, args: List[Ast]) raises -> Ast

Update the arguments of term a using the arguments args. The number of arguments num_args should coincide with the number of arguments to a. If a is a quantifier, then num_args has to be 1.

C API: Z3_update_term (z3_api.h, auto)

Models (5)

add_const_interp

def add_const_interp(self, m: Model, f: FuncDecl, a: Ast) raises

Add a constant interpretation.

C API: Z3_add_const_interp (z3_api.h, auto)

add_func_interp

def add_func_interp(self, m: Model, f: FuncDecl, default_value: Ast) raises -> FuncInterp

Create a fresh func_interp object, add it to a model for a specified function. It has reference count 0.

Parameters:

  • c — context
  • m — model
  • f — function declaration
  • default_value — default value for function interpretation

C API: Z3_add_func_interp (z3_api.h, auto)

get_as_array_func_decl

def get_as_array_func_decl(self, a: Ast) raises -> FuncDecl

Return the function declaration f associated with a (_ as_array f) node.

See also: Context.is_as_array

C API: Z3_get_as_array_func_decl (z3_api.h, auto)

is_as_array

def is_as_array(self, a: Ast) raises -> Bool

The (_ as-array f) AST node is a construct for assigning interpretations for arrays in Z3. It is the array such that forall indices i we have that (select (_ as-array f) i) is equal to (f i). This procedure returns true if the a is an as-array AST node.

Z3 current solvers have minimal support for as_array nodes.

See also: Context.get_as_array_func_decl

C API: Z3_is_as_array (z3_api.h, auto)

mk_model

def mk_model(self) raises -> Model

Create a fresh model object. It has reference count 0.

C API: Z3_mk_model (z3_api.h, auto)

String conversion (6)

ast_to_string

def ast_to_string(self, a: Ast) raises -> String

Convert the given AST node into a string.

Warning: The result buffer is statically allocated by Z3. It will be automatically deallocated when Z3_del_context is invoked. So, the buffer is invalidated in the next call to Z3_ast_to_string.

See also: Context.pattern_to_string, Context.sort_to_string

C API: Z3_ast_to_string (z3_api.h, auto)

benchmark_to_smtlib_string

def benchmark_to_smtlib_string(self, name: String, logic: String, status: String, attributes: String, assumptions: List[Ast], formula: Ast) raises -> String

Convert the given benchmark into SMT-LIB formatted string.

Parameters:

  • c — - context.
  • name — - name of benchmark. The argument is optional.
  • logic — - the benchmark logic.
  • status — - the status string (sat, unsat, or unknown)
  • attributes — - other attributes, such as source, difficulty or category.
  • num_assumptions — - number of assumptions.
  • assumptions — - auxiliary assumptions.
  • formula — - formula to be checked for consistency in conjunction with assumptions.

Warning: The result buffer is statically allocated by Z3. It will be automatically deallocated when Z3_del_context is invoked. So, the buffer is invalidated in the next call to Z3_benchmark_to_smtlib_string.

C API: Z3_benchmark_to_smtlib_string (z3_api.h, auto)

func_decl_to_string

def func_decl_to_string(self, d: FuncDecl) raises -> String

Safe wrapper for Z3_func_decl_to_string.

C API: Z3_func_decl_to_string (z3_api.h, auto)

pattern_to_string

def pattern_to_string(self, p: Pattern) raises -> String

Safe wrapper for Z3_pattern_to_string.

C API: Z3_pattern_to_string (z3_api.h, auto)

set_ast_print_mode

def set_ast_print_mode(self, mode: AstPrintMode) raises

Select mode for the format used for pretty-printing AST nodes.

The default mode for pretty printing AST nodes is to produce SMT-LIB style output where common subexpressions are printed at each occurrence. The mode is called Z3_PRINT_SMTLIB_FULL. To print shared common subexpressions only once, use the Z3_PRINT_LOW_LEVEL mode. To print in way that conforms to SMT-LIB standards and uses let expressions to share common sub-expressions use Z3_PRINT_SMTLIB2_COMPLIANT.

sort_to_string

def sort_to_string(self, s: Sort) raises -> String

Safe wrapper for Z3_sort_to_string.

C API: Z3_sort_to_string (z3_api.h, auto)

Parser interface (4)

eval_smtlib2_string

def eval_smtlib2_string(self, str: String) raises -> String

Parse and evaluate and SMT-LIB2 command sequence. The state from a previous call is saved so the next evaluation builds on top of the previous call.

Returns: output generated from processing commands.

C API: Z3_eval_smtlib2_string (z3_api.h, auto)

mk_parser_context

def mk_parser_context(self) raises -> ParserContext

Create a parser context.

A parser context maintains state between calls to Z3_parser_context_parse_string where the caller can pass in a set of SMTLIB2 commands. It maintains all the declarations from previous calls together with of sorts and function declarations (including 0-ary) that are added directly to the context.

C API: Z3_mk_parser_context (z3_api.h, auto)

parse_smtlib2_file

def parse_smtlib2_file(self, file_name: String, sort_names: List[Symbol], sorts: List[Sort], decl_names: List[Symbol], decls: List[FuncDecl]) raises -> AstVector

Similar to Z3_parse_smtlib2_string, but reads the benchmark from a file.

C API: Z3_parse_smtlib2_file (z3_api.h, auto)

parse_smtlib2_string

def parse_smtlib2_string(self, str: String, sort_names: List[Symbol], sorts: List[Sort], decl_names: List[Symbol], decls: List[FuncDecl]) raises -> AstVector

Parse the given string using the SMT-LIB2 parser.

It returns a formula comprising of the conjunction of assertions in the scope (up to push/pop) at the end of the string.

C API: Z3_parse_smtlib2_string (z3_api.h, auto)

Error Handling (3)

get_error_code

def get_error_code(self) raises -> ErrorCode

Return the error code for the last API call.

A call to a Z3 function may return a non Z3_OK error code, when it is not used correctly.

See also: Z3_set_error_handler

C API: Z3_get_error_code (z3_api.h, auto)

get_error_msg

def get_error_msg(self, err: ErrorCode) raises -> String

Return a string describing the given error code.

C API: Z3_get_error_msg (z3_api.h, auto)

set_error

def set_error(self, e: ErrorCode) raises

Set an error.

C API: Z3_set_error (z3_api.h, auto)

Tactics, Simplifiers and Probes (19)

get_num_probes

def get_num_probes(self) raises -> UInt32

Return the number of builtin probes available in Z3.

See also: Context.get_probe_name

C API: Z3_get_num_probes (z3_api.h, auto)

get_num_simplifiers

def get_num_simplifiers(self) raises -> UInt32

Return the number of builtin simplifiers available in Z3.

See also: Context.get_simplifier_name

C API: Z3_get_num_simplifiers (z3_api.h, auto)

get_num_tactics

def get_num_tactics(self) raises -> UInt32

Return the number of builtin tactics available in Z3.

See also: Context.get_tactic_name

C API: Z3_get_num_tactics (z3_api.h, auto)

get_probe_name

def get_probe_name(self, i: UInt32) raises -> String

Return the name of the i probe.

Precondition: i < Z3_get_num_probes(c)

See also: Context.get_num_probes

C API: Z3_get_probe_name (z3_api.h, auto)

get_simplifier_name

def get_simplifier_name(self, i: UInt32) raises -> String

Return the name of the idx simplifier.

Precondition: i < Z3_get_num_simplifiers(c)

See also: Context.get_num_simplifiers

C API: Z3_get_simplifier_name (z3_api.h, auto)

get_tactic_name

def get_tactic_name(self, i: UInt32) raises -> String

Return the name of the idx tactic.

Precondition: i < Z3_get_num_tactics(c)

See also: Context.get_num_tactics

C API: Z3_get_tactic_name (z3_api.h, auto)

mk_probe

def mk_probe(self, name: String) raises -> Probe

Return a probe associated with the given name. The complete list of probes may be obtained using the procedures Z3_get_num_probes and Z3_get_probe_name. It may also be obtained using the command (help-tactic) in the SMT 2.0 front-end.

Probes are used to inspect a goal (aka problem) and collect information that may be used to decide which solver and/or preprocessing step will be used.

C API: Z3_mk_probe (z3_api.h, auto)

mk_simplifier

def mk_simplifier(self, name: String) raises -> Simplifier

Return a simplifier associated with the given name. The complete list of simplifiers may be obtained using the procedures Z3_get_num_simplifiers and Z3_get_simplifier_name. It may also be obtained using the command (help-simplifier) in the SMT 2.0 front-end.

Simplifiers are the basic building block for creating custom solvers for specific problem domains.

C API: Z3_mk_simplifier (z3_api.h, auto)

probe_const

def probe_const(self, val: Float64) raises -> Probe

Return a probe that always evaluates to val.

C API: Z3_probe_const (z3_api.h, auto)

probe_get_descr

def probe_get_descr(self, name: String) raises -> String

Return a string containing a description of the probe with the given name.

C API: Z3_probe_get_descr (z3_api.h, auto)

simplifier_get_descr

def simplifier_get_descr(self, name: String) raises -> String

Return a string containing a description of the simplifier with the given name.

C API: Z3_simplifier_get_descr (z3_api.h, auto)

tactic_cond

def tactic_cond(self, p: Probe, t1: Tactic, t2: Tactic) raises -> Tactic

Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluates to false.

C API: Z3_tactic_cond (z3_api.h, auto)

tactic_fail

def tactic_fail(self) raises -> Tactic

Return a tactic that always fails.

C API: Z3_tactic_fail (z3_api.h, auto)

tactic_fail_if

def tactic_fail_if(self, p: Probe) raises -> Tactic

Return a tactic that fails if the probe p evaluates to false.

C API: Z3_tactic_fail_if (z3_api.h, auto)

tactic_fail_if_not_decided

def tactic_fail_if_not_decided(self) raises -> Tactic

Return a tactic that fails if the goal is not trivially satisfiable (i.e., empty) or trivially unsatisfiable (i.e., contains false).

C API: Z3_tactic_fail_if_not_decided (z3_api.h, auto)

tactic_get_descr

def tactic_get_descr(self, name: String) raises -> String

Return a string containing a description of the tactic with the given name.

C API: Z3_tactic_get_descr (z3_api.h, auto)

tactic_par_or

def tactic_par_or(self, ts: List[Tactic]) raises -> Tactic

Return a tactic that applies the given tactics in parallel.

C API: Z3_tactic_par_or (z3_api.h, auto)

tactic_skip

def tactic_skip(self) raises -> Tactic

Return a tactic that just return the given goal.

C API: Z3_tactic_skip (z3_api.h, auto)

tactic_when

def tactic_when(self, p: Probe, t: Tactic) raises -> Tactic

Return a tactic that applies t to a given goal is the probe p evaluates to true. If p evaluates to false, then the new tactic behaves like the skip tactic.

C API: Z3_tactic_when (z3_api.h, auto)

Solvers (3)

mk_simple_solver

def mk_simple_solver(self) raises -> Solver

Create a new incremental solver.

This is equivalent to applying the "smt" tactic.

Unlike Z3_mk_solver() this solver

  • Does not attempt to apply any logic specific tactics.
  • Does not change its behaviour based on whether it used incrementally/non-incrementally.

Note that these differences can result in very different performance compared to Z3_mk_solver().

The function Z3_solver_get_model retrieves a model if the assertions is satisfiable (i.e., the result is Z3_L_TRUE) and model construction is enabled. The function Z3_solver_get_model can also be used even if the result is Z3_L_UNDEF, but the returned model is not guaranteed to satisfy quantified assertions.

Note: User must use Z3_solver_inc_ref and Z3_solver_dec_ref to manage solver objects. Even if the context was created using Z3_mk_context instead of Z3_mk_context_rc.

See also: Solver.__init__, Solver.for_logic, Tactic.to_solver

C API: Z3_mk_simple_solver (z3_api.h, auto)

solver_next_split

def solver_next_split(self, cb: SolverCallback, t: Ast, idx: UInt32, phase: Lbool) raises -> Bool

Sets the next (registered) expression to split on. The function returns false and ignores the given expression in case the expression is already assigned internally (due to relevancy propagation, this assignments might not have been reported yet by the fixed callback). In case the function is called in the decide callback, it overrides the currently selected variable and phase.

C API: Z3_solver_next_split (z3_api.h, auto)

solver_propagate_declare

def solver_propagate_declare(self, name: Symbol, domain: List[Sort], range_: Sort) raises -> FuncDecl

Create uninterpreted function declaration for the user propagator. When expressions using the function are created by the solver invoke a callback to Z3_solver_propagate_created with arguments

  1. context and callback solve
  2. declared_expr: expression using function that was used as the top-level symbol
  3. declared_id: a unique identifier (unique within the current scope) to track the expression.

C API: Z3_solver_propagate_declare (z3_api.h, auto)

AST vectors (1)

mk_ast_vector

def mk_ast_vector(self) raises -> AstVector

Return an empty AST vector.

Note: Reference counting must be used to manage AST vectors, even when the Z3_context was created using Z3_mk_context instead of Z3_mk_context_rc.

C API: Z3_mk_ast_vector (z3_ast_containers.h, auto)

AST maps (1)

mk_ast_map

def mk_ast_map(self) raises -> AstMap

Return an empty mapping from AST to AST

Note: Reference counting must be used to manage AST maps, even when the Z3_context was created using Z3_mk_context instead of Z3_mk_context_rc.

C API: Z3_mk_ast_map (z3_ast_containers.h, auto)

Floating-Point Arithmetic (61)

mk_fpa_abs

def mk_fpa_abs(self, t: Ast) raises -> Ast

Floating-point absolute value

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

See also: Context.mk_fpa_is_negative, Context.mk_fpa_is_positive, Context.mk_fpa_neg

C API: Z3_mk_fpa_abs (z3_fpa.h, auto)

mk_fpa_add

def mk_fpa_add(self, rm: Ast, t1: Ast, t2: Ast) raises -> Ast

Floating-point addition

rm must be of RoundingMode sort, t1 and t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

C API: Z3_mk_fpa_add (z3_fpa.h, auto)

mk_fpa_div

def mk_fpa_div(self, rm: Ast, t1: Ast, t2: Ast) raises -> Ast

Floating-point division

The nodes rm must be of RoundingMode sort, t1 and t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t1 — term of FloatingPoint sort.
  • t2 — term of FloatingPoint sort

C API: Z3_mk_fpa_div (z3_fpa.h, auto)

mk_fpa_eq

def mk_fpa_eq(self, t1: Ast, t2: Ast) raises -> Ast

Floating-point equality.

Note that this is IEEE 754 equality (as opposed to SMT-LIB =).

t1 and t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

See also: Context.mk_fpa_geq, Context.mk_fpa_gt, Context.mk_fpa_leq, Context.mk_fpa_lt

C API: Z3_mk_fpa_eq (z3_fpa.h, auto)

mk_fpa_fma

def mk_fpa_fma(self, rm: Ast, t1: Ast, t2: Ast, t3: Ast) raises -> Ast

Floating-point fused multiply-add.

The result is round((t1 * t2) + t3).

rm must be of RoundingMode sort, t1, t2, and t3 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort
  • t3 — term of FloatingPoint sort

C API: Z3_mk_fpa_fma (z3_fpa.h, auto)

mk_fpa_fp

def mk_fpa_fp(self, sgn: Ast, exp: Ast, sig: Ast) raises -> Ast

Create an expression of FloatingPoint sort from three bit-vector expressions.

This is the operator named fp' in the SMT FP theory definition. Note thatsgn` is required to be a bit-vector of size 1. Significand and exponent are required to be longer than 1 and 2 respectively. The FloatingPoint sort of the resulting expression is automatically determined from the bit-vector sizes of the arguments. The exponent is assumed to be in IEEE-754 biased representation.

Parameters:

  • c — logical context
  • sgn — sign
  • exp — exponent
  • sig — significand

See also: Context.mk_fpa_numeral_double, Context.mk_fpa_numeral_float, Context.mk_fpa_numeral_int, Context.mk_fpa_numeral_int_uint, Context.mk_fpa_numeral_int64_uint64, Context.mk_numeral

C API: Z3_mk_fpa_fp (z3_fpa.h, auto)

mk_fpa_geq

def mk_fpa_geq(self, t1: Ast, t2: Ast) raises -> Ast

Floating-point greater than or equal.

t1 and t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

See also: Context.mk_fpa_eq, Context.mk_fpa_gt, Context.mk_fpa_leq, Context.mk_fpa_lt

C API: Z3_mk_fpa_geq (z3_fpa.h, auto)

mk_fpa_gt

def mk_fpa_gt(self, t1: Ast, t2: Ast) raises -> Ast

Floating-point greater than.

t1 and t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

See also: Context.mk_fpa_eq, Context.mk_fpa_geq, Context.mk_fpa_leq, Context.mk_fpa_lt

C API: Z3_mk_fpa_gt (z3_fpa.h, auto)

mk_fpa_inf

def mk_fpa_inf(self, s: Sort, negative: Bool) raises -> Ast

Create a floating-point infinity of sort s.

When negative is true, -oo will be generated instead of +oo.

Parameters:

  • c — logical context
  • s — target sort
  • negative — indicates whether the result should be negative

See also: Context.mk_fpa_is_infinite, Context.mk_fpa_nan, Context.mk_fpa_zero

C API: Z3_mk_fpa_inf (z3_fpa.h, auto)

mk_fpa_is_infinite

def mk_fpa_is_infinite(self, t: Ast) raises -> Ast

Predicate indicating whether t is a floating-point number representing +oo or -oo.

t must have FloatingPoint sort.

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

See also: Context.mk_fpa_inf, Context.mk_fpa_is_nan, Context.mk_fpa_is_normal, Context.mk_fpa_is_subnormal, Context.mk_fpa_is_zero

C API: Z3_mk_fpa_is_infinite (z3_fpa.h, auto)

mk_fpa_is_nan

def mk_fpa_is_nan(self, t: Ast) raises -> Ast

Predicate indicating whether t is a NaN.

t must have FloatingPoint sort.

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

See also: Context.mk_fpa_is_infinite, Context.mk_fpa_is_normal, Context.mk_fpa_is_subnormal, Context.mk_fpa_is_zero, Context.mk_fpa_nan

C API: Z3_mk_fpa_is_nan (z3_fpa.h, auto)

mk_fpa_is_negative

def mk_fpa_is_negative(self, t: Ast) raises -> Ast

Predicate indicating whether t is a negative floating-point number.

t must have FloatingPoint sort.

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

See also: Context.mk_fpa_abs, Context.mk_fpa_is_positive, Context.mk_fpa_neg

C API: Z3_mk_fpa_is_negative (z3_fpa.h, auto)

mk_fpa_is_normal

def mk_fpa_is_normal(self, t: Ast) raises -> Ast

Predicate indicating whether t is a normal floating-point number.

t must have FloatingPoint sort.

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

See also: Context.mk_fpa_is_infinite, Context.mk_fpa_is_nan, Context.mk_fpa_is_subnormal, Context.mk_fpa_is_zero

C API: Z3_mk_fpa_is_normal (z3_fpa.h, auto)

mk_fpa_is_positive

def mk_fpa_is_positive(self, t: Ast) raises -> Ast

Predicate indicating whether t is a positive floating-point number.

t must have FloatingPoint sort.

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

See also: Context.mk_fpa_abs, Context.mk_fpa_is_negative, Context.mk_fpa_neg

C API: Z3_mk_fpa_is_positive (z3_fpa.h, auto)

mk_fpa_is_subnormal

def mk_fpa_is_subnormal(self, t: Ast) raises -> Ast

Predicate indicating whether t is a subnormal floating-point number.

t must have FloatingPoint sort.

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

See also: Context.mk_fpa_is_infinite, Context.mk_fpa_is_nan, Context.mk_fpa_is_normal, Context.mk_fpa_is_zero

C API: Z3_mk_fpa_is_subnormal (z3_fpa.h, auto)

mk_fpa_is_zero

def mk_fpa_is_zero(self, t: Ast) raises -> Ast

Predicate indicating whether t is a floating-point number with zero value, i.e., +zero or -zero.

t must have FloatingPoint sort.

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

See also: Context.mk_fpa_is_infinite, Context.mk_fpa_is_nan, Context.mk_fpa_is_normal, Context.mk_fpa_is_subnormal, Context.mk_fpa_zero

C API: Z3_mk_fpa_is_zero (z3_fpa.h, auto)

mk_fpa_leq

def mk_fpa_leq(self, t1: Ast, t2: Ast) raises -> Ast

Floating-point less than or equal.

t1 and t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

See also: Context.mk_fpa_eq, Context.mk_fpa_geq, Context.mk_fpa_gt, Context.mk_fpa_lt

C API: Z3_mk_fpa_leq (z3_fpa.h, auto)

mk_fpa_lt

def mk_fpa_lt(self, t1: Ast, t2: Ast) raises -> Ast

Floating-point less than.

t1 and t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

See also: Context.mk_fpa_eq, Context.mk_fpa_geq, Context.mk_fpa_gt, Context.mk_fpa_leq

C API: Z3_mk_fpa_lt (z3_fpa.h, auto)

mk_fpa_max

def mk_fpa_max(self, t1: Ast, t2: Ast) raises -> Ast

Maximum of floating-point numbers.

t1, t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

See also: Context.mk_fpa_min

C API: Z3_mk_fpa_max (z3_fpa.h, auto)

mk_fpa_min

def mk_fpa_min(self, t1: Ast, t2: Ast) raises -> Ast

Minimum of floating-point numbers.

t1, t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

See also: Context.mk_fpa_max

C API: Z3_mk_fpa_min (z3_fpa.h, auto)

mk_fpa_mul

def mk_fpa_mul(self, rm: Ast, t1: Ast, t2: Ast) raises -> Ast

Floating-point multiplication

rm must be of RoundingMode sort, t1 and t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

C API: Z3_mk_fpa_mul (z3_fpa.h, auto)

mk_fpa_nan

def mk_fpa_nan(self, s: Sort) raises -> Ast

Create a floating-point NaN of sort s.

Parameters:

  • c — logical context
  • s — target sort

See also: Context.mk_fpa_inf, Context.mk_fpa_is_nan, Context.mk_fpa_zero

C API: Z3_mk_fpa_nan (z3_fpa.h, auto)

mk_fpa_neg

def mk_fpa_neg(self, t: Ast) raises -> Ast

Floating-point negation

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

See also: Context.mk_fpa_abs, Context.mk_fpa_is_negative, Context.mk_fpa_is_positive

C API: Z3_mk_fpa_neg (z3_fpa.h, auto)

mk_fpa_numeral_double

def mk_fpa_numeral_double(self, v: Float64, ty: Sort) raises -> Ast

Create a numeral of FloatingPoint sort from a double.

This function is used to create numerals that fit in a double value. It is slightly faster than Z3_mk_numeral since it is not necessary to parse a string.

ty must be a FloatingPoint sort

mk_fpa_numeral_float

def mk_fpa_numeral_float(self, v: Float32, ty: Sort) raises -> Ast

Create a numeral of FloatingPoint sort from a float.

This function is used to create numerals that fit in a float value. It is slightly faster than Z3_mk_numeral since it is not necessary to parse a string.

ty must be a FloatingPoint sort

mk_fpa_numeral_int

def mk_fpa_numeral_int(self, v: Int32, ty: Sort) raises -> Ast

Create a numeral of FloatingPoint sort from a signed integer.

ty must be a FloatingPoint sort

mk_fpa_numeral_int64_uint64

def mk_fpa_numeral_int64_uint64(self, sgn: Bool, exp: Int64, sig: UInt64, ty: Sort) raises -> Ast

Create a numeral of FloatingPoint sort from a sign bit and two 64-bit integers.

ty must be a FloatingPoint sort

Parameters:

  • c — logical context
  • sgn — sign bit (true == negative)
  • sig — significand
  • exp — exponent
  • ty — result sort

See also: Context.mk_fpa_fp, Context.mk_fpa_numeral_double, Context.mk_fpa_numeral_float, Context.mk_fpa_numeral_int, Context.mk_fpa_numeral_int_uint, Context.mk_numeral

C API: Z3_mk_fpa_numeral_int64_uint64 (z3_fpa.h, auto)

mk_fpa_numeral_int_uint

def mk_fpa_numeral_int_uint(self, sgn: Bool, exp: Int32, sig: UInt32, ty: Sort) raises -> Ast

Create a numeral of FloatingPoint sort from a sign bit and two integers.

ty must be a FloatingPoint sort

Parameters:

  • c — logical context
  • sgn — sign bit (true == negative)
  • sig — significand
  • exp — exponent
  • ty — result sort

See also: Context.mk_fpa_fp, Context.mk_fpa_numeral_double, Context.mk_fpa_numeral_float, Context.mk_fpa_numeral_int, Context.mk_fpa_numeral_int64_uint64, Context.mk_numeral

C API: Z3_mk_fpa_numeral_int_uint (z3_fpa.h, auto)

mk_fpa_rem

def mk_fpa_rem(self, t1: Ast, t2: Ast) raises -> Ast

Floating-point remainder

t1 and t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

C API: Z3_mk_fpa_rem (z3_fpa.h, auto)

mk_fpa_rna

def mk_fpa_rna(self) raises -> Ast

Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode.

This is the same as Z3_mk_fpa_round_nearest_ties_to_away.

Parameters:

  • c — logical context

See also: Context.mk_fpa_rounding_mode_sort, Context.mk_fpa_rne, Context.mk_fpa_rtn, Context.mk_fpa_rtp, Context.mk_fpa_rtz

C API: Z3_mk_fpa_rna (z3_fpa.h, auto)

mk_fpa_rne

def mk_fpa_rne(self) raises -> Ast

Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode.

This is the same as Z3_mk_fpa_round_nearest_ties_to_even.

Parameters:

  • c — logical context

See also: Context.mk_fpa_rounding_mode_sort, Context.mk_fpa_rna, Context.mk_fpa_rtn, Context.mk_fpa_rtp, Context.mk_fpa_rtz

C API: Z3_mk_fpa_rne (z3_fpa.h, auto)

mk_fpa_round_nearest_ties_to_away

def mk_fpa_round_nearest_ties_to_away(self) raises -> Ast

Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode.

This is the same as Z3_mk_fpa_rna.

mk_fpa_round_nearest_ties_to_even

def mk_fpa_round_nearest_ties_to_even(self) raises -> Ast

Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode.

This is the same as Z3_mk_fpa_rne.

mk_fpa_round_to_integral

def mk_fpa_round_to_integral(self, rm: Ast, t: Ast) raises -> Ast

Floating-point roundToIntegral. Rounds a floating-point number to the closest integer, again represented as a floating-point number.

t must be of FloatingPoint sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t — term of FloatingPoint sort

C API: Z3_mk_fpa_round_to_integral (z3_fpa.h, auto)

mk_fpa_round_toward_negative

def mk_fpa_round_toward_negative(self) raises -> Ast

Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.

This is the same as Z3_mk_fpa_rtn.

mk_fpa_round_toward_positive

def mk_fpa_round_toward_positive(self) raises -> Ast

Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode.

This is the same as Z3_mk_fpa_rtp.

mk_fpa_round_toward_zero

def mk_fpa_round_toward_zero(self) raises -> Ast

Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.

This is the same as Z3_mk_fpa_rtz.

mk_fpa_rounding_mode_sort

def mk_fpa_rounding_mode_sort(self) raises -> Sort

Create the RoundingMode sort.

mk_fpa_rtn

def mk_fpa_rtn(self) raises -> Ast

Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.

This is the same as Z3_mk_fpa_round_toward_negative.

Parameters:

  • c — logical context

See also: Context.mk_fpa_rounding_mode_sort, Context.mk_fpa_rna, Context.mk_fpa_rne, Context.mk_fpa_rtp, Context.mk_fpa_rtz

C API: Z3_mk_fpa_rtn (z3_fpa.h, auto)

mk_fpa_rtp

def mk_fpa_rtp(self) raises -> Ast

Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode.

This is the same as Z3_mk_fpa_round_toward_positive.

Parameters:

  • c — logical context

See also: Context.mk_fpa_rounding_mode_sort, Context.mk_fpa_rna, Context.mk_fpa_rne, Context.mk_fpa_rtn, Context.mk_fpa_rtz

C API: Z3_mk_fpa_rtp (z3_fpa.h, auto)

mk_fpa_rtz

def mk_fpa_rtz(self) raises -> Ast

Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.

This is the same as Z3_mk_fpa_round_toward_zero.

Parameters:

  • c — logical context

See also: Context.mk_fpa_rounding_mode_sort, Context.mk_fpa_rna, Context.mk_fpa_rne, Context.mk_fpa_rtn, Context.mk_fpa_rtp

C API: Z3_mk_fpa_rtz (z3_fpa.h, auto)

mk_fpa_sort

def mk_fpa_sort(self, ebits: UInt32, sbits: UInt32) raises -> Sort

Create a FloatingPoint sort.

Parameters:

  • c — logical context
  • ebits — number of exponent bits
  • sbits — number of significand bits

Note: ebits must be larger than 1 and sbits must be larger than 2.

See also: Context.mk_fpa_sort_half, Context.mk_fpa_sort_16, Context.mk_fpa_sort_single, Context.mk_fpa_sort_32, Context.mk_fpa_sort_double, Context.mk_fpa_sort_64, Context.mk_fpa_sort_quadruple, Context.mk_fpa_sort_128

C API: Z3_mk_fpa_sort (z3_fpa.h, auto)

mk_fpa_sort_128

def mk_fpa_sort_128(self) raises -> Sort

Create the quadruple-precision (128-bit) FloatingPoint sort.

This is the same as Z3_mk_fpa_sort_quadruple.

Parameters:

  • c — logical context

See also: Context.mk_fpa_sort, Context.mk_fpa_sort_16, Context.mk_fpa_sort_32, Context.mk_fpa_sort_64

C API: Z3_mk_fpa_sort_128 (z3_fpa.h, auto)

mk_fpa_sort_16

def mk_fpa_sort_16(self) raises -> Sort

Create the half-precision (16-bit) FloatingPoint sort.

This is the same as Z3_mk_fpa_sort_half.

Parameters:

  • c — logical context

See also: Context.mk_fpa_sort, Context.mk_fpa_sort_32, Context.mk_fpa_sort_64, Context.mk_fpa_sort_128

C API: Z3_mk_fpa_sort_16 (z3_fpa.h, auto)

mk_fpa_sort_32

def mk_fpa_sort_32(self) raises -> Sort

Create the single-precision (32-bit) FloatingPoint sort.

This is the same as Z3_mk_fpa_sort_single.

Parameters:

  • c — logical context

See also: Context.mk_fpa_sort, Context.mk_fpa_sort_16, Context.mk_fpa_sort_64, Context.mk_fpa_sort_128

C API: Z3_mk_fpa_sort_32 (z3_fpa.h, auto)

mk_fpa_sort_64

def mk_fpa_sort_64(self) raises -> Sort

Create the double-precision (64-bit) FloatingPoint sort.

This is the same as Z3_mk_fpa_sort_double.

Parameters:

  • c — logical context

See also: Context.mk_fpa_sort, Context.mk_fpa_sort_16, Context.mk_fpa_sort_32, Context.mk_fpa_sort_128

C API: Z3_mk_fpa_sort_64 (z3_fpa.h, auto)

mk_fpa_sort_double

def mk_fpa_sort_double(self) raises -> Sort

Create the double-precision (64-bit) FloatingPoint sort.

This is the same as Z3_mk_fpa_sort_64.

mk_fpa_sort_half

def mk_fpa_sort_half(self) raises -> Sort

Create the half-precision (16-bit) FloatingPoint sort.

This is the same as Z3_mk_fpa_sort_16.

mk_fpa_sort_quadruple

def mk_fpa_sort_quadruple(self) raises -> Sort

Create the quadruple-precision (128-bit) FloatingPoint sort.

This is the same as Z3_mk_fpa_sort_128.

mk_fpa_sort_single

def mk_fpa_sort_single(self) raises -> Sort

Create the single-precision (32-bit) FloatingPoint sort.

This is the same as Z3_mk_fpa_sort_32.

mk_fpa_sqrt

def mk_fpa_sqrt(self, rm: Ast, t: Ast) raises -> Ast

Floating-point square root

rm must be of RoundingMode sort, t must have FloatingPoint sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t — term of FloatingPoint sort

C API: Z3_mk_fpa_sqrt (z3_fpa.h, auto)

mk_fpa_sub

def mk_fpa_sub(self, rm: Ast, t1: Ast, t2: Ast) raises -> Ast

Floating-point subtraction

rm must be of RoundingMode sort, t1 and t2 must have the same FloatingPoint sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t1 — term of FloatingPoint sort
  • t2 — term of FloatingPoint sort

C API: Z3_mk_fpa_sub (z3_fpa.h, auto)

mk_fpa_to_fp_bv

def mk_fpa_to_fp_bv(self, bv: Ast, s: Sort) raises -> Ast

Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.

Produces a term that represents the conversion of a bit-vector term bv to a floating-point term of sort s.

s must be a FloatingPoint sort, t must be of bit-vector sort, and the bit-vector size of bv must be equal to ebits+sbits of s. The format of the bit-vector is as defined by the IEEE 754-2008 interchange format.

Parameters:

  • c — logical context
  • bv — a bit-vector term
  • s — floating-point sort

C API: Z3_mk_fpa_to_fp_bv (z3_fpa.h, auto)

mk_fpa_to_fp_float

def mk_fpa_to_fp_float(self, rm: Ast, t: Ast, s: Sort) raises -> Ast

Conversion of a FloatingPoint term into another term of different FloatingPoint sort.

Produces a term that represents the conversion of a floating-point term t to a floating-point term of sort s. If necessary, the result will be rounded according to rounding mode rm.

s must be a FloatingPoint sort, rm must be of RoundingMode sort, t must be of floating-point sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t — term of FloatingPoint sort
  • s — floating-point sort

C API: Z3_mk_fpa_to_fp_float (z3_fpa.h, auto)

mk_fpa_to_fp_real

def mk_fpa_to_fp_real(self, rm: Ast, t: Ast, s: Sort) raises -> Ast

Conversion of a term of real sort into a term of FloatingPoint sort.

Produces a term that represents the conversion of term t of real sort into a floating-point term of sort s. If necessary, the result will be rounded according to rounding mode rm.

s must be a FloatingPoint sort, rm must be of RoundingMode sort, t must be of real sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t — term of Real sort
  • s — floating-point sort

C API: Z3_mk_fpa_to_fp_real (z3_fpa.h, auto)

mk_fpa_to_fp_signed

def mk_fpa_to_fp_signed(self, rm: Ast, t: Ast, s: Sort) raises -> Ast

Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort.

Produces a term that represents the conversion of the bit-vector term t into a floating-point term of sort s. The bit-vector t is taken to be in signed 2's complement format. If necessary, the result will be rounded according to rounding mode rm.

s must be a FloatingPoint sort, rm must be of RoundingMode sort, t must be of bit-vector sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t — term of bit-vector sort
  • s — floating-point sort

C API: Z3_mk_fpa_to_fp_signed (z3_fpa.h, auto)

mk_fpa_to_fp_unsigned

def mk_fpa_to_fp_unsigned(self, rm: Ast, t: Ast, s: Sort) raises -> Ast

Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort.

Produces a term that represents the conversion of the bit-vector term t into a floating-point term of sort s. The bit-vector t is taken to be in unsigned 2's complement format. If necessary, the result will be rounded according to rounding mode rm.

s must be a FloatingPoint sort, rm must be of RoundingMode sort, t must be of bit-vector sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t — term of bit-vector sort
  • s — floating-point sort

C API: Z3_mk_fpa_to_fp_unsigned (z3_fpa.h, auto)

mk_fpa_to_real

def mk_fpa_to_real(self, t: Ast) raises -> Ast

Conversion of a floating-point term into a real-numbered term.

Produces a term that represents the conversion of the floating-point term t into a real number. Note that this type of conversion will often result in non-linear constraints over real terms.

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

C API: Z3_mk_fpa_to_real (z3_fpa.h, auto)

mk_fpa_to_sbv

def mk_fpa_to_sbv(self, rm: Ast, t: Ast, sz: UInt32) raises -> Ast

Conversion of a floating-point term into a signed bit-vector.

Produces a term that represents the conversion of the floating-point term t into a bit-vector term of size sz in signed 2's complement format. If necessary, the result will be rounded according to rounding mode rm.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t — term of FloatingPoint sort
  • sz — size of the resulting bit-vector

C API: Z3_mk_fpa_to_sbv (z3_fpa.h, auto)

mk_fpa_to_ubv

def mk_fpa_to_ubv(self, rm: Ast, t: Ast, sz: UInt32) raises -> Ast

Conversion of a floating-point term into an unsigned bit-vector.

Produces a term that represents the conversion of the floating-point term t into a bit-vector term of size sz in unsigned 2's complement format. If necessary, the result will be rounded according to rounding mode rm.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • t — term of FloatingPoint sort
  • sz — size of the resulting bit-vector

C API: Z3_mk_fpa_to_ubv (z3_fpa.h, auto)

mk_fpa_zero

def mk_fpa_zero(self, s: Sort, negative: Bool) raises -> Ast

Create a floating-point zero of sort s.

When negative is true, -zero will be generated instead of +zero.

Parameters:

  • c — logical context
  • s — target sort
  • negative — indicates whether the result should be negative

See also: Context.mk_fpa_inf, Context.mk_fpa_is_zero, Context.mk_fpa_nan

C API: Z3_mk_fpa_zero (z3_fpa.h, auto)

Z3-specific floating-point extensions (20)

fpa_get_ebits

def fpa_get_ebits(self, s: Sort) raises -> UInt32

Retrieves the number of bits reserved for the exponent in a FloatingPoint sort.

Parameters:

  • c — logical context
  • s — FloatingPoint sort

See also: Context.fpa_get_sbits

C API: Z3_fpa_get_ebits (z3_fpa.h, auto)

fpa_get_numeral_exponent_bv

def fpa_get_numeral_exponent_bv(self, t: Ast, biased: Bool) raises -> Ast

Retrieves the exponent of a floating-point literal as a bit-vector expression.

Remarks: This function extracts the exponent in t, without normalization. NaN is an invalid arguments.

Parameters:

  • c — logical context
  • t — a floating-point numeral
  • biased — flag to indicate whether the result is in biased representation

C API: Z3_fpa_get_numeral_exponent_bv (z3_fpa.h, auto)

fpa_get_numeral_exponent_int64

def fpa_get_numeral_exponent_int64(self, t: Ast, biased: Bool) raises -> Optional[Int64]

Return the exponent value of a floating-point numeral as a signed 64-bit integer

Remarks: This function extracts the exponent in t, without normalization. NaN is an invalid argument.

Parameters:

  • c — logical context
  • t — a floating-point numeral
  • n — exponent
  • biased — flag to indicate whether the result is in biased representation

Returns: true if t corresponds to a floating point numeral, otherwise invokes exception handler or returns false

C API: Z3_fpa_get_numeral_exponent_int64 (z3_fpa.h, auto)

fpa_get_numeral_exponent_string

def fpa_get_numeral_exponent_string(self, t: Ast, biased: Bool) raises -> String

Return the exponent value of a floating-point numeral as a string.

Remarks: This function extracts the exponent in t, without normalization. NaN is an invalid argument.

Parameters:

  • c — logical context
  • t — a floating-point numeral
  • biased — flag to indicate whether the result is in biased representation

Returns: true if t corresponds to a floating point numeral, otherwise invokes exception handler or returns false

C API: Z3_fpa_get_numeral_exponent_string (z3_fpa.h, auto)

fpa_get_numeral_sign

def fpa_get_numeral_sign(self, t: Ast) raises -> Optional[Bool]

Retrieves the sign of a floating-point literal.

Remarks: sets sgn to false if t' is positive and totrue` otherwise, except for NaN, which is an invalid argument.

Parameters:

  • c — logical context
  • t — a floating-point numeral
  • sgn — the retrieved sign

Returns: true if t corresponds to a floating point numeral, otherwise invokes exception handler or returns false

C API: Z3_fpa_get_numeral_sign (z3_fpa.h, auto)

fpa_get_numeral_sign_bv

def fpa_get_numeral_sign_bv(self, t: Ast) raises -> Ast

Retrieves the sign of a floating-point literal as a bit-vector expression.

Remarks: NaN is an invalid argument.

Parameters:

  • c — logical context
  • t — a floating-point numeral

C API: Z3_fpa_get_numeral_sign_bv (z3_fpa.h, auto)

fpa_get_numeral_significand_bv

def fpa_get_numeral_significand_bv(self, t: Ast) raises -> Ast

Retrieves the significand of a floating-point literal as a bit-vector expression.

Remarks: NaN is an invalid argument.

Parameters:

  • c — logical context
  • t — a floating-point numeral

C API: Z3_fpa_get_numeral_significand_bv (z3_fpa.h, auto)

fpa_get_numeral_significand_string

def fpa_get_numeral_significand_string(self, t: Ast) raises -> String

Return the significand value of a floating-point numeral as a string.

Remarks: The significand s is always 0.0 <= s < 2.0; the resulting string is long enough to represent the real significand precisely.

Parameters:

  • c — logical context
  • t — a floating-point numeral

Returns: true if t corresponds to a floating point numeral, otherwise invokes exception handler or returns false

C API: Z3_fpa_get_numeral_significand_string (z3_fpa.h, auto)

fpa_get_numeral_significand_uint64

def fpa_get_numeral_significand_uint64(self, t: Ast) raises -> Optional[UInt64]

Return the significand value of a floating-point numeral as a uint64.

Remarks: This function extracts the significand bits in t, without the hidden bit or normalization. Sets the Z3_INVALID_ARG error code if the significand does not fit into a uint64. NaN is an invalid argument.

Parameters:

  • c — logical context
  • t — a floating-point numeral
  • n — pointer to output uint64

C API: Z3_fpa_get_numeral_significand_uint64 (z3_fpa.h, auto)

fpa_get_sbits

def fpa_get_sbits(self, s: Sort) raises -> UInt32

Retrieves the number of bits reserved for the significand in a FloatingPoint sort.

Parameters:

  • c — logical context
  • s — FloatingPoint sort

See also: Context.fpa_get_ebits

C API: Z3_fpa_get_sbits (z3_fpa.h, auto)

fpa_is_numeral

def fpa_is_numeral(self, t: Ast) raises -> Bool

Checks whether a given ast is a floating-point numeral.

fpa_is_numeral_inf

def fpa_is_numeral_inf(self, t: Ast) raises -> Bool

Checks whether a given floating-point numeral is a +oo or -oo.

Parameters:

  • c — logical context
  • t — a floating-point numeral

See also: Context.fpa_is_numeral_nan, Context.fpa_is_numeral_normal, Context.fpa_is_numeral_subnormal, Context.fpa_is_numeral_zero

C API: Z3_fpa_is_numeral_inf (z3_fpa.h, auto)

fpa_is_numeral_nan

def fpa_is_numeral_nan(self, t: Ast) raises -> Bool

Checks whether a given floating-point numeral is a NaN.

Parameters:

  • c — logical context
  • t — a floating-point numeral

See also: Context.fpa_is_numeral_inf, Context.fpa_is_numeral_normal, Context.fpa_is_numeral_subnormal, Context.fpa_is_numeral_zero

C API: Z3_fpa_is_numeral_nan (z3_fpa.h, auto)

fpa_is_numeral_negative

def fpa_is_numeral_negative(self, t: Ast) raises -> Bool

Checks whether a given floating-point numeral is negative.

Parameters:

  • c — logical context
  • t — a floating-point numeral

See also: Context.fpa_is_numeral_positive

C API: Z3_fpa_is_numeral_negative (z3_fpa.h, auto)

fpa_is_numeral_normal

def fpa_is_numeral_normal(self, t: Ast) raises -> Bool

Checks whether a given floating-point numeral is normal.

Parameters:

  • c — logical context
  • t — a floating-point numeral

See also: Context.fpa_is_numeral_inf, Context.fpa_is_numeral_nan, Context.fpa_is_numeral_subnormal, Context.fpa_is_numeral_zero

C API: Z3_fpa_is_numeral_normal (z3_fpa.h, auto)

fpa_is_numeral_positive

def fpa_is_numeral_positive(self, t: Ast) raises -> Bool

Checks whether a given floating-point numeral is positive.

Parameters:

  • c — logical context
  • t — a floating-point numeral

See also: Context.fpa_is_numeral_negative

C API: Z3_fpa_is_numeral_positive (z3_fpa.h, auto)

fpa_is_numeral_subnormal

def fpa_is_numeral_subnormal(self, t: Ast) raises -> Bool

Checks whether a given floating-point numeral is subnormal.

Parameters:

  • c — logical context
  • t — a floating-point numeral

See also: Context.fpa_is_numeral_inf, Context.fpa_is_numeral_nan, Context.fpa_is_numeral_normal, Context.fpa_is_numeral_zero

C API: Z3_fpa_is_numeral_subnormal (z3_fpa.h, auto)

fpa_is_numeral_zero

def fpa_is_numeral_zero(self, t: Ast) raises -> Bool

Checks whether a given floating-point numeral is +zero or -zero.

Parameters:

  • c — logical context
  • t — a floating-point numeral

See also: Context.fpa_is_numeral_inf, Context.fpa_is_numeral_nan, Context.fpa_is_numeral_normal, Context.fpa_is_numeral_subnormal

C API: Z3_fpa_is_numeral_zero (z3_fpa.h, auto)

mk_fpa_to_fp_int_real

def mk_fpa_to_fp_int_real(self, rm: Ast, exp: Ast, sig: Ast, s: Sort) raises -> Ast

Conversion of a real-sorted significand and an integer-sorted exponent into a term of FloatingPoint sort.

Produces a term that represents the conversion of sig * 2^exp into a floating-point term of sort s. If necessary, the result will be rounded according to rounding mode rm.

s must be a FloatingPoint sort, rm must be of RoundingMode sort, exp must be of int sort, sig must be of real sort.

Parameters:

  • c — logical context
  • rm — term of RoundingMode sort
  • exp — exponent term of Int sort
  • sig — significand term of Real sort
  • s — FloatingPoint sort

C API: Z3_mk_fpa_to_fp_int_real (z3_fpa.h, auto)

mk_fpa_to_ieee_bv

def mk_fpa_to_ieee_bv(self, t: Ast) raises -> Ast

Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.

t must have FloatingPoint sort. The size of the resulting bit-vector is automatically determined.

Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion knows only one NaN and it will always produce the same bit-vector representation of that NaN.

Parameters:

  • c — logical context
  • t — term of FloatingPoint sort

C API: Z3_mk_fpa_to_ieee_bv (z3_fpa.h, auto)

Algebraic Numbers (21)

algebraic_add

def algebraic_add(self, a: Ast, b: Ast) raises -> Ast

Return the value a + b.

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • Z3_algebraic_is_value(c, b)

Postcondition: Z3_algebraic_is_value(c, result)

C API: Z3_algebraic_add (z3_algebraic.h, auto)

algebraic_div

def algebraic_div(self, a: Ast, b: Ast) raises -> Ast

Return the value a / b.

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • Z3_algebraic_is_value(c, b)
  • !Z3_algebraic_is_zero(c, b)

Postcondition: Z3_algebraic_is_value(c, result)

C API: Z3_algebraic_div (z3_algebraic.h, auto)

algebraic_eq

def algebraic_eq(self, a: Ast, b: Ast) raises -> Bool

Return true if a == b, and false otherwise.

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • Z3_algebraic_is_value(c, b)

C API: Z3_algebraic_eq (z3_algebraic.h, auto)

algebraic_eval

def algebraic_eval(self, p: Ast, a: List[Ast]) raises -> Int32

Given a multivariate polynomial p(x_0, ..., x_{n-1}), return the sign of p(a[0], ..., a[n-1]).

Preconditions:

  • p is a Z3 expression that contains only arithmetic terms and free variables.
  • forall i in [0, n) Z3_algebraic_is_value(c, a[i])

C API: Z3_algebraic_eval (z3_algebraic.h, auto)

algebraic_ge

def algebraic_ge(self, a: Ast, b: Ast) raises -> Bool

Return true if a >= b, and false otherwise.

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • Z3_algebraic_is_value(c, b)

C API: Z3_algebraic_ge (z3_algebraic.h, auto)

algebraic_get_i

def algebraic_get_i(self, a: Ast) raises -> UInt32

Return which root of the polynomial the algebraic number represents.

Precondition: Z3_is_algebraic_number(c, a)

C API: Z3_algebraic_get_i (z3_algebraic.h, auto)

algebraic_get_poly

def algebraic_get_poly(self, a: Ast) raises -> AstVector

Return the coefficients of the defining polynomial.

Precondition: Z3_is_algebraic_number(c, a)

C API: Z3_algebraic_get_poly (z3_algebraic.h, auto)

algebraic_gt

def algebraic_gt(self, a: Ast, b: Ast) raises -> Bool

Return true if a > b, and false otherwise.

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • Z3_algebraic_is_value(c, b)

C API: Z3_algebraic_gt (z3_algebraic.h, auto)

algebraic_is_neg

def algebraic_is_neg(self, a: Ast) raises -> Bool

Return true if a is negative, and false otherwise.

Precondition: Z3_algebraic_is_value(c, a)

C API: Z3_algebraic_is_neg (z3_algebraic.h, auto)

algebraic_is_pos

def algebraic_is_pos(self, a: Ast) raises -> Bool

Return true if a is positive, and false otherwise.

Precondition: Z3_algebraic_is_value(c, a)

C API: Z3_algebraic_is_pos (z3_algebraic.h, auto)

algebraic_is_value

def algebraic_is_value(self, a: Ast) raises -> Bool

Return true if a can be used as value in the Z3 real algebraic number package.

C API: Z3_algebraic_is_value (z3_algebraic.h, auto)

algebraic_is_zero

def algebraic_is_zero(self, a: Ast) raises -> Bool

Return true if a is zero, and false otherwise.

Precondition: Z3_algebraic_is_value(c, a)

C API: Z3_algebraic_is_zero (z3_algebraic.h, auto)

algebraic_le

def algebraic_le(self, a: Ast, b: Ast) raises -> Bool

Return true if a <= b, and false otherwise.

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • Z3_algebraic_is_value(c, b)

C API: Z3_algebraic_le (z3_algebraic.h, auto)

algebraic_lt

def algebraic_lt(self, a: Ast, b: Ast) raises -> Bool

Return true if a < b, and false otherwise.

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • Z3_algebraic_is_value(c, b)

C API: Z3_algebraic_lt (z3_algebraic.h, auto)

algebraic_mul

def algebraic_mul(self, a: Ast, b: Ast) raises -> Ast

Return the value a * b.

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • Z3_algebraic_is_value(c, b)

Postcondition: Z3_algebraic_is_value(c, result)

C API: Z3_algebraic_mul (z3_algebraic.h, auto)

algebraic_neq

def algebraic_neq(self, a: Ast, b: Ast) raises -> Bool

Return true if a != b, and false otherwise.

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • Z3_algebraic_is_value(c, b)

C API: Z3_algebraic_neq (z3_algebraic.h, auto)

algebraic_power

def algebraic_power(self, a: Ast, k: UInt32) raises -> Ast

Return the a^k

Precondition: Z3_algebraic_is_value(c, a)

Postcondition: Z3_algebraic_is_value(c, result)

C API: Z3_algebraic_power (z3_algebraic.h, auto)

algebraic_root

def algebraic_root(self, a: Ast, k: UInt32) raises -> Ast

Return the a^(1/k)

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • k is even => !Z3_algebraic_is_neg(c, a)

Postcondition: Z3_algebraic_is_value(c, result)

C API: Z3_algebraic_root (z3_algebraic.h, auto)

algebraic_roots

def algebraic_roots(self, p: Ast, a: List[Ast]) raises -> AstVector

Given a multivariate polynomial p(x_0, ..., x_{n-1}, x_n), returns the roots of the univariate polynomial p(a[0], ..., a[n-1], x_n).

Preconditions:

  • p is a Z3 expression that contains only arithmetic terms and free variables.
  • forall i in [0, n) Z3_algebraic_is_value(c, a[i])

Postcondition: forall r in result Z3_algebraic_is_value(c, result)

C API: Z3_algebraic_roots (z3_algebraic.h, auto)

algebraic_sign

def algebraic_sign(self, a: Ast) raises -> Int32

Return 1 if a is positive, 0 if a is zero, and -1 if a is negative.

Precondition: Z3_algebraic_is_value(c, a)

C API: Z3_algebraic_sign (z3_algebraic.h, auto)

algebraic_sub

def algebraic_sub(self, a: Ast, b: Ast) raises -> Ast

Return the value a - b.

Preconditions:

  • Z3_algebraic_is_value(c, a)
  • Z3_algebraic_is_value(c, b)

Postcondition: Z3_algebraic_is_value(c, result)

C API: Z3_algebraic_sub (z3_algebraic.h, auto)

Polynomials (1)

polynomial_subresultants

def polynomial_subresultants(self, p: Ast, q: Ast, x: Ast) raises -> AstVector

Return the nonzero subresultants of p and q with respect to the "variable" x.

Precondition: p, q and x are Z3 expressions where p and q are arithmetic terms. Note that, any subterm that cannot be viewed as a polynomial is assumed to be a variable. Example: f(a) is a considered to be a variable in the polynomial f(a)*f(a) + 2*f(a) + 1

C API: Z3_polynomial_subresultants (z3_polynomial.h, auto)

Real Closed Fields (5)

mk_rcf_e

def mk_rcf_e(self) raises -> RcfNum

Return e (Euler's constant)

C API: Z3_rcf_mk_e (z3_rcf.h, manual)

mk_rcf_infinitesimal

def mk_rcf_infinitesimal(self) raises -> RcfNum

Return a new infinitesimal that is smaller than all elements in the Z3 field.

C API: Z3_rcf_mk_infinitesimal (z3_rcf.h, manual)

mk_rcf_int

def mk_rcf_int(self, val: Int) raises -> RcfNum

Return a RCF small integer.

C API: Z3_rcf_mk_small_int (z3_rcf.h, manual)

mk_rcf_pi

def mk_rcf_pi(self) raises -> RcfNum

Return Pi

C API: Z3_rcf_mk_pi (z3_rcf.h, manual)

mk_rcf_rational

def mk_rcf_rational(self, val: Rational) raises -> RcfNum

Return a RCF rational using the given string.

Create an exact Real Closed Field number from apn_mojo.Rational (Z3_rcf_mk_rational).

C API: Z3_rcf_mk_rational (z3_rcf.h, manual)

Fixedpoint facilities (1)

mk_fixedpoint

def mk_fixedpoint(self) raises -> Fixedpoint

Create a new fixedpoint context.

Note: User must use Z3_fixedpoint_inc_ref and Z3_fixedpoint_dec_ref to manage fixedpoint objects. Even if the context was created using Z3_mk_context instead of Z3_mk_context_rc.

C API: Z3_mk_fixedpoint (z3_fixedpoint.h, auto)

Spacer facilities (4)

qe_lite

def qe_lite(self, vars: AstVector, body: Ast) raises -> Ast

Best-effort quantifier elimination

C API: Z3_qe_lite (z3_spacer.h, auto)

qe_model_project

def qe_model_project(self, m: Model, bound: List[App], body: Ast) raises -> Ast

Project variables given a model

C API: Z3_qe_model_project (z3_spacer.h, auto)

qe_model_project_skolem

def qe_model_project_skolem(self, m: Model, bound: List[App], body: Ast, map: AstMap) raises -> Ast

Project variables given a model

C API: Z3_qe_model_project_skolem (z3_spacer.h, auto)

qe_model_project_with_witness

def qe_model_project_with_witness(self, m: Model, bound: List[App], body: Ast, map: AstMap) raises -> Ast

Project with witness extraction.

The returned map contains a binding of variables to terms that such that when the binding is used for the formula, it remains true within the model.

C API: Z3_qe_model_project_with_witness (z3_spacer.h, auto)

Config

Exposes 2 Z3 C API bindings.

__init__

def __init__(out self) raises
def __init__(out self, api: CApiPtr, raw: Z3_config)
def __init__(out self, api: CApiPtr, ctx: Z3_context, owns_ctx: Bool = True)

Create a configuration object for the Z3 context object.

Configurations are created in order to assign parameters prior to creating contexts for Z3 interaction. For example, if the users wishes to use proof generation, then call:

Z3_set_param_value(cfg, "proof", "true")

The following parameters can be set:

  • proof (Boolean) Enable proof generation
  • debug_ref_count (Boolean) Enable debug support for Z3_ast reference counting
  • trace (Boolean) Tracing support for VCC
  • trace_file_name (String) Trace out file for VCC traces
  • timeout (unsigned) default timeout (in milliseconds) used for solvers
  • well_sorted_check type checker
  • auto_config use heuristics to automatically select solver and configure it
  • model model generation for solvers, this parameter can be overwritten when creating a solver
  • model_validate validate models produced by solvers
  • unsat_core unsat-core generation for solvers, this parameter can be overwritten when creating a solver
  • encoding the string encoding used internally (must be either "unicode" - 18 bit, "bmp" - 16 bit or "ascii" - 8 bit)

Note: In previous versions of Z3, the Z3_config was used to store global and module configurations. Now, we should use Z3_global_param_set.

See also: Config.set_param_value, Z3_del_config

C API: Z3_mk_config (z3_api.h, manual)

set_param_value

def set_param_value(self, param_id: String, param_value: String) raises

Set a configuration parameter.

The following parameters can be set for

See also: Config.__init__

C API: Z3_set_param_value (z3_api.h, manual)

Solver

var s = Solver.for_logic(ctx, "QF_LIA")
s.assert_formula(ctx.mk_gt(x, ctx.mk_int(0)))
if s.check().is_sat():
    var m = s.get_model().value()

Pythonic & ergonomic methods: add, append, assert_exprs, consequences, cube_vars, dimacs, from_tactic, help, insert, model, non_units, num_scopes, on_clause, param_descrs, proof, set, set_param_bool, set_param_uint, set_rlimit, set_seed, set_timeout_ms, set_unsat_core, sexpr, solutions, statistics, to_smt2, trail, trail_levels, units, unsat_core (see Pythonic API Reference).

Commonly used Solver methods:

Method Purpose
for_logic Create a new solver customized for the given logic. It behaves like Z3_mk_solver if the logic is unknown or unsupported.
assert_formula Assert a constraint into the solver.
assert_and_track Assert a constraint a into the solver, and track it (in the unsat) core using the Boolean constant p.
check Check whether the assertions in a given solver are consistent or not.
check_assumptions Check whether the assertions in the given solver and optional assumptions are consistent or not.
get_model Retrieve the model for the last Z3_solver_check or Z3_solver_check_assumptions
get_unsat_core Retrieve the unsat core for the last Z3_solver_check_assumptions The unsat core is a subset of the assumptions a.
push Create a backtracking point.
pop Backtrack n backtracking points.
reset Remove all assertions from the solver.
set_params Set the given solver using the given parameters.
set_propagator register a callback when a new expression with a registered function is used by the solver The registered function appears at t...

Exposes 42 methods (49 Z3 C API bindings).

__init__

def __init__(out self, ctx: Context) raises

Create a new solver. This solver is a "combined solver" (see combined_solver module) that internally uses a non-incremental (solver1) and an incremental solver (solver2). This combined solver changes its behaviour based on how it is used and how its parameters are set.

If the solver is used in a non incremental way (i.e. no calls to Z3_solver_push() or Z3_solver_pop(), and no calls to Z3_solver_assert() or Z3_solver_assert_and_track() after checking satisfiability without an intervening Z3_solver_reset()) then solver1 will be used. This solver will apply Z3's "default" tactic.

The "default" tactic will attempt to probe the logic used by the assertions and will apply a specialized tactic if one is supported. Otherwise the general (and-then simplify smt) tactic will be used.

If the solver is used in an incremental way then the combined solver will switch to using solver2 (which behaves similarly to the general "smt" tactic).

Note however it is possible to set the solver2_timeout, solver2_unknown, and ignore_solver1 parameters of the combined solver to change its behaviour.

The function Z3_solver_get_model retrieves a model if the assertions is satisfiable (i.e., the result is Z3_L_TRUE) and model construction is enabled. The function Z3_solver_get_model can also be used even if the result is Z3_L_UNDEF, but the returned model is not guaranteed to satisfy quantified assertions.

Note: User must use Z3_solver_inc_ref and Z3_solver_dec_ref to manage solver objects. Even if the context was created using Z3_mk_context instead of Z3_mk_context_rc.

See also: Context.mk_simple_solver, Solver.for_logic, Tactic.to_solver

C API: Z3_mk_solver (z3_api.h, manual)

add_simplifier

def add_simplifier(self, simplifier: Simplifier) raises -> Solver

Attach simplifier to a solver. The solver will use the simplifier for incremental pre-processing.

C API: Z3_solver_add_simplifier (z3_api.h, auto)

assert_and_track

def assert_and_track(self, formula: Ast, tracker: Ast) raises

Assert a constraint a into the solver, and track it (in the unsat) core using the Boolean constant p.

This API is an alternative to Z3_solver_check_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 Z3_solver_assert_and_track and the Boolean literals provided using Z3_solver_check_assumptions.

Preconditions:

  • a must be a Boolean expression
  • p must be a Boolean constant (aka variable).

See also: Solver.assert_formula, Solver.reset

C API: Z3_solver_assert_and_track (z3_api.h, manual)

assert_formula

def assert_formula(self, formula: Ast) raises

Assert a constraint into the solver.

The functions Z3_solver_check and Z3_solver_check_assumptions should be used to check whether the logical context is consistent or not.

See also: Solver.assert_and_track, Solver.reset

C API: Z3_solver_assert (z3_api.h, manual)

assertions

def assertions(self) raises -> List[Ast]

Return the set of asserted formulas on the solver.

C API: Z3_solver_get_assertions (z3_api.h, manual)

check

def check(self) raises -> CheckResult

Check whether the assertions in a given solver are consistent or not.

The function Z3_solver_get_model retrieves a model if the assertions is satisfiable (i.e., the result is Z3_L_TRUE) and model construction is enabled. Note that if the call returns Z3_L_UNDEF, Z3 does not ensure that calls to Z3_solver_get_model succeed and any models produced in this case are not guaranteed to satisfy the assertions.

The function Z3_solver_get_proof retrieves a proof if proof generation was enabled when the context was created, and the assertions are unsatisfiable (i.e., the result is Z3_L_FALSE).

See also: Solver.check_assumptions

C API: Z3_solver_check (z3_api.h, manual)

check_assumptions

def check_assumptions(self, assumptions: List[Ast]) raises -> CheckResult

Check whether the assertions in the given solver and optional assumptions are consistent or not.

The function Z3_solver_get_unsat_core retrieves the subset of the assumptions used in the unsatisfiability proof produced by Z3.

See also: Solver.check

C API: Z3_solver_check_assumptions (z3_api.h, manual)

congruence_explain

def congruence_explain(self, a: Ast, b: Ast) raises -> Ast

retrieve explanation for congruence.

Precondition: root(a) = root(b)

C API: Z3_solver_congruence_explain (z3_api.h, auto)

congruence_next

def congruence_next(self, a: Ast) raises -> Ast

retrieve the next expression in the congruence class. The set of congruent siblings form a cyclic list. Repeated calls on the siblings will result in returning to the original expression.

C API: Z3_solver_congruence_next (z3_api.h, auto)

congruence_root

def congruence_root(self, a: Ast) raises -> Ast

retrieve the congruence closure root of an expression. The root is retrieved relative to the state where the solver was in when it completed. If it completed during a set of case splits, the congruence roots are relative to these case splits. That is, the congruences are not consequences but they are true under the current state.

C API: Z3_solver_congruence_root (z3_api.h, auto)

cube

def cube(self, vars: AstVector, backtrack_level: UInt32) raises -> AstVector

extract a next cube for a solver. The last cube is the constant true or false. The number of (non-constant) cubes is by default 1. For the sat solver cubing is controlled using parameters sat.lookahead.cube.cutoff and sat.lookahead.cube.fraction.

The third argument is a vector of variables that may be used for cubing. The contents of the vector is only used in the first call. The initial list of variables is used in subsequent calls until it returns the unsatisfiable cube. The vector is modified to contain a set of Autarky variables that occur in clauses that are affected by the (last literal in the) cube. These variables could be used by a different cuber (on a different solver object) for further recursive cubing.

The last argument is a backtracking level. It instructs the cube process to backtrack below the indicated level for the next cube.

C API: Z3_solver_cube (z3_api.h, auto)

for_logic

def for_logic(ctx: Context, logic: String) raises -> Solver

Create a new solver customized for the given logic. It behaves like Z3_mk_solver if the logic is unknown or unsupported.

Note: User must use Z3_solver_inc_ref and Z3_solver_dec_ref to manage solver objects. Even if the context was created using Z3_mk_context instead of Z3_mk_context_rc.

See also: Solver.__init__, Context.mk_simple_solver, Tactic.to_solver

C API: Z3_mk_solver_for_logic (z3_api.h, manual)

from_file

def from_file(self, file_name: String) raises

load solver assertions from a file.

See also: Solver.from_string, Solver.to_string

C API: Z3_solver_from_file (z3_api.h, auto)

from_string

def from_string(self, smt2: String) raises

load solver assertions from a string.

See also: Solver.from_file, Solver.to_string

C API: Z3_solver_from_string (z3_api.h, manual)

get_consequences

def get_consequences(self, assumptions: AstVector, variables: AstVector, consequences: AstVector) raises -> Lbool

retrieve consequences from solver that determine values of the supplied function symbols.

C API: Z3_solver_get_consequences (z3_api.h, auto)

get_help

def get_help(self) raises -> String

Return a string describing all solver available parameters.

See also: Solver.get_param_descrs, Solver.set_params

C API: Z3_solver_get_help (z3_api.h, auto)

get_implied_equalities

def get_implied_equalities(self, terms: List[Ast]) raises -> Tuple[CheckResult, List[UInt32]]

Retrieve congruence class representatives for terms.

The function can be used for relying on Z3 to identify equal terms under the current set of assumptions. The array of terms and array of class identifiers should have the same length. The class identifiers are numerals that are assigned to the same value for their corresponding terms if the current context forces the terms to be equal. You cannot deduce that terms corresponding to different numerals must be all different, (especially when using non-convex theories). All implied equalities are returned by this call. This means that two terms map to the same class identifier if and only if the current context implies that they are equal.

A side-effect of the function is a satisfiability check on the assertions on the solver that is passed in. The function return Z3_L_FALSE if the current assertions are not satisfiable.

C API: Z3_get_implied_equalities (z3_api.h, manual)

get_levels

def get_levels(self, literals: AstVector) raises -> List[UInt32]

retrieve the decision depth of Boolean literals (variables or their negations). Assumes a check-sat call and no other calls (to extract models) have been invoked.

C API: Z3_solver_get_levels (z3_api.h, manual)

get_model

def get_model(self) raises -> Optional[Model]

Retrieve the model for the last Z3_solver_check or Z3_solver_check_assumptions

The error handler is invoked if a model is not available because the commands above were not invoked for the given solver, or if the result was Z3_L_FALSE.

C API: Z3_solver_get_model (z3_api.h, manual)

get_non_units

def get_non_units(self) raises -> AstVector

Return the set of non units in the solver state.

C API: Z3_solver_get_non_units (z3_api.h, auto)

get_num_scopes

def get_num_scopes(self) raises -> UInt32

Return the number of backtracking points.

See also: Solver.push, Solver.pop

C API: Z3_solver_get_num_scopes (z3_api.h, auto)

get_param_descrs

def get_param_descrs(self) raises -> ParamDescrs

Return the parameter description set for the given solver object.

See also: Solver.get_help, Solver.set_params

C API: Z3_solver_get_param_descrs (z3_api.h, auto)

get_proof

def get_proof(self) raises -> Ast

Retrieve the proof for the last Z3_solver_check or Z3_solver_check_assumptions

The error handler is invoked if proof generation is not enabled, or if the commands above were not invoked for the given solver, or if the result was different from Z3_L_FALSE.

C API: Z3_solver_get_proof (z3_api.h, auto)

get_statistics

def get_statistics(self) raises -> Stats

Return statistics for the given solver.

Note: User must use Z3_stats_inc_ref and Z3_stats_dec_ref to manage Z3_stats objects.

C API: Z3_solver_get_statistics (z3_api.h, auto)

get_trail

def get_trail(self) raises -> AstVector

Return the trail modulo model conversion, in order of decision level The decision level can be retrieved using Z3_solver_get_level based on the trail.

C API: Z3_solver_get_trail (z3_api.h, auto)

get_units

def get_units(self) raises -> AstVector

Return the set of units modulo model conversion.

C API: Z3_solver_get_units (z3_api.h, auto)

get_unsat_core

def get_unsat_core(self) raises -> List[Ast]

Retrieve the unsat core for the last Z3_solver_check_assumptions The unsat core is a subset of the assumptions a.

By default, the unsat core will not be minimized. Generation of a minimized unsat core can be enabled via the "sat.core.minimize" and "smt.core.minimize" settings for SAT and SMT cores respectively. Generation of minimized unsat cores will be more expensive.

C API: Z3_solver_get_unsat_core (z3_api.h, manual)

import_model_converter

def import_model_converter(self, dst: Solver) raises

Ad-hoc method for importing model conversion from solver.

This method is used for scenarios where src has been used to solve a set of formulas and was interrupted. The dst solver may be a strengthening of src obtained from cubing (assigning a subset of literals or adding constraints over the assertions available in src). If dst ends up being satisfiable, the model for dst may not correspond to a model of the original formula due to inprocessing in src. This method is used to take the side-effect of inprocessing into account when returning a model for dst.

C API: Z3_solver_import_model_converter (z3_api.h, auto)

interrupt

def interrupt(self) raises

Solver local interrupt. Normally you should use Z3_interrupt to cancel solvers because only one solver is enabled concurrently per context. However, per GitHub issue #1006, there are use cases where it is more convenient to cancel a specific solver. Solvers that are not selected for interrupts are left alone.

C API: Z3_solver_interrupt (z3_api.h, auto)

pop

def pop(self, n: Int = 1) raises

Backtrack n backtracking points.

Precondition: n <= Z3_solver_get_num_scopes(c, s)

See also: Solver.get_num_scopes, Solver.push

C API: Z3_solver_pop (z3_api.h, manual)

propagate_register

def propagate_register(self, e: Ast) raises

register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Vector can be registered for propagation.

C API: Z3_solver_propagate_register (z3_api.h, auto)

push

def push(self) raises

Create a backtracking point.

The solver contains a stack of assertions.

See also: Solver.get_num_scopes, Solver.pop

C API: Z3_solver_push (z3_api.h, manual)

reason_unknown

def reason_unknown(self) raises -> String

Return a brief justification for an "unknown" result (i.e., Z3_L_UNDEF) for the commands Z3_solver_check and Z3_solver_check_assumptions

C API: Z3_solver_get_reason_unknown (z3_api.h, manual)

register_on_clause

def register_on_clause[H: ClauseHandler](self, handler: ArcPointer[H]) raises

register a callback to that retrieves assumed, inferred and deleted clauses during search.

Register a ClauseHandler called on asserted, inferred, and deleted CDCL(T) clauses (Z3_solver_register_on_clause).

Parameters:

  • c — - context.
  • s — - solver object.
  • user_context — - a context used to maintain state for callbacks.
  • on_clause_eh — - a callback that is invoked by when a clause is - asserted to the CDCL engine (corresponding to an input clause after pre-processing) - inferred by CDCL(T) using either a SAT or theory conflict/propagation - deleted by the CDCL(T) engine

C API: Z3_solver_register_on_clause (z3_api.h, manual)

reset

def reset(self) raises

Remove all assertions from the solver.

See also: Solver.assert_formula, Solver.assert_and_track

C API: Z3_solver_reset (z3_api.h, manual)

set_initial_value

def set_initial_value(self, v: Ast, val: Ast) raises

provide an initialization hint to the solver. The initialization hint is used to calibrate an initial value of the expression that represents a variable. If the variable is Boolean, the initial phase is set according to value. If the variable is an integer or real, the initial Simplex tableau is recalibrated to attempt to follow the value assignment.

C API: Z3_solver_set_initial_value (z3_api.h, auto)

set_params

def set_params(self, params: Params) raises

Set the given solver using the given parameters.

See also: Solver.get_help, Solver.get_param_descrs

C API: Z3_solver_set_params (z3_api.h, manual)

set_propagator

def set_propagator[P: UserPropagator](self, propagator: ArcPointer[P], *, fixed: Bool = False, final: Bool = False, eq: Bool = False, diseq: Bool = False, created: Bool = False, decide: Bool = False, on_binding: Bool = False,) raises

Attach a UserPropagator to this solver and register the selected Z3 callbacks.

solve_for

def solve_for(self, variables: AstVector, terms: AstVector, guards: AstVector) raises

retrieve a 'solution' for variables as defined by equalities in maintained by solvers. At this point, only linear solution are supported. The solution to variables may be presented in triangular form, such that variables used in solutions themselves have solutions.

C API: Z3_solver_solve_for (z3_api.h, auto)

to_dimacs_string

def to_dimacs_string(self, include_names: Bool) raises -> String

Convert a solver into a DIMACS formatted string.

See also: Goal.to_dimacs_string

C API: Z3_solver_to_dimacs_string (z3_api.h, auto)

to_string

def to_string(self) raises -> String

Convert a solver into a string.

See also: Solver.from_file, Solver.from_string

C API: Z3_solver_to_string (z3_api.h, manual)

translate

def translate(self, target: Context) raises -> Solver

Copy a solver s from the context source to the context target.

C API: Z3_solver_translate (z3_api.h, auto)

Model

var m = s.get_model().value()
var val = m.eval(x, model_completion=True).value()
print("x =", val)

Pythonic & ergonomic methods: consts, decls, evaluate, func_interp, funcs, get_bool, get_integer, get_rational, get_universe, num_sorts, project, sexpr, sorts (see Pythonic API Reference).

Commonly used Model methods:

Method Purpose
eval Evaluate the AST node t in the given model. Return true if succeeded, and store the result in v.
get_const_interp Return the interpretation (i.e., assignment) of constant a in the model m.
get_func_interp Return the interpretation of the function f in the model m.
const_decl Return the i-th constant in the given model.
num_consts Return the number of constants assigned by the given model.
has_interp Test if there exists an interpretation (i.e., assignment) for a in the model m.
to_string Convert the given model into a string.
translate translate model from context c to context dst.

Exposes 14 Z3 C API bindings.

const_decl

def const_decl(self, index: Int) raises -> FuncDecl

Return the i-th constant in the given model.

Precondition: i < Z3_model_get_num_consts(c, m)

See also: Model.eval, Model.num_consts

C API: Z3_model_get_const_decl (z3_api.h, manual)

eval

def eval(self, ast: Ast, model_completion: Bool = True) raises -> Optional[Ast]

Evaluate the AST node t in the given model. Return true if succeeded, and store the result in v.

If model_completion is true, then Z3 will assign an interpretation for any constant or function that does not have an interpretation in m. These constants and functions were essentially don't cares.

If model_completion is false, then Z3 will not assign interpretations to constants for functions that do not have interpretations in m. Evaluation behaves as the identify function in this case.

The evaluation may fail for the following reasons:

  • t contains a quantifier.

  • the model m is partial, that is, it doesn't have a complete interpretation for uninterpreted functions. That is, the option MODEL_PARTIAL=true was used.

  • t is type incorrect.

  • Z3_interrupt was invoked during evaluation.

C API: Z3_model_eval (z3_api.h, manual)

extrapolate

def extrapolate(self, fml: Ast) raises -> Ast

Extrapolates a model of a formula

C API: Z3_model_extrapolate (z3_spacer.h, auto)

get_const_interp

def get_const_interp(self, a: FuncDecl) raises -> Ast

Return the interpretation (i.e., assignment) of constant a in the model m. Return NULL, if the model does not assign an interpretation for a. That should be interpreted as: the value of a does not matter.

Precondition: Z3_get_arity(c, a) == 0

C API: Z3_model_get_const_interp (z3_api.h, auto)

get_func_decl

def get_func_decl(self, i: UInt32) raises -> FuncDecl

Return the declaration of the i-th function in the given model.

Precondition: i < Z3_model_get_num_funcs(c, m)

See also: Model.get_num_funcs

C API: Z3_model_get_func_decl (z3_api.h, auto)

get_func_interp

def get_func_interp(self, f: FuncDecl) raises -> FuncInterp

Return the interpretation of the function f in the model m. Return NULL, if the model does not assign an interpretation for f. That should be interpreted as: the f does not matter.

Precondition: Z3_get_arity(c, f) > 0

Note: Reference counting must be used to manage Z3_func_interp objects, even when the Z3_context was created using Z3_mk_context instead of Z3_mk_context_rc.

C API: Z3_model_get_func_interp (z3_api.h, auto)

get_num_funcs

def get_num_funcs(self) raises -> UInt32

Return the number of function interpretations in the given model.

A function interpretation is represented as a finite map and an 'else' value. Each entry in the finite map represents the value of a function given a set of arguments.

See also: Model.get_func_decl

C API: Z3_model_get_num_funcs (z3_api.h, auto)

get_num_sorts

def get_num_sorts(self) raises -> UInt32

Return the number of uninterpreted sorts that m assigns an interpretation to.

Z3 also provides an interpretation for uninterpreted sorts used in a formula. The interpretation for a sort s is a finite set of distinct values. We say this finite set is the "universe" of s.

get_sort

def get_sort(self, i: UInt32) raises -> Sort

Return a uninterpreted sort that m assigns an interpretation.

Precondition: i < Z3_model_get_num_sorts(c, m)

See also: Model.get_num_sorts, Model.get_sort_universe

C API: Z3_model_get_sort (z3_api.h, auto)

get_sort_universe

def get_sort_universe(self, s: Sort) raises -> AstVector

Return the finite set of distinct values that represent the interpretation for sort s.

has_interp

def has_interp(self, a: FuncDecl) raises -> Bool

Test if there exists an interpretation (i.e., assignment) for a in the model m.

C API: Z3_model_has_interp (z3_api.h, auto)

num_consts

def num_consts(self) raises -> Int

Return the number of constants assigned by the given model.

See also: Model.const_decl

C API: Z3_model_get_num_consts (z3_api.h, manual)

to_string

def to_string(self) raises -> String

Convert the given model into a string.

Warning: The result buffer is statically allocated by Z3. It will be automatically deallocated when Z3_del_context is invoked. So, the buffer is invalidated in the next call to Z3_model_to_string.

C API: Z3_model_to_string (z3_api.h, manual)

translate

def translate(self, dst: Context) raises -> Model

translate model from context c to context dst.

Note: Use this method for cloning state between contexts. Note that operations on contexts are not thread safe and therefore all operations that related to a given context have to be synchronized (or run in the same thread).

C API: Z3_model_translate (z3_api.h, auto)

Optimize

var opt = Optimize.create(ctx)
opt.assert_formula(ctx.mk_le(x, ctx.mk_int(10)))
var obj = opt.maximize(x)
if opt.check().is_sat():
    print("upper =", opt.get_upper(obj))

Pythonic & ergonomic methods: add, add_soft, append, assert_exprs, assertions, help, insert, lower, lower_values, model, objectives, param_descrs, reason_unknown, set, set_timeout_ms, sexpr, statistics, unsat_core, upper, upper_values (see Pythonic API Reference).

Commonly used Optimize methods:

Method Purpose
create Create a new optimize context.
assert_formula Assert hard constraint to the optimization context.
assert_soft Assert soft constraint to the optimization context.
maximize Add a maximization constraint.
minimize Add a minimization constraint.
check Check consistency and produce optimal values.
get_model Retrieve the model for the last Z3_optimize_check
get_lower Retrieve lower bound value or approximation for the i'th optimization objective.
get_upper Retrieve upper bound value or approximation for the i'th optimization objective.
push Create a backtracking point.
pop Backtrack one level.
set_on_model register a model event handler for new models.

Exposes 28 Z3 C API bindings.

assert_and_track

def assert_and_track(self, a: Ast, t: Ast) raises

Assert tracked hard constraint to the optimization context.

See also: Optimize.assert_formula, Optimize.assert_soft

C API: Z3_optimize_assert_and_track (z3_optimization.h, auto)

assert_formula

def assert_formula(self, formula: Ast) raises

Assert hard constraint to the optimization context.

See also: Optimize.assert_soft, Optimize.assert_and_track

C API: Z3_optimize_assert (z3_optimization.h, manual)

assert_soft

def assert_soft(self, formula: Ast, weight: String = "1", group: String = "") raises -> Int

Assert soft constraint to the optimization context.

Parameters:

  • c — - context
  • o — - optimization context
  • a — - formula
  • weight — - a penalty for violating soft constraint. Negative weights convert into rewards.
  • id — - optional identifier to group soft constraints

See also: Optimize.assert_formula, Optimize.assert_and_track

C API: Z3_optimize_assert_soft (z3_optimization.h, manual)

check

def check(self) raises -> CheckResult

Check consistency and produce optimal values.

Parameters:

  • c — - context
  • o — - optimization context
  • num_assumptions — - number of additional assumptions
  • assumptions — - the additional assumptions

See also: Optimize.get_reason_unknown, Optimize.get_model, Optimize.get_statistics, Optimize.get_unsat_core

C API: Z3_optimize_check (z3_optimization.h, manual)

create

def create(ctx: Context) raises -> Optimize

Create a new optimize context.

Note: User must use Z3_optimize_inc_ref and Z3_optimize_dec_ref to manage optimize objects. Even if the context was created using Z3_mk_context instead of Z3_mk_context_rc.

C API: Z3_mk_optimize (z3_optimization.h, manual)

from_file

def from_file(self, s: String) raises

Parse an SMT-LIB2 file with assertions, soft constraints and optimization objectives. Add the parsed constraints and objectives to the optimization context.

Parameters:

  • c — - context.
  • o — - optimize context.
  • s — - path to file containing SMT2 specification.

See also: Optimize.from_string, Optimize.to_string

C API: Z3_optimize_from_file (z3_optimization.h, auto)

from_string

def from_string(self, s: String) raises

Parse an SMT-LIB2 string with assertions, soft constraints and optimization objectives. Add the parsed constraints and objectives to the optimization context.

Parameters:

  • c — - context.
  • o — - optimize context.
  • s — - string containing SMT2 specification.

See also: Optimize.from_file, Optimize.to_string

C API: Z3_optimize_from_string (z3_optimization.h, auto)

get_assertions

def get_assertions(self) raises -> AstVector

Return the set of asserted formulas on the optimization context.

C API: Z3_optimize_get_assertions (z3_optimization.h, auto)

get_help

def get_help(self) raises -> String

Return a string containing a description of parameters accepted by optimize.

See also: Optimize.get_param_descrs, Optimize.set_params

C API: Z3_optimize_get_help (z3_optimization.h, auto)

get_lower

def get_lower(self, handle: Int) raises -> Ast

Retrieve lower bound value or approximation for the i'th optimization objective.

An attained, certified irrational algebraic optimum is returned as an exact algebraic numeral by both Z3_optimize_get_lower and Z3_optimize_get_upper. Use Z3_get_algebraic_number_lower and Z3_get_algebraic_number_upper to obtain rational approximations.

A certified finite limit that is not attained includes an infinitesimal term: for example, sqrt(2) - epsilon for a supremum. The finite part can be algebraic even though the whole expression is not an algebraic numeral. Use Z3_optimize_get_lower_as_vector to inspect the finite part and the infinitesimal coefficient separately.

Parameters:

  • c — - context
  • o — - optimization context
  • idx — - index of optimization objective

See also: Optimize.get_upper, Optimize.get_lower_as_vector, Optimize.get_upper_as_vector

C API: Z3_optimize_get_lower (z3_optimization.h, manual)

get_lower_as_vector

def get_lower_as_vector(self, idx: UInt32) raises -> AstVector

Retrieve lower bound value or approximation for the i'th optimization objective. The returned vector is of length 3. Its entries are coefficients a, b, c and encode the result of Z3_optimize_get_lower a * infinity + b + c * epsilon. The coefficients a and c are rational numerals. The finite part b is a rational numeral or an exact irrational algebraic numeral when such a bound has been certified. For a finite attained optimum, a and c are zero. A finite open limit has a equal to zero and a nonzero infinitesimal coefficient c, even when b is algebraic.

Parameters:

  • c — - context
  • o — - optimization context
  • idx — - index of optimization objective

See also: Optimize.get_lower, Optimize.get_upper, Optimize.get_upper_as_vector

C API: Z3_optimize_get_lower_as_vector (z3_optimization.h, auto)

get_model

def get_model(self) raises -> Optional[Model]

Retrieve the model for the last Z3_optimize_check

The error handler is invoked if a model is not available because the commands above were not invoked for the given optimization solver, or if the result was Z3_L_FALSE.

C API: Z3_optimize_get_model (z3_optimization.h, manual)

get_objectives

def get_objectives(self) raises -> AstVector

Return objectives on the optimization context. If the objective function is a max-sat objective it is returned as a Pseudo-Boolean (minimization) sum of the form (+ (if f1 w1 0) (if f2 w2 0) ...) If the objective function is entered as a maximization objective, then return the corresponding minimization objective. In this way the resulting objective function is always returned as a minimization objective.

C API: Z3_optimize_get_objectives (z3_optimization.h, auto)

get_param_descrs

def get_param_descrs(self) raises -> ParamDescrs

Return the parameter description set for the given optimize object.

Parameters:

  • c — - context
  • o — - optimization context

See also: Optimize.get_help, Optimize.set_params

C API: Z3_optimize_get_param_descrs (z3_optimization.h, auto)

get_reason_unknown

def get_reason_unknown(self) raises -> String

Retrieve a string that describes the last status returned by Z3_optimize_check.

Use this method when Z3_optimize_check returns Z3_L_UNDEF.

C API: Z3_optimize_get_reason_unknown (z3_optimization.h, auto)

get_statistics

def get_statistics(self) raises -> Stats

Retrieve statistics information from the last call to Z3_optimize_check

C API: Z3_optimize_get_statistics (z3_optimization.h, auto)

get_unsat_core

def get_unsat_core(self) raises -> AstVector

Retrieve the unsat core for the last Z3_optimize_check The unsat core is a subset of the assumptions a.

C API: Z3_optimize_get_unsat_core (z3_optimization.h, auto)

get_upper

def get_upper(self, handle: Int) raises -> Ast

Retrieve upper bound value or approximation for the i'th optimization objective.

Certified algebraic optima and finite open limits are returned as described for Z3_optimize_get_lower.

Parameters:

  • c — - context
  • o — - optimization context
  • idx — - index of optimization objective

See also: Optimize.get_lower, Optimize.get_lower_as_vector, Optimize.get_upper_as_vector

C API: Z3_optimize_get_upper (z3_optimization.h, manual)

get_upper_as_vector

def get_upper_as_vector(self, idx: UInt32) raises -> AstVector

Retrieve upper bound value or approximation for the i'th optimization objective.

The returned vector has the same coefficient and algebraic-value semantics as Z3_optimize_get_lower_as_vector, and encodes the result of Z3_optimize_get_upper.

Parameters:

  • c — - context
  • o — - optimization context
  • idx — - index of optimization objective

See also: Optimize.get_lower, Optimize.get_upper, Optimize.get_lower_as_vector

C API: Z3_optimize_get_upper_as_vector (z3_optimization.h, auto)

maximize

def maximize(self, expr: Ast) raises -> Int

Add a maximization constraint.

Parameters:

  • c — - context
  • o — - optimization context
  • t — - arithmetical term

See also: Optimize.minimize

C API: Z3_optimize_maximize (z3_optimization.h, manual)

minimize

def minimize(self, expr: Ast) raises -> Int

Add a minimization constraint.

Parameters:

  • c — - context
  • o — - optimization context
  • t — - arithmetical term

See also: Optimize.maximize

C API: Z3_optimize_minimize (z3_optimization.h, manual)

pop

def pop(self) raises

Backtrack one level.

Precondition: The number of calls to pop cannot exceed calls to push.

See also: Optimize.push

C API: Z3_optimize_pop (z3_optimization.h, manual)

push

def push(self) raises

Create a backtracking point.

The optimize solver contains a set of rules, added facts and assertions. The set of rules, facts and assertions are restored upon calling Z3_optimize_pop.

See also: Optimize.pop

C API: Z3_optimize_push (z3_optimization.h, manual)

set_initial_value

def set_initial_value(self, v: Ast, val: Ast) raises

provide an initialization hint to the solver. The initialization hint is used to calibrate an initial value of the expression that represents a variable. If the variable is Boolean, the initial phase is set according to value. If the variable is an integer or real, the initial Simplex tableau is recalibrated to attempt to follow the value assignment.

C API: Z3_optimize_set_initial_value (z3_optimization.h, auto)

set_on_model

def set_on_model[H: ModelHandler](self, handler: ArcPointer[H]) raises

register a model event handler for new models.

Register a ModelHandler called whenever optimization finds an improving model (Z3_optimize_register_model_eh).

C API: Z3_optimize_register_model_eh (z3_optimization.h, manual)

set_params

def set_params(self, params: Params) raises

Set parameters on optimization context, including parameters for the underlying SMT solver.

Parameters:

  • c — - context
  • o — - optimization context
  • p — - parameters

See also: Optimize.get_help, Optimize.get_param_descrs

C API: Z3_optimize_set_params (z3_optimization.h, manual)

to_string

def to_string(self) raises -> String

Print the current context as a string.

Parameters:

  • c — - context.
  • o — - optimization context.

See also: Optimize.from_file, Optimize.from_string

C API: Z3_optimize_to_string (z3_optimization.h, manual)

translate

def translate(self, target: Context) raises -> Optimize

Copy an optimization context from a source to a target context.

This function allows translating an optimization context from one Z3_context to another. This is useful when working with multiple contexts and needing to transfer optimization problems between them.

Parameters:

  • c — Source context containing the optimization context to translate
  • o — The optimization context to translate from the source context
  • target — Target context where the optimization context will be created

Returns: A new optimization context in the target context with the same state

C API: Z3_optimize_translate (z3_optimization.h, auto)

Fixedpoint

var fp = Fixedpoint(ctx)
fp.register_relation(reach)
fp.add_rule(rule, "step")
var ans = fp.query(goal)

Pythonic & ergonomic methods: add, append, assert_exprs, assertions, create, fact, help, insert, param_descrs, parse_file, parse_string, query_check, reason_unknown, rule, set, sexpr, statistics (see Pythonic API Reference).

Exposes 29 Z3 C API bindings.

add_constraint

def add_constraint(self, e: Ast, lvl: UInt32) raises

Safe wrapper for Z3_fixedpoint_add_constraint.

C API: Z3_fixedpoint_add_constraint (z3_fixedpoint.h, auto)

add_cover

def add_cover(self, level: Int32, pred: FuncDecl, property: Ast) raises

Add property about the predicate pred. Add a property of predicate pred at level. It gets pushed forward when possible.

Note: level = -1 is treated as the fixedpoint. So passing -1 for the level means that the property is true of the fixed-point unfolding with respect to pred.

Note: this functionality is PDR specific.

C API: Z3_fixedpoint_add_cover (z3_fixedpoint.h, auto)

add_fact

def add_fact(self, r: FuncDecl, args: List[UInt32]) raises

Add a Database fact.

The number of arguments num_args should be equal to the number of sorts in the domain of r. Each sort in the domain should be an integral (bit-vector, Boolean or or finite domain sort).

The call has the same effect as adding a rule where r is applied to the arguments.

Parameters:

  • c — - context
  • d — - fixed point context
  • r — - relation signature for the row.
  • num_args — - number of columns for the given row.
  • args — - array of the row elements.

C API: Z3_fixedpoint_add_fact (z3_fixedpoint.h, auto)

add_invariant

def add_invariant(self, pred: FuncDecl, property: Ast) raises

Add an invariant for the predicate pred. Add an assumed invariant of predicate pred.

Note: this functionality is Spacer specific.

C API: Z3_fixedpoint_add_invariant (z3_spacer.h, auto)

add_rule

def add_rule(self, rule: Ast, name: String) raises
def add_rule(self, rule: Ast, name: Symbol) raises

Add a universal Horn clause as a named rule. The horn_rule should be of the form:

horn_rule ::= (forall (bound-vars) horn_rule)
           |  (=> atoms horn_rule)
           |  atom

C API: Z3_fixedpoint_add_rule (z3_fixedpoint.h, auto)

assert_

def assert_(self, axiom: Ast) raises

Assert a constraint to the fixedpoint context.

The constraints are used as background axioms when the fixedpoint engine uses the PDR mode. They are ignored for standard Datalog mode.

C API: Z3_fixedpoint_assert (z3_fixedpoint.h, auto)

from_file

def from_file(self, s: String) raises -> AstVector

Parse an SMT-LIB2 file with fixedpoint rules. Add the rules to the current fixedpoint context. Return the set of queries in the file.

Parameters:

  • c — - context.
  • f — - fixedpoint context.
  • s — - path to file containing SMT2 specification.

See also: Fixedpoint.from_string, Fixedpoint.to_string

C API: Z3_fixedpoint_from_file (z3_fixedpoint.h, auto)

from_string

def from_string(self, s: String) raises -> AstVector

Parse an SMT-LIB2 string with fixedpoint rules. Add the rules to the current fixedpoint context. Return the set of queries in the string.

Parameters:

  • c — - context.
  • f — - fixedpoint context.
  • s — - string containing SMT2 specification.

See also: Fixedpoint.from_file, Fixedpoint.to_string

C API: Z3_fixedpoint_from_string (z3_fixedpoint.h, auto)

get_answer

def get_answer(self) raises -> Ast

Retrieve a formula that encodes satisfying answers to the query.

When used in Datalog mode, the returned answer is a disjunction of conjuncts. Each conjunct encodes values of the bound variables of the query that are satisfied. In PDR mode, the returned answer is a single conjunction.

When used in Datalog mode the previous call to Z3_fixedpoint_query must have returned Z3_L_TRUE. When used with the PDR engine, the previous call must have been either Z3_L_TRUE or Z3_L_FALSE.

C API: Z3_fixedpoint_get_answer (z3_fixedpoint.h, auto)

get_assertions

def get_assertions(self) raises -> AstVector

Retrieve set of background assertions from fixedpoint context.

C API: Z3_fixedpoint_get_assertions (z3_fixedpoint.h, auto)

get_cover_delta

def get_cover_delta(self, level: Int32, pred: FuncDecl) raises -> Ast

Retrieve the current cover of pred up to level unfoldings. Return just the delta that is known at level. To obtain the full set of properties of pred one should query at level+1 , level+2 etc, and include level=-1.

Note: this functionality is PDR specific.

C API: Z3_fixedpoint_get_cover_delta (z3_fixedpoint.h, auto)

get_ground_sat_answer

def get_ground_sat_answer(self) raises -> Ast

Retrieve a bottom-up (from query) sequence of ground facts

The previous call to Z3_fixedpoint_query must have returned Z3_L_TRUE.

C API: Z3_fixedpoint_get_ground_sat_answer (z3_spacer.h, auto)

get_help

def get_help(self) raises -> String

Return a string describing all fixedpoint available parameters.

get_num_levels

def get_num_levels(self, pred: FuncDecl) raises -> UInt32

Query the PDR engine for the maximal levels properties are known about predicate.

This call retrieves the maximal number of relevant unfoldings of pred with respect to the current exploration state. Note: this functionality is PDR specific.

C API: Z3_fixedpoint_get_num_levels (z3_fixedpoint.h, auto)

get_param_descrs

def get_param_descrs(self) raises -> ParamDescrs

Return the parameter description set for the given fixedpoint object.

get_reachable

def get_reachable(self, pred: FuncDecl) raises -> Ast

Retrieve reachable states of a predicate. Note: this functionality is Spacer specific.

C API: Z3_fixedpoint_get_reachable (z3_spacer.h, auto)

get_reason_unknown

def get_reason_unknown(self) raises -> String

Retrieve a string that describes the last status returned by Z3_fixedpoint_query.

Use this method when Z3_fixedpoint_query returns Z3_L_UNDEF.

C API: Z3_fixedpoint_get_reason_unknown (z3_fixedpoint.h, auto)

get_rule_names_along_trace

def get_rule_names_along_trace(self) raises -> Symbol

Obtain the list of rules along the counterexample trace.

C API: Z3_fixedpoint_get_rule_names_along_trace (z3_spacer.h, auto)

get_rules

def get_rules(self) raises -> AstVector

Retrieve set of rules from fixedpoint context.

C API: Z3_fixedpoint_get_rules (z3_fixedpoint.h, auto)

get_rules_along_trace

def get_rules_along_trace(self) raises -> AstVector

Obtain the list of rules along the counterexample trace.

C API: Z3_fixedpoint_get_rules_along_trace (z3_spacer.h, auto)

get_statistics

def get_statistics(self) raises -> Stats

Retrieve statistics information from the last call to Z3_fixedpoint_query.

C API: Z3_fixedpoint_get_statistics (z3_fixedpoint.h, auto)

query

def query(self, query: Ast) raises -> Lbool

Pose a query against the asserted rules.

query ::= (exists (bound-vars) query)
      |  literals

query returns

  • Z3_L_FALSE if the query is unsatisfiable.
  • Z3_L_TRUE if the query is satisfiable. Obtain the answer by calling Z3_fixedpoint_get_answer.
  • Z3_L_UNDEF if the query was interrupted, timed out or otherwise failed.

C API: Z3_fixedpoint_query (z3_fixedpoint.h, auto)

query_from_lvl

def query_from_lvl(self, query: Ast, lvl: UInt32) raises -> Lbool

Pose a query against the asserted rules at the given level.

query ::= (exists (bound-vars) query)
      |  literals

query returns

  • Z3_L_FALSE if the query is unsatisfiable.
  • Z3_L_TRUE if the query is satisfiable. Obtain the answer by calling Z3_fixedpoint_get_answer.
  • Z3_L_UNDEF if the query was interrupted, timed out or otherwise failed.

C API: Z3_fixedpoint_query_from_lvl (z3_spacer.h, auto)

query_relations

def query_relations(self, relations: List[FuncDecl]) raises -> Lbool

Pose multiple queries against the asserted rules.

The queries are encoded as relations (function declarations).

query returns

  • Z3_L_FALSE if the query is unsatisfiable.
  • Z3_L_TRUE if the query is satisfiable. Obtain the answer by calling Z3_fixedpoint_get_answer.
  • Z3_L_UNDEF if the query was interrupted, timed out or otherwise failed.

C API: Z3_fixedpoint_query_relations (z3_fixedpoint.h, auto)

register_relation

def register_relation(self, f: FuncDecl) raises

Register relation as Fixedpoint defined. Fixedpoint defined relations have least-fixedpoint semantics. For example, the relation is empty if it does not occur in a head or a fact.

C API: Z3_fixedpoint_register_relation (z3_fixedpoint.h, auto)

set_params

def set_params(self, p: Params) raises

Set parameters on fixedpoint context.

set_predicate_representation

def set_predicate_representation(self, f: FuncDecl, relation_kinds: List[Symbol]) raises

Configure the predicate representation.

It sets the predicate to use a set of domains given by the list of symbols. The domains given by the list of symbols must belong to a set of built-in domains.

C API: Z3_fixedpoint_set_predicate_representation (z3_fixedpoint.h, auto)

to_string

def to_string(self, queries: List[Ast]) raises -> String

Print the current rules and background axioms as a string.

Parameters:

  • c — - context.
  • f — - fixedpoint context.
  • num_queries — - number of additional queries to print.
  • queries — - additional queries.

See also: Fixedpoint.from_file, Fixedpoint.from_string

C API: Z3_fixedpoint_to_string (z3_fixedpoint.h, auto)

update_rule

def update_rule(self, a: Ast, name: Symbol) raises

Update a named rule. A rule with the same name must have been previously created.

C API: Z3_fixedpoint_update_rule (z3_fixedpoint.h, auto)

Tactic

var tac = Tactic.create(ctx, "simplify").and_then(Tactic.create(ctx, "qfnra-nlsat"))
var s = tac.to_solver()

Pythonic & ergonomic methods: ctx, help, param_descrs, solver (see Pythonic API Reference).

Exposes 12 Z3 C API bindings.

and_then

def and_then(self, other: Tactic) raises -> Tactic

Return a tactic that applies t1 to a given goal and t2 to every subgoal produced by t1.

C API: Z3_tactic_and_then (z3_api.h, manual)

apply

def apply(self, goal: Goal) raises -> ApplyResult

Apply tactic t to the goal g.

See also: Tactic.apply_ex

C API: Z3_tactic_apply (z3_api.h, manual)

apply_ex

def apply_ex(self, g: Goal, p: Params) raises -> ApplyResult

Apply tactic t to the goal g using the parameter set p.

See also: Tactic.apply

C API: Z3_tactic_apply_ex (z3_api.h, auto)

create

def create(ctx: Context, name: String) raises -> Tactic

Return a tactic associated with the given name. The complete list of tactics may be obtained using the procedures Z3_get_num_tactics and Z3_get_tactic_name. It may also be obtained using the command (help-tactic) in the SMT 2.0 front-end.

Tactics are the basic building block for creating custom solvers for specific problem domains.

C API: Z3_mk_tactic (z3_api.h, manual)

get_help

def get_help(self) raises -> String

Return a string containing a description of parameters accepted by the given tactic.

C API: Z3_tactic_get_help (z3_api.h, auto)

get_param_descrs

def get_param_descrs(self) raises -> ParamDescrs

Return the parameter description set for the given tactic object.

C API: Z3_tactic_get_param_descrs (z3_api.h, auto)

or_else

def or_else(self, other: Tactic) raises -> Tactic

Return a tactic that first applies t1 to a given goal, if it fails then returns the result of t2 applied to the given goal.

C API: Z3_tactic_or_else (z3_api.h, manual)

par_and_then

def par_and_then(self, t2: Tactic) raises -> Tactic

Return a tactic that applies t1 to a given goal and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.

C API: Z3_tactic_par_and_then (z3_api.h, auto)

repeat

def repeat(self, max: UInt32) raises -> Tactic

Return a tactic that keeps applying t until the goal is not modified anymore or the maximum number of iterations max is reached.

C API: Z3_tactic_repeat (z3_api.h, auto)

to_solver

def to_solver(self) raises -> Solver

Create a new solver that is implemented using the given tactic. The solver supports the commands Z3_solver_push and Z3_solver_pop, but it will always solve each Z3_solver_check from scratch.

Note: User must use Z3_solver_inc_ref and Z3_solver_dec_ref to manage solver objects. Even if the context was created using Z3_mk_context instead of Z3_mk_context_rc.

See also: Solver.__init__, Context.mk_simple_solver, Solver.for_logic

C API: Z3_mk_solver_from_tactic (z3_api.h, manual)

try_for

def try_for(self, ms: Int) raises -> Tactic

Return a tactic that applies t to a given goal for ms milliseconds. If t does not terminate in ms milliseconds, then it fails.

C API: Z3_tactic_try_for (z3_api.h, manual)

with_params

def with_params(self, params: Params) raises -> Tactic

Return a tactic that applies t using the given set of parameters.

C API: Z3_tactic_using_params (z3_api.h, manual)

Goal

var g = Goal(ctx)
g.assert_formula(ctx.mk_lt(ctx.mk_mul(x, x), ctx.mk_int(0)))
var res = Tactic.create(ctx, "simplify").apply(g)

Pythonic & ergonomic methods: add, append, as_expr, assert_exprs, dimacs, get, insert, prec, sexpr, simplify (see Pythonic API Reference).

Exposes 15 Z3 C API bindings.

assert_formula

def assert_formula(self, formula: Ast) raises

Add a new formula a to the given goal. The formula is split according to the following procedure that is applied until a fixed-point: Conjunctions are split into separate formulas. Negations are distributed over disjunctions, resulting in separate formulas. If the goal is false, adding new formulas is a no-op. If the formula a is true, then nothing is added. If the formula a is false, then the entire goal is replaced by the formula false.

C API: Z3_goal_assert (z3_api.h, manual)

convert_model

def convert_model(self, m: Model) raises -> Model

Convert a model of the formulas of a goal to a model of an original goal. The model may be null, in which case the returned model is valid if the goal was established satisfiable.

When using this feature it is advisable to set the parameter model.compact to false. It is by default true, which erases variables created by the solver from models. Without access to model values for intermediary variables, values of other variables may end up having the wrong values.

C API: Z3_goal_convert_model (z3_api.h, auto)

create

def create(ctx: Context, models: Bool = True, unsat_cores: Bool = False, proofs: Bool = False) raises -> Goal

Create a goal (aka problem). A goal is essentially a set of formulas, that can be solved and/or transformed using tactics and solvers.

If models is true, then model generation is enabled for the new goal.

If unsat_cores is true, then unsat core generation is enabled for the new goal.

If proofs is true, then proof generation is enabled for the new goal. Remark, the Z3 context c must have been created with proof generation support.

Note: Reference counting must be used to manage goals, even when the Z3_context was created using Z3_mk_context instead of Z3_mk_context_rc.

C API: Z3_mk_goal (z3_api.h, manual)

depth

def depth(self) raises -> UInt32

Return the depth of the given goal. It tracks how many transformations were applied to it.

C API: Z3_goal_depth (z3_api.h, auto)

formula

def formula(self, index: Int) raises -> Ast

Return a formula from the given goal.

Precondition: idx < Z3_goal_size(c, g)

C API: Z3_goal_formula (z3_api.h, manual)

inconsistent

def inconsistent(self) raises -> Bool

Return true if the given goal contains the formula false.

C API: Z3_goal_inconsistent (z3_api.h, auto)

is_decided_sat

def is_decided_sat(self) raises -> Bool

Return true if the goal is empty, and it is precise or the product of a under approximation.

C API: Z3_goal_is_decided_sat (z3_api.h, auto)

is_decided_unsat

def is_decided_unsat(self) raises -> Bool

Return true if the goal contains false, and it is precise or the product of an over approximation.

C API: Z3_goal_is_decided_unsat (z3_api.h, auto)

num_exprs

def num_exprs(self) raises -> UInt32

Return the number of formulas, subformulas and terms in the given goal.

C API: Z3_goal_num_exprs (z3_api.h, auto)

precision

def precision(self) raises -> GoalPrec

Return the "precision" of the given goal. Goals can be transformed using over and under approximations. A under approximation is applied when the objective is to find a model for a given goal. An over approximation is applied when the objective is to find a proof for a given goal.

C API: Z3_goal_precision (z3_api.h, auto)

reset

def reset(self) raises

Erase all formulas from the given goal.

C API: Z3_goal_reset (z3_api.h, auto)

size

def size(self) raises -> Int

Return the number of formulas in the given goal.

C API: Z3_goal_size (z3_api.h, manual)

to_dimacs_string

def to_dimacs_string(self, include_names: Bool) raises -> String

Convert a goal into a DIMACS formatted string. The goal must be in CNF. You can convert a goal to CNF by applying the tseitin-cnf tactic. Bit-vectors are not automatically converted to Booleans either, so if the caller intends to preserve satisfiability, it should apply bit-blasting tactics. Quantifiers and theory atoms will not be encoded.

C API: Z3_goal_to_dimacs_string (z3_api.h, auto)

to_string

def to_string(self) raises -> String

Convert a goal into a string.

C API: Z3_goal_to_string (z3_api.h, manual)

translate

def translate(self, target: Context) raises -> Goal

Copy a goal g from the context source to the context target.

C API: Z3_goal_translate (z3_api.h, auto)

ApplyResult

Exposes 3 Z3 C API bindings.

num_subgoals

def num_subgoals(self) raises -> Int

Return the number of subgoals in the Z3_apply_result object returned by Z3_tactic_apply.

See also: ApplyResult.subgoal

C API: Z3_apply_result_get_num_subgoals (z3_api.h, manual)

subgoal

def subgoal(self, index: Int) raises -> Goal

Return one of the subgoals in the Z3_apply_result object returned by Z3_tactic_apply.

Precondition: i < Z3_apply_result_get_num_subgoals(c, r)

See also: ApplyResult.num_subgoals

C API: Z3_apply_result_get_subgoal (z3_api.h, manual)

to_string

def to_string(self) raises -> String

Convert the Z3_apply_result object returned by Z3_tactic_apply into a string.

C API: Z3_apply_result_to_string (z3_api.h, auto)

Probe

Pythonic & ergonomic methods: const, create, ctx (see Pythonic API Reference).

Exposes 9 Z3 C API bindings.

and_

def and_(self, p2: Probe) raises -> Probe

Return a probe that evaluates to "true" when p1 and p2 evaluates to true.

Note: For probes, "true" is any value different from 0.0.

C API: Z3_probe_and (z3_api.h, auto)

apply

def apply(self, g: Goal) raises -> Float64

Execute the probe over the goal. The probe always produce a double value. "Boolean" probes return 0.0 for false, and a value different from 0.0 for true.

C API: Z3_probe_apply (z3_api.h, auto)

eq

def eq(self, val: Float64) raises -> Probe
def eq(self, val: Int) raises -> Probe
def eq(self, p2: Probe) raises -> Probe

Return a probe that evaluates to "true" when the value returned by p1 is equal to the value returned by p2.

Note: For probes, "true" is any value different from 0.0.

C API: Z3_probe_eq (z3_api.h, auto)

ge

def ge(self, p2: Probe) raises -> Probe

Return a probe that evaluates to "true" when the value returned by p1 is greater than or equal to the value returned by p2.

Note: For probes, "true" is any value different from 0.0.

C API: Z3_probe_ge (z3_api.h, auto)

gt

def gt(self, p2: Probe) raises -> Probe

Return a probe that evaluates to "true" when the value returned by p1 is greater than the value returned by p2.

Note: For probes, "true" is any value different from 0.0.

C API: Z3_probe_gt (z3_api.h, auto)

le

def le(self, p2: Probe) raises -> Probe

Return a probe that evaluates to "true" when the value returned by p1 is less than or equal to the value returned by p2.

Note: For probes, "true" is any value different from 0.0.

C API: Z3_probe_le (z3_api.h, auto)

lt

def lt(self, p2: Probe) raises -> Probe

Return a probe that evaluates to "true" when the value returned by p1 is less than the value returned by p2.

Note: For probes, "true" is any value different from 0.0.

C API: Z3_probe_lt (z3_api.h, auto)

not_

def not_(self) raises -> Probe

Return a probe that evaluates to "true" when p does not evaluate to true.

Note: For probes, "true" is any value different from 0.0.

C API: Z3_probe_not (z3_api.h, auto)

or_

def or_(self, p2: Probe) raises -> Probe

Return a probe that evaluates to "true" when p1 or p2 evaluates to true.

Note: For probes, "true" is any value different from 0.0.

C API: Z3_probe_or (z3_api.h, auto)

Simplifier

Exposes 4 Z3 C API bindings.

and_then

def and_then(self, t2: Simplifier) raises -> Simplifier

Return a simplifier that applies t1 to a given goal and t2 to every subgoal produced by t1.

C API: Z3_simplifier_and_then (z3_api.h, auto)

get_help

def get_help(self) raises -> String

Return a string containing a description of parameters accepted by the given simplifier.

C API: Z3_simplifier_get_help (z3_api.h, auto)

get_param_descrs

def get_param_descrs(self) raises -> ParamDescrs

Return the parameter description set for the given simplifier object.

C API: Z3_simplifier_get_param_descrs (z3_api.h, auto)

using_params

def using_params(self, p: Params) raises -> Simplifier

Return a simplifier that applies t using the given set of parameters.

C API: Z3_simplifier_using_params (z3_api.h, auto)

Params

Exposes 7 Z3 C API bindings.

create

def create(ctx: Context) raises -> Params

Create a Z3 (empty) parameter set. Starting at Z3 4.0, parameter sets are used to configure many components such as: simplifiers, tactics, solvers, etc.

Note: Reference counting must be used to manage parameter sets, even when the Z3_context was created using Z3_mk_context instead of Z3_mk_context_rc.

C API: Z3_mk_params (z3_api.h, manual)

set_bool

def set_bool(self, key: String, val: Bool) raises

Add a Boolean parameter k with value v to the parameter set p.

C API: Z3_params_set_bool (z3_api.h, manual)

set_double

def set_double(self, key: String, val: Float64) raises

Add a double parameter k with value v to the parameter set p.

C API: Z3_params_set_double (z3_api.h, manual)

set_symbol

def set_symbol(self, key: String, val: String) raises

Add a symbol parameter k with value v to the parameter set p.

C API: Z3_params_set_symbol (z3_api.h, manual)

set_uint

def set_uint(self, key: String, val: Int) raises

Add a unsigned parameter k with value v to the parameter set p.

C API: Z3_params_set_uint (z3_api.h, manual)

to_string

def to_string(self) raises -> String

Convert a parameter set into a string. This function is mainly used for printing the contents of a parameter set.

C API: Z3_params_to_string (z3_api.h, manual)

validate

def validate(self, d: ParamDescrs) raises

Validate the parameter set p against the parameter description set d.

The procedure invokes the error handler if p is invalid.

C API: Z3_params_validate (z3_api.h, auto)

ParamDescrs

Exposes 5 Z3 C API bindings.

get_documentation

def get_documentation(self, s: Symbol) raises -> String

Retrieve documentation string corresponding to parameter name s.

C API: Z3_param_descrs_get_documentation (z3_api.h, auto)

get_kind

def get_kind(self, n: Symbol) raises -> ParamKind

Return the kind associated with the given parameter name n.

C API: Z3_param_descrs_get_kind (z3_api.h, auto)

get_name

def get_name(self, i: UInt32) raises -> Symbol

Return the name of the parameter at given index i.

Precondition: i < Z3_param_descrs_size(c, p)

C API: Z3_param_descrs_get_name (z3_api.h, auto)

size

def size(self) raises -> UInt32

Return the number of parameters in the given parameter description set.

C API: Z3_param_descrs_size (z3_api.h, auto)

to_string

def to_string(self) raises -> String

Convert a parameter description set into a string. This function is mainly used for printing the contents of a parameter description set.

C API: Z3_param_descrs_to_string (z3_api.h, auto)

Stats

Pythonic & ergonomic methods: entries, get_double, get_uint (see Pythonic API Reference).

Exposes 7 Z3 C API bindings.

get_double_value

def get_double_value(self, idx: UInt32) raises -> Float64

Return the double value of the given statistical data.

Precondition: idx < Z3_stats_size(c, s) && Z3_stats_is_double(c, s)

C API: Z3_stats_get_double_value (z3_api.h, auto)

get_key

def get_key(self, idx: UInt32) raises -> String

Return the key (a string) for a particular statistical data.

Precondition: idx < Z3_stats_size(c, s)

C API: Z3_stats_get_key (z3_api.h, auto)

get_uint_value

def get_uint_value(self, idx: UInt32) raises -> UInt32

Return the unsigned value of the given statistical data.

Precondition: idx < Z3_stats_size(c, s) && Z3_stats_is_uint(c, s)

C API: Z3_stats_get_uint_value (z3_api.h, auto)

is_double

def is_double(self, idx: UInt32) raises -> Bool

Return true if the given statistical data is a double.

Precondition: idx < Z3_stats_size(c, s)

C API: Z3_stats_is_double (z3_api.h, auto)

is_uint

def is_uint(self, idx: UInt32) raises -> Bool

Return true if the given statistical data is a unsigned integer.

Precondition: idx < Z3_stats_size(c, s)

C API: Z3_stats_is_uint (z3_api.h, auto)

size

def size(self) raises -> UInt32

Return the number of statistical data in s.

C API: Z3_stats_size (z3_api.h, auto)

to_string

def to_string(self) raises -> String

Convert a statistics into a string.

C API: Z3_stats_to_string (z3_api.h, auto)

Ast

Pythonic & ergonomic methods: arg, as_bool, as_integer, as_rational, children, ctx, decl, decl_kind, eq, get_id, hash, hash_code, implies, is_algebraic_number, is_app, is_array, is_bool, is_bv, is_complex, is_const, is_false, is_finite_field, is_finite_set, is_fp, is_int, is_numeral, is_quantifier, is_real, is_string, is_true, kind, ne, num_args, sexpr, simplify, sort, sort_kind, substitute, to_string, translate, write_to (see Pythonic API Reference).

Value/handle wrapper managed by Context; see Context methods and Pythonic API.

Sort

Pythonic & ergonomic methods: ctx, get_id, kind, name, sexpr, to_string, write_to (see Pythonic API Reference).

Value/handle wrapper managed by Context; see Context methods and Pythonic API.

Symbol

Pythonic & ergonomic methods: kind, to_string, write_to (see Pythonic API Reference).

Value/handle wrapper managed by Context; see Context methods and Pythonic API.

FuncDecl

Pythonic & ergonomic methods: arity, ctx, domain, get_id, hash, kind, name, range, sexpr (see Pythonic API Reference).

Value/handle wrapper managed by Context; see Context methods and Pythonic API.

App

Value/handle wrapper managed by Context; see Context methods and Pythonic API.

Pattern

Value/handle wrapper managed by Context; see Context methods and Pythonic API.

AstVector

Pythonic & ergonomic methods: to_list (see Pythonic API Reference).

Exposes 7 Z3 C API bindings.

get

def get(self, i: UInt32) raises -> Ast

Return the AST at position i in the AST vector v.

Precondition: i < Z3_ast_vector_size(c, v)

C API: Z3_ast_vector_get (z3_ast_containers.h, auto)

push

def push(self, a: Ast) raises

Add the AST a in the end of the AST vector v. The size of v is increased by one.

C API: Z3_ast_vector_push (z3_ast_containers.h, auto)

resize

def resize(self, n: UInt32) raises

Resize the AST vector v.

C API: Z3_ast_vector_resize (z3_ast_containers.h, auto)

set

def set(self, i: UInt32, a: Ast) raises

Update position i of the AST vector v with the AST a.

Precondition: i < Z3_ast_vector_size(c, v)

C API: Z3_ast_vector_set (z3_ast_containers.h, auto)

size

def size(self) raises -> UInt32

Return the size of the given AST vector.

C API: Z3_ast_vector_size (z3_ast_containers.h, auto)

to_string

def to_string(self) raises -> String

Convert AST vector into a string.

C API: Z3_ast_vector_to_string (z3_ast_containers.h, auto)

translate

def translate(self, t: Context) raises -> AstVector

Translate the AST vector v from context s into an AST vector in context t.

C API: Z3_ast_vector_translate (z3_ast_containers.h, auto)

AstMap

Exposes 8 Z3 C API bindings.

contains

def contains(self, k: Ast) raises -> Bool

Return true if the map m contains the AST key k.

C API: Z3_ast_map_contains (z3_ast_containers.h, auto)

erase

def erase(self, k: Ast) raises

Erase a key from the map.

C API: Z3_ast_map_erase (z3_ast_containers.h, auto)

find

def find(self, k: Ast) raises -> Ast

Return the value associated with the key k.

The procedure invokes the error handler if k is not in the map.

C API: Z3_ast_map_find (z3_ast_containers.h, auto)

insert

def insert(self, k: Ast, v: Ast) raises

Store/Replace a new key, value pair in the given map.

C API: Z3_ast_map_insert (z3_ast_containers.h, auto)

keys

def keys(self) raises -> AstVector

Return the keys stored in the given map.

C API: Z3_ast_map_keys (z3_ast_containers.h, auto)

reset

def reset(self) raises

Remove all keys from the given map.

C API: Z3_ast_map_reset (z3_ast_containers.h, auto)

size

def size(self) raises -> UInt32

Return the size of the given map.

C API: Z3_ast_map_size (z3_ast_containers.h, auto)

to_string

def to_string(self) raises -> String

Convert the given map into a string.

C API: Z3_ast_map_to_string (z3_ast_containers.h, auto)

FuncInterp

Pythonic & ergonomic methods: else_value, entries (see Pythonic API Reference).

Exposes 6 Z3 C API bindings.

add_entry

def add_entry(self, args: AstVector, value: Ast) raises

add a function entry to a function interpretation.

It is assumed that entries added to a function cover disjoint arguments. If an two entries are added with the same arguments, only the second insertion survives and the first inserted entry is removed.

Parameters:

  • c — logical context
  • fi — a function interpretation to be updated.
  • args — list of arguments. They should be constant values (such as integers) and be of the same types as the domain of the function.
  • value — value of the function when the parameters match args.

C API: Z3_func_interp_add_entry (z3_api.h, auto)

get_arity

def get_arity(self) raises -> UInt32

Return the arity (number of arguments) of the given function interpretation.

C API: Z3_func_interp_get_arity (z3_api.h, auto)

get_else

def get_else(self) raises -> Ast

Return the 'else' value of the given function interpretation.

A function interpretation is represented as a finite map and an 'else' value. This procedure returns the 'else' value.

C API: Z3_func_interp_get_else (z3_api.h, auto)

get_entry

def get_entry(self, i: UInt32) raises -> FuncEntry

Return a "point" of the given function interpretation. It represents the value of f in a particular point.

Precondition: i < Z3_func_interp_get_num_entries(c, f)

See also: FuncInterp.get_num_entries

C API: Z3_func_interp_get_entry (z3_api.h, auto)

get_num_entries

def get_num_entries(self) raises -> UInt32

Return the number of entries in the given function interpretation.

A function interpretation is represented as a finite map and an 'else' value. Each entry in the finite map represents the value of a function given a set of arguments. This procedure return the number of element in the finite map of f.

See also: FuncInterp.get_entry

C API: Z3_func_interp_get_num_entries (z3_api.h, auto)

set_else

def set_else(self, else_value: Ast) raises

Return the 'else' value of the given function interpretation.

A function interpretation is represented as a finite map and an 'else' value. This procedure can be used to update the 'else' value.

C API: Z3_func_interp_set_else (z3_api.h, auto)

FuncEntry

Exposes 3 Z3 C API bindings.

get_arg

def get_arg(self, i: UInt32) raises -> Ast

Return an argument of a Z3_func_entry object.

Precondition: i < Z3_func_entry_get_num_args(c, e)

See also: FuncEntry.get_num_args, FuncInterp.get_entry

C API: Z3_func_entry_get_arg (z3_api.h, auto)

get_num_args

def get_num_args(self) raises -> UInt32

Return the number of arguments in a Z3_func_entry object.

get_value

def get_value(self) raises -> Ast

Return the value of this point.

A Z3_func_entry object represents an element in the finite map used to encode a function interpretation.

See also: FuncInterp.get_entry

C API: Z3_func_entry_get_value (z3_api.h, auto)

ParserContext

Exposes 3 Z3 C API bindings.

add_decl

def add_decl(self, f: FuncDecl) raises

Add a function declaration.

C API: Z3_parser_context_add_decl (z3_api.h, auto)

add_sort

def add_sort(self, s: Sort) raises

Add a sort declaration.

C API: Z3_parser_context_add_sort (z3_api.h, auto)

from_string

def from_string(self, s: String) raises -> AstVector

Parse a string of SMTLIB2 commands. Return assertions.

C API: Z3_parser_context_from_string (z3_api.h, auto)

Constructor

Exposes 1 Z3 C API bindings.

num_fields

def num_fields(self) raises -> UInt32

Retrieve the number of fields of a constructor

Parameters:

  • c — logical context.
  • constr — constructor.

C API: Z3_constructor_num_fields (z3_api.h, auto)

ConstructorList

Value/handle wrapper managed by Context; see Context methods and Pythonic API.

RcfNum

var coeffs: List[RcfNum] = [ctx.mk_rcf_int(-2), ctx.mk_rcf_int(0), ctx.mk_rcf_int(1)]
var roots = RcfNum.mk_roots(ctx, coeffs)
print("sqrt(2) ~=", roots[1].to_decimal(10))

Exposes 31 Z3 C API bindings.

add

def add(self, b: RcfNum) raises -> RcfNum

Return the value a + b.

C API: Z3_rcf_add (z3_rcf.h, auto)

coefficient

def coefficient(self, i: UInt32) raises -> RcfNum

Extract a coefficient from an algebraic number.

Precondition: Z3_rcf_is_algebraic(ctx, a);

C API: Z3_rcf_coefficient (z3_rcf.h, auto)

div

def div(self, b: RcfNum) raises -> RcfNum

Return the value a / b.

C API: Z3_rcf_div (z3_rcf.h, auto)

eq

def eq(self, b: RcfNum) raises -> Bool

Return true if a == b.

C API: Z3_rcf_eq (z3_rcf.h, auto)

extension_index

def extension_index(self) raises -> UInt32

Return the index of a field extension.

C API: Z3_rcf_extension_index (z3_rcf.h, auto)

ge

def ge(self, b: RcfNum) raises -> Bool

Return true if a >= b.

C API: Z3_rcf_ge (z3_rcf.h, auto)

gt

def gt(self, b: RcfNum) raises -> Bool

Return true if a > b.

C API: Z3_rcf_gt (z3_rcf.h, auto)

infinitesimal_name

def infinitesimal_name(self) raises -> Symbol

Return the name of an infinitesimal.

Precondition: Z3_rcf_is_infinitesimal(ctx, a);

C API: Z3_rcf_infinitesimal_name (z3_rcf.h, auto)

interval

def interval(self) raises -> Tuple[Int32, Bool, Bool, RcfNum, Bool, Bool, RcfNum]

Extract an interval from an algebraic number.

Precondition: Z3_rcf_is_algebraic(ctx, a);

C API: Z3_rcf_interval (z3_rcf.h, manual)

inv

def inv(self) raises -> RcfNum

Return the value 1/a.

C API: Z3_rcf_inv (z3_rcf.h, auto)

is_algebraic

def is_algebraic(self) raises -> Bool

Return true if a represents an algebraic number.

C API: Z3_rcf_is_algebraic (z3_rcf.h, auto)

is_infinitesimal

def is_infinitesimal(self) raises -> Bool

Return true if a represents an infinitesimal.

C API: Z3_rcf_is_infinitesimal (z3_rcf.h, auto)

is_rational

def is_rational(self) raises -> Bool

Return true if a represents a rational number.

C API: Z3_rcf_is_rational (z3_rcf.h, auto)

is_transcendental

def is_transcendental(self) raises -> Bool

Return true if a represents a transcendental number.

C API: Z3_rcf_is_transcendental (z3_rcf.h, auto)

le

def le(self, b: RcfNum) raises -> Bool

Return true if a <= b.

C API: Z3_rcf_le (z3_rcf.h, auto)

lt

def lt(self, b: RcfNum) raises -> Bool

Return true if a < b.

C API: Z3_rcf_lt (z3_rcf.h, auto)

mk_roots

def mk_roots(ctx: Context, coeffs: List[RcfNum]) raises -> List[RcfNum]

Store in roots the roots of the polynomial a[n-1]*x^{n-1} + ... + a[0]. The output vector roots must have size n. It returns the number of roots of the polynomial.

Precondition: The input polynomial is not the zero polynomial.

C API: Z3_rcf_mk_roots (z3_rcf.h, manual)

mul

def mul(self, b: RcfNum) raises -> RcfNum

Return the value a * b.

C API: Z3_rcf_mul (z3_rcf.h, auto)

neg

def neg(self) raises -> RcfNum

Return the value -a.

C API: Z3_rcf_neg (z3_rcf.h, auto)

neq

def neq(self, b: RcfNum) raises -> Bool

Return true if a != b.

C API: Z3_rcf_neq (z3_rcf.h, auto)

num_coefficients

def num_coefficients(self) raises -> UInt32

Return the number of coefficients in an algebraic number.

Precondition: Z3_rcf_is_algebraic(ctx, a);

C API: Z3_rcf_num_coefficients (z3_rcf.h, auto)

num_sign_condition_coefficients

def num_sign_condition_coefficients(self, i: UInt32) raises -> UInt32

Return the number of sign condition polynomial coefficients of an algebraic number.

Precondition: Z3_rcf_is_algebraic(ctx, a);

C API: Z3_rcf_num_sign_condition_coefficients (z3_rcf.h, auto)

num_sign_conditions

def num_sign_conditions(self) raises -> UInt32

Return the number of sign conditions of an algebraic number.

Precondition: Z3_rcf_is_algebraic(ctx, a);

C API: Z3_rcf_num_sign_conditions (z3_rcf.h, auto)

numerator_denominator

def numerator_denominator(self) raises -> Tuple[RcfNum, RcfNum]

Extract the "numerator" and "denominator" of the given RCF numeral. We have that a = n/d, moreover n and d are not represented using rational functions.

C API: Z3_rcf_get_numerator_denominator (z3_rcf.h, manual)

power

def power(self, k: UInt32) raises -> RcfNum

Return the value a^k.

C API: Z3_rcf_power (z3_rcf.h, auto)

sign_condition_coefficient

def sign_condition_coefficient(self, i: UInt32, j: UInt32) raises -> RcfNum

Extract the j-th polynomial coefficient of the i-th sign condition.

Precondition: Z3_rcf_is_algebraic(ctx, a);

C API: Z3_rcf_sign_condition_coefficient (z3_rcf.h, auto)

sign_condition_sign

def sign_condition_sign(self, i: UInt32) raises -> Int32

Extract the sign of a sign condition from an algebraic number.

Precondition: Z3_rcf_is_algebraic(ctx, a);

C API: Z3_rcf_sign_condition_sign (z3_rcf.h, auto)

sub

def sub(self, b: RcfNum) raises -> RcfNum

Return the value a - b.

C API: Z3_rcf_sub (z3_rcf.h, auto)

to_decimal

def to_decimal(self, prec: Int = 15) raises -> String

Convert the RCF numeral into a string in decimal notation.

C API: Z3_rcf_num_to_decimal_string (z3_rcf.h, manual)

to_string

def to_string(self, compact: Bool = True, html: Bool = False) raises -> String

Convert the RCF numeral into a string.

C API: Z3_rcf_num_to_string (z3_rcf.h, manual)

transcendental_name

def transcendental_name(self) raises -> Symbol

Return the name of a transcendental.

Precondition: Z3_rcf_is_transcendtal(ctx, a);

C API: Z3_rcf_transcendental_name (z3_rcf.h, auto)

SolverCallback

Pythonic & ergonomic methods: add, conflict, ctx, next_split, propagate (see Pythonic API Reference).

Exposes 2 Z3 C API bindings.

consequence

def consequence(self, fixed: List[Ast], eq_lhs: List[Ast], eq_rhs: List[Ast], conseq: Ast) raises -> Bool

propagate a consequence based on fixed values and equalities. A client may invoke it during the propagate_fixed, propagate_eq, propagate_diseq, and propagate_final callbacks. The callback adds a propagation consequence based on the fixed values passed in fixed and equalities between eq_lhs and eq_rhs.

The solver might discard the propagation in case it is true in the current state. The function returns false in this case; otw. the function returns true. At least one propagation in the final callback has to return true in order to prevent the solver from finishing.

Parameters:

  • c — - context
  • cb — - solver callback
  • num_fixed — - number of fixed terms used as premise to propagation
  • fixed — - array of length num_fixed containing terms that are fixed in the current scope
  • num_eqs — - number of equalities used as premise to propagation
  • eq_lhs — - left side of equalities
  • eq_rhs — - right side of equalities
  • conseq — - consequence to propagate. It is typically an atomic formula, but it can be an arbitrary formula.

C API: Z3_solver_propagate_consequence (z3_api.h, auto)

register_cb

def register_cb(self, e: Ast) raises

register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Vector can be registered for propagation. Unlike Z3_solver_propagate_register, this function takes a solver callback context as argument. It can be invoked during a callback to register new expressions.

C API: Z3_solver_propagate_register_cb (z3_api.h, auto)

z3_mojo v5.3.3.0 for Mojo 1.2 and Z3 5.3.3 · Apache License 2.0 with LLVM Exceptions · Source on GitHub