Z3Context

public class Z3Context

Main interaction point to Z3.

  • Gets or sets a reference to a rounding mode for floating-point operations performed on Z3FloatingPoint instances created by this context.

    Changes to this value change the rounding mode that is passed to the underlying Z3_mk_fpa_* methods that are generated via overloaded operators on Z3FloatingPoint instances.

    Defaults to NearestTiesToEven rounding mode, if not configured.

    Declaration

    Swift

    public var currentFpaRoundingMode: Z3RoundingMode { get set }
  • Return the error code for the last API call.

    Declaration

    Swift

    public var errorCode: Z3ErrorCode { get }
  • Return true if the last API call resulted in an error.

    Declaration

    Swift

    public var hasError: Bool { get }
  • Return the number of builtin probes available in Z3.

    Declaration

    Swift

    public var probeCount: UInt32 { get }
  • Return the number of builtin tactics available in Z3.

    Declaration

    Swift

    public var tacticCount: UInt32 { get }
  • Declaration

    Swift

    public init(configuration: Z3Config? = nil)
  • Return a string describing the given error code.

    Declaration

    Swift

    public func errorMessage(_ code: Z3ErrorCode) -> String
  • Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers, simplifiers and tactics.

    Declaration

    Swift

    public func interrupt()
  • 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.

    Declaration

    Swift

    public func makeParams() -> Z3Params
  • Create a new optimize context.

    Declaration

    Swift

    public func makeOptimize() -> Z3Optimize
  • Return a string describing all available parameters.

    Seealso

    simplifyEx

    Seealso

    getSimplifyParamDescrs

    Declaration

    Swift

    public func getSimplifyHelp() -> String
  • Return the parameter description set for the simplify procedure.

    Seealso

    simplifyEx

    Seealso

    getSimplifyHelp

    Declaration

    Swift

    public func getSimplifyParamDescrs() -> Z3ParamDescrs
  • 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).

    Seealso

    simplifyEx

    Declaration

    Swift

    public func simplify(_ a: AnyZ3Ast) -> AnyZ3Ast
  • 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.

    Seealso

    simplify

    Seealso

    getSimplifyHelp

    Seealso

    getSimplifyParamDescrs

    Declaration

    Swift

    public func simplifyEx(_ a: AnyZ3Ast, _ p: Z3Params) -> AnyZ3Ast
  • 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 Z3AstPrintMode.printSmtlibFull. To print shared common subexpressions only once, use the Z3AstPrintMode.printLowLevel mode. To print in way that conforms to SMT-LIB standards and uses let expressions to share common sub-expressions use Z3AstPrintMode.printSmtlib2Compliant.

    Declaration

    Swift

    public func setAstPrintMode(_ mode: Z3AstPrintMode)
  • Convert the given benchmark into SMT-LIB formatted string.

    Declaration

    Swift

    public func benchmarkToSmtlibString(
        name: String? = nil,
        logic: String,
        status: String,
        attributes: String,
        assumptions: [Z3AstBase],
        formula: Z3AstBase
    ) -> String

    Parameters

    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.

Accessors

  • Return Z3_INT_SYMBOL if the symbol was constructed using makeIntSymbol, and Z3_STRING_SYMBOL if the symbol was constructed using makeStringSymbol.

    Declaration

    Swift

    func getSymbolKind(_ symbol: Z3Symbol) -> Z3_symbol_kind
  • Return the symbol int value.

    Precondition

    getSymbolKind(s) == Z3_INT_SYMBOL

    Declaration

    Swift

    func getSymbolInt(_ symbol: Z3Symbol) -> Int32
  • Return the symbol name.

    Precondition

    getSymbolKind(s) == Z3_STRING_SYMBOL

    Seealso

    makeStringSymbol

    Declaration

    Swift

    func getSymbolString(_ symbol: Z3Symbol) -> String
  • Return the sort name as a symbol.

    Declaration

    Swift

    func getSortName(_ sort: Z3Sort) -> Z3Symbol
  • Return the sort kind (e.g., array, tuple, int, bool, etc).

    Seealso

    Z3_sort_kind

    Declaration

    Swift

    func getSortKind(_ sort: Z3Sort) -> Z3_sort_kind
  • Return the size of the given bit-vector sort.

    Precondition

    getSortKind(t) == Z3_BV_SORT

    Seealso

    makeBvSort

    Seealso

    getSortKind

    Declaration

    Swift

    func getBvSortSize(_ sort: Z3Sort) -> UInt32

Algebraic Numbers

Integers and Reals

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

    All arguments must have int or real sort.

    Remark

    The number of arguments must be greater than zero.

    Declaration

    Swift

    func makeAdd<T>(_ arguments: [Z3Ast<T>]) -> Z3Ast<T> where T : ArithmeticSort
  • Create an AST node representing args[0] * ... * args[num_args-1].

    All arguments must have int or real sort.

    Remark

    Z3 has limited support for non-linear arithmetic.

    Remark

    The number of arguments must be greater than zero.

    Declaration

    Swift

    func makeMul<T>(_ arguments: [Z3Ast<T>]) -> Z3Ast<T> where T : ArithmeticSort
  • Create an AST node representing args[0] + ... + args[num_args-1].

    All arguments must have int or real sort.

    Remark

    The number of arguments must be greater than zero.

    Declaration

    Swift

    func makeSub<T>(_ arguments: [Z3Ast<T>]) -> Z3Ast<T> where T : ArithmeticSort
  • Create an AST node representing - arg. The arguments must have int or real type.

    Declaration

    Swift

    func makeUnaryMinus<T>(_ ast: Z3Ast<T>) -> Z3Ast<T> where T : ArithmeticSort
  • Create an AST node representing arg1 div arg2.

    The arguments must either both have int type or both have real type. If the arguments have int type, then the result type is an int type, otherwise the the result type is real.

    Declaration

    Swift

    func makeDiv<T>(_ arg1: Z3Ast<T>, _ arg2: Z3Ast<T>) -> Z3Ast<T> where T : ArithmeticSort
  • Create an AST node representing arg1 mod arg2.

    The arguments must have int type.

    Declaration

    Swift

    func makeMod(_ arg1: Z3Int, _ arg2: Z3Int) -> Z3Int
  • Create an AST node representing arg1 rem arg2.

    The arguments must have int type.

    Declaration

    Swift

    func makeRem(_ arg1: Z3Int, _ arg2: Z3Int) -> Z3Int
  • Create an AST node representing arg1 ^ arg2.

    The arguments must have int or real type.

    Declaration

    Swift

    func makePower<T>(_ arg1: Z3Ast<T>, _ arg2: Z3Ast<T>) -> Z3Ast<T> where T : ArithmeticSort
  • Create less than. The nodes t1 and t2 must have the same sort, and must be int or real.

    Declaration

    Swift

    func makeLessThan<T>(_ t1: Z3Ast<T>, _ t2: Z3Ast<T>) -> Z3Bool where T : ArithmeticSort
  • Create less than or equal to. The nodes t1 and t2 must have the same sort, and must be int or real.

    Declaration

    Swift

    func makeLessThanOrEqualTo<T>(_ t1: Z3Ast<T>, _ t2: Z3Ast<T>) -> Z3Bool where T : ArithmeticSort
  • Create greater than. The nodes t1 and t2 must have the same sort, and must be int or real.

    Declaration

    Swift

    func makeGreaterThan<T>(_ t1: Z3Ast<T>, _ t2: Z3Ast<T>) -> Z3Bool where T : ArithmeticSort
  • Create greater than or equal to. The nodes t1 and t2 must have the same sort, and must be int or real.

    Declaration

    Swift

    func makeGreaterThanOrEqualTo<T>(_ t1: Z3Ast<T>, _ t2: Z3Ast<T>) -> Z3Bool where T : ArithmeticSort
  • 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.

    Declaration

    Swift

    func makeDivides(_ t1: Z3Int, _ t2: Z3Int) -> Z3Bool
  • 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.

    Seealso

    makeReal2Int

    Seealso

    makeIsInt

    Declaration

    Swift

    func makeIntToReal(_ t1: Z3Int) -> Z3Real
  • Coerce a real to an integer.

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

    Seealso

    makeInt2Real

    Seealso

    makeIsInt

    Declaration

    Swift

    func makeRealToInt(_ t1: Z3Real) -> Z3Int
  • Coerce an integer to a float.

    Declaration

    Swift

    func makeIntToFloat<T>(_ t1: Z3Int, sort: T.Type) -> Z3Ast<T> where T : FloatingSort
  • Coerce an integer to a float.

    sort must be a float sort

    Declaration

    Swift

    func makeIntToFloat(_ t1: Z3Int, sort: Z3Sort) -> AnyZ3Ast
  • Check if a real number is an integer.

    Seealso

    makeInt2Real

    Seealso

    makeReal2Int

    Declaration

    Swift

    func makeIsInt(_ t1: Z3Real) -> Z3Bool

Arrays

  • 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.

    • makeArraySort
    • makeStore

    Declaration

    Swift

    func makeSelect<D, R>(_ a: Z3Array<D, R>, _ i: Z3Ast<D>) -> Z3Ast<R> where D : SortKind, R : SortKind
  • Array read.

    Type-erased version.

    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.

    • makeArraySort
    • makeStore

    Declaration

    Swift

    func makeSelectAny(_ a: AnyZ3Ast, _ i: AnyZ3Ast) -> AnyZ3Ast
  • n-ary Array read.

    The argument a is the array and idxs are the indices of the array that gets read.

    Declaration

    Swift

    func makeSelectN<D, R>(_ a: Z3Array<D, R>, _ idxs: [Z3Ast<D>]) -> AnyZ3Ast where D : SortKind, R : SortKind
  • n-ary Array read.

    Type-erased version.

    The argument a is the array and idxs are the indices of the array that gets read.

    Declaration

    Swift

    func makeSelectNAny(_ a: AnyZ3Ast, _ idxs: [AnyZ3Ast]) -> AnyZ3Ast
  • 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).

    Declaration

    Swift

    func makeStore<D, R>(_ a: Z3Array<D, R>, _ i: Z3Ast<D>, _ v: Z3Ast<R>) -> Z3Array<D, R> where D : SortKind, R : SortKind
  • Array update.

    Type-erased version.

    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).

    Declaration

    Swift

    func makeStoreAny(_ a: AnyZ3Ast, _ i: AnyZ3Ast, _ v: AnyZ3Ast) -> AnyZ3Ast
  • n-ary Array update.

    Declaration

    Swift

    func makeStoreN<D, R>(_ a: Z3Array<D, R>, _ idxs: [Z3Ast<D>], _ v: Z3Ast<R>) -> Z3Array<D, R> where D : SortKind, R : SortKind
  • n-ary Array update.

    Type-erased version

    Declaration

    Swift

    func makeStoreNAny(_ a: AnyZ3Ast, _ idxs: [AnyZ3Ast], _ v: AnyZ3Ast) -> AnyZ3Ast
  • Create the constant array.

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

    Declaration

    Swift

    func makeConstArray<D, R>(_ value: Z3Ast<R>) -> Z3Array<D, R> where D : SortKind, R : SortKind
  • Create the constant array.

    Type-erased version

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

    Declaration

    Swift

    func makeConstArrayAny(_ domain: Z3Sort, _ value: AnyZ3Ast) -> AnyZ3Ast
  • 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].

    Seealso

    makeArraySort

    Seealso

    makeStore

    Seealso

    makeSelect

    Declaration

    Swift

    func makeMap(_ f: Z3FuncDecl, args: [AnyZ3Ast]) -> AnyZ3Ast
  • Access the array default value. Produces the default range value, for arrays that can be represented as finite maps with a default range value.

    Declaration

    Swift

    func makeArrayDefault<D, R>(_ array: Z3Array<D, R>) -> Z3Ast<R> where D : SortKind, R : SortKind

    Parameters

    array

    array value whose default range value is accessed.

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

    Type-erased version.

    Declaration

    Swift

    func makeArrayDefaultAny(_ array: AnyZ3Ast) -> AnyZ3Ast

    Parameters

    array

    array value whose default range value is accessed.

  • 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.

    Declaration

    Swift

    func makeAsArray(_ f: Z3FuncDecl) -> AnyZ3Ast
  • Create predicate that holds if Boolean array set has k elements set to true.

    Declaration

    Swift

    func makeSetHasSize<T>(_ set: Z3Set<T>, _ k: AnyZ3Ast) -> Z3Bool where T : SortKind

Bit-vectors

Constants and Applications

  • Declare a constant or function.

    After declaring a constant or function, the function makeApp() can be used to create a constant or function application.

    Seealso

    makeApply

    Seealso

    makeFreshFuncDecl

    Seealso

    makeRecFuncDecl

    Declaration

    Swift

    func makeFuncDecl(name: Z3Symbol, domain: [Z3Sort], range: Z3Sort) -> Z3FuncDecl

    Parameters

    name

    name of the constant or function.

    domain

    array containing the sort of each argument. Must be empty when declaring a constant.

    range

    sort of the constant or the return sort of the function.

  • Create a constant or function application.

    Seealso

    makeFreshFuncDecl

    Seealso

    makeFuncDecl

    Seealso

    makeRecFuncDecl

    Declaration

    Swift

    func makeApply(_ decl: Z3FuncDecl, args: [AnyZ3Ast]) -> AnyZ3Ast
  • Declare and create a constant.

    This function is a shorthand for:

    let symbol = context.makeStringSymbol(name)
    let decl = context.makeFuncDecl(name: symbol, domain: [], range: sort)
    let n = context.makeApply(decl, args: [])
    

    Declaration

    Swift

    func makeConstant(name: String, sort: Z3Sort) -> AnyZ3Ast
  • Declare and create a constant.

    This function is a shorthand for:

    let decl = context.makeFuncDecl(name: name, domain: [], range: sort)
    let n = context.makeApply(decl, args: [])
    

    Declaration

    Swift

    func makeConstant(name: Z3Symbol, sort: Z3Sort) -> AnyZ3Ast
  • Declare and create a constant.

    This function is a shorthand for:

    let symbol = context.makeStringSymbol(name)
    let n = context.makeConstant(name: symbol, sort: sort.getSort(self)).unsafeCastTo<T>()
    

    Seealso

    makeApply

    Seealso

    makeFreshConst

    Seealso

    makeFuncDecl

    Declaration

    Swift

    func makeConstant<T>(name: String, sort: T.Type = T.self) -> Z3Ast<T> where T : SortKind
  • Declare and create a constant.

    This function is a shorthand for:

    let symbol = context.makeStringSymbol(name)
    let n = context.makeConstant(name: symbol, sort: sort.getSort(self)).unsafeCastTo<T>()
    

    Seealso

    makeApply

    Seealso

    makeFreshConst

    Seealso

    makeFuncDecl

    Declaration

    Swift

    func makeConstant<T>(name: Z3Symbol, sort: T.Type = T.self) -> Z3Ast<T> where T : SortKind
  • Declare a fresh constant or function.

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

    Remark

    If prefix is nil, then it is assumed to be the empty string.

    Seealso

    makeFuncDecl

    Declaration

    Swift

    func makeFreshFuncDecl(prefix: String?, domain: [Z3Sort], range: Z3Sort) -> Z3FuncDecl
  • Declare and create a fresh constant.

    This function is a shorthand for:

    let decl = context.makeFreshFuncDecl(prefix: prefix, domain: [], range: sort)
    let n = context.makeApply(decl, args: [])
    

    Remark

    If prefix is nil, then it is assumed to be the empty string.

    Seealso

    makeApply

    Seealso

    makeConstant

    Seealso

    makeFreshFuncDecl

    Seealso

    makeFuncDecl

    Declaration

    Swift

    func makeFreshConstant(prefix: String?, sort: Z3Sort) -> AnyZ3Ast
  • Declare a recursive function

    After declaring recursive function, it should be associated with a recursive definition addRecDef. The function makeApply() can be used to create a constant or function application.

    Seealso

    addRecDef

    Seealso

    makeApply

    Seealso

    makeFuncDecl

    Declaration

    Swift

    func makeRecFuncDecl(name: Z3Symbol, domain: [Z3Sort], range: Z3Sort) -> Z3FuncDecl

    Parameters

    name

    name of the function.

    domain

    array containing the sort of each argument. The array must not be empty.

    range

    sort of the constant or the return sort of the function.

  • 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.

    Seealso

    makeRecFuncDecl

    Declaration

    Swift

    func addRecDef(_ f: Z3FuncDecl, args: [AnyZ3Ast], body: AnyZ3Ast)

    Parameters

    f

    function declaration.

    args

    constants that are used as arguments to the recursive function in the definition.

    body

    body of the recursive function

Fixedpoint facilities

Floating-Point Arithmetic

Propositional Logic and Equality

  • Create an AST node representing true.

    Declaration

    Swift

    func makeTrue() -> Z3Bool
  • Create an AST node representing false.

    Declaration

    Swift

    func makeFalse() -> Z3Bool
  • Create an AST node representing l = r.

    The nodes l and r must have the same type.

    Declaration

    Swift

    func makeEqual<T>(_ l: Z3Ast<T>, _ r: Z3Ast<T>) -> Z3Bool where T : SortKind
  • Create an AST node representing l = r.

    Type-erased version.

    The nodes l and r must have the same type.

    Declaration

    Swift

    func makeEqualAny(_ l: AnyZ3Ast, _ r: AnyZ3Ast) -> Z3Bool
  • 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.

    Precondition

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

    Declaration

    Swift

    func makeDistinct<T>(_ args: [Z3Ast<T>]) -> Z3Bool where T : SortKind
  • 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.

    Type-erased version.

    Precondition

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

    Declaration

    Swift

    func makeDistinctAny(_ args: [Z3AstBase]) -> Z3Bool
  • Create an AST node representing not(a).

    The node a must have Boolean sort.

    Declaration

    Swift

    func makeNot(_ a: Z3Bool) -> Z3Bool
  • 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.

    Declaration

    Swift

    func makeIfThenElse<T>(_ t1: Z3Bool, _ t2: Z3Ast<T>, _ t3: Z3Ast<T>) -> Z3Ast<T> where T : SortKind
  • Create an AST node representing t1 iff t2.

    The nodes t1 and t2 must have Boolean sort.

    Declaration

    Swift

    func makeIff(_ t1: Z3Bool, _ t2: Z3Bool) -> Z3Bool
  • Create an AST node representing t1 implies t2.

    The nodes t1 and t2 must have Boolean sort.

    Declaration

    Swift

    func makeImplies(_ t1: Z3Bool, _ t2: Z3Bool) -> Z3Bool
  • Create an AST node representing t1 xor t2.

    The nodes t1 and t2 must have Boolean sort.

    Declaration

    Swift

    func makeXor(_ t1: Z3Bool, _ t2: Z3Bool) -> Z3Bool
  • Create an AST node representing args[0] and ... and args[num_args-1].

    All arguments must have Boolean sort.

    Precondition

    The number of arguments must be greater than zero.

    Declaration

    Swift

    func makeAnd(_ args: [Z3Bool]) -> Z3Bool
  • Create an AST node representing args[0] and ... and args[num_args-1].

    All arguments must have Boolean sort.

    Type-erased version of makeAny.

    Precondition

    The number of arguments must be greater than zero.

    Declaration

    Swift

    func makeAndAny(_ args: [AnyZ3Ast]) -> Z3Bool
  • Create an AST node representing args[0] or ... or args[num_args-1].

    All arguments must have Boolean sort.

    Precondition

    The number of arguments must be greater than zero.

    Declaration

    Swift

    func makeOr(_ args: [Z3Bool]) -> Z3Bool
  • Create an AST node representing args[0] or ... or args[num_args-1].

    All arguments must have Boolean sort.

    Type-erased version of makeOr.

    Precondition

    The number of arguments must be greater than zero.

    Declaration

    Swift

    func makeOrAny(_ args: [AnyZ3Ast]) -> Z3Bool

Numeral creation and extraction

  • Create a numeral of a given sort.

    Seealso

    makeInteger()

    Seealso

    makeUnsignedInteger()

    Declaration

    Swift

    func makeNumeral<T>(number: String, sort: T.Type) -> Z3Ast<T> where T : NumericalSort

    Parameters

    number

    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]* .

    sort

    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.

  • Create a numeral of a given sort.

    Seealso

    makeInteger()

    Seealso

    makeUnsignedInteger()

    Declaration

    Swift

    func makeNumeral(number: String, sort: Z3Sort) -> AnyZ3Ast

    Parameters

    number

    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]* .

    sort

    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.

  • Create a real from a fraction.

    Seealso

    makeNumeral

    Seealso

    makeInteger

    Seealso

    makeUnsignedInteger

    Precondition

    den != 0

    Declaration

    Swift

    func makeReal(_ num: Int32, _ den: Int32 = 1) -> Z3Real

    Parameters

    num

    numerator of rational.

    den

    denominator of rational.

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

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

    Declaration

    Swift

    func makeInteger(_ value: Int32) -> Z3Int
  • Create a numeral of a bit-vector.

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

    Declaration

    Swift

    func makeIntegerBv(_ value: Int32) -> Z3BitVector32
  • Create a numeral of a bit-vector of one bit.

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

    Declaration

    Swift

    func makeInteger1Bv(_ value: UInt32) -> Z3BitVector1
  • Create a numeral of an int, bit-vector, or finite-domain sort.

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

    Declaration

    Swift

    func makeUnsignedInteger(_ value: UInt32) -> Z3Int
  • Create a numeral of a bit-vector.

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

    Declaration

    Swift

    func makeUnsignedIntegerBv(_ value: UInt32) -> Z3BitVectorU32
  • Create a numeral of an int, bit-vector, or finite-domain sort.

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

    Declaration

    Swift

    func makeInteger64(_ value: Int64) -> Z3Int
  • Create a numeral of a bit-vector.

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

    Declaration

    Swift

    func makeInteger64Bv(_ value: Int64) -> Z3BitVector64
  • Create a numeral of an int, bit-vector, or finite-domain sort.

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

    Declaration

    Swift

    func makeUnsignedInteger64(_ value: UInt64) -> Z3Int
  • Create a numeral of an int, bit-vector, or finite-domain sort.

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

    Declaration

    Swift

    func makeUnsignedInteger64Any(_ value: UInt64, sort: Z3Sort) -> AnyZ3Ast
  • Create a numeral of a bit-vector.

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

    Declaration

    Swift

    func makeUnsignedInteger64Bv(_ value: UInt64) -> Z3BitVectorU64
  • Create a numeral of a bit-vector.

    This method can be used to create numerals that fit in a 128-bit integer. The initial value is split into two UInt64 bit patterns that fit the low (0-63) and high (64-127) bit ranges.

    Declaration

    Swift

    func makeInteger128Bv(highBits: UInt64, lowBits: UInt64) -> Z3BitVector128
  • Create a numeral of a bit-vector.

    This method can be used to create numerals that fit in a 128-bit integer.

    Declaration

    Swift

    func makeUnsignedInteger128Bv(highBits: UInt64, lowBits: UInt64) -> Z3BitVector128
  • Create a bit-vector numeral from a vector of Booleans.

    Precondition

    !values.isEmpty

    Declaration

    Swift

    func makeIntegerBvFromBools(_ values: [Bool]) -> AnyZ3BitVector
  • Return numeral value, as a decimal string of a numeric constant term

    Declaration

    Swift

    func getNumeralString(_ numeral: AnyZ3Ast) -> String
  • Similar to getNumeralString(_:), but only succeeds if the value can fit in a machine Int64 int. Returns nil if it fails.

    Declaration

    Swift

    func getNumeralInt64(_ numeral: AnyZ3Ast) -> Int64?
  • Similar to getNumeralString(_:), but only succeeds if the value can fit in a machine UInt64 int. Returns nil if it fails.

    Declaration

    Swift

    func getNumeralUInt64(_ numeral: AnyZ3Ast) -> UInt64?

Parser interface

  • 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.

    Declaration

    Swift

    func parseSmtlib2String(
        _ str: String,
        sorts: [(name: Z3Symbol, Z3Sort)],
        decls: [(name: Z3Symbol, Z3FuncDecl)]
    ) throws -> Z3AstVector
  • Parse the contents of a given file path 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 file.

    Similar to parseSmtlib2String(_:sorts:decls:), but reads the benchmark from a file.

    Declaration

    Swift

    func parseSmtlib2File(
        filePath: String,
        sorts: [(name: Z3Symbol, Z3Sort)],
        decls: [(name: Z3Symbol, Z3FuncDecl)]
    ) throws -> Z3AstVector
  • 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.

    Declaration

    Swift

    func evalSmtlib2String(_ str: String) -> String
  • Create a parser context.

    A parser context maintains state between calls to Z3ParserContext.parseString(_:) 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.

    Declaration

    Swift

    func createParserContext() -> Z3ParserContext

Polynomials

  • Return the nonzero subresultants of p and q with respect to the “variable” x.

    \pre 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

    Declaration

    Swift

    func polynomialSubresultants<PSort: ArithmeticSort, QSort: ArithmeticSort>(
        _ p: Z3Ast<PSort>,
        _ q: Z3Ast<QSort>,
        _ x: AnyZ3Ast
    ) -> Z3AstVector?

Qualifiers

  • 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.

    Seealso

    makeForAll

    Seealso

    makeExists

    Declaration

    Swift

    func makePattern(_ terms: [AnyZ3Ast]) -> Z3Pattern
  • Create a bound variable.

    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.

    Seealso

    makeForAll

    Seealso

    makeExists

    Declaration

    Swift

    func makeBound(_ index: UInt32, _ ty: Z3Sort) -> AnyZ3Ast

    Parameters

    index

    de-Bruijn index

    ty

    sort of the bound variable

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

    Seealso

    makePattern

    Seealso

    makeBound

    Seealso

    makeExists

    Declaration

    Swift

    func makeForall(weight: UInt32,
                    patterns: [Z3Pattern],
                    declarations: [(Z3Sort, Z3Symbol)],
                    body: AnyZ3Ast) -> AnyZ3Ast

    Parameters

    weight

    quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0.

    patterns

    array containing the patterns created using makePattern

    declarations

    an array of declarations containing the sorts and names of the bound variables.

    body

    the body of the quantifier.

  • Create an exists formula. Similar to makeForall.

    Seealso

    makePattern

    Seealso

    makeBound

    Seealso

    makeForall

    Seealso

    makeQuantifier

    Declaration

    Swift

    func makeExists(weight: UInt32,
                    patterns: [Z3Pattern],
                    declarations: [(Z3Sort, Z3Symbol)],
                    body: AnyZ3Ast) -> AnyZ3Ast

    Parameters

    weight

    quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0.

    patterns

    array containing the patterns created using makePattern

    declarations

    an array of declarations containing the sorts and names of the bound variables.

    body

    the body of the quantifier.

  • Create a quantifier - universal or existential, with pattern hints.

    Seealso

    makePattern

    Seealso

    makeBound

    Seealso

    makeForall

    Seealso

    makeExists

    Declaration

    Swift

    func makeQuantifier(isForall: Bool,
                        weight: UInt32,
                        patterns: [Z3Pattern],
                        declarations: [(Z3Sort, Z3Symbol)],
                        body: AnyZ3Ast) -> AnyZ3Ast

    Parameters

    isForall

    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.

    patterns

    array containing the patterns created using makePattern

    declarations

    an array of declarations containing the sorts and names of the bound variables.

    body

    the body of the quantifier.

Regular Expressions

  • Create the regular language re+.

    Declaration

    Swift

    func makeRePlus<Element>(_ re: Z3RegularExp<Element>) -> Z3RegularExp<Element> where Element : SortKind
  • Create the regular language re+.

    Type-erased version.

    Precondition

    re is of a regular expression sort.

    Declaration

    Swift

    func makeRePlusAny(_ re: AnyZ3Ast) -> AnyZ3Ast
  • Create the regular language re*.

    Declaration

    Swift

    func makeReStar<Element>(_ re: Z3RegularExp<Element>) -> Z3RegularExp<Element> where Element : SortKind
  • Create the regular language re*.

    Type-erased version.

    Precondition

    re is of a regular expression sort.

    Declaration

    Swift

    func makeReStarAny(_ re: AnyZ3Ast) -> AnyZ3Ast
  • Create the regular language [re].

    Declaration

    Swift

    func makeReOption<Element>(_ re: Z3RegularExp<Element>) -> Z3RegularExp<Element> where Element : SortKind
  • Create the regular language [re].

    Type-erased version.

    Precondition

    re is of a regular expression sort.

    Declaration

    Swift

    func makeReOptionAny(_ re: AnyZ3Ast) -> AnyZ3Ast
  • Create the union of the regular languages.

    Precondition

    asts.count > 0.

    Declaration

    Swift

    func makeReUnion<Element>(_ asts: [Z3RegularExp<Element>]) -> Z3RegularExp<Element> where Element : SortKind
  • Create the union of the regular languages.

    Type-erased version.

    Precondition

    asts.count > 0.

    Precondition

    asts are the same regular expression sort.

    Declaration

    Swift

    func makeReUnionAny(_ asts: [AnyZ3Ast]) -> AnyZ3Ast
  • Create the concatenation of the regular languages.

    Precondition

    asts.count > 0.

    Declaration

    Swift

    func makeReConcat<Element>(_ asts: [Z3RegularExp<Element>]) -> Z3RegularExp<Element> where Element : SortKind
  • Create the concatenation of the regular languages.

    Type-erased version.

    Precondition

    asts.count > 0.

    Precondition

    asts are the same regular expression sort.

    Declaration

    Swift

    func makeReConcatAny(_ asts: [AnyZ3Ast]) -> AnyZ3Ast
  • Create the range regular expression over two sequences of length 1.

    Declaration

    Swift

    func makeReRange<Element>(
        low: Z3Seq<Element>,
        high: Z3Seq<Element>
    ) -> Z3RegularExp<Element>
  • Create the range regular expression over two sequences of length 1.

    Type-erased version.

    Precondition

    low and high are the same sequence sort.

    Declaration

    Swift

    func makeReRangeAny(low: AnyZ3Ast, high: AnyZ3Ast) -> AnyZ3Ast
  • Create a regular expression that accepts all singleton sequences of the regular expression sort.

    Declaration

    Swift

    func makeReAllChar<Element>(
        _ sort: ReSort<Element>.Type = ReSort<Element>.self
    ) -> Z3RegularExp<Element>
  • Create a regular expression that accepts all singleton sequences of the regular expression sort.

    Type-erased version.

    Precondition

    sort is a regular expression sort.

    Declaration

    Swift

    func makeReAllCharAny(_ sort: Z3Sort) -> AnyZ3Ast
  • Create a regular expression loop.

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

    Declaration

    Swift

    func makeReLoop<Element>(
        _ ast: Z3RegularExp<Element>,
        low: UInt32,
        high: UInt32
    ) -> Z3RegularExp<Element>
  • Create a regular expression loop.

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

    Type-erased version.

    Precondition

    ast is of a regular expression sort.

    Declaration

    Swift

    func makeReLoopAny(_ ast: AnyZ3Ast, low: UInt32, high: UInt32) -> AnyZ3Ast
  • Create a power regular expression.

    Declaration

    Swift

    func makeRePower<Element>(_ ast: Z3RegularExp<Element>, count: UInt32) -> Z3RegularExp<Element> where Element : SortKind
  • Create a power regular expression.

    Type-erased version.

    Precondition

    ast is of a regular expression sort.

    Declaration

    Swift

    func makeRePowerAny(_ ast: AnyZ3Ast, count: UInt32) -> AnyZ3Ast
  • Create the intersection of the regular languages.

    Precondition

    asts.count > 0.

    Declaration

    Swift

    func makeReIntersect<Element>(_ asts: [Z3RegularExp<Element>]) -> Z3RegularExp<Element> where Element : SortKind
  • Create the intersection of the regular languages.

    Type-erased version.

    Precondition

    asts.count > 0.

    Precondition

    asts are the same regular expression sort.

    Declaration

    Swift

    func makeReIntersectAny(_ asts: [AnyZ3Ast]) -> AnyZ3Ast
  • Create the complement of the regular language re.

    Declaration

    Swift

    func makeReComplement<Element>(_ re: Z3RegularExp<Element>) -> Z3RegularExp<Element> where Element : SortKind
  • Create the complement of the regular language re.

    Type-erased version.

    Precondition

    re is of a regular expression sort.

    Declaration

    Swift

    func makeReComplementAny(_ re: AnyZ3Ast) -> AnyZ3Ast
  • Create the difference of regular expressions.

    Declaration

    Swift

    func makeReDiff<Element>(_ re1: Z3RegularExp<Element>, _ re2: Z3RegularExp<Element>) -> Z3RegularExp<Element> where Element : SortKind
  • Create the difference of regular expressions.

    Type-erased version.

    Precondition

    re1 and re2 are the same regular expression sort.

    Declaration

    Swift

    func makeReDiffAny(_ re1: AnyZ3Ast, _ re2: AnyZ3Ast) -> AnyZ3Ast
  • Create an empty regular expression of sort sort.

    Declaration

    Swift

    func makeReEmpty<Element>(
        _ sort: ReSort<Element>.Type = ReSort<Element>.self
    ) -> Z3RegularExp<Element>
  • Create an empty regular expression of sort sort.

    Type-erased version.

    Precondition

    sort is of a regular expression sort.

    Declaration

    Swift

    func makeReEmptyAny(_ sort: Z3Sort) -> AnyZ3Ast
  • Create an universal regular expression of sort sort.

    Declaration

    Swift

    func makeReFull<Element>(
        _ sort: ReSort<Element>.Type = ReSort<Element>.self
    ) -> Z3RegularExp<Element>
  • Create an universal regular expression of sort sort.

    Type-erased version.

    Precondition

    sort is of a regular expression sort.

    Declaration

    Swift

    func makeReFullAny(_ sort: Z3Sort) -> AnyZ3Ast
  • Creates a character literal.

    Declaration

    Swift

    func makeChar(_ character: UInt32) -> Z3Char
  • Create less than or equal to between two characters.

    Declaration

    Swift

    func makeCharLe(_ ch1: Z3Char, _ ch2: Z3Char) -> Z3Bool
  • Create an integer (code point) from character.

    Declaration

    Swift

    func makeCharToInt(_ char: Z3Char) -> Z3Int
  • Create a bit-vector (code point) from character.

    Declaration

    Swift

    func makeCharToBv(_ char: Z3Char) -> AnyZ3BitVector
  • Create a character from a bit-vector (code point).

    Declaration

    Swift

    func makeCharFromBv<Sort>(_ bv: Z3BitVector<Sort>) -> Z3Char where Sort : BitVectorSort
  • Create a check if the character is a digit.

    Declaration

    Swift

    func makeCharIsDigit(_ char: Z3Char) -> Z3Bool

Sequences

  • Create an empty sequence of the sequence of sort sort.

    Declaration

    Swift

    func makeSeqEmpty<Element>(_ sort: SeqSort<Element>.Type = SeqSort<Element>.self) -> Z3Seq<Element> where Element : SortKind
  • Create an empty sequence of the sequence of sort sort.

    Type-erased version.

    Precondition

    sort is a sequence sort.

    Declaration

    Swift

    func makeSeqEmptyAny(_ sort: Z3Sort) -> AnyZ3Ast
  • Create a unit sequence of ast.

    Declaration

    Swift

    func makeSeqUnit<Element>(_ ast: Z3Ast<Element>) -> Z3Seq<Element> where Element : SortKind
  • Create a unit sequence of ast.

    Type-erased version.

    Declaration

    Swift

    func makeSeqUnitAny(_ ast: AnyZ3Ast) -> AnyZ3Ast
  • Concatenate sequences.

    Precondition

    The number of arguments must be greater than zero.

    Declaration

    Swift

    func makeSeqConcat<Element>(_ args: [Z3Seq<Element>]) -> Z3Seq<Element> where Element : SortKind
  • Concatenate sequences.

    Type-erased version.

    Precondition

    The number of arguments must be greater than zero.

    Precondition

    All arguments are the same sequence sort.

    Declaration

    Swift

    func makeSeqConcatAny(_ args: [AnyZ3Ast]) -> AnyZ3Ast
  • Check if prefix is a prefix of sequence.

    Declaration

    Swift

    func makeSeqPrefix<Element>(_ sequence: Z3Seq<Element>, prefix: Z3Seq<Element>) -> Z3Bool where Element : SortKind
  • Check if prefix is a prefix of sequence.

    Type-erased version.

    Precondition

    prefix and sequence are the same sequence sorts.

    Declaration

    Swift

    func makeSeqPrefixAny(_ sequence: AnyZ3Ast, prefix: AnyZ3Ast) -> Z3Bool
  • Check if suffix is a suffix of sequence.

    Declaration

    Swift

    func makeSeqSuffix<Element>(_ sequence: Z3Seq<Element>, suffix: Z3Seq<Element>) -> Z3Bool where Element : SortKind
  • Check if suffix is a suffix of sequence.

    Type-erased version.

    Precondition

    suffix and sequence are the same sequence sorts.

    Declaration

    Swift

    func makeSeqSuffixAny(_ sequence: AnyZ3Ast, suffix: AnyZ3Ast) -> Z3Bool
  • Check if subsequence is a subsequence of sequence.

    Declaration

    Swift

    func makeSeqContains<Element>(_ sequence: Z3Seq<Element>, subsequence: Z3Seq<Element>) -> Z3Bool where Element : SortKind
  • Check if subsequence is a subsequence of sequence.

    Type-erased version.

    Precondition

    subsequence and sequence are the same sequence sorts.

    Declaration

    Swift

    func makeSeqContainsAny(_ sequence: AnyZ3Ast, subsequence: AnyZ3Ast) -> Z3Bool
  • Extract subsequence starting at offset of length.

    Declaration

    Swift

    func makeSeqExtract<Element>(_ sequence: Z3Seq<Element>, offset: Z3Int, length: Z3Int) -> Z3Seq<Element> where Element : SortKind
  • Extract subsequence starting at offset of length.

    Type-erased version.

    Precondition

    sequence is a sequence sort, offset and length are int sort.

    Declaration

    Swift

    func makeSeqExtractAny(_ sequence: AnyZ3Ast, offset: AnyZ3Ast, length: AnyZ3Ast) -> AnyZ3Ast
  • Replace the first occurrence of src with dst in sequence.

    Declaration

    Swift

    func makeSeqReplace<Element>(_ sequence: Z3Seq<Element>, src: Z3Seq<Element>, dest: Z3Seq<Element>) -> Z3Seq<Element> where Element : SortKind
  • Replace the first occurrence of src with dst in sequence.

    Type-erased version.

    Precondition

    sequence, src, and dest are the same sequence sort.

    Declaration

    Swift

    func makeSeqReplaceAny(_ sequence: AnyZ3Ast, src: AnyZ3Ast, dest: AnyZ3Ast) -> AnyZ3Ast
  • Retrieve from sequence the unit sequence positioned at position index.

    Declaration

    Swift

    func makeSeqAt<Element>(_ sequence: Z3Seq<Element>, index: Z3Int) -> Z3Seq<Element> where Element : SortKind
  • Retrieve from sequence the unit sequence positioned at position index.

    Type-erased version.

    Precondition

    sequence is a sequence sort, index is int sort.

    Declaration

    Swift

    func makeSeqAtAny(_ sequence: AnyZ3Ast, index: AnyZ3Ast) -> AnyZ3Ast
  • Retrieve from sequence the the element positioned at position index.

    Declaration

    Swift

    func makeSeqNth<Element>(_ sequence: Z3Seq<Element>, index: Z3Int) -> Z3Ast<Element> where Element : SortKind
  • Retrieve from sequence the the element positioned at position index.

    Type-erased version.

    Precondition

    sequence is a sequence sort, index is int sort.

    Declaration

    Swift

    func makeSeqNthAny(_ sequence: AnyZ3Ast, index: AnyZ3Ast) -> AnyZ3Ast
  • Returns the length of sequence.

    Declaration

    Swift

    func makeSeqLength<Element>(_ sequence: Z3Seq<Element>) -> Z3Int where Element : SortKind
  • Returns the length of sequence.

    Type-erased version.

    Precondition

    sequence, is a sequence sort.

    Declaration

    Swift

    func makeSeqLengthAny(_ sequence: AnyZ3Ast) -> Z3Int
  • Return index of the first occurrence of substr in sequence starting from offset.

    If sequence does not contain substr, then the value is -1, if offset is the length of sequence, then the value is -1 as well. The value is -1 if offset is negative or larger than the length of sequence.

    Declaration

    Swift

    func makeSeqIndex<Element>(_ sequence: Z3Seq<Element>, substr: Z3Seq<Element>, offset: Z3Int) -> Z3Int where Element : SortKind
  • Return index of the first occurrence of substr in sequence starting from offset.

    If sequence does not contain substr, then the value is -1, if offset is the length of sequence, then the value is -1 as well. The value is -1 if offset is negative or larger than the length of sequence.

    Type-erased version.

    Precondition

    sequence and substr are the same sequence sort, offset is int sort.

    Declaration

    Swift

    func makeSeqIndexAny(_ sequence: AnyZ3Ast, substr: AnyZ3Ast, offset: AnyZ3Ast) -> Z3Int
  • Return index of the last occurrence of substr in sequence.

    If sequence does not contain substr, then the value is -1.

    Declaration

    Swift

    func makeSeqLastIndex<Element>(_ sequence: Z3Seq<Element>, substr: Z3Seq<Element>) -> Z3Int where Element : SortKind
  • Return index of the last occurrence of substr in sequence.

    If sequence does not contain substr, then the value is -1.

    Type-erased version.

    Precondition

    sequence and substr are the same sequence sort.

    Declaration

    Swift

    func makeSeqLastIndexAny(_ sequence: AnyZ3Ast, substr: AnyZ3Ast) -> Z3Int
  • Create a regular expression that accepts the sequence sequence.

    Declaration

    Swift

    func makeSeqToRe<Element>(_ sequence: Z3Seq<Element>) -> Z3RegularExp<Element> where Element : SortKind
  • Create a regular expression that accepts the sequence sequence.

    Type-erased version.

    Precondition

    sequence is a sequence sort.

    Declaration

    Swift

    func makeSeqToReAny(_ sequence: AnyZ3Ast) -> AnyZ3Ast
  • Check for regular expression membership.

    Declaration

    Swift

    func makeSeqInRe<Element>(_ sequence: Z3Seq<Element>, regex: Z3RegularExp<Element>) -> Z3Bool where Element : SortKind
  • Check for regular expression membership.

    Type-erased version.

    Precondition

    sequence is a sequence sort, and regex is a regular expression sort with the same basis sort as sequence.

    Declaration

    Swift

    func makeSeqInReAny(_ sequence: AnyZ3Ast, regex: AnyZ3Ast) -> Z3Bool

Sets

Solvers

  • 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 Z3Solver.push() or Z3Solver.pop(_:), and no calls to Z3Solver.assert() or Z3Solver.assertAndTrack after checking satisfiability without an intervening 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 method Z3Solver.getModel() retrieves a model if the assertions is satisfiable (i.e., the result is Z3LBool.lUndef) and model construction is enabled.

    The method Z3Solver.getModel() can also be used even if the result is Z3LBool.lUndef, but the returned model is not guaranteed to satisfy quantified assertions.

    Declaration

    Swift

    func makeSolver() -> Z3Solver
  • Create a new incremental solver.

    This is equivalent to applying the “smt” tactic.

    Unlike Z3Context.makeSolver() 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 Z3Context.makeSolver().

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

    Seealso

    makeSolver()

    Declaration

    Swift

    func makeSimpleSolver() -> Z3Solver
  • Create a new solver customized for the given logic. It behaves like makeSolver() if the logic is unknown or unsupported.

    Seealso

    makeSolver()

    Declaration

    Swift

    func makeSolverForLogic(_ symbol: Z3Symbol) -> Z3Solver
  • Create a new solver that is implemented using the given tactic. The solver supports the commands Z3Solver.push() and Z3Solver.pop(), but it will always solve each Z3Solver.check() from scratch.

    Seealso

    makeSolver()

    Declaration

    Swift

    func makeSolver(fromTactic tactic: Z3Tactic) -> Z3Solver

Sorts

  • Return the sort of an AST node.

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

    Declaration

    Swift

    func getSort(_ ast: Z3AstBase) -> Z3Sort
  • Create a free (uninterpreted) type using the given name (symbol).

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

    Declaration

    Swift

    func makeUninterpretedSort(_ symbol: Z3Symbol) -> Z3Sort
  • 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 bitVectorSort(size:) creates a bit-vector type.

    Seealso

    Z3_mk_bv_sort

    Declaration

    Swift

    func intSort() -> Z3Sort
  • Create the Boolean type. This type is used to create propositional variables and predicates.

    Declaration

    Swift

    func boolSort() -> Z3Sort
  • Create the real type.

    Note that this type is not a floating point number.

    Declaration

    Swift

    func realSort() -> Z3Sort
  • Create a bit-vector type of the given size. This type can also be seen as a machine integer.

    Remark

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

    Declaration

    Swift

    func bitVectorSort(size: UInt32) -> Z3Sort
  • 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.

    Seealso

    getFiniteDomainSortSize

    Declaration

    Swift

    func makeFiniteDomainSort(name: Z3Symbol, size: UInt64) -> Z3FiniteDomainSort
  • 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.

    Seealso

    makeSelect

    Seealso

    makeStore

    Declaration

    Swift

    func makeArraySort(domain: Z3Sort, range: Z3Sort) -> Z3Sort
  • Create an array type with N arguments

    Seealso

    seealso makeSelectN

    Seealso

    seealso makeStoreN

    Declaration

    Swift

    func makeArraySortN(domains: [Z3Sort], range: Z3Sort) -> Z3Sort
  • 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.

    Declaration

    Swift

    func makeTupleSort(mkTupleName: Z3Symbol,
                       fieldNames: [Z3Symbol],
                       fieldSorts: [Z3Sort]) -> (mkTupleDecl: Z3FuncDecl, projDecl: [Z3FuncDecl], tupleSort: Z3Sort)

    Parameters

    mkTupleName

    name of the constructor function associated with the tuple type.

    fieldNames

    name of the projection functions.

    fieldSorts

    type of the tuple fields. Must be at least the same size as fieldNames.

    Return Value

    A tuple containing:

    • mkTupleDecl: output that will contain the constructor declaration.
    • projDecl: output that will contain the projection function declarations.
    • tupleSort: the proper generated tuple sort

  • 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 enumConstants. The array enumTesters 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.

    Declaration

    Swift

    func makeEnumerationSort(name: Z3Symbol, enumNames: [Z3Symbol]) -> (enumConstants: [Z3FuncDecl], enumTesters: [Z3FuncDecl], sort: Z3Sort)

    Parameters

    name

    name of the enumeration sort.

    n

    number of elements in enumeration sort.

    enumNames

    names of the enumerated elements.

    Return Value

    A tuple containing:

    • enumConstants: constants corresponding to the enumerated elements.
    • parameter: predicates testing if terms of the enumeration sort correspond to an enumeration.
    • sort: The resulting sort

  • Create a constructor.

    Seealso

    makeConstructorList

    Seealso

    queryConstructor

    Declaration

    Swift

    func makeConstructor(name: Z3Symbol, recognizer: Z3Symbol,
                         fieldNames: [Z3Symbol], sorts: [Z3Sort],
                         sortRefs: [UInt32]) -> Z3Constructor

    Parameters

    name

    constructor name.

    recognizer

    name of recognizer function.

    fieldNames

    names of the constructor fields.

    sorts

    field sorts, 0 if the field sort refers to a recursive sort.

    sortRefs

    reference to datatype sort that is an argument to the constructor; if the corresponding sort reference is 0, then the value in sortRefs should be an index referring to one of the recursive data types that is declared.

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

    Seealso

    makeConstructor

    Seealso

    makeConstructorList

    Seealso

    makeDatatypes

    Declaration

    Swift

    func makeDatatype(name: Z3Symbol, constructors: inout [Z3Constructor]) -> Z3Sort

    Parameters

    name

    name of datatype.

    constructors

    array of constructor containers.

  • Create list of constructors.

    Seealso

    makeConstructor

    Declaration

    Swift

    func makeConstructorList(_ constructors: [Z3Constructor]) -> Z3ConstructorList
  • Create mutually recursive datatypes

    Seealso

    makeConstructor

    Seealso

    makeConstructorList

    Seealso

    makeDatatype

    Declaration

    Swift

    func makeDatatypes(sortNames: [Z3Symbol], constructorLists: [Z3ConstructorList]) -> [Z3Sort]

    Parameters

    sortNames

    names of datatype sorts.

    constructorLists

    list of constructors, one list per sort.

    Return Value

    array of datatype sorts

  • Query constructor for declared functions.

    Seealso

    makeConstructor

    Declaration

    Swift

    func queryConstructor(constructor: Z3Constructor, numFields: UInt32) -> (constructor: Z3FuncDecl, tester: Z3FuncDecl, accessors: [Z3FuncDecl])

    Parameters

    constr

    constructor container. The container must have been passed in to a makeDatatype call.

    numFields

    number of accessor fields in the constructor.

    Return Value

    A tuple containing:

    • 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 contains numFields elements.

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

    Declaration

    Swift

    func seqSort(element: Z3Sort) -> Z3Sort
  • Returns whether sort is a sequence sort.

    Declaration

    Swift

    func isSeqSort(_ sort: Z3Sort) -> Bool
  • Retrieve basis sort for sequence sort.

    Declaration

    Swift

    func getSeqSortBasis(_ sort: Z3Sort) -> Z3Sort
  • Create a regular expression sort out of the sort for the underlying sequence sort.

    Declaration

    Swift

    func reSort(seqSort: Z3Sort) -> Z3Sort
  • Check if sort is a regular expression sort.

    Declaration

    Swift

    func isReSort(_ sort: Z3Sort) -> Bool
  • Retrieve basis sort for a regex sort.

    Declaration

    Swift

    func getReSortBasis(_ sort: Z3Sort) -> Z3Sort
  • Create a sort for unicode strings.

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

    Declaration

    Swift

    func stringSort() -> Z3Sort
  • Check if sort is a string sort.

    Declaration

    Swift

    func isStringSort(_ sort: Z3Sort) -> Bool
  • 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.

    Declaration

    Swift

    func charSort() -> Z3Sort
  • Check if sort is a character sort.

    Declaration

    Swift

    func isCharSort(_ sort: Z3Sort) -> Bool

Strings

Symbols

  • 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.

    Seealso

    getSymbolInt

    Seealso

    makeStringSymbol

    Declaration

    Swift

    func makeIntSymbol(_ i: Int32) -> Z3Symbol
  • Create a Z3 symbol using a C string.

    Symbols are used to name several term and type constructors.

    Seealso

    getSymbolString

    Seealso

    makeIntSymbol

    Declaration

    Swift

    func makeStringSymbol(_ s: String) -> Z3Symbol

Tactics and Probes

  • Return a tactic associated with the given name.

    The complete list of tactics may be obtained using the procedures getNumTactics and getTacticName. 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.

    Throws

    If name is not a valid/known tactic name.

    Declaration

    Swift

    func makeTactic(name: String) throws -> Z3Tactic
  • Return the number of builtin tactics available in Z3.

    Declaration

    Swift

    func getNumTactics() -> UInt32
  • Return the name of the idx tactic.

    Precondition

    index < getNumTactics()

    Declaration

    Swift

    func getTacticName(index: UInt32) -> String
  • Return a string containing a description of the tactic with the given name.

    Declaration

    Swift

    func getTacticDescription(name: String) -> String
  • Return a tactic that just return the given goal.

    Declaration

    Swift

    func tacticSkip() -> Z3Tactic
  • Return a tactic that always fails.

    Declaration

    Swift

    func tacticFail() -> Z3Tactic
  • Return a tactic that fails if probe evaluates to false.

    Declaration

    Swift

    func tacticFailIf(_ probe: Z3Probe) -> Z3Tactic
  • Return a tactic that fails if the goal is not trivially satisfiable (i.e., empty) or trivially unsatisfiable (i.e., contains false).

    Declaration

    Swift

    func tacticFailIfNotDecided() -> Z3Tactic
  • Return a probe associated with the given name. The complete list of probes may be obtained using the methods probeCount and probeName(_:). It may also be obtained using the command (help-tactic) in the SMT 2.0 front-end.

    Declaration

    Swift

    func probe(named name: String) -> Z3Probe
  • Return a probe that always evaluates to value.

    Declaration

    Swift

    func probeConst(_ value: Double) -> Z3Probe
  • Return a probe that evaluates to “true” when the value returned by p1 is less than the value returned by p2.

    Remark

    For probes, “true” is any value different from 0.0.

    Declaration

    Swift

    func probeLt(_ p1: Z3Probe, _ p2: Z3Probe) -> Z3Probe
  • Return a probe that evaluates to “true” when the value returned by p1 is greater than the value returned by p2.

    Remark

    For probes, “true” is any value different from 0.0.

    Declaration

    Swift

    func probeGt(_ p1: Z3Probe, _ p2: Z3Probe) -> Z3Probe
  • Return a probe that evaluates to “true” when the value returned by p1 is less than or equal the value returned by p2.

    Remark

    For probes, “true” is any value different from 0.0.

    Declaration

    Swift

    func probeLe(_ p1: Z3Probe, _ p2: Z3Probe) -> Z3Probe
  • Return a probe that evaluates to “true” when the value returned by p1 is greater than or equal the value returned by p2.

    Remark

    For probes, “true” is any value different from 0.0.

    Declaration

    Swift

    func probeGe(_ p1: Z3Probe, _ p2: Z3Probe) -> Z3Probe
  • Return a probe that evaluates to “true” when the value returned by p1 is equal to the value returned by p2.

    Remark

    For probes, “true” is any value different from 0.0.

    Declaration

    Swift

    func probeEq(_ p1: Z3Probe, _ p2: Z3Probe) -> Z3Probe
  • Return a probe that evaluates to “true” when p1 and p2 evaluate to true.

    Remark

    For probes, “true” is any value different from 0.0.

    Declaration

    Swift

    func probeAnd(_ p1: Z3Probe, _ p2: Z3Probe) -> Z3Probe
  • Return a probe that evaluates to “true” when p1 or p2 evaluate to true.

    Remark

    For probes, “true” is any value different from 0.0.

    Declaration

    Swift

    func probeOr(_ p1: Z3Probe, _ p2: Z3Probe) -> Z3Probe
  • Return a probe that evaluates to “true” when probe does not evaluate to true.

    Remark

    For probes, “true” is any value different from 0.0.

    Declaration

    Swift

    func probeNot(_ probe: Z3Probe) -> Z3Probe
  • Return the name of the tactic of index index.

    Precondition

    index < self.tacticCount

    Declaration

    Swift

    func tacticName(atIndex index: UInt32) -> String
  • Return the name of the probe of index index.

    Precondition

    index < self.probeCount

    Declaration

    Swift

    func probeName(atIndex index: UInt32) -> String
  • Return a string containing a description of the tactic with the given name.

    Declaration

    Swift

    func tacticDescription(tacticName: String) -> String
  • Return a string containing a description of the probe with the given name.

    Declaration

    Swift

    func probeDescription(probeName: String) -> String