Z3
Data Structures | Functions | Variables
z3py Namespace Reference

Data Structures

class  AlgebraicNumRef
 
class  ApplyResult
 
class  ArithRef
 
class  ArithSortRef
 Arithmetic. More...
 
class  ArrayRef
 
class  ArraySortRef
 Arrays. More...
 
class  AstMap
 
class  AstRef
 
class  AstVector
 
class  BitVecNumRef
 
class  BitVecRef
 
class  BitVecSortRef
 Bit-Vectors. More...
 
class  BoolRef
 
class  BoolSortRef
 Booleans. More...
 
class  CheckSatResult
 
class  Context
 
class  Datatype
 
class  DatatypeRef
 
class  DatatypeSortRef
 
class  ExprRef
 Expressions. More...
 
class  FiniteDomainNumRef
 
class  FiniteDomainRef
 
class  FiniteDomainSortRef
 
class  Fixedpoint
 Fixedpoint. More...
 
class  FPNumRef
 FP Numerals. More...
 
class  FPRef
 FP Expressions. More...
 
class  FPRMRef
 
class  FPRMSortRef
 
class  FPSortRef
 FP Sorts. More...
 
class  FuncDeclRef
 Function Declarations. More...
 
class  FuncEntry
 
class  FuncInterp
 
class  Goal
 
class  IntNumRef
 
class  ModelRef
 
class  Optimize
 
class  OptimizeObjective
 Optimize. More...
 
class  ParamDescrsRef
 
class  ParamsRef
 Parameter Sets. More...
 
class  PatternRef
 Patterns. More...
 
class  Probe
 
class  QuantifierRef
 Quantifiers. More...
 
class  RatNumRef
 
class  ReRef
 
class  ReSortRef
 Regular expressions. More...
 
class  ScopedConstructor
 
class  ScopedConstructorList
 
class  SeqRef
 
class  SeqSortRef
 Strings, Sequences and Regular expressions. More...
 
class  Solver
 
class  SortRef
 
class  Statistics
 Statistics. More...
 
class  Tactic
 
class  Z3PPObject
 ASTs base class. More...
 

Functions

def enable_trace (msg)
 
def disable_trace (msg)
 
def get_version_string ()
 
def get_version ()
 
def get_full_version ()
 
def open_log (fname)
 
def append_log (s)
 
def to_symbol (s, ctx=None)
 
def z3_error_handler (c, e)
 
def main_ctx ()
 
def set_param (args, kws)
 
def reset_params ()
 
def set_option (args, kws)
 
def get_param (name)
 
def is_ast (a)
 
def eq (a, b)
 
def is_sort (s)
 
def DeclareSort (name, ctx=None)
 
def is_func_decl (a)
 
def Function (name, sig)
 
def is_expr (a)
 
def is_app (a)
 
def is_const (a)
 
def is_var (a)
 
def get_var_index (a)
 
def is_app_of (a, k)
 
def If (a, b, c, ctx=None)
 
def Distinct (args)
 
def Const (name, sort)
 
def Consts (names, sort)
 
def Var (idx, s)
 
def RealVar (idx, ctx=None)
 
def RealVarVector (n, ctx=None)
 
def is_bool (a)
 
def is_true (a)
 
def is_false (a)
 
def is_and (a)
 
def is_or (a)
 
def is_not (a)
 
def is_eq (a)
 
def is_distinct (a)
 
def BoolSort (ctx=None)
 
def BoolVal (val, ctx=None)
 
def Bool (name, ctx=None)
 
def Bools (names, ctx=None)
 
def BoolVector (prefix, sz, ctx=None)
 
def FreshBool (prefix='b', ctx=None)
 
def Implies (a, b, ctx=None)
 
def Xor (a, b, ctx=None)
 
def Not (a, ctx=None)
 
def And (args)
 
def Or (args)
 
def is_pattern (a)
 
def MultiPattern (args)
 
def is_quantifier (a)
 
def ForAll (vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
 
def Exists (vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
 
def is_arith_sort (s)
 
def is_arith (a)
 
def is_int (a)
 
def is_real (a)
 
def is_int_value (a)
 
def is_rational_value (a)
 
def is_algebraic_value (a)
 
def is_add (a)
 
def is_mul (a)
 
def is_sub (a)
 
def is_div (a)
 
def is_idiv (a)
 
def is_mod (a)
 
def is_le (a)
 
def is_lt (a)
 
def is_ge (a)
 
def is_gt (a)
 
def is_is_int (a)
 
def is_to_real (a)
 
def is_to_int (a)
 
def IntSort (ctx=None)
 
def RealSort (ctx=None)
 
def IntVal (val, ctx=None)
 
def RealVal (val, ctx=None)
 
def RatVal (a, b, ctx=None)
 
def Q (a, b, ctx=None)
 
def Int (name, ctx=None)
 
def Ints (names, ctx=None)
 
def IntVector (prefix, sz, ctx=None)
 
def FreshInt (prefix='x', ctx=None)
 
def Real (name, ctx=None)
 
def Reals (names, ctx=None)
 
def RealVector (prefix, sz, ctx=None)
 
def FreshReal (prefix='b', ctx=None)
 
def ToReal (a)
 
def ToInt (a)
 
def IsInt (a)
 
def Sqrt (a, ctx=None)
 
def Cbrt (a, ctx=None)
 
def is_bv_sort (s)
 
def is_bv (a)
 
def is_bv_value (a)
 
def BV2Int (a, is_signed=False)
 
def Int2BV (a, num_bits)
 
def BitVecSort (sz, ctx=None)
 
def BitVecVal (val, bv, ctx=None)
 
def BitVec (name, bv, ctx=None)
 
def BitVecs (names, bv, ctx=None)
 
def Concat (args)
 
def Extract (high, low, a)
 
def ULE (a, b)
 
def ULT (a, b)
 
def UGE (a, b)
 
def UGT (a, b)
 
def UDiv (a, b)
 
def URem (a, b)
 
def SRem (a, b)
 
def LShR (a, b)
 
def RotateLeft (a, b)
 
def RotateRight (a, b)
 
def SignExt (n, a)
 
def ZeroExt (n, a)
 
def RepeatBitVec (n, a)
 
def BVRedAnd (a)
 
def BVRedOr (a)
 
def BVAddNoOverflow (a, b, signed)
 
def BVAddNoUnderflow (a, b)
 
def BVSubNoOverflow (a, b)
 
def BVSubNoUnderflow (a, b, signed)
 
def BVSDivNoOverflow (a, b)
 
def BVSNegNoOverflow (a)
 
def BVMulNoOverflow (a, b, signed)
 
def BVMulNoUnderflow (a, b)
 
def is_array (a)
 
def is_const_array (a)
 
def is_K (a)
 
def is_map (a)
 
def is_default (a)
 
def get_map_func (a)
 
def ArraySort (d, r)
 
def Array (name, dom, rng)
 
def Update (a, i, v)
 
def Default (a)
 
def Store (a, i, v)
 
def Select (a, i)
 
def Map (f, args)
 
def K (dom, v)
 
def Ext (a, b)
 
def is_select (a)
 
def is_store (a)
 
def CreateDatatypes (ds)
 
def EnumSort (name, values, ctx=None)
 
def args2params (arguments, keywords, ctx=None)
 
def is_as_array (n)
 
def get_as_array_func (n)
 
def SolverFor (logic, ctx=None)
 
def SimpleSolver (ctx=None)
 
def FiniteDomainSort (name, sz, ctx=None)
 
def is_finite_domain_sort (s)
 
def is_finite_domain (a)
 
def FiniteDomainVal (val, sort, ctx=None)
 
def is_finite_domain_value (a)
 
def AndThen (ts, ks)
 
def Then (ts, ks)
 
def OrElse (ts, ks)
 
def ParOr (ts, ks)
 
def ParThen (t1, t2, ctx=None)
 
def ParAndThen (t1, t2, ctx=None)
 
def With (t, args, keys)
 
def WithParams (t, p)
 
def Repeat (t, max=4294967295, ctx=None)
 
def TryFor (t, ms, ctx=None)
 
def tactics (ctx=None)
 
def tactic_description (name, ctx=None)
 
def describe_tactics ()
 
def is_probe (p)
 
def probes (ctx=None)
 
def probe_description (name, ctx=None)
 
def describe_probes ()
 
def FailIf (p, ctx=None)
 
def When (p, t, ctx=None)
 
def Cond (p, t1, t2, ctx=None)
 
def simplify (a, arguments, keywords)
 Utils. More...
 
def help_simplify ()
 
def simplify_param_descrs ()
 
def substitute (t, m)
 
def substitute_vars (t, m)
 
def Sum (args)
 
def Product (args)
 
def AtMost (args)
 
def AtLeast (args)
 
def PbLe (args, k)
 
def PbGe (args, k)
 
def PbEq (args, k, ctx=None)
 
def solve (args, keywords)
 
def solve_using (s, args, keywords)
 
def prove (claim, keywords)
 
def parse_smt2_string (s, sorts={}, decls={}, ctx=None)
 
def parse_smt2_file (f, sorts={}, decls={}, ctx=None)
 
def Interpolant (a, ctx=None)
 
def tree_interpolant (pat, p=None, ctx=None)
 
def binary_interpolant (a, b, p=None, ctx=None)
 
def sequence_interpolant (v, p=None, ctx=None)
 
def get_default_rounding_mode (ctx=None)
 
def set_default_rounding_mode (rm, ctx=None)
 
def get_default_fp_sort (ctx=None)
 
def set_default_fp_sort (ebits, sbits, ctx=None)
 
def Float16 (ctx=None)
 
def FloatHalf (ctx=None)
 
def Float32 (ctx=None)
 
def FloatSingle (ctx=None)
 
def Float64 (ctx=None)
 
def FloatDouble (ctx=None)
 
def Float128 (ctx=None)
 
def FloatQuadruple (ctx=None)
 
def is_fp_sort (s)
 
def is_fprm_sort (s)
 
def RoundNearestTiesToEven (ctx=None)
 
def RNE (ctx=None)
 
def RoundNearestTiesToAway (ctx=None)
 
def RNA (ctx=None)
 
def RoundTowardPositive (ctx=None)
 
def RTP (ctx=None)
 
def RoundTowardNegative (ctx=None)
 
def RTN (ctx=None)
 
def RoundTowardZero (ctx=None)
 
def RTZ (ctx=None)
 
def is_fprm (a)
 
def is_fprm_value (a)
 
def is_fp (a)
 
def is_fp_value (a)
 
def FPSort (ebits, sbits, ctx=None)
 
def fpNaN (s)
 
def fpPlusInfinity (s)
 
def fpMinusInfinity (s)
 
def fpInfinity (s, negative)
 
def fpPlusZero (s)
 
def fpMinusZero (s)
 
def fpZero (s, negative)
 
def FPVal (sig, exp=None, fps=None, ctx=None)
 
def FP (name, fpsort, ctx=None)
 
def FPs (names, fpsort, ctx=None)
 
def fpAbs (a, ctx=None)
 
def fpNeg (a, ctx=None)
 
def fpAdd (rm, a, b, ctx=None)
 
def fpSub (rm, a, b, ctx=None)
 
def fpMul (rm, a, b, ctx=None)
 
def fpDiv (rm, a, b, ctx=None)
 
def fpRem (a, b, ctx=None)
 
def fpMin (a, b, ctx=None)
 
def fpMax (a, b, ctx=None)
 
def fpFMA (rm, a, b, c, ctx=None)
 
def fpSqrt (rm, a, ctx=None)
 
def fpRoundToIntegral (rm, a, ctx=None)
 
def fpIsNaN (a, ctx=None)
 
def fpIsInf (a, ctx=None)
 
def fpIsZero (a, ctx=None)
 
def fpIsNormal (a, ctx=None)
 
def fpIsSubnormal (a, ctx=None)
 
def fpIsNegative (a, ctx=None)
 
def fpIsPositive (a, ctx=None)
 
def fpLT (a, b, ctx=None)
 
def fpLEQ (a, b, ctx=None)
 
def fpGT (a, b, ctx=None)
 
def fpGEQ (a, b, ctx=None)
 
def fpEQ (a, b, ctx=None)
 
def fpNEQ (a, b, ctx=None)
 
def fpFP (sgn, exp, sig, ctx=None)
 
def fpToFP (a1, a2=None, a3=None, ctx=None)
 
def fpBVToFP (v, sort, ctx=None)
 
def fpFPToFP (rm, v, sort, ctx=None)
 
def fpRealToFP (rm, v, sort, ctx=None)
 
def fpSignedToFP (rm, v, sort, ctx=None)
 
def fpUnsignedToFP (rm, v, sort, ctx=None)
 
def fpToFPUnsigned (rm, x, s, ctx=None)
 
def fpToSBV (rm, x, s, ctx=None)
 
def fpToUBV (rm, x, s, ctx=None)
 
def fpToReal (x, ctx=None)
 
def fpToIEEEBV (x, ctx=None)
 
def StringSort (ctx=None)
 
def SeqSort (s)
 
def is_seq (a)
 
def is_string (a)
 
def is_string_value (a)
 
def StringVal (s, ctx=None)
 
def String (name, ctx=None)
 
def SubString (s, offset, length)
 
def SubSeq (s, offset, length)
 
def Strings (names, ctx=None)
 
def Empty (s)
 
def Full (s)
 
def Unit (a)
 
def PrefixOf (a, b)
 
def SuffixOf (a, b)
 
def Contains (a, b)
 
def Replace (s, src, dst)
 
def IndexOf (s, substr)
 
def IndexOf (s, substr, offset)
 
def Length (s)
 
def StrToInt (s)
 
def IntToStr (s)
 
def Re (s, ctx=None)
 
def ReSort (s)
 
def is_re (s)
 
def InRe (s, re)
 
def Union (args)
 
def Plus (re)
 
def Option (re)
 
def Complement (re)
 
def Star (re)
 
def Loop (re, lo, hi=0)
 

Variables

 sat = CheckSatResult(Z3_L_TRUE)
 
 unsat = CheckSatResult(Z3_L_FALSE)
 
 unknown = CheckSatResult(Z3_L_UNDEF)
 

Function Documentation

§ And()

def z3py.And (   args)
Create a Z3 and-expression or and-probe.

>>> p, q, r = Bools('p q r')
>>> And(p, q, r)
And(p, q, r)
>>> P = BoolVector('p', 5)
>>> And(P)
And(p__0, p__1, p__2, p__3, p__4)

Definition at line 1592 of file z3py.py.

Referenced by Fixedpoint.add_rule(), Goal.as_expr(), Bool(), Bools(), BoolVector(), Fixedpoint.query(), Fixedpoint.query_from_lvl(), tree_interpolant(), and Fixedpoint.update_rule().

1592 def And(*args):
1593  """Create a Z3 and-expression or and-probe.
1594 
1595  >>> p, q, r = Bools('p q r')
1596  >>> And(p, q, r)
1597  And(p, q, r)
1598  >>> P = BoolVector('p', 5)
1599  >>> And(P)
1600  And(p__0, p__1, p__2, p__3, p__4)
1601  """
1602  last_arg = None
1603  if len(args) > 0:
1604  last_arg = args[len(args)-1]
1605  if isinstance(last_arg, Context):
1606  ctx = args[len(args)-1]
1607  args = args[:len(args)-1]
1608  elif len(args) == 1 and isinstance(args[0], AstVector):
1609  ctx = args[0].ctx
1610  args = [a for a in args[0]]
1611  else:
1612  ctx = main_ctx()
1613  args = _get_args(args)
1614  ctx_args = _ctx_from_ast_arg_list(args, ctx)
1615  if __debug__:
1616  _z3_assert(ctx_args is None or ctx_args == ctx, "context mismatch")
1617  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1618  if _has_probe(args):
1619  return _probe_and(args, ctx)
1620  else:
1621  args = _coerce_expr_list(args, ctx)
1622  _args, sz = _to_ast_array(args)
1623  return BoolRef(Z3_mk_and(ctx.ref(), sz, _args), ctx)
1624 
def And(args)
Definition: z3py.py:1592
def main_ctx()
Definition: z3py.py:203
Z3_ast Z3_API Z3_mk_and(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] and ... and args[num_args-1].

§ AndThen()

def z3py.AndThen (   ts,
  ks 
)
Return a tactic that applies the tactics in `*ts` in sequence.

>>> x, y = Ints('x y')
>>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
>>> t(And(x == 0, y > x + 1))
[[Not(y <= 1)]]
>>> t(And(x == 0, y > x + 1)).as_expr()
Not(y <= 1)

Definition at line 7358 of file z3py.py.

Referenced by Then().

7358 def AndThen(*ts, **ks):
7359  """Return a tactic that applies the tactics in `*ts` in sequence.
7360 
7361  >>> x, y = Ints('x y')
7362  >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
7363  >>> t(And(x == 0, y > x + 1))
7364  [[Not(y <= 1)]]
7365  >>> t(And(x == 0, y > x + 1)).as_expr()
7366  Not(y <= 1)
7367  """
7368  if __debug__:
7369  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7370  ctx = ks.get('ctx', None)
7371  num = len(ts)
7372  r = ts[0]
7373  for i in range(num - 1):
7374  r = _and_then(r, ts[i+1], ctx)
7375  return r
7376 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def AndThen(ts, ks)
Definition: z3py.py:7358

§ append_log()

def z3py.append_log (   s)
Append user-defined string to interaction log. 

Definition at line 97 of file z3py.py.

97 def append_log(s):
98  """Append user-defined string to interaction log. """
99  Z3_append_log(s)
100 
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.
def append_log(s)
Definition: z3py.py:97

§ args2params()

def z3py.args2params (   arguments,
  keywords,
  ctx = None 
)
Convert python arguments into a Z3_params object.
A ':' is added to the keywords, and '_' is replaced with '-'

>>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
(params model true relevancy 2 elim_and true)

Definition at line 4766 of file z3py.py.

Referenced by Tactic.apply(), Fixedpoint.set(), Optimize.set(), simplify(), and With().

4766 def args2params(arguments, keywords, ctx=None):
4767  """Convert python arguments into a Z3_params object.
4768  A ':' is added to the keywords, and '_' is replaced with '-'
4769 
4770  >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
4771  (params model true relevancy 2 elim_and true)
4772  """
4773  if __debug__:
4774  _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
4775  prev = None
4776  r = ParamsRef(ctx)
4777  for a in arguments:
4778  if prev is None:
4779  prev = a
4780  else:
4781  r.set(prev, a)
4782  prev = None
4783  for k in keywords:
4784  v = keywords[k]
4785  r.set(k, v)
4786  return r
4787 
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:4766

§ Array()

def z3py.Array (   name,
  dom,
  rng 
)
Return an array constant named `name` with the given domain and range sorts.

>>> a = Array('a', IntSort(), IntSort())
>>> a.sort()
Array(Int, Int)
>>> a[0]
a[0]

Definition at line 4242 of file z3py.py.

Referenced by ArrayRef.__getitem__(), ArraySort(), ArrayRef.domain(), get_map_func(), is_array(), is_const_array(), is_K(), is_map(), is_select(), is_store(), K(), Map(), ArrayRef.range(), Select(), ArrayRef.sort(), Store(), and Update().

4242 def Array(name, dom, rng):
4243  """Return an array constant named `name` with the given domain and range sorts.
4244 
4245  >>> a = Array('a', IntSort(), IntSort())
4246  >>> a.sort()
4247  Array(Int, Int)
4248  >>> a[0]
4249  a[0]
4250  """
4251  s = ArraySort(dom, rng)
4252  ctx = s.ctx
4253  return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4254 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:101
def Array(name, dom, rng)
Definition: z3py.py:4242
def ArraySort(d, r)
Definition: z3py.py:4221

§ ArraySort()

def z3py.ArraySort (   d,
  r 
)
Return the Z3 array sort with the given domain and range sorts.

>>> A = ArraySort(IntSort(), BoolSort())
>>> A
Array(Int, Bool)
>>> A.domain()
Int
>>> A.range()
Bool
>>> AA = ArraySort(IntSort(), A)
>>> AA
Array(Int, Array(Int, Bool))

Definition at line 4221 of file z3py.py.

Referenced by ArraySortRef.domain(), Context.mkArraySort(), ArraySortRef.range(), and Sort.translate().

4221 def ArraySort(d, r):
4222  """Return the Z3 array sort with the given domain and range sorts.
4223 
4224  >>> A = ArraySort(IntSort(), BoolSort())
4225  >>> A
4226  Array(Int, Bool)
4227  >>> A.domain()
4228  Int
4229  >>> A.range()
4230  Bool
4231  >>> AA = ArraySort(IntSort(), A)
4232  >>> AA
4233  Array(Int, Array(Int, Bool))
4234  """
4235  if __debug__:
4236  _z3_assert(is_sort(d), "Z3 sort expected")
4237  _z3_assert(is_sort(r), "Z3 sort expected")
4238  _z3_assert(d.ctx == r.ctx, "Context mismatch")
4239  ctx = d.ctx
4240  return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4241 
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
def is_sort(s)
Definition: z3py.py:575
def ArraySort(d, r)
Definition: z3py.py:4221

§ AtLeast()

def z3py.AtLeast (   args)
Create an at-most Pseudo-Boolean k constraint.

>>> a, b, c = Bools('a b c')
>>> f = AtLeast(a, b, c, 2)

Definition at line 7939 of file z3py.py.

7939 def AtLeast(*args):
7940  """Create an at-most Pseudo-Boolean k constraint.
7941 
7942  >>> a, b, c = Bools('a b c')
7943  >>> f = AtLeast(a, b, c, 2)
7944  """
7945  args = _get_args(args)
7946  if __debug__:
7947  _z3_assert(len(args) > 1, "Non empty list of arguments expected")
7948  ctx = _ctx_from_ast_arg_list(args)
7949  if __debug__:
7950  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
7951  args1 = _coerce_expr_list(args[:-1], ctx)
7952  k = args[-1]
7953  _args, sz = _to_ast_array(args1)
7954  return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
7955 
7956 
def AtLeast(args)
Definition: z3py.py:7939
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.

§ AtMost()

def z3py.AtMost (   args)
Create an at-most Pseudo-Boolean k constraint.

>>> a, b, c = Bools('a b c')
>>> f = AtMost(a, b, c, 2)

Definition at line 7922 of file z3py.py.

7922 def AtMost(*args):
7923  """Create an at-most Pseudo-Boolean k constraint.
7924 
7925  >>> a, b, c = Bools('a b c')
7926  >>> f = AtMost(a, b, c, 2)
7927  """
7928  args = _get_args(args)
7929  if __debug__:
7930  _z3_assert(len(args) > 1, "Non empty list of arguments expected")
7931  ctx = _ctx_from_ast_arg_list(args)
7932  if __debug__:
7933  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
7934  args1 = _coerce_expr_list(args[:-1], ctx)
7935  k = args[-1]
7936  _args, sz = _to_ast_array(args1)
7937  return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
7938 
def AtMost(args)
Definition: z3py.py:7922
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.

§ binary_interpolant()

def z3py.binary_interpolant (   a,
  b,
  p = None,
  ctx = None 
)
Compute an interpolant for a binary conjunction.

If a & b is unsatisfiable, returns an interpolant for a & b.
This is a formula phi such that

1) a implies phi
2) b implies not phi
3) All the uninterpreted symbols of phi occur in both a and b.

If a & b is satisfiable, raises an object of class ModelRef
that represents a model of a &b.

If neither a proof of unsatisfiability nor a model is obtained
(for example, because of a timeout, or because models are disabled)
then None is returned.

If parameters p are supplied, these are used in creating the
solver that determines satisfiability.

x = Int('x')
print(binary_interpolant(x<0,x>2))
Not(x >= 0)

Definition at line 8304 of file z3py.py.

8304 def binary_interpolant(a,b,p=None,ctx=None):
8305  """Compute an interpolant for a binary conjunction.
8306 
8307  If a & b is unsatisfiable, returns an interpolant for a & b.
8308  This is a formula phi such that
8309 
8310  1) a implies phi
8311  2) b implies not phi
8312  3) All the uninterpreted symbols of phi occur in both a and b.
8313 
8314  If a & b is satisfiable, raises an object of class ModelRef
8315  that represents a model of a &b.
8316 
8317  If neither a proof of unsatisfiability nor a model is obtained
8318  (for example, because of a timeout, or because models are disabled)
8319  then None is returned.
8320 
8321  If parameters p are supplied, these are used in creating the
8322  solver that determines satisfiability.
8323 
8324  x = Int('x')
8325  print(binary_interpolant(x<0,x>2))
8326  Not(x >= 0)
8327  """
8328  f = And(Interpolant(a),b)
8329  ti = tree_interpolant(f,p,ctx)
8330  return ti[0] if ti is not None else None
8331 
def And(args)
Definition: z3py.py:1592
def binary_interpolant(a, b, p=None, ctx=None)
Definition: z3py.py:8304
def Interpolant(a, ctx=None)
Definition: z3py.py:8225
def tree_interpolant(pat, p=None, ctx=None)
Definition: z3py.py:8239

§ BitVec()

def z3py.BitVec (   name,
  bv,
  ctx = None 
)
Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
If `ctx=None`, then the global context is used.

>>> x  = BitVec('x', 16)
>>> is_bv(x)
True
>>> x.size()
16
>>> x.sort()
BitVec(16)
>>> word = BitVecSort(16)
>>> x2 = BitVec('x', word)
>>> eq(x, x2)
True

Definition at line 3623 of file z3py.py.

Referenced by BitVecRef.__add__(), BitVecRef.__and__(), BitVecRef.__div__(), BitVecRef.__invert__(), BitVecRef.__mod__(), BitVecRef.__mul__(), BitVecRef.__neg__(), BitVecRef.__or__(), BitVecRef.__pos__(), BitVecRef.__radd__(), BitVecRef.__rand__(), BitVecRef.__rdiv__(), BitVecRef.__rlshift__(), BitVecRef.__rmod__(), BitVecRef.__rmul__(), BitVecRef.__ror__(), BitVecRef.__rrshift__(), BitVecRef.__rsub__(), BitVecRef.__rxor__(), BitVecRef.__sub__(), BitVecRef.__xor__(), BitVecs(), BitVecSort(), BV2Int(), Extract(), is_bv(), is_bv_value(), RepeatBitVec(), SignExt(), BitVecRef.size(), BitVecRef.sort(), SRem(), UDiv(), URem(), and ZeroExt().

3623 def BitVec(name, bv, ctx=None):
3624  """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
3625  If `ctx=None`, then the global context is used.
3626 
3627  >>> x = BitVec('x', 16)
3628  >>> is_bv(x)
3629  True
3630  >>> x.size()
3631  16
3632  >>> x.sort()
3633  BitVec(16)
3634  >>> word = BitVecSort(16)
3635  >>> x2 = BitVec('x', word)
3636  >>> eq(x, x2)
3637  True
3638  """
3639  if isinstance(bv, BitVecSortRef):
3640  ctx = bv.ctx
3641  else:
3642  ctx = _get_ctx(ctx)
3643  bv = BitVecSort(bv, ctx)
3644  return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
3645 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:101
def BitVec(name, bv, ctx=None)
Definition: z3py.py:3623
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3593

§ BitVecs()

def z3py.BitVecs (   names,
  bv,
  ctx = None 
)
Return a tuple of bit-vector constants of size bv.

>>> x, y, z = BitVecs('x y z', 16)
>>> x.size()
16
>>> x.sort()
BitVec(16)
>>> Sum(x, y, z)
0 + x + y + z
>>> Product(x, y, z)
1*x*y*z
>>> simplify(Product(x, y, z))
x*y*z

Definition at line 3646 of file z3py.py.

Referenced by BitVecRef.__ge__(), BitVecRef.__gt__(), BitVecRef.__le__(), BitVecRef.__lshift__(), BitVecRef.__lt__(), BitVecRef.__rshift__(), LShR(), RotateLeft(), RotateRight(), UGE(), UGT(), ULE(), and ULT().

3646 def BitVecs(names, bv, ctx=None):
3647  """Return a tuple of bit-vector constants of size bv.
3648 
3649  >>> x, y, z = BitVecs('x y z', 16)
3650  >>> x.size()
3651  16
3652  >>> x.sort()
3653  BitVec(16)
3654  >>> Sum(x, y, z)
3655  0 + x + y + z
3656  >>> Product(x, y, z)
3657  1*x*y*z
3658  >>> simplify(Product(x, y, z))
3659  x*y*z
3660  """
3661  ctx = _get_ctx(ctx)
3662  if isinstance(names, str):
3663  names = names.split(" ")
3664  return [BitVec(name, bv, ctx) for name in names]
3665 
def BitVec(name, bv, ctx=None)
Definition: z3py.py:3623
def BitVecs(names, bv, ctx=None)
Definition: z3py.py:3646

§ BitVecSort()

def z3py.BitVecSort (   sz,
  ctx = None 
)
Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.

>>> Byte = BitVecSort(8)
>>> Word = BitVecSort(16)
>>> Byte
BitVec(8)
>>> x = Const('x', Byte)
>>> eq(x, BitVec('x', 8))
True

Definition at line 3593 of file z3py.py.

Referenced by BitVec(), BitVecSortRef.cast(), fpSignedToFP(), fpToFP(), fpToSBV(), fpToUBV(), fpUnsignedToFP(), is_bv_sort(), Context.mkBitVecSort(), BitVecSortRef.size(), BitVecRef.sort(), and Sort.translate().

3593 def BitVecSort(sz, ctx=None):
3594  """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3595 
3596  >>> Byte = BitVecSort(8)
3597  >>> Word = BitVecSort(16)
3598  >>> Byte
3599  BitVec(8)
3600  >>> x = Const('x', Byte)
3601  >>> eq(x, BitVec('x', 8))
3602  True
3603  """
3604  ctx = _get_ctx(ctx)
3605  return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
3606 
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3593

§ BitVecVal()

def z3py.BitVecVal (   val,
  bv,
  ctx = None 
)
Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.

>>> v = BitVecVal(10, 32)
>>> v
10
>>> print("0x%.8x" % v.as_long())
0x0000000a

Definition at line 3607 of file z3py.py.

Referenced by BitVecRef.__lshift__(), BitVecRef.__rshift__(), BitVecNumRef.as_long(), BitVecNumRef.as_signed_long(), Concat(), fpBVToFP(), fpFP(), fpSignedToFP(), fpToFP(), fpUnsignedToFP(), is_bv_value(), LShR(), RepeatBitVec(), SignExt(), and ZeroExt().

3607 def BitVecVal(val, bv, ctx=None):
3608  """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3609 
3610  >>> v = BitVecVal(10, 32)
3611  >>> v
3612  10
3613  >>> print("0x%.8x" % v.as_long())
3614  0x0000000a
3615  """
3616  if is_bv_sort(bv):
3617  ctx = bv.ctx
3618  return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
3619  else:
3620  ctx = _get_ctx(ctx)
3621  return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
3622 
def BitVecVal(val, bv, ctx=None)
Definition: z3py.py:3607
def is_bv_sort(s)
Definition: z3py.py:3075
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3593
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.

§ Bool()

def z3py.Bool (   name,
  ctx = None 
)
Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.

>>> p = Bool('p')
>>> q = Bool('q')
>>> And(p, q)
And(p, q)

Definition at line 1484 of file z3py.py.

Referenced by Solver.assert_and_track(), and Not().

1484 def Bool(name, ctx=None):
1485  """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1486 
1487  >>> p = Bool('p')
1488  >>> q = Bool('q')
1489  >>> And(p, q)
1490  And(p, q)
1491  """
1492  ctx = _get_ctx(ctx)
1493  return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
1494 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:101
def Bool(name, ctx=None)
Definition: z3py.py:1484
def BoolSort(ctx=None)
Definition: z3py.py:1449

§ Bools()

def z3py.Bools (   names,
  ctx = None 
)
Return a tuple of Boolean constants.

`names` is a single string containing all names separated by blank spaces.
If `ctx=None`, then the global context is used.

>>> p, q, r = Bools('p q r')
>>> And(p, Or(q, r))
And(p, Or(q, r))

Definition at line 1495 of file z3py.py.

Referenced by And(), Solver.consequences(), Implies(), Or(), Solver.unsat_core(), and Xor().

1495 def Bools(names, ctx=None):
1496  """Return a tuple of Boolean constants.
1497 
1498  `names` is a single string containing all names separated by blank spaces.
1499  If `ctx=None`, then the global context is used.
1500 
1501  >>> p, q, r = Bools('p q r')
1502  >>> And(p, Or(q, r))
1503  And(p, Or(q, r))
1504  """
1505  ctx = _get_ctx(ctx)
1506  if isinstance(names, str):
1507  names = names.split(" ")
1508  return [Bool(name, ctx) for name in names]
1509 
def Bools(names, ctx=None)
Definition: z3py.py:1495
def Bool(name, ctx=None)
Definition: z3py.py:1484

§ BoolSort()

def z3py.BoolSort (   ctx = None)
Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.

>>> BoolSort()
Bool
>>> p = Const('p', BoolSort())
>>> is_bool(p)
True
>>> r = Function('r', IntSort(), IntSort(), BoolSort())
>>> r(0, 1)
r(0, 1)
>>> is_bool(r(0, 1))
True

Definition at line 1449 of file z3py.py.

Referenced by ArrayRef.__getitem__(), ArraySort(), Fixedpoint.assert_exprs(), ArraySortRef.domain(), ArrayRef.domain(), Context.getBoolSort(), If(), IntSort(), is_arith_sort(), Context.mkBoolSort(), ArraySortRef.range(), ArrayRef.range(), ArrayRef.sort(), and Sort.translate().

1449 def BoolSort(ctx=None):
1450  """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1451 
1452  >>> BoolSort()
1453  Bool
1454  >>> p = Const('p', BoolSort())
1455  >>> is_bool(p)
1456  True
1457  >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1458  >>> r(0, 1)
1459  r(0, 1)
1460  >>> is_bool(r(0, 1))
1461  True
1462  """
1463  ctx = _get_ctx(ctx)
1464  return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
1465 
def is_bool(a)
Definition: z3py.py:1349
def BoolSort(ctx=None)
Definition: z3py.py:1449

§ BoolVal()

def z3py.BoolVal (   val,
  ctx = None 
)
Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.

>>> BoolVal(True)
True
>>> is_true(BoolVal(True))
True
>>> is_true(True)
False
>>> is_false(BoolVal(False))
True

Definition at line 1466 of file z3py.py.

Referenced by ApplyResult.as_expr(), BoolSortRef.cast(), Re(), and Solver.to_smt2().

1466 def BoolVal(val, ctx=None):
1467  """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1468 
1469  >>> BoolVal(True)
1470  True
1471  >>> is_true(BoolVal(True))
1472  True
1473  >>> is_true(True)
1474  False
1475  >>> is_false(BoolVal(False))
1476  True
1477  """
1478  ctx = _get_ctx(ctx)
1479  if val == False:
1480  return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1481  else:
1482  return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1483 
Z3_ast Z3_API Z3_mk_true(Z3_context c)
Create an AST node representing true.
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.
def BoolVal(val, ctx=None)
Definition: z3py.py:1466

§ BoolVector()

def z3py.BoolVector (   prefix,
  sz,
  ctx = None 
)
Return a list of Boolean constants of size `sz`.

The constants are named using the given prefix.
If `ctx=None`, then the global context is used.

>>> P = BoolVector('p', 3)
>>> P
[p__0, p__1, p__2]
>>> And(P)
And(p__0, p__1, p__2)

Definition at line 1510 of file z3py.py.

Referenced by And(), and Or().

1510 def BoolVector(prefix, sz, ctx=None):
1511  """Return a list of Boolean constants of size `sz`.
1512 
1513  The constants are named using the given prefix.
1514  If `ctx=None`, then the global context is used.
1515 
1516  >>> P = BoolVector('p', 3)
1517  >>> P
1518  [p__0, p__1, p__2]
1519  >>> And(P)
1520  And(p__0, p__1, p__2)
1521  """
1522  return [ Bool('%s__%s' % (prefix, i)) for i in range(sz) ]
1523 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def BoolVector(prefix, sz, ctx=None)
Definition: z3py.py:1510
def Bool(name, ctx=None)
Definition: z3py.py:1484

§ BV2Int()

def z3py.BV2Int (   a,
  is_signed = False 
)
Return the Z3 expression BV2Int(a).

>>> b = BitVec('b', 3)
>>> BV2Int(b).sort()
Int
>>> x = Int('x')
>>> x > BV2Int(b)
x > BV2Int(b)
>>> x > BV2Int(b, is_signed=False)
x > BV2Int(b)
>>> x > BV2Int(b, is_signed=True)
x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
>>> solve(x > BV2Int(b), b == 1, x < 3)
[b = 1, x = 2]

Definition at line 3563 of file z3py.py.

3563 def BV2Int(a, is_signed=False):
3564  """Return the Z3 expression BV2Int(a).
3565 
3566  >>> b = BitVec('b', 3)
3567  >>> BV2Int(b).sort()
3568  Int
3569  >>> x = Int('x')
3570  >>> x > BV2Int(b)
3571  x > BV2Int(b)
3572  >>> x > BV2Int(b, is_signed=False)
3573  x > BV2Int(b)
3574  >>> x > BV2Int(b, is_signed=True)
3575  x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3576  >>> solve(x > BV2Int(b), b == 1, x < 3)
3577  [b = 1, x = 2]
3578  """
3579  if __debug__:
3580  _z3_assert(is_bv(a), "Z3 bit-vector expression expected")
3581  ctx = a.ctx
3582 
3583  return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
3584 
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast t1, Z3_bool is_signed)
Create an integer from the bit-vector argument t1. If is_signed is false, then the bit-vector t1 is t...
def BV2Int(a, is_signed=False)
Definition: z3py.py:3563
def is_bv(a)
Definition: z3py.py:3536

§ BVAddNoOverflow()

def z3py.BVAddNoOverflow (   a,
  b,
  signed 
)
A predicate the determines that bit-vector addition does not overflow

Definition at line 4018 of file z3py.py.

4018 def BVAddNoOverflow(a, b, signed):
4019  """A predicate the determines that bit-vector addition does not overflow"""
4020  _check_bv_args(a, b)
4021  a, b = _coerce_exprs(a, b)
4022  return BoolRef(Z3_mk_bvadd_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4023 
def BVAddNoOverflow(a, b, signed)
Definition: z3py.py:4018
Z3_ast Z3_API Z3_mk_bvadd_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_bool is_signed)
Create a predicate that checks that the bit-wise addition of t1 and t2 does not overflow.

§ BVAddNoUnderflow()

def z3py.BVAddNoUnderflow (   a,
  b 
)
A predicate the determines that signed bit-vector addition does not underflow

Definition at line 4024 of file z3py.py.

4024 def BVAddNoUnderflow(a, b):
4025  """A predicate the determines that signed bit-vector addition does not underflow"""
4026  _check_bv_args(a, b)
4027  a, b = _coerce_exprs(a, b)
4028  return BoolRef(Z3_mk_bvadd_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4029 
def BVAddNoUnderflow(a, b)
Definition: z3py.py:4024
Z3_ast Z3_API Z3_mk_bvadd_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed addition of t1 and t2 does not underflow...

§ BVMulNoOverflow()

def z3py.BVMulNoOverflow (   a,
  b,
  signed 
)
A predicate the determines that bit-vector multiplication does not overflow

Definition at line 4055 of file z3py.py.

4055 def BVMulNoOverflow(a, b, signed):
4056  """A predicate the determines that bit-vector multiplication does not overflow"""
4057  _check_bv_args(a, b)
4058  a, b = _coerce_exprs(a, b)
4059  return BoolRef(Z3_mk_bvmul_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4060 
4061 
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_bool is_signed)
Create a predicate that checks that the bit-wise multiplication of t1 and t2 does not overflow...
def BVMulNoOverflow(a, b, signed)
Definition: z3py.py:4055

§ BVMulNoUnderflow()

def z3py.BVMulNoUnderflow (   a,
  b 
)
A predicate the determines that bit-vector signed multiplication does not underflow

Definition at line 4062 of file z3py.py.

4062 def BVMulNoUnderflow(a, b):
4063  """A predicate the determines that bit-vector signed multiplication does not underflow"""
4064  _check_bv_args(a, b)
4065  a, b = _coerce_exprs(a, b)
4066  return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4067 
4068 
4069 
Z3_ast Z3_API Z3_mk_bvmul_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed multiplication of t1 and t2 does not underflo...
def BVMulNoUnderflow(a, b)
Definition: z3py.py:4062

§ BVRedAnd()

def z3py.BVRedAnd (   a)
Return the reduction-and expression of `a`.

Definition at line 4006 of file z3py.py.

4006 def BVRedAnd(a):
4007  """Return the reduction-and expression of `a`."""
4008  if __debug__:
4009  _z3_assert(is_bv(a), "First argument must be a Z3 Bitvector expression")
4010  return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
4011 
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.
def BVRedAnd(a)
Definition: z3py.py:4006
def is_bv(a)
Definition: z3py.py:3536

§ BVRedOr()

def z3py.BVRedOr (   a)
Return the reduction-or expression of `a`.

Definition at line 4012 of file z3py.py.

4012 def BVRedOr(a):
4013  """Return the reduction-or expression of `a`."""
4014  if __debug__:
4015  _z3_assert(is_bv(a), "First argument must be a Z3 Bitvector expression")
4016  return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
4017 
def BVRedOr(a)
Definition: z3py.py:4012
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
def is_bv(a)
Definition: z3py.py:3536

§ BVSDivNoOverflow()

def z3py.BVSDivNoOverflow (   a,
  b 
)
A predicate the determines that bit-vector signed division does not overflow

Definition at line 4043 of file z3py.py.

4043 def BVSDivNoOverflow(a, b):
4044  """A predicate the determines that bit-vector signed division does not overflow"""
4045  _check_bv_args(a, b)
4046  a, b = _coerce_exprs(a, b)
4047  return BoolRef(Z3_mk_bvsdiv_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4048 
def BVSDivNoOverflow(a, b)
Definition: z3py.py:4043
Z3_ast Z3_API Z3_mk_bvsdiv_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed division of t1 and t2 does not overflow...

§ BVSNegNoOverflow()

def z3py.BVSNegNoOverflow (   a)
A predicate the determines that bit-vector unary negation does not overflow

Definition at line 4049 of file z3py.py.

4049 def BVSNegNoOverflow(a):
4050  """A predicate the determines that bit-vector unary negation does not overflow"""
4051  if __debug__:
4052  _z3_assert(is_bv(a), "Argument should be a bit-vector")
4053  return BoolRef(Z3_mk_bvneg_no_overflow(a.ctx_ref(), a.as_ast()), a.ctx)
4054 
Z3_ast Z3_API Z3_mk_bvneg_no_overflow(Z3_context c, Z3_ast t1)
Check that bit-wise negation does not overflow when t1 is interpreted as a signed bit-vector...
def BVSNegNoOverflow(a)
Definition: z3py.py:4049
def is_bv(a)
Definition: z3py.py:3536

§ BVSubNoOverflow()

def z3py.BVSubNoOverflow (   a,
  b 
)
A predicate the determines that bit-vector subtraction does not overflow

Definition at line 4030 of file z3py.py.

4030 def BVSubNoOverflow(a, b):
4031  """A predicate the determines that bit-vector subtraction does not overflow"""
4032  _check_bv_args(a, b)
4033  a, b = _coerce_exprs(a, b)
4034  return BoolRef(Z3_mk_bvsub_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4035 
4036 
def BVSubNoOverflow(a, b)
Definition: z3py.py:4030
Z3_ast Z3_API Z3_mk_bvsub_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed subtraction of t1 and t2 does not overflow...

§ BVSubNoUnderflow()

def z3py.BVSubNoUnderflow (   a,
  b,
  signed 
)
A predicate the determines that bit-vector subtraction does not underflow

Definition at line 4037 of file z3py.py.

4037 def BVSubNoUnderflow(a, b, signed):
4038  """A predicate the determines that bit-vector subtraction does not underflow"""
4039  _check_bv_args(a, b)
4040  a, b = _coerce_exprs(a, b)
4041  return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4042 
def BVSubNoUnderflow(a, b, signed)
Definition: z3py.py:4037
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_bool is_signed)
Create a predicate that checks that the bit-wise subtraction of t1 and t2 does not underflow...

§ Cbrt()

def z3py.Cbrt (   a,
  ctx = None 
)
Return a Z3 expression which represents the cubic root of a.

>>> x = Real('x')
>>> Cbrt(x)
x**(1/3)

Definition at line 3025 of file z3py.py.

3025 def Cbrt(a, ctx=None):
3026  """ Return a Z3 expression which represents the cubic root of a.
3027 
3028  >>> x = Real('x')
3029  >>> Cbrt(x)
3030  x**(1/3)
3031  """
3032  if not is_expr(a):
3033  ctx = _get_ctx(ctx)
3034  a = RealVal(a, ctx)
3035  return a ** "1/3"
3036 
def Cbrt(a, ctx=None)
Definition: z3py.py:3025
def RealVal(val, ctx=None)
Definition: z3py.py:2818
def is_expr(a)
Definition: z3py.py:1047

§ Complement()

def z3py.Complement (   re)
Create the complement regular expression.

Definition at line 10090 of file z3py.py.

10090 def Complement(re):
10091  """Create the complement regular expression."""
10092  return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
10093 
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.
def Complement(re)
Definition: z3py.py:10090

§ Concat()

def z3py.Concat (   args)
Create a Z3 bit-vector concatenation expression.

>>> v = BitVecVal(1, 4)
>>> Concat(v, v+1, v)
Concat(Concat(1, 1 + 1), 1)
>>> simplify(Concat(v, v+1, v))
289
>>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
121

Definition at line 3666 of file z3py.py.

Referenced by Contains(), and BitVecRef.size().

3666 def Concat(*args):
3667  """Create a Z3 bit-vector concatenation expression.
3668 
3669  >>> v = BitVecVal(1, 4)
3670  >>> Concat(v, v+1, v)
3671  Concat(Concat(1, 1 + 1), 1)
3672  >>> simplify(Concat(v, v+1, v))
3673  289
3674  >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
3675  121
3676  """
3677  args = _get_args(args)
3678  sz = len(args)
3679  if __debug__:
3680  _z3_assert(sz >= 2, "At least two arguments expected.")
3681 
3682  ctx = None
3683  for a in args:
3684  if is_expr(a):
3685  ctx = a.ctx
3686  break
3687  if is_seq(args[0]) or isinstance(args[0], str):
3688  args = [_coerce_seq(s, ctx) for s in args]
3689  if __debug__:
3690  _z3_assert(all([is_seq(a) for a in args]), "All arguments must be sequence expressions.")
3691  v = (Ast * sz)()
3692  for i in range(sz):
3693  v[i] = args[i].as_ast()
3694  return SeqRef(Z3_mk_seq_concat(ctx.ref(), sz, v), ctx)
3695 
3696  if is_re(args[0]):
3697  if __debug__:
3698  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
3699  v = (Ast * sz)()
3700  for i in range(sz):
3701  v[i] = args[i].as_ast()
3702  return ReRef(Z3_mk_re_concat(ctx.ref(), sz, v), ctx)
3703 
3704  if __debug__:
3705  _z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.")
3706  r = args[0]
3707  for i in range(sz - 1):
3708  r = BitVecRef(Z3_mk_concat(ctx.ref(), r.as_ast(), args[i+1].as_ast()), ctx)
3709  return r
3710 
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
Z3_ast Z3_API Z3_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
def is_re(s)
Definition: z3py.py:10030
def is_expr(a)
Definition: z3py.py:1047
def is_bv(a)
Definition: z3py.py:3536
def Concat(args)
Definition: z3py.py:3666
def is_seq(a)
Definition: z3py.py:9790

§ Cond()

def z3py.Cond (   p,
  t1,
  t2,
  ctx = None 
)
Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.

>>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))

Definition at line 7777 of file z3py.py.

Referenced by If().

7777 def Cond(p, t1, t2, ctx=None):
7778  """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
7779 
7780  >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
7781  """
7782  p = _to_probe(p, ctx)
7783  t1 = _to_tactic(t1, ctx)
7784  t2 = _to_tactic(t2, ctx)
7785  return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
7786 
def Cond(p, t1, t2, ctx=None)
Definition: z3py.py:7777
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluat...

§ Const()

def z3py.Const (   name,
  sort 
)
Create a constant of the given sort.

>>> Const('x', IntSort())
x

Definition at line 1233 of file z3py.py.

Referenced by BitVecSort(), Consts(), FPSort(), IntSort(), RealSort(), and DatatypeSortRef.recognizer().

1233 def Const(name, sort):
1234  """Create a constant of the given sort.
1235 
1236  >>> Const('x', IntSort())
1237  x
1238  """
1239  if __debug__:
1240  _z3_assert(isinstance(sort, SortRef), "Z3 sort expected")
1241  ctx = sort.ctx
1242  return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
1243 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:101
def Const(name, sort)
Definition: z3py.py:1233

§ Consts()

def z3py.Consts (   names,
  sort 
)
Create a several constants of the given sort.

`names` is a string containing the names of all constants to be created.
Blank spaces separate the names of different constants.

>>> x, y, z = Consts('x y z', IntSort())
>>> x + y + z
x + y + z

Definition at line 1244 of file z3py.py.

Referenced by ModelRef.get_sort(), ModelRef.get_universe(), ModelRef.num_sorts(), and ModelRef.sorts().

1244 def Consts(names, sort):
1245  """Create a several constants of the given sort.
1246 
1247  `names` is a string containing the names of all constants to be created.
1248  Blank spaces separate the names of different constants.
1249 
1250  >>> x, y, z = Consts('x y z', IntSort())
1251  >>> x + y + z
1252  x + y + z
1253  """
1254  if isinstance(names, str):
1255  names = names.split(" ")
1256  return [Const(name, sort) for name in names]
1257 
def Consts(names, sort)
Definition: z3py.py:1244
def Const(name, sort)
Definition: z3py.py:1233

§ Contains()

def z3py.Contains (   a,
  b 
)
Check if 'a' contains 'b'
>>> s1 = Contains("abc", "ab")
>>> simplify(s1)
True
>>> s2 = Contains("abc", "bc")
>>> simplify(s2)
True
>>> x, y, z = Strings('x y z')
>>> s3 = Contains(Concat(x,y,z), y)
>>> simplify(s3)
True

Definition at line 9911 of file z3py.py.

9911 def Contains(a, b):
9912  """Check if 'a' contains 'b'
9913  >>> s1 = Contains("abc", "ab")
9914  >>> simplify(s1)
9915  True
9916  >>> s2 = Contains("abc", "bc")
9917  >>> simplify(s2)
9918  True
9919  >>> x, y, z = Strings('x y z')
9920  >>> s3 = Contains(Concat(x,y,z), y)
9921  >>> simplify(s3)
9922  True
9923  """
9924  ctx = _get_ctx2(a, b)
9925  a = _coerce_seq(a, ctx)
9926  b = _coerce_seq(b, ctx)
9927  return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
9928 
9929 
def Contains(a, b)
Definition: z3py.py:9911
Z3_ast Z3_API Z3_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.

§ CreateDatatypes()

def z3py.CreateDatatypes (   ds)
Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.

In the following example we define a Tree-List using two mutually recursive datatypes.

>>> TreeList = Datatype('TreeList')
>>> Tree     = Datatype('Tree')
>>> # Tree has two constructors: leaf and node
>>> Tree.declare('leaf', ('val', IntSort()))
>>> # a node contains a list of trees
>>> Tree.declare('node', ('children', TreeList))
>>> TreeList.declare('nil')
>>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
>>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
>>> Tree.val(Tree.leaf(10))
val(leaf(10))
>>> simplify(Tree.val(Tree.leaf(10)))
10
>>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
>>> n1
node(cons(leaf(10), cons(leaf(20), nil)))
>>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
>>> simplify(n2 == n1)
False
>>> simplify(TreeList.car(Tree.children(n2)) == n1)
True

Definition at line 4501 of file z3py.py.

Referenced by Datatype.create().

4501 def CreateDatatypes(*ds):
4502  """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
4503 
4504  In the following example we define a Tree-List using two mutually recursive datatypes.
4505 
4506  >>> TreeList = Datatype('TreeList')
4507  >>> Tree = Datatype('Tree')
4508  >>> # Tree has two constructors: leaf and node
4509  >>> Tree.declare('leaf', ('val', IntSort()))
4510  >>> # a node contains a list of trees
4511  >>> Tree.declare('node', ('children', TreeList))
4512  >>> TreeList.declare('nil')
4513  >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
4514  >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
4515  >>> Tree.val(Tree.leaf(10))
4516  val(leaf(10))
4517  >>> simplify(Tree.val(Tree.leaf(10)))
4518  10
4519  >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
4520  >>> n1
4521  node(cons(leaf(10), cons(leaf(20), nil)))
4522  >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
4523  >>> simplify(n2 == n1)
4524  False
4525  >>> simplify(TreeList.car(Tree.children(n2)) == n1)
4526  True
4527  """
4528  ds = _get_args(ds)
4529  if __debug__:
4530  _z3_assert(len(ds) > 0, "At least one Datatype must be specified")
4531  _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
4532  _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
4533  _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
4534  ctx = ds[0].ctx
4535  num = len(ds)
4536  names = (Symbol * num)()
4537  out = (Sort * num)()
4538  clists = (ConstructorList * num)()
4539  to_delete = []
4540  for i in range(num):
4541  d = ds[i]
4542  names[i] = to_symbol(d.name, ctx)
4543  num_cs = len(d.constructors)
4544  cs = (Constructor * num_cs)()
4545  for j in range(num_cs):
4546  c = d.constructors[j]
4547  cname = to_symbol(c[0], ctx)
4548  rname = to_symbol(c[1], ctx)
4549  fs = c[2]
4550  num_fs = len(fs)
4551  fnames = (Symbol * num_fs)()
4552  sorts = (Sort * num_fs)()
4553  refs = (ctypes.c_uint * num_fs)()
4554  for k in range(num_fs):
4555  fname = fs[k][0]
4556  ftype = fs[k][1]
4557  fnames[k] = to_symbol(fname, ctx)
4558  if isinstance(ftype, Datatype):
4559  if __debug__:
4560  _z3_assert(ds.count(ftype) == 1, "One and only one occurrence of each datatype is expected")
4561  sorts[k] = None
4562  refs[k] = ds.index(ftype)
4563  else:
4564  if __debug__:
4565  _z3_assert(is_sort(ftype), "Z3 sort expected")
4566  sorts[k] = ftype.ast
4567  refs[k] = 0
4568  cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
4569  to_delete.append(ScopedConstructor(cs[j], ctx))
4570  clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs)
4571  to_delete.append(ScopedConstructorList(clists[i], ctx))
4572  Z3_mk_datatypes(ctx.ref(), num, names, out, clists)
4573  result = []
4574 
4575  for i in range(num):
4576  dref = DatatypeSortRef(out[i], ctx)
4577  num_cs = dref.num_constructors()
4578  for j in range(num_cs):
4579  cref = dref.constructor(j)
4580  cref_name = cref.name()
4581  cref_arity = cref.arity()
4582  if cref.arity() == 0:
4583  cref = cref()
4584  setattr(dref, cref_name, cref)
4585  rref = dref.recognizer(j)
4586  setattr(dref, "is_" + cref_name, rref)
4587  for k in range(cref_arity):
4588  aref = dref.accessor(j, k)
4589  setattr(dref, aref.name(), aref)
4590  result.append(dref)
4591  return tuple(result)
4592 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def to_symbol(s, ctx=None)
Definition: z3py.py:101
Z3_constructor Z3_API Z3_mk_constructor(Z3_context c, Z3_symbol name, Z3_symbol recognizer, unsigned num_fields, Z3_symbol const field_names[], Z3_sort_opt const sorts[], unsigned sort_refs[])
Create a constructor.
def CreateDatatypes(ds)
Definition: z3py.py:4501
def is_sort(s)
Definition: z3py.py:575
void Z3_API Z3_mk_datatypes(Z3_context c, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort sorts[], Z3_constructor_list constructor_lists[])
Create mutually recursive datatypes.
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.

§ DeclareSort()

def z3py.DeclareSort (   name,
  ctx = None 
)
Create a new uninterpreted sort named `name`.

If `ctx=None`, then the new sort is declared in the global Z3Py context.

>>> A = DeclareSort('A')
>>> a = Const('a', A)
>>> b = Const('b', A)
>>> a.sort() == A
True
>>> b.sort() == A
True
>>> a == b
a == b

Definition at line 612 of file z3py.py.

Referenced by ModelRef.get_sort(), ModelRef.get_universe(), ModelRef.num_sorts(), and ModelRef.sorts().

612 def DeclareSort(name, ctx=None):
613  """Create a new uninterpreted sort named `name`.
614 
615  If `ctx=None`, then the new sort is declared in the global Z3Py context.
616 
617  >>> A = DeclareSort('A')
618  >>> a = Const('a', A)
619  >>> b = Const('b', A)
620  >>> a.sort() == A
621  True
622  >>> b.sort() == A
623  True
624  >>> a == b
625  a == b
626  """
627  ctx = _get_ctx(ctx)
628  return SortRef(Z3_mk_uninterpreted_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
629 
def to_symbol(s, ctx=None)
Definition: z3py.py:101
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
def DeclareSort(name, ctx=None)
Definition: z3py.py:612

§ Default()

def z3py.Default (   a)
Return a default value for array expression.
>>> b = K(IntSort(), 1)
>>> prove(Default(b) == 1)
proved

Definition at line 4276 of file z3py.py.

Referenced by is_default().

4276 def Default(a):
4277  """ Return a default value for array expression.
4278  >>> b = K(IntSort(), 1)
4279  >>> prove(Default(b) == 1)
4280  proved
4281  """
4282  if __debug__:
4283  _z3_assert(is_array(a), "First argument must be a Z3 array expression")
4284  return a.default()
4285 
4286 
def is_array(a)
Definition: z3py.py:4144
def Default(a)
Definition: z3py.py:4276

§ describe_probes()

def z3py.describe_probes ( )
Display a (tabular) description of all available probes in Z3.

Definition at line 7707 of file z3py.py.

7707 def describe_probes():
7708  """Display a (tabular) description of all available probes in Z3."""
7709  if in_html_mode():
7710  even = True
7711  print('<table border="1" cellpadding="2" cellspacing="0">')
7712  for p in probes():
7713  if even:
7714  print('<tr style="background-color:#CFCFCF">')
7715  even = False
7716  else:
7717  print('<tr>')
7718  even = True
7719  print('<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(probe_description(p), 40)))
7720  print('</table>')
7721  else:
7722  for p in probes():
7723  print('%s : %s' % (p, probe_description(p)))
7724 
def probes(ctx=None)
Definition: z3py.py:7689
def probe_description(name, ctx=None)
Definition: z3py.py:7699
def describe_probes()
Definition: z3py.py:7707

§ describe_tactics()

def z3py.describe_tactics ( )
Display a (tabular) description of all available tactics in Z3.

Definition at line 7516 of file z3py.py.

7516 def describe_tactics():
7517  """Display a (tabular) description of all available tactics in Z3."""
7518  if in_html_mode():
7519  even = True
7520  print('<table border="1" cellpadding="2" cellspacing="0">')
7521  for t in tactics():
7522  if even:
7523  print('<tr style="background-color:#CFCFCF">')
7524  even = False
7525  else:
7526  print('<tr>')
7527  even = True
7528  print('<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(tactic_description(t), 40)))
7529  print('</table>')
7530  else:
7531  for t in tactics():
7532  print('%s : %s' % (t, tactic_description(t)))
7533 
def tactics(ctx=None)
Definition: z3py.py:7498
def tactic_description(name, ctx=None)
Definition: z3py.py:7508
def describe_tactics()
Definition: z3py.py:7516

§ disable_trace()

def z3py.disable_trace (   msg)

Definition at line 65 of file z3py.py.

65 def disable_trace(msg):
66  Z3_disable_trace(msg)
67 
void Z3_API Z3_disable_trace(Z3_string tag)
Disable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise...
def disable_trace(msg)
Definition: z3py.py:65

§ Distinct()

def z3py.Distinct (   args)
Create a Z3 distinct expression.

>>> x = Int('x')
>>> y = Int('y')
>>> Distinct(x, y)
x != y
>>> z = Int('z')
>>> Distinct(x, y, z)
Distinct(x, y, z)
>>> simplify(Distinct(x, y, z))
Distinct(x, y, z)
>>> simplify(Distinct(x, y, z), blast_distinct=True)
And(Not(x == y), Not(x == z), Not(y == z))

Definition at line 1202 of file z3py.py.

1202 def Distinct(*args):
1203  """Create a Z3 distinct expression.
1204 
1205  >>> x = Int('x')
1206  >>> y = Int('y')
1207  >>> Distinct(x, y)
1208  x != y
1209  >>> z = Int('z')
1210  >>> Distinct(x, y, z)
1211  Distinct(x, y, z)
1212  >>> simplify(Distinct(x, y, z))
1213  Distinct(x, y, z)
1214  >>> simplify(Distinct(x, y, z), blast_distinct=True)
1215  And(Not(x == y), Not(x == z), Not(y == z))
1216  """
1217  args = _get_args(args)
1218  ctx = _ctx_from_ast_arg_list(args)
1219  if __debug__:
1220  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
1221  args = _coerce_expr_list(args, ctx)
1222  _args, sz = _to_ast_array(args)
1223  return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
1224 
Z3_ast Z3_API Z3_mk_distinct(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing distinct(args[0], ..., args[num_args-1]).
def Distinct(args)
Definition: z3py.py:1202

§ Empty()

def z3py.Empty (   s)
Create the empty sequence of the given sort
>>> e = Empty(StringSort())
>>> print(e)
""
>>> e2 = StringVal("")
>>> print(e.eq(e2))
True
>>> e3 = Empty(SeqSort(IntSort()))
>>> print(e3)
seq.empty
>>> e4 = Empty(ReSort(SeqSort(IntSort())))
>>> print(e4)
re.empty

Definition at line 9844 of file z3py.py.

9844 def Empty(s):
9845  """Create the empty sequence of the given sort
9846  >>> e = Empty(StringSort())
9847  >>> print(e)
9848  ""
9849  >>> e2 = StringVal("")
9850  >>> print(e.eq(e2))
9851  True
9852  >>> e3 = Empty(SeqSort(IntSort()))
9853  >>> print(e3)
9854  seq.empty
9855  >>> e4 = Empty(ReSort(SeqSort(IntSort())))
9856  >>> print(e4)
9857  re.empty
9858  """
9859  if isinstance(s, SeqSortRef):
9860  return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
9861  if isinstance(s, ReSortRef):
9862  return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
9863  raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
9864 
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
def Empty(s)
Definition: z3py.py:9844

§ enable_trace()

def z3py.enable_trace (   msg)

Definition at line 62 of file z3py.py.

62 def enable_trace(msg):
63  Z3_enable_trace(msg)
64 
void Z3_API Z3_enable_trace(Z3_string tag)
Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise...
def enable_trace(msg)
Definition: z3py.py:62

§ EnumSort()

def z3py.EnumSort (   name,
  values,
  ctx = None 
)
Return a new enumeration sort named `name` containing the given values.

The result is a pair (sort, list of constants).
Example:
    >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])

Definition at line 4690 of file z3py.py.

Referenced by Context.mkEnumSort().

4690 def EnumSort(name, values, ctx=None):
4691  """Return a new enumeration sort named `name` containing the given values.
4692 
4693  The result is a pair (sort, list of constants).
4694  Example:
4695  >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
4696  """
4697  if __debug__:
4698  _z3_assert(isinstance(name, str), "Name must be a string")
4699  _z3_assert(all([isinstance(v, str) for v in values]), "Eumeration sort values must be strings")
4700  _z3_assert(len(values) > 0, "At least one value expected")
4701  ctx = _get_ctx(ctx)
4702  num = len(values)
4703  _val_names = (Symbol * num)()
4704  for i in range(num):
4705  _val_names[i] = to_symbol(values[i])
4706  _values = (FuncDecl * num)()
4707  _testers = (FuncDecl * num)()
4708  name = to_symbol(name)
4709  S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
4710  V = []
4711  for i in range(num):
4712  V.append(FuncDeclRef(_values[i], ctx))
4713  V = [a() for a in V]
4714  return S, V
4715 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def to_symbol(s, ctx=None)
Definition: z3py.py:101
def EnumSort(name, values, ctx=None)
Definition: z3py.py:4690
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c, Z3_symbol name, unsigned n, Z3_symbol const enum_names[], Z3_func_decl enum_consts[], Z3_func_decl enum_testers[])
Create a enumeration sort.

§ eq()

def z3py.eq (   a,
  b 
)
Return `True` if `a` and `b` are structurally identical AST nodes.

>>> x = Int('x')
>>> y = Int('y')
>>> eq(x, y)
False
>>> eq(x + 1, x + 1)
True
>>> eq(x + 1, 1 + x)
False
>>> eq(simplify(x + 1), simplify(1 + x))
True

Definition at line 412 of file z3py.py.

Referenced by BitVec(), BitVecSort(), FP(), FPSort(), FreshBool(), FreshInt(), FreshReal(), get_map_func(), Select(), and substitute().

412 def eq(a, b):
413  """Return `True` if `a` and `b` are structurally identical AST nodes.
414 
415  >>> x = Int('x')
416  >>> y = Int('y')
417  >>> eq(x, y)
418  False
419  >>> eq(x + 1, x + 1)
420  True
421  >>> eq(x + 1, 1 + x)
422  False
423  >>> eq(simplify(x + 1), simplify(1 + x))
424  True
425  """
426  if __debug__:
427  _z3_assert(is_ast(a) and is_ast(b), "Z3 ASTs expected")
428  return a.eq(b)
429 
def eq(a, b)
Definition: z3py.py:412
def is_ast(a)
Definition: z3py.py:392

§ Exists()

def z3py.Exists (   vs,
  body,
  weight = 1,
  qid = "",
  skid = "",
  patterns = [],
  no_patterns = [] 
)
Create a Z3 exists formula.

The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.

See http://rise4fun.com/Z3Py/tutorial/advanced for more details.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> x = Int('x')
>>> y = Int('y')
>>> q = Exists([x, y], f(x, y) >= x, skid="foo")
>>> q
Exists([x, y], f(x, y) >= x)
>>> is_quantifier(q)
True
>>> r = Tactic('nnf')(q).as_expr()
>>> is_quantifier(r)
False

Definition at line 1937 of file z3py.py.

Referenced by Fixedpoint.abstract(), and QuantifierRef.is_forall().

1937 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
1938  """Create a Z3 exists formula.
1939 
1940  The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
1941 
1942  See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
1943 
1944  >>> f = Function('f', IntSort(), IntSort(), IntSort())
1945  >>> x = Int('x')
1946  >>> y = Int('y')
1947  >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
1948  >>> q
1949  Exists([x, y], f(x, y) >= x)
1950  >>> is_quantifier(q)
1951  True
1952  >>> r = Tactic('nnf')(q).as_expr()
1953  >>> is_quantifier(r)
1954  False
1955  """
1956  return _mk_quantifier(False, vs, body, weight, qid, skid, patterns, no_patterns)
1957 
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Definition: z3py.py:1937

§ Ext()

def z3py.Ext (   a,
  b 
)
Return extensionality index for arrays.

Definition at line 4361 of file z3py.py.

4361 def Ext(a, b):
4362  """Return extensionality index for arrays.
4363  """
4364  if __debug__:
4365  _z3_assert(is_array(a) and is_array(b))
4366  return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()));
4367 
Z3_ast Z3_API Z3_mk_array_ext(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create array extensionality index given two arrays with the same sort. The meaning is given by the ax...
def is_array(a)
Definition: z3py.py:4144
def Ext(a, b)
Definition: z3py.py:4361

§ Extract()

def z3py.Extract (   high,
  low,
  a 
)
Create a Z3 bit-vector extraction expression, or create a string extraction expression.

>>> x = BitVec('x', 8)
>>> Extract(6, 2, x)
Extract(6, 2, x)
>>> Extract(6, 2, x).sort()
BitVec(5)
>>> simplify(Extract(StringVal("abcd"),2,1))
"c"

Definition at line 3711 of file z3py.py.

3711 def Extract(high, low, a):
3712  """Create a Z3 bit-vector extraction expression, or create a string extraction expression.
3713 
3714  >>> x = BitVec('x', 8)
3715  >>> Extract(6, 2, x)
3716  Extract(6, 2, x)
3717  >>> Extract(6, 2, x).sort()
3718  BitVec(5)
3719  >>> simplify(Extract(StringVal("abcd"),2,1))
3720  "c"
3721  """
3722  if isinstance(high, str):
3723  high = StringVal(high)
3724  if is_seq(high):
3725  s = high
3726  offset, length = _coerce_exprs(low, a, s.ctx)
3727  return SeqRef(Z3_mk_seq_extract(s.ctx_ref(), s.as_ast(), offset.as_ast(), length.as_ast()), s.ctx)
3728  if __debug__:
3729  _z3_assert(low <= high, "First argument must be greater than or equal to second argument")
3730  _z3_assert(_is_int(high) and high >= 0 and _is_int(low) and low >= 0, "First and second arguments must be non negative integers")
3731  _z3_assert(is_bv(a), "Third argument must be a Z3 Bitvector expression")
3732  return BitVecRef(Z3_mk_extract(a.ctx_ref(), high, low, a.as_ast()), a.ctx)
3733 
def Extract(high, low, a)
Definition: z3py.py:3711
def StringVal(s, ctx=None)
Definition: z3py.py:9816
Z3_ast Z3_API Z3_mk_seq_extract(Z3_context c, Z3_ast s, Z3_ast offset, Z3_ast length)
Extract subsequence starting at offset of length.
Z3_ast Z3_API Z3_mk_extract(Z3_context c, unsigned high, unsigned low, Z3_ast t1)
Extract the bits high down to low from a bit-vector of size m to yield a new bit-vector of size n...
def is_bv(a)
Definition: z3py.py:3536
def is_seq(a)
Definition: z3py.py:9790

§ FailIf()

def z3py.FailIf (   p,
  ctx = None 
)
Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.

In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal.

>>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
>>> x, y = Ints('x y')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(y > 0)
>>> t(g)
[[x > 0, y > 0]]
>>> g.add(x == y + 1)
>>> t(g)
[[Not(x <= 0), Not(y <= 0), x == 1 + y]]

Definition at line 7740 of file z3py.py.

7740 def FailIf(p, ctx=None):
7741  """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
7742 
7743  In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal.
7744 
7745  >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
7746  >>> x, y = Ints('x y')
7747  >>> g = Goal()
7748  >>> g.add(x > 0)
7749  >>> g.add(y > 0)
7750  >>> t(g)
7751  [[x > 0, y > 0]]
7752  >>> g.add(x == y + 1)
7753  >>> t(g)
7754  [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
7755  """
7756  p = _to_probe(p, ctx)
7757  return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
7758 
Z3_tactic Z3_API Z3_tactic_fail_if(Z3_context c, Z3_probe p)
Return a tactic that fails if the probe p evaluates to false.
def FailIf(p, ctx=None)
Definition: z3py.py:7740

§ FiniteDomainSort()

def z3py.FiniteDomainSort (   name,
  sz,
  ctx = None 
)
Create a named finite domain sort of a given size sz

Definition at line 6835 of file z3py.py.

Referenced by Context.mkFiniteDomainSort(), and Sort.translate().

6835 def FiniteDomainSort(name, sz, ctx=None):
6836  """Create a named finite domain sort of a given size sz"""
6837  if not isinstance(name, Symbol):
6838  name = to_symbol(name)
6839  ctx = _get_ctx(ctx)
6840  return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
6841 
def to_symbol(s, ctx=None)
Definition: z3py.py:101
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, uint64_t size)
Create a named finite domain sort.
def FiniteDomainSort(name, sz, ctx=None)
Definition: z3py.py:6835

§ FiniteDomainVal()

def z3py.FiniteDomainVal (   val,
  sort,
  ctx = None 
)
Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.

>>> s = FiniteDomainSort('S', 256)
>>> FiniteDomainVal(255, s)
255
>>> FiniteDomainVal('100', s)
100

Definition at line 6903 of file z3py.py.

6903 def FiniteDomainVal(val, sort, ctx=None):
6904  """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
6905 
6906  >>> s = FiniteDomainSort('S', 256)
6907  >>> FiniteDomainVal(255, s)
6908  255
6909  >>> FiniteDomainVal('100', s)
6910  100
6911  """
6912  if __debug__:
6913  _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort" )
6914  ctx = sort.ctx
6915  return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
6916 
def is_finite_domain_sort(s)
Definition: z3py.py:6842
def FiniteDomainVal(val, sort, ctx=None)
Definition: z3py.py:6903
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.

§ Float128()

def z3py.Float128 (   ctx = None)
Floating-point 128-bit (quadruple) sort.

Definition at line 8511 of file z3py.py.

8511 def Float128(ctx=None):
8512  """Floating-point 128-bit (quadruple) sort."""
8513  ctx = _get_ctx(ctx)
8514  return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
8515 
def Float128(ctx=None)
Definition: z3py.py:8511
Z3_sort Z3_API Z3_mk_fpa_sort_128(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.

§ Float16()

def z3py.Float16 (   ctx = None)
Floating-point 16-bit (half) sort.

Definition at line 8481 of file z3py.py.

8481 def Float16(ctx=None):
8482  """Floating-point 16-bit (half) sort."""
8483  ctx = _get_ctx(ctx)
8484  return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
8485 
def Float16(ctx=None)
Definition: z3py.py:8481
Z3_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.

§ Float32()

def z3py.Float32 (   ctx = None)
Floating-point 32-bit (single) sort.

Definition at line 8491 of file z3py.py.

Referenced by FPRef.__neg__(), fpBVToFP(), fpFPToFP(), fpRealToFP(), fpSignedToFP(), fpToFP(), and fpUnsignedToFP().

8491 def Float32(ctx=None):
8492  """Floating-point 32-bit (single) sort."""
8493  ctx = _get_ctx(ctx)
8494  return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
8495 
Z3_sort Z3_API Z3_mk_fpa_sort_32(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
def Float32(ctx=None)
Definition: z3py.py:8491

§ Float64()

def z3py.Float64 (   ctx = None)
Floating-point 64-bit (double) sort.

Definition at line 8501 of file z3py.py.

Referenced by fpFPToFP(), and fpToFP().

8501 def Float64(ctx=None):
8502  """Floating-point 64-bit (double) sort."""
8503  ctx = _get_ctx(ctx)
8504  return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
8505 
def Float64(ctx=None)
Definition: z3py.py:8501
Z3_sort Z3_API Z3_mk_fpa_sort_64(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.

§ FloatDouble()

def z3py.FloatDouble (   ctx = None)
Floating-point 64-bit (double) sort.

Definition at line 8506 of file z3py.py.

8506 def FloatDouble(ctx=None):
8507  """Floating-point 64-bit (double) sort."""
8508  ctx = _get_ctx(ctx)
8509  return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
8510 
def FloatDouble(ctx=None)
Definition: z3py.py:8506
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.

§ FloatHalf()

def z3py.FloatHalf (   ctx = None)
Floating-point 16-bit (half) sort.

Definition at line 8486 of file z3py.py.

8486 def FloatHalf(ctx=None):
8487  """Floating-point 16-bit (half) sort."""
8488  ctx = _get_ctx(ctx)
8489  return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
8490 
Z3_sort Z3_API Z3_mk_fpa_sort_half(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
def FloatHalf(ctx=None)
Definition: z3py.py:8486

§ FloatQuadruple()

def z3py.FloatQuadruple (   ctx = None)
Floating-point 128-bit (quadruple) sort.

Definition at line 8516 of file z3py.py.

8516 def FloatQuadruple(ctx=None):
8517  """Floating-point 128-bit (quadruple) sort."""
8518  ctx = _get_ctx(ctx)
8519  return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
8520 
Z3_sort Z3_API Z3_mk_fpa_sort_quadruple(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
def FloatQuadruple(ctx=None)
Definition: z3py.py:8516

§ FloatSingle()

def z3py.FloatSingle (   ctx = None)
Floating-point 32-bit (single) sort.

Definition at line 8496 of file z3py.py.

8496 def FloatSingle(ctx=None):
8497  """Floating-point 32-bit (single) sort."""
8498  ctx = _get_ctx(ctx)
8499  return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
8500 
def FloatSingle(ctx=None)
Definition: z3py.py:8496
Z3_sort Z3_API Z3_mk_fpa_sort_single(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.

§ ForAll()

def z3py.ForAll (   vs,
  body,
  weight = 1,
  qid = "",
  skid = "",
  patterns = [],
  no_patterns = [] 
)
Create a Z3 forall formula.

The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.

See http://rise4fun.com/Z3Py/tutorial/advanced for more details.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> x = Int('x')
>>> y = Int('y')
>>> ForAll([x, y], f(x, y) >= x)
ForAll([x, y], f(x, y) >= x)
>>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
ForAll([x, y], f(x, y) >= x)
>>> ForAll([x, y], f(x, y) >= x, weight=10)
ForAll([x, y], f(x, y) >= x)

Definition at line 1918 of file z3py.py.

Referenced by Fixedpoint.abstract(), QuantifierRef.body(), QuantifierRef.children(), QuantifierRef.is_forall(), is_pattern(), is_quantifier(), MultiPattern(), QuantifierRef.num_patterns(), QuantifierRef.num_vars(), QuantifierRef.pattern(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and QuantifierRef.weight().

1918 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
1919  """Create a Z3 forall formula.
1920 
1921  The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
1922 
1923  See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
1924 
1925  >>> f = Function('f', IntSort(), IntSort(), IntSort())
1926  >>> x = Int('x')
1927  >>> y = Int('y')
1928  >>> ForAll([x, y], f(x, y) >= x)
1929  ForAll([x, y], f(x, y) >= x)
1930  >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
1931  ForAll([x, y], f(x, y) >= x)
1932  >>> ForAll([x, y], f(x, y) >= x, weight=10)
1933  ForAll([x, y], f(x, y) >= x)
1934  """
1935  return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
1936 
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Definition: z3py.py:1918

§ FP()

def z3py.FP (   name,
  fpsort,
  ctx = None 
)
Return a floating-point constant named `name`.
`fpsort` is the floating-point sort.
If `ctx=None`, then the global context is used.

>>> x  = FP('x', FPSort(8, 24))
>>> is_fp(x)
True
>>> x.ebits()
8
>>> x.sort()
FPSort(8, 24)
>>> word = FPSort(8, 24)
>>> x2 = FP('x', word)
>>> eq(x, x2)
True

Definition at line 9094 of file z3py.py.

Referenced by FPRef.__add__(), FPRef.__div__(), FPRef.__mul__(), FPRef.__neg__(), FPRef.__radd__(), FPRef.__rdiv__(), FPRef.__rmul__(), FPRef.__rsub__(), FPRef.__sub__(), fpAdd(), fpDiv(), fpIsInf(), fpIsNaN(), fpMax(), fpMin(), fpMul(), fpNeg(), fpRem(), FPSort(), fpSub(), fpToIEEEBV(), fpToReal(), fpToSBV(), fpToUBV(), is_fp(), is_fp_value(), and FPRef.sort().

9094 def FP(name, fpsort, ctx=None):
9095  """Return a floating-point constant named `name`.
9096  `fpsort` is the floating-point sort.
9097  If `ctx=None`, then the global context is used.
9098 
9099  >>> x = FP('x', FPSort(8, 24))
9100  >>> is_fp(x)
9101  True
9102  >>> x.ebits()
9103  8
9104  >>> x.sort()
9105  FPSort(8, 24)
9106  >>> word = FPSort(8, 24)
9107  >>> x2 = FP('x', word)
9108  >>> eq(x, x2)
9109  True
9110  """
9111  if isinstance(fpsort, FPSortRef) and ctx is None:
9112  ctx = fpsort.ctx
9113  else:
9114  ctx = _get_ctx(ctx)
9115  return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
9116 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:101
def FP(name, fpsort, ctx=None)
Definition: z3py.py:9094

§ fpAbs()

def z3py.fpAbs (   a,
  ctx = None 
)
Create a Z3 floating-point absolute value expression.

>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FPVal(1.0, s)
>>> fpAbs(x)
fpAbs(1)
>>> y = FPVal(-20.0, s)
>>> y
-1.25*(2**4)
>>> fpAbs(y)
fpAbs(-1.25*(2**4))
>>> fpAbs(-1.25*(2**4))
fpAbs(-1.25*(2**4))
>>> fpAbs(x).sort()
FPSort(8, 24)

Definition at line 9135 of file z3py.py.

9135 def fpAbs(a, ctx=None):
9136  """Create a Z3 floating-point absolute value expression.
9137 
9138  >>> s = FPSort(8, 24)
9139  >>> rm = RNE()
9140  >>> x = FPVal(1.0, s)
9141  >>> fpAbs(x)
9142  fpAbs(1)
9143  >>> y = FPVal(-20.0, s)
9144  >>> y
9145  -1.25*(2**4)
9146  >>> fpAbs(y)
9147  fpAbs(-1.25*(2**4))
9148  >>> fpAbs(-1.25*(2**4))
9149  fpAbs(-1.25*(2**4))
9150  >>> fpAbs(x).sort()
9151  FPSort(8, 24)
9152  """
9153  ctx = _get_ctx(ctx)
9154  [a] = _coerce_fp_expr_list([a], ctx)
9155  return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
9156 
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
def fpAbs(a, ctx=None)
Definition: z3py.py:9135

§ fpAdd()

def z3py.fpAdd (   rm,
  a,
  b,
  ctx = None 
)
Create a Z3 floating-point addition expression.

>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpAdd(rm, x, y)
fpAdd(RNE(), x, y)
>>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
x + y
>>> fpAdd(rm, x, y).sort()
FPSort(8, 24)

Definition at line 9224 of file z3py.py.

Referenced by FPs().

9224 def fpAdd(rm, a, b, ctx=None):
9225  """Create a Z3 floating-point addition expression.
9226 
9227  >>> s = FPSort(8, 24)
9228  >>> rm = RNE()
9229  >>> x = FP('x', s)
9230  >>> y = FP('y', s)
9231  >>> fpAdd(rm, x, y)
9232  fpAdd(RNE(), x, y)
9233  >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
9234  x + y
9235  >>> fpAdd(rm, x, y).sort()
9236  FPSort(8, 24)
9237  """
9238  return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
9239 
def fpAdd(rm, a, b, ctx=None)
Definition: z3py.py:9224

§ fpBVToFP()

def z3py.fpBVToFP (   v,
  sort,
  ctx = None 
)
Create a Z3 floating-point conversion expression that represents the 
conversion from a bit-vector term to a floating-point term.

>>> x_bv = BitVecVal(0x3F800000, 32)
>>> x_fp = fpBVToFP(x_bv, Float32())
>>> x_fp
fpToFP(1065353216)
>>> simplify(x_fp)
1

Definition at line 9521 of file z3py.py.

9521 def fpBVToFP(v, sort, ctx=None):
9522  """Create a Z3 floating-point conversion expression that represents the
9523  conversion from a bit-vector term to a floating-point term.
9524 
9525  >>> x_bv = BitVecVal(0x3F800000, 32)
9526  >>> x_fp = fpBVToFP(x_bv, Float32())
9527  >>> x_fp
9528  fpToFP(1065353216)
9529  >>> simplify(x_fp)
9530  1
9531  """
9532  _z3_assert(is_bv(v), "First argument must be a Z3 floating-point rounding mode expression.")
9533  _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
9534  ctx = _get_ctx(ctx)
9535  return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
9536 
def fpBVToFP(v, sort, ctx=None)
Definition: z3py.py:9521
Z3_ast Z3_API Z3_mk_fpa_to_fp_bv(Z3_context c, Z3_ast bv, Z3_sort s)
Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.
def is_fp_sort(s)
Definition: z3py.py:8525
def is_bv(a)
Definition: z3py.py:3536

§ fpDiv()

def z3py.fpDiv (   rm,
  a,
  b,
  ctx = None 
)
Create a Z3 floating-point division expression.

>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpDiv(rm, x, y)
fpDiv(RNE(), x, y)
>>> fpDiv(rm, x, y).sort()
FPSort(8, 24)

Definition at line 9268 of file z3py.py.

9268 def fpDiv(rm, a, b, ctx=None):
9269  """Create a Z3 floating-point division expression.
9270 
9271  >>> s = FPSort(8, 24)
9272  >>> rm = RNE()
9273  >>> x = FP('x', s)
9274  >>> y = FP('y', s)
9275  >>> fpDiv(rm, x, y)
9276  fpDiv(RNE(), x, y)
9277  >>> fpDiv(rm, x, y).sort()
9278  FPSort(8, 24)
9279  """
9280  return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
9281 
def fpDiv(rm, a, b, ctx=None)
Definition: z3py.py:9268

§ fpEQ()

def z3py.fpEQ (   a,
  b,
  ctx = None 
)
Create the Z3 floating-point expression `fpEQ(other, self)`.

>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpEQ(x, y)
fpEQ(x, y)
>>> fpEQ(x, y).sexpr()
'(fp.eq x y)'

Definition at line 9433 of file z3py.py.

Referenced by fpFP(), and fpNEQ().

9433 def fpEQ(a, b, ctx=None):
9434  """Create the Z3 floating-point expression `fpEQ(other, self)`.
9435 
9436  >>> x, y = FPs('x y', FPSort(8, 24))
9437  >>> fpEQ(x, y)
9438  fpEQ(x, y)
9439  >>> fpEQ(x, y).sexpr()
9440  '(fp.eq x y)'
9441  """
9442  return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
9443 
def fpEQ(a, b, ctx=None)
Definition: z3py.py:9433

§ fpFMA()

def z3py.fpFMA (   rm,
  a,
  b,
  c,
  ctx = None 
)
Create a Z3 floating-point fused multiply-add expression.

Definition at line 9323 of file z3py.py.

9323 def fpFMA(rm, a, b, c, ctx=None):
9324  """Create a Z3 floating-point fused multiply-add expression.
9325  """
9326  return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
9327 
def fpFMA(rm, a, b, c, ctx=None)
Definition: z3py.py:9323

§ fpFP()

def z3py.fpFP (   sgn,
  exp,
  sig,
  ctx = None 
)
Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.

>>> s = FPSort(8, 24)
>>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
>>> print(x)
fpFP(1, 127, 4194304)
>>> xv = FPVal(-1.5, s)
>>> print(xv)
-1.5
>>> slvr = Solver()
>>> slvr.add(fpEQ(x, xv))
>>> slvr.check()
sat
>>> xv = FPVal(+1.5, s)
>>> print(xv)
1.5
>>> slvr = Solver()
>>> slvr.add(fpEQ(x, xv))
>>> slvr.check()
unsat

Definition at line 9455 of file z3py.py.

9455 def fpFP(sgn, exp, sig, ctx=None):
9456  """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
9457 
9458  >>> s = FPSort(8, 24)
9459  >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
9460  >>> print(x)
9461  fpFP(1, 127, 4194304)
9462  >>> xv = FPVal(-1.5, s)
9463  >>> print(xv)
9464  -1.5
9465  >>> slvr = Solver()
9466  >>> slvr.add(fpEQ(x, xv))
9467  >>> slvr.check()
9468  sat
9469  >>> xv = FPVal(+1.5, s)
9470  >>> print(xv)
9471  1.5
9472  >>> slvr = Solver()
9473  >>> slvr.add(fpEQ(x, xv))
9474  >>> slvr.check()
9475  unsat
9476  """
9477  _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
9478  _z3_assert(sgn.sort().size() == 1, "sort mismatch")
9479  ctx = _get_ctx(ctx)
9480  _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
9481  return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
9482 
Z3_ast Z3_API Z3_mk_fpa_fp(Z3_context c, Z3_ast sgn, Z3_ast exp, Z3_ast sig)
Create an expression of FloatingPoint sort from three bit-vector expressions.
def fpFP(sgn, exp, sig, ctx=None)
Definition: z3py.py:9455
def is_bv(a)
Definition: z3py.py:3536

§ fpFPToFP()

def z3py.fpFPToFP (   rm,
  v,
  sort,
  ctx = None 
)
Create a Z3 floating-point conversion expression that represents the 
conversion from a floating-point term to a floating-point term of different precision.

>>> x_sgl = FPVal(1.0, Float32())
>>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
>>> x_dbl
fpToFP(RNE(), 1)
>>> simplify(x_dbl)
1
>>> x_dbl.sort()
FPSort(11, 53)

Definition at line 9537 of file z3py.py.

9537 def fpFPToFP(rm, v, sort, ctx=None):
9538  """Create a Z3 floating-point conversion expression that represents the
9539  conversion from a floating-point term to a floating-point term of different precision.
9540 
9541  >>> x_sgl = FPVal(1.0, Float32())
9542  >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
9543  >>> x_dbl
9544  fpToFP(RNE(), 1)
9545  >>> simplify(x_dbl)
9546  1
9547  >>> x_dbl.sort()
9548  FPSort(11, 53)
9549  """
9550  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9551  _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
9552  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9553  ctx = _get_ctx(ctx)
9554  return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9555 
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
def is_fp_sort(s)
Definition: z3py.py:8525
def fpFPToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9537
def is_fprm(a)
Definition: z3py.py:8773
def is_fp(a)
Definition: z3py.py:8906

§ fpGEQ()

def z3py.fpGEQ (   a,
  b,
  ctx = None 
)
Create the Z3 floating-point expression `other >= self`.

>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpGEQ(x, y)
x >= y
>>> (x >= y).sexpr()
'(fp.geq x y)'

Definition at line 9422 of file z3py.py.

9422 def fpGEQ(a, b, ctx=None):
9423  """Create the Z3 floating-point expression `other >= self`.
9424 
9425  >>> x, y = FPs('x y', FPSort(8, 24))
9426  >>> fpGEQ(x, y)
9427  x >= y
9428  >>> (x >= y).sexpr()
9429  '(fp.geq x y)'
9430  """
9431  return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
9432 
def fpGEQ(a, b, ctx=None)
Definition: z3py.py:9422

§ fpGT()

def z3py.fpGT (   a,
  b,
  ctx = None 
)
Create the Z3 floating-point expression `other > self`.

>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpGT(x, y)
x > y
>>> (x > y).sexpr()
'(fp.gt x y)'

Definition at line 9411 of file z3py.py.

9411 def fpGT(a, b, ctx=None):
9412  """Create the Z3 floating-point expression `other > self`.
9413 
9414  >>> x, y = FPs('x y', FPSort(8, 24))
9415  >>> fpGT(x, y)
9416  x > y
9417  >>> (x > y).sexpr()
9418  '(fp.gt x y)'
9419  """
9420  return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
9421 
def fpGT(a, b, ctx=None)
Definition: z3py.py:9411

§ fpInfinity()

def z3py.fpInfinity (   s,
  negative 
)
Create a Z3 floating-point +oo or -oo term.

Definition at line 9028 of file z3py.py.

9028 def fpInfinity(s, negative):
9029  """Create a Z3 floating-point +oo or -oo term."""
9030  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9031  _z3_assert(isinstance(negative, bool), "expected Boolean flag")
9032  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
9033 
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, Z3_bool negative)
Create a floating-point infinity of sort s.
def fpInfinity(s, negative)
Definition: z3py.py:9028

§ fpIsInf()

def z3py.fpIsInf (   a,
  ctx = None 
)
Create a Z3 floating-point isInfinite expression.

>>> s = FPSort(8, 24)
>>> x = FP('x', s)
>>> fpIsInf(x)
fpIsInf(x)

Definition at line 9349 of file z3py.py.

9349 def fpIsInf(a, ctx=None):
9350  """Create a Z3 floating-point isInfinite expression.
9351 
9352  >>> s = FPSort(8, 24)
9353  >>> x = FP('x', s)
9354  >>> fpIsInf(x)
9355  fpIsInf(x)
9356  """
9357  return _mk_fp_unary_norm(Z3_mk_fpa_is_infinite, a, ctx)
9358 
def fpIsInf(a, ctx=None)
Definition: z3py.py:9349

§ fpIsNaN()

def z3py.fpIsNaN (   a,
  ctx = None 
)
Create a Z3 floating-point isNaN expression.

>>> s = FPSort(8, 24)
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpIsNaN(x)
fpIsNaN(x)

Definition at line 9338 of file z3py.py.

9338 def fpIsNaN(a, ctx=None):
9339  """Create a Z3 floating-point isNaN expression.
9340 
9341  >>> s = FPSort(8, 24)
9342  >>> x = FP('x', s)
9343  >>> y = FP('y', s)
9344  >>> fpIsNaN(x)
9345  fpIsNaN(x)
9346  """
9347  return _mk_fp_unary_norm(Z3_mk_fpa_is_nan, a, ctx)
9348 
def fpIsNaN(a, ctx=None)
Definition: z3py.py:9338

§ fpIsNegative()

def z3py.fpIsNegative (   a,
  ctx = None 
)
Create a Z3 floating-point isNegative expression.

Definition at line 9374 of file z3py.py.

9374 def fpIsNegative(a, ctx=None):
9375  """Create a Z3 floating-point isNegative expression.
9376  """
9377  return _mk_fp_unary_norm(Z3_mk_fpa_is_negative, a, ctx)
9378 
def fpIsNegative(a, ctx=None)
Definition: z3py.py:9374

§ fpIsNormal()

def z3py.fpIsNormal (   a,
  ctx = None 
)
Create a Z3 floating-point isNormal expression.

Definition at line 9364 of file z3py.py.

9364 def fpIsNormal(a, ctx=None):
9365  """Create a Z3 floating-point isNormal expression.
9366  """
9367  return _mk_fp_unary_norm(Z3_mk_fpa_is_normal, a, ctx)
9368 
def fpIsNormal(a, ctx=None)
Definition: z3py.py:9364

§ fpIsPositive()

def z3py.fpIsPositive (   a,
  ctx = None 
)
Create a Z3 floating-point isPositive expression.

Definition at line 9379 of file z3py.py.

9379 def fpIsPositive(a, ctx=None):
9380  """Create a Z3 floating-point isPositive expression.
9381  """
9382  return _mk_fp_unary_norm(Z3_mk_fpa_is_positive, a, ctx)
9383  return FPRef(Z3_mk_fpa_is_positive(a.ctx_ref(), a.as_ast()), a.ctx)
9384 
Z3_ast Z3_API Z3_mk_fpa_is_positive(Z3_context c, Z3_ast t)
Predicate indicating whether t is a positive floating-point number.
def fpIsPositive(a, ctx=None)
Definition: z3py.py:9379

§ fpIsSubnormal()

def z3py.fpIsSubnormal (   a,
  ctx = None 
)
Create a Z3 floating-point isSubnormal expression.

Definition at line 9369 of file z3py.py.

9369 def fpIsSubnormal(a, ctx=None):
9370  """Create a Z3 floating-point isSubnormal expression.
9371  """
9372  return _mk_fp_unary_norm(Z3_mk_fpa_is_subnormal, a, ctx)
9373 
def fpIsSubnormal(a, ctx=None)
Definition: z3py.py:9369

§ fpIsZero()

def z3py.fpIsZero (   a,
  ctx = None 
)
Create a Z3 floating-point isZero expression.

Definition at line 9359 of file z3py.py.

9359 def fpIsZero(a, ctx=None):
9360  """Create a Z3 floating-point isZero expression.
9361  """
9362  return _mk_fp_unary_norm(Z3_mk_fpa_is_zero, a, ctx)
9363 
def fpIsZero(a, ctx=None)
Definition: z3py.py:9359

§ fpLEQ()

def z3py.fpLEQ (   a,
  b,
  ctx = None 
)
Create the Z3 floating-point expression `other <= self`.

>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpLEQ(x, y)
x <= y
>>> (x <= y).sexpr()
'(fp.leq x y)'

Definition at line 9400 of file z3py.py.

9400 def fpLEQ(a, b, ctx=None):
9401  """Create the Z3 floating-point expression `other <= self`.
9402 
9403  >>> x, y = FPs('x y', FPSort(8, 24))
9404  >>> fpLEQ(x, y)
9405  x <= y
9406  >>> (x <= y).sexpr()
9407  '(fp.leq x y)'
9408  """
9409  return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
9410 
def fpLEQ(a, b, ctx=None)
Definition: z3py.py:9400

§ fpLT()

def z3py.fpLT (   a,
  b,
  ctx = None 
)
Create the Z3 floating-point expression `other < self`.

>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpLT(x, y)
x < y
>>> (x < y).sexpr()
'(fp.lt x y)'

Definition at line 9389 of file z3py.py.

9389 def fpLT(a, b, ctx=None):
9390  """Create the Z3 floating-point expression `other < self`.
9391 
9392  >>> x, y = FPs('x y', FPSort(8, 24))
9393  >>> fpLT(x, y)
9394  x < y
9395  >>> (x < y).sexpr()
9396  '(fp.lt x y)'
9397  """
9398  return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
9399 
def fpLT(a, b, ctx=None)
Definition: z3py.py:9389

§ fpMax()

def z3py.fpMax (   a,
  b,
  ctx = None 
)
Create a Z3 floating-point maximum expression.

>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpMax(x, y)
fpMax(x, y)
>>> fpMax(x, y).sort()
FPSort(8, 24)

Definition at line 9309 of file z3py.py.

9309 def fpMax(a, b, ctx=None):
9310  """Create a Z3 floating-point maximum expression.
9311 
9312  >>> s = FPSort(8, 24)
9313  >>> rm = RNE()
9314  >>> x = FP('x', s)
9315  >>> y = FP('y', s)
9316  >>> fpMax(x, y)
9317  fpMax(x, y)
9318  >>> fpMax(x, y).sort()
9319  FPSort(8, 24)
9320  """
9321  return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
9322 
def fpMax(a, b, ctx=None)
Definition: z3py.py:9309

§ fpMin()

def z3py.fpMin (   a,
  b,
  ctx = None 
)
Create a Z3 floating-point minimum expression.

>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpMin(x, y)
fpMin(x, y)
>>> fpMin(x, y).sort()
FPSort(8, 24)

Definition at line 9295 of file z3py.py.

9295 def fpMin(a, b, ctx=None):
9296  """Create a Z3 floating-point minimum expression.
9297 
9298  >>> s = FPSort(8, 24)
9299  >>> rm = RNE()
9300  >>> x = FP('x', s)
9301  >>> y = FP('y', s)
9302  >>> fpMin(x, y)
9303  fpMin(x, y)
9304  >>> fpMin(x, y).sort()
9305  FPSort(8, 24)
9306  """
9307  return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
9308 
def fpMin(a, b, ctx=None)
Definition: z3py.py:9295

§ fpMinusInfinity()

def z3py.fpMinusInfinity (   s)
Create a Z3 floating-point -oo term.

Definition at line 9023 of file z3py.py.

9023 def fpMinusInfinity(s):
9024  """Create a Z3 floating-point -oo term."""
9025  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9026  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
9027 
def fpMinusInfinity(s)
Definition: z3py.py:9023
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, Z3_bool negative)
Create a floating-point infinity of sort s.

§ fpMinusZero()

def z3py.fpMinusZero (   s)
Create a Z3 floating-point -0.0 term.

Definition at line 9039 of file z3py.py.

9039 def fpMinusZero(s):
9040  """Create a Z3 floating-point -0.0 term."""
9041  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9042  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
9043 
def fpMinusZero(s)
Definition: z3py.py:9039
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, Z3_bool negative)
Create a floating-point zero of sort s.

§ fpMul()

def z3py.fpMul (   rm,
  a,
  b,
  ctx = None 
)
Create a Z3 floating-point multiplication expression.

>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpMul(rm, x, y)
fpMul(RNE(), x, y)
>>> fpMul(rm, x, y).sort()
FPSort(8, 24)

Definition at line 9254 of file z3py.py.

Referenced by FPs().

9254 def fpMul(rm, a, b, ctx=None):
9255  """Create a Z3 floating-point multiplication expression.
9256 
9257  >>> s = FPSort(8, 24)
9258  >>> rm = RNE()
9259  >>> x = FP('x', s)
9260  >>> y = FP('y', s)
9261  >>> fpMul(rm, x, y)
9262  fpMul(RNE(), x, y)
9263  >>> fpMul(rm, x, y).sort()
9264  FPSort(8, 24)
9265  """
9266  return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
9267 
def fpMul(rm, a, b, ctx=None)
Definition: z3py.py:9254

§ fpNaN()

def z3py.fpNaN (   s)
Create a Z3 floating-point NaN term.

>>> s = FPSort(8, 24)
>>> set_fpa_pretty(True)
>>> fpNaN(s)
NaN
>>> pb = get_fpa_pretty()
>>> set_fpa_pretty(False)
>>> fpNaN(s)
fpNaN(FPSort(8, 24))
>>> set_fpa_pretty(pb)

Definition at line 8991 of file z3py.py.

8991 def fpNaN(s):
8992  """Create a Z3 floating-point NaN term.
8993 
8994  >>> s = FPSort(8, 24)
8995  >>> set_fpa_pretty(True)
8996  >>> fpNaN(s)
8997  NaN
8998  >>> pb = get_fpa_pretty()
8999  >>> set_fpa_pretty(False)
9000  >>> fpNaN(s)
9001  fpNaN(FPSort(8, 24))
9002  >>> set_fpa_pretty(pb)
9003  """
9004  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9005  return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
9006 
def fpNaN(s)
Definition: z3py.py:8991
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.

§ fpNeg()

def z3py.fpNeg (   a,
  ctx = None 
)
Create a Z3 floating-point addition expression.

>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> fpNeg(x)
-x
>>> fpNeg(x).sort()
FPSort(8, 24)

Definition at line 9157 of file z3py.py.

9157 def fpNeg(a, ctx=None):
9158  """Create a Z3 floating-point addition expression.
9159 
9160  >>> s = FPSort(8, 24)
9161  >>> rm = RNE()
9162  >>> x = FP('x', s)
9163  >>> fpNeg(x)
9164  -x
9165  >>> fpNeg(x).sort()
9166  FPSort(8, 24)
9167  """
9168  ctx = _get_ctx(ctx)
9169  [a] = _coerce_fp_expr_list([a], ctx)
9170  return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
9171 
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
def fpNeg(a, ctx=None)
Definition: z3py.py:9157

§ fpNEQ()

def z3py.fpNEQ (   a,
  b,
  ctx = None 
)
Create the Z3 floating-point expression `Not(fpEQ(other, self))`.

>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpNEQ(x, y)
Not(fpEQ(x, y))
>>> (x != y).sexpr()
'(distinct x y)'

Definition at line 9444 of file z3py.py.

9444 def fpNEQ(a, b, ctx=None):
9445  """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
9446 
9447  >>> x, y = FPs('x y', FPSort(8, 24))
9448  >>> fpNEQ(x, y)
9449  Not(fpEQ(x, y))
9450  >>> (x != y).sexpr()
9451  '(distinct x y)'
9452  """
9453  return Not(fpEQ(a, b, ctx))
9454 
def fpEQ(a, b, ctx=None)
Definition: z3py.py:9433
def Not(a, ctx=None)
Definition: z3py.py:1567
def fpNEQ(a, b, ctx=None)
Definition: z3py.py:9444

§ fpPlusInfinity()

def z3py.fpPlusInfinity (   s)
Create a Z3 floating-point +oo term.

>>> s = FPSort(8, 24)
>>> pb = get_fpa_pretty()
>>> set_fpa_pretty(True)
>>> fpPlusInfinity(s)
+oo
>>> set_fpa_pretty(False)
>>> fpPlusInfinity(s)
fpPlusInfinity(FPSort(8, 24))
>>> set_fpa_pretty(pb)

Definition at line 9007 of file z3py.py.

9007 def fpPlusInfinity(s):
9008  """Create a Z3 floating-point +oo term.
9009 
9010  >>> s = FPSort(8, 24)
9011  >>> pb = get_fpa_pretty()
9012  >>> set_fpa_pretty(True)
9013  >>> fpPlusInfinity(s)
9014  +oo
9015  >>> set_fpa_pretty(False)
9016  >>> fpPlusInfinity(s)
9017  fpPlusInfinity(FPSort(8, 24))
9018  >>> set_fpa_pretty(pb)
9019  """
9020  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9021  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
9022 
def fpPlusInfinity(s)
Definition: z3py.py:9007
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, Z3_bool negative)
Create a floating-point infinity of sort s.

§ fpPlusZero()

def z3py.fpPlusZero (   s)
Create a Z3 floating-point +0.0 term.

Definition at line 9034 of file z3py.py.

9034 def fpPlusZero(s):
9035  """Create a Z3 floating-point +0.0 term."""
9036  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9037  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
9038 
def fpPlusZero(s)
Definition: z3py.py:9034
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, Z3_bool negative)
Create a floating-point zero of sort s.

§ fpRealToFP()

def z3py.fpRealToFP (   rm,
  v,
  sort,
  ctx = None 
)
Create a Z3 floating-point conversion expression that represents the 
conversion from a real term to a floating-point term.

>>> x_r = RealVal(1.5)
>>> x_fp = fpRealToFP(RNE(), x_r, Float32())
>>> x_fp
fpToFP(RNE(), 3/2)
>>> simplify(x_fp)
1.5

Definition at line 9556 of file z3py.py.

9556 def fpRealToFP(rm, v, sort, ctx=None):
9557  """Create a Z3 floating-point conversion expression that represents the
9558  conversion from a real term to a floating-point term.
9559 
9560  >>> x_r = RealVal(1.5)
9561  >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
9562  >>> x_fp
9563  fpToFP(RNE(), 3/2)
9564  >>> simplify(x_fp)
9565  1.5
9566  """
9567  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9568  _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
9569  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9570  ctx = _get_ctx(ctx)
9571  return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9572 
Z3_ast Z3_API Z3_mk_fpa_to_fp_real(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a term of real sort into a term of FloatingPoint sort.
def is_real(a)
Definition: z3py.py:2370
def is_fp_sort(s)
Definition: z3py.py:8525
def fpRealToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9556
def is_fprm(a)
Definition: z3py.py:8773

§ fpRem()

def z3py.fpRem (   a,
  b,
  ctx = None 
)
Create a Z3 floating-point remainder expression.

>>> s = FPSort(8, 24)
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpRem(x, y)
fpRem(x, y)
>>> fpRem(x, y).sort()
FPSort(8, 24)

Definition at line 9282 of file z3py.py.

9282 def fpRem(a, b, ctx=None):
9283  """Create a Z3 floating-point remainder expression.
9284 
9285  >>> s = FPSort(8, 24)
9286  >>> x = FP('x', s)
9287  >>> y = FP('y', s)
9288  >>> fpRem(x, y)
9289  fpRem(x, y)
9290  >>> fpRem(x, y).sort()
9291  FPSort(8, 24)
9292  """
9293  return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
9294 
def fpRem(a, b, ctx=None)
Definition: z3py.py:9282

§ fpRoundToIntegral()

def z3py.fpRoundToIntegral (   rm,
  a,
  ctx = None 
)
Create a Z3 floating-point roundToIntegral expression.

Definition at line 9333 of file z3py.py.

9333 def fpRoundToIntegral(rm, a, ctx=None):
9334  """Create a Z3 floating-point roundToIntegral expression.
9335  """
9336  return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
9337 
def fpRoundToIntegral(rm, a, ctx=None)
Definition: z3py.py:9333

§ FPs()

def z3py.FPs (   names,
  fpsort,
  ctx = None 
)
Return an array of floating-point constants.

>>> x, y, z = FPs('x y z', FPSort(8, 24))
>>> x.sort()
FPSort(8, 24)
>>> x.sbits()
24
>>> x.ebits()
8
>>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
fpMul(RNE(), fpAdd(RNE(), x, y), z)

Definition at line 9117 of file z3py.py.

Referenced by fpEQ(), fpGEQ(), fpGT(), fpLEQ(), fpLT(), and fpNEQ().

9117 def FPs(names, fpsort, ctx=None):
9118  """Return an array of floating-point constants.
9119 
9120  >>> x, y, z = FPs('x y z', FPSort(8, 24))
9121  >>> x.sort()
9122  FPSort(8, 24)
9123  >>> x.sbits()
9124  24
9125  >>> x.ebits()
9126  8
9127  >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
9128  fpMul(RNE(), fpAdd(RNE(), x, y), z)
9129  """
9130  ctx = _get_ctx(ctx)
9131  if isinstance(names, str):
9132  names = names.split(" ")
9133  return [FP(name, fpsort, ctx) for name in names]
9134 
def FPs(names, fpsort, ctx=None)
Definition: z3py.py:9117
def FP(name, fpsort, ctx=None)
Definition: z3py.py:9094

§ fpSignedToFP()

def z3py.fpSignedToFP (   rm,
  v,
  sort,
  ctx = None 
)
Create a Z3 floating-point conversion expression that represents the 
conversion from a signed bit-vector term (encoding an integer) to a floating-point term.

>>> x_signed = BitVecVal(-5, BitVecSort(32))
>>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
>>> x_fp
fpToFP(RNE(), 4294967291)
>>> simplify(x_fp)
-1.25*(2**2)

Definition at line 9573 of file z3py.py.

9573 def fpSignedToFP(rm, v, sort, ctx=None):
9574  """Create a Z3 floating-point conversion expression that represents the
9575  conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
9576 
9577  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9578  >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
9579  >>> x_fp
9580  fpToFP(RNE(), 4294967291)
9581  >>> simplify(x_fp)
9582  -1.25*(2**2)
9583  """
9584  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9585  _z3_assert(is_bv(v), "Second argument must be a Z3 expression or real sort.")
9586  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9587  ctx = _get_ctx(ctx)
9588  return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9589 
Z3_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2&#39;s complement signed bit-vector term into a term of FloatingPoint sort...
def fpSignedToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9573
def is_fp_sort(s)
Definition: z3py.py:8525
def is_bv(a)
Definition: z3py.py:3536
def is_fprm(a)
Definition: z3py.py:8773

§ FPSort()

def z3py.FPSort (   ebits,
  sbits,
  ctx = None 
)
Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.

>>> Single = FPSort(8, 24)
>>> Double = FPSort(11, 53)
>>> Single
FPSort(8, 24)
>>> x = Const('x', Single)
>>> eq(x, FP('x', FPSort(8, 24)))
True

Definition at line 8933 of file z3py.py.

Referenced by FPRef.__add__(), FPRef.__div__(), FPRef.__mul__(), FPRef.__radd__(), FPRef.__rdiv__(), FPRef.__rmul__(), FPRef.__rsub__(), FPRef.__sub__(), FPSortRef.cast(), FPSortRef.ebits(), FPRef.ebits(), FPNumRef.exponent(), FP(), fpAbs(), fpAdd(), fpDiv(), fpEQ(), fpFP(), fpFPToFP(), fpGEQ(), fpGT(), fpIsInf(), fpIsNaN(), fpLEQ(), fpLT(), fpMax(), fpMin(), fpMul(), fpNaN(), fpNeg(), fpNEQ(), fpPlusInfinity(), fpRem(), FPs(), fpSub(), fpToFP(), fpToIEEEBV(), fpToReal(), fpToSBV(), fpToUBV(), FPVal(), is_fp(), is_fp_sort(), is_fp_value(), is_fprm_sort(), FPNumRef.isNegative(), Context.mkFPSort(), Context.mkFPSort128(), Context.mkFPSort16(), Context.mkFPSort32(), Context.mkFPSort64(), Context.mkFPSortDouble(), Context.mkFPSortHalf(), Context.mkFPSortQuadruple(), Context.mkFPSortSingle(), FPSortRef.sbits(), FPRef.sbits(), FPNumRef.sign_as_bv(), FPNumRef.significand(), FPNumRef.significand_as_bv(), FPRef.sort(), and Sort.translate().

8933 def FPSort(ebits, sbits, ctx=None):
8934  """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
8935 
8936  >>> Single = FPSort(8, 24)
8937  >>> Double = FPSort(11, 53)
8938  >>> Single
8939  FPSort(8, 24)
8940  >>> x = Const('x', Single)
8941  >>> eq(x, FP('x', FPSort(8, 24)))
8942  True
8943  """
8944  ctx = _get_ctx(ctx)
8945  return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
8946 
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
def FPSort(ebits, sbits, ctx=None)
Definition: z3py.py:8933

§ fpSqrt()

def z3py.fpSqrt (   rm,
  a,
  ctx = None 
)
Create a Z3 floating-point square root expression.

Definition at line 9328 of file z3py.py.

9328 def fpSqrt(rm, a, ctx=None):
9329  """Create a Z3 floating-point square root expression.
9330  """
9331  return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
9332 
def fpSqrt(rm, a, ctx=None)
Definition: z3py.py:9328

§ fpSub()

def z3py.fpSub (   rm,
  a,
  b,
  ctx = None 
)
Create a Z3 floating-point subtraction expression.

>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpSub(rm, x, y)
fpSub(RNE(), x, y)
>>> fpSub(rm, x, y).sort()
FPSort(8, 24)

Definition at line 9240 of file z3py.py.

9240 def fpSub(rm, a, b, ctx=None):
9241  """Create a Z3 floating-point subtraction expression.
9242 
9243  >>> s = FPSort(8, 24)
9244  >>> rm = RNE()
9245  >>> x = FP('x', s)
9246  >>> y = FP('y', s)
9247  >>> fpSub(rm, x, y)
9248  fpSub(RNE(), x, y)
9249  >>> fpSub(rm, x, y).sort()
9250  FPSort(8, 24)
9251  """
9252  return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
9253 
def fpSub(rm, a, b, ctx=None)
Definition: z3py.py:9240

§ fpToFP()

def z3py.fpToFP (   a1,
  a2 = None,
  a3 = None,
  ctx = None 
)
Create a Z3 floating-point conversion expression from other term sorts
to floating-point.

From a bit-vector term in IEEE 754-2008 format:
>>> x = FPVal(1.0, Float32())
>>> x_bv = fpToIEEEBV(x)
>>> simplify(fpToFP(x_bv, Float32()))
1

From a floating-point term with different precision:
>>> x = FPVal(1.0, Float32())
>>> x_db = fpToFP(RNE(), x, Float64())
>>> x_db.sort()
FPSort(11, 53)

From a real term:
>>> x_r = RealVal(1.5)
>>> simplify(fpToFP(RNE(), x_r, Float32()))
1.5

From a signed bit-vector term:
>>> x_signed = BitVecVal(-5, BitVecSort(32))
>>> simplify(fpToFP(RNE(), x_signed, Float32()))
-1.25*(2**2)

Definition at line 9483 of file z3py.py.

Referenced by fpBVToFP(), fpFPToFP(), fpRealToFP(), and fpSignedToFP().

9483 def fpToFP(a1, a2=None, a3=None, ctx=None):
9484  """Create a Z3 floating-point conversion expression from other term sorts
9485  to floating-point.
9486 
9487  From a bit-vector term in IEEE 754-2008 format:
9488  >>> x = FPVal(1.0, Float32())
9489  >>> x_bv = fpToIEEEBV(x)
9490  >>> simplify(fpToFP(x_bv, Float32()))
9491  1
9492 
9493  From a floating-point term with different precision:
9494  >>> x = FPVal(1.0, Float32())
9495  >>> x_db = fpToFP(RNE(), x, Float64())
9496  >>> x_db.sort()
9497  FPSort(11, 53)
9498 
9499  From a real term:
9500  >>> x_r = RealVal(1.5)
9501  >>> simplify(fpToFP(RNE(), x_r, Float32()))
9502  1.5
9503 
9504  From a signed bit-vector term:
9505  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9506  >>> simplify(fpToFP(RNE(), x_signed, Float32()))
9507  -1.25*(2**2)
9508  """
9509  ctx = _get_ctx(ctx)
9510  if is_bv(a1) and is_fp_sort(a2):
9511  return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
9512  elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
9513  return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9514  elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
9515  return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9516  elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
9517  return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9518  else:
9519  raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
9520 
def fpToFP(a1, a2=None, a3=None, ctx=None)
Definition: z3py.py:9483
Z3_ast Z3_API Z3_mk_fpa_to_fp_bv(Z3_context c, Z3_ast bv, Z3_sort s)
Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.
Z3_ast Z3_API Z3_mk_fpa_to_fp_real(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a term of real sort into a term of FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2&#39;s complement signed bit-vector term into a term of FloatingPoint sort...
def is_real(a)
Definition: z3py.py:2370
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
def is_fp_sort(s)
Definition: z3py.py:8525
def is_bv(a)
Definition: z3py.py:3536
def is_fprm(a)
Definition: z3py.py:8773
def is_fp(a)
Definition: z3py.py:8906

§ fpToFPUnsigned()

def z3py.fpToFPUnsigned (   rm,
  x,
  s,
  ctx = None 
)
Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression.

Definition at line 9607 of file z3py.py.

Referenced by fpUnsignedToFP().

9607 def fpToFPUnsigned(rm, x, s, ctx=None):
9608  """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
9609  if __debug__:
9610  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9611  _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
9612  _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
9613  ctx = _get_ctx(ctx)
9614  return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
9615 
def fpToFPUnsigned(rm, x, s, ctx=None)
Definition: z3py.py:9607
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2&#39;s complement unsigned bit-vector term into a term of FloatingPoint sort...
def is_fp_sort(s)
Definition: z3py.py:8525
def is_bv(a)
Definition: z3py.py:3536
def is_fprm(a)
Definition: z3py.py:8773

§ fpToIEEEBV()

def z3py.fpToIEEEBV (   x,
  ctx = None 
)
\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.

The size of the resulting bit-vector is automatically determined.

Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
knows only one NaN and it will always produce the same bit-vector representation of
that NaN.

>>> x = FP('x', FPSort(8, 24))
>>> y = fpToIEEEBV(x)
>>> print(is_fp(x))
True
>>> print(is_bv(y))
True
>>> print(is_fp(y))
False
>>> print(is_bv(x))
False

Definition at line 9677 of file z3py.py.

Referenced by fpToFP().

9677 def fpToIEEEBV(x, ctx=None):
9678  """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
9679 
9680  The size of the resulting bit-vector is automatically determined.
9681 
9682  Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
9683  knows only one NaN and it will always produce the same bit-vector representation of
9684  that NaN.
9685 
9686  >>> x = FP('x', FPSort(8, 24))
9687  >>> y = fpToIEEEBV(x)
9688  >>> print(is_fp(x))
9689  True
9690  >>> print(is_bv(y))
9691  True
9692  >>> print(is_fp(y))
9693  False
9694  >>> print(is_bv(x))
9695  False
9696  """
9697  if __debug__:
9698  _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
9699  ctx = _get_ctx(ctx)
9700  return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
9701 
9702 
9703 
def fpToIEEEBV(x, ctx=None)
Definition: z3py.py:9677
Z3_ast Z3_API Z3_mk_fpa_to_ieee_bv(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
def is_fp(a)
Definition: z3py.py:8906

§ fpToReal()

def z3py.fpToReal (   x,
  ctx = None 
)
Create a Z3 floating-point conversion expression, from floating-point expression to real.

>>> x = FP('x', FPSort(8, 24))
>>> y = fpToReal(x)
>>> print(is_fp(x))
True
>>> print(is_real(y))
True
>>> print(is_fp(y))
False
>>> print(is_real(x))
False

Definition at line 9658 of file z3py.py.

9658 def fpToReal(x, ctx=None):
9659  """Create a Z3 floating-point conversion expression, from floating-point expression to real.
9660 
9661  >>> x = FP('x', FPSort(8, 24))
9662  >>> y = fpToReal(x)
9663  >>> print(is_fp(x))
9664  True
9665  >>> print(is_real(y))
9666  True
9667  >>> print(is_fp(y))
9668  False
9669  >>> print(is_real(x))
9670  False
9671  """
9672  if __debug__:
9673  _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
9674  ctx = _get_ctx(ctx)
9675  return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
9676 
Z3_ast Z3_API Z3_mk_fpa_to_real(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a real-numbered term.
def fpToReal(x, ctx=None)
Definition: z3py.py:9658
def is_fp(a)
Definition: z3py.py:8906

§ fpToSBV()

def z3py.fpToSBV (   rm,
  x,
  s,
  ctx = None 
)
Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.

>>> x = FP('x', FPSort(8, 24))
>>> y = fpToSBV(RTZ(), x, BitVecSort(32))
>>> print(is_fp(x))
True
>>> print(is_bv(y))
True
>>> print(is_fp(y))
False
>>> print(is_bv(x))
False

Definition at line 9616 of file z3py.py.

9616 def fpToSBV(rm, x, s, ctx=None):
9617  """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
9618 
9619  >>> x = FP('x', FPSort(8, 24))
9620  >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
9621  >>> print(is_fp(x))
9622  True
9623  >>> print(is_bv(y))
9624  True
9625  >>> print(is_fp(y))
9626  False
9627  >>> print(is_bv(x))
9628  False
9629  """
9630  if __debug__:
9631  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9632  _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
9633  _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
9634  ctx = _get_ctx(ctx)
9635  return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
9636 
Z3_ast Z3_API Z3_mk_fpa_to_sbv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into a signed bit-vector.
def fpToSBV(rm, x, s, ctx=None)
Definition: z3py.py:9616
def is_bv_sort(s)
Definition: z3py.py:3075
def is_fprm(a)
Definition: z3py.py:8773
def is_fp(a)
Definition: z3py.py:8906

§ fpToUBV()

def z3py.fpToUBV (   rm,
  x,
  s,
  ctx = None 
)
Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.

>>> x = FP('x', FPSort(8, 24))
>>> y = fpToUBV(RTZ(), x, BitVecSort(32))
>>> print(is_fp(x))
True
>>> print(is_bv(y))
True
>>> print(is_fp(y))
False
>>> print(is_bv(x))
False

Definition at line 9637 of file z3py.py.

9637 def fpToUBV(rm, x, s, ctx=None):
9638  """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
9639 
9640  >>> x = FP('x', FPSort(8, 24))
9641  >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
9642  >>> print(is_fp(x))
9643  True
9644  >>> print(is_bv(y))
9645  True
9646  >>> print(is_fp(y))
9647  False
9648  >>> print(is_bv(x))
9649  False
9650  """
9651  if __debug__:
9652  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9653  _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
9654  _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
9655  ctx = _get_ctx(ctx)
9656  return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
9657 
Z3_ast Z3_API Z3_mk_fpa_to_ubv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into an unsigned bit-vector.
def fpToUBV(rm, x, s, ctx=None)
Definition: z3py.py:9637
def is_bv_sort(s)
Definition: z3py.py:3075
def is_fprm(a)
Definition: z3py.py:8773
def is_fp(a)
Definition: z3py.py:8906

§ fpUnsignedToFP()

def z3py.fpUnsignedToFP (   rm,
  v,
  sort,
  ctx = None 
)
Create a Z3 floating-point conversion expression that represents the 
conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.

>>> x_signed = BitVecVal(-5, BitVecSort(32))
>>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
>>> x_fp
fpToFPUnsigned(RNE(), 4294967291)
>>> simplify(x_fp)
1*(2**32)

Definition at line 9590 of file z3py.py.

9590 def fpUnsignedToFP(rm, v, sort, ctx=None):
9591  """Create a Z3 floating-point conversion expression that represents the
9592  conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
9593 
9594  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9595  >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
9596  >>> x_fp
9597  fpToFPUnsigned(RNE(), 4294967291)
9598  >>> simplify(x_fp)
9599  1*(2**32)
9600  """
9601  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9602  _z3_assert(is_bv(v), "Second argument must be a Z3 expression or real sort.")
9603  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9604  ctx = _get_ctx(ctx)
9605  return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9606 
def fpUnsignedToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9590
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2&#39;s complement unsigned bit-vector term into a term of FloatingPoint sort...
def is_fp_sort(s)
Definition: z3py.py:8525
def is_bv(a)
Definition: z3py.py:3536
def is_fprm(a)
Definition: z3py.py:8773

§ FPVal()

def z3py.FPVal (   sig,
  exp = None,
  fps = None,
  ctx = None 
)
Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used.

>>> v = FPVal(20.0, FPSort(8, 24))
>>> v
1.25*(2**4)
>>> print("0x%.8x" % v.exponent_as_long(False))
0x00000004
>>> v = FPVal(2.25, FPSort(8, 24))
>>> v
1.125*(2**1)
>>> v = FPVal(-2.25, FPSort(8, 24))
>>> v
-1.125*(2**1)
>>> FPVal(-0.0, FPSort(8, 24))
-0.0
>>> FPVal(0.0, FPSort(8, 24))
+0.0
>>> FPVal(+0.0, FPSort(8, 24))
+0.0

Definition at line 9050 of file z3py.py.

Referenced by FPNumRef.exponent(), fpAbs(), fpFP(), fpFPToFP(), fpToFP(), is_fp_value(), FPNumRef.isNegative(), FPNumRef.sign_as_bv(), FPNumRef.significand(), and FPNumRef.significand_as_bv().

9050 def FPVal(sig, exp=None, fps=None, ctx=None):
9051  """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used.
9052 
9053  >>> v = FPVal(20.0, FPSort(8, 24))
9054  >>> v
9055  1.25*(2**4)
9056  >>> print("0x%.8x" % v.exponent_as_long(False))
9057  0x00000004
9058  >>> v = FPVal(2.25, FPSort(8, 24))
9059  >>> v
9060  1.125*(2**1)
9061  >>> v = FPVal(-2.25, FPSort(8, 24))
9062  >>> v
9063  -1.125*(2**1)
9064  >>> FPVal(-0.0, FPSort(8, 24))
9065  -0.0
9066  >>> FPVal(0.0, FPSort(8, 24))
9067  +0.0
9068  >>> FPVal(+0.0, FPSort(8, 24))
9069  +0.0
9070  """
9071  ctx = _get_ctx(ctx)
9072  if is_fp_sort(exp):
9073  fps = exp
9074  exp = None
9075  elif fps is None:
9076  fps = _dflt_fps(ctx)
9077  _z3_assert(is_fp_sort(fps), "sort mismatch")
9078  if exp is None:
9079  exp = 0
9080  val = _to_float_str(sig)
9081  if val == "NaN" or val == "nan":
9082  return fpNaN(fps)
9083  elif val == "-0.0":
9084  return fpMinusZero(fps)
9085  elif val == "0.0" or val == "+0.0":
9086  return fpPlusZero(fps)
9087  elif val == "+oo" or val == "+inf" or val == "+Inf":
9088  return fpPlusInfinity(fps)
9089  elif val == "-oo" or val == "-inf" or val == "-Inf":
9090  return fpMinusInfinity(fps)
9091  else:
9092  return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
9093 
def FPVal(sig, exp=None, fps=None, ctx=None)
Definition: z3py.py:9050
def fpMinusInfinity(s)
Definition: z3py.py:9023
def fpMinusZero(s)
Definition: z3py.py:9039
def fpPlusZero(s)
Definition: z3py.py:9034
def fpPlusInfinity(s)
Definition: z3py.py:9007
def fpNaN(s)
Definition: z3py.py:8991
def is_fp_sort(s)
Definition: z3py.py:8525
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.

§ fpZero()

def z3py.fpZero (   s,
  negative 
)
Create a Z3 floating-point +0.0 or -0.0 term.

Definition at line 9044 of file z3py.py.

9044 def fpZero(s, negative):
9045  """Create a Z3 floating-point +0.0 or -0.0 term."""
9046  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9047  _z3_assert(isinstance(negative, bool), "expected Boolean flag")
9048  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
9049 
def fpZero(s, negative)
Definition: z3py.py:9044
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, Z3_bool negative)
Create a floating-point zero of sort s.

§ FreshBool()

def z3py.FreshBool (   prefix = 'b',
  ctx = None 
)
Return a fresh Boolean constant in the given context using the given prefix.

If `ctx=None`, then the global context is used.

>>> b1 = FreshBool()
>>> b2 = FreshBool()
>>> eq(b1, b2)
False

Definition at line 1524 of file z3py.py.

1524 def FreshBool(prefix='b', ctx=None):
1525  """Return a fresh Boolean constant in the given context using the given prefix.
1526 
1527  If `ctx=None`, then the global context is used.
1528 
1529  >>> b1 = FreshBool()
1530  >>> b2 = FreshBool()
1531  >>> eq(b1, b2)
1532  False
1533  """
1534  ctx = _get_ctx(ctx)
1535  return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1536 
def FreshBool(prefix='b', ctx=None)
Definition: z3py.py:1524
def BoolSort(ctx=None)
Definition: z3py.py:1449
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.

§ FreshInt()

def z3py.FreshInt (   prefix = 'x',
  ctx = None 
)
Return a fresh integer constant in the given context using the given prefix.

>>> x = FreshInt()
>>> y = FreshInt()
>>> eq(x, y)
False
>>> x.sort()
Int

Definition at line 2898 of file z3py.py.

2898 def FreshInt(prefix='x', ctx=None):
2899  """Return a fresh integer constant in the given context using the given prefix.
2900 
2901  >>> x = FreshInt()
2902  >>> y = FreshInt()
2903  >>> eq(x, y)
2904  False
2905  >>> x.sort()
2906  Int
2907  """
2908  ctx = _get_ctx(ctx)
2909  return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
2910 
def IntSort(ctx=None)
Definition: z3py.py:2760
def FreshInt(prefix='x', ctx=None)
Definition: z3py.py:2898
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.

§ FreshReal()

def z3py.FreshReal (   prefix = 'b',
  ctx = None 
)
Return a fresh real constant in the given context using the given prefix.

>>> x = FreshReal()
>>> y = FreshReal()
>>> eq(x, y)
False
>>> x.sort()
Real

Definition at line 2950 of file z3py.py.

2950 def FreshReal(prefix='b', ctx=None):
2951  """Return a fresh real constant in the given context using the given prefix.
2952 
2953  >>> x = FreshReal()
2954  >>> y = FreshReal()
2955  >>> eq(x, y)
2956  False
2957  >>> x.sort()
2958  Real
2959  """
2960  ctx = _get_ctx(ctx)
2961  return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
2962 
def FreshReal(prefix='b', ctx=None)
Definition: z3py.py:2950
def RealSort(ctx=None)
Definition: z3py.py:2776
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.

§ Full()

def z3py.Full (   s)
Create the regular expression that accepts the universal language
>>> e = Full(ReSort(SeqSort(IntSort())))
>>> print(e)
re.all
>>> e1 = Full(ReSort(StringSort()))
>>> print(e1)
re.all

Definition at line 9865 of file z3py.py.

9865 def Full(s):
9866  """Create the regular expression that accepts the universal language
9867  >>> e = Full(ReSort(SeqSort(IntSort())))
9868  >>> print(e)
9869  re.all
9870  >>> e1 = Full(ReSort(StringSort()))
9871  >>> print(e1)
9872  re.all
9873  """
9874  if isinstance(s, ReSortRef):
9875  return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
9876  raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
9877 
9878 
def Full(s)
Definition: z3py.py:9865
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.

§ Function()

def z3py.Function (   name,
  sig 
)
Create a new Z3 uninterpreted function with the given sorts.

>>> f = Function('f', IntSort(), IntSort())
>>> f(f(0))
f(f(0))

Definition at line 774 of file z3py.py.

Referenced by ModelRef.__getitem__(), ModelRef.__len__(), FuncEntry.arg_value(), FuncInterp.arity(), FuncEntry.as_list(), FuncInterp.as_list(), QuantifierRef.body(), QuantifierRef.children(), ModelRef.decls(), FuncInterp.else_value(), FuncInterp.entry(), Exists(), ForAll(), ModelRef.get_interp(), get_map_func(), QuantifierRef.is_forall(), is_map(), is_pattern(), is_quantifier(), Map(), MultiPattern(), FuncEntry.num_args(), FuncInterp.num_entries(), QuantifierRef.num_patterns(), QuantifierRef.num_vars(), QuantifierRef.pattern(), FuncEntry.value(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and QuantifierRef.weight().

774 def Function(name, *sig):
775  """Create a new Z3 uninterpreted function with the given sorts.
776 
777  >>> f = Function('f', IntSort(), IntSort())
778  >>> f(f(0))
779  f(f(0))
780  """
781  sig = _get_args(sig)
782  if __debug__:
783  _z3_assert(len(sig) > 0, "At least two arguments expected")
784  arity = len(sig) - 1
785  rng = sig[arity]
786  if __debug__:
787  _z3_assert(is_sort(rng), "Z3 sort expected")
788  dom = (Sort * arity)()
789  for i in range(arity):
790  if __debug__:
791  _z3_assert(is_sort(sig[i]), "Z3 sort expected")
792  dom[i] = sig[i].ast
793  ctx = rng.ctx
794  return FuncDeclRef(Z3_mk_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
795 
def Function(name, sig)
Definition: z3py.py:774
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def to_symbol(s, ctx=None)
Definition: z3py.py:101
Z3_func_decl Z3_API Z3_mk_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a constant or function.
def is_sort(s)
Definition: z3py.py:575

§ get_as_array_func()

def z3py.get_as_array_func (   n)
Return the function declaration f associated with a Z3 expression of the form (_ as-array f).

Definition at line 5907 of file z3py.py.

5907 def get_as_array_func(n):
5908  """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
5909  if __debug__:
5910  _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
5911  return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
5912 
Z3_func_decl Z3_API Z3_get_as_array_func_decl(Z3_context c, Z3_ast a)
Return the function declaration f associated with a (_ as_array f) node.
def get_as_array_func(n)
Definition: z3py.py:5907
def is_as_array(n)
Definition: z3py.py:5903

§ get_default_fp_sort()

def z3py.get_default_fp_sort (   ctx = None)

Definition at line 8405 of file z3py.py.

8405 def get_default_fp_sort(ctx=None):
8406  return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
8407 
def FPSort(ebits, sbits, ctx=None)
Definition: z3py.py:8933
def get_default_fp_sort(ctx=None)
Definition: z3py.py:8405

§ get_default_rounding_mode()

def z3py.get_default_rounding_mode (   ctx = None)
Retrieves the global default rounding mode.

Definition at line 8378 of file z3py.py.

8378 def get_default_rounding_mode(ctx=None):
8379  """Retrieves the global default rounding mode."""
8380  global _dflt_rounding_mode
8381  if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
8382  return RTZ(ctx)
8383  elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
8384  return RTN(ctx)
8385  elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
8386  return RTP(ctx)
8387  elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
8388  return RNE(ctx)
8389  elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
8390  return RNA(ctx)
8391 
def RTN(ctx=None)
Definition: z3py.py:8761
def RTZ(ctx=None)
Definition: z3py.py:8769
def RTP(ctx=None)
Definition: z3py.py:8753
def RNA(ctx=None)
Definition: z3py.py:8745
def get_default_rounding_mode(ctx=None)
Definition: z3py.py:8378
def RNE(ctx=None)
Definition: z3py.py:8737

§ get_full_version()

def z3py.get_full_version ( )

Definition at line 84 of file z3py.py.

84 def get_full_version():
85  return Z3_get_full_version()
86 
87 # We use _z3_assert instead of the assert command because we want to
88 # produce nice error messages in Z3Py at rise4fun.com
Z3_string Z3_API Z3_get_full_version(void)
Return a string that fully describes the version of Z3 in use.
def get_full_version()
Definition: z3py.py:84

§ get_map_func()

def z3py.get_map_func (   a)
Return the function declaration associated with a Z3 map array expression.

>>> f = Function('f', IntSort(), IntSort())
>>> b = Array('b', IntSort(), IntSort())
>>> a  = Map(f, b)
>>> eq(f, get_map_func(a))
True
>>> get_map_func(a)
f
>>> get_map_func(a)(0)
f(0)

Definition at line 4204 of file z3py.py.

4204 def get_map_func(a):
4205  """Return the function declaration associated with a Z3 map array expression.
4206 
4207  >>> f = Function('f', IntSort(), IntSort())
4208  >>> b = Array('b', IntSort(), IntSort())
4209  >>> a = Map(f, b)
4210  >>> eq(f, get_map_func(a))
4211  True
4212  >>> get_map_func(a)
4213  f
4214  >>> get_map_func(a)(0)
4215  f(0)
4216  """
4217  if __debug__:
4218  _z3_assert(is_map(a), "Z3 array map expression expected.")
4219  return FuncDeclRef(Z3_to_func_decl(a.ctx_ref(), Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0)), a.ctx)
4220 
Z3_func_decl Z3_API Z3_to_func_decl(Z3_context c, Z3_ast a)
Convert an AST into a FUNC_DECL_AST. This is just type casting.
def is_map(a)
Definition: z3py.py:4181
def get_map_func(a)
Definition: z3py.py:4204
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.

§ get_param()

def z3py.get_param (   name)
Return the value of a Z3 global (or module) parameter

>>> get_param('nlsat.reorder')
'true'

Definition at line 262 of file z3py.py.

262 def get_param(name):
263  """Return the value of a Z3 global (or module) parameter
264 
265  >>> get_param('nlsat.reorder')
266  'true'
267  """
268  ptr = (ctypes.c_char_p * 1)()
269  if Z3_global_param_get(str(name), ptr):
270  r = z3core._to_pystr(ptr[0])
271  return r
272  raise Z3Exception("failed to retrieve value for '%s'" % name)
273 
Z3_bool Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value)
Get a global (or module) parameter.
def get_param(name)
Definition: z3py.py:262

§ get_var_index()

def z3py.get_var_index (   a)
Return the de-Bruijn index of the Z3 bounded variable `a`.

>>> x = Int('x')
>>> y = Int('y')
>>> is_var(x)
False
>>> is_const(x)
True
>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> # Z3 replaces x and y with bound variables when ForAll is executed.
>>> q = ForAll([x, y], f(x, y) == x + y)
>>> q.body()
f(Var(1), Var(0)) == Var(1) + Var(0)
>>> b = q.body()
>>> b.arg(0)
f(Var(1), Var(0))
>>> v1 = b.arg(0).arg(0)
>>> v2 = b.arg(0).arg(1)
>>> v1
Var(1)
>>> v2
Var(0)
>>> get_var_index(v1)
1
>>> get_var_index(v2)
0

Definition at line 1136 of file z3py.py.

1136 def get_var_index(a):
1137  """Return the de-Bruijn index of the Z3 bounded variable `a`.
1138 
1139  >>> x = Int('x')
1140  >>> y = Int('y')
1141  >>> is_var(x)
1142  False
1143  >>> is_const(x)
1144  True
1145  >>> f = Function('f', IntSort(), IntSort(), IntSort())
1146  >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1147  >>> q = ForAll([x, y], f(x, y) == x + y)
1148  >>> q.body()
1149  f(Var(1), Var(0)) == Var(1) + Var(0)
1150  >>> b = q.body()
1151  >>> b.arg(0)
1152  f(Var(1), Var(0))
1153  >>> v1 = b.arg(0).arg(0)
1154  >>> v2 = b.arg(0).arg(1)
1155  >>> v1
1156  Var(1)
1157  >>> v2
1158  Var(0)
1159  >>> get_var_index(v1)
1160  1
1161  >>> get_var_index(v2)
1162  0
1163  """
1164  if __debug__:
1165  _z3_assert(is_var(a), "Z3 bound variable expected")
1166  return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
1167 
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.
def get_var_index(a)
Definition: z3py.py:1136
def is_var(a)
Definition: z3py.py:1112

§ get_version()

def z3py.get_version ( )

Definition at line 76 of file z3py.py.

76 def get_version():
77  major = ctypes.c_uint(0)
78  minor = ctypes.c_uint(0)
79  build = ctypes.c_uint(0)
80  rev = ctypes.c_uint(0)
81  Z3_get_version(major, minor, build, rev)
82  return (major.value, minor.value, build.value, rev.value)
83 
def get_version()
Definition: z3py.py:76
void Z3_API Z3_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.

§ get_version_string()

def z3py.get_version_string ( )

Definition at line 68 of file z3py.py.

68 def get_version_string():
69  major = ctypes.c_uint(0)
70  minor = ctypes.c_uint(0)
71  build = ctypes.c_uint(0)
72  rev = ctypes.c_uint(0)
73  Z3_get_version(major, minor, build, rev)
74  return "%s.%s.%s" % (major.value, minor.value, build.value)
75 
def get_version_string()
Definition: z3py.py:68
void Z3_API Z3_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.

§ help_simplify()

def z3py.help_simplify ( )
Return a string describing all options available for Z3 `simplify` procedure.

Definition at line 7817 of file z3py.py.

7817 def help_simplify():
7818  """Return a string describing all options available for Z3 `simplify` procedure."""
7819  print(Z3_simplify_get_help(main_ctx().ref()))
7820 
def main_ctx()
Definition: z3py.py:203
def help_simplify()
Definition: z3py.py:7817
Z3_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.

§ If()

def z3py.If (   a,
  b,
  c,
  ctx = None 
)
Create a Z3 if-then-else expression.

>>> x = Int('x')
>>> y = Int('y')
>>> max = If(x > y, x, y)
>>> max
If(x > y, x, y)
>>> simplify(max)
If(x <= y, y, x)

Definition at line 1180 of file z3py.py.

Referenced by BoolRef.__mul__(), and BV2Int().

1180 def If(a, b, c, ctx=None):
1181  """Create a Z3 if-then-else expression.
1182 
1183  >>> x = Int('x')
1184  >>> y = Int('y')
1185  >>> max = If(x > y, x, y)
1186  >>> max
1187  If(x > y, x, y)
1188  >>> simplify(max)
1189  If(x <= y, y, x)
1190  """
1191  if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1192  return Cond(a, b, c, ctx)
1193  else:
1194  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1195  s = BoolSort(ctx)
1196  a = s.cast(a)
1197  b, c = _coerce_exprs(b, c, ctx)
1198  if __debug__:
1199  _z3_assert(a.ctx == b.ctx, "Context mismatch")
1200  return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1201 
def If(a, b, c, ctx=None)
Definition: z3py.py:1180
def Cond(p, t1, t2, ctx=None)
Definition: z3py.py:7777
Z3_ast Z3_API Z3_mk_ite(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Create an AST node representing an if-then-else: ite(t1, t2, t3).
def BoolSort(ctx=None)
Definition: z3py.py:1449

§ Implies()

def z3py.Implies (   a,
  b,
  ctx = None 
)
Create a Z3 implies expression.

>>> p, q = Bools('p q')
>>> Implies(p, q)
Implies(p, q)
>>> simplify(Implies(p, q))
Or(Not(p), q)

Definition at line 1537 of file z3py.py.

Referenced by Fixedpoint.add_rule(), Solver.consequences(), Store(), Solver.unsat_core(), Update(), and Fixedpoint.update_rule().

1537 def Implies(a, b, ctx=None):
1538  """Create a Z3 implies expression.
1539 
1540  >>> p, q = Bools('p q')
1541  >>> Implies(p, q)
1542  Implies(p, q)
1543  >>> simplify(Implies(p, q))
1544  Or(Not(p), q)
1545  """
1546  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1547  s = BoolSort(ctx)
1548  a = s.cast(a)
1549  b = s.cast(b)
1550  return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1551 
def Implies(a, b, ctx=None)
Definition: z3py.py:1537
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
def BoolSort(ctx=None)
Definition: z3py.py:1449

§ IndexOf() [1/2]

def z3py.IndexOf (   s,
  substr 
)

Definition at line 9944 of file z3py.py.

Referenced by IndexOf().

9944 def IndexOf(s, substr):
9945  return IndexOf(s, substr, IntVal(0))
9946 
def IntVal(val, ctx=None)
Definition: z3py.py:2807
def IndexOf(s, substr)
Definition: z3py.py:9944

§ IndexOf() [2/2]

def z3py.IndexOf (   s,
  substr,
  offset 
)
Retrieve the index of substring within a string starting at a specified offset.
>>> simplify(IndexOf("abcabc", "bc", 0))
1
>>> simplify(IndexOf("abcabc", "bc", 2))
4

Definition at line 9947 of file z3py.py.

9947 def IndexOf(s, substr, offset):
9948  """Retrieve the index of substring within a string starting at a specified offset.
9949  >>> simplify(IndexOf("abcabc", "bc", 0))
9950  1
9951  >>> simplify(IndexOf("abcabc", "bc", 2))
9952  4
9953  """
9954  ctx = None
9955  if is_expr(offset):
9956  ctx = offset.ctx
9957  ctx = _get_ctx2(s, substr, ctx)
9958  s = _coerce_seq(s, ctx)
9959  substr = _coerce_seq(substr, ctx)
9960  if _is_int(offset):
9961  offset = IntVal(offset, ctx)
9962  return SeqRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
9963 
def IntVal(val, ctx=None)
Definition: z3py.py:2807
def IndexOf(s, substr)
Definition: z3py.py:9944
Z3_ast Z3_API Z3_mk_seq_index(Z3_context c, Z3_ast s, Z3_ast substr, Z3_ast offset)
Return index of first occurrence of substr in s starting from offset offset. If s does not contain su...
def is_expr(a)
Definition: z3py.py:1047

§ InRe()

def z3py.InRe (   s,
  re 
)
Create regular expression membership test
>>> re = Union(Re("a"),Re("b"))
>>> print (simplify(InRe("a", re)))
True
>>> print (simplify(InRe("b", re)))
True
>>> print (simplify(InRe("c", re)))
False

Definition at line 10034 of file z3py.py.

Referenced by Loop(), Option(), Plus(), Star(), and Union().

10034 def InRe(s, re):
10035  """Create regular expression membership test
10036  >>> re = Union(Re("a"),Re("b"))
10037  >>> print (simplify(InRe("a", re)))
10038  True
10039  >>> print (simplify(InRe("b", re)))
10040  True
10041  >>> print (simplify(InRe("c", re)))
10042  False
10043  """
10044  s = _coerce_seq(s, re.ctx)
10045  return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
10046 
def InRe(s, re)
Definition: z3py.py:10034
Z3_ast Z3_API Z3_mk_seq_in_re(Z3_context c, Z3_ast seq, Z3_ast re)
Check if seq is in the language generated by the regular expression re.

§ Int()

def z3py.Int (   name,
  ctx = None 
)
Return an integer constant named `name`. If `ctx=None`, then the global context is used.

>>> x = Int('x')
>>> is_int(x)
True
>>> is_int(x + 1)
True

Definition at line 2863 of file z3py.py.

Referenced by ArithRef.__add__(), AstVector.__contains__(), AstMap.__contains__(), ArithRef.__div__(), Statistics.__getattr__(), ArrayRef.__getitem__(), AstVector.__getitem__(), AstMap.__getitem__(), ModelRef.__getitem__(), Statistics.__getitem__(), AstVector.__len__(), AstMap.__len__(), ModelRef.__len__(), Statistics.__len__(), ArithRef.__mod__(), ArithRef.__neg__(), ArithRef.__pos__(), ArithRef.__radd__(), ArithRef.__rdiv__(), ArithRef.__rmod__(), ArithRef.__rsub__(), AstVector.__setitem__(), AstMap.__setitem__(), ArithRef.__sub__(), Goal.add(), Solver.add(), Goal.append(), Solver.append(), Goal.as_expr(), Solver.assert_and_track(), Goal.assert_exprs(), Solver.assert_exprs(), Solver.assertions(), binary_interpolant(), QuantifierRef.body(), BV2Int(), Solver.check(), QuantifierRef.children(), ModelRef.decls(), AstMap.erase(), ModelRef.eval(), ModelRef.evaluate(), Exists(), ForAll(), ModelRef.get_interp(), Statistics.get_key_value(), Goal.insert(), Solver.insert(), Interpolant(), is_arith(), is_arith_sort(), is_bv(), QuantifierRef.is_forall(), is_fp(), ArithSortRef.is_int(), ArithRef.is_int(), is_int(), is_int_value(), is_pattern(), is_quantifier(), ArithSortRef.is_real(), is_real(), is_select(), is_to_real(), K(), AstMap.keys(), Statistics.keys(), Solver.model(), MultiPattern(), QuantifierRef.num_patterns(), QuantifierRef.num_vars(), QuantifierRef.pattern(), Solver.pop(), AstVector.push(), Solver.push(), Solver.reason_unknown(), AstMap.reset(), Solver.reset(), AstVector.resize(), Select(), sequence_interpolant(), Solver.sexpr(), Goal.simplify(), ArithRef.sort(), Solver.statistics(), Store(), ToReal(), Goal.translate(), AstVector.translate(), tree_interpolant(), Update(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and QuantifierRef.weight().

2863 def Int(name, ctx=None):
2864  """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
2865 
2866  >>> x = Int('x')
2867  >>> is_int(x)
2868  True
2869  >>> is_int(x + 1)
2870  True
2871  """
2872  ctx = _get_ctx(ctx)
2873  return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
2874 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:101
def Int(name, ctx=None)
Definition: z3py.py:2863
def IntSort(ctx=None)
Definition: z3py.py:2760

§ Int2BV()

def z3py.Int2BV (   a,
  num_bits 
)
Return the z3 expression Int2BV(a, num_bits).
It is a bit-vector of width num_bits and represents the
modulo of a by 2^num_bits

Definition at line 3585 of file z3py.py.

3585 def Int2BV(a, num_bits):
3586  """Return the z3 expression Int2BV(a, num_bits).
3587  It is a bit-vector of width num_bits and represents the
3588  modulo of a by 2^num_bits
3589  """
3590  ctx = a.ctx
3591  return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
3592 
Z3_ast Z3_API Z3_mk_int2bv(Z3_context c, unsigned n, Z3_ast t1)
Create an n bit bit-vector from the integer argument t1.
def Int2BV(a, num_bits)
Definition: z3py.py:3585

§ Interpolant()

def z3py.Interpolant (   a,
  ctx = None 
)
Create an interpolation operator.

The argument is an interpolation pattern (see tree_interpolant).

>>> x = Int('x')
>>> print(Interpolant(x>0))
interp(x > 0)

Definition at line 8225 of file z3py.py.

Referenced by tree_interpolant().

8225 def Interpolant(a,ctx=None):
8226  """Create an interpolation operator.
8227 
8228  The argument is an interpolation pattern (see tree_interpolant).
8229 
8230  >>> x = Int('x')
8231  >>> print(Interpolant(x>0))
8232  interp(x > 0)
8233  """
8234  ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
8235  s = BoolSort(ctx)
8236  a = s.cast(a)
8237  return BoolRef(Z3_mk_interpolant(ctx.ref(), a.as_ast()), ctx)
8238 
Z3_ast Z3_API Z3_mk_interpolant(Z3_context c, Z3_ast a)
Create an AST node marking a formula position for interpolation.
def Interpolant(a, ctx=None)
Definition: z3py.py:8225
def BoolSort(ctx=None)
Definition: z3py.py:1449

§ Ints()

def z3py.Ints (   names,
  ctx = None 
)
Return a tuple of Integer constants.

>>> x, y, z = Ints('x y z')
>>> Sum(x, y, z)
x + y + z

Definition at line 2875 of file z3py.py.

Referenced by ArithRef.__ge__(), Goal.__getitem__(), ArithRef.__gt__(), ArithRef.__le__(), Goal.__len__(), ArithRef.__lt__(), Goal.depth(), Goal.get(), Goal.inconsistent(), is_add(), is_div(), is_ge(), is_gt(), is_idiv(), is_le(), is_lt(), is_mod(), is_mul(), is_sub(), Goal.prec(), Goal.size(), Store(), Solver.unsat_core(), and Update().

2875 def Ints(names, ctx=None):
2876  """Return a tuple of Integer constants.
2877 
2878  >>> x, y, z = Ints('x y z')
2879  >>> Sum(x, y, z)
2880  x + y + z
2881  """
2882  ctx = _get_ctx(ctx)
2883  if isinstance(names, str):
2884  names = names.split(" ")
2885  return [Int(name, ctx) for name in names]
2886 
def Int(name, ctx=None)
Definition: z3py.py:2863
def Ints(names, ctx=None)
Definition: z3py.py:2875

§ IntSort()

def z3py.IntSort (   ctx = None)
Return the integer sort in the given context. If `ctx=None`, then the global context is used.

>>> IntSort()
Int
>>> x = Const('x', IntSort())
>>> is_int(x)
True
>>> x.sort() == IntSort()
True
>>> x.sort() == BoolSort()
False

Definition at line 2760 of file z3py.py.

Referenced by ArrayRef.__getitem__(), ModelRef.__getitem__(), ModelRef.__len__(), DatatypeSortRef.accessor(), FuncEntry.arg_value(), FuncInterp.arity(), Array(), ArraySort(), FuncEntry.as_list(), FuncInterp.as_list(), QuantifierRef.body(), ArithSortRef.cast(), QuantifierRef.children(), DatatypeSortRef.constructor(), Datatype.create(), CreateDatatypes(), Datatype.declare(), ModelRef.decls(), Default(), ArraySortRef.domain(), ArrayRef.domain(), FuncInterp.else_value(), Empty(), FuncInterp.entry(), Exists(), ForAll(), Full(), ModelRef.get_interp(), get_map_func(), Context.getIntSort(), is_arith_sort(), is_array(), is_bv_sort(), is_const_array(), is_default(), QuantifierRef.is_forall(), is_fp_sort(), is_K(), is_map(), is_pattern(), is_quantifier(), is_select(), is_store(), SeqSortRef.is_string(), K(), Map(), Context.mkIntSort(), MultiPattern(), FuncEntry.num_args(), DatatypeSortRef.num_constructors(), FuncInterp.num_entries(), QuantifierRef.num_patterns(), QuantifierRef.num_vars(), QuantifierRef.pattern(), ArraySortRef.range(), ArrayRef.range(), DatatypeSortRef.recognizer(), Select(), SeqSort(), ArrayRef.sort(), Store(), Sort.translate(), Update(), FuncEntry.value(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and QuantifierRef.weight().

2760 def IntSort(ctx=None):
2761  """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
2762 
2763  >>> IntSort()
2764  Int
2765  >>> x = Const('x', IntSort())
2766  >>> is_int(x)
2767  True
2768  >>> x.sort() == IntSort()
2769  True
2770  >>> x.sort() == BoolSort()
2771  False
2772  """
2773  ctx = _get_ctx(ctx)
2774  return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
2775 
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
def IntSort(ctx=None)
Definition: z3py.py:2760

§ IntToStr()

def z3py.IntToStr (   s)
Convert integer expression to string

Definition at line 9989 of file z3py.py.

Referenced by StrToInt().

9989 def IntToStr(s):
9990  """Convert integer expression to string"""
9991  if not is_expr(s):
9992  s = _py2expr(s)
9993  return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
9994 
9995 
def IntToStr(s)
Definition: z3py.py:9989
def is_expr(a)
Definition: z3py.py:1047
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.

§ IntVal()

def z3py.IntVal (   val,
  ctx = None 
)
Return a Z3 integer value. If `ctx=None`, then the global context is used.

>>> IntVal(1)
1
>>> IntVal("100")
100

Definition at line 2807 of file z3py.py.

Referenced by AstMap.__len__(), ArithRef.__mod__(), ArithRef.__pow__(), ArithRef.__rpow__(), AstMap.__setitem__(), IntNumRef.as_long(), IntNumRef.as_string(), is_arith(), is_int(), is_int_value(), is_rational_value(), is_seq(), AstMap.keys(), AstMap.reset(), and SeqSort().

2807 def IntVal(val, ctx=None):
2808  """Return a Z3 integer value. If `ctx=None`, then the global context is used.
2809 
2810  >>> IntVal(1)
2811  1
2812  >>> IntVal("100")
2813  100
2814  """
2815  ctx = _get_ctx(ctx)
2816  return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
2817 
def IntVal(val, ctx=None)
Definition: z3py.py:2807
def IntSort(ctx=None)
Definition: z3py.py:2760
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.

§ IntVector()

def z3py.IntVector (   prefix,
  sz,
  ctx = None 
)
Return a list of integer constants of size `sz`.

>>> X = IntVector('x', 3)
>>> X
[x__0, x__1, x__2]
>>> Sum(X)
x__0 + x__1 + x__2

Definition at line 2887 of file z3py.py.

2887 def IntVector(prefix, sz, ctx=None):
2888  """Return a list of integer constants of size `sz`.
2889 
2890  >>> X = IntVector('x', 3)
2891  >>> X
2892  [x__0, x__1, x__2]
2893  >>> Sum(X)
2894  x__0 + x__1 + x__2
2895  """
2896  return [ Int('%s__%s' % (prefix, i)) for i in range(sz) ]
2897 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def Int(name, ctx=None)
Definition: z3py.py:2863
def IntVector(prefix, sz, ctx=None)
Definition: z3py.py:2887

§ is_add()

def z3py.is_add (   a)
Return `True` if `a` is an expression of the form b + c.

>>> x, y = Ints('x y')
>>> is_add(x + y)
True
>>> is_add(x - y)
False

Definition at line 2451 of file z3py.py.

2451 def is_add(a):
2452  """Return `True` if `a` is an expression of the form b + c.
2453 
2454  >>> x, y = Ints('x y')
2455  >>> is_add(x + y)
2456  True
2457  >>> is_add(x - y)
2458  False
2459  """
2460  return is_app_of(a, Z3_OP_ADD)
2461 
def is_app_of(a, k)
Definition: z3py.py:1168
def is_add(a)
Definition: z3py.py:2451

§ is_algebraic_value()

def z3py.is_algebraic_value (   a)
Return `True` if `a` is an algebraic value of sort Real.

>>> is_algebraic_value(RealVal("3/5"))
False
>>> n = simplify(Sqrt(2))
>>> n
1.4142135623?
>>> is_algebraic_value(n)
True

Definition at line 2438 of file z3py.py.

2438 def is_algebraic_value(a):
2439  """Return `True` if `a` is an algebraic value of sort Real.
2440 
2441  >>> is_algebraic_value(RealVal("3/5"))
2442  False
2443  >>> n = simplify(Sqrt(2))
2444  >>> n
2445  1.4142135623?
2446  >>> is_algebraic_value(n)
2447  True
2448  """
2449  return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2450 
def is_arith(a)
Definition: z3py.py:2332
def is_algebraic_value(a)
Definition: z3py.py:2438

§ is_and()

def z3py.is_and (   a)
Return `True` if `a` is a Z3 and expression.

>>> p, q = Bools('p q')
>>> is_and(And(p, q))
True
>>> is_and(Or(p, q))
False

Definition at line 1396 of file z3py.py.

1396 def is_and(a):
1397  """Return `True` if `a` is a Z3 and expression.
1398 
1399  >>> p, q = Bools('p q')
1400  >>> is_and(And(p, q))
1401  True
1402  >>> is_and(Or(p, q))
1403  False
1404  """
1405  return is_app_of(a, Z3_OP_AND)
1406 
def is_and(a)
Definition: z3py.py:1396
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_app()

def z3py.is_app (   a)
Return `True` if `a` is a Z3 function application.

Note that, constants are function applications with 0 arguments.

>>> a = Int('a')
>>> is_app(a)
True
>>> is_app(a + 1)
True
>>> is_app(IntSort())
False
>>> is_app(1)
False
>>> is_app(IntVal(1))
True
>>> x = Int('x')
>>> is_app(ForAll(x, x >= 0))
False

Definition at line 1069 of file z3py.py.

Referenced by ExprRef.arg(), ExprRef.children(), ExprRef.decl(), expr.hi(), is_app_of(), expr.is_const(), is_const(), expr.lo(), ExprRef.num_args(), and expr.operator Z3_app().

1069 def is_app(a):
1070  """Return `True` if `a` is a Z3 function application.
1071 
1072  Note that, constants are function applications with 0 arguments.
1073 
1074  >>> a = Int('a')
1075  >>> is_app(a)
1076  True
1077  >>> is_app(a + 1)
1078  True
1079  >>> is_app(IntSort())
1080  False
1081  >>> is_app(1)
1082  False
1083  >>> is_app(IntVal(1))
1084  True
1085  >>> x = Int('x')
1086  >>> is_app(ForAll(x, x >= 0))
1087  False
1088  """
1089  if not isinstance(a, ExprRef):
1090  return False
1091  k = _ast_kind(a.ctx, a)
1092  return k == Z3_NUMERAL_AST or k == Z3_APP_AST
1093 
def is_app(a)
Definition: z3py.py:1069

§ is_app_of()

def z3py.is_app_of (   a,
  k 
)
Return `True` if `a` is an application of the given kind `k`.

>>> x = Int('x')
>>> n = x + 1
>>> is_app_of(n, Z3_OP_ADD)
True
>>> is_app_of(n, Z3_OP_MUL)
False

Definition at line 1168 of file z3py.py.

Referenced by is_and(), is_distinct(), is_eq(), is_false(), is_not(), is_or(), and is_true().

1168 def is_app_of(a, k):
1169  """Return `True` if `a` is an application of the given kind `k`.
1170 
1171  >>> x = Int('x')
1172  >>> n = x + 1
1173  >>> is_app_of(n, Z3_OP_ADD)
1174  True
1175  >>> is_app_of(n, Z3_OP_MUL)
1176  False
1177  """
1178  return is_app(a) and a.decl().kind() == k
1179 
def is_app(a)
Definition: z3py.py:1069
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_arith()

def z3py.is_arith (   a)
Return `True` if `a` is an arithmetical expression.

>>> x = Int('x')
>>> is_arith(x)
True
>>> is_arith(x + 1)
True
>>> is_arith(1)
False
>>> is_arith(IntVal(1))
True
>>> y = Real('y')
>>> is_arith(y)
True
>>> is_arith(y + 1)
True

Definition at line 2332 of file z3py.py.

2332 def is_arith(a):
2333  """Return `True` if `a` is an arithmetical expression.
2334 
2335  >>> x = Int('x')
2336  >>> is_arith(x)
2337  True
2338  >>> is_arith(x + 1)
2339  True
2340  >>> is_arith(1)
2341  False
2342  >>> is_arith(IntVal(1))
2343  True
2344  >>> y = Real('y')
2345  >>> is_arith(y)
2346  True
2347  >>> is_arith(y + 1)
2348  True
2349  """
2350  return isinstance(a, ArithRef)
2351 
def is_arith(a)
Definition: z3py.py:2332

§ is_arith_sort()

def z3py.is_arith_sort (   s)
Return `True` if s is an arithmetical sort (type).

>>> is_arith_sort(IntSort())
True
>>> is_arith_sort(RealSort())
True
>>> is_arith_sort(BoolSort())
False
>>> n = Int('x') + 1
>>> is_arith_sort(n.sort())
True

Definition at line 2035 of file z3py.py.

2035 def is_arith_sort(s):
2036  """Return `True` if s is an arithmetical sort (type).
2037 
2038  >>> is_arith_sort(IntSort())
2039  True
2040  >>> is_arith_sort(RealSort())
2041  True
2042  >>> is_arith_sort(BoolSort())
2043  False
2044  >>> n = Int('x') + 1
2045  >>> is_arith_sort(n.sort())
2046  True
2047  """
2048  return isinstance(s, ArithSortRef)
2049 
def is_arith_sort(s)
Definition: z3py.py:2035

§ is_array()

def z3py.is_array (   a)
Return `True` if `a` is a Z3 array expression.

>>> a = Array('a', IntSort(), IntSort())
>>> is_array(a)
True
>>> is_array(Store(a, 0, 1))
True
>>> is_array(a[0])
False

Definition at line 4144 of file z3py.py.

Referenced by sort.array_domain(), and sort.array_range().

4144 def is_array(a):
4145  """Return `True` if `a` is a Z3 array expression.
4146 
4147  >>> a = Array('a', IntSort(), IntSort())
4148  >>> is_array(a)
4149  True
4150  >>> is_array(Store(a, 0, 1))
4151  True
4152  >>> is_array(a[0])
4153  False
4154  """
4155  return isinstance(a, ArrayRef)
4156 
def is_array(a)
Definition: z3py.py:4144

§ is_as_array()

def z3py.is_as_array (   n)
Return true if n is a Z3 expression of the form (_ as-array f).

Definition at line 5903 of file z3py.py.

5903 def is_as_array(n):
5904  """Return true if n is a Z3 expression of the form (_ as-array f)."""
5905  return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
5906 
def is_as_array(n)
Definition: z3py.py:5903
Z3_bool Z3_API Z3_is_as_array(Z3_context c, Z3_ast a)
The (_ as-array f) AST node is a construct for assigning interpretations for arrays in Z3...

§ is_ast()

def z3py.is_ast (   a)
Return `True` if `a` is an AST node.

>>> is_ast(10)
False
>>> is_ast(IntVal(10))
True
>>> is_ast(Int('x'))
True
>>> is_ast(BoolSort())
True
>>> is_ast(Function('f', IntSort(), IntSort()))
True
>>> is_ast("x")
False
>>> is_ast(Solver())
False

Definition at line 392 of file z3py.py.

Referenced by AstRef.eq(), and eq().

392 def is_ast(a):
393  """Return `True` if `a` is an AST node.
394 
395  >>> is_ast(10)
396  False
397  >>> is_ast(IntVal(10))
398  True
399  >>> is_ast(Int('x'))
400  True
401  >>> is_ast(BoolSort())
402  True
403  >>> is_ast(Function('f', IntSort(), IntSort()))
404  True
405  >>> is_ast("x")
406  False
407  >>> is_ast(Solver())
408  False
409  """
410  return isinstance(a, AstRef)
411 
def is_ast(a)
Definition: z3py.py:392

§ is_bool()

def z3py.is_bool (   a)
Return `True` if `a` is a Z3 Boolean expression.

>>> p = Bool('p')
>>> is_bool(p)
True
>>> q = Bool('q')
>>> is_bool(And(p, q))
True
>>> x = Real('x')
>>> is_bool(x)
False
>>> is_bool(x == 0)
True

Definition at line 1349 of file z3py.py.

Referenced by BoolSort(), and prove().

1349 def is_bool(a):
1350  """Return `True` if `a` is a Z3 Boolean expression.
1351 
1352  >>> p = Bool('p')
1353  >>> is_bool(p)
1354  True
1355  >>> q = Bool('q')
1356  >>> is_bool(And(p, q))
1357  True
1358  >>> x = Real('x')
1359  >>> is_bool(x)
1360  False
1361  >>> is_bool(x == 0)
1362  True
1363  """
1364  return isinstance(a, BoolRef)
1365 
def is_bool(a)
Definition: z3py.py:1349

§ is_bv()

def z3py.is_bv (   a)
Return `True` if `a` is a Z3 bit-vector expression.

>>> b = BitVec('b', 32)
>>> is_bv(b)
True
>>> is_bv(b + 10)
True
>>> is_bv(Int('x'))
False

Definition at line 3536 of file z3py.py.

Referenced by BitVec(), sort.bv_size(), fpToIEEEBV(), fpToSBV(), fpToUBV(), Product(), and Sum().

3536 def is_bv(a):
3537  """Return `True` if `a` is a Z3 bit-vector expression.
3538 
3539  >>> b = BitVec('b', 32)
3540  >>> is_bv(b)
3541  True
3542  >>> is_bv(b + 10)
3543  True
3544  >>> is_bv(Int('x'))
3545  False
3546  """
3547  return isinstance(a, BitVecRef)
3548 
def is_bv(a)
Definition: z3py.py:3536

§ is_bv_sort()

def z3py.is_bv_sort (   s)
Return True if `s` is a Z3 bit-vector sort.

>>> is_bv_sort(BitVecSort(32))
True
>>> is_bv_sort(IntSort())
False

Definition at line 3075 of file z3py.py.

3075 def is_bv_sort(s):
3076  """Return True if `s` is a Z3 bit-vector sort.
3077 
3078  >>> is_bv_sort(BitVecSort(32))
3079  True
3080  >>> is_bv_sort(IntSort())
3081  False
3082  """
3083  return isinstance(s, BitVecSortRef)
3084 
def is_bv_sort(s)
Definition: z3py.py:3075

§ is_bv_value()

def z3py.is_bv_value (   a)
Return `True` if `a` is a Z3 bit-vector numeral value.

>>> b = BitVec('b', 32)
>>> is_bv_value(b)
False
>>> b = BitVecVal(10, 32)
>>> b
10
>>> is_bv_value(b)
True

Definition at line 3549 of file z3py.py.

3549 def is_bv_value(a):
3550  """Return `True` if `a` is a Z3 bit-vector numeral value.
3551 
3552  >>> b = BitVec('b', 32)
3553  >>> is_bv_value(b)
3554  False
3555  >>> b = BitVecVal(10, 32)
3556  >>> b
3557  10
3558  >>> is_bv_value(b)
3559  True
3560  """
3561  return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
3562 
def is_bv_value(a)
Definition: z3py.py:3549
def is_bv(a)
Definition: z3py.py:3536

§ is_const()

def z3py.is_const (   a)
Return `True` if `a` is Z3 constant/variable expression.

>>> a = Int('a')
>>> is_const(a)
True
>>> is_const(a + 1)
False
>>> is_const(1)
False
>>> is_const(IntVal(1))
True
>>> x = Int('x')
>>> is_const(ForAll(x, x >= 0))
False

Definition at line 1094 of file z3py.py.

Referenced by prove().

1094 def is_const(a):
1095  """Return `True` if `a` is Z3 constant/variable expression.
1096 
1097  >>> a = Int('a')
1098  >>> is_const(a)
1099  True
1100  >>> is_const(a + 1)
1101  False
1102  >>> is_const(1)
1103  False
1104  >>> is_const(IntVal(1))
1105  True
1106  >>> x = Int('x')
1107  >>> is_const(ForAll(x, x >= 0))
1108  False
1109  """
1110  return is_app(a) and a.num_args() == 0
1111 
def is_app(a)
Definition: z3py.py:1069
def is_const(a)
Definition: z3py.py:1094

§ is_const_array()

def z3py.is_const_array (   a)
Return `True` if `a` is a Z3 constant array.

>>> a = K(IntSort(), 10)
>>> is_const_array(a)
True
>>> a = Array('a', IntSort(), IntSort())
>>> is_const_array(a)
False

Definition at line 4157 of file z3py.py.

4157 def is_const_array(a):
4158  """Return `True` if `a` is a Z3 constant array.
4159 
4160  >>> a = K(IntSort(), 10)
4161  >>> is_const_array(a)
4162  True
4163  >>> a = Array('a', IntSort(), IntSort())
4164  >>> is_const_array(a)
4165  False
4166  """
4167  return is_app_of(a, Z3_OP_CONST_ARRAY)
4168 
def is_const_array(a)
Definition: z3py.py:4157
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_default()

def z3py.is_default (   a)
Return `True` if `a` is a Z3 default array expression.
>>> d = Default(K(IntSort(), 10))
>>> is_default(d)
True

Definition at line 4196 of file z3py.py.

4196 def is_default(a):
4197  """Return `True` if `a` is a Z3 default array expression.
4198  >>> d = Default(K(IntSort(), 10))
4199  >>> is_default(d)
4200  True
4201  """
4202  return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4203 
def is_default(a)
Definition: z3py.py:4196
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_distinct()

def z3py.is_distinct (   a)
Return `True` if `a` is a Z3 distinct expression.

>>> x, y, z = Ints('x y z')
>>> is_distinct(x == y)
False
>>> is_distinct(Distinct(x, y, z))
True

Definition at line 1438 of file z3py.py.

1438 def is_distinct(a):
1439  """Return `True` if `a` is a Z3 distinct expression.
1440 
1441  >>> x, y, z = Ints('x y z')
1442  >>> is_distinct(x == y)
1443  False
1444  >>> is_distinct(Distinct(x, y, z))
1445  True
1446  """
1447  return is_app_of(a, Z3_OP_DISTINCT)
1448 
def is_distinct(a)
Definition: z3py.py:1438
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_div()

def z3py.is_div (   a)
Return `True` if `a` is an expression of the form b / c.

>>> x, y = Reals('x y')
>>> is_div(x / y)
True
>>> is_div(x + y)
False
>>> x, y = Ints('x y')
>>> is_div(x / y)
False
>>> is_idiv(x / y)
True

Definition at line 2484 of file z3py.py.

2484 def is_div(a):
2485  """Return `True` if `a` is an expression of the form b / c.
2486 
2487  >>> x, y = Reals('x y')
2488  >>> is_div(x / y)
2489  True
2490  >>> is_div(x + y)
2491  False
2492  >>> x, y = Ints('x y')
2493  >>> is_div(x / y)
2494  False
2495  >>> is_idiv(x / y)
2496  True
2497  """
2498  return is_app_of(a, Z3_OP_DIV)
2499 
def is_div(a)
Definition: z3py.py:2484
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_eq()

def z3py.is_eq (   a)
Return `True` if `a` is a Z3 equality expression.

>>> x, y = Ints('x y')
>>> is_eq(x == y)
True

Definition at line 1429 of file z3py.py.

Referenced by AstRef.__bool__().

1429 def is_eq(a):
1430  """Return `True` if `a` is a Z3 equality expression.
1431 
1432  >>> x, y = Ints('x y')
1433  >>> is_eq(x == y)
1434  True
1435  """
1436  return is_app_of(a, Z3_OP_EQ)
1437 
def is_eq(a)
Definition: z3py.py:1429
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_expr()

def z3py.is_expr (   a)
Return `True` if `a` is a Z3 expression.

>>> a = Int('a')
>>> is_expr(a)
True
>>> is_expr(a + 1)
True
>>> is_expr(IntSort())
False
>>> is_expr(1)
False
>>> is_expr(IntVal(1))
True
>>> x = Int('x')
>>> is_expr(ForAll(x, x >= 0))
True
>>> is_expr(FPVal(1.0))
True

Definition at line 1047 of file z3py.py.

Referenced by SortRef.cast(), BoolSortRef.cast(), ExprRef.children(), is_var(), simplify(), substitute(), and substitute_vars().

1047 def is_expr(a):
1048  """Return `True` if `a` is a Z3 expression.
1049 
1050  >>> a = Int('a')
1051  >>> is_expr(a)
1052  True
1053  >>> is_expr(a + 1)
1054  True
1055  >>> is_expr(IntSort())
1056  False
1057  >>> is_expr(1)
1058  False
1059  >>> is_expr(IntVal(1))
1060  True
1061  >>> x = Int('x')
1062  >>> is_expr(ForAll(x, x >= 0))
1063  True
1064  >>> is_expr(FPVal(1.0))
1065  True
1066  """
1067  return isinstance(a, ExprRef)
1068 
def is_expr(a)
Definition: z3py.py:1047

§ is_false()

def z3py.is_false (   a)
Return `True` if `a` is the Z3 false expression.

>>> p = Bool('p')
>>> is_false(p)
False
>>> is_false(False)
False
>>> is_false(BoolVal(False))
True

Definition at line 1383 of file z3py.py.

Referenced by AstRef.__bool__(), and BoolVal().

1383 def is_false(a):
1384  """Return `True` if `a` is the Z3 false expression.
1385 
1386  >>> p = Bool('p')
1387  >>> is_false(p)
1388  False
1389  >>> is_false(False)
1390  False
1391  >>> is_false(BoolVal(False))
1392  True
1393  """
1394  return is_app_of(a, Z3_OP_FALSE)
1395 
def is_app_of(a, k)
Definition: z3py.py:1168
def is_false(a)
Definition: z3py.py:1383

§ is_finite_domain()

def z3py.is_finite_domain (   a)
Return `True` if `a` is a Z3 finite-domain expression.

>>> s = FiniteDomainSort('S', 100)
>>> b = Const('b', s)
>>> is_finite_domain(b)
True
>>> is_finite_domain(Int('x'))
False

Definition at line 6864 of file z3py.py.

Referenced by is_finite_domain_value().

6864 def is_finite_domain(a):
6865  """Return `True` if `a` is a Z3 finite-domain expression.
6866 
6867  >>> s = FiniteDomainSort('S', 100)
6868  >>> b = Const('b', s)
6869  >>> is_finite_domain(b)
6870  True
6871  >>> is_finite_domain(Int('x'))
6872  False
6873  """
6874  return isinstance(a, FiniteDomainRef)
6875 
6876 
def is_finite_domain(a)
Definition: z3py.py:6864

§ is_finite_domain_sort()

def z3py.is_finite_domain_sort (   s)
Return True if `s` is a Z3 finite-domain sort.

>>> is_finite_domain_sort(FiniteDomainSort('S', 100))
True
>>> is_finite_domain_sort(IntSort())
False

Definition at line 6842 of file z3py.py.

Referenced by FiniteDomainVal().

6842 def is_finite_domain_sort(s):
6843  """Return True if `s` is a Z3 finite-domain sort.
6844 
6845  >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
6846  True
6847  >>> is_finite_domain_sort(IntSort())
6848  False
6849  """
6850  return isinstance(s, FiniteDomainSortRef)
6851 
6852 
def is_finite_domain_sort(s)
Definition: z3py.py:6842

§ is_finite_domain_value()

def z3py.is_finite_domain_value (   a)
Return `True` if `a` is a Z3 finite-domain value.

>>> s = FiniteDomainSort('S', 100)
>>> b = Const('b', s)
>>> is_finite_domain_value(b)
False
>>> b = FiniteDomainVal(10, s)
>>> b
10
>>> is_finite_domain_value(b)
True

Definition at line 6917 of file z3py.py.

6917 def is_finite_domain_value(a):
6918  """Return `True` if `a` is a Z3 finite-domain value.
6919 
6920  >>> s = FiniteDomainSort('S', 100)
6921  >>> b = Const('b', s)
6922  >>> is_finite_domain_value(b)
6923  False
6924  >>> b = FiniteDomainVal(10, s)
6925  >>> b
6926  10
6927  >>> is_finite_domain_value(b)
6928  True
6929  """
6930  return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
6931 
6932 
def is_finite_domain_value(a)
Definition: z3py.py:6917
def is_finite_domain(a)
Definition: z3py.py:6864

§ is_fp()

def z3py.is_fp (   a)
Return `True` if `a` is a Z3 floating-point expression.

>>> b = FP('b', FPSort(8, 24))
>>> is_fp(b)
True
>>> is_fp(b + 1.0)
True
>>> is_fp(Int('x'))
False

Definition at line 8906 of file z3py.py.

Referenced by FP(), fpToIEEEBV(), fpToReal(), fpToSBV(), and fpToUBV().

8906 def is_fp(a):
8907  """Return `True` if `a` is a Z3 floating-point expression.
8908 
8909  >>> b = FP('b', FPSort(8, 24))
8910  >>> is_fp(b)
8911  True
8912  >>> is_fp(b + 1.0)
8913  True
8914  >>> is_fp(Int('x'))
8915  False
8916  """
8917  return isinstance(a, FPRef)
8918 
def is_fp(a)
Definition: z3py.py:8906

§ is_fp_sort()

def z3py.is_fp_sort (   s)
Return True if `s` is a Z3 floating-point sort.

>>> is_fp_sort(FPSort(8, 24))
True
>>> is_fp_sort(IntSort())
False

Definition at line 8525 of file z3py.py.

8525 def is_fp_sort(s):
8526  """Return True if `s` is a Z3 floating-point sort.
8527 
8528  >>> is_fp_sort(FPSort(8, 24))
8529  True
8530  >>> is_fp_sort(IntSort())
8531  False
8532  """
8533  return isinstance(s, FPSortRef)
8534 
def is_fp_sort(s)
Definition: z3py.py:8525

§ is_fp_value()

def z3py.is_fp_value (   a)
Return `True` if `a` is a Z3 floating-point numeral value.

>>> b = FP('b', FPSort(8, 24))
>>> is_fp_value(b)
False
>>> b = FPVal(1.0, FPSort(8, 24))
>>> b
1
>>> is_fp_value(b)
True

Definition at line 8919 of file z3py.py.

8919 def is_fp_value(a):
8920  """Return `True` if `a` is a Z3 floating-point numeral value.
8921 
8922  >>> b = FP('b', FPSort(8, 24))
8923  >>> is_fp_value(b)
8924  False
8925  >>> b = FPVal(1.0, FPSort(8, 24))
8926  >>> b
8927  1
8928  >>> is_fp_value(b)
8929  True
8930  """
8931  return is_fp(a) and _is_numeral(a.ctx, a.ast)
8932 
def is_fp_value(a)
Definition: z3py.py:8919
def is_fp(a)
Definition: z3py.py:8906

§ is_fprm()

def z3py.is_fprm (   a)
Return `True` if `a` is a Z3 floating-point rounding mode expression.

>>> rm = RNE()
>>> is_fprm(rm)
True
>>> rm = 1.0
>>> is_fprm(rm)
False

Definition at line 8773 of file z3py.py.

8773 def is_fprm(a):
8774  """Return `True` if `a` is a Z3 floating-point rounding mode expression.
8775 
8776  >>> rm = RNE()
8777  >>> is_fprm(rm)
8778  True
8779  >>> rm = 1.0
8780  >>> is_fprm(rm)
8781  False
8782  """
8783  return isinstance(a, FPRMRef)
8784 
def is_fprm(a)
Definition: z3py.py:8773

§ is_fprm_sort()

def z3py.is_fprm_sort (   s)
Return True if `s` is a Z3 floating-point rounding mode sort.

>>> is_fprm_sort(FPSort(8, 24))
False
>>> is_fprm_sort(RNE().sort())
True

Definition at line 8535 of file z3py.py.

8535 def is_fprm_sort(s):
8536  """Return True if `s` is a Z3 floating-point rounding mode sort.
8537 
8538  >>> is_fprm_sort(FPSort(8, 24))
8539  False
8540  >>> is_fprm_sort(RNE().sort())
8541  True
8542  """
8543  return isinstance(s, FPRMSortRef)
8544 
def is_fprm_sort(s)
Definition: z3py.py:8535

§ is_fprm_value()

def z3py.is_fprm_value (   a)
Return `True` if `a` is a Z3 floating-point rounding mode numeral value.

Definition at line 8785 of file z3py.py.

8785 def is_fprm_value(a):
8786  """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
8787  return is_fprm(a) and _is_numeral(a.ctx, a.ast)
8788 
def is_fprm_value(a)
Definition: z3py.py:8785
def is_fprm(a)
Definition: z3py.py:8773

§ is_func_decl()

def z3py.is_func_decl (   a)
Return `True` if `a` is a Z3 function declaration.

>>> f = Function('f', IntSort(), IntSort())
>>> is_func_decl(f)
True
>>> x = Real('x')
>>> is_func_decl(x)
False

Definition at line 762 of file z3py.py.

Referenced by prove().

762 def is_func_decl(a):
763  """Return `True` if `a` is a Z3 function declaration.
764 
765  >>> f = Function('f', IntSort(), IntSort())
766  >>> is_func_decl(f)
767  True
768  >>> x = Real('x')
769  >>> is_func_decl(x)
770  False
771  """
772  return isinstance(a, FuncDeclRef)
773 
def is_func_decl(a)
Definition: z3py.py:762

§ is_ge()

def z3py.is_ge (   a)
Return `True` if `a` is an expression of the form b >= c.

>>> x, y = Ints('x y')
>>> is_ge(x >= y)
True
>>> is_ge(x == y)
False

Definition at line 2544 of file z3py.py.

2544 def is_ge(a):
2545  """Return `True` if `a` is an expression of the form b >= c.
2546 
2547  >>> x, y = Ints('x y')
2548  >>> is_ge(x >= y)
2549  True
2550  >>> is_ge(x == y)
2551  False
2552  """
2553  return is_app_of(a, Z3_OP_GE)
2554 
def is_ge(a)
Definition: z3py.py:2544
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_gt()

def z3py.is_gt (   a)
Return `True` if `a` is an expression of the form b > c.

>>> x, y = Ints('x y')
>>> is_gt(x > y)
True
>>> is_gt(x == y)
False

Definition at line 2555 of file z3py.py.

2555 def is_gt(a):
2556  """Return `True` if `a` is an expression of the form b > c.
2557 
2558  >>> x, y = Ints('x y')
2559  >>> is_gt(x > y)
2560  True
2561  >>> is_gt(x == y)
2562  False
2563  """
2564  return is_app_of(a, Z3_OP_GT)
2565 
def is_gt(a)
Definition: z3py.py:2555
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_idiv()

def z3py.is_idiv (   a)
Return `True` if `a` is an expression of the form b div c.

>>> x, y = Ints('x y')
>>> is_idiv(x / y)
True
>>> is_idiv(x + y)
False

Definition at line 2500 of file z3py.py.

Referenced by is_div().

2500 def is_idiv(a):
2501  """Return `True` if `a` is an expression of the form b div c.
2502 
2503  >>> x, y = Ints('x y')
2504  >>> is_idiv(x / y)
2505  True
2506  >>> is_idiv(x + y)
2507  False
2508  """
2509  return is_app_of(a, Z3_OP_IDIV)
2510 
def is_idiv(a)
Definition: z3py.py:2500
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_int()

def z3py.is_int (   a)
Return `True` if `a` is an integer expression.

>>> x = Int('x')
>>> is_int(x + 1)
True
>>> is_int(1)
False
>>> is_int(IntVal(1))
True
>>> y = Real('y')
>>> is_int(y)
False
>>> is_int(y + 1)
False

Definition at line 2352 of file z3py.py.

Referenced by Int(), IntSort(), and RealSort().

2352 def is_int(a):
2353  """Return `True` if `a` is an integer expression.
2354 
2355  >>> x = Int('x')
2356  >>> is_int(x + 1)
2357  True
2358  >>> is_int(1)
2359  False
2360  >>> is_int(IntVal(1))
2361  True
2362  >>> y = Real('y')
2363  >>> is_int(y)
2364  False
2365  >>> is_int(y + 1)
2366  False
2367  """
2368  return is_arith(a) and a.is_int()
2369 
def is_arith(a)
Definition: z3py.py:2332
def is_int(a)
Definition: z3py.py:2352

§ is_int_value()

def z3py.is_int_value (   a)
Return `True` if `a` is an integer value of sort Int.

>>> is_int_value(IntVal(1))
True
>>> is_int_value(1)
False
>>> is_int_value(Int('x'))
False
>>> n = Int('x') + 1
>>> n
x + 1
>>> n.arg(1)
1
>>> is_int_value(n.arg(1))
True
>>> is_int_value(RealVal("1/3"))
False
>>> is_int_value(RealVal(1))
False

Definition at line 2394 of file z3py.py.

2394 def is_int_value(a):
2395  """Return `True` if `a` is an integer value of sort Int.
2396 
2397  >>> is_int_value(IntVal(1))
2398  True
2399  >>> is_int_value(1)
2400  False
2401  >>> is_int_value(Int('x'))
2402  False
2403  >>> n = Int('x') + 1
2404  >>> n
2405  x + 1
2406  >>> n.arg(1)
2407  1
2408  >>> is_int_value(n.arg(1))
2409  True
2410  >>> is_int_value(RealVal("1/3"))
2411  False
2412  >>> is_int_value(RealVal(1))
2413  False
2414  """
2415  return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
2416 
def is_int_value(a)
Definition: z3py.py:2394
def is_arith(a)
Definition: z3py.py:2332

§ is_is_int()

def z3py.is_is_int (   a)
Return `True` if `a` is an expression of the form IsInt(b).

>>> x = Real('x')
>>> is_is_int(IsInt(x))
True
>>> is_is_int(x)
False

Definition at line 2566 of file z3py.py.

2566 def is_is_int(a):
2567  """Return `True` if `a` is an expression of the form IsInt(b).
2568 
2569  >>> x = Real('x')
2570  >>> is_is_int(IsInt(x))
2571  True
2572  >>> is_is_int(x)
2573  False
2574  """
2575  return is_app_of(a, Z3_OP_IS_INT)
2576 
def is_app_of(a, k)
Definition: z3py.py:1168
def is_is_int(a)
Definition: z3py.py:2566

§ is_K()

def z3py.is_K (   a)
Return `True` if `a` is a Z3 constant array.

>>> a = K(IntSort(), 10)
>>> is_K(a)
True
>>> a = Array('a', IntSort(), IntSort())
>>> is_K(a)
False

Definition at line 4169 of file z3py.py.

4169 def is_K(a):
4170  """Return `True` if `a` is a Z3 constant array.
4171 
4172  >>> a = K(IntSort(), 10)
4173  >>> is_K(a)
4174  True
4175  >>> a = Array('a', IntSort(), IntSort())
4176  >>> is_K(a)
4177  False
4178  """
4179  return is_app_of(a, Z3_OP_CONST_ARRAY)
4180 
def is_K(a)
Definition: z3py.py:4169
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_le()

def z3py.is_le (   a)
Return `True` if `a` is an expression of the form b <= c.

>>> x, y = Ints('x y')
>>> is_le(x <= y)
True
>>> is_le(x < y)
False

Definition at line 2522 of file z3py.py.

2522 def is_le(a):
2523  """Return `True` if `a` is an expression of the form b <= c.
2524 
2525  >>> x, y = Ints('x y')
2526  >>> is_le(x <= y)
2527  True
2528  >>> is_le(x < y)
2529  False
2530  """
2531  return is_app_of(a, Z3_OP_LE)
2532 
def is_le(a)
Definition: z3py.py:2522
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_lt()

def z3py.is_lt (   a)
Return `True` if `a` is an expression of the form b < c.

>>> x, y = Ints('x y')
>>> is_lt(x < y)
True
>>> is_lt(x == y)
False

Definition at line 2533 of file z3py.py.

2533 def is_lt(a):
2534  """Return `True` if `a` is an expression of the form b < c.
2535 
2536  >>> x, y = Ints('x y')
2537  >>> is_lt(x < y)
2538  True
2539  >>> is_lt(x == y)
2540  False
2541  """
2542  return is_app_of(a, Z3_OP_LT)
2543 
def is_lt(a)
Definition: z3py.py:2533
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_map()

def z3py.is_map (   a)
Return `True` if `a` is a Z3 map array expression.

>>> f = Function('f', IntSort(), IntSort())
>>> b = Array('b', IntSort(), IntSort())
>>> a  = Map(f, b)
>>> a
Map(f, b)
>>> is_map(a)
True
>>> is_map(b)
False

Definition at line 4181 of file z3py.py.

4181 def is_map(a):
4182  """Return `True` if `a` is a Z3 map array expression.
4183 
4184  >>> f = Function('f', IntSort(), IntSort())
4185  >>> b = Array('b', IntSort(), IntSort())
4186  >>> a = Map(f, b)
4187  >>> a
4188  Map(f, b)
4189  >>> is_map(a)
4190  True
4191  >>> is_map(b)
4192  False
4193  """
4194  return is_app_of(a, Z3_OP_ARRAY_MAP)
4195 
def is_map(a)
Definition: z3py.py:4181
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_mod()

def z3py.is_mod (   a)
Return `True` if `a` is an expression of the form b % c.

>>> x, y = Ints('x y')
>>> is_mod(x % y)
True
>>> is_mod(x + y)
False

Definition at line 2511 of file z3py.py.

2511 def is_mod(a):
2512  """Return `True` if `a` is an expression of the form b % c.
2513 
2514  >>> x, y = Ints('x y')
2515  >>> is_mod(x % y)
2516  True
2517  >>> is_mod(x + y)
2518  False
2519  """
2520  return is_app_of(a, Z3_OP_MOD)
2521 
def is_mod(a)
Definition: z3py.py:2511
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_mul()

def z3py.is_mul (   a)
Return `True` if `a` is an expression of the form b * c.

>>> x, y = Ints('x y')
>>> is_mul(x * y)
True
>>> is_mul(x - y)
False

Definition at line 2462 of file z3py.py.

2462 def is_mul(a):
2463  """Return `True` if `a` is an expression of the form b * c.
2464 
2465  >>> x, y = Ints('x y')
2466  >>> is_mul(x * y)
2467  True
2468  >>> is_mul(x - y)
2469  False
2470  """
2471  return is_app_of(a, Z3_OP_MUL)
2472 
def is_app_of(a, k)
Definition: z3py.py:1168
def is_mul(a)
Definition: z3py.py:2462

§ is_not()

def z3py.is_not (   a)
Return `True` if `a` is a Z3 not expression.

>>> p = Bool('p')
>>> is_not(p)
False
>>> is_not(Not(p))
True

Definition at line 1418 of file z3py.py.

1418 def is_not(a):
1419  """Return `True` if `a` is a Z3 not expression.
1420 
1421  >>> p = Bool('p')
1422  >>> is_not(p)
1423  False
1424  >>> is_not(Not(p))
1425  True
1426  """
1427  return is_app_of(a, Z3_OP_NOT)
1428 
def is_not(a)
Definition: z3py.py:1418
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_or()

def z3py.is_or (   a)
Return `True` if `a` is a Z3 or expression.

>>> p, q = Bools('p q')
>>> is_or(Or(p, q))
True
>>> is_or(And(p, q))
False

Definition at line 1407 of file z3py.py.

1407 def is_or(a):
1408  """Return `True` if `a` is a Z3 or expression.
1409 
1410  >>> p, q = Bools('p q')
1411  >>> is_or(Or(p, q))
1412  True
1413  >>> is_or(And(p, q))
1414  False
1415  """
1416  return is_app_of(a, Z3_OP_OR)
1417 
def is_or(a)
Definition: z3py.py:1407
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_pattern()

def z3py.is_pattern (   a)
Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.

See http://rise4fun.com/Z3Py/tutorial/advanced for more details.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
>>> q
ForAll(x, f(x) == 0)
>>> q.num_patterns()
1
>>> is_pattern(q.pattern(0))
True
>>> q.pattern(0)
f(Var(0))

Definition at line 1672 of file z3py.py.

Referenced by MultiPattern().

1672 def is_pattern(a):
1673  """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1674 
1675  See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
1676 
1677  >>> f = Function('f', IntSort(), IntSort())
1678  >>> x = Int('x')
1679  >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1680  >>> q
1681  ForAll(x, f(x) == 0)
1682  >>> q.num_patterns()
1683  1
1684  >>> is_pattern(q.pattern(0))
1685  True
1686  >>> q.pattern(0)
1687  f(Var(0))
1688  """
1689  return isinstance(a, PatternRef)
1690 
def is_pattern(a)
Definition: z3py.py:1672

§ is_probe()

def z3py.is_probe (   p)
Return `True` if `p` is a Z3 probe.

>>> is_probe(Int('x'))
False
>>> is_probe(Probe('memory'))
True

Definition at line 7673 of file z3py.py.

Referenced by eq().

7673 def is_probe(p):
7674  """Return `True` if `p` is a Z3 probe.
7675 
7676  >>> is_probe(Int('x'))
7677  False
7678  >>> is_probe(Probe('memory'))
7679  True
7680  """
7681  return isinstance(p, Probe)
7682 
def is_probe(p)
Definition: z3py.py:7673

§ is_quantifier()

def z3py.is_quantifier (   a)
Return `True` if `a` is a Z3 quantifier.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0)
>>> is_quantifier(q)
True
>>> is_quantifier(f(x))
False

Definition at line 1875 of file z3py.py.

Referenced by expr.body(), and Exists().

1875 def is_quantifier(a):
1876  """Return `True` if `a` is a Z3 quantifier.
1877 
1878  >>> f = Function('f', IntSort(), IntSort())
1879  >>> x = Int('x')
1880  >>> q = ForAll(x, f(x) == 0)
1881  >>> is_quantifier(q)
1882  True
1883  >>> is_quantifier(f(x))
1884  False
1885  """
1886  return isinstance(a, QuantifierRef)
1887 
def is_quantifier(a)
Definition: z3py.py:1875

§ is_rational_value()

def z3py.is_rational_value (   a)
Return `True` if `a` is rational value of sort Real.

>>> is_rational_value(RealVal(1))
True
>>> is_rational_value(RealVal("3/5"))
True
>>> is_rational_value(IntVal(1))
False
>>> is_rational_value(1)
False
>>> n = Real('x') + 1
>>> n.arg(1)
1
>>> is_rational_value(n.arg(1))
True
>>> is_rational_value(Real('x'))
False

Definition at line 2417 of file z3py.py.

Referenced by RatNumRef.denominator(), and RatNumRef.numerator().

2417 def is_rational_value(a):
2418  """Return `True` if `a` is rational value of sort Real.
2419 
2420  >>> is_rational_value(RealVal(1))
2421  True
2422  >>> is_rational_value(RealVal("3/5"))
2423  True
2424  >>> is_rational_value(IntVal(1))
2425  False
2426  >>> is_rational_value(1)
2427  False
2428  >>> n = Real('x') + 1
2429  >>> n.arg(1)
2430  1
2431  >>> is_rational_value(n.arg(1))
2432  True
2433  >>> is_rational_value(Real('x'))
2434  False
2435  """
2436  return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2437 
def is_arith(a)
Definition: z3py.py:2332
def is_rational_value(a)
Definition: z3py.py:2417

§ is_re()

def z3py.is_re (   s)

Definition at line 10030 of file z3py.py.

10030 def is_re(s):
10031  return isinstance(s, ReRef)
10032 
10033 
def is_re(s)
Definition: z3py.py:10030

§ is_real()

def z3py.is_real (   a)
Return `True` if `a` is a real expression.

>>> x = Int('x')
>>> is_real(x + 1)
False
>>> y = Real('y')
>>> is_real(y)
True
>>> is_real(y + 1)
True
>>> is_real(1)
False
>>> is_real(RealVal(1))
True

Definition at line 2370 of file z3py.py.

Referenced by fpToReal(), sort.is_arith(), Real(), and RealSort().

2370 def is_real(a):
2371  """Return `True` if `a` is a real expression.
2372 
2373  >>> x = Int('x')
2374  >>> is_real(x + 1)
2375  False
2376  >>> y = Real('y')
2377  >>> is_real(y)
2378  True
2379  >>> is_real(y + 1)
2380  True
2381  >>> is_real(1)
2382  False
2383  >>> is_real(RealVal(1))
2384  True
2385  """
2386  return is_arith(a) and a.is_real()
2387 
def is_real(a)
Definition: z3py.py:2370
def is_arith(a)
Definition: z3py.py:2332

§ is_select()

def z3py.is_select (   a)
Return `True` if `a` is a Z3 array select application.

>>> a = Array('a', IntSort(), IntSort())
>>> is_select(a)
False
>>> i = Int('i')
>>> is_select(a[i])
True

Definition at line 4368 of file z3py.py.

4368 def is_select(a):
4369  """Return `True` if `a` is a Z3 array select application.
4370 
4371  >>> a = Array('a', IntSort(), IntSort())
4372  >>> is_select(a)
4373  False
4374  >>> i = Int('i')
4375  >>> is_select(a[i])
4376  True
4377  """
4378  return is_app_of(a, Z3_OP_SELECT)
4379 
def is_select(a)
Definition: z3py.py:4368
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_seq()

def z3py.is_seq (   a)
Return `True` if `a` is a Z3 sequence expression.
>>> print (is_seq(Unit(IntVal(0))))
True
>>> print (is_seq(StringVal("abc")))
True

Definition at line 9790 of file z3py.py.

9790 def is_seq(a):
9791  """Return `True` if `a` is a Z3 sequence expression.
9792  >>> print (is_seq(Unit(IntVal(0))))
9793  True
9794  >>> print (is_seq(StringVal("abc")))
9795  True
9796  """
9797  return isinstance(a, SeqRef)
9798 
def is_seq(a)
Definition: z3py.py:9790

§ is_sort()

def z3py.is_sort (   s)
Return `True` if `s` is a Z3 sort.

>>> is_sort(IntSort())
True
>>> is_sort(Int('x'))
False
>>> is_expr(Int('x'))
True

Definition at line 575 of file z3py.py.

Referenced by Function(), prove(), and Var().

575 def is_sort(s):
576  """Return `True` if `s` is a Z3 sort.
577 
578  >>> is_sort(IntSort())
579  True
580  >>> is_sort(Int('x'))
581  False
582  >>> is_expr(Int('x'))
583  True
584  """
585  return isinstance(s, SortRef)
586 
def is_sort(s)
Definition: z3py.py:575

§ is_store()

def z3py.is_store (   a)
Return `True` if `a` is a Z3 array store application.

>>> a = Array('a', IntSort(), IntSort())
>>> is_store(a)
False
>>> is_store(Store(a, 0, 1))
True

Definition at line 4380 of file z3py.py.

4380 def is_store(a):
4381  """Return `True` if `a` is a Z3 array store application.
4382 
4383  >>> a = Array('a', IntSort(), IntSort())
4384  >>> is_store(a)
4385  False
4386  >>> is_store(Store(a, 0, 1))
4387  True
4388  """
4389  return is_app_of(a, Z3_OP_STORE)
4390 
def is_store(a)
Definition: z3py.py:4380
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_string()

def z3py.is_string (   a)
Return `True` if `a` is a Z3 string expression.
>>> print (is_string(StringVal("ab")))
True

Definition at line 9799 of file z3py.py.

9799 def is_string(a):
9800  """Return `True` if `a` is a Z3 string expression.
9801  >>> print (is_string(StringVal("ab")))
9802  True
9803  """
9804  return isinstance(a, SeqRef) and a.is_string()
9805 
def is_string(a)
Definition: z3py.py:9799

§ is_string_value()

def z3py.is_string_value (   a)
return 'True' if 'a' is a Z3 string constant expression.
>>> print (is_string_value(StringVal("a")))
True
>>> print (is_string_value(StringVal("a") + StringVal("b")))
False

Definition at line 9806 of file z3py.py.

9806 def is_string_value(a):
9807  """return 'True' if 'a' is a Z3 string constant expression.
9808  >>> print (is_string_value(StringVal("a")))
9809  True
9810  >>> print (is_string_value(StringVal("a") + StringVal("b")))
9811  False
9812  """
9813  return isinstance(a, SeqRef) and a.is_string_value()
9814 
9815 
def is_string_value(a)
Definition: z3py.py:9806

§ is_sub()

def z3py.is_sub (   a)
Return `True` if `a` is an expression of the form b - c.

>>> x, y = Ints('x y')
>>> is_sub(x - y)
True
>>> is_sub(x + y)
False

Definition at line 2473 of file z3py.py.

2473 def is_sub(a):
2474  """Return `True` if `a` is an expression of the form b - c.
2475 
2476  >>> x, y = Ints('x y')
2477  >>> is_sub(x - y)
2478  True
2479  >>> is_sub(x + y)
2480  False
2481  """
2482  return is_app_of(a, Z3_OP_SUB)
2483 
def is_app_of(a, k)
Definition: z3py.py:1168
def is_sub(a)
Definition: z3py.py:2473

§ is_to_int()

def z3py.is_to_int (   a)
Return `True` if `a` is an expression of the form ToInt(b).

>>> x = Real('x')
>>> n = ToInt(x)
>>> n
ToInt(x)
>>> is_to_int(n)
True
>>> is_to_int(x)
False

Definition at line 2591 of file z3py.py.

2591 def is_to_int(a):
2592  """Return `True` if `a` is an expression of the form ToInt(b).
2593 
2594  >>> x = Real('x')
2595  >>> n = ToInt(x)
2596  >>> n
2597  ToInt(x)
2598  >>> is_to_int(n)
2599  True
2600  >>> is_to_int(x)
2601  False
2602  """
2603  return is_app_of(a, Z3_OP_TO_INT)
2604 
def is_app_of(a, k)
Definition: z3py.py:1168
def is_to_int(a)
Definition: z3py.py:2591

§ is_to_real()

def z3py.is_to_real (   a)
Return `True` if `a` is an expression of the form ToReal(b).

>>> x = Int('x')
>>> n = ToReal(x)
>>> n
ToReal(x)
>>> is_to_real(n)
True
>>> is_to_real(x)
False

Definition at line 2577 of file z3py.py.

2577 def is_to_real(a):
2578  """Return `True` if `a` is an expression of the form ToReal(b).
2579 
2580  >>> x = Int('x')
2581  >>> n = ToReal(x)
2582  >>> n
2583  ToReal(x)
2584  >>> is_to_real(n)
2585  True
2586  >>> is_to_real(x)
2587  False
2588  """
2589  return is_app_of(a, Z3_OP_TO_REAL)
2590 
def is_to_real(a)
Definition: z3py.py:2577
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_true()

def z3py.is_true (   a)
Return `True` if `a` is the Z3 true expression.

>>> p = Bool('p')
>>> is_true(p)
False
>>> is_true(simplify(p == p))
True
>>> x = Real('x')
>>> is_true(x == 0)
False
>>> # True is a Python Boolean expression
>>> is_true(True)
False

Definition at line 1366 of file z3py.py.

Referenced by AstRef.__bool__(), and BoolVal().

1366 def is_true(a):
1367  """Return `True` if `a` is the Z3 true expression.
1368 
1369  >>> p = Bool('p')
1370  >>> is_true(p)
1371  False
1372  >>> is_true(simplify(p == p))
1373  True
1374  >>> x = Real('x')
1375  >>> is_true(x == 0)
1376  False
1377  >>> # True is a Python Boolean expression
1378  >>> is_true(True)
1379  False
1380  """
1381  return is_app_of(a, Z3_OP_TRUE)
1382 
def is_true(a)
Definition: z3py.py:1366
def is_app_of(a, k)
Definition: z3py.py:1168

§ is_var()

def z3py.is_var (   a)
Return `True` if `a` is variable.

Z3 uses de-Bruijn indices for representing bound variables in
quantifiers.

>>> x = Int('x')
>>> is_var(x)
False
>>> is_const(x)
True
>>> f = Function('f', IntSort(), IntSort())
>>> # Z3 replaces x with bound variables when ForAll is executed.
>>> q = ForAll(x, f(x) == x)
>>> b = q.body()
>>> b
f(Var(0)) == Var(0)
>>> b.arg(1)
Var(0)
>>> is_var(b.arg(1))
True

Definition at line 1112 of file z3py.py.

Referenced by get_var_index().

1112 def is_var(a):
1113  """Return `True` if `a` is variable.
1114 
1115  Z3 uses de-Bruijn indices for representing bound variables in
1116  quantifiers.
1117 
1118  >>> x = Int('x')
1119  >>> is_var(x)
1120  False
1121  >>> is_const(x)
1122  True
1123  >>> f = Function('f', IntSort(), IntSort())
1124  >>> # Z3 replaces x with bound variables when ForAll is executed.
1125  >>> q = ForAll(x, f(x) == x)
1126  >>> b = q.body()
1127  >>> b
1128  f(Var(0)) == Var(0)
1129  >>> b.arg(1)
1130  Var(0)
1131  >>> is_var(b.arg(1))
1132  True
1133  """
1134  return is_expr(a) and _ast_kind(a.ctx, a) == Z3_VAR_AST
1135 
def is_expr(a)
Definition: z3py.py:1047
def is_var(a)
Definition: z3py.py:1112

§ IsInt()

def z3py.IsInt (   a)
Return the Z3 predicate IsInt(a).

>>> x = Real('x')
>>> IsInt(x + "1/2")
IsInt(x + 1/2)
>>> solve(IsInt(x + "1/2"), x > 0, x < 1)
[x = 1/2]
>>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
no solution

Definition at line 2997 of file z3py.py.

Referenced by is_is_int().

2997 def IsInt(a):
2998  """ Return the Z3 predicate IsInt(a).
2999 
3000  >>> x = Real('x')
3001  >>> IsInt(x + "1/2")
3002  IsInt(x + 1/2)
3003  >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3004  [x = 1/2]
3005  >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3006  no solution
3007  """
3008  if __debug__:
3009  _z3_assert(a.is_real(), "Z3 real expression expected.")
3010  ctx = a.ctx
3011  return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
3012 
def IsInt(a)
Definition: z3py.py:2997
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.

§ K()

def z3py.K (   dom,
  v 
)
Return a Z3 constant array expression.

>>> a = K(IntSort(), 10)
>>> a
K(Int, 10)
>>> a.sort()
Array(Int, Int)
>>> i = Int('i')
>>> a[i]
K(Int, 10)[i]
>>> simplify(a[i])
10

Definition at line 4340 of file z3py.py.

Referenced by Default(), is_const_array(), is_default(), and is_K().

4340 def K(dom, v):
4341  """Return a Z3 constant array expression.
4342 
4343  >>> a = K(IntSort(), 10)
4344  >>> a
4345  K(Int, 10)
4346  >>> a.sort()
4347  Array(Int, Int)
4348  >>> i = Int('i')
4349  >>> a[i]
4350  K(Int, 10)[i]
4351  >>> simplify(a[i])
4352  10
4353  """
4354  if __debug__:
4355  _z3_assert(is_sort(dom), "Z3 sort expected")
4356  ctx = dom.ctx
4357  if not is_expr(v):
4358  v = _py2expr(v, ctx)
4359  return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
4360 
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
def is_sort(s)
Definition: z3py.py:575
def K(dom, v)
Definition: z3py.py:4340
def is_expr(a)
Definition: z3py.py:1047

§ Length()

def z3py.Length (   s)
Obtain the length of a sequence 's'
>>> l = Length(StringVal("abc"))
>>> simplify(l)
3

Definition at line 9964 of file z3py.py.

9964 def Length(s):
9965  """Obtain the length of a sequence 's'
9966  >>> l = Length(StringVal("abc"))
9967  >>> simplify(l)
9968  3
9969  """
9970  s = _coerce_seq(s)
9971  return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
9972 
Z3_ast Z3_API Z3_mk_seq_length(Z3_context c, Z3_ast s)
Return the length of the sequence s.
def Length(s)
Definition: z3py.py:9964

§ Loop()

def z3py.Loop (   re,
  lo,
  hi = 0 
)
Create the regular expression accepting between a lower and upper bound repetitions
>>> re = Loop(Re("a"), 1, 3)
>>> print(simplify(InRe("aa", re)))
True
>>> print(simplify(InRe("aaaa", re)))
False
>>> print(simplify(InRe("", re)))
False

Definition at line 10106 of file z3py.py.

10106 def Loop(re, lo, hi=0):
10107  """Create the regular expression accepting between a lower and upper bound repetitions
10108  >>> re = Loop(Re("a"), 1, 3)
10109  >>> print(simplify(InRe("aa", re)))
10110  True
10111  >>> print(simplify(InRe("aaaa", re)))
10112  False
10113  >>> print(simplify(InRe("", re)))
10114  False
10115  """
10116  return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
10117 
Z3_ast Z3_API Z3_mk_re_loop(Z3_context c, Z3_ast r, unsigned lo, unsigned hi)
Create a regular expression loop. The supplied regular expression r is repeated between lo and hi tim...
def Loop(re, lo, hi=0)
Definition: z3py.py:10106

§ LShR()

def z3py.LShR (   a,
  b 
)
Create the Z3 expression logical right shift.

Use the operator >> for the arithmetical right shift.

>>> x, y = BitVecs('x y', 32)
>>> LShR(x, y)
LShR(x, y)
>>> (x >> y).sexpr()
'(bvashr x y)'
>>> LShR(x, y).sexpr()
'(bvlshr x y)'
>>> BitVecVal(4, 3)
4
>>> BitVecVal(4, 3).as_signed_long()
-4
>>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
-2
>>> simplify(BitVecVal(4, 3) >> 1)
6
>>> simplify(LShR(BitVecVal(4, 3), 1))
2
>>> simplify(BitVecVal(2, 3) >> 1)
1
>>> simplify(LShR(BitVecVal(2, 3), 1))
1

Definition at line 3866 of file z3py.py.

Referenced by BitVecRef.__rlshift__(), BitVecRef.__rrshift__(), and BitVecRef.__rshift__().

3866 def LShR(a, b):
3867  """Create the Z3 expression logical right shift.
3868 
3869  Use the operator >> for the arithmetical right shift.
3870 
3871  >>> x, y = BitVecs('x y', 32)
3872  >>> LShR(x, y)
3873  LShR(x, y)
3874  >>> (x >> y).sexpr()
3875  '(bvashr x y)'
3876  >>> LShR(x, y).sexpr()
3877  '(bvlshr x y)'
3878  >>> BitVecVal(4, 3)
3879  4
3880  >>> BitVecVal(4, 3).as_signed_long()
3881  -4
3882  >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3883  -2
3884  >>> simplify(BitVecVal(4, 3) >> 1)
3885  6
3886  >>> simplify(LShR(BitVecVal(4, 3), 1))
3887  2
3888  >>> simplify(BitVecVal(2, 3) >> 1)
3889  1
3890  >>> simplify(LShR(BitVecVal(2, 3), 1))
3891  1
3892  """
3893  _check_bv_args(a, b)
3894  a, b = _coerce_exprs(a, b)
3895  return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3896 
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.
def LShR(a, b)
Definition: z3py.py:3866

§ main_ctx()

def z3py.main_ctx ( )
Return a reference to the global Z3 context.

>>> x = Real('x')
>>> x.ctx == main_ctx()
True
>>> c = Context()
>>> c == main_ctx()
False
>>> x2 = Real('x', c)
>>> x2.ctx == c
True
>>> eq(x, x2)
False

Definition at line 203 of file z3py.py.

Referenced by help_simplify(), simplify_param_descrs(), and Goal.translate().

203 def main_ctx():
204  """Return a reference to the global Z3 context.
205 
206  >>> x = Real('x')
207  >>> x.ctx == main_ctx()
208  True
209  >>> c = Context()
210  >>> c == main_ctx()
211  False
212  >>> x2 = Real('x', c)
213  >>> x2.ctx == c
214  True
215  >>> eq(x, x2)
216  False
217  """
218  global _main_ctx
219  if _main_ctx is None:
220  _main_ctx = Context()
221  return _main_ctx
222 
def main_ctx()
Definition: z3py.py:203

§ Map()

def z3py.Map (   f,
  args 
)
Return a Z3 map array expression.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> a1 = Array('a1', IntSort(), IntSort())
>>> a2 = Array('a2', IntSort(), IntSort())
>>> b  = Map(f, a1, a2)
>>> b
Map(f, a1, a2)
>>> prove(b[0] == f(a1[0], a2[0]))
proved

Definition at line 4318 of file z3py.py.

Referenced by Context.Context(), get_map_func(), is_map(), and InterpolationContext.mkContext().

4318 def Map(f, *args):
4319  """Return a Z3 map array expression.
4320 
4321  >>> f = Function('f', IntSort(), IntSort(), IntSort())
4322  >>> a1 = Array('a1', IntSort(), IntSort())
4323  >>> a2 = Array('a2', IntSort(), IntSort())
4324  >>> b = Map(f, a1, a2)
4325  >>> b
4326  Map(f, a1, a2)
4327  >>> prove(b[0] == f(a1[0], a2[0]))
4328  proved
4329  """
4330  args = _get_args(args)
4331  if __debug__:
4332  _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
4333  _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
4334  _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
4335  _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
4336  _args, sz = _to_ast_array(args)
4337  ctx = f.ctx
4338  return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
4339 
def is_array(a)
Definition: z3py.py:4144
def Map(f, args)
Definition: z3py.py:4318
Z3_ast Z3_API Z3_mk_map(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast const *args)
Map f on the argument arrays.
def is_func_decl(a)
Definition: z3py.py:762

§ MultiPattern()

def z3py.MultiPattern (   args)
Create a Z3 multi-pattern using the given expressions `*args`

See http://rise4fun.com/Z3Py/tutorial/advanced for more details.

>>> f = Function('f', IntSort(), IntSort())
>>> g = Function('g', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
>>> q
ForAll(x, f(x) != g(x))
>>> q.num_patterns()
1
>>> is_pattern(q.pattern(0))
True
>>> q.pattern(0)
MultiPattern(f(Var(0)), g(Var(0)))

Definition at line 1691 of file z3py.py.

1691 def MultiPattern(*args):
1692  """Create a Z3 multi-pattern using the given expressions `*args`
1693 
1694  See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
1695 
1696  >>> f = Function('f', IntSort(), IntSort())
1697  >>> g = Function('g', IntSort(), IntSort())
1698  >>> x = Int('x')
1699  >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
1700  >>> q
1701  ForAll(x, f(x) != g(x))
1702  >>> q.num_patterns()
1703  1
1704  >>> is_pattern(q.pattern(0))
1705  True
1706  >>> q.pattern(0)
1707  MultiPattern(f(Var(0)), g(Var(0)))
1708  """
1709  if __debug__:
1710  _z3_assert(len(args) > 0, "At least one argument expected")
1711  _z3_assert(all([ is_expr(a) for a in args ]), "Z3 expressions expected")
1712  ctx = args[0].ctx
1713  args, sz = _to_ast_array(args)
1714  return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
1715 
Z3_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[])
Create a pattern for quantifier instantiation.
def MultiPattern(args)
Definition: z3py.py:1691
def is_expr(a)
Definition: z3py.py:1047

§ Not()

def z3py.Not (   a,
  ctx = None 
)
Create a Z3 not expression or probe.

>>> p = Bool('p')
>>> Not(Not(p))
Not(Not(p))
>>> simplify(Not(Not(p)))
p

Definition at line 1567 of file z3py.py.

Referenced by binary_interpolant(), Solver.consequences(), fpNEQ(), Implies(), prove(), sequence_interpolant(), tree_interpolant(), and Xor().

1567 def Not(a, ctx=None):
1568  """Create a Z3 not expression or probe.
1569 
1570  >>> p = Bool('p')
1571  >>> Not(Not(p))
1572  Not(Not(p))
1573  >>> simplify(Not(Not(p)))
1574  p
1575  """
1576  ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1577  if is_probe(a):
1578  # Not is also used to build probes
1579  return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1580  else:
1581  s = BoolSort(ctx)
1582  a = s.cast(a)
1583  return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1584 
Z3_probe Z3_API Z3_probe_not(Z3_context x, Z3_probe p)
Return a probe that evaluates to "true" when p does not evaluate to true.
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
def Not(a, ctx=None)
Definition: z3py.py:1567
def is_probe(p)
Definition: z3py.py:7673
def BoolSort(ctx=None)
Definition: z3py.py:1449

§ open_log()

def z3py.open_log (   fname)
Log interaction to a file. This function must be invoked immediately after init(). 

Definition at line 93 of file z3py.py.

93 def open_log(fname):
94  """Log interaction to a file. This function must be invoked immediately after init(). """
95  Z3_open_log(fname)
96 
Z3_bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.
def open_log(fname)
Definition: z3py.py:93

§ Option()

def z3py.Option (   re)
Create the regular expression that optionally accepts the argument.
>>> re = Option(Re("a"))
>>> print(simplify(InRe("a", re)))
True
>>> print(simplify(InRe("", re)))
True
>>> print(simplify(InRe("aa", re)))
False

Definition at line 10078 of file z3py.py.

10078 def Option(re):
10079  """Create the regular expression that optionally accepts the argument.
10080  >>> re = Option(Re("a"))
10081  >>> print(simplify(InRe("a", re)))
10082  True
10083  >>> print(simplify(InRe("", re)))
10084  True
10085  >>> print(simplify(InRe("aa", re)))
10086  False
10087  """
10088  return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
10089 
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].
def Option(re)
Definition: z3py.py:10078

§ Or()

def z3py.Or (   args)
Create a Z3 or-expression or or-probe.

>>> p, q, r = Bools('p q r')
>>> Or(p, q, r)
Or(p, q, r)
>>> P = BoolVector('p', 5)
>>> Or(P)
Or(p__0, p__1, p__2, p__3, p__4)

Definition at line 1625 of file z3py.py.

Referenced by ApplyResult.as_expr(), Bools(), and Implies().

1625 def Or(*args):
1626  """Create a Z3 or-expression or or-probe.
1627 
1628  >>> p, q, r = Bools('p q r')
1629  >>> Or(p, q, r)
1630  Or(p, q, r)
1631  >>> P = BoolVector('p', 5)
1632  >>> Or(P)
1633  Or(p__0, p__1, p__2, p__3, p__4)
1634  """
1635  last_arg = None
1636  if len(args) > 0:
1637  last_arg = args[len(args)-1]
1638  if isinstance(last_arg, Context):
1639  ctx = args[len(args)-1]
1640  args = args[:len(args)-1]
1641  else:
1642  ctx = main_ctx()
1643  args = _get_args(args)
1644  ctx_args = _ctx_from_ast_arg_list(args, ctx)
1645  if __debug__:
1646  _z3_assert(ctx_args is None or ctx_args == ctx, "context mismatch")
1647  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1648  if _has_probe(args):
1649  return _probe_or(args, ctx)
1650  else:
1651  args = _coerce_expr_list(args, ctx)
1652  _args, sz = _to_ast_array(args)
1653  return BoolRef(Z3_mk_or(ctx.ref(), sz, _args), ctx)
1654 
Z3_ast Z3_API Z3_mk_or(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] or ... or args[num_args-1].
def main_ctx()
Definition: z3py.py:203
def Or(args)
Definition: z3py.py:1625

§ OrElse()

def z3py.OrElse (   ts,
  ks 
)
Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).

>>> x = Int('x')
>>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
>>> # Tactic split-clause fails if there is no clause in the given goal.
>>> t(x == 0)
[[x == 0]]
>>> t(Or(x == 0, x == 1))
[[x == 0], [x == 1]]

Definition at line 7389 of file z3py.py.

7389 def OrElse(*ts, **ks):
7390  """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
7391 
7392  >>> x = Int('x')
7393  >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
7394  >>> # Tactic split-clause fails if there is no clause in the given goal.
7395  >>> t(x == 0)
7396  [[x == 0]]
7397  >>> t(Or(x == 0, x == 1))
7398  [[x == 0], [x == 1]]
7399  """
7400  if __debug__:
7401  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7402  ctx = ks.get('ctx', None)
7403  num = len(ts)
7404  r = ts[0]
7405  for i in range(num - 1):
7406  r = _or_else(r, ts[i+1], ctx)
7407  return r
7408 
def OrElse(ts, ks)
Definition: z3py.py:7389
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868

§ ParAndThen()

def z3py.ParAndThen (   t1,
  t2,
  ctx = None 
)
Alias for ParThen(t1, t2, ctx).

Definition at line 7441 of file z3py.py.

7441 def ParAndThen(t1, t2, ctx=None):
7442  """Alias for ParThen(t1, t2, ctx)."""
7443  return ParThen(t1, t2, ctx)
7444 
def ParAndThen(t1, t2, ctx=None)
Definition: z3py.py:7441
def ParThen(t1, t2, ctx=None)
Definition: z3py.py:7427

§ ParOr()

def z3py.ParOr (   ts,
  ks 
)
Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).

>>> x = Int('x')
>>> t = ParOr(Tactic('simplify'), Tactic('fail'))
>>> t(x + 1 == 2)
[[x == 1]]

Definition at line 7409 of file z3py.py.

7409 def ParOr(*ts, **ks):
7410  """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
7411 
7412  >>> x = Int('x')
7413  >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
7414  >>> t(x + 1 == 2)
7415  [[x == 1]]
7416  """
7417  if __debug__:
7418  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7419  ctx = _get_ctx(ks.get('ctx', None))
7420  ts = [ _to_tactic(t, ctx) for t in ts ]
7421  sz = len(ts)
7422  _args = (TacticObj * sz)()
7423  for i in range(sz):
7424  _args[i] = ts[i].tactic
7425  return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
7426 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
Z3_tactic Z3_API Z3_tactic_par_or(Z3_context c, unsigned num, Z3_tactic const ts[])
Return a tactic that applies the given tactics in parallel.
def ParOr(ts, ks)
Definition: z3py.py:7409

§ parse_smt2_file()

def z3py.parse_smt2_file (   f,
  sorts = {},
  decls = {},
  ctx = None 
)
Parse a file in SMT 2.0 format using the given sorts and decls.

This function is similar to parse_smt2_string().

Definition at line 8212 of file z3py.py.

8212 def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
8213  """Parse a file in SMT 2.0 format using the given sorts and decls.
8214 
8215  This function is similar to parse_smt2_string().
8216  """
8217  ctx = _get_ctx(ctx)
8218  ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8219  dsz, dnames, ddecls = _dict2darray(decls, ctx)
8220  try:
8221  return _to_expr_ref(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
8222  except Z3Exception as e:
8223  _handle_parse_error(e, ctx)
8224 
Z3_ast Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Similar to Z3_parse_smtlib2_string, but reads the benchmark from a file.
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
Definition: z3py.py:8212

§ parse_smt2_string()

def z3py.parse_smt2_string (   s,
  sorts = {},
  decls = {},
  ctx = None 
)
Parse a string in SMT 2.0 format using the given sorts and decls.

The arguments sorts and decls are Python dictionaries used to initialize
the symbol table used for the SMT 2.0 parser.

>>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
And(x > 0, x < 10)
>>> x, y = Ints('x y')
>>> f = Function('f', IntSort(), IntSort())
>>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
x + f(y) > 0
>>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
a > 0

Definition at line 8189 of file z3py.py.

Referenced by parse_smt2_file().

8189 def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
8190  """Parse a string in SMT 2.0 format using the given sorts and decls.
8191 
8192  The arguments sorts and decls are Python dictionaries used to initialize
8193  the symbol table used for the SMT 2.0 parser.
8194 
8195  >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
8196  And(x > 0, x < 10)
8197  >>> x, y = Ints('x y')
8198  >>> f = Function('f', IntSort(), IntSort())
8199  >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
8200  x + f(y) > 0
8201  >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() }) a > 0
8202  """
8203  ctx = _get_ctx(ctx)
8204  ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8205  dsz, dnames, ddecls = _dict2darray(decls, ctx)
8206  try:
8207  return _to_expr_ref(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
8208  except Z3Exception as e:
8209  _handle_parse_error(e, ctx)
8210 
8211 
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
Definition: z3py.py:8189

§ ParThen()

def z3py.ParThen (   t1,
  t2,
  ctx = None 
)
Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.

>>> x, y = Ints('x y')
>>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
>>> t(And(Or(x == 1, x == 2), y == x + 1))
[[x == 1, y == 2], [x == 2, y == 3]]

Definition at line 7427 of file z3py.py.

Referenced by ParAndThen().

7427 def ParThen(t1, t2, ctx=None):
7428  """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.
7429 
7430  >>> x, y = Ints('x y')
7431  >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
7432  >>> t(And(Or(x == 1, x == 2), y == x + 1))
7433  [[x == 1, y == 2], [x == 2, y == 3]]
7434  """
7435  t1 = _to_tactic(t1, ctx)
7436  t2 = _to_tactic(t2, ctx)
7437  if __debug__:
7438  _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
7439  return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
7440 
Z3_tactic Z3_API Z3_tactic_par_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and then t2 to every subgoal produced by t1...
def ParThen(t1, t2, ctx=None)
Definition: z3py.py:7427

§ PbEq()

def z3py.PbEq (   args,
  k,
  ctx = None 
)
Create a Pseudo-Boolean inequality k constraint.

>>> a, b, c = Bools('a b c')
>>> f = PbEq(((a,1),(b,3),(c,2)), 3)

Definition at line 7992 of file z3py.py.

7992 def PbEq(args, k, ctx = None):
7993  """Create a Pseudo-Boolean inequality k constraint.
7994 
7995  >>> a, b, c = Bools('a b c')
7996  >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
7997  """
7998  ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
7999  return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
8000 
8001 
Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
def PbEq(args, k, ctx=None)
Definition: z3py.py:7992

§ PbGe()

def z3py.PbGe (   args,
  k 
)
Create a Pseudo-Boolean inequality k constraint.

>>> a, b, c = Bools('a b c')
>>> f = PbGe(((a,1),(b,3),(c,2)), 3)

Definition at line 7983 of file z3py.py.

7983 def PbGe(args, k):
7984  """Create a Pseudo-Boolean inequality k constraint.
7985 
7986  >>> a, b, c = Bools('a b c')
7987  >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
7988  """
7989  ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
7990  return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
7991 
def PbGe(args, k)
Definition: z3py.py:7983
Z3_ast Z3_API Z3_mk_pbge(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.

§ PbLe()

def z3py.PbLe (   args,
  k 
)
Create a Pseudo-Boolean inequality k constraint.

>>> a, b, c = Bools('a b c')
>>> f = PbLe(((a,1),(b,3),(c,2)), 3)

Definition at line 7974 of file z3py.py.

7974 def PbLe(args, k):
7975  """Create a Pseudo-Boolean inequality k constraint.
7976 
7977  >>> a, b, c = Bools('a b c')
7978  >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
7979  """
7980  ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
7981  return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
7982 
def PbLe(args, k)
Definition: z3py.py:7974
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.

§ Plus()

def z3py.Plus (   re)
Create the regular expression accepting one or more repetitions of argument.
>>> re = Plus(Re("a"))
>>> print(simplify(InRe("aa", re)))
True
>>> print(simplify(InRe("ab", re)))
False
>>> print(simplify(InRe("", re)))
False

Definition at line 10066 of file z3py.py.

10066 def Plus(re):
10067  """Create the regular expression accepting one or more repetitions of argument.
10068  >>> re = Plus(Re("a"))
10069  >>> print(simplify(InRe("aa", re)))
10070  True
10071  >>> print(simplify(InRe("ab", re)))
10072  False
10073  >>> print(simplify(InRe("", re)))
10074  False
10075  """
10076  return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
10077 
def Plus(re)
Definition: z3py.py:10066
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.

§ PrefixOf()

def z3py.PrefixOf (   a,
  b 
)
Check if 'a' is a prefix of 'b'
>>> s1 = PrefixOf("ab", "abc")
>>> simplify(s1)
True
>>> s2 = PrefixOf("bc", "abc")
>>> simplify(s2)
False

Definition at line 9883 of file z3py.py.

9883 def PrefixOf(a, b):
9884  """Check if 'a' is a prefix of 'b'
9885  >>> s1 = PrefixOf("ab", "abc")
9886  >>> simplify(s1)
9887  True
9888  >>> s2 = PrefixOf("bc", "abc")
9889  >>> simplify(s2)
9890  False
9891  """
9892  ctx = _get_ctx2(a, b)
9893  a = _coerce_seq(a, ctx)
9894  b = _coerce_seq(b, ctx)
9895  return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
9896 
Z3_ast Z3_API Z3_mk_seq_prefix(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if prefix is a prefix of s.
def PrefixOf(a, b)
Definition: z3py.py:9883

§ probe_description()

def z3py.probe_description (   name,
  ctx = None 
)
Return a short description for the probe named `name`.

>>> d = probe_description('memory')

Definition at line 7699 of file z3py.py.

Referenced by describe_probes().

7699 def probe_description(name, ctx=None):
7700  """Return a short description for the probe named `name`.
7701 
7702  >>> d = probe_description('memory')
7703  """
7704  ctx = _get_ctx(ctx)
7705  return Z3_probe_get_descr(ctx.ref(), name)
7706 
def probe_description(name, ctx=None)
Definition: z3py.py:7699
Z3_string Z3_API Z3_probe_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the probe with the given name.

§ probes()

def z3py.probes (   ctx = None)
Return a list of all available probes in Z3.

>>> l = probes()
>>> l.count('memory') == 1
True

Definition at line 7689 of file z3py.py.

Referenced by describe_probes().

7689 def probes(ctx=None):
7690  """Return a list of all available probes in Z3.
7691 
7692  >>> l = probes()
7693  >>> l.count('memory') == 1
7694  True
7695  """
7696  ctx = _get_ctx(ctx)
7697  return [ Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref())) ]
7698 
Z3_string Z3_API Z3_get_probe_name(Z3_context c, unsigned i)
Return the name of the i probe.
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def probes(ctx=None)
Definition: z3py.py:7689
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.

§ Product()

def z3py.Product (   args)
Create the product of the Z3 expressions.

>>> a, b, c = Ints('a b c')
>>> Product(a, b, c)
a*b*c
>>> Product([a, b, c])
a*b*c
>>> A = IntVector('a', 5)
>>> Product(A)
a__0*a__1*a__2*a__3*a__4

Definition at line 7897 of file z3py.py.

Referenced by BitVecs().

7897 def Product(*args):
7898  """Create the product of the Z3 expressions.
7899 
7900  >>> a, b, c = Ints('a b c')
7901  >>> Product(a, b, c)
7902  a*b*c
7903  >>> Product([a, b, c])
7904  a*b*c
7905  >>> A = IntVector('a', 5)
7906  >>> Product(A)
7907  a__0*a__1*a__2*a__3*a__4
7908  """
7909  args = _get_args(args)
7910  if len(args) == 0:
7911  return 1
7912  ctx = _ctx_from_ast_arg_list(args)
7913  if ctx is None:
7914  return _reduce(lambda a, b: a * b, args, 1)
7915  args = _coerce_expr_list(args, ctx)
7916  if is_bv(args[0]):
7917  return _reduce(lambda a, b: a * b, args, 1)
7918  else:
7919  _args, sz = _to_ast_array(args)
7920  return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
7921 
Z3_ast Z3_API Z3_mk_mul(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] * ... * args[num_args-1].
def Product(args)
Definition: z3py.py:7897
def is_bv(a)
Definition: z3py.py:3536

§ prove()

def z3py.prove (   claim,
  keywords 
)
Try to prove the given claim.

This is a simple function for creating demonstrations.  It tries to prove
`claim` by showing the negation is unsatisfiable.

>>> p, q = Bools('p q')
>>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
proved

Definition at line 8059 of file z3py.py.

Referenced by Default(), Map(), Store(), and Update().

8059 def prove(claim, **keywords):
8060  """Try to prove the given claim.
8061 
8062  This is a simple function for creating demonstrations. It tries to prove
8063  `claim` by showing the negation is unsatisfiable.
8064 
8065  >>> p, q = Bools('p q')
8066  >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
8067  proved
8068  """
8069  if __debug__:
8070  _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
8071  s = Solver()
8072  s.set(**keywords)
8073  s.add(Not(claim))
8074  if keywords.get('show', False):
8075  print(s)
8076  r = s.check()
8077  if r == unsat:
8078  print("proved")
8079  elif r == unknown:
8080  print("failed to prove")
8081  print(s.model())
8082  else:
8083  print("counterexample")
8084  print(s.model())
8085 
def prove(claim, keywords)
Definition: z3py.py:8059
def Not(a, ctx=None)
Definition: z3py.py:1567
def is_bool(a)
Definition: z3py.py:1349

§ Q()

def z3py.Q (   a,
  b,
  ctx = None 
)
Return a Z3 rational a/b.

If `ctx=None`, then the global context is used.

>>> Q(3,5)
3/5
>>> Q(3,5).sort()
Real

Definition at line 2851 of file z3py.py.

Referenced by RatNumRef.as_string(), RatNumRef.denominator(), and RatNumRef.numerator().

2851 def Q(a, b, ctx=None):
2852  """Return a Z3 rational a/b.
2853 
2854  If `ctx=None`, then the global context is used.
2855 
2856  >>> Q(3,5)
2857  3/5
2858  >>> Q(3,5).sort()
2859  Real
2860  """
2861  return simplify(RatVal(a, b))
2862 
def simplify(a, arguments, keywords)
Utils.
Definition: z3py.py:7793
def RatVal(a, b, ctx=None)
Definition: z3py.py:2836
def Q(a, b, ctx=None)
Definition: z3py.py:2851

§ RatVal()

def z3py.RatVal (   a,
  b,
  ctx = None 
)
Return a Z3 rational a/b.

If `ctx=None`, then the global context is used.

>>> RatVal(3,5)
3/5
>>> RatVal(3,5).sort()
Real

Definition at line 2836 of file z3py.py.

2836 def RatVal(a, b, ctx=None):
2837  """Return a Z3 rational a/b.
2838 
2839  If `ctx=None`, then the global context is used.
2840 
2841  >>> RatVal(3,5)
2842  3/5
2843  >>> RatVal(3,5).sort()
2844  Real
2845  """
2846  if __debug__:
2847  _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
2848  _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
2849  return simplify(RealVal(a, ctx)/RealVal(b, ctx))
2850 
def simplify(a, arguments, keywords)
Utils.
Definition: z3py.py:7793
def RatVal(a, b, ctx=None)
Definition: z3py.py:2836
def RealVal(val, ctx=None)
Definition: z3py.py:2818

§ Re()

def z3py.Re (   s,
  ctx = None 
)
The regular expression that accepts sequence 's'
>>> s1 = Re("ab")
>>> s2 = Re(StringVal("ab"))
>>> s3 = Re(Unit(BoolVal(True)))

Definition at line 9996 of file z3py.py.

Referenced by InRe(), Loop(), Option(), Plus(), Star(), and Union().

9996 def Re(s, ctx=None):
9997  """The regular expression that accepts sequence 's'
9998  >>> s1 = Re("ab")
9999  >>> s2 = Re(StringVal("ab"))
10000  >>> s3 = Re(Unit(BoolVal(True)))
10001  """
10002  s = _coerce_seq(s, ctx)
10003  return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
10004 
10005 
10006 
10007 
def Re(s, ctx=None)
Definition: z3py.py:9996
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.

§ Real()

def z3py.Real (   name,
  ctx = None 
)
Return a real constant named `name`. If `ctx=None`, then the global context is used.

>>> x = Real('x')
>>> is_real(x)
True
>>> is_real(x + 1)
True

Definition at line 2911 of file z3py.py.

Referenced by ArithRef.__div__(), ArithRef.__ge__(), ArithRef.__gt__(), ArithRef.__le__(), ArithRef.__lt__(), ArithRef.__mul__(), ArithRef.__pow__(), ArithRef.__rdiv__(), ArithRef.__rmul__(), ArithRef.__rpow__(), Cbrt(), is_arith(), ArithSortRef.is_int(), ArithRef.is_int(), is_int(), is_is_int(), is_rational_value(), ArithSortRef.is_real(), ArithRef.is_real(), is_real(), is_to_int(), IsInt(), ArithRef.sort(), Sqrt(), ToInt(), and QuantifierRef.var_sort().

2911 def Real(name, ctx=None):
2912  """Return a real constant named `name`. If `ctx=None`, then the global context is used.
2913 
2914  >>> x = Real('x')
2915  >>> is_real(x)
2916  True
2917  >>> is_real(x + 1)
2918  True
2919  """
2920  ctx = _get_ctx(ctx)
2921  return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
2922 
def RealSort(ctx=None)
Definition: z3py.py:2776
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:101
def Real(name, ctx=None)
Definition: z3py.py:2911

§ Reals()

def z3py.Reals (   names,
  ctx = None 
)
Return a tuple of real constants.

>>> x, y, z = Reals('x y z')
>>> Sum(x, y, z)
x + y + z
>>> Sum(x, y, z).sort()
Real

Definition at line 2923 of file z3py.py.

Referenced by is_div().

2923 def Reals(names, ctx=None):
2924  """Return a tuple of real constants.
2925 
2926  >>> x, y, z = Reals('x y z')
2927  >>> Sum(x, y, z)
2928  x + y + z
2929  >>> Sum(x, y, z).sort()
2930  Real
2931  """
2932  ctx = _get_ctx(ctx)
2933  if isinstance(names, str):
2934  names = names.split(" ")
2935  return [Real(name, ctx) for name in names]
2936 
def Real(name, ctx=None)
Definition: z3py.py:2911
def Reals(names, ctx=None)
Definition: z3py.py:2923

§ RealSort()

def z3py.RealSort (   ctx = None)
Return the real sort in the given context. If `ctx=None`, then the global context is used.

>>> RealSort()
Real
>>> x = Const('x', RealSort())
>>> is_real(x)
True
>>> is_int(x)
False
>>> x.sort() == RealSort()
True

Definition at line 2776 of file z3py.py.

Referenced by ArithSortRef.cast(), Context.getRealSort(), is_arith_sort(), Context.mkRealSort(), RealVar(), Sort.translate(), and QuantifierRef.var_sort().

2776 def RealSort(ctx=None):
2777  """Return the real sort in the given context. If `ctx=None`, then the global context is used.
2778 
2779  >>> RealSort()
2780  Real
2781  >>> x = Const('x', RealSort())
2782  >>> is_real(x)
2783  True
2784  >>> is_int(x)
2785  False
2786  >>> x.sort() == RealSort()
2787  True
2788  """
2789  ctx = _get_ctx(ctx)
2790  return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
2791 
def RealSort(ctx=None)
Definition: z3py.py:2776
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.

§ RealVal()

def z3py.RealVal (   val,
  ctx = None 
)
Return a Z3 real value.

`val` may be a Python int, long, float or string representing a number in decimal or rational notation.
If `ctx=None`, then the global context is used.

>>> RealVal(1)
1
>>> RealVal(1).sort()
Real
>>> RealVal("3/5")
3/5
>>> RealVal("1.5")
3/2

Definition at line 2818 of file z3py.py.

Referenced by RatNumRef.as_decimal(), RatNumRef.as_fraction(), RatNumRef.denominator_as_long(), fpRealToFP(), fpToFP(), is_algebraic_value(), is_int_value(), is_rational_value(), is_real(), RatNumRef.numerator(), and RatNumRef.numerator_as_long().

2818 def RealVal(val, ctx=None):
2819  """Return a Z3 real value.
2820 
2821  `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
2822  If `ctx=None`, then the global context is used.
2823 
2824  >>> RealVal(1)
2825  1
2826  >>> RealVal(1).sort()
2827  Real
2828  >>> RealVal("3/5")
2829  3/5
2830  >>> RealVal("1.5")
2831  3/2
2832  """
2833  ctx = _get_ctx(ctx)
2834  return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), RealSort(ctx).ast), ctx)
2835 
def RealSort(ctx=None)
Definition: z3py.py:2776
def RealVal(val, ctx=None)
Definition: z3py.py:2818
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.

§ RealVar()

def z3py.RealVar (   idx,
  ctx = None 
)
Create a real free variable. Free variables are used to create quantified formulas.
They are also used to create polynomials.

>>> RealVar(0)
Var(0)

Definition at line 1270 of file z3py.py.

Referenced by RealVarVector().

1270 def RealVar(idx, ctx=None):
1271  """
1272  Create a real free variable. Free variables are used to create quantified formulas.
1273  They are also used to create polynomials.
1274 
1275  >>> RealVar(0)
1276  Var(0)
1277  """
1278  return Var(idx, RealSort(ctx))
1279 
def RealSort(ctx=None)
Definition: z3py.py:2776
def Var(idx, s)
Definition: z3py.py:1258
def RealVar(idx, ctx=None)
Definition: z3py.py:1270

§ RealVarVector()

def z3py.RealVarVector (   n,
  ctx = None 
)
Create a list of Real free variables.
The variables have ids: 0, 1, ..., n-1

>>> x0, x1, x2, x3 = RealVarVector(4)
>>> x2
Var(2)

Definition at line 1280 of file z3py.py.

1280 def RealVarVector(n, ctx=None):
1281  """
1282  Create a list of Real free variables.
1283  The variables have ids: 0, 1, ..., n-1
1284 
1285  >>> x0, x1, x2, x3 = RealVarVector(4)
1286  >>> x2
1287  Var(2)
1288  """
1289  return [ RealVar(i, ctx) for i in range(n) ]
1290 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def RealVarVector(n, ctx=None)
Definition: z3py.py:1280
def RealVar(idx, ctx=None)
Definition: z3py.py:1270

§ RealVector()

def z3py.RealVector (   prefix,
  sz,
  ctx = None 
)
Return a list of real constants of size `sz`.

>>> X = RealVector('x', 3)
>>> X
[x__0, x__1, x__2]
>>> Sum(X)
x__0 + x__1 + x__2
>>> Sum(X).sort()
Real

Definition at line 2937 of file z3py.py.

2937 def RealVector(prefix, sz, ctx=None):
2938  """Return a list of real constants of size `sz`.
2939 
2940  >>> X = RealVector('x', 3)
2941  >>> X
2942  [x__0, x__1, x__2]
2943  >>> Sum(X)
2944  x__0 + x__1 + x__2
2945  >>> Sum(X).sort()
2946  Real
2947  """
2948  return [ Real('%s__%s' % (prefix, i)) for i in range(sz) ]
2949 
def RealVector(prefix, sz, ctx=None)
Definition: z3py.py:2937
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def Real(name, ctx=None)
Definition: z3py.py:2911

§ Repeat()

def z3py.Repeat (   t,
  max = 4294967295,
  ctx = None 
)
Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.

>>> x, y = Ints('x y')
>>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
>>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
>>> r = t(c)
>>> for subgoal in r: print(subgoal)
[x == 0, y == 0, x > y]
[x == 0, y == 1, x > y]
[x == 1, y == 0, x > y]
[x == 1, y == 1, x > y]
>>> t = Then(t, Tactic('propagate-values'))
>>> t(c)
[[x == 1, y == 0]]

Definition at line 7471 of file z3py.py.

7471 def Repeat(t, max=4294967295, ctx=None):
7472  """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.
7473 
7474  >>> x, y = Ints('x y')
7475  >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
7476  >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
7477  >>> r = t(c)
7478  >>> for subgoal in r: print(subgoal)
7479  [x == 0, y == 0, x > y]
7480  [x == 0, y == 1, x > y]
7481  [x == 1, y == 0, x > y]
7482  [x == 1, y == 1, x > y]
7483  >>> t = Then(t, Tactic('propagate-values'))
7484  >>> t(c)
7485  [[x == 1, y == 0]]
7486  """
7487  t = _to_tactic(t, ctx)
7488  return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
7489 
Z3_tactic Z3_API Z3_tactic_repeat(Z3_context c, Z3_tactic t, unsigned max)
Return a tactic that keeps applying t until the goal is not modified anymore or the maximum number of...
def Repeat(t, max=4294967295, ctx=None)
Definition: z3py.py:7471

§ RepeatBitVec()

def z3py.RepeatBitVec (   n,
  a 
)
Return an expression representing `n` copies of `a`.

>>> x = BitVec('x', 8)
>>> n = RepeatBitVec(4, x)
>>> n
RepeatBitVec(4, x)
>>> n.size()
32
>>> v0 = BitVecVal(10, 4)
>>> print("%.x" % v0.as_long())
a
>>> v = simplify(RepeatBitVec(4, v0))
>>> v.size()
16
>>> print("%.x" % v.as_long())
aaaa

Definition at line 3983 of file z3py.py.

3983 def RepeatBitVec(n, a):
3984  """Return an expression representing `n` copies of `a`.
3985 
3986  >>> x = BitVec('x', 8)
3987  >>> n = RepeatBitVec(4, x)
3988  >>> n
3989  RepeatBitVec(4, x)
3990  >>> n.size()
3991  32
3992  >>> v0 = BitVecVal(10, 4)
3993  >>> print("%.x" % v0.as_long())
3994  a
3995  >>> v = simplify(RepeatBitVec(4, v0))
3996  >>> v.size()
3997  16
3998  >>> print("%.x" % v.as_long())
3999  aaaa
4000  """
4001  if __debug__:
4002  _z3_assert(_is_int(n), "First argument must be an integer")
4003  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
4004  return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
4005 
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
def is_bv(a)
Definition: z3py.py:3536
def RepeatBitVec(n, a)
Definition: z3py.py:3983

§ Replace()

def z3py.Replace (   s,
  src,
  dst 
)
Replace the first occurrence of 'src' by 'dst' in 's'
>>> r = Replace("aaa", "a", "b")
>>> simplify(r)
"baa"

Definition at line 9930 of file z3py.py.

9930 def Replace(s, src, dst):
9931  """Replace the first occurrence of 'src' by 'dst' in 's'
9932  >>> r = Replace("aaa", "a", "b")
9933  >>> simplify(r)
9934  "baa"
9935  """
9936  ctx = _get_ctx2(dst, s)
9937  if ctx is None and is_expr(src):
9938  ctx = src.ctx
9939  src = _coerce_seq(src, ctx)
9940  dst = _coerce_seq(dst, ctx)
9941  s = _coerce_seq(s, ctx)
9942  return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
9943 
Z3_ast Z3_API Z3_mk_seq_replace(Z3_context c, Z3_ast s, Z3_ast src, Z3_ast dst)
Replace the first occurrence of src with dst in s.
def Replace(s, src, dst)
Definition: z3py.py:9930
def is_expr(a)
Definition: z3py.py:1047

§ reset_params()

def z3py.reset_params ( )
Reset all global (or module) parameters.

Definition at line 252 of file z3py.py.

252 def reset_params():
253  """Reset all global (or module) parameters.
254  """
256 
def reset_params()
Definition: z3py.py:252
void Z3_API Z3_global_param_reset_all(void)
Restore the value of all global (and module) parameters. This command will not affect already created...

§ ReSort()

def z3py.ReSort (   s)

Definition at line 10014 of file z3py.py.

Referenced by Empty(), Full(), Context.mkReSort(), and Sort.translate().

10014 def ReSort(s):
10015  if is_ast(s):
10016  return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
10017  if s is None or isinstance(s, Context):
10018  ctx = _get_ctx(s)
10019  return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
10020  raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
10021 
10022 
def ReSort(s)
Definition: z3py.py:10014
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for 8 bit strings.
def is_ast(a)
Definition: z3py.py:392
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort seq)
Create a regular expression sort out of a sequence sort.

§ RNA()

def z3py.RNA (   ctx = None)

Definition at line 8745 of file z3py.py.

8745 def RNA (ctx=None):
8746  ctx = _get_ctx(ctx)
8747  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
8748 
def RNA(ctx=None)
Definition: z3py.py:8745
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_away(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode...

§ RNE()

def z3py.RNE (   ctx = None)

Definition at line 8737 of file z3py.py.

Referenced by fpAbs(), fpAdd(), fpDiv(), fpFPToFP(), fpMax(), fpMin(), fpMul(), fpNeg(), fpRealToFP(), FPs(), fpSignedToFP(), fpSub(), fpToFP(), fpUnsignedToFP(), is_fprm(), and is_fprm_sort().

8737 def RNE (ctx=None):
8738  ctx = _get_ctx(ctx)
8739  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
8740 
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_even(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode...
def RNE(ctx=None)
Definition: z3py.py:8737

§ RotateLeft()

def z3py.RotateLeft (   a,
  b 
)
Return an expression representing `a` rotated to the left `b` times.

>>> a, b = BitVecs('a b', 16)
>>> RotateLeft(a, b)
RotateLeft(a, b)
>>> simplify(RotateLeft(a, 0))
a
>>> simplify(RotateLeft(a, 16))
a

Definition at line 3897 of file z3py.py.

3897 def RotateLeft(a, b):
3898  """Return an expression representing `a` rotated to the left `b` times.
3899 
3900  >>> a, b = BitVecs('a b', 16)
3901  >>> RotateLeft(a, b)
3902  RotateLeft(a, b)
3903  >>> simplify(RotateLeft(a, 0))
3904  a
3905  >>> simplify(RotateLeft(a, 16))
3906  a
3907  """
3908  _check_bv_args(a, b)
3909  a, b = _coerce_exprs(a, b)
3910  return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3911 
def RotateLeft(a, b)
Definition: z3py.py:3897
Z3_ast Z3_API Z3_mk_ext_rotate_left(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the left t2 times.

§ RotateRight()

def z3py.RotateRight (   a,
  b 
)
Return an expression representing `a` rotated to the right `b` times.

>>> a, b = BitVecs('a b', 16)
>>> RotateRight(a, b)
RotateRight(a, b)
>>> simplify(RotateRight(a, 0))
a
>>> simplify(RotateRight(a, 16))
a

Definition at line 3912 of file z3py.py.

3912 def RotateRight(a, b):
3913  """Return an expression representing `a` rotated to the right `b` times.
3914 
3915  >>> a, b = BitVecs('a b', 16)
3916  >>> RotateRight(a, b)
3917  RotateRight(a, b)
3918  >>> simplify(RotateRight(a, 0))
3919  a
3920  >>> simplify(RotateRight(a, 16))
3921  a
3922  """
3923  _check_bv_args(a, b)
3924  a, b = _coerce_exprs(a, b)
3925  return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3926 
Z3_ast Z3_API Z3_mk_ext_rotate_right(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the right t2 times.
def RotateRight(a, b)
Definition: z3py.py:3912

§ RoundNearestTiesToAway()

def z3py.RoundNearestTiesToAway (   ctx = None)

Definition at line 8741 of file z3py.py.

8741 def RoundNearestTiesToAway(ctx=None):
8742  ctx = _get_ctx(ctx)
8743  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
8744 
def RoundNearestTiesToAway(ctx=None)
Definition: z3py.py:8741
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_away(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode...

§ RoundNearestTiesToEven()

def z3py.RoundNearestTiesToEven (   ctx = None)

Definition at line 8733 of file z3py.py.

8733 def RoundNearestTiesToEven(ctx=None):
8734  ctx = _get_ctx(ctx)
8735  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
8736 
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_even(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode...
def RoundNearestTiesToEven(ctx=None)
Definition: z3py.py:8733

§ RoundTowardNegative()

def z3py.RoundTowardNegative (   ctx = None)

Definition at line 8757 of file z3py.py.

8757 def RoundTowardNegative(ctx=None):
8758  ctx = _get_ctx(ctx)
8759  return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
8760 
def RoundTowardNegative(ctx=None)
Definition: z3py.py:8757
Z3_ast Z3_API Z3_mk_fpa_round_toward_negative(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode...

§ RoundTowardPositive()

def z3py.RoundTowardPositive (   ctx = None)

Definition at line 8749 of file z3py.py.

8749 def RoundTowardPositive(ctx=None):
8750  ctx = _get_ctx(ctx)
8751  return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
8752 
def RoundTowardPositive(ctx=None)
Definition: z3py.py:8749
Z3_ast Z3_API Z3_mk_fpa_round_toward_positive(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode...

§ RoundTowardZero()

def z3py.RoundTowardZero (   ctx = None)

Definition at line 8765 of file z3py.py.

8765 def RoundTowardZero(ctx=None):
8766  ctx = _get_ctx(ctx)
8767  return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
8768 
Z3_ast Z3_API Z3_mk_fpa_round_toward_zero(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.
def RoundTowardZero(ctx=None)
Definition: z3py.py:8765

§ RTN()

def z3py.RTN (   ctx = None)

Definition at line 8761 of file z3py.py.

8761 def RTN(ctx=None):
8762  ctx = _get_ctx(ctx)
8763  return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
8764 
def RTN(ctx=None)
Definition: z3py.py:8761
Z3_ast Z3_API Z3_mk_fpa_round_toward_negative(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode...

§ RTP()

def z3py.RTP (   ctx = None)

Definition at line 8753 of file z3py.py.

8753 def RTP(ctx=None):
8754  ctx = _get_ctx(ctx)
8755  return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
8756 
def RTP(ctx=None)
Definition: z3py.py:8753
Z3_ast Z3_API Z3_mk_fpa_round_toward_positive(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode...

§ RTZ()

def z3py.RTZ (   ctx = None)

Definition at line 8769 of file z3py.py.

Referenced by fpAdd(), fpToSBV(), and fpToUBV().

8769 def RTZ(ctx=None):
8770  ctx = _get_ctx(ctx)
8771  return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
8772 
def RTZ(ctx=None)
Definition: z3py.py:8769
Z3_ast Z3_API Z3_mk_fpa_round_toward_zero(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.

§ Select()

def z3py.Select (   a,
  i 
)
Return a Z3 select array expression.

>>> a = Array('a', IntSort(), IntSort())
>>> i = Int('i')
>>> Select(a, i)
a[i]
>>> eq(Select(a, i), a[i])
True

Definition at line 4303 of file z3py.py.

4303 def Select(a, i):
4304  """Return a Z3 select array expression.
4305 
4306  >>> a = Array('a', IntSort(), IntSort())
4307  >>> i = Int('i')
4308  >>> Select(a, i)
4309  a[i]
4310  >>> eq(Select(a, i), a[i])
4311  True
4312  """
4313  if __debug__:
4314  _z3_assert(is_array(a), "First argument must be a Z3 array expression")
4315  return a[i]
4316 
4317 
def is_array(a)
Definition: z3py.py:4144
def Select(a, i)
Definition: z3py.py:4303

§ SeqSort()

def z3py.SeqSort (   s)
Create a sequence sort over elements provided in the argument
>>> s = SeqSort(IntSort())
>>> s == Unit(IntVal(1)).sort()
True

Definition at line 9735 of file z3py.py.

Referenced by Empty(), Full(), SeqSortRef.is_string(), Context.mkSeqSort(), Context.mkStringSort(), and Sort.translate().

9735 def SeqSort(s):
9736  """Create a sequence sort over elements provided in the argument
9737  >>> s = SeqSort(IntSort())
9738  >>> s == Unit(IntVal(1)).sort()
9739  True
9740  """
9741  return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
9742 
def SeqSort(s)
Definition: z3py.py:9735
Z3_sort Z3_API Z3_mk_seq_sort(Z3_context c, Z3_sort s)
Create a sequence sort out of the sort for the elements.

§ sequence_interpolant()

def z3py.sequence_interpolant (   v,
  p = None,
  ctx = None 
)
Compute interpolant for a sequence of formulas.

If len(v) == N, and if the conjunction of the formulas in v is
unsatisfiable, the interpolant is a sequence of formulas w
such that len(w) = N-1 and v[0] implies w[0] and for i in 0..N-1:

1) w[i] & v[i+1] implies w[i+1] (or false if i+1 = N)
2) All uninterpreted symbols in w[i] occur in both v[0]..v[i]
and v[i+1]..v[n]

Requires len(v) >= 1.

If a & b is satisfiable, raises an object of class ModelRef
that represents a model of a & b.

If neither a proof of unsatisfiability nor a model is obtained
(for example, because of a timeout, or because models are disabled)
then None is returned.

If parameters p are supplied, these are used in creating the
solver that determines satisfiability.

x = Int('x')
y = Int('y')
print(sequence_interpolant([x < 0, y == x , y > 2]))
[Not(x >= 0), Not(y >= 0)]

Definition at line 8332 of file z3py.py.

8332 def sequence_interpolant(v,p=None,ctx=None):
8333  """Compute interpolant for a sequence of formulas.
8334 
8335  If len(v) == N, and if the conjunction of the formulas in v is
8336  unsatisfiable, the interpolant is a sequence of formulas w
8337  such that len(w) = N-1 and v[0] implies w[0] and for i in 0..N-1:
8338 
8339  1) w[i] & v[i+1] implies w[i+1] (or false if i+1 = N)
8340  2) All uninterpreted symbols in w[i] occur in both v[0]..v[i]
8341  and v[i+1]..v[n]
8342 
8343  Requires len(v) >= 1.
8344 
8345  If a & b is satisfiable, raises an object of class ModelRef
8346  that represents a model of a & b.
8347 
8348  If neither a proof of unsatisfiability nor a model is obtained
8349  (for example, because of a timeout, or because models are disabled)
8350  then None is returned.
8351 
8352  If parameters p are supplied, these are used in creating the
8353  solver that determines satisfiability.
8354 
8355  x = Int('x')
8356  y = Int('y')
8357  print(sequence_interpolant([x < 0, y == x , y > 2]))
8358  [Not(x >= 0), Not(y >= 0)]
8359  """
8360  f = v[0]
8361  for i in range(1,len(v)):
8362  f = And(Interpolant(f),v[i])
8363  return tree_interpolant(f,p,ctx)
8364 
8365 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def And(args)
Definition: z3py.py:1592
def Interpolant(a, ctx=None)
Definition: z3py.py:8225
def sequence_interpolant(v, p=None, ctx=None)
Definition: z3py.py:8332
def tree_interpolant(pat, p=None, ctx=None)
Definition: z3py.py:8239

§ set_default_fp_sort()

def z3py.set_default_fp_sort (   ebits,
  sbits,
  ctx = None 
)

Definition at line 8408 of file z3py.py.

8408 def set_default_fp_sort(ebits, sbits, ctx=None):
8409  global _dflt_fpsort_ebits
8410  global _dflt_fpsort_sbits
8411  _dflt_fpsort_ebits = ebits
8412  _dflt_fpsort_sbits = sbits
8413 
def set_default_fp_sort(ebits, sbits, ctx=None)
Definition: z3py.py:8408

§ set_default_rounding_mode()

def z3py.set_default_rounding_mode (   rm,
  ctx = None 
)

Definition at line 8392 of file z3py.py.

8392 def set_default_rounding_mode(rm, ctx=None):
8393  global _dflt_rounding_mode
8394  if is_fprm_value(rm):
8395  _dflt_rounding_mode = rm.decl().kind()
8396  else:
8397  _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO or
8398  _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE or
8399  _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE or
8400  _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN or
8401  _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY,
8402  "illegal rounding mode")
8403  _dflt_rounding_mode = rm
8404 
def set_default_rounding_mode(rm, ctx=None)
Definition: z3py.py:8392
def is_fprm_value(a)
Definition: z3py.py:8785

§ set_option()

def z3py.set_option (   args,
  kws 
)
Alias for 'set_param' for backward compatibility.

Definition at line 257 of file z3py.py.

257 def set_option(*args, **kws):
258  """Alias for 'set_param' for backward compatibility.
259  """
260  return set_param(*args, **kws)
261 
def set_option(args, kws)
Definition: z3py.py:257
def set_param(args, kws)
Definition: z3py.py:229

§ set_param()

def z3py.set_param (   args,
  kws 
)
Set Z3 global (or module) parameters.

>>> set_param(precision=10)

Definition at line 229 of file z3py.py.

Referenced by set_option().

229 def set_param(*args, **kws):
230  """Set Z3 global (or module) parameters.
231 
232  >>> set_param(precision=10)
233  """
234  if __debug__:
235  _z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
236  new_kws = {}
237  for k in kws:
238  v = kws[k]
239  if not set_pp_option(k, v):
240  new_kws[k] = v
241  for key in new_kws:
242  value = new_kws[key]
243  Z3_global_param_set(str(key).upper(), _to_param_value(value))
244  prev = None
245  for a in args:
246  if prev is None:
247  prev = a
248  else:
249  Z3_global_param_set(str(prev), _to_param_value(a))
250  prev = None
251 
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value)
Set a global (or module) parameter. This setting is shared by all Z3 contexts.
def set_param(args, kws)
Definition: z3py.py:229

§ SignExt()

def z3py.SignExt (   n,
  a 
)
Return a bit-vector expression with `n` extra sign-bits.

>>> x = BitVec('x', 16)
>>> n = SignExt(8, x)
>>> n.size()
24
>>> n
SignExt(8, x)
>>> n.sort()
BitVec(24)
>>> v0 = BitVecVal(2, 2)
>>> v0
2
>>> v0.size()
2
>>> v  = simplify(SignExt(6, v0))
>>> v
254
>>> v.size()
8
>>> print("%.x" % v.as_long())
fe

Definition at line 3927 of file z3py.py.

3927 def SignExt(n, a):
3928  """Return a bit-vector expression with `n` extra sign-bits.
3929 
3930  >>> x = BitVec('x', 16)
3931  >>> n = SignExt(8, x)
3932  >>> n.size()
3933  24
3934  >>> n
3935  SignExt(8, x)
3936  >>> n.sort()
3937  BitVec(24)
3938  >>> v0 = BitVecVal(2, 2)
3939  >>> v0
3940  2
3941  >>> v0.size()
3942  2
3943  >>> v = simplify(SignExt(6, v0))
3944  >>> v
3945  254
3946  >>> v.size()
3947  8
3948  >>> print("%.x" % v.as_long())
3949  fe
3950  """
3951  if __debug__:
3952  _z3_assert(_is_int(n), "First argument must be an integer")
3953  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
3954  return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
3955 
def SignExt(n, a)
Definition: z3py.py:3927
Z3_ast Z3_API Z3_mk_sign_ext(Z3_context c, unsigned i, Z3_ast t1)
Sign-extend of the given bit-vector to the (signed) equivalent bit-vector of size m+i...
def is_bv(a)
Definition: z3py.py:3536

§ SimpleSolver()

def z3py.SimpleSolver (   ctx = None)
Return a simple general purpose solver with limited amount of preprocessing.

>>> s = SimpleSolver()
>>> x = Int('x')
>>> s.add(x > 0)
>>> s.check()
sat

Definition at line 6531 of file z3py.py.

Referenced by Solver.reason_unknown(), and Solver.statistics().

6531 def SimpleSolver(ctx=None):
6532  """Return a simple general purpose solver with limited amount of preprocessing.
6533 
6534  >>> s = SimpleSolver()
6535  >>> x = Int('x')
6536  >>> s.add(x > 0)
6537  >>> s.check()
6538  sat
6539  """
6540  ctx = _get_ctx(ctx)
6541  return Solver(Z3_mk_simple_solver(ctx.ref()), ctx)
6542 
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
def SimpleSolver(ctx=None)
Definition: z3py.py:6531

§ simplify()

def z3py.simplify (   a,
  arguments,
  keywords 
)

Utils.

Simplify the expression `a` using the given options.

This function has many options. Use `help_simplify` to obtain the complete list.

>>> x = Int('x')
>>> y = Int('y')
>>> simplify(x + 1 + y + x + 1)
2 + 2*x + y
>>> simplify((x + 1)*(y + 1), som=True)
1 + x + y + x*y
>>> simplify(Distinct(x, y, 1), blast_distinct=True)
And(Not(x == y), Not(x == 1), Not(y == 1))
>>> simplify(And(x == 0, y == 1), elim_and=True)
Not(Or(Not(x == 0), Not(y == 1)))

Definition at line 7793 of file z3py.py.

Referenced by BitVecRef.__invert__(), BitVecRef.__lshift__(), ArithRef.__mod__(), ArithRef.__neg__(), BitVecRef.__neg__(), ArithRef.__pow__(), ArithRef.__rpow__(), BitVecRef.__rshift__(), AlgebraicNumRef.approx(), AlgebraicNumRef.as_decimal(), BitVecs(), Concat(), Contains(), CreateDatatypes(), Extract(), fpBVToFP(), fpFPToFP(), fpRealToFP(), fpSignedToFP(), fpToFP(), fpUnsignedToFP(), Implies(), IndexOf(), InRe(), is_algebraic_value(), K(), Length(), Loop(), LShR(), Not(), Option(), Plus(), PrefixOf(), DatatypeSortRef.recognizer(), RepeatBitVec(), Replace(), RotateLeft(), RotateRight(), SignExt(), Star(), StrToInt(), SuffixOf(), Union(), Xor(), and ZeroExt().

7793 def simplify(a, *arguments, **keywords):
7794  """Simplify the expression `a` using the given options.
7795 
7796  This function has many options. Use `help_simplify` to obtain the complete list.
7797 
7798  >>> x = Int('x')
7799  >>> y = Int('y')
7800  >>> simplify(x + 1 + y + x + 1)
7801  2 + 2*x + y
7802  >>> simplify((x + 1)*(y + 1), som=True)
7803  1 + x + y + x*y
7804  >>> simplify(Distinct(x, y, 1), blast_distinct=True)
7805  And(Not(x == y), Not(x == 1), Not(y == 1))
7806  >>> simplify(And(x == 0, y == 1), elim_and=True)
7807  Not(Or(Not(x == 0), Not(y == 1)))
7808  """
7809  if __debug__:
7810  _z3_assert(is_expr(a), "Z3 expression expected")
7811  if len(arguments) > 0 or len(keywords) > 0:
7812  p = args2params(arguments, keywords, a.ctx)
7813  return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
7814  else:
7815  return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
7816 
def simplify(a, arguments, keywords)
Utils.
Definition: z3py.py:7793
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:4766
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
def is_expr(a)
Definition: z3py.py:1047

§ simplify_param_descrs()

def z3py.simplify_param_descrs ( )
Return the set of parameter descriptions for Z3 `simplify` procedure.

Definition at line 7821 of file z3py.py.

7821 def simplify_param_descrs():
7822  """Return the set of parameter descriptions for Z3 `simplify` procedure."""
7823  return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
7824 
def main_ctx()
Definition: z3py.py:203
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.
def simplify_param_descrs()
Definition: z3py.py:7821

§ solve()

def z3py.solve (   args,
  keywords 
)
Solve the constraints `*args`.

This is a simple function for creating demonstrations. It creates a solver,
configure it using the options in `keywords`, adds the constraints
in `args`, and invokes check.

>>> a = Int('a')
>>> solve(a > 0, a < 2)
[a = 1]

Definition at line 8002 of file z3py.py.

Referenced by BV2Int(), and IsInt().

8002 def solve(*args, **keywords):
8003  """Solve the constraints `*args`.
8004 
8005  This is a simple function for creating demonstrations. It creates a solver,
8006  configure it using the options in `keywords`, adds the constraints
8007  in `args`, and invokes check.
8008 
8009  >>> a = Int('a')
8010  >>> solve(a > 0, a < 2)
8011  [a = 1]
8012  """
8013  s = Solver()
8014  s.set(**keywords)
8015  s.add(*args)
8016  if keywords.get('show', False):
8017  print(s)
8018  r = s.check()
8019  if r == unsat:
8020  print("no solution")
8021  elif r == unknown:
8022  print("failed to solve")
8023  try:
8024  print(s.model())
8025  except Z3Exception:
8026  return
8027  else:
8028  print(s.model())
8029 
def solve(args, keywords)
Definition: z3py.py:8002

§ solve_using()

def z3py.solve_using (   s,
  args,
  keywords 
)
Solve the constraints `*args` using solver `s`.

This is a simple function for creating demonstrations. It is similar to `solve`,
but it uses the given solver `s`.
It configures solver `s` using the options in `keywords`, adds the constraints
in `args`, and invokes check.

Definition at line 8030 of file z3py.py.

8030 def solve_using(s, *args, **keywords):
8031  """Solve the constraints `*args` using solver `s`.
8032 
8033  This is a simple function for creating demonstrations. It is similar to `solve`,
8034  but it uses the given solver `s`.
8035  It configures solver `s` using the options in `keywords`, adds the constraints
8036  in `args`, and invokes check.
8037  """
8038  if __debug__:
8039  _z3_assert(isinstance(s, Solver), "Solver object expected")
8040  s.set(**keywords)
8041  s.add(*args)
8042  if keywords.get('show', False):
8043  print("Problem:")
8044  print(s)
8045  r = s.check()
8046  if r == unsat:
8047  print("no solution")
8048  elif r == unknown:
8049  print("failed to solve")
8050  try:
8051  print(s.model())
8052  except Z3Exception:
8053  return
8054  else:
8055  if keywords.get('show', False):
8056  print("Solution:")
8057  print(s.model())
8058 
def solve_using(s, args, keywords)
Definition: z3py.py:8030

§ SolverFor()

def z3py.SolverFor (   logic,
  ctx = None 
)
Create a solver customized for the given logic.

The parameter `logic` is a string. It should be contains
the name of a SMT-LIB logic.
See http://www.smtlib.org/ for the name of all available logics.

>>> s = SolverFor("QF_LIA")
>>> x = Int('x')
>>> s.add(x > 0)
>>> s.add(x < 2)
>>> s.check()
sat
>>> s.model()
[x = 1]

Definition at line 6511 of file z3py.py.

6511 def SolverFor(logic, ctx=None):
6512  """Create a solver customized for the given logic.
6513 
6514  The parameter `logic` is a string. It should be contains
6515  the name of a SMT-LIB logic.
6516  See http://www.smtlib.org/ for the name of all available logics.
6517 
6518  >>> s = SolverFor("QF_LIA")
6519  >>> x = Int('x')
6520  >>> s.add(x > 0)
6521  >>> s.add(x < 2)
6522  >>> s.check()
6523  sat
6524  >>> s.model()
6525  [x = 1]
6526  """
6527  ctx = _get_ctx(ctx)
6528  logic = to_symbol(logic)
6529  return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx)
6530 
def to_symbol(s, ctx=None)
Definition: z3py.py:101
Z3_solver Z3_API Z3_mk_solver_for_logic(Z3_context c, Z3_symbol logic)
Create a new solver customized for the given logic. It behaves like Z3_mk_solver if the logic is unkn...
def SolverFor(logic, ctx=None)
Definition: z3py.py:6511

§ Sqrt()

def z3py.Sqrt (   a,
  ctx = None 
)
Return a Z3 expression which represents the square root of a.

>>> x = Real('x')
>>> Sqrt(x)
x**(1/2)

Definition at line 3013 of file z3py.py.

Referenced by AlgebraicNumRef.approx(), AlgebraicNumRef.as_decimal(), and is_algebraic_value().

3013 def Sqrt(a, ctx=None):
3014  """ Return a Z3 expression which represents the square root of a.
3015 
3016  >>> x = Real('x')
3017  >>> Sqrt(x)
3018  x**(1/2)
3019  """
3020  if not is_expr(a):
3021  ctx = _get_ctx(ctx)
3022  a = RealVal(a, ctx)
3023  return a ** "1/2"
3024 
def RealVal(val, ctx=None)
Definition: z3py.py:2818
def is_expr(a)
Definition: z3py.py:1047
def Sqrt(a, ctx=None)
Definition: z3py.py:3013

§ SRem()

def z3py.SRem (   a,
  b 
)
Create the Z3 expression signed remainder.

Use the operator % for signed modulus, and URem() for unsigned remainder.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> SRem(x, y)
SRem(x, y)
>>> SRem(x, y).sort()
BitVec(32)
>>> (x % y).sexpr()
'(bvsmod x y)'
>>> SRem(x, y).sexpr()
'(bvsrem x y)'

Definition at line 3846 of file z3py.py.

Referenced by BitVecRef.__mod__(), BitVecRef.__rmod__(), and URem().

3846 def SRem(a, b):
3847  """Create the Z3 expression signed remainder.
3848 
3849  Use the operator % for signed modulus, and URem() for unsigned remainder.
3850 
3851  >>> x = BitVec('x', 32)
3852  >>> y = BitVec('y', 32)
3853  >>> SRem(x, y)
3854  SRem(x, y)
3855  >>> SRem(x, y).sort()
3856  BitVec(32)
3857  >>> (x % y).sexpr()
3858  '(bvsmod x y)'
3859  >>> SRem(x, y).sexpr()
3860  '(bvsrem x y)'
3861  """
3862  _check_bv_args(a, b)
3863  a, b = _coerce_exprs(a, b)
3864  return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3865 
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two&#39;s complement signed remainder (sign follows dividend).
def SRem(a, b)
Definition: z3py.py:3846

§ Star()

def z3py.Star (   re)
Create the regular expression accepting zero or more repetitions of argument.
>>> re = Star(Re("a"))
>>> print(simplify(InRe("aa", re)))
True
>>> print(simplify(InRe("ab", re)))
False
>>> print(simplify(InRe("", re)))
True

Definition at line 10094 of file z3py.py.

10094 def Star(re):
10095  """Create the regular expression accepting zero or more repetitions of argument.
10096  >>> re = Star(Re("a"))
10097  >>> print(simplify(InRe("aa", re)))
10098  True
10099  >>> print(simplify(InRe("ab", re)))
10100  False
10101  >>> print(simplify(InRe("", re)))
10102  True
10103  """
10104  return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
10105 
def Star(re)
Definition: z3py.py:10094
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.

§ Store()

def z3py.Store (   a,
  i,
  v 
)
Return a Z3 store array expression.

>>> a    = Array('a', IntSort(), IntSort())
>>> i, v = Ints('i v')
>>> s    = Store(a, i, v)
>>> s.sort()
Array(Int, Int)
>>> prove(s[i] == v)
proved
>>> j    = Int('j')
>>> prove(Implies(i != j, s[j] == a[j]))
proved

Definition at line 4287 of file z3py.py.

Referenced by is_array(), and is_store().

4287 def Store(a, i, v):
4288  """Return a Z3 store array expression.
4289 
4290  >>> a = Array('a', IntSort(), IntSort())
4291  >>> i, v = Ints('i v')
4292  >>> s = Store(a, i, v)
4293  >>> s.sort()
4294  Array(Int, Int)
4295  >>> prove(s[i] == v)
4296  proved
4297  >>> j = Int('j')
4298  >>> prove(Implies(i != j, s[j] == a[j]))
4299  proved
4300  """
4301  return Update(a, i, v)
4302 
def Update(a, i, v)
Definition: z3py.py:4255
def Store(a, i, v)
Definition: z3py.py:4287

§ String()

def z3py.String (   name,
  ctx = None 
)
Return a string constant named `name`. If `ctx=None`, then the global context is used.

>>> x = String('x')

Definition at line 9821 of file z3py.py.

Referenced by Optimize.Add(), Probe.apply(), Native.applyResultToString(), Native.astMapToString(), Native.astToString(), Native.astVectorToString(), Native.benchmarkToSmtlibString(), Context.Context(), Native.evalSmtlib2String(), Native.fixedpointGetHelp(), Native.fixedpointGetReasonUnknown(), Native.fixedpointToString(), Native.fpaGetNumeralExponentString(), Native.fpaGetNumeralSignificandString(), Native.funcDeclToString(), Native.getDeclRationalParameter(), Statistics.getEntries(), Native.getErrorMsg(), Native.getFullVersion(), Statistics.getKeys(), Native.getNumeralDecimalString(), Native.getNumeralString(), FuncDecl.Parameter.getParameterKind(), Native.getParserError(), Native.getProbeName(), Context.getProbeNames(), Tactic.getSolver(), StringSymbol.getString(), Native.getString(), Native.getSymbolString(), Native.getTacticName(), Context.getTacticNames(), Native.goalToString(), Native.interpolationProfile(), InterpolationContext.mkContext(), Context.mkSymbol(), Native.modelToString(), Native.optimizeGetHelp(), Native.optimizeGetReasonUnknown(), Native.optimizeToString(), Native.paramDescrsGetDocumentation(), Native.paramDescrsToString(), Native.paramsToString(), Native.patternToString(), Native.probeGetDescr(), Native.rcfNumToDecimalString(), Native.rcfNumToString(), Native.simplifyGetHelp(), Native.solverGetHelp(), Native.solverGetReasonUnknown(), Native.solverToString(), Native.sortToString(), Native.statsGetKey(), Native.statsToString(), Native.tacticGetDescr(), Native.tacticGetHelp(), Statistics.Entry.toString(), and FuncInterp.toString().

9821 def String(name, ctx=None):
9822  """Return a string constant named `name`. If `ctx=None`, then the global context is used.
9823 
9824  >>> x = String('x')
9825  """
9826  ctx = _get_ctx(ctx)
9827  return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
9828 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:101
def StringSort(ctx=None)
Definition: z3py.py:9725
def String(name, ctx=None)
Definition: z3py.py:9821

§ Strings()

def z3py.Strings (   names,
  ctx = None 
)
Return a tuple of String constants. 

Definition at line 9837 of file z3py.py.

Referenced by Contains().

9837 def Strings(names, ctx=None):
9838  """Return a tuple of String constants. """
9839  ctx = _get_ctx(ctx)
9840  if isinstance(names, str):
9841  names = names.split(" ")
9842  return [String(name, ctx) for name in names]
9843 
def Strings(names, ctx=None)
Definition: z3py.py:9837
def String(name, ctx=None)
Definition: z3py.py:9821

§ StringSort()

def z3py.StringSort (   ctx = None)
Create a string sort
>>> s = StringSort()
>>> print(s)
String

Definition at line 9725 of file z3py.py.

Referenced by Empty(), Full(), and SeqSortRef.is_string().

9725 def StringSort(ctx=None):
9726  """Create a string sort
9727  >>> s = StringSort()
9728  >>> print(s)
9729  String
9730  """
9731  ctx = _get_ctx(ctx)
9732  return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
9733 
9734 
def StringSort(ctx=None)
Definition: z3py.py:9725
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for 8 bit strings.

§ StringVal()

def z3py.StringVal (   s,
  ctx = None 
)
create a string expression

Definition at line 9816 of file z3py.py.

Referenced by Empty(), Extract(), is_seq(), is_string(), is_string_value(), Length(), and Re().

9816 def StringVal(s, ctx=None):
9817  """create a string expression"""
9818  ctx = _get_ctx(ctx)
9819  return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
9820 
Z3_ast Z3_API Z3_mk_string(Z3_context c, Z3_string s)
Create a string constant out of the string that is passed in.
def StringVal(s, ctx=None)
Definition: z3py.py:9816

§ StrToInt()

def z3py.StrToInt (   s)
Convert string expression to integer
>>> a = StrToInt("1")
>>> simplify(1 == a)
True
>>> b = StrToInt("2")
>>> simplify(1 == b)
False
>>> c = StrToInt(IntToStr(2))
>>> simplify(1 == c)
False

Definition at line 9973 of file z3py.py.

9973 def StrToInt(s):
9974  """Convert string expression to integer
9975  >>> a = StrToInt("1")
9976  >>> simplify(1 == a)
9977  True
9978  >>> b = StrToInt("2")
9979  >>> simplify(1 == b)
9980  False
9981  >>> c = StrToInt(IntToStr(2))
9982  >>> simplify(1 == c)
9983  False
9984  """
9985  s = _coerce_seq(s)
9986  return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
9987 
9988 
Z3_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.
def StrToInt(s)
Definition: z3py.py:9973

§ SubSeq()

def z3py.SubSeq (   s,
  offset,
  length 
)
Extract substring or subsequence starting at offset

Definition at line 9833 of file z3py.py.

9833 def SubSeq(s, offset, length):
9834  """Extract substring or subsequence starting at offset"""
9835  return Extract(s, offset, length)
9836 
def SubSeq(s, offset, length)
Definition: z3py.py:9833
def Extract(high, low, a)
Definition: z3py.py:3711

§ substitute()

def z3py.substitute (   t,
  m 
)
Apply substitution m on t, m is a list of pairs of the form (from, to). Every occurrence in t of from is replaced with to.

>>> x = Int('x')
>>> y = Int('y')
>>> substitute(x + 1, (x, y + 1))
y + 1 + 1
>>> f = Function('f', IntSort(), IntSort())
>>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
1 + 1

Definition at line 7825 of file z3py.py.

Referenced by expr.simplify().

7825 def substitute(t, *m):
7826  """Apply substitution m on t, m is a list of pairs of the form (from, to). Every occurrence in t of from is replaced with to.
7827 
7828  >>> x = Int('x')
7829  >>> y = Int('y')
7830  >>> substitute(x + 1, (x, y + 1))
7831  y + 1 + 1
7832  >>> f = Function('f', IntSort(), IntSort())
7833  >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
7834  1 + 1
7835  """
7836  if isinstance(m, tuple):
7837  m1 = _get_args(m)
7838  if isinstance(m1, list):
7839  m = m1
7840  if __debug__:
7841  _z3_assert(is_expr(t), "Z3 expression expected")
7842  _z3_assert(all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) and p[0].sort().eq(p[1].sort()) for p in m]), "Z3 invalid substitution, expression pairs expected.")
7843  num = len(m)
7844  _from = (Ast * num)()
7845  _to = (Ast * num)()
7846  for i in range(num):
7847  _from[i] = m[i][0].as_ast()
7848  _to[i] = m[i][1].as_ast()
7849  return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
7850 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
Z3_ast Z3_API Z3_substitute(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const from[], Z3_ast const to[])
Substitute every occurrence of from[i] in a with to[i], for i smaller than num_exprs. The result is the new AST. The arrays from and to must have size num_exprs. For every i smaller than num_exprs, we must have that sort of from[i] must be equal to sort of to[i].
def substitute(t, m)
Definition: z3py.py:7825
def eq(a, b)
Definition: z3py.py:412
def is_expr(a)
Definition: z3py.py:1047

§ substitute_vars()

def z3py.substitute_vars (   t,
  m 
)
Substitute the free variables in t with the expression in m.

>>> v0 = Var(0, IntSort())
>>> v1 = Var(1, IntSort())
>>> x  = Int('x')
>>> f  = Function('f', IntSort(), IntSort(), IntSort())
>>> # replace v0 with x+1 and v1 with x
>>> substitute_vars(f(v0, v1), x + 1, x)
f(x + 1, x)

Definition at line 7851 of file z3py.py.

7851 def substitute_vars(t, *m):
7852  """Substitute the free variables in t with the expression in m.
7853 
7854  >>> v0 = Var(0, IntSort())
7855  >>> v1 = Var(1, IntSort())
7856  >>> x = Int('x')
7857  >>> f = Function('f', IntSort(), IntSort(), IntSort())
7858  >>> # replace v0 with x+1 and v1 with x
7859  >>> substitute_vars(f(v0, v1), x + 1, x)
7860  f(x + 1, x)
7861  """
7862  if __debug__:
7863  _z3_assert(is_expr(t), "Z3 expression expected")
7864  _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
7865  num = len(m)
7866  _to = (Ast * num)()
7867  for i in range(num):
7868  _to[i] = m[i].as_ast()
7869  return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
7870 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def substitute_vars(t, m)
Definition: z3py.py:7851
Z3_ast Z3_API Z3_substitute_vars(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const to[])
Substitute the free variables in a with the expressions in to. For every i smaller than num_exprs...
def is_expr(a)
Definition: z3py.py:1047

§ SubString()

def z3py.SubString (   s,
  offset,
  length 
)
Extract substring or subsequence starting at offset

Definition at line 9829 of file z3py.py.

9829 def SubString(s, offset, length):
9830  """Extract substring or subsequence starting at offset"""
9831  return Extract(s, offset, length)
9832 
def SubString(s, offset, length)
Definition: z3py.py:9829
def Extract(high, low, a)
Definition: z3py.py:3711

§ SuffixOf()

def z3py.SuffixOf (   a,
  b 
)
Check if 'a' is a suffix of 'b'
>>> s1 = SuffixOf("ab", "abc")
>>> simplify(s1)
False
>>> s2 = SuffixOf("bc", "abc")
>>> simplify(s2)
True

Definition at line 9897 of file z3py.py.

9897 def SuffixOf(a, b):
9898  """Check if 'a' is a suffix of 'b'
9899  >>> s1 = SuffixOf("ab", "abc")
9900  >>> simplify(s1)
9901  False
9902  >>> s2 = SuffixOf("bc", "abc")
9903  >>> simplify(s2)
9904  True
9905  """
9906  ctx = _get_ctx2(a, b)
9907  a = _coerce_seq(a, ctx)
9908  b = _coerce_seq(b, ctx)
9909  return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
9910 
Z3_ast Z3_API Z3_mk_seq_suffix(Z3_context c, Z3_ast suffix, Z3_ast s)
Check if suffix is a suffix of s.
def SuffixOf(a, b)
Definition: z3py.py:9897

§ Sum()

def z3py.Sum (   args)
Create the sum of the Z3 expressions.

>>> a, b, c = Ints('a b c')
>>> Sum(a, b, c)
a + b + c
>>> Sum([a, b, c])
a + b + c
>>> A = IntVector('a', 5)
>>> Sum(A)
a__0 + a__1 + a__2 + a__3 + a__4

Definition at line 7871 of file z3py.py.

Referenced by BitVecs(), Ints(), IntVector(), Reals(), and RealVector().

7871 def Sum(*args):
7872  """Create the sum of the Z3 expressions.
7873 
7874  >>> a, b, c = Ints('a b c')
7875  >>> Sum(a, b, c)
7876  a + b + c
7877  >>> Sum([a, b, c])
7878  a + b + c
7879  >>> A = IntVector('a', 5)
7880  >>> Sum(A)
7881  a__0 + a__1 + a__2 + a__3 + a__4
7882  """
7883  args = _get_args(args)
7884  if len(args) == 0:
7885  return 0
7886  ctx = _ctx_from_ast_arg_list(args)
7887  if ctx is None:
7888  return _reduce(lambda a, b: a + b, args, 0)
7889  args = _coerce_expr_list(args, ctx)
7890  if is_bv(args[0]):
7891  return _reduce(lambda a, b: a + b, args, 0)
7892  else:
7893  _args, sz = _to_ast_array(args)
7894  return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
7895 
7896 
def Sum(args)
Definition: z3py.py:7871
Z3_ast Z3_API Z3_mk_add(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] + ... + args[num_args-1].
def is_bv(a)
Definition: z3py.py:3536

§ tactic_description()

def z3py.tactic_description (   name,
  ctx = None 
)
Return a short description for the tactic named `name`.

>>> d = tactic_description('simplify')

Definition at line 7508 of file z3py.py.

Referenced by describe_tactics().

7508 def tactic_description(name, ctx=None):
7509  """Return a short description for the tactic named `name`.
7510 
7511  >>> d = tactic_description('simplify')
7512  """
7513  ctx = _get_ctx(ctx)
7514  return Z3_tactic_get_descr(ctx.ref(), name)
7515 
def tactic_description(name, ctx=None)
Definition: z3py.py:7508
Z3_string Z3_API Z3_tactic_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the tactic with the given name.

§ tactics()

def z3py.tactics (   ctx = None)
Return a list of all available tactics in Z3.

>>> l = tactics()
>>> l.count('simplify') == 1
True

Definition at line 7498 of file z3py.py.

Referenced by describe_tactics(), and tactic.help().

7498 def tactics(ctx=None):
7499  """Return a list of all available tactics in Z3.
7500 
7501  >>> l = tactics()
7502  >>> l.count('simplify') == 1
7503  True
7504  """
7505  ctx = _get_ctx(ctx)
7506  return [ Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref())) ]
7507 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
Z3_string Z3_API Z3_get_tactic_name(Z3_context c, unsigned i)
Return the name of the idx tactic.
def tactics(ctx=None)
Definition: z3py.py:7498
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.

§ Then()

def z3py.Then (   ts,
  ks 
)
Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).

>>> x, y = Ints('x y')
>>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
>>> t(And(x == 0, y > x + 1))
[[Not(y <= 1)]]
>>> t(And(x == 0, y > x + 1)).as_expr()
Not(y <= 1)

Definition at line 7377 of file z3py.py.

Referenced by Statistics.__getattr__(), Statistics.__getitem__(), Statistics.__len__(), Goal.depth(), Statistics.get_key_value(), and Statistics.keys().

7377 def Then(*ts, **ks):
7378  """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
7379 
7380  >>> x, y = Ints('x y')
7381  >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
7382  >>> t(And(x == 0, y > x + 1))
7383  [[Not(y <= 1)]]
7384  >>> t(And(x == 0, y > x + 1)).as_expr()
7385  Not(y <= 1)
7386  """
7387  return AndThen(*ts, **ks)
7388 
def Then(ts, ks)
Definition: z3py.py:7377
def AndThen(ts, ks)
Definition: z3py.py:7358

§ to_symbol()

def z3py.to_symbol (   s,
  ctx = None 
)
Convert an integer or string into a Z3 symbol.

Definition at line 101 of file z3py.py.

Referenced by Fixedpoint.add_rule(), Optimize.add_soft(), Const(), DeclareSort(), FiniteDomainSort(), Function(), prove(), Fixedpoint.set_predicate_representation(), SolverFor(), and Fixedpoint.update_rule().

101 def to_symbol(s, ctx=None):
102  """Convert an integer or string into a Z3 symbol."""
103  if _is_int(s):
104  return Z3_mk_int_symbol(_get_ctx(ctx).ref(), s)
105  else:
106  return Z3_mk_string_symbol(_get_ctx(ctx).ref(), s)
107 
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
def to_symbol(s, ctx=None)
Definition: z3py.py:101
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.

§ ToInt()

def z3py.ToInt (   a)
Return the Z3 expression ToInt(a).

>>> x = Real('x')
>>> x.sort()
Real
>>> n = ToInt(x)
>>> n
ToInt(x)
>>> n.sort()
Int

Definition at line 2980 of file z3py.py.

Referenced by is_to_int().

2980 def ToInt(a):
2981  """ Return the Z3 expression ToInt(a).
2982 
2983  >>> x = Real('x')
2984  >>> x.sort()
2985  Real
2986  >>> n = ToInt(x)
2987  >>> n
2988  ToInt(x)
2989  >>> n.sort()
2990  Int
2991  """
2992  if __debug__:
2993  _z3_assert(a.is_real(), "Z3 real expression expected.")
2994  ctx = a.ctx
2995  return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
2996 
Z3_ast Z3_API Z3_mk_real2int(Z3_context c, Z3_ast t1)
Coerce a real to an integer.
def ToInt(a)
Definition: z3py.py:2980

§ ToReal()

def z3py.ToReal (   a)
Return the Z3 expression ToReal(a).

>>> x = Int('x')
>>> x.sort()
Int
>>> n = ToReal(x)
>>> n
ToReal(x)
>>> n.sort()
Real

Definition at line 2963 of file z3py.py.

Referenced by ArithRef.__ge__(), ArithRef.__gt__(), ArithRef.__le__(), ArithRef.__lt__(), and is_to_real().

2963 def ToReal(a):
2964  """ Return the Z3 expression ToReal(a).
2965 
2966  >>> x = Int('x')
2967  >>> x.sort()
2968  Int
2969  >>> n = ToReal(x)
2970  >>> n
2971  ToReal(x)
2972  >>> n.sort()
2973  Real
2974  """
2975  if __debug__:
2976  _z3_assert(a.is_int(), "Z3 integer expression expected.")
2977  ctx = a.ctx
2978  return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
2979 
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.
def ToReal(a)
Definition: z3py.py:2963

§ tree_interpolant()

def z3py.tree_interpolant (   pat,
  p = None,
  ctx = None 
)
Compute interpolant for a tree of formulas.

The input is an interpolation pattern over a set of formulas C.
The pattern pat is a formula combining the formulas in C using
logical conjunction and the "interp" operator (see Interp). This
interp operator is logically the identity operator. It marks the
sub-formulas of the pattern for which interpolants should be
computed. The interpolant is a map sigma from marked subformulas
to formulas, such that, for each marked subformula phi of pat
(where phi sigma is phi with sigma(psi) substituted for each
subformula psi of phi such that psi in dom(sigma)):

  1) phi sigma implies sigma(phi), and

  2) sigma(phi) is in the common uninterpreted vocabulary between
  the formulas of C occurring in phi and those not occurring in
  phi

  and moreover pat sigma implies false. In the simplest case
  an interpolant for the pattern "(and (interp A) B)" maps A
  to an interpolant for A /\ B.

  The return value is a vector of formulas representing sigma. This
  vector contains sigma(phi) for each marked subformula of pat, in
  pre-order traversal. This means that subformulas of phi occur before phi
  in the vector. Also, subformulas that occur multiply in pat will
  occur multiply in the result vector.

If pat is satisfiable, raises an object of class ModelRef
that represents a model of pat.

If neither a proof of unsatisfiability nor a model is obtained
(for example, because of a timeout, or because models are disabled)
then None is returned.

If parameters p are supplied, these are used in creating the
solver that determines satisfiability.

>>> x = Int('x')
>>> y = Int('y')        
>>> print(tree_interpolant(And(Interpolant(x < 0), Interpolant(y > 2), x == y)))
[Not(x >= 0), Not(y <= 2)]

# >>> g = And(Interpolant(x<0),x<2)
# >>> try:
# ...     print tree_interpolant(g).sexpr()
# ... except ModelRef as m:
# ...     print m.sexpr()
(define-fun x () Int
  (- 1))

Definition at line 8239 of file z3py.py.

8239 def tree_interpolant(pat,p=None,ctx=None):
8240  """Compute interpolant for a tree of formulas.
8241 
8242  The input is an interpolation pattern over a set of formulas C.
8243  The pattern pat is a formula combining the formulas in C using
8244  logical conjunction and the "interp" operator (see Interp). This
8245  interp operator is logically the identity operator. It marks the
8246  sub-formulas of the pattern for which interpolants should be
8247  computed. The interpolant is a map sigma from marked subformulas
8248  to formulas, such that, for each marked subformula phi of pat
8249  (where phi sigma is phi with sigma(psi) substituted for each
8250  subformula psi of phi such that psi in dom(sigma)):
8251 
8252  1) phi sigma implies sigma(phi), and
8253 
8254  2) sigma(phi) is in the common uninterpreted vocabulary between
8255  the formulas of C occurring in phi and those not occurring in
8256  phi
8257 
8258  and moreover pat sigma implies false. In the simplest case
8259  an interpolant for the pattern "(and (interp A) B)" maps A
8260  to an interpolant for A /\ B.
8261 
8262  The return value is a vector of formulas representing sigma. This
8263  vector contains sigma(phi) for each marked subformula of pat, in
8264  pre-order traversal. This means that subformulas of phi occur before phi
8265  in the vector. Also, subformulas that occur multiply in pat will
8266  occur multiply in the result vector.
8267 
8268  If pat is satisfiable, raises an object of class ModelRef
8269  that represents a model of pat.
8270 
8271  If neither a proof of unsatisfiability nor a model is obtained
8272  (for example, because of a timeout, or because models are disabled)
8273  then None is returned.
8274 
8275  If parameters p are supplied, these are used in creating the
8276  solver that determines satisfiability.
8277 
8278  >>> x = Int('x')
8279  >>> y = Int('y')
8280  >>> print(tree_interpolant(And(Interpolant(x < 0), Interpolant(y > 2), x == y)))
8281  [Not(x >= 0), Not(y <= 2)]
8282 
8283  # >>> g = And(Interpolant(x<0),x<2)
8284  # >>> try:
8285  # ... print tree_interpolant(g).sexpr()
8286  # ... except ModelRef as m:
8287  # ... print m.sexpr()
8288  (define-fun x () Int
8289  (- 1))
8290  """
8291  f = pat
8292  ctx = _get_ctx(_ctx_from_ast_arg_list([f], ctx))
8293  ptr = (AstVectorObj * 1)()
8294  mptr = (Model * 1)()
8295  if p is None:
8296  p = ParamsRef(ctx)
8297  res = Z3_compute_interpolant(ctx.ref(),f.as_ast(),p.params,ptr,mptr)
8298  if res == Z3_L_FALSE:
8299  return AstVector(ptr[0],ctx)
8300  if mptr[0]:
8301  raise ModelRef(mptr[0], ctx)
8302  return None
8303 
Z3_lbool Z3_API Z3_compute_interpolant(Z3_context c, Z3_ast pat, Z3_params p, Z3_ast_vector *interp, Z3_model *model)
def tree_interpolant(pat, p=None, ctx=None)
Definition: z3py.py:8239

§ TryFor()

def z3py.TryFor (   t,
  ms,
  ctx = None 
)
Return a tactic that applies `t` to a given goal for `ms` milliseconds.

If `t` does not terminate in `ms` milliseconds, then it fails.

Definition at line 7490 of file z3py.py.

7490 def TryFor(t, ms, ctx=None):
7491  """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
7492 
7493  If `t` does not terminate in `ms` milliseconds, then it fails.
7494  """
7495  t = _to_tactic(t, ctx)
7496  return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
7497 
Z3_tactic Z3_API Z3_tactic_try_for(Z3_context c, Z3_tactic t, unsigned ms)
Return a tactic that applies t to a given goal for ms milliseconds. If t does not terminate in ms mil...
def TryFor(t, ms, ctx=None)
Definition: z3py.py:7490

§ UDiv()

def z3py.UDiv (   a,
  b 
)
Create the Z3 expression (unsigned) division `self / other`.

Use the operator / for signed division.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> UDiv(x, y)
UDiv(x, y)
>>> UDiv(x, y).sort()
BitVec(32)
>>> (x / y).sexpr()
'(bvsdiv x y)'
>>> UDiv(x, y).sexpr()
'(bvudiv x y)'

Definition at line 3806 of file z3py.py.

Referenced by BitVecRef.__div__(), and BitVecRef.__rdiv__().

3806 def UDiv(a, b):
3807  """Create the Z3 expression (unsigned) division `self / other`.
3808 
3809  Use the operator / for signed division.
3810 
3811  >>> x = BitVec('x', 32)
3812  >>> y = BitVec('y', 32)
3813  >>> UDiv(x, y)
3814  UDiv(x, y)
3815  >>> UDiv(x, y).sort()
3816  BitVec(32)
3817  >>> (x / y).sexpr()
3818  '(bvsdiv x y)'
3819  >>> UDiv(x, y).sexpr()
3820  '(bvudiv x y)'
3821  """
3822  _check_bv_args(a, b)
3823  a, b = _coerce_exprs(a, b)
3824  return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3825 
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
def UDiv(a, b)
Definition: z3py.py:3806

§ UGE()

def z3py.UGE (   a,
  b 
)
Create the Z3 expression (unsigned) `other >= self`.

Use the operator >= for signed greater than or equal to.

>>> x, y = BitVecs('x y', 32)
>>> UGE(x, y)
UGE(x, y)
>>> (x >= y).sexpr()
'(bvsge x y)'
>>> UGE(x, y).sexpr()
'(bvuge x y)'

Definition at line 3772 of file z3py.py.

Referenced by BitVecRef.__ge__().

3772 def UGE(a, b):
3773  """Create the Z3 expression (unsigned) `other >= self`.
3774 
3775  Use the operator >= for signed greater than or equal to.
3776 
3777  >>> x, y = BitVecs('x y', 32)
3778  >>> UGE(x, y)
3779  UGE(x, y)
3780  >>> (x >= y).sexpr()
3781  '(bvsge x y)'
3782  >>> UGE(x, y).sexpr()
3783  '(bvuge x y)'
3784  """
3785  _check_bv_args(a, b)
3786  a, b = _coerce_exprs(a, b)
3787  return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3788 
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
def UGE(a, b)
Definition: z3py.py:3772

§ UGT()

def z3py.UGT (   a,
  b 
)
Create the Z3 expression (unsigned) `other > self`.

Use the operator > for signed greater than.

>>> x, y = BitVecs('x y', 32)
>>> UGT(x, y)
UGT(x, y)
>>> (x > y).sexpr()
'(bvsgt x y)'
>>> UGT(x, y).sexpr()
'(bvugt x y)'

Definition at line 3789 of file z3py.py.

Referenced by BitVecRef.__gt__().

3789 def UGT(a, b):
3790  """Create the Z3 expression (unsigned) `other > self`.
3791 
3792  Use the operator > for signed greater than.
3793 
3794  >>> x, y = BitVecs('x y', 32)
3795  >>> UGT(x, y)
3796  UGT(x, y)
3797  >>> (x > y).sexpr()
3798  '(bvsgt x y)'
3799  >>> UGT(x, y).sexpr()
3800  '(bvugt x y)'
3801  """
3802  _check_bv_args(a, b)
3803  a, b = _coerce_exprs(a, b)
3804  return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3805 
Z3_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.
def UGT(a, b)
Definition: z3py.py:3789

§ ULE()

def z3py.ULE (   a,
  b 
)
Create the Z3 expression (unsigned) `other <= self`.

Use the operator <= for signed less than or equal to.

>>> x, y = BitVecs('x y', 32)
>>> ULE(x, y)
ULE(x, y)
>>> (x <= y).sexpr()
'(bvsle x y)'
>>> ULE(x, y).sexpr()
'(bvule x y)'

Definition at line 3738 of file z3py.py.

Referenced by BitVecRef.__le__().

3738 def ULE(a, b):
3739  """Create the Z3 expression (unsigned) `other <= self`.
3740 
3741  Use the operator <= for signed less than or equal to.
3742 
3743  >>> x, y = BitVecs('x y', 32)
3744  >>> ULE(x, y)
3745  ULE(x, y)
3746  >>> (x <= y).sexpr()
3747  '(bvsle x y)'
3748  >>> ULE(x, y).sexpr()
3749  '(bvule x y)'
3750  """
3751  _check_bv_args(a, b)
3752  a, b = _coerce_exprs(a, b)
3753  return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3754 
Z3_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.
def ULE(a, b)
Definition: z3py.py:3738

§ ULT()

def z3py.ULT (   a,
  b 
)
Create the Z3 expression (unsigned) `other < self`.

Use the operator < for signed less than.

>>> x, y = BitVecs('x y', 32)
>>> ULT(x, y)
ULT(x, y)
>>> (x < y).sexpr()
'(bvslt x y)'
>>> ULT(x, y).sexpr()
'(bvult x y)'

Definition at line 3755 of file z3py.py.

Referenced by BitVecRef.__lt__().

3755 def ULT(a, b):
3756  """Create the Z3 expression (unsigned) `other < self`.
3757 
3758  Use the operator < for signed less than.
3759 
3760  >>> x, y = BitVecs('x y', 32)
3761  >>> ULT(x, y)
3762  ULT(x, y)
3763  >>> (x < y).sexpr()
3764  '(bvslt x y)'
3765  >>> ULT(x, y).sexpr()
3766  '(bvult x y)'
3767  """
3768  _check_bv_args(a, b)
3769  a, b = _coerce_exprs(a, b)
3770  return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3771 
def ULT(a, b)
Definition: z3py.py:3755
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.

§ Union()

def z3py.Union (   args)
Create union of regular expressions.
>>> re = Union(Re("a"), Re("b"), Re("c"))
>>> print (simplify(InRe("d", re)))
False

Definition at line 10047 of file z3py.py.

Referenced by InRe().

10047 def Union(*args):
10048  """Create union of regular expressions.
10049  >>> re = Union(Re("a"), Re("b"), Re("c"))
10050  >>> print (simplify(InRe("d", re)))
10051  False
10052  """
10053  args = _get_args(args)
10054  sz = len(args)
10055  if __debug__:
10056  _z3_assert(sz > 0, "At least one argument expected.")
10057  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
10058  if sz == 1:
10059  return args[0]
10060  ctx = args[0].ctx
10061  v = (Ast * sz)()
10062  for i in range(sz):
10063  v[i] = args[i].as_ast()
10064  return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
10065 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
def Union(args)
Definition: z3py.py:10047
def is_re(s)
Definition: z3py.py:10030
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.

§ Unit()

def z3py.Unit (   a)
Create a singleton sequence

Definition at line 9879 of file z3py.py.

Referenced by is_seq(), Re(), and SeqSort().

9879 def Unit(a):
9880  """Create a singleton sequence"""
9881  return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
9882 
def Unit(a)
Definition: z3py.py:9879
Z3_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.

§ Update()

def z3py.Update (   a,
  i,
  v 
)
Return a Z3 store array expression.

>>> a    = Array('a', IntSort(), IntSort())
>>> i, v = Ints('i v')
>>> s    = Update(a, i, v)
>>> s.sort()
Array(Int, Int)
>>> prove(s[i] == v)
proved
>>> j    = Int('j')
>>> prove(Implies(i != j, s[j] == a[j]))
proved

Definition at line 4255 of file z3py.py.

4255 def Update(a, i, v):
4256  """Return a Z3 store array expression.
4257 
4258  >>> a = Array('a', IntSort(), IntSort())
4259  >>> i, v = Ints('i v')
4260  >>> s = Update(a, i, v)
4261  >>> s.sort()
4262  Array(Int, Int)
4263  >>> prove(s[i] == v)
4264  proved
4265  >>> j = Int('j')
4266  >>> prove(Implies(i != j, s[j] == a[j]))
4267  proved
4268  """
4269  if __debug__:
4270  _z3_assert(is_array(a), "First argument must be a Z3 array expression")
4271  i = a.domain().cast(i)
4272  v = a.range().cast(v)
4273  ctx = a.ctx
4274  return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4275 
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
def is_array(a)
Definition: z3py.py:4144
def Update(a, i, v)
Definition: z3py.py:4255

§ URem()

def z3py.URem (   a,
  b 
)
Create the Z3 expression (unsigned) remainder `self % other`.

Use the operator % for signed modulus, and SRem() for signed remainder.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> URem(x, y)
URem(x, y)
>>> URem(x, y).sort()
BitVec(32)
>>> (x % y).sexpr()
'(bvsmod x y)'
>>> URem(x, y).sexpr()
'(bvurem x y)'

Definition at line 3826 of file z3py.py.

Referenced by BitVecRef.__mod__(), BitVecRef.__rmod__(), and SRem().

3826 def URem(a, b):
3827  """Create the Z3 expression (unsigned) remainder `self % other`.
3828 
3829  Use the operator % for signed modulus, and SRem() for signed remainder.
3830 
3831  >>> x = BitVec('x', 32)
3832  >>> y = BitVec('y', 32)
3833  >>> URem(x, y)
3834  URem(x, y)
3835  >>> URem(x, y).sort()
3836  BitVec(32)
3837  >>> (x % y).sexpr()
3838  '(bvsmod x y)'
3839  >>> URem(x, y).sexpr()
3840  '(bvurem x y)'
3841  """
3842  _check_bv_args(a, b)
3843  a, b = _coerce_exprs(a, b)
3844  return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3845 
def URem(a, b)
Definition: z3py.py:3826
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.

§ Var()

def z3py.Var (   idx,
  s 
)
Create a Z3 free variable. Free variables are used to create quantified formulas.

>>> Var(0, IntSort())
Var(0)
>>> eq(Var(0, IntSort()), Var(0, BoolSort()))
False

Definition at line 1258 of file z3py.py.

Referenced by QuantifierRef.body(), QuantifierRef.children(), is_pattern(), MultiPattern(), QuantifierRef.pattern(), and RealVar().

1258 def Var(idx, s):
1259  """Create a Z3 free variable. Free variables are used to create quantified formulas.
1260 
1261  >>> Var(0, IntSort())
1262  Var(0)
1263  >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1264  False
1265  """
1266  if __debug__:
1267  _z3_assert(is_sort(s), "Z3 sort expected")
1268  return _to_expr_ref(Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1269 
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a bound variable.
def Var(idx, s)
Definition: z3py.py:1258
def is_sort(s)
Definition: z3py.py:575

§ When()

def z3py.When (   p,
  t,
  ctx = None 
)
Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.

>>> t = When(Probe('size') > 2, Tactic('simplify'))
>>> x, y = Ints('x y')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(y > 0)
>>> t(g)
[[x > 0, y > 0]]
>>> g.add(x == y + 1)
>>> t(g)
[[Not(x <= 0), Not(y <= 0), x == 1 + y]]

Definition at line 7759 of file z3py.py.

7759 def When(p, t, ctx=None):
7760  """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
7761 
7762  >>> t = When(Probe('size') > 2, Tactic('simplify'))
7763  >>> x, y = Ints('x y')
7764  >>> g = Goal()
7765  >>> g.add(x > 0)
7766  >>> g.add(y > 0)
7767  >>> t(g)
7768  [[x > 0, y > 0]]
7769  >>> g.add(x == y + 1)
7770  >>> t(g)
7771  [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
7772  """
7773  p = _to_probe(p, ctx)
7774  t = _to_tactic(t, ctx)
7775  return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
7776 
Z3_tactic Z3_API Z3_tactic_when(Z3_context c, Z3_probe p, Z3_tactic t)
Return a tactic that applies t to a given goal is the probe p evaluates to true. If p evaluates to fa...
def When(p, t, ctx=None)
Definition: z3py.py:7759

§ With()

def z3py.With (   t,
  args,
  keys 
)
Return a tactic that applies tactic `t` using the given configuration options.

>>> x, y = Ints('x y')
>>> t = With(Tactic('simplify'), som=True)
>>> t((x + 1)*(y + 2) == 0)
[[2*x + y + x*y == -2]]

Definition at line 7445 of file z3py.py.

Referenced by Goal.prec().

7445 def With(t, *args, **keys):
7446  """Return a tactic that applies tactic `t` using the given configuration options.
7447 
7448  >>> x, y = Ints('x y')
7449  >>> t = With(Tactic('simplify'), som=True)
7450  >>> t((x + 1)*(y + 2) == 0)
7451  [[2*x + y + x*y == -2]]
7452  """
7453  ctx = keys.pop('ctx', None)
7454  t = _to_tactic(t, ctx)
7455  p = args2params(args, keys, t.ctx)
7456  return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
7457 
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:4766
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p)
Return a tactic that applies t using the given set of parameters.
def With(t, args, keys)
Definition: z3py.py:7445

§ WithParams()

def z3py.WithParams (   t,
  p 
)
Return a tactic that applies tactic `t` using the given configuration options.

>>> x, y = Ints('x y')
>>> p = ParamsRef()
>>> p.set("som", True)
>>> t = WithParams(Tactic('simplify'), p)
>>> t((x + 1)*(y + 2) == 0)
[[2*x + y + x*y == -2]]

Definition at line 7458 of file z3py.py.

7458 def WithParams(t, p):
7459  """Return a tactic that applies tactic `t` using the given configuration options.
7460 
7461  >>> x, y = Ints('x y')
7462  >>> p = ParamsRef()
7463  >>> p.set("som", True)
7464  >>> t = WithParams(Tactic('simplify'), p)
7465  >>> t((x + 1)*(y + 2) == 0)
7466  [[2*x + y + x*y == -2]]
7467  """
7468  t = _to_tactic(t, None)
7469  return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
7470 
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p)
Return a tactic that applies t using the given set of parameters.
def WithParams(t, p)
Definition: z3py.py:7458

§ Xor()

def z3py.Xor (   a,
  b,
  ctx = None 
)
Create a Z3 Xor expression.

>>> p, q = Bools('p q')
>>> Xor(p, q)
Xor(p, q)
>>> simplify(Xor(p, q))
Not(p) == q

Definition at line 1552 of file z3py.py.

1552 def Xor(a, b, ctx=None):
1553  """Create a Z3 Xor expression.
1554 
1555  >>> p, q = Bools('p q')
1556  >>> Xor(p, q)
1557  Xor(p, q)
1558  >>> simplify(Xor(p, q))
1559  Not(p) == q
1560  """
1561  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1562  s = BoolSort(ctx)
1563  a = s.cast(a)
1564  b = s.cast(b)
1565  return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1566 
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.
def Xor(a, b, ctx=None)
Definition: z3py.py:1552
def BoolSort(ctx=None)
Definition: z3py.py:1449

§ z3_error_handler()

def z3py.z3_error_handler (   c,
  e 
)

Definition at line 148 of file z3py.py.

148 def z3_error_handler(c, e):
149  # Do nothing error handler, just avoid exit(0)
150  # The wrappers in z3core.py will raise a Z3Exception if an error is detected
151  return
152 
def z3_error_handler(c, e)
Definition: z3py.py:148

§ ZeroExt()

def z3py.ZeroExt (   n,
  a 
)
Return a bit-vector expression with `n` extra zero-bits.

>>> x = BitVec('x', 16)
>>> n = ZeroExt(8, x)
>>> n.size()
24
>>> n
ZeroExt(8, x)
>>> n.sort()
BitVec(24)
>>> v0 = BitVecVal(2, 2)
>>> v0
2
>>> v0.size()
2
>>> v  = simplify(ZeroExt(6, v0))
>>> v
2
>>> v.size()
8

Definition at line 3956 of file z3py.py.

3956 def ZeroExt(n, a):
3957  """Return a bit-vector expression with `n` extra zero-bits.
3958 
3959  >>> x = BitVec('x', 16)
3960  >>> n = ZeroExt(8, x)
3961  >>> n.size()
3962  24
3963  >>> n
3964  ZeroExt(8, x)
3965  >>> n.sort()
3966  BitVec(24)
3967  >>> v0 = BitVecVal(2, 2)
3968  >>> v0
3969  2
3970  >>> v0.size()
3971  2
3972  >>> v = simplify(ZeroExt(6, v0))
3973  >>> v
3974  2
3975  >>> v.size()
3976  8
3977  """
3978  if __debug__:
3979  _z3_assert(_is_int(n), "First argument must be an integer")
3980  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
3981  return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
3982 
def ZeroExt(n, a)
Definition: z3py.py:3956
def is_bv(a)
Definition: z3py.py:3536
Z3_ast Z3_API Z3_mk_zero_ext(Z3_context c, unsigned i, Z3_ast t1)
Extend the given bit-vector with zeros to the (unsigned) equivalent bit-vector of size m+i...

Variable Documentation

§ sat

Definition at line 6088 of file z3py.py.

§ unknown

Definition at line 6090 of file z3py.py.

§ unsat

Definition at line 6089 of file z3py.py.