Documentation ¶
Overview ¶
Package z3 checks the satisfiability of logical formulas.
This package provides bindings for the Z3 SMT solver (https://github.com/Z3Prover/z3). Z3 checks satisfiability of logical formulas over a wide range of terms, including booleans, integers, reals, bit-vectors, and uninterpreted functions. For a good introduction to the concepts of SMT and Z3, see the Z3 guide (http://rise4fun.com/z3/tutorialcontent/guide).
This package does not yet support all of the features or types supported by Z3, though it supports a reasonably large subset.
The main entry point to the z3 package is type Context. All values are created and all solving is done relative to some Context, and values from different Contexts cannot be mixed.
Symbolic values implement the Value interface. Every value has a type, called a "sort" and represented by type Sort. Sorts fall into general categories called "kinds", such as Bool and Int. Each kind corresponds to a different concrete type that implements the Value interface, since the kind determines the set of operations that make sense on a value. A Bool expression is also called a "formula".
These concrete value types help with type checking expressions, but type checking is ultimately done dynamically by Z3. Attempting to create a badly typed value will panic.
Symbolic values are represented as expressions of numerals, constants, and uninterpreted functions. A numeral is a literal, fixed value like "2". A constant is a term like "x", whose value is fixed but unspecified. An uninterpreted function is a function whose mapping from arguments to results is fixed but unspecified (this is in contrast to an "interpreted function" like + whose interpretation is specified to be addition). Functions are pure (side-effect-free) like mathematical functions, but unlike mathematical functions they are always total. A constant can be thought of as a function with zero arguments.
It's possible to go back and forth between a symbolic value and the expression representing that value using Value.AsAST and AST.AsValue.
Type Solver checks the satisfiability of a set of formulas. If the Solver determines that a set of formulas is satisfiable, it can construct a Model giving a specific assignment of constants and uninterpreted functions that satisfies the set of formulas.
Index ¶
- Constants
- type AST
- func (ast AST) AsFuncDecl() FuncDecl
- func (ast AST) AsSort() Sort
- func (ast AST) AsValue() Value
- func (ast AST) Context() *Context
- func (ast AST) Equal(o AST) bool
- func (ast AST) Hash() uint64
- func (ast AST) ID() uint64
- func (ast AST) Kind() ASTKind
- func (ast AST) String() string
- func (ast AST) Translate(target *Context) AST
- type ASTKind
- type Array
- type BV
- func (l BV) Add(r BV) BV
- func (l BV) AllBits() BV
- func (l BV) And(r BV) BV
- func (l BV) AnyBits() BV
- func (lit BV) AsBigSigned() (val *big.Int, isLiteral bool)
- func (lit BV) AsBigUnsigned() (val *big.Int, isLiteral bool)
- func (lit BV) AsInt64() (val int64, isLiteral, ok bool)
- func (lit BV) AsUint64() (val uint64, isLiteral, ok bool)
- func (l BV) Concat(r BV) BV
- func (l BV) Eq(r BV) Bool
- func (l BV) Extract(high int, low int) BV
- func (l BV) IEEEToFloat(s Sort) Float
- func (l BV) Lsh(i BV) BV
- func (l BV) Mul(r BV) BV
- func (l BV) NE(r BV) Bool
- func (l BV) Nand(r BV) BV
- func (l BV) Neg() BV
- func (l BV) Nor(r BV) BV
- func (l BV) Not() BV
- func (l BV) Or(r BV) BV
- func (l BV) Repeat(i int) BV
- func (l BV) RotateLeft(i BV) BV
- func (l BV) RotateRight(i BV) BV
- func (l BV) SDiv(r BV) BV
- func (l BV) SGE(r BV) Bool
- func (l BV) SGT(r BV) Bool
- func (l BV) SLE(r BV) Bool
- func (l BV) SLT(r BV) Bool
- func (l BV) SMod(r BV) BV
- func (l BV) SRem(r BV) BV
- func (l BV) SRsh(i BV) BV
- func (l BV) SToFloat(s Sort) Float
- func (l BV) SToInt() Int
- func (l BV) SignExtend(i int) BV
- func (l BV) Sub(r BV) BV
- func (l BV) UDiv(r BV) BV
- func (l BV) UGE(r BV) Bool
- func (l BV) UGT(r BV) Bool
- func (l BV) ULE(r BV) Bool
- func (l BV) ULT(r BV) Bool
- func (l BV) URem(r BV) BV
- func (l BV) URsh(i BV) BV
- func (l BV) UToFloat(s Sort) Float
- func (l BV) UToInt() Int
- func (l BV) Xnor(r BV) BV
- func (l BV) Xor(r BV) BV
- func (l BV) ZeroExtend(i int) BV
- type Bool
- func (l Bool) And(r ...Bool) Bool
- func (l Bool) AsBool() (val bool, isLiteral bool)
- func (l Bool) Eq(r Bool) Bool
- func (cond Bool) IfThenElse(cons Value, alt Value) Value
- func (l Bool) Iff(r Bool) Bool
- func (l Bool) Implies(r Bool) Bool
- func (l Bool) NE(r Bool) Bool
- func (l Bool) Not() Bool
- func (l Bool) Or(r ...Bool) Bool
- func (l Bool) Xor(r Bool) Bool
- type Config
- type Context
- func (ctx *Context) ArraySort(domain, range_ Sort) Sort
- func (ctx *Context) BVConst(name string, bits int) BV
- func (ctx *Context) BVSort(bits int) Sort
- func (ctx *Context) BoolConst(name string) Bool
- func (ctx *Context) BoolSort() Sort
- func (ctx *Context) Config() *Config
- func (ctx *Context) Const(name string, sort Sort) Value
- func (ctx *Context) ConstArray(domain Sort, value Value) Array
- func (ctx *Context) Distinct(vals ...Value) Bool
- func (ctx *Context) Extra(key interface{}) interface{}
- func (ctx *Context) FiniteDomainSort(name string, n uint64) Sort
- func (ctx *Context) FloatFromBits(sign, exp, sig BV) Float
- func (ctx *Context) FloatInf(s Sort, neg bool) Float
- func (ctx *Context) FloatNaN(s Sort) Float
- func (ctx *Context) FloatSort(ebits, sbits int) Sort
- func (ctx *Context) FloatZero(s Sort, neg bool) Float
- func (ctx *Context) FreshConst(prefix string, sort Sort) Value
- func (ctx *Context) FreshFuncDecl(prefix string, domain []Sort, range_ Sort) FuncDecl
- func (ctx *Context) FromBigInt(val *big.Int, sort Sort) Value
- func (ctx *Context) FromBigRat(val *big.Rat) Real
- func (ctx *Context) FromBool(val bool) Bool
- func (ctx *Context) FromFloat32(val float32, sort Sort) Float
- func (ctx *Context) FromFloat64(val float64, sort Sort) Float
- func (ctx *Context) FromInt(val int64, sort Sort) Value
- func (ctx *Context) FuncDecl(name string, domain []Sort, range_ Sort) FuncDecl
- func (ctx *Context) IntConst(name string) Int
- func (ctx *Context) IntSort() Sort
- func (ctx *Context) Interrupt()
- func (ctx *Context) RealConst(name string) Real
- func (ctx *Context) RealSort() Sort
- func (ctx *Context) RoundingMode() RoundingMode
- func (ctx *Context) SetExtra(key, value interface{})
- func (ctx *Context) SetRoundingMode(rm RoundingMode) RoundingMode
- func (ctx *Context) Simplify(x Value, config *Config) Value
- func (ctx *Context) UninterpretedSort(name string) Sort
- type ErrSatUnknown
- type FiniteDomain
- type Float
- func (l Float) Abs() Float
- func (l Float) Add(r Float) Float
- func (lit Float) AsBigFloat() (val *big.Float, isLiteral bool)
- func (l Float) Div(r Float) Float
- func (l Float) Eq(r Float) Bool
- func (l Float) GE(r Float) Bool
- func (l Float) GT(r Float) Bool
- func (l Float) IEEEEq(r Float) Bool
- func (l Float) IsInfinite() Bool
- func (l Float) IsNaN() Bool
- func (l Float) IsNegative() Bool
- func (l Float) IsNormal() Bool
- func (l Float) IsPositive() Bool
- func (l Float) IsSubnormal() Bool
- func (l Float) IsZero() Bool
- func (l Float) LE(r Float) Bool
- func (l Float) LT(r Float) Bool
- func (l Float) Max(r Float) Float
- func (l Float) Min(r Float) Float
- func (l Float) Mul(r Float) Float
- func (l Float) MulAdd(r Float, a Float) Float
- func (l Float) NE(r Float) Bool
- func (l Float) Neg() Float
- func (l Float) Rem(r Float) Float
- func (l Float) Round(rm RoundingMode) Float
- func (l Float) Sqrt() Float
- func (l Float) Sub(r Float) Float
- func (l Float) ToFloat(s Sort) Float
- func (l Float) ToIEEEBV() BV
- func (l Float) ToReal() Real
- func (l Float) ToSBV(bits int) BV
- func (l Float) ToUBV(bits int) BV
- type FuncDecl
- type Int
- func (l Int) Add(r ...Int) Int
- func (lit Int) AsBigInt() (val *big.Int, isConst bool)
- func (lit Int) AsInt64() (val int64, isLiteral, ok bool)
- func (lit Int) AsUint64() (val uint64, isLiteral, ok bool)
- func (l Int) Div(r Int) Int
- func (l Int) Eq(r Int) Bool
- func (l Int) Exp(r Int) Int
- func (l Int) GE(r Int) Bool
- func (l Int) GT(r Int) Bool
- func (l Int) LE(r Int) Bool
- func (l Int) LT(r Int) Bool
- func (l Int) Mod(r Int) Int
- func (l Int) Mul(r ...Int) Int
- func (l Int) NE(r Int) Bool
- func (l Int) Neg() Int
- func (l Int) Rem(r Int) Int
- func (l Int) Sub(r ...Int) Int
- func (l Int) ToBV(bits int) BV
- func (l Int) ToReal() Real
- type Kind
- type Model
- type Real
- func (l Real) Add(r ...Real) Real
- func (lit Real) Approx(precision int) (lower, upper Real, isLiteralIrrational bool)
- func (lit Real) AsBigRat() (val *big.Rat, isLiteralRational bool)
- func (lit Real) AsRat() (numer, denom Int, isLiteralRational bool)
- func (l Real) Div(r Real) Real
- func (l Real) Eq(r Real) Bool
- func (l Real) Exp(r Real) Real
- func (l Real) GE(r Real) Bool
- func (l Real) GT(r Real) Bool
- func (l Real) IsInt() Bool
- func (l Real) LE(r Real) Bool
- func (l Real) LT(r Real) Bool
- func (l Real) Mul(r ...Real) Real
- func (l Real) NE(r Real) Bool
- func (l Real) Neg() Real
- func (l Real) Sub(r ...Real) Real
- func (l Real) ToFloat(s Sort) Float
- func (l Real) ToFloatExp(exp Int, s Sort) Float
- func (l Real) ToInt() Int
- type RoundingMode
- type Solver
- type Sort
- type Uninterpreted
- type Value
Constants ¶
const ( ASTKindApp = ASTKind(C.Z3_APP_AST) // Constant and applications ASTKindNumeral = ASTKind(C.Z3_NUMERAL_AST) // Numeral constants (excluding real algebraic numbers) ASTKindVar = ASTKind(C.Z3_VAR_AST) // Bound variables ASTKindQuantifier = ASTKind(C.Z3_QUANTIFIER_AST) // Quantifiers ASTKindSort = ASTKind(C.Z3_SORT_AST) // Sorts ASTKindFuncDecl = ASTKind(C.Z3_FUNC_DECL_AST) // Function declarations ASTKindUnknown = ASTKind(C.Z3_UNKNOWN_AST) )
const ( KindUninterpreted = Kind(C.Z3_UNINTERPRETED_SORT) KindBool = Kind(C.Z3_BOOL_SORT) KindInt = Kind(C.Z3_INT_SORT) KindReal = Kind(C.Z3_REAL_SORT) KindBV = Kind(C.Z3_BV_SORT) KindArray = Kind(C.Z3_ARRAY_SORT) KindDatatype = Kind(C.Z3_DATATYPE_SORT) KindRelation = Kind(C.Z3_RELATION_SORT) KindFiniteDomain = Kind(C.Z3_FINITE_DOMAIN_SORT) KindFloatingPoint = Kind(C.Z3_FLOATING_POINT_SORT) KindRoundingMode = Kind(C.Z3_ROUNDING_MODE_SORT) KindUnknown = Kind(C.Z3_UNKNOWN_SORT) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AST ¶
type AST struct {
// contains filtered or unexported fields
}
An AST is the abstract syntax tree of an expression, sort, etc.
func (AST) AsFuncDecl ¶
AsFuncDecl returns this AST as a FuncDecl.
It panics if ast is not a function declaration expression. That is, ast must have Kind ASTKindFuncDecl.
func (AST) AsSort ¶
AsSort returns this AST as a sort.
It panics if ast is not a sort expression. That is, ast must have Kind ASTKindSort.
func (AST) AsValue ¶
AsValue returns this AST as a symbolic value.
It panics if ast is not a value expression. That is, ast must have Kind ASTKindApp, ASTKindNumeral, ASTKindVar, or ASTKindQuantifier.
func (AST) Hash ¶
Hash returns a hash of ast. Structurally identical ASTs will have the same hash code.
type ASTKind ¶
type ASTKind int
ASTKind is a general category of ASTs, such as numerals, applications, or sorts.
type Array ¶
type Array value
Array is a symbolic value representing an extensional array.
Unlike typical arrays in programming, an extensional array has an arbitrary index (domain) sort, in addition to an arbitrary value (range) sort. It can also be viewed like a hash table, except that all possible keys are always present.
Arrays are "updated" by storing a new value to a particular index. This creates a new array that's identical to the old array except that that index.
Array implements Value.
func (Array) Default ¶
Default returns the default value of an array, for arrays that can be represented as finite maps plus a default value.
This is useful for extracting array values interpreted by models.
type BV ¶
type BV value
BV is a symbolic value representing a bit-vector.
Bit vectors correspond to machine words. They have finite domains of size 2^n and implement modular arithmetic in both unsigned and two's complement signed forms.
BV implements Value.
func (BV) AsBigSigned ¶
AsBigSigned returns the value of lit as a math/big.Int, interpreting lit as a signed two's complement number. If lit is not a literal, it returns nil, false.
func (BV) AsBigUnsigned ¶
AsBigUnsigned is like AsBigSigned, but interprets lit as unsigned.
func (BV) AsInt64 ¶
AsInt64 returns the value of lit as an int64, interpreting lit as a two's complement signed number. If lit is not a literal, it returns 0, false, false. If lit is a literal, but its value cannot be represented as an int64, it returns 0, true, false.
func (BV) AsUint64 ¶
AsUint64 is like AsInt64, but interprets lit as unsigned and fails if lit cannot be represented as a uint64.
func (BV) Concat ¶
Concat returns concatenation of l and r.
The result is a bit-vector whose length is the sum of the lengths of l and r.
func (BV) Extract ¶
Extract returns bits [high, low] (inclusive) of l, where bit 0 is the least significant bit.
func (BV) IEEEToFloat ¶
IEEEToFloat converts l into a floating-point number, interpreting l in IEEE 754-2008 format.
The size of l must equal ebits+sbits of s.
func (BV) Lsh ¶
Lsh returns l shifted left by i bits.
This is equivalent to l * 2^i.
l and i must have the same size. The result has the same sort.
func (BV) Mul ¶
Mul returns the two's complement product of l and r.
l and r must have the same size.
func (BV) RotateLeft ¶
RotateLeft returns l rotated left by i bits.
l and i must have the same size.
func (BV) RotateRight ¶
RotateRight returns l rotated right by i bits.
l and i must have the same size.
func (BV) SDiv ¶
SDiv returns l / r rounded toward 0, treating l and r as two's complement signed numbers.
If r is 0, the result is unconstrained.
l and r must have the same size.
func (BV) SMod ¶
SMod returns the two's complement signed modulus of l divided by r.
The sign of the result follows the sign of r.
l and r must have the same size.
func (BV) SRem ¶
SRem returns the two's complement signed remainder of l divided by r.
The sign of the result follows the sign of l.
l and r must have the same size.
func (BV) SRsh ¶
SRsh returns l arithmetically shifted right by i bits.
This is like URsh, but the sign of the result is the sign of l.
l and i must have the same size. The result has the same sort.
func (BV) SToFloat ¶
SToFloat converts signed bit-vector l into a floating-point number.
If necessary, the result will be rounded according to the current rounding mode.
func (BV) SignExtend ¶
SignExtend returns l sign-extended to a bit-vector of length m+i, where m is the length of l.
func (BV) Sub ¶
Sub returns the two's complement subtraction l minus r.
l and r must have the same size.
func (BV) UDiv ¶
UDiv returns the floor of l / r, treating l and r as unsigned.
If r is 0, the result is unconstrained.
l and r must have the same size.
func (BV) UGE ¶
UGE returns the l >= r, where l and r are unsigned.
l and r must have the same size.
func (BV) ULE ¶
ULE returns the l <= r, where l and r are unsigned.
l and r must have the same size.
func (BV) URem ¶
URem returns the unsigned remainder of l divided by r.
l and r must have the same size.
func (BV) URsh ¶
URsh returns l logically shifted right by i bits.
This is equivalent to l / 2^i, where l and i are unsigned.
l and i must have the same size. The result has the same sort.
func (BV) UToFloat ¶
UToFloat converts unsigned bit-vector l into a floating-point number.
If necessary, the result will be rounded according to the current rounding mode.
func (BV) ZeroExtend ¶
ZeroExtend returns l zero-extended to a bit-vector of length m+i, where m is the length of l.
type Bool ¶
type Bool value
Bool is a symbolic value representing "true" or "false".
Bool implements Value.
func (Bool) AsBool ¶
AsBool returns the value of l as a Go bool. If l is not a literal, AsBool returns false, false.
func (Bool) IfThenElse ¶
IfThenElse returns a Value equal to cons if cond is true, otherwise alt.
cons and alt must have the same sort. The result will have the same sort as cons and alt.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config stores a set of configuration parameters. Configs are used to configure many different objects in Z3.
func NewContextConfig ¶
func NewContextConfig() *Config
NewContextConfig returns *Config for configuring a new Context.
The following are commonly useful parameters:
timeout uint Timeout in milliseconds used for solvers (default: ∞) auto_config bool Use heuristics to automatically select solver and configure it (default: true) proof bool Enable proof generation (default: false) model bool Enable model generation for solvers by default (default: true) unsat_core bool Enable unsat core generation for solvers by default (default: false)
Most of these can be changed after a Context is created using Context.Config().
func NewSimplifyConfig ¶
NewSimplifyConfig returns *Config for configuring the simplifier.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is an environment for creating symbolic values and checking satisfiability.
Nearly all interaction with Z3 is done relative to a Context. Values are bound to the Context that created them and cannot be combined with Values from other Contexts.
Context is thread-safe. However, most operations block other operations (one notable exception is Interrupt). Hence, to do things in parallel, it's best to create multiple Contexts.
func NewContext ¶
NewContext returns a new Z3 context with the given configuration.
The config argument must have been created with NewContextConfig. If config is nil, the default configuration is used.
func (*Context) ArraySort ¶
ArraySort returns a sort for arrays that are indexed by domain and have values from range.
func (*Context) BVConst ¶
BVConst returns a bit-vector constant named "name" with the given width in bits.
func (*Context) Config ¶
Config returns a *Config object for dynamically changing ctx's configuration.
func (*Context) Const ¶
Const returns a constant named "name" of the given sort. This constant will be same as all other constants created with this name.
func (*Context) ConstArray ¶
ConstArray returns an Array value where every index maps to value.
func (*Context) Distinct ¶
Distinct returns a Value that is true if no two vals are equal.
All Values must have the same sort.
func (*Context) Extra ¶
func (ctx *Context) Extra(key interface{}) interface{}
Extra returns the "extra" data associated with key, or nil if there is no data associated with key.
func (*Context) FiniteDomainSort ¶
FiniteDomainSort returns a sort for finite domain values with domain size n.
Two finite-domain sorts are the same if and only if they have the same name.
func (*Context) FloatFromBits ¶
FloatFromBits constructs a floating-point value from a sign bit, exponent bits, and significand bits.
See the description of type Float for how these bits are interpreted.
sign must be a 1-bit bit-vector.
func (*Context) FloatSort ¶
FloatSort returns a floating-point sort with ebits exponent bits and sbits significand bits.
Note that sbits counts the "hidden" most-significant bit of the significand. Hence, a double-precision floating point number has sbits of 53, even though only 52 bits are actually represented.
Common exponent and significand bit counts are:
ebits sbits Half precision 5 11 Single precision 8 24 (float32) Double precision 11 53 (float64) Quad precision 15 113
func (*Context) FreshConst ¶
FreshConst returns a constant that is distinct from all other constants. The name will begin with "prefix".
func (*Context) FreshFuncDecl ¶
FreshFuncDecl creates a fresh uninterpreted function distinct from all other functions.
func (*Context) FromBigInt ¶
FromBigInt returns a literal whose value is val. sort must have kind int, real, finite-domain, bit-vector, or float.
func (*Context) FromBigRat ¶
FromBigRat returns a real literal whose value is val.
func (*Context) FromFloat32 ¶
FromFloat32 constructs a floating-point literal from val. sort must be a floating-point sort.
func (*Context) FromFloat64 ¶
FromFloat64 constructs a floating-point literal from val. sort must be a floating-point sort.
func (*Context) FromInt ¶
FromInt returns a literal whose value is val. sort must have kind int, real, finite-domain, bit-vector, or float.
func (*Context) FuncDecl ¶
FuncDecl creates an uninterpreted function named "name".
In contrast with an interpreted function like "+", an uninterpreted function is only assigned an interpretation in a particular model, and different models may assign different interpretations.
func (*Context) Interrupt ¶
func (ctx *Context) Interrupt()
Interrupt stops the current solver, simplifier, or tactic being executed by ctx.
func (*Context) RoundingMode ¶
func (ctx *Context) RoundingMode() RoundingMode
RoundingMode returns ctx's current rounding mode for floating-point operations.
func (*Context) SetExtra ¶
func (ctx *Context) SetExtra(key, value interface{})
SetExtra associates key with value in ctx's "extra" data. This can be used by other packages to associate other data with ctx, such as caches. key must support comparison.
func (*Context) SetRoundingMode ¶
func (ctx *Context) SetRoundingMode(rm RoundingMode) RoundingMode
SetRoundingMode sets ctx's current rounding mode for floating-point operations and returns ctx's old rounding mode.
func (*Context) Simplify ¶
Simplify simplifies expression x.
The config argument must have been created with NewSimplifyConfig. If config is nil, the default configuration is used.
The resulting expression will have the same sort and value as x, but with a simpler AST.
func (*Context) UninterpretedSort ¶
UninterpretedSort returns a sort for uninterpreted values.
Two uninterpreted sorts are the same if and only if they have the same name.
type ErrSatUnknown ¶
type ErrSatUnknown struct { // Reason gives a brief description of why Z3 could not // determine satisfiability. Reason string }
ErrSatUnknown is produced when Z3 cannot determine satisfiability.
func (*ErrSatUnknown) Error ¶
func (e *ErrSatUnknown) Error() string
Error returns the reason Z3 could not determine satisfiability.
type FiniteDomain ¶
type FiniteDomain value
FiniteDomain is a symbolic value from a finite domain of size n, where n depends on the value's sort.
Finite domain values are uninterpreted (see Uninterpreted), but represented as numerals. Hence, to construct a specific finite-domain value, use methods like Context.FromInt with a value in [0, n).
FiniteDomain implements Value.
func (FiniteDomain) Eq ¶
func (l FiniteDomain) Eq(r FiniteDomain) Bool
Eq returns a Value that is true if l and r are equal.
func (FiniteDomain) NE ¶
func (l FiniteDomain) NE(r FiniteDomain) Bool
NE returns a Value that is true if l and r are not equal.
type Float ¶
type Float value
Float is a symbolic value representing a floating-point number with IEEE 764-2008 semantics (extended to any possible exponent and significand length).
A floating-point number falls into one of five categories: normal numbers, subnormal numbers, zero, infinite, or NaN. All of these except for NaN can be either positive or negative.
Floating-point numbers are represented as three fields: a single bit sign, an exponent ebits wide, and a significand sbits-1 wide. If the exponent field is neither all 0s or all 1s, then the value is a "normal" number, which is interpreted as
(-1)^sign * 2^(exp - bias) * (1 + sig / 2^sbits)
where bias = 2^(ebits - 1) - 1, and exp and sig are interpreted as unsigned binary values. In particular, the significand is extended with a "hidden" most-significant 1 bit and the exponent is "biased".
Float implements Value.
func (Float) AsBigFloat ¶
AsBigFloat returns the value of lit as a math/big.Float. If lit is not a literal, it returns nil, false. If lit is NaN, it returns nil, true (because big.Float cannot represent NaN).
func (Float) IEEEEq ¶
IEEEEq returns l == r according to IEEE 754 equality.
This differs from Eq, which is true if l and r are identical. In contrast, under IEEE equality, ±0 == ±0, while NaN != NaN and ±inf != ±inf.
func (Float) IsNegative ¶
IsNegative returns true if l is negative.
func (Float) IsPositive ¶
IsPositive returns true if l is positive.
func (Float) IsSubnormal ¶
IsSubnormal returns true if l is a subnormal floating-point number.
func (Float) MulAdd ¶
MulAdd returns l*r+a (fused multiply and add).
MulAdd uses the current rounding mode on the result of the whole operation.
func (Float) Round ¶
func (l Float) Round(rm RoundingMode) Float
Round rounds l to an integral floating-point value according to rounding mode rm.
func (Float) ToFloat ¶
ToFloat converts l into a floating-point number of a different floating-point sort.
If necessary, the result will be rounded according to the current rounding mode.
func (Float) ToIEEEBV ¶
ToIEEEBV converts l to a bit-vector in IEEE 754-2008 format.
Note that NaN has many possible representations. This conversion always uses the same representation.
func (Float) ToReal ¶
ToReal converts l into a real number.
If l is ±inf, or NaN, the result is unspecified.
type FuncDecl ¶
type FuncDecl struct {
// contains filtered or unexported fields
}
FuncDecl is a function declaration.
A FuncDecl can represent either a interpreted function like "+" or an uninterpreted function created by Context.FuncDecl.
A FuncDecl can be applied to a set of arguments to create a Value representing the result of the function.
func (FuncDecl) Apply ¶
Apply creates a Value representing the result of applying f to args.
The sorts of args must be the domain of f. The sort of the resulting value will be f's range.
type Int ¶
type Int value
Int is a symbolic value representing an integer with infinite precision.
Int implements Value.
func (Int) AsBigInt ¶
AsBigInt returns the value of lit as a math/big.Int. If lit is not a literal, it returns nil, false.
func (Int) AsInt64 ¶
AsInt64 returns the value of lit as an int64. If lit is not a literal, it returns 0, false, false. If lit is a literal, but its value cannot be represented as an int64, it returns 0, true, false.
func (Int) AsUint64 ¶
AsUint64 is like AsInt64, but returns a uint64 and fails if lit cannot be represented as a uint64.
func (Int) Div ¶
Div returns the floor of l / r.
If r is 0, the result is unconstrained.
Note that this differs from Go division: Go rounds toward zero (truncated division), whereas this rounds toward -inf.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
A Model is a binding of constants that satisfies a set of formulas.
func (*Model) Eval ¶
Eval evaluates val using the concrete interpretations of constants and functions in model m.
If completion is true, it will assign interpretations for any constants or functions that currently don't have an interpretation in m. Otherwise, the resulting value may not be concrete.
Eval returns nil if val cannot be evaluated. This can happen if val contains a quantifier or is type-incorrect, or if m is a partial model (that is, the option MODEL_PARTIAL was set to true).
func (*Model) SortUniverse ¶
func (m *Model) SortUniverse(s Sort) []Uninterpreted
SortUniverse returns the interpretation of s in m. s must be in the set returned by m.Sorts.
The interpretation of s is a finite set of distinct values of sort s.
type Real ¶
type Real value
Real is a symbolic value representing a real number.
Real implements Value.
func (Real) Approx ¶
Approx approximates lit as two rational literals, where the difference between lower and upper is less than 1/10**precision. If lit is not an irrational literal, it returns false for isLiteralIrrational.
func (Real) AsBigRat ¶
AsBigRat returns the value of lit as a math/big.Rat. If lit is not a literal or is not rational, it returns nil, false.
func (Real) AsRat ¶
AsRat returns the value of lit as a numerator and denominator Int literals. If lit is not a literal or is not rational, it returns false for isLiteralRational. To round an arbitrary real to be rational, see method Real.Approx.
func (Real) ToFloat ¶
ToFloat converts l into a floating-point number.
If necessary, the result will be rounded according to the current rounding mode.
func (Real) ToFloatExp ¶
ToFloatExp converts l into a floating-point number l*2^exp.
If necessary, the result will be rounded according to the current rounding mode.
type RoundingMode ¶
type RoundingMode int
RoundingMode represents a floating-point rounding mode.
The zero value of RoundingMode is RoundToNearestEven, which is the rounding mode in Go and the typical default rounding mode in floating-point math.
const ( // RoundToNearestEven rounds floating-point results to the // nearest representable value. If the result is exactly // midway between two representable values, the even // representable value is chosen. RoundToNearestEven RoundingMode = iota // RoundToNearestAway rounds floating-point results to the // nearest representable value. If the result is exactly // midway between two representable values, the value with the // largest magnitude (away from 0) is chosen. RoundToNearestAway // RoundToPositive rounds floating-point results toward // positive infinity. RoundToPositive // RoundToPositive rounds floating-point results toward // negative infinity. RoundToNegative // RoundToZero rounds floating-point results toward zero. RoundToZero )
type Solver ¶
type Solver struct {
// contains filtered or unexported fields
}
A Solver is a collection of predicates that can be checked for satisfiability.
These predicates form a stack that can be manipulated with Push/Pop.
func (*Solver) Check ¶
Check determines whether the predicates in Solver s are satisfiable or unsatisfiable. If Z3 is unable to determine satisfiability, it returns an *ErrSatUnknown error.
func (*Solver) Model ¶
Model returns the model for the last Check. Model panics if Check has not been called or the last Check did not return true.
func (*Solver) Pop ¶
func (s *Solver) Pop()
Pop removes assertions that were added since the matching Push.
func (*Solver) Push ¶
func (s *Solver) Push()
Push saves the current state of the Solver so it can be restored with Pop.
type Sort ¶
type Sort struct {
// contains filtered or unexported fields
}
Sort represents the type of a symbolic value. A Sort can be a basic type such as "int" or "bool" or a parameterized type such as "bit-vector of 30 bits" or "array from int to bool".
func (Sort) DomainAndRange ¶
DomainAndRange returns the domain and range of an array sort.
type Uninterpreted ¶
type Uninterpreted value
Uninterpreted is a symbolic value with no interpretation. Uninterpreted values have identity—that is, they can be compared for equality—but have no inherent meaning otherwise.
Uninterpreted and FiniteDomain are similar, except that Uninterpreted values come from an unbounded universe.
Uninterpreted implements Value.
func (Uninterpreted) Eq ¶
func (l Uninterpreted) Eq(r Uninterpreted) Bool
Eq returns a Value that is true if l and r are equal.
func (Uninterpreted) NE ¶
func (l Uninterpreted) NE(r Uninterpreted) Bool
NE returns a Value that is true if l and r are not equal.
type Value ¶
type Value interface { // AsAST returns the abstract syntax tree underlying this // Value. AsAST() AST // Sort returns this value's sort. Sort() Sort // Context returns the Context that created this Value. Context() *Context // String returns an S-expression representation of this value. String() string // contains filtered or unexported methods }
An Value is a symbolic value (a Z3 expression).
This package exports a concrete type for each different kind of value, such as Bool, BV, and Int. These concrete types provide methods for deriving other values.
Having separate types for each kind separates which methods can be applied to which kind of value and provides some level of static type safety. However, by no means does this fully capture Z3's type system, so dynamic type checking can still fail.
Source Files ¶
- array.go
- array.wrap.go
- ast.go
- astkind.go
- bv.go
- bv.wrap.go
- config.go
- context.go
- expr.go
- finite.go
- finite.wrap.go
- float.go
- float.wrap.go
- funcdecl.go
- int.go
- int.wrap.go
- intreal.go
- kind.go
- logic.go
- logic.wrap.go
- model.go
- package.go
- real.go
- real.wrap.go
- simplify.go
- solver.go
- sort.go
- uninterp.go
- uninterp.wrap.go