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 RecFunction (name, sig)
 
def RecAddDefinition (f, args, body)
 
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 FreshConst (sort, prefix='c')
 
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_implies (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 Lambda (vs, body)
 
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 (sig)
 
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 SetSort (s)
 Sets. More...
 
def EmptySet (s)
 
def FullSet (s)
 
def SetUnion (args)
 
def SetIntersect (args)
 
def SetAdd (s, e)
 
def SetDel (s, e)
 
def SetComplement (s)
 
def SetDifference (a, b)
 
def IsMember (e, s)
 
def IsSubset (a, b)
 
def CreateDatatypes (ds)
 
def EnumSort (name, values, ctx=None)
 
def args2params (arguments, keywords, ctx=None)
 
def Model (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 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 1655 of file z3py.py.

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

1655 def And(*args):
1656  """Create a Z3 and-expression or and-probe.
1657 
1658  >>> p, q, r = Bools('p q r')
1659  >>> And(p, q, r)
1660  And(p, q, r)
1661  >>> P = BoolVector('p', 5)
1662  >>> And(P)
1663  And(p__0, p__1, p__2, p__3, p__4)
1664  """
1665  last_arg = None
1666  if len(args) > 0:
1667  last_arg = args[len(args)-1]
1668  if isinstance(last_arg, Context):
1669  ctx = args[len(args)-1]
1670  args = args[:len(args)-1]
1671  elif len(args) == 1 and isinstance(args[0], AstVector):
1672  ctx = args[0].ctx
1673  args = [a for a in args[0]]
1674  else:
1675  ctx = main_ctx()
1676  args = _get_args(args)
1677  ctx_args = _ctx_from_ast_arg_list(args, ctx)
1678  if __debug__:
1679  _z3_assert(ctx_args is None or ctx_args == ctx, "context mismatch")
1680  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1681  if _has_probe(args):
1682  return _probe_and(args, ctx)
1683  else:
1684  args = _coerce_expr_list(args, ctx)
1685  _args, sz = _to_ast_array(args)
1686  return BoolRef(Z3_mk_and(ctx.ref(), sz, _args), ctx)
1687 
def And(args)
Definition: z3py.py:1655
def main_ctx()
Definition: z3py.py:207
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 7645 of file z3py.py.

Referenced by Then().

7645 def AndThen(*ts, **ks):
7646  """Return a tactic that applies the tactics in `*ts` in sequence.
7647 
7648  >>> x, y = Ints('x y')
7649  >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
7650  >>> t(And(x == 0, y > x + 1))
7651  [[Not(y <= 1)]]
7652  >>> t(And(x == 0, y > x + 1)).as_expr()
7653  Not(y <= 1)
7654  """
7655  if __debug__:
7656  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7657  ctx = ks.get('ctx', None)
7658  num = len(ts)
7659  r = ts[0]
7660  for i in range(num - 1):
7661  r = _and_then(r, ts[i+1], ctx)
7662  return r
7663 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def AndThen(ts, ks)
Definition: z3py.py:7645

◆ append_log()

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

Definition at line 101 of file z3py.py.

101 def append_log(s):
102  """Append user-defined string to interaction log. """
103  Z3_append_log(s)
104 
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.
def append_log(s)
Definition: z3py.py:101

◆ 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 5001 of file z3py.py.

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

5001 def args2params(arguments, keywords, ctx=None):
5002  """Convert python arguments into a Z3_params object.
5003  A ':' is added to the keywords, and '_' is replaced with '-'
5004 
5005  >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5006  (params model true relevancy 2 elim_and true)
5007  """
5008  if __debug__:
5009  _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
5010  prev = None
5011  r = ParamsRef(ctx)
5012  for a in arguments:
5013  if prev is None:
5014  prev = a
5015  else:
5016  r.set(prev, a)
5017  prev = None
5018  for k in keywords:
5019  v = keywords[k]
5020  r.set(k, v)
5021  return r
5022 
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:5001

◆ 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 4366 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(), Lambda(), Map(), ArrayRef.range(), Select(), ArrayRef.sort(), Store(), and Update().

4366 def Array(name, dom, rng):
4367  """Return an array constant named `name` with the given domain and range sorts.
4368 
4369  >>> a = Array('a', IntSort(), IntSort())
4370  >>> a.sort()
4371  Array(Int, Int)
4372  >>> a[0]
4373  a[0]
4374  """
4375  s = ArraySort(dom, rng)
4376  ctx = s.ctx
4377  return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4378 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def ArraySort(sig)
Definition: z3py.py:4334
def to_symbol(s, ctx=None)
Definition: z3py.py:105
def Array(name, dom, rng)
Definition: z3py.py:4366

◆ ArraySort()

def z3py.ArraySort (   sig)
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 4334 of file z3py.py.

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

4334 def ArraySort(*sig):
4335  """Return the Z3 array sort with the given domain and range sorts.
4336 
4337  >>> A = ArraySort(IntSort(), BoolSort())
4338  >>> A
4339  Array(Int, Bool)
4340  >>> A.domain()
4341  Int
4342  >>> A.range()
4343  Bool
4344  >>> AA = ArraySort(IntSort(), A)
4345  >>> AA
4346  Array(Int, Array(Int, Bool))
4347  """
4348  sig = _get_args(sig)
4349  if __debug__:
4350  _z3_assert(len(sig) > 1, "At least two arguments expected")
4351  arity = len(sig) - 1
4352  r = sig[arity]
4353  d = sig[0]
4354  if __debug__:
4355  for s in sig:
4356  _z3_assert(is_sort(s), "Z3 sort expected")
4357  _z3_assert(s.ctx == r.ctx, "Context mismatch")
4358  ctx = d.ctx
4359  if len(sig) == 2:
4360  return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4361  dom = (Sort * arity)()
4362  for i in range(arity):
4363  dom[i] = sig[i].ast
4364  return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
4365 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def ArraySort(sig)
Definition: z3py.py:4334
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
def is_sort(s)
Definition: z3py.py:579

◆ 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 8226 of file z3py.py.

8226 def AtLeast(*args):
8227  """Create an at-most Pseudo-Boolean k constraint.
8228 
8229  >>> a, b, c = Bools('a b c')
8230  >>> f = AtLeast(a, b, c, 2)
8231  """
8232  args = _get_args(args)
8233  if __debug__:
8234  _z3_assert(len(args) > 1, "Non empty list of arguments expected")
8235  ctx = _ctx_from_ast_arg_list(args)
8236  if __debug__:
8237  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
8238  args1 = _coerce_expr_list(args[:-1], ctx)
8239  k = args[-1]
8240  _args, sz = _to_ast_array(args1)
8241  return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
8242 
8243 
def AtLeast(args)
Definition: z3py.py:8226
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 8209 of file z3py.py.

8209 def AtMost(*args):
8210  """Create an at-most Pseudo-Boolean k constraint.
8211 
8212  >>> a, b, c = Bools('a b c')
8213  >>> f = AtMost(a, b, c, 2)
8214  """
8215  args = _get_args(args)
8216  if __debug__:
8217  _z3_assert(len(args) > 1, "Non empty list of arguments expected")
8218  ctx = _ctx_from_ast_arg_list(args)
8219  if __debug__:
8220  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
8221  args1 = _coerce_expr_list(args[:-1], ctx)
8222  k = args[-1]
8223  _args, sz = _to_ast_array(args1)
8224  return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
8225 
def AtMost(args)
Definition: z3py.py:8209
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.

◆ 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 3736 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().

3736 def BitVec(name, bv, ctx=None):
3737  """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
3738  If `ctx=None`, then the global context is used.
3739 
3740  >>> x = BitVec('x', 16)
3741  >>> is_bv(x)
3742  True
3743  >>> x.size()
3744  16
3745  >>> x.sort()
3746  BitVec(16)
3747  >>> word = BitVecSort(16)
3748  >>> x2 = BitVec('x', word)
3749  >>> eq(x, x2)
3750  True
3751  """
3752  if isinstance(bv, BitVecSortRef):
3753  ctx = bv.ctx
3754  else:
3755  ctx = _get_ctx(ctx)
3756  bv = BitVecSort(bv, ctx)
3757  return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
3758 
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:105
def BitVec(name, bv, ctx=None)
Definition: z3py.py:3736
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3706

◆ 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 3759 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().

3759 def BitVecs(names, bv, ctx=None):
3760  """Return a tuple of bit-vector constants of size bv.
3761 
3762  >>> x, y, z = BitVecs('x y z', 16)
3763  >>> x.size()
3764  16
3765  >>> x.sort()
3766  BitVec(16)
3767  >>> Sum(x, y, z)
3768  0 + x + y + z
3769  >>> Product(x, y, z)
3770  1*x*y*z
3771  >>> simplify(Product(x, y, z))
3772  x*y*z
3773  """
3774  ctx = _get_ctx(ctx)
3775  if isinstance(names, str):
3776  names = names.split(" ")
3777  return [BitVec(name, bv, ctx) for name in names]
3778 
def BitVec(name, bv, ctx=None)
Definition: z3py.py:3736
def BitVecs(names, bv, ctx=None)
Definition: z3py.py:3759

◆ 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 3706 of file z3py.py.

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

3706 def BitVecSort(sz, ctx=None):
3707  """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3708 
3709  >>> Byte = BitVecSort(8)
3710  >>> Word = BitVecSort(16)
3711  >>> Byte
3712  BitVec(8)
3713  >>> x = Const('x', Byte)
3714  >>> eq(x, BitVec('x', 8))
3715  True
3716  """
3717  ctx = _get_ctx(ctx)
3718  return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
3719 
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:3706

◆ 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 3720 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().

3720 def BitVecVal(val, bv, ctx=None):
3721  """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3722 
3723  >>> v = BitVecVal(10, 32)
3724  >>> v
3725  10
3726  >>> print("0x%.8x" % v.as_long())
3727  0x0000000a
3728  """
3729  if is_bv_sort(bv):
3730  ctx = bv.ctx
3731  return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
3732  else:
3733  ctx = _get_ctx(ctx)
3734  return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
3735 
def BitVecVal(val, bv, ctx=None)
Definition: z3py.py:3720
def is_bv_sort(s)
Definition: z3py.py:3188
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3706
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 1547 of file z3py.py.

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

1547 def Bool(name, ctx=None):
1548  """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1549 
1550  >>> p = Bool('p')
1551  >>> q = Bool('q')
1552  >>> And(p, q)
1553  And(p, q)
1554  """
1555  ctx = _get_ctx(ctx)
1556  return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
1557 
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:105
def Bool(name, ctx=None)
Definition: z3py.py:1547
def BoolSort(ctx=None)
Definition: z3py.py:1512

◆ 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 1558 of file z3py.py.

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

1558 def Bools(names, ctx=None):
1559  """Return a tuple of Boolean constants.
1560 
1561  `names` is a single string containing all names separated by blank spaces.
1562  If `ctx=None`, then the global context is used.
1563 
1564  >>> p, q, r = Bools('p q r')
1565  >>> And(p, Or(q, r))
1566  And(p, Or(q, r))
1567  """
1568  ctx = _get_ctx(ctx)
1569  if isinstance(names, str):
1570  names = names.split(" ")
1571  return [Bool(name, ctx) for name in names]
1572 
def Bools(names, ctx=None)
Definition: z3py.py:1558
def Bool(name, ctx=None)
Definition: z3py.py:1547

◆ 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 1512 of file z3py.py.

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

1512 def BoolSort(ctx=None):
1513  """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1514 
1515  >>> BoolSort()
1516  Bool
1517  >>> p = Const('p', BoolSort())
1518  >>> is_bool(p)
1519  True
1520  >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1521  >>> r(0, 1)
1522  r(0, 1)
1523  >>> is_bool(r(0, 1))
1524  True
1525  """
1526  ctx = _get_ctx(ctx)
1527  return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
1528 
def is_bool(a)
Definition: z3py.py:1401
def BoolSort(ctx=None)
Definition: z3py.py:1512

◆ 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 1529 of file z3py.py.

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

1529 def BoolVal(val, ctx=None):
1530  """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1531 
1532  >>> BoolVal(True)
1533  True
1534  >>> is_true(BoolVal(True))
1535  True
1536  >>> is_true(True)
1537  False
1538  >>> is_false(BoolVal(False))
1539  True
1540  """
1541  ctx = _get_ctx(ctx)
1542  if val == False:
1543  return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1544  else:
1545  return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1546 
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:1529

◆ 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 1573 of file z3py.py.

Referenced by And(), and Or().

1573 def BoolVector(prefix, sz, ctx=None):
1574  """Return a list of Boolean constants of size `sz`.
1575 
1576  The constants are named using the given prefix.
1577  If `ctx=None`, then the global context is used.
1578 
1579  >>> P = BoolVector('p', 3)
1580  >>> P
1581  [p__0, p__1, p__2]
1582  >>> And(P)
1583  And(p__0, p__1, p__2)
1584  """
1585  return [ Bool('%s__%s' % (prefix, i)) for i in range(sz) ]
1586 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def BoolVector(prefix, sz, ctx=None)
Definition: z3py.py:1573
def Bool(name, ctx=None)
Definition: z3py.py:1547

◆ 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 3676 of file z3py.py.

3676 def BV2Int(a, is_signed=False):
3677  """Return the Z3 expression BV2Int(a).
3678 
3679  >>> b = BitVec('b', 3)
3680  >>> BV2Int(b).sort()
3681  Int
3682  >>> x = Int('x')
3683  >>> x > BV2Int(b)
3684  x > BV2Int(b)
3685  >>> x > BV2Int(b, is_signed=False)
3686  x > BV2Int(b)
3687  >>> x > BV2Int(b, is_signed=True)
3688  x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3689  >>> solve(x > BV2Int(b), b == 1, x < 3)
3690  [b = 1, x = 2]
3691  """
3692  if __debug__:
3693  _z3_assert(is_bv(a), "Z3 bit-vector expression expected")
3694  ctx = a.ctx
3695 
3696  return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
3697 
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:3676
def is_bv(a)
Definition: z3py.py:3649

◆ BVAddNoOverflow()

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

Definition at line 4131 of file z3py.py.

4131 def BVAddNoOverflow(a, b, signed):
4132  """A predicate the determines that bit-vector addition does not overflow"""
4133  _check_bv_args(a, b)
4134  a, b = _coerce_exprs(a, b)
4135  return BoolRef(Z3_mk_bvadd_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4136 
def BVAddNoOverflow(a, b, signed)
Definition: z3py.py:4131
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 4137 of file z3py.py.

4137 def BVAddNoUnderflow(a, b):
4138  """A predicate the determines that signed bit-vector addition does not underflow"""
4139  _check_bv_args(a, b)
4140  a, b = _coerce_exprs(a, b)
4141  return BoolRef(Z3_mk_bvadd_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4142 
def BVAddNoUnderflow(a, b)
Definition: z3py.py:4137
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 4168 of file z3py.py.

4168 def BVMulNoOverflow(a, b, signed):
4169  """A predicate the determines that bit-vector multiplication does not overflow"""
4170  _check_bv_args(a, b)
4171  a, b = _coerce_exprs(a, b)
4172  return BoolRef(Z3_mk_bvmul_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4173 
4174 
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:4168

◆ BVMulNoUnderflow()

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

Definition at line 4175 of file z3py.py.

4175 def BVMulNoUnderflow(a, b):
4176  """A predicate the determines that bit-vector signed multiplication does not underflow"""
4177  _check_bv_args(a, b)
4178  a, b = _coerce_exprs(a, b)
4179  return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4180 
4181 
4182 
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:4175

◆ BVRedAnd()

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

Definition at line 4119 of file z3py.py.

4119 def BVRedAnd(a):
4120  """Return the reduction-and expression of `a`."""
4121  if __debug__:
4122  _z3_assert(is_bv(a), "First argument must be a Z3 Bitvector expression")
4123  return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
4124 
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:4119
def is_bv(a)
Definition: z3py.py:3649

◆ BVRedOr()

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

Definition at line 4125 of file z3py.py.

4125 def BVRedOr(a):
4126  """Return the reduction-or expression of `a`."""
4127  if __debug__:
4128  _z3_assert(is_bv(a), "First argument must be a Z3 Bitvector expression")
4129  return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
4130 
def BVRedOr(a)
Definition: z3py.py:4125
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:3649

◆ BVSDivNoOverflow()

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

Definition at line 4156 of file z3py.py.

4156 def BVSDivNoOverflow(a, b):
4157  """A predicate the determines that bit-vector signed division does not overflow"""
4158  _check_bv_args(a, b)
4159  a, b = _coerce_exprs(a, b)
4160  return BoolRef(Z3_mk_bvsdiv_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4161 
def BVSDivNoOverflow(a, b)
Definition: z3py.py:4156
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 4162 of file z3py.py.

4162 def BVSNegNoOverflow(a):
4163  """A predicate the determines that bit-vector unary negation does not overflow"""
4164  if __debug__:
4165  _z3_assert(is_bv(a), "Argument should be a bit-vector")
4166  return BoolRef(Z3_mk_bvneg_no_overflow(a.ctx_ref(), a.as_ast()), a.ctx)
4167 
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:4162
def is_bv(a)
Definition: z3py.py:3649

◆ BVSubNoOverflow()

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

Definition at line 4143 of file z3py.py.

4143 def BVSubNoOverflow(a, b):
4144  """A predicate the determines that bit-vector subtraction does not overflow"""
4145  _check_bv_args(a, b)
4146  a, b = _coerce_exprs(a, b)
4147  return BoolRef(Z3_mk_bvsub_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4148 
4149 
def BVSubNoOverflow(a, b)
Definition: z3py.py:4143
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 4150 of file z3py.py.

4150 def BVSubNoUnderflow(a, b, signed):
4151  """A predicate the determines that bit-vector subtraction does not underflow"""
4152  _check_bv_args(a, b)
4153  a, b = _coerce_exprs(a, b)
4154  return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4155 
def BVSubNoUnderflow(a, b, signed)
Definition: z3py.py:4150
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 3138 of file z3py.py.

3138 def Cbrt(a, ctx=None):
3139  """ Return a Z3 expression which represents the cubic root of a.
3140 
3141  >>> x = Real('x')
3142  >>> Cbrt(x)
3143  x**(1/3)
3144  """
3145  if not is_expr(a):
3146  ctx = _get_ctx(ctx)
3147  a = RealVal(a, ctx)
3148  return a ** "1/3"
3149 
def Cbrt(a, ctx=None)
Definition: z3py.py:3138
def RealVal(val, ctx=None)
Definition: z3py.py:2931
def is_expr(a)
Definition: z3py.py:1094

◆ Complement()

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

Definition at line 10233 of file z3py.py.

10233 def Complement(re):
10234  """Create the complement regular expression."""
10235  return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
10236 
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:10233

◆ 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 3779 of file z3py.py.

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

3779 def Concat(*args):
3780  """Create a Z3 bit-vector concatenation expression.
3781 
3782  >>> v = BitVecVal(1, 4)
3783  >>> Concat(v, v+1, v)
3784  Concat(Concat(1, 1 + 1), 1)
3785  >>> simplify(Concat(v, v+1, v))
3786  289
3787  >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
3788  121
3789  """
3790  args = _get_args(args)
3791  sz = len(args)
3792  if __debug__:
3793  _z3_assert(sz >= 2, "At least two arguments expected.")
3794 
3795  ctx = None
3796  for a in args:
3797  if is_expr(a):
3798  ctx = a.ctx
3799  break
3800  if is_seq(args[0]) or isinstance(args[0], str):
3801  args = [_coerce_seq(s, ctx) for s in args]
3802  if __debug__:
3803  _z3_assert(all([is_seq(a) for a in args]), "All arguments must be sequence expressions.")
3804  v = (Ast * sz)()
3805  for i in range(sz):
3806  v[i] = args[i].as_ast()
3807  return SeqRef(Z3_mk_seq_concat(ctx.ref(), sz, v), ctx)
3808 
3809  if is_re(args[0]):
3810  if __debug__:
3811  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
3812  v = (Ast * sz)()
3813  for i in range(sz):
3814  v[i] = args[i].as_ast()
3815  return ReRef(Z3_mk_re_concat(ctx.ref(), sz, v), ctx)
3816 
3817  if __debug__:
3818  _z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.")
3819  r = args[0]
3820  for i in range(sz - 1):
3821  r = BitVecRef(Z3_mk_concat(ctx.ref(), r.as_ast(), args[i+1].as_ast()), ctx)
3822  return r
3823 
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:3244
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:10173
def is_expr(a)
Definition: z3py.py:1094
def is_bv(a)
Definition: z3py.py:3649
def Concat(args)
Definition: z3py.py:3779
def is_seq(a)
Definition: z3py.py:9933

◆ 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 8064 of file z3py.py.

Referenced by If().

8064 def Cond(p, t1, t2, ctx=None):
8065  """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8066 
8067  >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8068  """
8069  p = _to_probe(p, ctx)
8070  t1 = _to_tactic(t1, ctx)
8071  t2 = _to_tactic(t2, ctx)
8072  return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
8073 
def Cond(p, t1, t2, ctx=None)
Definition: z3py.py:8064
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 1280 of file z3py.py.

Referenced by BitVecSort(), Consts(), FPSort(), IntSort(), IsMember(), IsSubset(), RealSort(), DatatypeSortRef.recognizer(), SetAdd(), SetComplement(), SetDel(), SetDifference(), SetIntersect(), and SetUnion().

1280 def Const(name, sort):
1281  """Create a constant of the given sort.
1282 
1283  >>> Const('x', IntSort())
1284  x
1285  """
1286  if __debug__:
1287  _z3_assert(isinstance(sort, SortRef), "Z3 sort expected")
1288  ctx = sort.ctx
1289  return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
1290 
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:105
def Const(name, sort)
Definition: z3py.py:1280

◆ 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 1291 of file z3py.py.

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

1291 def Consts(names, sort):
1292  """Create a several constants of the given sort.
1293 
1294  `names` is a string containing the names of all constants to be created.
1295  Blank spaces separate the names of different constants.
1296 
1297  >>> x, y, z = Consts('x y z', IntSort())
1298  >>> x + y + z
1299  x + y + z
1300  """
1301  if isinstance(names, str):
1302  names = names.split(" ")
1303  return [Const(name, sort) for name in names]
1304 
def Consts(names, sort)
Definition: z3py.py:1291
def Const(name, sort)
Definition: z3py.py:1280

◆ 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 10054 of file z3py.py.

10054 def Contains(a, b):
10055  """Check if 'a' contains 'b'
10056  >>> s1 = Contains("abc", "ab")
10057  >>> simplify(s1)
10058  True
10059  >>> s2 = Contains("abc", "bc")
10060  >>> simplify(s2)
10061  True
10062  >>> x, y, z = Strings('x y z')
10063  >>> s3 = Contains(Concat(x,y,z), y)
10064  >>> simplify(s3)
10065  True
10066  """
10067  ctx = _get_ctx2(a, b)
10068  a = _coerce_seq(a, ctx)
10069  b = _coerce_seq(b, ctx)
10070  return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
10071 
10072 
def Contains(a, b)
Definition: z3py.py:10054
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 4736 of file z3py.py.

Referenced by Datatype.create().

4736 def CreateDatatypes(*ds):
4737  """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
4738 
4739  In the following example we define a Tree-List using two mutually recursive datatypes.
4740 
4741  >>> TreeList = Datatype('TreeList')
4742  >>> Tree = Datatype('Tree')
4743  >>> # Tree has two constructors: leaf and node
4744  >>> Tree.declare('leaf', ('val', IntSort()))
4745  >>> # a node contains a list of trees
4746  >>> Tree.declare('node', ('children', TreeList))
4747  >>> TreeList.declare('nil')
4748  >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
4749  >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
4750  >>> Tree.val(Tree.leaf(10))
4751  val(leaf(10))
4752  >>> simplify(Tree.val(Tree.leaf(10)))
4753  10
4754  >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
4755  >>> n1
4756  node(cons(leaf(10), cons(leaf(20), nil)))
4757  >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
4758  >>> simplify(n2 == n1)
4759  False
4760  >>> simplify(TreeList.car(Tree.children(n2)) == n1)
4761  True
4762  """
4763  ds = _get_args(ds)
4764  if __debug__:
4765  _z3_assert(len(ds) > 0, "At least one Datatype must be specified")
4766  _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
4767  _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
4768  _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
4769  ctx = ds[0].ctx
4770  num = len(ds)
4771  names = (Symbol * num)()
4772  out = (Sort * num)()
4773  clists = (ConstructorList * num)()
4774  to_delete = []
4775  for i in range(num):
4776  d = ds[i]
4777  names[i] = to_symbol(d.name, ctx)
4778  num_cs = len(d.constructors)
4779  cs = (Constructor * num_cs)()
4780  for j in range(num_cs):
4781  c = d.constructors[j]
4782  cname = to_symbol(c[0], ctx)
4783  rname = to_symbol(c[1], ctx)
4784  fs = c[2]
4785  num_fs = len(fs)
4786  fnames = (Symbol * num_fs)()
4787  sorts = (Sort * num_fs)()
4788  refs = (ctypes.c_uint * num_fs)()
4789  for k in range(num_fs):
4790  fname = fs[k][0]
4791  ftype = fs[k][1]
4792  fnames[k] = to_symbol(fname, ctx)
4793  if isinstance(ftype, Datatype):
4794  if __debug__:
4795  _z3_assert(ds.count(ftype) == 1, "One and only one occurrence of each datatype is expected")
4796  sorts[k] = None
4797  refs[k] = ds.index(ftype)
4798  else:
4799  if __debug__:
4800  _z3_assert(is_sort(ftype), "Z3 sort expected")
4801  sorts[k] = ftype.ast
4802  refs[k] = 0
4803  cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
4804  to_delete.append(ScopedConstructor(cs[j], ctx))
4805  clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs)
4806  to_delete.append(ScopedConstructorList(clists[i], ctx))
4807  Z3_mk_datatypes(ctx.ref(), num, names, out, clists)
4808  result = []
4809 
4810  for i in range(num):
4811  dref = DatatypeSortRef(out[i], ctx)
4812  num_cs = dref.num_constructors()
4813  for j in range(num_cs):
4814  cref = dref.constructor(j)
4815  cref_name = cref.name()
4816  cref_arity = cref.arity()
4817  if cref.arity() == 0:
4818  cref = cref()
4819  setattr(dref, cref_name, cref)
4820  rref = dref.recognizer(j)
4821  setattr(dref, "is_" + cref_name, rref)
4822  for k in range(cref_arity):
4823  aref = dref.accessor(j, k)
4824  setattr(dref, aref.name(), aref)
4825  result.append(dref)
4826  return tuple(result)
4827 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def to_symbol(s, ctx=None)
Definition: z3py.py:105
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:4736
def is_sort(s)
Definition: z3py.py:579
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 616 of file z3py.py.

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

616 def DeclareSort(name, ctx=None):
617  """Create a new uninterpreted sort named `name`.
618 
619  If `ctx=None`, then the new sort is declared in the global Z3Py context.
620 
621  >>> A = DeclareSort('A')
622  >>> a = Const('a', A)
623  >>> b = Const('b', A)
624  >>> a.sort() == A
625  True
626  >>> b.sort() == A
627  True
628  >>> a == b
629  a == b
630  """
631  ctx = _get_ctx(ctx)
632  return SortRef(Z3_mk_uninterpreted_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
633 
def to_symbol(s, ctx=None)
Definition: z3py.py:105
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:616

◆ Default()

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

Definition at line 4400 of file z3py.py.

Referenced by is_default().

4400 def Default(a):
4401  """ Return a default value for array expression.
4402  >>> b = K(IntSort(), 1)
4403  >>> prove(Default(b) == 1)
4404  proved
4405  """
4406  if __debug__:
4407  _z3_assert(is_array(a), "First argument must be a Z3 array expression")
4408  return a.default()
4409 
4410 
def is_array(a)
Definition: z3py.py:4257
def Default(a)
Definition: z3py.py:4400

◆ describe_probes()

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

Definition at line 7994 of file z3py.py.

7994 def describe_probes():
7995  """Display a (tabular) description of all available probes in Z3."""
7996  if in_html_mode():
7997  even = True
7998  print('<table border="1" cellpadding="2" cellspacing="0">')
7999  for p in probes():
8000  if even:
8001  print('<tr style="background-color:#CFCFCF">')
8002  even = False
8003  else:
8004  print('<tr>')
8005  even = True
8006  print('<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(probe_description(p), 40)))
8007  print('</table>')
8008  else:
8009  for p in probes():
8010  print('%s : %s' % (p, probe_description(p)))
8011 
def probes(ctx=None)
Definition: z3py.py:7976
def probe_description(name, ctx=None)
Definition: z3py.py:7986
def describe_probes()
Definition: z3py.py:7994

◆ describe_tactics()

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

Definition at line 7803 of file z3py.py.

7803 def describe_tactics():
7804  """Display a (tabular) description of all available tactics in Z3."""
7805  if in_html_mode():
7806  even = True
7807  print('<table border="1" cellpadding="2" cellspacing="0">')
7808  for t in tactics():
7809  if even:
7810  print('<tr style="background-color:#CFCFCF">')
7811  even = False
7812  else:
7813  print('<tr>')
7814  even = True
7815  print('<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(tactic_description(t), 40)))
7816  print('</table>')
7817  else:
7818  for t in tactics():
7819  print('%s : %s' % (t, tactic_description(t)))
7820 
def tactics(ctx=None)
Definition: z3py.py:7785
def tactic_description(name, ctx=None)
Definition: z3py.py:7795
def describe_tactics()
Definition: z3py.py:7803

◆ disable_trace()

def z3py.disable_trace (   msg)

Definition at line 66 of file z3py.py.

66 def disable_trace(msg):
67  Z3_disable_trace(msg)
68 
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:66

◆ 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 1249 of file z3py.py.

1249 def Distinct(*args):
1250  """Create a Z3 distinct expression.
1251 
1252  >>> x = Int('x')
1253  >>> y = Int('y')
1254  >>> Distinct(x, y)
1255  x != y
1256  >>> z = Int('z')
1257  >>> Distinct(x, y, z)
1258  Distinct(x, y, z)
1259  >>> simplify(Distinct(x, y, z))
1260  Distinct(x, y, z)
1261  >>> simplify(Distinct(x, y, z), blast_distinct=True)
1262  And(Not(x == y), Not(x == z), Not(y == z))
1263  """
1264  args = _get_args(args)
1265  ctx = _ctx_from_ast_arg_list(args)
1266  if __debug__:
1267  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
1268  args = _coerce_expr_list(args, ctx)
1269  _args, sz = _to_ast_array(args)
1270  return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
1271 
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:1249

◆ 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 9987 of file z3py.py.

9987 def Empty(s):
9988  """Create the empty sequence of the given sort
9989  >>> e = Empty(StringSort())
9990  >>> print(e)
9991  ""
9992  >>> e2 = StringVal("")
9993  >>> print(e.eq(e2))
9994  True
9995  >>> e3 = Empty(SeqSort(IntSort()))
9996  >>> print(e3)
9997  seq.empty
9998  >>> e4 = Empty(ReSort(SeqSort(IntSort())))
9999  >>> print(e4)
10000  re.empty
10001  """
10002  if isinstance(s, SeqSortRef):
10003  return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
10004  if isinstance(s, ReSortRef):
10005  return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
10006  raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
10007 
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:9987

◆ EmptySet()

def z3py.EmptySet (   s)
Create the empty set
>>> EmptySet(IntSort())
K(Int, False)

Definition at line 4526 of file z3py.py.

4526 def EmptySet(s):
4527  """Create the empty set
4528  >>> EmptySet(IntSort())
4529  K(Int, False)
4530  """
4531  ctx = s.ctx
4532  return ArrayRef(Z3_mk_empty_set(ctx.ref(), s.ast), ctx)
4533 
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
def EmptySet(s)
Definition: z3py.py:4526

◆ enable_trace()

def z3py.enable_trace (   msg)

Definition at line 63 of file z3py.py.

63 def enable_trace(msg):
64  Z3_enable_trace(msg)
65 
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:63

◆ 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 4925 of file z3py.py.

Referenced by Context.mkEnumSort().

4925 def EnumSort(name, values, ctx=None):
4926  """Return a new enumeration sort named `name` containing the given values.
4927 
4928  The result is a pair (sort, list of constants).
4929  Example:
4930  >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
4931  """
4932  if __debug__:
4933  _z3_assert(isinstance(name, str), "Name must be a string")
4934  _z3_assert(all([isinstance(v, str) for v in values]), "Eumeration sort values must be strings")
4935  _z3_assert(len(values) > 0, "At least one value expected")
4936  ctx = _get_ctx(ctx)
4937  num = len(values)
4938  _val_names = (Symbol * num)()
4939  for i in range(num):
4940  _val_names[i] = to_symbol(values[i])
4941  _values = (FuncDecl * num)()
4942  _testers = (FuncDecl * num)()
4943  name = to_symbol(name)
4944  S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
4945  V = []
4946  for i in range(num):
4947  V.append(FuncDeclRef(_values[i], ctx))
4948  V = [a() for a in V]
4949  return S, V
4950 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def to_symbol(s, ctx=None)
Definition: z3py.py:105
def EnumSort(name, values, ctx=None)
Definition: z3py.py:4925
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 416 of file z3py.py.

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

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

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


>>> 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 2027 of file z3py.py.

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

2027 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2028  """Create a Z3 exists formula.
2029 
2030  The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2031 
2032 
2033  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2034  >>> x = Int('x')
2035  >>> y = Int('y')
2036  >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2037  >>> q
2038  Exists([x, y], f(x, y) >= x)
2039  >>> is_quantifier(q)
2040  True
2041  >>> r = Tactic('nnf')(q).as_expr()
2042  >>> is_quantifier(r)
2043  False
2044  """
2045  return _mk_quantifier(False, vs, body, weight, qid, skid, patterns, no_patterns)
2046 
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Definition: z3py.py:2027

◆ Ext()

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

Definition at line 4485 of file z3py.py.

4485 def Ext(a, b):
4486  """Return extensionality index for arrays.
4487  """
4488  if __debug__:
4489  _z3_assert(is_array(a) and is_array(b))
4490  return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()));
4491 
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:4257
def Ext(a, b)
Definition: z3py.py:4485

◆ 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 3824 of file z3py.py.

3824 def Extract(high, low, a):
3825  """Create a Z3 bit-vector extraction expression, or create a string extraction expression.
3826 
3827  >>> x = BitVec('x', 8)
3828  >>> Extract(6, 2, x)
3829  Extract(6, 2, x)
3830  >>> Extract(6, 2, x).sort()
3831  BitVec(5)
3832  >>> simplify(Extract(StringVal("abcd"),2,1))
3833  "c"
3834  """
3835  if isinstance(high, str):
3836  high = StringVal(high)
3837  if is_seq(high):
3838  s = high
3839  offset, length = _coerce_exprs(low, a, s.ctx)
3840  return SeqRef(Z3_mk_seq_extract(s.ctx_ref(), s.as_ast(), offset.as_ast(), length.as_ast()), s.ctx)
3841  if __debug__:
3842  _z3_assert(low <= high, "First argument must be greater than or equal to second argument")
3843  _z3_assert(_is_int(high) and high >= 0 and _is_int(low) and low >= 0, "First and second arguments must be non negative integers")
3844  _z3_assert(is_bv(a), "Third argument must be a Z3 Bitvector expression")
3845  return BitVecRef(Z3_mk_extract(a.ctx_ref(), high, low, a.as_ast()), a.ctx)
3846 
def Extract(high, low, a)
Definition: z3py.py:3824
def StringVal(s, ctx=None)
Definition: z3py.py:9959
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:3649
def is_seq(a)
Definition: z3py.py:9933

◆ 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 8027 of file z3py.py.

8027 def FailIf(p, ctx=None):
8028  """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8029 
8030  In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal.
8031 
8032  >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8033  >>> x, y = Ints('x y')
8034  >>> g = Goal()
8035  >>> g.add(x > 0)
8036  >>> g.add(y > 0)
8037  >>> t(g)
8038  [[x > 0, y > 0]]
8039  >>> g.add(x == y + 1)
8040  >>> t(g)
8041  [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8042  """
8043  p = _to_probe(p, ctx)
8044  return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
8045 
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:8027

◆ FiniteDomainSort()

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

Definition at line 7142 of file z3py.py.

Referenced by Context.mkFiniteDomainSort().

7142 def FiniteDomainSort(name, sz, ctx=None):
7143  """Create a named finite domain sort of a given size sz"""
7144  if not isinstance(name, Symbol):
7145  name = to_symbol(name)
7146  ctx = _get_ctx(ctx)
7147  return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
7148 
def to_symbol(s, ctx=None)
Definition: z3py.py:105
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:7142

◆ 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 7210 of file z3py.py.

7210 def FiniteDomainVal(val, sort, ctx=None):
7211  """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7212 
7213  >>> s = FiniteDomainSort('S', 256)
7214  >>> FiniteDomainVal(255, s)
7215  255
7216  >>> FiniteDomainVal('100', s)
7217  100
7218  """
7219  if __debug__:
7220  _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort" )
7221  ctx = sort.ctx
7222  return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
7223 
def is_finite_domain_sort(s)
Definition: z3py.py:7149
def FiniteDomainVal(val, sort, ctx=None)
Definition: z3py.py:7210
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 8651 of file z3py.py.

8651 def Float128(ctx=None):
8652  """Floating-point 128-bit (quadruple) sort."""
8653  ctx = _get_ctx(ctx)
8654  return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
8655 
def Float128(ctx=None)
Definition: z3py.py:8651
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 8621 of file z3py.py.

8621 def Float16(ctx=None):
8622  """Floating-point 16-bit (half) sort."""
8623  ctx = _get_ctx(ctx)
8624  return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
8625 
def Float16(ctx=None)
Definition: z3py.py:8621
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 8631 of file z3py.py.

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

8631 def Float32(ctx=None):
8632  """Floating-point 32-bit (single) sort."""
8633  ctx = _get_ctx(ctx)
8634  return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
8635 
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:8631

◆ Float64()

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

Definition at line 8641 of file z3py.py.

Referenced by fpFPToFP(), and fpToFP().

8641 def Float64(ctx=None):
8642  """Floating-point 64-bit (double) sort."""
8643  ctx = _get_ctx(ctx)
8644  return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
8645 
def Float64(ctx=None)
Definition: z3py.py:8641
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 8646 of file z3py.py.

8646 def FloatDouble(ctx=None):
8647  """Floating-point 64-bit (double) sort."""
8648  ctx = _get_ctx(ctx)
8649  return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
8650 
def FloatDouble(ctx=None)
Definition: z3py.py:8646
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 8626 of file z3py.py.

8626 def FloatHalf(ctx=None):
8627  """Floating-point 16-bit (half) sort."""
8628  ctx = _get_ctx(ctx)
8629  return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
8630 
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:8626

◆ FloatQuadruple()

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

Definition at line 8656 of file z3py.py.

8656 def FloatQuadruple(ctx=None):
8657  """Floating-point 128-bit (quadruple) sort."""
8658  ctx = _get_ctx(ctx)
8659  return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
8660 
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:8656

◆ FloatSingle()

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

Definition at line 8636 of file z3py.py.

8636 def FloatSingle(ctx=None):
8637  """Floating-point 32-bit (single) sort."""
8638  ctx = _get_ctx(ctx)
8639  return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
8640 
def FloatSingle(ctx=None)
Definition: z3py.py:8636
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.

>>> 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 2010 of file z3py.py.

Referenced by Fixedpoint.abstract(), QuantifierRef.body(), QuantifierRef.children(), QuantifierRef.is_exists(), 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().

2010 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2011  """Create a Z3 forall formula.
2012 
2013  The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2014 
2015  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2016  >>> x = Int('x')
2017  >>> y = Int('y')
2018  >>> ForAll([x, y], f(x, y) >= x)
2019  ForAll([x, y], f(x, y) >= x)
2020  >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2021  ForAll([x, y], f(x, y) >= x)
2022  >>> ForAll([x, y], f(x, y) >= x, weight=10)
2023  ForAll([x, y], f(x, y) >= x)
2024  """
2025  return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
2026 
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Definition: z3py.py:2010

◆ 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 9237 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().

9237 def FP(name, fpsort, ctx=None):
9238  """Return a floating-point constant named `name`.
9239  `fpsort` is the floating-point sort.
9240  If `ctx=None`, then the global context is used.
9241 
9242  >>> x = FP('x', FPSort(8, 24))
9243  >>> is_fp(x)
9244  True
9245  >>> x.ebits()
9246  8
9247  >>> x.sort()
9248  FPSort(8, 24)
9249  >>> word = FPSort(8, 24)
9250  >>> x2 = FP('x', word)
9251  >>> eq(x, x2)
9252  True
9253  """
9254  if isinstance(fpsort, FPSortRef) and ctx is None:
9255  ctx = fpsort.ctx
9256  else:
9257  ctx = _get_ctx(ctx)
9258  return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
9259 
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:105
def FP(name, fpsort, ctx=None)
Definition: z3py.py:9237

◆ 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 9278 of file z3py.py.

9278 def fpAbs(a, ctx=None):
9279  """Create a Z3 floating-point absolute value expression.
9280 
9281  >>> s = FPSort(8, 24)
9282  >>> rm = RNE()
9283  >>> x = FPVal(1.0, s)
9284  >>> fpAbs(x)
9285  fpAbs(1)
9286  >>> y = FPVal(-20.0, s)
9287  >>> y
9288  -1.25*(2**4)
9289  >>> fpAbs(y)
9290  fpAbs(-1.25*(2**4))
9291  >>> fpAbs(-1.25*(2**4))
9292  fpAbs(-1.25*(2**4))
9293  >>> fpAbs(x).sort()
9294  FPSort(8, 24)
9295  """
9296  ctx = _get_ctx(ctx)
9297  [a] = _coerce_fp_expr_list([a], ctx)
9298  return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
9299 
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:9278

◆ 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 9367 of file z3py.py.

Referenced by FPs().

9367 def fpAdd(rm, a, b, ctx=None):
9368  """Create a Z3 floating-point addition expression.
9369 
9370  >>> s = FPSort(8, 24)
9371  >>> rm = RNE()
9372  >>> x = FP('x', s)
9373  >>> y = FP('y', s)
9374  >>> fpAdd(rm, x, y)
9375  fpAdd(RNE(), x, y)
9376  >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
9377  x + y
9378  >>> fpAdd(rm, x, y).sort()
9379  FPSort(8, 24)
9380  """
9381  return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
9382 
def fpAdd(rm, a, b, ctx=None)
Definition: z3py.py:9367

◆ 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 9664 of file z3py.py.

9664 def fpBVToFP(v, sort, ctx=None):
9665  """Create a Z3 floating-point conversion expression that represents the
9666  conversion from a bit-vector term to a floating-point term.
9667 
9668  >>> x_bv = BitVecVal(0x3F800000, 32)
9669  >>> x_fp = fpBVToFP(x_bv, Float32())
9670  >>> x_fp
9671  fpToFP(1065353216)
9672  >>> simplify(x_fp)
9673  1
9674  """
9675  _z3_assert(is_bv(v), "First argument must be a Z3 floating-point rounding mode expression.")
9676  _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
9677  ctx = _get_ctx(ctx)
9678  return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
9679 
def fpBVToFP(v, sort, ctx=None)
Definition: z3py.py:9664
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:8665
def is_bv(a)
Definition: z3py.py:3649

◆ 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 9411 of file z3py.py.

9411 def fpDiv(rm, a, b, ctx=None):
9412  """Create a Z3 floating-point division expression.
9413 
9414  >>> s = FPSort(8, 24)
9415  >>> rm = RNE()
9416  >>> x = FP('x', s)
9417  >>> y = FP('y', s)
9418  >>> fpDiv(rm, x, y)
9419  fpDiv(RNE(), x, y)
9420  >>> fpDiv(rm, x, y).sort()
9421  FPSort(8, 24)
9422  """
9423  return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
9424 
def fpDiv(rm, a, b, ctx=None)
Definition: z3py.py:9411

◆ 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 9576 of file z3py.py.

Referenced by fpFP(), and fpNEQ().

9576 def fpEQ(a, b, ctx=None):
9577  """Create the Z3 floating-point expression `fpEQ(other, self)`.
9578 
9579  >>> x, y = FPs('x y', FPSort(8, 24))
9580  >>> fpEQ(x, y)
9581  fpEQ(x, y)
9582  >>> fpEQ(x, y).sexpr()
9583  '(fp.eq x y)'
9584  """
9585  return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
9586 
def fpEQ(a, b, ctx=None)
Definition: z3py.py:9576

◆ fpFMA()

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

Definition at line 9466 of file z3py.py.

9466 def fpFMA(rm, a, b, c, ctx=None):
9467  """Create a Z3 floating-point fused multiply-add expression.
9468  """
9469  return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
9470 
def fpFMA(rm, a, b, c, ctx=None)
Definition: z3py.py:9466

◆ 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 9598 of file z3py.py.

9598 def fpFP(sgn, exp, sig, ctx=None):
9599  """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
9600 
9601  >>> s = FPSort(8, 24)
9602  >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
9603  >>> print(x)
9604  fpFP(1, 127, 4194304)
9605  >>> xv = FPVal(-1.5, s)
9606  >>> print(xv)
9607  -1.5
9608  >>> slvr = Solver()
9609  >>> slvr.add(fpEQ(x, xv))
9610  >>> slvr.check()
9611  sat
9612  >>> xv = FPVal(+1.5, s)
9613  >>> print(xv)
9614  1.5
9615  >>> slvr = Solver()
9616  >>> slvr.add(fpEQ(x, xv))
9617  >>> slvr.check()
9618  unsat
9619  """
9620  _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
9621  _z3_assert(sgn.sort().size() == 1, "sort mismatch")
9622  ctx = _get_ctx(ctx)
9623  _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
9624  return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
9625 
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:9598
def is_bv(a)
Definition: z3py.py:3649

◆ 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 9680 of file z3py.py.

9680 def fpFPToFP(rm, v, sort, ctx=None):
9681  """Create a Z3 floating-point conversion expression that represents the
9682  conversion from a floating-point term to a floating-point term of different precision.
9683 
9684  >>> x_sgl = FPVal(1.0, Float32())
9685  >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
9686  >>> x_dbl
9687  fpToFP(RNE(), 1)
9688  >>> simplify(x_dbl)
9689  1
9690  >>> x_dbl.sort()
9691  FPSort(11, 53)
9692  """
9693  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9694  _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
9695  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9696  ctx = _get_ctx(ctx)
9697  return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9698 
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:8665
def fpFPToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9680
def is_fprm(a)
Definition: z3py.py:8913
def is_fp(a)
Definition: z3py.py:9049

◆ 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 9565 of file z3py.py.

9565 def fpGEQ(a, b, ctx=None):
9566  """Create the Z3 floating-point expression `other >= self`.
9567 
9568  >>> x, y = FPs('x y', FPSort(8, 24))
9569  >>> fpGEQ(x, y)
9570  x >= y
9571  >>> (x >= y).sexpr()
9572  '(fp.geq x y)'
9573  """
9574  return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
9575 
def fpGEQ(a, b, ctx=None)
Definition: z3py.py:9565

◆ 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 9554 of file z3py.py.

9554 def fpGT(a, b, ctx=None):
9555  """Create the Z3 floating-point expression `other > self`.
9556 
9557  >>> x, y = FPs('x y', FPSort(8, 24))
9558  >>> fpGT(x, y)
9559  x > y
9560  >>> (x > y).sexpr()
9561  '(fp.gt x y)'
9562  """
9563  return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
9564 
def fpGT(a, b, ctx=None)
Definition: z3py.py:9554

◆ fpInfinity()

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

Definition at line 9171 of file z3py.py.

9171 def fpInfinity(s, negative):
9172  """Create a Z3 floating-point +oo or -oo term."""
9173  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9174  _z3_assert(isinstance(negative, bool), "expected Boolean flag")
9175  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
9176 
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:9171

◆ 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 9492 of file z3py.py.

9492 def fpIsInf(a, ctx=None):
9493  """Create a Z3 floating-point isInfinite expression.
9494 
9495  >>> s = FPSort(8, 24)
9496  >>> x = FP('x', s)
9497  >>> fpIsInf(x)
9498  fpIsInf(x)
9499  """
9500  return _mk_fp_unary_norm(Z3_mk_fpa_is_infinite, a, ctx)
9501 
def fpIsInf(a, ctx=None)
Definition: z3py.py:9492

◆ 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 9481 of file z3py.py.

9481 def fpIsNaN(a, ctx=None):
9482  """Create a Z3 floating-point isNaN expression.
9483 
9484  >>> s = FPSort(8, 24)
9485  >>> x = FP('x', s)
9486  >>> y = FP('y', s)
9487  >>> fpIsNaN(x)
9488  fpIsNaN(x)
9489  """
9490  return _mk_fp_unary_norm(Z3_mk_fpa_is_nan, a, ctx)
9491 
def fpIsNaN(a, ctx=None)
Definition: z3py.py:9481

◆ fpIsNegative()

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

Definition at line 9517 of file z3py.py.

9517 def fpIsNegative(a, ctx=None):
9518  """Create a Z3 floating-point isNegative expression.
9519  """
9520  return _mk_fp_unary_norm(Z3_mk_fpa_is_negative, a, ctx)
9521 
def fpIsNegative(a, ctx=None)
Definition: z3py.py:9517

◆ fpIsNormal()

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

Definition at line 9507 of file z3py.py.

9507 def fpIsNormal(a, ctx=None):
9508  """Create a Z3 floating-point isNormal expression.
9509  """
9510  return _mk_fp_unary_norm(Z3_mk_fpa_is_normal, a, ctx)
9511 
def fpIsNormal(a, ctx=None)
Definition: z3py.py:9507

◆ fpIsPositive()

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

Definition at line 9522 of file z3py.py.

9522 def fpIsPositive(a, ctx=None):
9523  """Create a Z3 floating-point isPositive expression.
9524  """
9525  return _mk_fp_unary_norm(Z3_mk_fpa_is_positive, a, ctx)
9526  return FPRef(Z3_mk_fpa_is_positive(a.ctx_ref(), a.as_ast()), a.ctx)
9527 
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:9522

◆ fpIsSubnormal()

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

Definition at line 9512 of file z3py.py.

9512 def fpIsSubnormal(a, ctx=None):
9513  """Create a Z3 floating-point isSubnormal expression.
9514  """
9515  return _mk_fp_unary_norm(Z3_mk_fpa_is_subnormal, a, ctx)
9516 
def fpIsSubnormal(a, ctx=None)
Definition: z3py.py:9512

◆ fpIsZero()

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

Definition at line 9502 of file z3py.py.

9502 def fpIsZero(a, ctx=None):
9503  """Create a Z3 floating-point isZero expression.
9504  """
9505  return _mk_fp_unary_norm(Z3_mk_fpa_is_zero, a, ctx)
9506 
def fpIsZero(a, ctx=None)
Definition: z3py.py:9502

◆ 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 9543 of file z3py.py.

9543 def fpLEQ(a, b, ctx=None):
9544  """Create the Z3 floating-point expression `other <= self`.
9545 
9546  >>> x, y = FPs('x y', FPSort(8, 24))
9547  >>> fpLEQ(x, y)
9548  x <= y
9549  >>> (x <= y).sexpr()
9550  '(fp.leq x y)'
9551  """
9552  return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
9553 
def fpLEQ(a, b, ctx=None)
Definition: z3py.py:9543

◆ 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 9532 of file z3py.py.

9532 def fpLT(a, b, ctx=None):
9533  """Create the Z3 floating-point expression `other < self`.
9534 
9535  >>> x, y = FPs('x y', FPSort(8, 24))
9536  >>> fpLT(x, y)
9537  x < y
9538  >>> (x < y).sexpr()
9539  '(fp.lt x y)'
9540  """
9541  return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
9542 
def fpLT(a, b, ctx=None)
Definition: z3py.py:9532

◆ 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 9452 of file z3py.py.

9452 def fpMax(a, b, ctx=None):
9453  """Create a Z3 floating-point maximum expression.
9454 
9455  >>> s = FPSort(8, 24)
9456  >>> rm = RNE()
9457  >>> x = FP('x', s)
9458  >>> y = FP('y', s)
9459  >>> fpMax(x, y)
9460  fpMax(x, y)
9461  >>> fpMax(x, y).sort()
9462  FPSort(8, 24)
9463  """
9464  return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
9465 
def fpMax(a, b, ctx=None)
Definition: z3py.py:9452

◆ 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 9438 of file z3py.py.

9438 def fpMin(a, b, ctx=None):
9439  """Create a Z3 floating-point minimum expression.
9440 
9441  >>> s = FPSort(8, 24)
9442  >>> rm = RNE()
9443  >>> x = FP('x', s)
9444  >>> y = FP('y', s)
9445  >>> fpMin(x, y)
9446  fpMin(x, y)
9447  >>> fpMin(x, y).sort()
9448  FPSort(8, 24)
9449  """
9450  return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
9451 
def fpMin(a, b, ctx=None)
Definition: z3py.py:9438

◆ fpMinusInfinity()

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

Definition at line 9166 of file z3py.py.

9166 def fpMinusInfinity(s):
9167  """Create a Z3 floating-point -oo term."""
9168  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9169  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
9170 
def fpMinusInfinity(s)
Definition: z3py.py:9166
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 9182 of file z3py.py.

9182 def fpMinusZero(s):
9183  """Create a Z3 floating-point -0.0 term."""
9184  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9185  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
9186 
def fpMinusZero(s)
Definition: z3py.py:9182
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 9397 of file z3py.py.

Referenced by FPs().

9397 def fpMul(rm, a, b, ctx=None):
9398  """Create a Z3 floating-point multiplication expression.
9399 
9400  >>> s = FPSort(8, 24)
9401  >>> rm = RNE()
9402  >>> x = FP('x', s)
9403  >>> y = FP('y', s)
9404  >>> fpMul(rm, x, y)
9405  fpMul(RNE(), x, y)
9406  >>> fpMul(rm, x, y).sort()
9407  FPSort(8, 24)
9408  """
9409  return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
9410 
def fpMul(rm, a, b, ctx=None)
Definition: z3py.py:9397

◆ 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 9134 of file z3py.py.

9134 def fpNaN(s):
9135  """Create a Z3 floating-point NaN term.
9136 
9137  >>> s = FPSort(8, 24)
9138  >>> set_fpa_pretty(True)
9139  >>> fpNaN(s)
9140  NaN
9141  >>> pb = get_fpa_pretty()
9142  >>> set_fpa_pretty(False)
9143  >>> fpNaN(s)
9144  fpNaN(FPSort(8, 24))
9145  >>> set_fpa_pretty(pb)
9146  """
9147  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9148  return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
9149 
def fpNaN(s)
Definition: z3py.py:9134
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 9300 of file z3py.py.

9300 def fpNeg(a, ctx=None):
9301  """Create a Z3 floating-point addition expression.
9302 
9303  >>> s = FPSort(8, 24)
9304  >>> rm = RNE()
9305  >>> x = FP('x', s)
9306  >>> fpNeg(x)
9307  -x
9308  >>> fpNeg(x).sort()
9309  FPSort(8, 24)
9310  """
9311  ctx = _get_ctx(ctx)
9312  [a] = _coerce_fp_expr_list([a], ctx)
9313  return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
9314 
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:9300

◆ 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 9587 of file z3py.py.

9587 def fpNEQ(a, b, ctx=None):
9588  """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
9589 
9590  >>> x, y = FPs('x y', FPSort(8, 24))
9591  >>> fpNEQ(x, y)
9592  Not(fpEQ(x, y))
9593  >>> (x != y).sexpr()
9594  '(distinct x y)'
9595  """
9596  return Not(fpEQ(a, b, ctx))
9597 
def fpEQ(a, b, ctx=None)
Definition: z3py.py:9576
def Not(a, ctx=None)
Definition: z3py.py:1630
def fpNEQ(a, b, ctx=None)
Definition: z3py.py:9587

◆ 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 9150 of file z3py.py.

9150 def fpPlusInfinity(s):
9151  """Create a Z3 floating-point +oo term.
9152 
9153  >>> s = FPSort(8, 24)
9154  >>> pb = get_fpa_pretty()
9155  >>> set_fpa_pretty(True)
9156  >>> fpPlusInfinity(s)
9157  +oo
9158  >>> set_fpa_pretty(False)
9159  >>> fpPlusInfinity(s)
9160  fpPlusInfinity(FPSort(8, 24))
9161  >>> set_fpa_pretty(pb)
9162  """
9163  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9164  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
9165 
def fpPlusInfinity(s)
Definition: z3py.py:9150
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 9177 of file z3py.py.

9177 def fpPlusZero(s):
9178  """Create a Z3 floating-point +0.0 term."""
9179  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9180  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
9181 
def fpPlusZero(s)
Definition: z3py.py:9177
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 9699 of file z3py.py.

9699 def fpRealToFP(rm, v, sort, ctx=None):
9700  """Create a Z3 floating-point conversion expression that represents the
9701  conversion from a real term to a floating-point term.
9702 
9703  >>> x_r = RealVal(1.5)
9704  >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
9705  >>> x_fp
9706  fpToFP(RNE(), 3/2)
9707  >>> simplify(x_fp)
9708  1.5
9709  """
9710  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9711  _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
9712  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9713  ctx = _get_ctx(ctx)
9714  return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9715 
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:2481
def is_fp_sort(s)
Definition: z3py.py:8665
def fpRealToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9699
def is_fprm(a)
Definition: z3py.py:8913

◆ 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 9425 of file z3py.py.

9425 def fpRem(a, b, ctx=None):
9426  """Create a Z3 floating-point remainder expression.
9427 
9428  >>> s = FPSort(8, 24)
9429  >>> x = FP('x', s)
9430  >>> y = FP('y', s)
9431  >>> fpRem(x, y)
9432  fpRem(x, y)
9433  >>> fpRem(x, y).sort()
9434  FPSort(8, 24)
9435  """
9436  return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
9437 
def fpRem(a, b, ctx=None)
Definition: z3py.py:9425

◆ fpRoundToIntegral()

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

Definition at line 9476 of file z3py.py.

9476 def fpRoundToIntegral(rm, a, ctx=None):
9477  """Create a Z3 floating-point roundToIntegral expression.
9478  """
9479  return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
9480 
def fpRoundToIntegral(rm, a, ctx=None)
Definition: z3py.py:9476

◆ 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 9260 of file z3py.py.

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

9260 def FPs(names, fpsort, ctx=None):
9261  """Return an array of floating-point constants.
9262 
9263  >>> x, y, z = FPs('x y z', FPSort(8, 24))
9264  >>> x.sort()
9265  FPSort(8, 24)
9266  >>> x.sbits()
9267  24
9268  >>> x.ebits()
9269  8
9270  >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
9271  fpMul(RNE(), fpAdd(RNE(), x, y), z)
9272  """
9273  ctx = _get_ctx(ctx)
9274  if isinstance(names, str):
9275  names = names.split(" ")
9276  return [FP(name, fpsort, ctx) for name in names]
9277 
def FPs(names, fpsort, ctx=None)
Definition: z3py.py:9260
def FP(name, fpsort, ctx=None)
Definition: z3py.py:9237

◆ 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 9716 of file z3py.py.

9716 def fpSignedToFP(rm, v, sort, ctx=None):
9717  """Create a Z3 floating-point conversion expression that represents the
9718  conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
9719 
9720  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9721  >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
9722  >>> x_fp
9723  fpToFP(RNE(), 4294967291)
9724  >>> simplify(x_fp)
9725  -1.25*(2**2)
9726  """
9727  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9728  _z3_assert(is_bv(v), "Second argument must be a Z3 expression or real sort.")
9729  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9730  ctx = _get_ctx(ctx)
9731  return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9732 
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:9716
def is_fp_sort(s)
Definition: z3py.py:8665
def is_bv(a)
Definition: z3py.py:3649
def is_fprm(a)
Definition: z3py.py:8913

◆ 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 9076 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(), and FPRef.sort().

9076 def FPSort(ebits, sbits, ctx=None):
9077  """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9078 
9079  >>> Single = FPSort(8, 24)
9080  >>> Double = FPSort(11, 53)
9081  >>> Single
9082  FPSort(8, 24)
9083  >>> x = Const('x', Single)
9084  >>> eq(x, FP('x', FPSort(8, 24)))
9085  True
9086  """
9087  ctx = _get_ctx(ctx)
9088  return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
9089 
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:9076

◆ fpSqrt()

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

Definition at line 9471 of file z3py.py.

9471 def fpSqrt(rm, a, ctx=None):
9472  """Create a Z3 floating-point square root expression.
9473  """
9474  return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
9475 
def fpSqrt(rm, a, ctx=None)
Definition: z3py.py:9471

◆ 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 9383 of file z3py.py.

9383 def fpSub(rm, a, b, ctx=None):
9384  """Create a Z3 floating-point subtraction expression.
9385 
9386  >>> s = FPSort(8, 24)
9387  >>> rm = RNE()
9388  >>> x = FP('x', s)
9389  >>> y = FP('y', s)
9390  >>> fpSub(rm, x, y)
9391  fpSub(RNE(), x, y)
9392  >>> fpSub(rm, x, y).sort()
9393  FPSort(8, 24)
9394  """
9395  return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
9396 
def fpSub(rm, a, b, ctx=None)
Definition: z3py.py:9383

◆ 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 9626 of file z3py.py.

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

9626 def fpToFP(a1, a2=None, a3=None, ctx=None):
9627  """Create a Z3 floating-point conversion expression from other term sorts
9628  to floating-point.
9629 
9630  From a bit-vector term in IEEE 754-2008 format:
9631  >>> x = FPVal(1.0, Float32())
9632  >>> x_bv = fpToIEEEBV(x)
9633  >>> simplify(fpToFP(x_bv, Float32()))
9634  1
9635 
9636  From a floating-point term with different precision:
9637  >>> x = FPVal(1.0, Float32())
9638  >>> x_db = fpToFP(RNE(), x, Float64())
9639  >>> x_db.sort()
9640  FPSort(11, 53)
9641 
9642  From a real term:
9643  >>> x_r = RealVal(1.5)
9644  >>> simplify(fpToFP(RNE(), x_r, Float32()))
9645  1.5
9646 
9647  From a signed bit-vector term:
9648  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9649  >>> simplify(fpToFP(RNE(), x_signed, Float32()))
9650  -1.25*(2**2)
9651  """
9652  ctx = _get_ctx(ctx)
9653  if is_bv(a1) and is_fp_sort(a2):
9654  return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
9655  elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
9656  return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9657  elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
9658  return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9659  elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
9660  return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9661  else:
9662  raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
9663 
def fpToFP(a1, a2=None, a3=None, ctx=None)
Definition: z3py.py:9626
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:2481
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:8665
def is_bv(a)
Definition: z3py.py:3649
def is_fprm(a)
Definition: z3py.py:8913
def is_fp(a)
Definition: z3py.py:9049

◆ 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 9750 of file z3py.py.

Referenced by fpUnsignedToFP().

9750 def fpToFPUnsigned(rm, x, s, ctx=None):
9751  """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
9752  if __debug__:
9753  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9754  _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
9755  _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
9756  ctx = _get_ctx(ctx)
9757  return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
9758 
def fpToFPUnsigned(rm, x, s, ctx=None)
Definition: z3py.py:9750
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:8665
def is_bv(a)
Definition: z3py.py:3649
def is_fprm(a)
Definition: z3py.py:8913

◆ 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 9820 of file z3py.py.

Referenced by fpToFP().

9820 def fpToIEEEBV(x, ctx=None):
9821  """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
9822 
9823  The size of the resulting bit-vector is automatically determined.
9824 
9825  Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
9826  knows only one NaN and it will always produce the same bit-vector representation of
9827  that NaN.
9828 
9829  >>> x = FP('x', FPSort(8, 24))
9830  >>> y = fpToIEEEBV(x)
9831  >>> print(is_fp(x))
9832  True
9833  >>> print(is_bv(y))
9834  True
9835  >>> print(is_fp(y))
9836  False
9837  >>> print(is_bv(x))
9838  False
9839  """
9840  if __debug__:
9841  _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
9842  ctx = _get_ctx(ctx)
9843  return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
9844 
9845 
9846 
def fpToIEEEBV(x, ctx=None)
Definition: z3py.py:9820
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:9049

◆ 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 9801 of file z3py.py.

9801 def fpToReal(x, ctx=None):
9802  """Create a Z3 floating-point conversion expression, from floating-point expression to real.
9803 
9804  >>> x = FP('x', FPSort(8, 24))
9805  >>> y = fpToReal(x)
9806  >>> print(is_fp(x))
9807  True
9808  >>> print(is_real(y))
9809  True
9810  >>> print(is_fp(y))
9811  False
9812  >>> print(is_real(x))
9813  False
9814  """
9815  if __debug__:
9816  _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
9817  ctx = _get_ctx(ctx)
9818  return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
9819 
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:9801
def is_fp(a)
Definition: z3py.py:9049

◆ 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 9759 of file z3py.py.

9759 def fpToSBV(rm, x, s, ctx=None):
9760  """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
9761 
9762  >>> x = FP('x', FPSort(8, 24))
9763  >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
9764  >>> print(is_fp(x))
9765  True
9766  >>> print(is_bv(y))
9767  True
9768  >>> print(is_fp(y))
9769  False
9770  >>> print(is_bv(x))
9771  False
9772  """
9773  if __debug__:
9774  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9775  _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
9776  _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
9777  ctx = _get_ctx(ctx)
9778  return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
9779 
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:9759
def is_bv_sort(s)
Definition: z3py.py:3188
def is_fprm(a)
Definition: z3py.py:8913
def is_fp(a)
Definition: z3py.py:9049

◆ 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 9780 of file z3py.py.

9780 def fpToUBV(rm, x, s, ctx=None):
9781  """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
9782 
9783  >>> x = FP('x', FPSort(8, 24))
9784  >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
9785  >>> print(is_fp(x))
9786  True
9787  >>> print(is_bv(y))
9788  True
9789  >>> print(is_fp(y))
9790  False
9791  >>> print(is_bv(x))
9792  False
9793  """
9794  if __debug__:
9795  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9796  _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
9797  _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
9798  ctx = _get_ctx(ctx)
9799  return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
9800 
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:9780
def is_bv_sort(s)
Definition: z3py.py:3188
def is_fprm(a)
Definition: z3py.py:8913
def is_fp(a)
Definition: z3py.py:9049

◆ 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 9733 of file z3py.py.

9733 def fpUnsignedToFP(rm, v, sort, ctx=None):
9734  """Create a Z3 floating-point conversion expression that represents the
9735  conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
9736 
9737  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9738  >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
9739  >>> x_fp
9740  fpToFPUnsigned(RNE(), 4294967291)
9741  >>> simplify(x_fp)
9742  1*(2**32)
9743  """
9744  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9745  _z3_assert(is_bv(v), "Second argument must be a Z3 expression or real sort.")
9746  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9747  ctx = _get_ctx(ctx)
9748  return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9749 
def fpUnsignedToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9733
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:8665
def is_bv(a)
Definition: z3py.py:3649
def is_fprm(a)
Definition: z3py.py:8913

◆ 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 9193 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().

9193 def FPVal(sig, exp=None, fps=None, ctx=None):
9194  """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used.
9195 
9196  >>> v = FPVal(20.0, FPSort(8, 24))
9197  >>> v
9198  1.25*(2**4)
9199  >>> print("0x%.8x" % v.exponent_as_long(False))
9200  0x00000004
9201  >>> v = FPVal(2.25, FPSort(8, 24))
9202  >>> v
9203  1.125*(2**1)
9204  >>> v = FPVal(-2.25, FPSort(8, 24))
9205  >>> v
9206  -1.125*(2**1)
9207  >>> FPVal(-0.0, FPSort(8, 24))
9208  -0.0
9209  >>> FPVal(0.0, FPSort(8, 24))
9210  +0.0
9211  >>> FPVal(+0.0, FPSort(8, 24))
9212  +0.0
9213  """
9214  ctx = _get_ctx(ctx)
9215  if is_fp_sort(exp):
9216  fps = exp
9217  exp = None
9218  elif fps is None:
9219  fps = _dflt_fps(ctx)
9220  _z3_assert(is_fp_sort(fps), "sort mismatch")
9221  if exp is None:
9222  exp = 0
9223  val = _to_float_str(sig)
9224  if val == "NaN" or val == "nan":
9225  return fpNaN(fps)
9226  elif val == "-0.0":
9227  return fpMinusZero(fps)
9228  elif val == "0.0" or val == "+0.0":
9229  return fpPlusZero(fps)
9230  elif val == "+oo" or val == "+inf" or val == "+Inf":
9231  return fpPlusInfinity(fps)
9232  elif val == "-oo" or val == "-inf" or val == "-Inf":
9233  return fpMinusInfinity(fps)
9234  else:
9235  return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
9236 
def FPVal(sig, exp=None, fps=None, ctx=None)
Definition: z3py.py:9193
def fpMinusInfinity(s)
Definition: z3py.py:9166
def fpMinusZero(s)
Definition: z3py.py:9182
def fpPlusZero(s)
Definition: z3py.py:9177
def fpPlusInfinity(s)
Definition: z3py.py:9150
def fpNaN(s)
Definition: z3py.py:9134
def is_fp_sort(s)
Definition: z3py.py:8665
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 9187 of file z3py.py.

9187 def fpZero(s, negative):
9188  """Create a Z3 floating-point +0.0 or -0.0 term."""
9189  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9190  _z3_assert(isinstance(negative, bool), "expected Boolean flag")
9191  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
9192 
def fpZero(s, negative)
Definition: z3py.py:9187
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 1587 of file z3py.py.

1587 def FreshBool(prefix='b', ctx=None):
1588  """Return a fresh Boolean constant in the given context using the given prefix.
1589 
1590  If `ctx=None`, then the global context is used.
1591 
1592  >>> b1 = FreshBool()
1593  >>> b2 = FreshBool()
1594  >>> eq(b1, b2)
1595  False
1596  """
1597  ctx = _get_ctx(ctx)
1598  return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1599 
def FreshBool(prefix='b', ctx=None)
Definition: z3py.py:1587
def BoolSort(ctx=None)
Definition: z3py.py:1512
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.

◆ FreshConst()

def z3py.FreshConst (   sort,
  prefix = 'c' 
)
Create a fresh constant of a specified sort

Definition at line 1305 of file z3py.py.

1305 def FreshConst(sort, prefix='c'):
1306  """Create a fresh constant of a specified sort"""
1307  ctx = _get_ctx(sort.ctx)
1308  return _to_expr_ref(Z3_mk_fresh_const(ctx.ref(), prefix, sort.ast), ctx)
1309 
def FreshConst(sort, prefix='c')
Definition: z3py.py:1305
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 3011 of file z3py.py.

3011 def FreshInt(prefix='x', ctx=None):
3012  """Return a fresh integer constant in the given context using the given prefix.
3013 
3014  >>> x = FreshInt()
3015  >>> y = FreshInt()
3016  >>> eq(x, y)
3017  False
3018  >>> x.sort()
3019  Int
3020  """
3021  ctx = _get_ctx(ctx)
3022  return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
3023 
def IntSort(ctx=None)
Definition: z3py.py:2873
def FreshInt(prefix='x', ctx=None)
Definition: z3py.py:3011
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 3063 of file z3py.py.

3063 def FreshReal(prefix='b', ctx=None):
3064  """Return a fresh real constant in the given context using the given prefix.
3065 
3066  >>> x = FreshReal()
3067  >>> y = FreshReal()
3068  >>> eq(x, y)
3069  False
3070  >>> x.sort()
3071  Real
3072  """
3073  ctx = _get_ctx(ctx)
3074  return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
3075 
def FreshReal(prefix='b', ctx=None)
Definition: z3py.py:3063
def RealSort(ctx=None)
Definition: z3py.py:2889
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 10008 of file z3py.py.

10008 def Full(s):
10009  """Create the regular expression that accepts the universal language
10010  >>> e = Full(ReSort(SeqSort(IntSort())))
10011  >>> print(e)
10012  re.all
10013  >>> e1 = Full(ReSort(StringSort()))
10014  >>> print(e1)
10015  re.all
10016  """
10017  if isinstance(s, ReSortRef):
10018  return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
10019  raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
10020 
10021 
def Full(s)
Definition: z3py.py:10008
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.

◆ FullSet()

def z3py.FullSet (   s)
Create the full set
>>> FullSet(IntSort())
K(Int, True)

Definition at line 4534 of file z3py.py.

4534 def FullSet(s):
4535  """Create the full set
4536  >>> FullSet(IntSort())
4537  K(Int, True)
4538  """
4539  ctx = s.ctx
4540  return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
4541 
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
def FullSet(s)
Definition: z3py.py:4534

◆ 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 778 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_exists(), QuantifierRef.is_forall(), QuantifierRef.is_lambda(), is_map(), is_pattern(), is_quantifier(), Lambda(), 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().

778 def Function(name, *sig):
779  """Create a new Z3 uninterpreted function with the given sorts.
780 
781  >>> f = Function('f', IntSort(), IntSort())
782  >>> f(f(0))
783  f(f(0))
784  """
785  sig = _get_args(sig)
786  if __debug__:
787  _z3_assert(len(sig) > 0, "At least two arguments expected")
788  arity = len(sig) - 1
789  rng = sig[arity]
790  if __debug__:
791  _z3_assert(is_sort(rng), "Z3 sort expected")
792  dom = (Sort * arity)()
793  for i in range(arity):
794  if __debug__:
795  _z3_assert(is_sort(sig[i]), "Z3 sort expected")
796  dom[i] = sig[i].ast
797  ctx = rng.ctx
798  return FuncDeclRef(Z3_mk_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
799 
def Function(name, sig)
Definition: z3py.py:778
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def to_symbol(s, ctx=None)
Definition: z3py.py:105
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:579

◆ 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 6175 of file z3py.py.

6175 def get_as_array_func(n):
6176  """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6177  if __debug__:
6178  _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
6179  return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
6180 
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:6175
def is_as_array(n)
Definition: z3py.py:6171

◆ get_default_fp_sort()

def z3py.get_default_fp_sort (   ctx = None)

Definition at line 8545 of file z3py.py.

8545 def get_default_fp_sort(ctx=None):
8546  return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
8547 
def FPSort(ebits, sbits, ctx=None)
Definition: z3py.py:9076
def get_default_fp_sort(ctx=None)
Definition: z3py.py:8545

◆ get_default_rounding_mode()

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

Definition at line 8518 of file z3py.py.

8518 def get_default_rounding_mode(ctx=None):
8519  """Retrieves the global default rounding mode."""
8520  global _dflt_rounding_mode
8521  if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
8522  return RTZ(ctx)
8523  elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
8524  return RTN(ctx)
8525  elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
8526  return RTP(ctx)
8527  elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
8528  return RNE(ctx)
8529  elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
8530  return RNA(ctx)
8531 
def RTN(ctx=None)
Definition: z3py.py:8901
def RTZ(ctx=None)
Definition: z3py.py:8909
def RTP(ctx=None)
Definition: z3py.py:8893
def RNA(ctx=None)
Definition: z3py.py:8885
def get_default_rounding_mode(ctx=None)
Definition: z3py.py:8518
def RNE(ctx=None)
Definition: z3py.py:8877

◆ get_full_version()

def z3py.get_full_version ( )

Definition at line 85 of file z3py.py.

85 def get_full_version():
86  return Z3_get_full_version()
87 
88 # We use _z3_assert instead of the assert command because we want to
89 # 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:85

◆ 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 4317 of file z3py.py.

4317 def get_map_func(a):
4318  """Return the function declaration associated with a Z3 map array expression.
4319 
4320  >>> f = Function('f', IntSort(), IntSort())
4321  >>> b = Array('b', IntSort(), IntSort())
4322  >>> a = Map(f, b)
4323  >>> eq(f, get_map_func(a))
4324  True
4325  >>> get_map_func(a)
4326  f
4327  >>> get_map_func(a)(0)
4328  f(0)
4329  """
4330  if __debug__:
4331  _z3_assert(is_map(a), "Z3 array map expression expected.")
4332  return FuncDeclRef(Z3_to_func_decl(a.ctx_ref(), Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0)), a.ctx)
4333 
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:4294
def get_map_func(a)
Definition: z3py.py:4317
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 266 of file z3py.py.

266 def get_param(name):
267  """Return the value of a Z3 global (or module) parameter
268 
269  >>> get_param('nlsat.reorder')
270  'true'
271  """
272  ptr = (ctypes.c_char_p * 1)()
273  if Z3_global_param_get(str(name), ptr):
274  r = z3core._to_pystr(ptr[0])
275  return r
276  raise Z3Exception("failed to retrieve value for '%s'" % name)
277 
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:266

◆ 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 1183 of file z3py.py.

1183 def get_var_index(a):
1184  """Return the de-Bruijn index of the Z3 bounded variable `a`.
1185 
1186  >>> x = Int('x')
1187  >>> y = Int('y')
1188  >>> is_var(x)
1189  False
1190  >>> is_const(x)
1191  True
1192  >>> f = Function('f', IntSort(), IntSort(), IntSort())
1193  >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1194  >>> q = ForAll([x, y], f(x, y) == x + y)
1195  >>> q.body()
1196  f(Var(1), Var(0)) == Var(1) + Var(0)
1197  >>> b = q.body()
1198  >>> b.arg(0)
1199  f(Var(1), Var(0))
1200  >>> v1 = b.arg(0).arg(0)
1201  >>> v2 = b.arg(0).arg(1)
1202  >>> v1
1203  Var(1)
1204  >>> v2
1205  Var(0)
1206  >>> get_var_index(v1)
1207  1
1208  >>> get_var_index(v2)
1209  0
1210  """
1211  if __debug__:
1212  _z3_assert(is_var(a), "Z3 bound variable expected")
1213  return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
1214 
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:1183
def is_var(a)
Definition: z3py.py:1159

◆ get_version()

def z3py.get_version ( )

Definition at line 77 of file z3py.py.

77 def get_version():
78  major = ctypes.c_uint(0)
79  minor = ctypes.c_uint(0)
80  build = ctypes.c_uint(0)
81  rev = ctypes.c_uint(0)
82  Z3_get_version(major, minor, build, rev)
83  return (major.value, minor.value, build.value, rev.value)
84 
def get_version()
Definition: z3py.py:77
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 69 of file z3py.py.

69 def get_version_string():
70  major = ctypes.c_uint(0)
71  minor = ctypes.c_uint(0)
72  build = ctypes.c_uint(0)
73  rev = ctypes.c_uint(0)
74  Z3_get_version(major, minor, build, rev)
75  return "%s.%s.%s" % (major.value, minor.value, build.value)
76 
def get_version_string()
Definition: z3py.py:69
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 8104 of file z3py.py.

8104 def help_simplify():
8105  """Return a string describing all options available for Z3 `simplify` procedure."""
8106  print(Z3_simplify_get_help(main_ctx().ref()))
8107 
def main_ctx()
Definition: z3py.py:207
def help_simplify()
Definition: z3py.py:8104
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 1227 of file z3py.py.

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

1227 def If(a, b, c, ctx=None):
1228  """Create a Z3 if-then-else expression.
1229 
1230  >>> x = Int('x')
1231  >>> y = Int('y')
1232  >>> max = If(x > y, x, y)
1233  >>> max
1234  If(x > y, x, y)
1235  >>> simplify(max)
1236  If(x <= y, y, x)
1237  """
1238  if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1239  return Cond(a, b, c, ctx)
1240  else:
1241  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1242  s = BoolSort(ctx)
1243  a = s.cast(a)
1244  b, c = _coerce_exprs(b, c, ctx)
1245  if __debug__:
1246  _z3_assert(a.ctx == b.ctx, "Context mismatch")
1247  return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1248 
def If(a, b, c, ctx=None)
Definition: z3py.py:1227
def Cond(p, t1, t2, ctx=None)
Definition: z3py.py:8064
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:1512

◆ 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 1600 of file z3py.py.

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

1600 def Implies(a, b, ctx=None):
1601  """Create a Z3 implies expression.
1602 
1603  >>> p, q = Bools('p q')
1604  >>> Implies(p, q)
1605  Implies(p, q)
1606  >>> simplify(Implies(p, q))
1607  Or(Not(p), q)
1608  """
1609  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1610  s = BoolSort(ctx)
1611  a = s.cast(a)
1612  b = s.cast(b)
1613  return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1614 
def Implies(a, b, ctx=None)
Definition: z3py.py:1600
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:1512

◆ IndexOf() [1/2]

def z3py.IndexOf (   s,
  substr 
)

Definition at line 10087 of file z3py.py.

Referenced by IndexOf().

10087 def IndexOf(s, substr):
10088  return IndexOf(s, substr, IntVal(0))
10089 
def IntVal(val, ctx=None)
Definition: z3py.py:2920
def IndexOf(s, substr)
Definition: z3py.py:10087

◆ 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 10090 of file z3py.py.

10090 def IndexOf(s, substr, offset):
10091  """Retrieve the index of substring within a string starting at a specified offset.
10092  >>> simplify(IndexOf("abcabc", "bc", 0))
10093  1
10094  >>> simplify(IndexOf("abcabc", "bc", 2))
10095  4
10096  """
10097  ctx = None
10098  if is_expr(offset):
10099  ctx = offset.ctx
10100  ctx = _get_ctx2(s, substr, ctx)
10101  s = _coerce_seq(s, ctx)
10102  substr = _coerce_seq(substr, ctx)
10103  if _is_int(offset):
10104  offset = IntVal(offset, ctx)
10105  return SeqRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
10106 
def IntVal(val, ctx=None)
Definition: z3py.py:2920
def IndexOf(s, substr)
Definition: z3py.py:10087
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:1094

◆ 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 10177 of file z3py.py.

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

10177 def InRe(s, re):
10178  """Create regular expression membership test
10179  >>> re = Union(Re("a"),Re("b"))
10180  >>> print (simplify(InRe("a", re)))
10181  True
10182  >>> print (simplify(InRe("b", re)))
10183  True
10184  >>> print (simplify(InRe("c", re)))
10185  False
10186  """
10187  s = _coerce_seq(s, re.ctx)
10188  return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
10189 
def InRe(s, re)
Definition: z3py.py:10177
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 2976 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(), 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(), is_arith(), is_arith_sort(), is_bv(), QuantifierRef.is_exists(), QuantifierRef.is_forall(), is_fp(), ArithSortRef.is_int(), ArithRef.is_int(), is_int(), is_int_value(), QuantifierRef.is_lambda(), 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(), Solver.sexpr(), Goal.simplify(), ArithRef.sort(), Solver.statistics(), Store(), ToReal(), Goal.translate(), AstVector.translate(), Update(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and QuantifierRef.weight().

2976 def Int(name, ctx=None):
2977  """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
2978 
2979  >>> x = Int('x')
2980  >>> is_int(x)
2981  True
2982  >>> is_int(x + 1)
2983  True
2984  """
2985  ctx = _get_ctx(ctx)
2986  return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
2987 
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:105
def Int(name, ctx=None)
Definition: z3py.py:2976
def IntSort(ctx=None)
Definition: z3py.py:2873

◆ 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 3698 of file z3py.py.

3698 def Int2BV(a, num_bits):
3699  """Return the z3 expression Int2BV(a, num_bits).
3700  It is a bit-vector of width num_bits and represents the
3701  modulo of a by 2^num_bits
3702  """
3703  ctx = a.ctx
3704  return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
3705 
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:3698

◆ 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 2988 of file z3py.py.

Referenced by ArithRef.__ge__(), Goal.__getitem__(), ArithRef.__gt__(), ArithRef.__le__(), Goal.__len__(), ArithRef.__lt__(), Goal.convert_model(), 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(), Lambda(), Goal.prec(), Goal.size(), Store(), Solver.unsat_core(), and Update().

2988 def Ints(names, ctx=None):
2989  """Return a tuple of Integer constants.
2990 
2991  >>> x, y, z = Ints('x y z')
2992  >>> Sum(x, y, z)
2993  x + y + z
2994  """
2995  ctx = _get_ctx(ctx)
2996  if isinstance(names, str):
2997  names = names.split(" ")
2998  return [Int(name, ctx) for name in names]
2999 
def Int(name, ctx=None)
Definition: z3py.py:2976
def Ints(names, ctx=None)
Definition: z3py.py:2988

◆ 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 2873 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(), EmptySet(), FuncInterp.entry(), Exists(), ForAll(), Full(), FullSet(), ModelRef.get_interp(), get_map_func(), Context.getIntSort(), is_arith_sort(), is_array(), is_bv_sort(), is_const_array(), is_default(), QuantifierRef.is_exists(), QuantifierRef.is_forall(), is_fp_sort(), is_K(), QuantifierRef.is_lambda(), is_map(), is_pattern(), is_quantifier(), is_select(), is_store(), SeqSortRef.is_string(), IsMember(), IsSubset(), K(), Lambda(), 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(), SetAdd(), SetComplement(), SetDel(), SetDifference(), SetIntersect(), SetUnion(), ArrayRef.sort(), Store(), Update(), FuncEntry.value(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and QuantifierRef.weight().

2873 def IntSort(ctx=None):
2874  """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
2875 
2876  >>> IntSort()
2877  Int
2878  >>> x = Const('x', IntSort())
2879  >>> is_int(x)
2880  True
2881  >>> x.sort() == IntSort()
2882  True
2883  >>> x.sort() == BoolSort()
2884  False
2885  """
2886  ctx = _get_ctx(ctx)
2887  return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
2888 
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
def IntSort(ctx=None)
Definition: z3py.py:2873

◆ IntToStr()

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

Definition at line 10132 of file z3py.py.

Referenced by StrToInt().

10132 def IntToStr(s):
10133  """Convert integer expression to string"""
10134  if not is_expr(s):
10135  s = _py2expr(s)
10136  return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
10137 
10138 
def IntToStr(s)
Definition: z3py.py:10132
def is_expr(a)
Definition: z3py.py:1094
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 2920 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().

2920 def IntVal(val, ctx=None):
2921  """Return a Z3 integer value. If `ctx=None`, then the global context is used.
2922 
2923  >>> IntVal(1)
2924  1
2925  >>> IntVal("100")
2926  100
2927  """
2928  ctx = _get_ctx(ctx)
2929  return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
2930 
def IntVal(val, ctx=None)
Definition: z3py.py:2920
def IntSort(ctx=None)
Definition: z3py.py:2873
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 3000 of file z3py.py.

3000 def IntVector(prefix, sz, ctx=None):
3001  """Return a list of integer constants of size `sz`.
3002 
3003  >>> X = IntVector('x', 3)
3004  >>> X
3005  [x__0, x__1, x__2]
3006  >>> Sum(X)
3007  x__0 + x__1 + x__2
3008  """
3009  return [ Int('%s__%s' % (prefix, i)) for i in range(sz) ]
3010 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def Int(name, ctx=None)
Definition: z3py.py:2976
def IntVector(prefix, sz, ctx=None)
Definition: z3py.py:3000

◆ 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 2562 of file z3py.py.

2562 def is_add(a):
2563  """Return `True` if `a` is an expression of the form b + c.
2564 
2565  >>> x, y = Ints('x y')
2566  >>> is_add(x + y)
2567  True
2568  >>> is_add(x - y)
2569  False
2570  """
2571  return is_app_of(a, Z3_OP_ADD)
2572 
def is_app_of(a, k)
Definition: z3py.py:1215
def is_add(a)
Definition: z3py.py:2562

◆ 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 2549 of file z3py.py.

2549 def is_algebraic_value(a):
2550  """Return `True` if `a` is an algebraic value of sort Real.
2551 
2552  >>> is_algebraic_value(RealVal("3/5"))
2553  False
2554  >>> n = simplify(Sqrt(2))
2555  >>> n
2556  1.4142135623?
2557  >>> is_algebraic_value(n)
2558  True
2559  """
2560  return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2561 
def is_arith(a)
Definition: z3py.py:2443
def is_algebraic_value(a)
Definition: z3py.py:2549

◆ 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 1448 of file z3py.py.

1448 def is_and(a):
1449  """Return `True` if `a` is a Z3 and expression.
1450 
1451  >>> p, q = Bools('p q')
1452  >>> is_and(And(p, q))
1453  True
1454  >>> is_and(Or(p, q))
1455  False
1456  """
1457  return is_app_of(a, Z3_OP_AND)
1458 
def is_and(a)
Definition: z3py.py:1448
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 1116 of file z3py.py.

Referenced by ExprRef.arg(), ExprRef.children(), ExprRef.decl(), is_app_of(), is_const(), ExprRef.num_args(), and RecAddDefinition().

1116 def is_app(a):
1117  """Return `True` if `a` is a Z3 function application.
1118 
1119  Note that, constants are function applications with 0 arguments.
1120 
1121  >>> a = Int('a')
1122  >>> is_app(a)
1123  True
1124  >>> is_app(a + 1)
1125  True
1126  >>> is_app(IntSort())
1127  False
1128  >>> is_app(1)
1129  False
1130  >>> is_app(IntVal(1))
1131  True
1132  >>> x = Int('x')
1133  >>> is_app(ForAll(x, x >= 0))
1134  False
1135  """
1136  if not isinstance(a, ExprRef):
1137  return False
1138  k = _ast_kind(a.ctx, a)
1139  return k == Z3_NUMERAL_AST or k == Z3_APP_AST
1140 
def is_app(a)
Definition: z3py.py:1116

◆ 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 1215 of file z3py.py.

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

1215 def is_app_of(a, k):
1216  """Return `True` if `a` is an application of the given kind `k`.
1217 
1218  >>> x = Int('x')
1219  >>> n = x + 1
1220  >>> is_app_of(n, Z3_OP_ADD)
1221  True
1222  >>> is_app_of(n, Z3_OP_MUL)
1223  False
1224  """
1225  return is_app(a) and a.decl().kind() == k
1226 
def is_app(a)
Definition: z3py.py:1116
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 2443 of file z3py.py.

2443 def is_arith(a):
2444  """Return `True` if `a` is an arithmetical expression.
2445 
2446  >>> x = Int('x')
2447  >>> is_arith(x)
2448  True
2449  >>> is_arith(x + 1)
2450  True
2451  >>> is_arith(1)
2452  False
2453  >>> is_arith(IntVal(1))
2454  True
2455  >>> y = Real('y')
2456  >>> is_arith(y)
2457  True
2458  >>> is_arith(y + 1)
2459  True
2460  """
2461  return isinstance(a, ArithRef)
2462 
def is_arith(a)
Definition: z3py.py:2443

◆ 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 2144 of file z3py.py.

2144 def is_arith_sort(s):
2145  """Return `True` if s is an arithmetical sort (type).
2146 
2147  >>> is_arith_sort(IntSort())
2148  True
2149  >>> is_arith_sort(RealSort())
2150  True
2151  >>> is_arith_sort(BoolSort())
2152  False
2153  >>> n = Int('x') + 1
2154  >>> is_arith_sort(n.sort())
2155  True
2156  """
2157  return isinstance(s, ArithSortRef)
2158 
def is_arith_sort(s)
Definition: z3py.py:2144

◆ 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 4257 of file z3py.py.

4257 def is_array(a):
4258  """Return `True` if `a` is a Z3 array expression.
4259 
4260  >>> a = Array('a', IntSort(), IntSort())
4261  >>> is_array(a)
4262  True
4263  >>> is_array(Store(a, 0, 1))
4264  True
4265  >>> is_array(a[0])
4266  False
4267  """
4268  return isinstance(a, ArrayRef)
4269 
def is_array(a)
Definition: z3py.py:4257

◆ 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 6171 of file z3py.py.

6171 def is_as_array(n):
6172  """Return true if n is a Z3 expression of the form (_ as-array f)."""
6173  return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6174 
def is_as_array(n)
Definition: z3py.py:6171
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 396 of file z3py.py.

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

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

◆ 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 1401 of file z3py.py.

Referenced by BoolSort(), and prove().

1401 def is_bool(a):
1402  """Return `True` if `a` is a Z3 Boolean expression.
1403 
1404  >>> p = Bool('p')
1405  >>> is_bool(p)
1406  True
1407  >>> q = Bool('q')
1408  >>> is_bool(And(p, q))
1409  True
1410  >>> x = Real('x')
1411  >>> is_bool(x)
1412  False
1413  >>> is_bool(x == 0)
1414  True
1415  """
1416  return isinstance(a, BoolRef)
1417 
def is_bool(a)
Definition: z3py.py:1401

◆ 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 3649 of file z3py.py.

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

3649 def is_bv(a):
3650  """Return `True` if `a` is a Z3 bit-vector expression.
3651 
3652  >>> b = BitVec('b', 32)
3653  >>> is_bv(b)
3654  True
3655  >>> is_bv(b + 10)
3656  True
3657  >>> is_bv(Int('x'))
3658  False
3659  """
3660  return isinstance(a, BitVecRef)
3661 
def is_bv(a)
Definition: z3py.py:3649

◆ 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 3188 of file z3py.py.

3188 def is_bv_sort(s):
3189  """Return True if `s` is a Z3 bit-vector sort.
3190 
3191  >>> is_bv_sort(BitVecSort(32))
3192  True
3193  >>> is_bv_sort(IntSort())
3194  False
3195  """
3196  return isinstance(s, BitVecSortRef)
3197 
def is_bv_sort(s)
Definition: z3py.py:3188

◆ 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 3662 of file z3py.py.

3662 def is_bv_value(a):
3663  """Return `True` if `a` is a Z3 bit-vector numeral value.
3664 
3665  >>> b = BitVec('b', 32)
3666  >>> is_bv_value(b)
3667  False
3668  >>> b = BitVecVal(10, 32)
3669  >>> b
3670  10
3671  >>> is_bv_value(b)
3672  True
3673  """
3674  return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
3675 
def is_bv_value(a)
Definition: z3py.py:3662
def is_bv(a)
Definition: z3py.py:3649

◆ 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 1141 of file z3py.py.

Referenced by prove().

1141 def is_const(a):
1142  """Return `True` if `a` is Z3 constant/variable expression.
1143 
1144  >>> a = Int('a')
1145  >>> is_const(a)
1146  True
1147  >>> is_const(a + 1)
1148  False
1149  >>> is_const(1)
1150  False
1151  >>> is_const(IntVal(1))
1152  True
1153  >>> x = Int('x')
1154  >>> is_const(ForAll(x, x >= 0))
1155  False
1156  """
1157  return is_app(a) and a.num_args() == 0
1158 
def is_app(a)
Definition: z3py.py:1116
def is_const(a)
Definition: z3py.py:1141

◆ 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 4270 of file z3py.py.

4270 def is_const_array(a):
4271  """Return `True` if `a` is a Z3 constant array.
4272 
4273  >>> a = K(IntSort(), 10)
4274  >>> is_const_array(a)
4275  True
4276  >>> a = Array('a', IntSort(), IntSort())
4277  >>> is_const_array(a)
4278  False
4279  """
4280  return is_app_of(a, Z3_OP_CONST_ARRAY)
4281 
def is_const_array(a)
Definition: z3py.py:4270
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 4309 of file z3py.py.

4309 def is_default(a):
4310  """Return `True` if `a` is a Z3 default array expression.
4311  >>> d = Default(K(IntSort(), 10))
4312  >>> is_default(d)
4313  True
4314  """
4315  return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4316 
def is_default(a)
Definition: z3py.py:4309
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 1501 of file z3py.py.

1501 def is_distinct(a):
1502  """Return `True` if `a` is a Z3 distinct expression.
1503 
1504  >>> x, y, z = Ints('x y z')
1505  >>> is_distinct(x == y)
1506  False
1507  >>> is_distinct(Distinct(x, y, z))
1508  True
1509  """
1510  return is_app_of(a, Z3_OP_DISTINCT)
1511 
def is_distinct(a)
Definition: z3py.py:1501
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 2595 of file z3py.py.

2595 def is_div(a):
2596  """Return `True` if `a` is an expression of the form b / c.
2597 
2598  >>> x, y = Reals('x y')
2599  >>> is_div(x / y)
2600  True
2601  >>> is_div(x + y)
2602  False
2603  >>> x, y = Ints('x y')
2604  >>> is_div(x / y)
2605  False
2606  >>> is_idiv(x / y)
2607  True
2608  """
2609  return is_app_of(a, Z3_OP_DIV)
2610 
def is_div(a)
Definition: z3py.py:2595
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 1492 of file z3py.py.

Referenced by AstRef.__bool__().

1492 def is_eq(a):
1493  """Return `True` if `a` is a Z3 equality expression.
1494 
1495  >>> x, y = Ints('x y')
1496  >>> is_eq(x == y)
1497  True
1498  """
1499  return is_app_of(a, Z3_OP_EQ)
1500 
def is_eq(a)
Definition: z3py.py:1492
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 1094 of file z3py.py.

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

1094 def is_expr(a):
1095  """Return `True` if `a` is a Z3 expression.
1096 
1097  >>> a = Int('a')
1098  >>> is_expr(a)
1099  True
1100  >>> is_expr(a + 1)
1101  True
1102  >>> is_expr(IntSort())
1103  False
1104  >>> is_expr(1)
1105  False
1106  >>> is_expr(IntVal(1))
1107  True
1108  >>> x = Int('x')
1109  >>> is_expr(ForAll(x, x >= 0))
1110  True
1111  >>> is_expr(FPVal(1.0))
1112  True
1113  """
1114  return isinstance(a, ExprRef)
1115 
def is_expr(a)
Definition: z3py.py:1094

◆ 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 1435 of file z3py.py.

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

1435 def is_false(a):
1436  """Return `True` if `a` is the Z3 false expression.
1437 
1438  >>> p = Bool('p')
1439  >>> is_false(p)
1440  False
1441  >>> is_false(False)
1442  False
1443  >>> is_false(BoolVal(False))
1444  True
1445  """
1446  return is_app_of(a, Z3_OP_FALSE)
1447 
def is_app_of(a, k)
Definition: z3py.py:1215
def is_false(a)
Definition: z3py.py:1435

◆ 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 7171 of file z3py.py.

Referenced by is_finite_domain_value().

7171 def is_finite_domain(a):
7172  """Return `True` if `a` is a Z3 finite-domain expression.
7173 
7174  >>> s = FiniteDomainSort('S', 100)
7175  >>> b = Const('b', s)
7176  >>> is_finite_domain(b)
7177  True
7178  >>> is_finite_domain(Int('x'))
7179  False
7180  """
7181  return isinstance(a, FiniteDomainRef)
7182 
7183 
def is_finite_domain(a)
Definition: z3py.py:7171

◆ 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 7149 of file z3py.py.

Referenced by FiniteDomainVal().

7149 def is_finite_domain_sort(s):
7150  """Return True if `s` is a Z3 finite-domain sort.
7151 
7152  >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7153  True
7154  >>> is_finite_domain_sort(IntSort())
7155  False
7156  """
7157  return isinstance(s, FiniteDomainSortRef)
7158 
7159 
def is_finite_domain_sort(s)
Definition: z3py.py:7149

◆ 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 7224 of file z3py.py.

7224 def is_finite_domain_value(a):
7225  """Return `True` if `a` is a Z3 finite-domain value.
7226 
7227  >>> s = FiniteDomainSort('S', 100)
7228  >>> b = Const('b', s)
7229  >>> is_finite_domain_value(b)
7230  False
7231  >>> b = FiniteDomainVal(10, s)
7232  >>> b
7233  10
7234  >>> is_finite_domain_value(b)
7235  True
7236  """
7237  return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
7238 
7239 
def is_finite_domain_value(a)
Definition: z3py.py:7224
def is_finite_domain(a)
Definition: z3py.py:7171

◆ 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 9049 of file z3py.py.

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

9049 def is_fp(a):
9050  """Return `True` if `a` is a Z3 floating-point expression.
9051 
9052  >>> b = FP('b', FPSort(8, 24))
9053  >>> is_fp(b)
9054  True
9055  >>> is_fp(b + 1.0)
9056  True
9057  >>> is_fp(Int('x'))
9058  False
9059  """
9060  return isinstance(a, FPRef)
9061 
def is_fp(a)
Definition: z3py.py:9049

◆ 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 8665 of file z3py.py.

8665 def is_fp_sort(s):
8666  """Return True if `s` is a Z3 floating-point sort.
8667 
8668  >>> is_fp_sort(FPSort(8, 24))
8669  True
8670  >>> is_fp_sort(IntSort())
8671  False
8672  """
8673  return isinstance(s, FPSortRef)
8674 
def is_fp_sort(s)
Definition: z3py.py:8665

◆ 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 9062 of file z3py.py.

9062 def is_fp_value(a):
9063  """Return `True` if `a` is a Z3 floating-point numeral value.
9064 
9065  >>> b = FP('b', FPSort(8, 24))
9066  >>> is_fp_value(b)
9067  False
9068  >>> b = FPVal(1.0, FPSort(8, 24))
9069  >>> b
9070  1
9071  >>> is_fp_value(b)
9072  True
9073  """
9074  return is_fp(a) and _is_numeral(a.ctx, a.ast)
9075 
def is_fp_value(a)
Definition: z3py.py:9062
def is_fp(a)
Definition: z3py.py:9049

◆ 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 8913 of file z3py.py.

8913 def is_fprm(a):
8914  """Return `True` if `a` is a Z3 floating-point rounding mode expression.
8915 
8916  >>> rm = RNE()
8917  >>> is_fprm(rm)
8918  True
8919  >>> rm = 1.0
8920  >>> is_fprm(rm)
8921  False
8922  """
8923  return isinstance(a, FPRMRef)
8924 
def is_fprm(a)
Definition: z3py.py:8913

◆ 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 8675 of file z3py.py.

8675 def is_fprm_sort(s):
8676  """Return True if `s` is a Z3 floating-point rounding mode sort.
8677 
8678  >>> is_fprm_sort(FPSort(8, 24))
8679  False
8680  >>> is_fprm_sort(RNE().sort())
8681  True
8682  """
8683  return isinstance(s, FPRMSortRef)
8684 
def is_fprm_sort(s)
Definition: z3py.py:8675

◆ 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 8925 of file z3py.py.

8925 def is_fprm_value(a):
8926  """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
8927  return is_fprm(a) and _is_numeral(a.ctx, a.ast)
8928 
def is_fprm_value(a)
Definition: z3py.py:8925
def is_fprm(a)
Definition: z3py.py:8913

◆ 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 766 of file z3py.py.

Referenced by prove().

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

◆ 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 2655 of file z3py.py.

2655 def is_ge(a):
2656  """Return `True` if `a` is an expression of the form b >= c.
2657 
2658  >>> x, y = Ints('x y')
2659  >>> is_ge(x >= y)
2660  True
2661  >>> is_ge(x == y)
2662  False
2663  """
2664  return is_app_of(a, Z3_OP_GE)
2665 
def is_ge(a)
Definition: z3py.py:2655
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 2666 of file z3py.py.

2666 def is_gt(a):
2667  """Return `True` if `a` is an expression of the form b > c.
2668 
2669  >>> x, y = Ints('x y')
2670  >>> is_gt(x > y)
2671  True
2672  >>> is_gt(x == y)
2673  False
2674  """
2675  return is_app_of(a, Z3_OP_GT)
2676 
def is_gt(a)
Definition: z3py.py:2666
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 2611 of file z3py.py.

Referenced by is_div().

2611 def is_idiv(a):
2612  """Return `True` if `a` is an expression of the form b div c.
2613 
2614  >>> x, y = Ints('x y')
2615  >>> is_idiv(x / y)
2616  True
2617  >>> is_idiv(x + y)
2618  False
2619  """
2620  return is_app_of(a, Z3_OP_IDIV)
2621 
def is_idiv(a)
Definition: z3py.py:2611
def is_app_of(a, k)
Definition: z3py.py:1215

◆ is_implies()

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

>>> p, q = Bools('p q')
>>> is_implies(Implies(p, q))
True
>>> is_implies(And(p, q))
False

Definition at line 1470 of file z3py.py.

1470 def is_implies(a):
1471  """Return `True` if `a` is a Z3 implication expression.
1472 
1473  >>> p, q = Bools('p q')
1474  >>> is_implies(Implies(p, q))
1475  True
1476  >>> is_implies(And(p, q))
1477  False
1478  """
1479  return is_app_of(a, Z3_OP_IMPLIES)
1480 
def is_implies(a)
Definition: z3py.py:1470
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 2463 of file z3py.py.

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

2463 def is_int(a):
2464  """Return `True` if `a` is an integer expression.
2465 
2466  >>> x = Int('x')
2467  >>> is_int(x + 1)
2468  True
2469  >>> is_int(1)
2470  False
2471  >>> is_int(IntVal(1))
2472  True
2473  >>> y = Real('y')
2474  >>> is_int(y)
2475  False
2476  >>> is_int(y + 1)
2477  False
2478  """
2479  return is_arith(a) and a.is_int()
2480 
def is_arith(a)
Definition: z3py.py:2443
def is_int(a)
Definition: z3py.py:2463

◆ 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 2505 of file z3py.py.

2505 def is_int_value(a):
2506  """Return `True` if `a` is an integer value of sort Int.
2507 
2508  >>> is_int_value(IntVal(1))
2509  True
2510  >>> is_int_value(1)
2511  False
2512  >>> is_int_value(Int('x'))
2513  False
2514  >>> n = Int('x') + 1
2515  >>> n
2516  x + 1
2517  >>> n.arg(1)
2518  1
2519  >>> is_int_value(n.arg(1))
2520  True
2521  >>> is_int_value(RealVal("1/3"))
2522  False
2523  >>> is_int_value(RealVal(1))
2524  False
2525  """
2526  return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
2527 
def is_int_value(a)
Definition: z3py.py:2505
def is_arith(a)
Definition: z3py.py:2443

◆ 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 2677 of file z3py.py.

2677 def is_is_int(a):
2678  """Return `True` if `a` is an expression of the form IsInt(b).
2679 
2680  >>> x = Real('x')
2681  >>> is_is_int(IsInt(x))
2682  True
2683  >>> is_is_int(x)
2684  False
2685  """
2686  return is_app_of(a, Z3_OP_IS_INT)
2687 
def is_app_of(a, k)
Definition: z3py.py:1215
def is_is_int(a)
Definition: z3py.py:2677

◆ 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 4282 of file z3py.py.

4282 def is_K(a):
4283  """Return `True` if `a` is a Z3 constant array.
4284 
4285  >>> a = K(IntSort(), 10)
4286  >>> is_K(a)
4287  True
4288  >>> a = Array('a', IntSort(), IntSort())
4289  >>> is_K(a)
4290  False
4291  """
4292  return is_app_of(a, Z3_OP_CONST_ARRAY)
4293 
def is_K(a)
Definition: z3py.py:4282
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 2633 of file z3py.py.

2633 def is_le(a):
2634  """Return `True` if `a` is an expression of the form b <= c.
2635 
2636  >>> x, y = Ints('x y')
2637  >>> is_le(x <= y)
2638  True
2639  >>> is_le(x < y)
2640  False
2641  """
2642  return is_app_of(a, Z3_OP_LE)
2643 
def is_le(a)
Definition: z3py.py:2633
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 2644 of file z3py.py.

2644 def is_lt(a):
2645  """Return `True` if `a` is an expression of the form b < c.
2646 
2647  >>> x, y = Ints('x y')
2648  >>> is_lt(x < y)
2649  True
2650  >>> is_lt(x == y)
2651  False
2652  """
2653  return is_app_of(a, Z3_OP_LT)
2654 
def is_lt(a)
Definition: z3py.py:2644
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 4294 of file z3py.py.

4294 def is_map(a):
4295  """Return `True` if `a` is a Z3 map array expression.
4296 
4297  >>> f = Function('f', IntSort(), IntSort())
4298  >>> b = Array('b', IntSort(), IntSort())
4299  >>> a = Map(f, b)
4300  >>> a
4301  Map(f, b)
4302  >>> is_map(a)
4303  True
4304  >>> is_map(b)
4305  False
4306  """
4307  return is_app_of(a, Z3_OP_ARRAY_MAP)
4308 
def is_map(a)
Definition: z3py.py:4294
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 2622 of file z3py.py.

2622 def is_mod(a):
2623  """Return `True` if `a` is an expression of the form b % c.
2624 
2625  >>> x, y = Ints('x y')
2626  >>> is_mod(x % y)
2627  True
2628  >>> is_mod(x + y)
2629  False
2630  """
2631  return is_app_of(a, Z3_OP_MOD)
2632 
def is_mod(a)
Definition: z3py.py:2622
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 2573 of file z3py.py.

2573 def is_mul(a):
2574  """Return `True` if `a` is an expression of the form b * c.
2575 
2576  >>> x, y = Ints('x y')
2577  >>> is_mul(x * y)
2578  True
2579  >>> is_mul(x - y)
2580  False
2581  """
2582  return is_app_of(a, Z3_OP_MUL)
2583 
def is_app_of(a, k)
Definition: z3py.py:1215
def is_mul(a)
Definition: z3py.py:2573

◆ 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 1481 of file z3py.py.

1481 def is_not(a):
1482  """Return `True` if `a` is a Z3 not expression.
1483 
1484  >>> p = Bool('p')
1485  >>> is_not(p)
1486  False
1487  >>> is_not(Not(p))
1488  True
1489  """
1490  return is_app_of(a, Z3_OP_NOT)
1491 
def is_not(a)
Definition: z3py.py:1481
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 1459 of file z3py.py.

1459 def is_or(a):
1460  """Return `True` if `a` is a Z3 or expression.
1461 
1462  >>> p, q = Bools('p q')
1463  >>> is_or(Or(p, q))
1464  True
1465  >>> is_or(And(p, q))
1466  False
1467  """
1468  return is_app_of(a, Z3_OP_OR)
1469 
def is_or(a)
Definition: z3py.py:1459
def is_app_of(a, k)
Definition: z3py.py:1215

◆ is_pattern()

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

>>> 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 1734 of file z3py.py.

Referenced by MultiPattern().

1734 def is_pattern(a):
1735  """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1736 
1737  >>> f = Function('f', IntSort(), IntSort())
1738  >>> x = Int('x')
1739  >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1740  >>> q
1741  ForAll(x, f(x) == 0)
1742  >>> q.num_patterns()
1743  1
1744  >>> is_pattern(q.pattern(0))
1745  True
1746  >>> q.pattern(0)
1747  f(Var(0))
1748  """
1749  return isinstance(a, PatternRef)
1750 
def is_pattern(a)
Definition: z3py.py:1734

◆ 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 7960 of file z3py.py.

Referenced by eq().

7960 def is_probe(p):
7961  """Return `True` if `p` is a Z3 probe.
7962 
7963  >>> is_probe(Int('x'))
7964  False
7965  >>> is_probe(Probe('memory'))
7966  True
7967  """
7968  return isinstance(p, Probe)
7969 
def is_probe(p)
Definition: z3py.py:7960

◆ 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 1963 of file z3py.py.

Referenced by Exists().

1963 def is_quantifier(a):
1964  """Return `True` if `a` is a Z3 quantifier.
1965 
1966  >>> f = Function('f', IntSort(), IntSort())
1967  >>> x = Int('x')
1968  >>> q = ForAll(x, f(x) == 0)
1969  >>> is_quantifier(q)
1970  True
1971  >>> is_quantifier(f(x))
1972  False
1973  """
1974  return isinstance(a, QuantifierRef)
1975 
def is_quantifier(a)
Definition: z3py.py:1963

◆ 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 2528 of file z3py.py.

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

2528 def is_rational_value(a):
2529  """Return `True` if `a` is rational value of sort Real.
2530 
2531  >>> is_rational_value(RealVal(1))
2532  True
2533  >>> is_rational_value(RealVal("3/5"))
2534  True
2535  >>> is_rational_value(IntVal(1))
2536  False
2537  >>> is_rational_value(1)
2538  False
2539  >>> n = Real('x') + 1
2540  >>> n.arg(1)
2541  1
2542  >>> is_rational_value(n.arg(1))
2543  True
2544  >>> is_rational_value(Real('x'))
2545  False
2546  """
2547  return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2548 
def is_arith(a)
Definition: z3py.py:2443
def is_rational_value(a)
Definition: z3py.py:2528

◆ is_re()

def z3py.is_re (   s)

Definition at line 10173 of file z3py.py.

10173 def is_re(s):
10174  return isinstance(s, ReRef)
10175 
10176 
def is_re(s)
Definition: z3py.py:10173

◆ 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 2481 of file z3py.py.

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

2481 def is_real(a):
2482  """Return `True` if `a` is a real expression.
2483 
2484  >>> x = Int('x')
2485  >>> is_real(x + 1)
2486  False
2487  >>> y = Real('y')
2488  >>> is_real(y)
2489  True
2490  >>> is_real(y + 1)
2491  True
2492  >>> is_real(1)
2493  False
2494  >>> is_real(RealVal(1))
2495  True
2496  """
2497  return is_arith(a) and a.is_real()
2498 
def is_real(a)
Definition: z3py.py:2481
def is_arith(a)
Definition: z3py.py:2443

◆ 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 4492 of file z3py.py.

4492 def is_select(a):
4493  """Return `True` if `a` is a Z3 array select application.
4494 
4495  >>> a = Array('a', IntSort(), IntSort())
4496  >>> is_select(a)
4497  False
4498  >>> i = Int('i')
4499  >>> is_select(a[i])
4500  True
4501  """
4502  return is_app_of(a, Z3_OP_SELECT)
4503 
def is_select(a)
Definition: z3py.py:4492
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 9933 of file z3py.py.

9933 def is_seq(a):
9934  """Return `True` if `a` is a Z3 sequence expression.
9935  >>> print (is_seq(Unit(IntVal(0))))
9936  True
9937  >>> print (is_seq(StringVal("abc")))
9938  True
9939  """
9940  return isinstance(a, SeqRef)
9941 
def is_seq(a)
Definition: z3py.py:9933

◆ 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 579 of file z3py.py.

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

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

◆ 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 4504 of file z3py.py.

4504 def is_store(a):
4505  """Return `True` if `a` is a Z3 array store application.
4506 
4507  >>> a = Array('a', IntSort(), IntSort())
4508  >>> is_store(a)
4509  False
4510  >>> is_store(Store(a, 0, 1))
4511  True
4512  """
4513  return is_app_of(a, Z3_OP_STORE)
4514 
def is_store(a)
Definition: z3py.py:4504
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 9942 of file z3py.py.

9942 def is_string(a):
9943  """Return `True` if `a` is a Z3 string expression.
9944  >>> print (is_string(StringVal("ab")))
9945  True
9946  """
9947  return isinstance(a, SeqRef) and a.is_string()
9948 
def is_string(a)
Definition: z3py.py:9942

◆ 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 9949 of file z3py.py.

9949 def is_string_value(a):
9950  """return 'True' if 'a' is a Z3 string constant expression.
9951  >>> print (is_string_value(StringVal("a")))
9952  True
9953  >>> print (is_string_value(StringVal("a") + StringVal("b")))
9954  False
9955  """
9956  return isinstance(a, SeqRef) and a.is_string_value()
9957 
9958 
def is_string_value(a)
Definition: z3py.py:9949

◆ 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 2584 of file z3py.py.

2584 def is_sub(a):
2585  """Return `True` if `a` is an expression of the form b - c.
2586 
2587  >>> x, y = Ints('x y')
2588  >>> is_sub(x - y)
2589  True
2590  >>> is_sub(x + y)
2591  False
2592  """
2593  return is_app_of(a, Z3_OP_SUB)
2594 
def is_app_of(a, k)
Definition: z3py.py:1215
def is_sub(a)
Definition: z3py.py:2584

◆ 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 2702 of file z3py.py.

2702 def is_to_int(a):
2703  """Return `True` if `a` is an expression of the form ToInt(b).
2704 
2705  >>> x = Real('x')
2706  >>> n = ToInt(x)
2707  >>> n
2708  ToInt(x)
2709  >>> is_to_int(n)
2710  True
2711  >>> is_to_int(x)
2712  False
2713  """
2714  return is_app_of(a, Z3_OP_TO_INT)
2715 
def is_app_of(a, k)
Definition: z3py.py:1215
def is_to_int(a)
Definition: z3py.py:2702

◆ 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 2688 of file z3py.py.

2688 def is_to_real(a):
2689  """Return `True` if `a` is an expression of the form ToReal(b).
2690 
2691  >>> x = Int('x')
2692  >>> n = ToReal(x)
2693  >>> n
2694  ToReal(x)
2695  >>> is_to_real(n)
2696  True
2697  >>> is_to_real(x)
2698  False
2699  """
2700  return is_app_of(a, Z3_OP_TO_REAL)
2701 
def is_to_real(a)
Definition: z3py.py:2688
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 1418 of file z3py.py.

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

1418 def is_true(a):
1419  """Return `True` if `a` is the Z3 true expression.
1420 
1421  >>> p = Bool('p')
1422  >>> is_true(p)
1423  False
1424  >>> is_true(simplify(p == p))
1425  True
1426  >>> x = Real('x')
1427  >>> is_true(x == 0)
1428  False
1429  >>> # True is a Python Boolean expression
1430  >>> is_true(True)
1431  False
1432  """
1433  return is_app_of(a, Z3_OP_TRUE)
1434 
def is_true(a)
Definition: z3py.py:1418
def is_app_of(a, k)
Definition: z3py.py:1215

◆ 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 1159 of file z3py.py.

Referenced by get_var_index().

1159 def is_var(a):
1160  """Return `True` if `a` is variable.
1161 
1162  Z3 uses de-Bruijn indices for representing bound variables in
1163  quantifiers.
1164 
1165  >>> x = Int('x')
1166  >>> is_var(x)
1167  False
1168  >>> is_const(x)
1169  True
1170  >>> f = Function('f', IntSort(), IntSort())
1171  >>> # Z3 replaces x with bound variables when ForAll is executed.
1172  >>> q = ForAll(x, f(x) == x)
1173  >>> b = q.body()
1174  >>> b
1175  f(Var(0)) == Var(0)
1176  >>> b.arg(1)
1177  Var(0)
1178  >>> is_var(b.arg(1))
1179  True
1180  """
1181  return is_expr(a) and _ast_kind(a.ctx, a) == Z3_VAR_AST
1182 
def is_expr(a)
Definition: z3py.py:1094
def is_var(a)
Definition: z3py.py:1159

◆ 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 3110 of file z3py.py.

Referenced by is_is_int().

3110 def IsInt(a):
3111  """ Return the Z3 predicate IsInt(a).
3112 
3113  >>> x = Real('x')
3114  >>> IsInt(x + "1/2")
3115  IsInt(x + 1/2)
3116  >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3117  [x = 1/2]
3118  >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3119  no solution
3120  """
3121  if __debug__:
3122  _z3_assert(a.is_real(), "Z3 real expression expected.")
3123  ctx = a.ctx
3124  return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
3125 
def IsInt(a)
Definition: z3py.py:3110
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.

◆ IsMember()

def z3py.IsMember (   e,
  s 
)
Check if e is a member of set s
>>> a = Const('a', SetSort(IntSort()))
>>> IsMember(1, a)
a[1]

Definition at line 4605 of file z3py.py.

4605 def IsMember(e, s):
4606  """ Check if e is a member of set s
4607  >>> a = Const('a', SetSort(IntSort()))
4608  >>> IsMember(1, a)
4609  a[1]
4610  """
4611  ctx = _ctx_from_ast_arg_list([s,e])
4612  e = _py2expr(e, ctx)
4613  return BoolRef(Z3_mk_set_member(ctx.ref(), e.as_ast(), s.as_ast()), ctx)
4614 
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
def IsMember(e, s)
Definition: z3py.py:4605

◆ IsSubset()

def z3py.IsSubset (   a,
  b 
)
Check if a is a subset of b
>>> a = Const('a', SetSort(IntSort()))
>>> b = Const('b', SetSort(IntSort()))
>>> IsSubset(a, b)
subset(a, b)

Definition at line 4615 of file z3py.py.

4615 def IsSubset(a, b):
4616  """ Check if a is a subset of b
4617  >>> a = Const('a', SetSort(IntSort()))
4618  >>> b = Const('b', SetSort(IntSort()))
4619  >>> IsSubset(a, b)
4620  subset(a, b)
4621  """
4622  ctx = _ctx_from_ast_arg_list([a, b])
4623  return BoolRef(Z3_mk_set_subset(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4624 
4625 
def IsSubset(a, b)
Definition: z3py.py:4615
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.

◆ 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 4464 of file z3py.py.

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

4464 def K(dom, v):
4465  """Return a Z3 constant array expression.
4466 
4467  >>> a = K(IntSort(), 10)
4468  >>> a
4469  K(Int, 10)
4470  >>> a.sort()
4471  Array(Int, Int)
4472  >>> i = Int('i')
4473  >>> a[i]
4474  K(Int, 10)[i]
4475  >>> simplify(a[i])
4476  10
4477  """
4478  if __debug__:
4479  _z3_assert(is_sort(dom), "Z3 sort expected")
4480  ctx = dom.ctx
4481  if not is_expr(v):
4482  v = _py2expr(v, ctx)
4483  return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
4484 
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:579
def K(dom, v)
Definition: z3py.py:4464
def is_expr(a)
Definition: z3py.py:1094

◆ Lambda()

def z3py.Lambda (   vs,
  body 
)
Create a Z3 lambda expression.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> mem0 = Array('mem0', IntSort(), IntSort())
>>> lo, hi, e, i = Ints('lo hi e i')
>>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
>>> mem1
Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))

Definition at line 2047 of file z3py.py.

Referenced by QuantifierRef.is_lambda().

2047 def Lambda(vs, body):
2048  """Create a Z3 lambda expression.
2049 
2050  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2051  >>> mem0 = Array('mem0', IntSort(), IntSort())
2052  >>> lo, hi, e, i = Ints('lo hi e i')
2053  >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2054  >>> mem1
2055  Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2056  """
2057  ctx = body.ctx
2058  if is_app(vs):
2059  vs = [vs]
2060  num_vars = len(vs)
2061  _vs = (Ast * num_vars)()
2062  for i in range(num_vars):
2063 
2064  _vs[i] = vs[i].as_ast()
2065  return QuantifierRef(Z3_mk_lambda_const(ctx.ref(), num_vars, _vs, body.as_ast()), ctx)
2066 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def is_app(a)
Definition: z3py.py:1116
Z3_ast Z3_API Z3_mk_lambda_const(Z3_context c, unsigned num_bound, Z3_app const bound[], Z3_ast body)
Create a lambda expression using a list of constants that form the set of bound variables.
def Lambda(vs, body)
Definition: z3py.py:2047

◆ Length()

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

Definition at line 10107 of file z3py.py.

10107 def Length(s):
10108  """Obtain the length of a sequence 's'
10109  >>> l = Length(StringVal("abc"))
10110  >>> simplify(l)
10111  3
10112  """
10113  s = _coerce_seq(s)
10114  return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
10115 
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:10107

◆ 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 10249 of file z3py.py.

10249 def Loop(re, lo, hi=0):
10250  """Create the regular expression accepting between a lower and upper bound repetitions
10251  >>> re = Loop(Re("a"), 1, 3)
10252  >>> print(simplify(InRe("aa", re)))
10253  True
10254  >>> print(simplify(InRe("aaaa", re)))
10255  False
10256  >>> print(simplify(InRe("", re)))
10257  False
10258  """
10259  return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
10260 
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:10249

◆ 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 3979 of file z3py.py.

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

3979 def LShR(a, b):
3980  """Create the Z3 expression logical right shift.
3981 
3982  Use the operator >> for the arithmetical right shift.
3983 
3984  >>> x, y = BitVecs('x y', 32)
3985  >>> LShR(x, y)
3986  LShR(x, y)
3987  >>> (x >> y).sexpr()
3988  '(bvashr x y)'
3989  >>> LShR(x, y).sexpr()
3990  '(bvlshr x y)'
3991  >>> BitVecVal(4, 3)
3992  4
3993  >>> BitVecVal(4, 3).as_signed_long()
3994  -4
3995  >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3996  -2
3997  >>> simplify(BitVecVal(4, 3) >> 1)
3998  6
3999  >>> simplify(LShR(BitVecVal(4, 3), 1))
4000  2
4001  >>> simplify(BitVecVal(2, 3) >> 1)
4002  1
4003  >>> simplify(LShR(BitVecVal(2, 3), 1))
4004  1
4005  """
4006  _check_bv_args(a, b)
4007  a, b = _coerce_exprs(a, b)
4008  return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4009 
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:3979

◆ 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 207 of file z3py.py.

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

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

◆ 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 4442 of file z3py.py.

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

4442 def Map(f, *args):
4443  """Return a Z3 map array expression.
4444 
4445  >>> f = Function('f', IntSort(), IntSort(), IntSort())
4446  >>> a1 = Array('a1', IntSort(), IntSort())
4447  >>> a2 = Array('a2', IntSort(), IntSort())
4448  >>> b = Map(f, a1, a2)
4449  >>> b
4450  Map(f, a1, a2)
4451  >>> prove(b[0] == f(a1[0], a2[0]))
4452  proved
4453  """
4454  args = _get_args(args)
4455  if __debug__:
4456  _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
4457  _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
4458  _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
4459  _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
4460  _args, sz = _to_ast_array(args)
4461  ctx = f.ctx
4462  return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
4463 
def is_array(a)
Definition: z3py.py:4257
def Map(f, args)
Definition: z3py.py:4442
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:766

◆ Model()

def z3py.Model (   ctx = None)

Definition at line 6167 of file z3py.py.

Referenced by Goal.convertModel(), Optimize.getModel(), and Solver.getModel().

6167 def Model(ctx = None):
6168  ctx = _get_ctx(ctx)
6169  return ModelRef(Z3_mk_model(ctx.ref()), ctx)
6170 
def Model(ctx=None)
Definition: z3py.py:6167
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.

◆ MultiPattern()

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

>>> 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 1751 of file z3py.py.

1751 def MultiPattern(*args):
1752  """Create a Z3 multi-pattern using the given expressions `*args`
1753 
1754  >>> f = Function('f', IntSort(), IntSort())
1755  >>> g = Function('g', IntSort(), IntSort())
1756  >>> x = Int('x')
1757  >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
1758  >>> q
1759  ForAll(x, f(x) != g(x))
1760  >>> q.num_patterns()
1761  1
1762  >>> is_pattern(q.pattern(0))
1763  True
1764  >>> q.pattern(0)
1765  MultiPattern(f(Var(0)), g(Var(0)))
1766  """
1767  if __debug__:
1768  _z3_assert(len(args) > 0, "At least one argument expected")
1769  _z3_assert(all([ is_expr(a) for a in args ]), "Z3 expressions expected")
1770  ctx = args[0].ctx
1771  args, sz = _to_ast_array(args)
1772  return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
1773 
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:1751
def is_expr(a)
Definition: z3py.py:1094

◆ 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 1630 of file z3py.py.

Referenced by Solver.consequences(), Goal.convert_model(), fpNEQ(), Implies(), prove(), and Xor().

1630 def Not(a, ctx=None):
1631  """Create a Z3 not expression or probe.
1632 
1633  >>> p = Bool('p')
1634  >>> Not(Not(p))
1635  Not(Not(p))
1636  >>> simplify(Not(Not(p)))
1637  p
1638  """
1639  ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1640  if is_probe(a):
1641  # Not is also used to build probes
1642  return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1643  else:
1644  s = BoolSort(ctx)
1645  a = s.cast(a)
1646  return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1647 
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:1630
def is_probe(p)
Definition: z3py.py:7960
def BoolSort(ctx=None)
Definition: z3py.py:1512

◆ open_log()

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

Definition at line 97 of file z3py.py.

97 def open_log(fname):
98  """Log interaction to a file. This function must be invoked immediately after init(). """
99  Z3_open_log(fname)
100 
Z3_bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.
def open_log(fname)
Definition: z3py.py:97

◆ 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 10221 of file z3py.py.

10221 def Option(re):
10222  """Create the regular expression that optionally accepts the argument.
10223  >>> re = Option(Re("a"))
10224  >>> print(simplify(InRe("a", re)))
10225  True
10226  >>> print(simplify(InRe("", re)))
10227  True
10228  >>> print(simplify(InRe("aa", re)))
10229  False
10230  """
10231  return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
10232 
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:10221

◆ 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 1688 of file z3py.py.

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

1688 def Or(*args):
1689  """Create a Z3 or-expression or or-probe.
1690 
1691  >>> p, q, r = Bools('p q r')
1692  >>> Or(p, q, r)
1693  Or(p, q, r)
1694  >>> P = BoolVector('p', 5)
1695  >>> Or(P)
1696  Or(p__0, p__1, p__2, p__3, p__4)
1697  """
1698  last_arg = None
1699  if len(args) > 0:
1700  last_arg = args[len(args)-1]
1701  if isinstance(last_arg, Context):
1702  ctx = args[len(args)-1]
1703  args = args[:len(args)-1]
1704  else:
1705  ctx = main_ctx()
1706  args = _get_args(args)
1707  ctx_args = _ctx_from_ast_arg_list(args, ctx)
1708  if __debug__:
1709  _z3_assert(ctx_args is None or ctx_args == ctx, "context mismatch")
1710  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1711  if _has_probe(args):
1712  return _probe_or(args, ctx)
1713  else:
1714  args = _coerce_expr_list(args, ctx)
1715  _args, sz = _to_ast_array(args)
1716  return BoolRef(Z3_mk_or(ctx.ref(), sz, _args), ctx)
1717 
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:207
def Or(args)
Definition: z3py.py:1688

◆ 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 7676 of file z3py.py.

7676 def OrElse(*ts, **ks):
7677  """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
7678 
7679  >>> x = Int('x')
7680  >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
7681  >>> # Tactic split-clause fails if there is no clause in the given goal.
7682  >>> t(x == 0)
7683  [[x == 0]]
7684  >>> t(Or(x == 0, x == 1))
7685  [[x == 0], [x == 1]]
7686  """
7687  if __debug__:
7688  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7689  ctx = ks.get('ctx', None)
7690  num = len(ts)
7691  r = ts[0]
7692  for i in range(num - 1):
7693  r = _or_else(r, ts[i+1], ctx)
7694  return r
7695 
def OrElse(ts, ks)
Definition: z3py.py:7676
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244

◆ ParAndThen()

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

Definition at line 7728 of file z3py.py.

7728 def ParAndThen(t1, t2, ctx=None):
7729  """Alias for ParThen(t1, t2, ctx)."""
7730  return ParThen(t1, t2, ctx)
7731 
def ParAndThen(t1, t2, ctx=None)
Definition: z3py.py:7728
def ParThen(t1, t2, ctx=None)
Definition: z3py.py:7714

◆ 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 7696 of file z3py.py.

7696 def ParOr(*ts, **ks):
7697  """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
7698 
7699  >>> x = Int('x')
7700  >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
7701  >>> t(x + 1 == 2)
7702  [[x == 1]]
7703  """
7704  if __debug__:
7705  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7706  ctx = _get_ctx(ks.get('ctx', None))
7707  ts = [ _to_tactic(t, ctx) for t in ts ]
7708  sz = len(ts)
7709  _args = (TacticObj * sz)()
7710  for i in range(sz):
7711  _args[i] = ts[i].tactic
7712  return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
7713 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
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:7696

◆ 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 8495 of file z3py.py.

8495 def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
8496  """Parse a file in SMT 2.0 format using the given sorts and decls.
8497 
8498  This function is similar to parse_smt2_string().
8499  """
8500  ctx = _get_ctx(ctx)
8501  ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8502  dsz, dnames, ddecls = _dict2darray(decls, ctx)
8503  return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
8504 
8505 
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
Definition: z3py.py:8495
Z3_ast_vector 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.

◆ 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))')
[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 8475 of file z3py.py.

Referenced by parse_smt2_file().

8475 def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
8476  """Parse a string in SMT 2.0 format using the given sorts and decls.
8477 
8478  The arguments sorts and decls are Python dictionaries used to initialize
8479  the symbol table used for the SMT 2.0 parser.
8480 
8481  >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
8482  [x > 0, x < 10]
8483  >>> x, y = Ints('x y')
8484  >>> f = Function('f', IntSort(), IntSort())
8485  >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
8486  [x + f(y) > 0]
8487  >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() }) [a > 0]
8488  """
8489  ctx = _get_ctx(ctx)
8490  ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8491  dsz, dnames, ddecls = _dict2darray(decls, ctx)
8492  return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
8493 
8494 
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
Definition: z3py.py:8475

◆ 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 7714 of file z3py.py.

Referenced by ParAndThen().

7714 def ParThen(t1, t2, ctx=None):
7715  """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.
7716 
7717  >>> x, y = Ints('x y')
7718  >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
7719  >>> t(And(Or(x == 1, x == 2), y == x + 1))
7720  [[x == 1, y == 2], [x == 2, y == 3]]
7721  """
7722  t1 = _to_tactic(t1, ctx)
7723  t2 = _to_tactic(t2, ctx)
7724  if __debug__:
7725  _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
7726  return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
7727 
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:7714

◆ 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 8282 of file z3py.py.

8282 def PbEq(args, k, ctx = None):
8283  """Create a Pseudo-Boolean inequality k constraint.
8284 
8285  >>> a, b, c = Bools('a b c')
8286  >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
8287  """
8288  _z3_check_cint_overflow(k, "k")
8289  ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8290  return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
8291 
8292 
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:8282

◆ 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 8272 of file z3py.py.

8272 def PbGe(args, k):
8273  """Create a Pseudo-Boolean inequality k constraint.
8274 
8275  >>> a, b, c = Bools('a b c')
8276  >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
8277  """
8278  _z3_check_cint_overflow(k, "k")
8279  ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8280  return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
8281 
def PbGe(args, k)
Definition: z3py.py:8272
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 8262 of file z3py.py.

8262 def PbLe(args, k):
8263  """Create a Pseudo-Boolean inequality k constraint.
8264 
8265  >>> a, b, c = Bools('a b c')
8266  >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
8267  """
8268  _z3_check_cint_overflow(k, "k")
8269  ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8270  return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
8271 
def PbLe(args, k)
Definition: z3py.py:8262
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 10209 of file z3py.py.

10209 def Plus(re):
10210  """Create the regular expression accepting one or more repetitions of argument.
10211  >>> re = Plus(Re("a"))
10212  >>> print(simplify(InRe("aa", re)))
10213  True
10214  >>> print(simplify(InRe("ab", re)))
10215  False
10216  >>> print(simplify(InRe("", re)))
10217  False
10218  """
10219  return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
10220 
def Plus(re)
Definition: z3py.py:10209
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 10026 of file z3py.py.

10026 def PrefixOf(a, b):
10027  """Check if 'a' is a prefix of 'b'
10028  >>> s1 = PrefixOf("ab", "abc")
10029  >>> simplify(s1)
10030  True
10031  >>> s2 = PrefixOf("bc", "abc")
10032  >>> simplify(s2)
10033  False
10034  """
10035  ctx = _get_ctx2(a, b)
10036  a = _coerce_seq(a, ctx)
10037  b = _coerce_seq(b, ctx)
10038  return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
10039 
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:10026

◆ 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 7986 of file z3py.py.

Referenced by describe_probes().

7986 def probe_description(name, ctx=None):
7987  """Return a short description for the probe named `name`.
7988 
7989  >>> d = probe_description('memory')
7990  """
7991  ctx = _get_ctx(ctx)
7992  return Z3_probe_get_descr(ctx.ref(), name)
7993 
def probe_description(name, ctx=None)
Definition: z3py.py:7986
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 7976 of file z3py.py.

Referenced by describe_probes().

7976 def probes(ctx=None):
7977  """Return a list of all available probes in Z3.
7978 
7979  >>> l = probes()
7980  >>> l.count('memory') == 1
7981  True
7982  """
7983  ctx = _get_ctx(ctx)
7984  return [ Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref())) ]
7985 
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:3244
def probes(ctx=None)
Definition: z3py.py:7976
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 8184 of file z3py.py.

Referenced by BitVecs().

8184 def Product(*args):
8185  """Create the product of the Z3 expressions.
8186 
8187  >>> a, b, c = Ints('a b c')
8188  >>> Product(a, b, c)
8189  a*b*c
8190  >>> Product([a, b, c])
8191  a*b*c
8192  >>> A = IntVector('a', 5)
8193  >>> Product(A)
8194  a__0*a__1*a__2*a__3*a__4
8195  """
8196  args = _get_args(args)
8197  if len(args) == 0:
8198  return 1
8199  ctx = _ctx_from_ast_arg_list(args)
8200  if ctx is None:
8201  return _reduce(lambda a, b: a * b, args, 1)
8202  args = _coerce_expr_list(args, ctx)
8203  if is_bv(args[0]):
8204  return _reduce(lambda a, b: a * b, args, 1)
8205  else:
8206  _args, sz = _to_ast_array(args)
8207  return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
8208 
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:8184
def is_bv(a)
Definition: z3py.py:3649

◆ 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 8350 of file z3py.py.

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

8350 def prove(claim, **keywords):
8351  """Try to prove the given claim.
8352 
8353  This is a simple function for creating demonstrations. It tries to prove
8354  `claim` by showing the negation is unsatisfiable.
8355 
8356  >>> p, q = Bools('p q')
8357  >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
8358  proved
8359  """
8360  if __debug__:
8361  _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
8362  s = Solver()
8363  s.set(**keywords)
8364  s.add(Not(claim))
8365  if keywords.get('show', False):
8366  print(s)
8367  r = s.check()
8368  if r == unsat:
8369  print("proved")
8370  elif r == unknown:
8371  print("failed to prove")
8372  print(s.model())
8373  else:
8374  print("counterexample")
8375  print(s.model())
8376 
def prove(claim, keywords)
Definition: z3py.py:8350
def Not(a, ctx=None)
Definition: z3py.py:1630
def is_bool(a)
Definition: z3py.py:1401

◆ 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 2964 of file z3py.py.

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

2964 def Q(a, b, ctx=None):
2965  """Return a Z3 rational a/b.
2966 
2967  If `ctx=None`, then the global context is used.
2968 
2969  >>> Q(3,5)
2970  3/5
2971  >>> Q(3,5).sort()
2972  Real
2973  """
2974  return simplify(RatVal(a, b))
2975 
def simplify(a, arguments, keywords)
Utils.
Definition: z3py.py:8080
def RatVal(a, b, ctx=None)
Definition: z3py.py:2949
def Q(a, b, ctx=None)
Definition: z3py.py:2964

◆ 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 2949 of file z3py.py.

2949 def RatVal(a, b, ctx=None):
2950  """Return a Z3 rational a/b.
2951 
2952  If `ctx=None`, then the global context is used.
2953 
2954  >>> RatVal(3,5)
2955  3/5
2956  >>> RatVal(3,5).sort()
2957  Real
2958  """
2959  if __debug__:
2960  _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
2961  _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
2962  return simplify(RealVal(a, ctx)/RealVal(b, ctx))
2963 
def simplify(a, arguments, keywords)
Utils.
Definition: z3py.py:8080
def RatVal(a, b, ctx=None)
Definition: z3py.py:2949
def RealVal(val, ctx=None)
Definition: z3py.py:2931

◆ 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 10139 of file z3py.py.

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

10139 def Re(s, ctx=None):
10140  """The regular expression that accepts sequence 's'
10141  >>> s1 = Re("ab")
10142  >>> s2 = Re(StringVal("ab"))
10143  >>> s3 = Re(Unit(BoolVal(True)))
10144  """
10145  s = _coerce_seq(s, ctx)
10146  return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
10147 
10148 
10149 
10150 
def Re(s, ctx=None)
Definition: z3py.py:10139
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 3024 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().

3024 def Real(name, ctx=None):
3025  """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3026 
3027  >>> x = Real('x')
3028  >>> is_real(x)
3029  True
3030  >>> is_real(x + 1)
3031  True
3032  """
3033  ctx = _get_ctx(ctx)
3034  return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
3035 
def RealSort(ctx=None)
Definition: z3py.py:2889
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:105
def Real(name, ctx=None)
Definition: z3py.py:3024

◆ 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 3036 of file z3py.py.

Referenced by is_div().

3036 def Reals(names, ctx=None):
3037  """Return a tuple of real constants.
3038 
3039  >>> x, y, z = Reals('x y z')
3040  >>> Sum(x, y, z)
3041  x + y + z
3042  >>> Sum(x, y, z).sort()
3043  Real
3044  """
3045  ctx = _get_ctx(ctx)
3046  if isinstance(names, str):
3047  names = names.split(" ")
3048  return [Real(name, ctx) for name in names]
3049 
def Real(name, ctx=None)
Definition: z3py.py:3024
def Reals(names, ctx=None)
Definition: z3py.py:3036

◆ 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 2889 of file z3py.py.

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

2889 def RealSort(ctx=None):
2890  """Return the real sort in the given context. If `ctx=None`, then the global context is used.
2891 
2892  >>> RealSort()
2893  Real
2894  >>> x = Const('x', RealSort())
2895  >>> is_real(x)
2896  True
2897  >>> is_int(x)
2898  False
2899  >>> x.sort() == RealSort()
2900  True
2901  """
2902  ctx = _get_ctx(ctx)
2903  return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
2904 
def RealSort(ctx=None)
Definition: z3py.py:2889
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 2931 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().

2931 def RealVal(val, ctx=None):
2932  """Return a Z3 real value.
2933 
2934  `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
2935  If `ctx=None`, then the global context is used.
2936 
2937  >>> RealVal(1)
2938  1
2939  >>> RealVal(1).sort()
2940  Real
2941  >>> RealVal("3/5")
2942  3/5
2943  >>> RealVal("1.5")
2944  3/2
2945  """
2946  ctx = _get_ctx(ctx)
2947  return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), RealSort(ctx).ast), ctx)
2948 
def RealSort(ctx=None)
Definition: z3py.py:2889
def RealVal(val, ctx=None)
Definition: z3py.py:2931
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 1322 of file z3py.py.

Referenced by RealVarVector().

1322 def RealVar(idx, ctx=None):
1323  """
1324  Create a real free variable. Free variables are used to create quantified formulas.
1325  They are also used to create polynomials.
1326 
1327  >>> RealVar(0)
1328  Var(0)
1329  """
1330  return Var(idx, RealSort(ctx))
1331 
def RealSort(ctx=None)
Definition: z3py.py:2889
def Var(idx, s)
Definition: z3py.py:1310
def RealVar(idx, ctx=None)
Definition: z3py.py:1322

◆ 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 1332 of file z3py.py.

1332 def RealVarVector(n, ctx=None):
1333  """
1334  Create a list of Real free variables.
1335  The variables have ids: 0, 1, ..., n-1
1336 
1337  >>> x0, x1, x2, x3 = RealVarVector(4)
1338  >>> x2
1339  Var(2)
1340  """
1341  return [ RealVar(i, ctx) for i in range(n) ]
1342 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def RealVarVector(n, ctx=None)
Definition: z3py.py:1332
def RealVar(idx, ctx=None)
Definition: z3py.py:1322

◆ 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 3050 of file z3py.py.

3050 def RealVector(prefix, sz, ctx=None):
3051  """Return a list of real constants of size `sz`.
3052 
3053  >>> X = RealVector('x', 3)
3054  >>> X
3055  [x__0, x__1, x__2]
3056  >>> Sum(X)
3057  x__0 + x__1 + x__2
3058  >>> Sum(X).sort()
3059  Real
3060  """
3061  return [ Real('%s__%s' % (prefix, i)) for i in range(sz) ]
3062 
def RealVector(prefix, sz, ctx=None)
Definition: z3py.py:3050
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def Real(name, ctx=None)
Definition: z3py.py:3024

◆ RecAddDefinition()

def z3py.RecAddDefinition (   f,
  args,
  body 
)
Set the body of a recursive function.
   Recursive definitions are only unfolded during search.
>>> ctx = Context()
>>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
>>> n = Int('n', ctx)
>>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
>>> simplify(fac(5))
fac(5)
>>> s = Solver(ctx=ctx)
>>> s.add(fac(n) < 3)
>>> s.check()
sat
>>> s.model().eval(fac(5))
120

Definition at line 820 of file z3py.py.

820 def RecAddDefinition(f, args, body):
821  """Set the body of a recursive function.
822  Recursive definitions are only unfolded during search.
823  >>> ctx = Context()
824  >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
825  >>> n = Int('n', ctx)
826  >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
827  >>> simplify(fac(5))
828  fac(5)
829  >>> s = Solver(ctx=ctx)
830  >>> s.add(fac(n) < 3)
831  >>> s.check()
832  sat
833  >>> s.model().eval(fac(5))
834  120
835  """
836  if is_app(args):
837  args = [args]
838  ctx = body.ctx
839  args = _get_args(args)
840  n = len(args)
841  _args = (Ast * n)()
842  for i in range(n):
843  _args[i] = args[i].ast
844  Z3_add_rec_def(ctx.ref(), f.ast, n, _args, body.ast)
845 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def is_app(a)
Definition: z3py.py:1116
def RecAddDefinition(f, args, body)
Definition: z3py.py:820
void Z3_API Z3_add_rec_def(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast args[], Z3_ast body)
Define the body of a recursive function.

◆ RecFunction()

def z3py.RecFunction (   name,
  sig 
)
Create a new Z3 recursive with the given sorts.

Definition at line 803 of file z3py.py.

803 def RecFunction(name, *sig):
804  """Create a new Z3 recursive with the given sorts."""
805  sig = _get_args(sig)
806  if __debug__:
807  _z3_assert(len(sig) > 0, "At least two arguments expected")
808  arity = len(sig) - 1
809  rng = sig[arity]
810  if __debug__:
811  _z3_assert(is_sort(rng), "Z3 sort expected")
812  dom = (Sort * arity)()
813  for i in range(arity):
814  if __debug__:
815  _z3_assert(is_sort(sig[i]), "Z3 sort expected")
816  dom[i] = sig[i].ast
817  ctx = rng.ctx
818  return FuncDeclRef(Z3_mk_rec_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
819 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def to_symbol(s, ctx=None)
Definition: z3py.py:105
def RecFunction(name, sig)
Definition: z3py.py:803
def is_sort(s)
Definition: z3py.py:579
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a recursive function.

◆ 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 7758 of file z3py.py.

7758 def Repeat(t, max=4294967295, ctx=None):
7759  """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.
7760 
7761  >>> x, y = Ints('x y')
7762  >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
7763  >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
7764  >>> r = t(c)
7765  >>> for subgoal in r: print(subgoal)
7766  [x == 0, y == 0, x > y]
7767  [x == 0, y == 1, x > y]
7768  [x == 1, y == 0, x > y]
7769  [x == 1, y == 1, x > y]
7770  >>> t = Then(t, Tactic('propagate-values'))
7771  >>> t(c)
7772  [[x == 1, y == 0]]
7773  """
7774  t = _to_tactic(t, ctx)
7775  return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
7776 
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:7758

◆ 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 4096 of file z3py.py.

4096 def RepeatBitVec(n, a):
4097  """Return an expression representing `n` copies of `a`.
4098 
4099  >>> x = BitVec('x', 8)
4100  >>> n = RepeatBitVec(4, x)
4101  >>> n
4102  RepeatBitVec(4, x)
4103  >>> n.size()
4104  32
4105  >>> v0 = BitVecVal(10, 4)
4106  >>> print("%.x" % v0.as_long())
4107  a
4108  >>> v = simplify(RepeatBitVec(4, v0))
4109  >>> v.size()
4110  16
4111  >>> print("%.x" % v.as_long())
4112  aaaa
4113  """
4114  if __debug__:
4115  _z3_assert(_is_int(n), "First argument must be an integer")
4116  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
4117  return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
4118 
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:3649
def RepeatBitVec(n, a)
Definition: z3py.py:4096

◆ 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 10073 of file z3py.py.

10073 def Replace(s, src, dst):
10074  """Replace the first occurrence of 'src' by 'dst' in 's'
10075  >>> r = Replace("aaa", "a", "b")
10076  >>> simplify(r)
10077  "baa"
10078  """
10079  ctx = _get_ctx2(dst, s)
10080  if ctx is None and is_expr(src):
10081  ctx = src.ctx
10082  src = _coerce_seq(src, ctx)
10083  dst = _coerce_seq(dst, ctx)
10084  s = _coerce_seq(s, ctx)
10085  return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
10086 
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:10073
def is_expr(a)
Definition: z3py.py:1094

◆ reset_params()

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

Definition at line 256 of file z3py.py.

256 def reset_params():
257  """Reset all global (or module) parameters.
258  """
260 
def reset_params()
Definition: z3py.py:256
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 10157 of file z3py.py.

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

10157 def ReSort(s):
10158  if is_ast(s):
10159  return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
10160  if s is None or isinstance(s, Context):
10161  ctx = _get_ctx(s)
10162  return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
10163  raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
10164 
10165 
def ReSort(s)
Definition: z3py.py:10157
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:396
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 8885 of file z3py.py.

8885 def RNA (ctx=None):
8886  ctx = _get_ctx(ctx)
8887  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
8888 
def RNA(ctx=None)
Definition: z3py.py:8885
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 8877 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().

8877 def RNE (ctx=None):
8878  ctx = _get_ctx(ctx)
8879  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
8880 
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:8877

◆ 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 4010 of file z3py.py.

4010 def RotateLeft(a, b):
4011  """Return an expression representing `a` rotated to the left `b` times.
4012 
4013  >>> a, b = BitVecs('a b', 16)
4014  >>> RotateLeft(a, b)
4015  RotateLeft(a, b)
4016  >>> simplify(RotateLeft(a, 0))
4017  a
4018  >>> simplify(RotateLeft(a, 16))
4019  a
4020  """
4021  _check_bv_args(a, b)
4022  a, b = _coerce_exprs(a, b)
4023  return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4024 
def RotateLeft(a, b)
Definition: z3py.py:4010
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 4025 of file z3py.py.

4025 def RotateRight(a, b):
4026  """Return an expression representing `a` rotated to the right `b` times.
4027 
4028  >>> a, b = BitVecs('a b', 16)
4029  >>> RotateRight(a, b)
4030  RotateRight(a, b)
4031  >>> simplify(RotateRight(a, 0))
4032  a
4033  >>> simplify(RotateRight(a, 16))
4034  a
4035  """
4036  _check_bv_args(a, b)
4037  a, b = _coerce_exprs(a, b)
4038  return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4039 
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:4025

◆ RoundNearestTiesToAway()

def z3py.RoundNearestTiesToAway (   ctx = None)

Definition at line 8881 of file z3py.py.

8881 def RoundNearestTiesToAway(ctx=None):
8882  ctx = _get_ctx(ctx)
8883  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
8884 
def RoundNearestTiesToAway(ctx=None)
Definition: z3py.py:8881
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 8873 of file z3py.py.

8873 def RoundNearestTiesToEven(ctx=None):
8874  ctx = _get_ctx(ctx)
8875  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
8876 
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:8873

◆ RoundTowardNegative()

def z3py.RoundTowardNegative (   ctx = None)

Definition at line 8897 of file z3py.py.

8897 def RoundTowardNegative(ctx=None):
8898  ctx = _get_ctx(ctx)
8899  return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
8900 
def RoundTowardNegative(ctx=None)
Definition: z3py.py:8897
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 8889 of file z3py.py.

8889 def RoundTowardPositive(ctx=None):
8890  ctx = _get_ctx(ctx)
8891  return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
8892 
def RoundTowardPositive(ctx=None)
Definition: z3py.py:8889
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 8905 of file z3py.py.

8905 def RoundTowardZero(ctx=None):
8906  ctx = _get_ctx(ctx)
8907  return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
8908 
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:8905

◆ RTN()

def z3py.RTN (   ctx = None)

Definition at line 8901 of file z3py.py.

8901 def RTN(ctx=None):
8902  ctx = _get_ctx(ctx)
8903  return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
8904 
def RTN(ctx=None)
Definition: z3py.py:8901
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 8893 of file z3py.py.

8893 def RTP(ctx=None):
8894  ctx = _get_ctx(ctx)
8895  return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
8896 
def RTP(ctx=None)
Definition: z3py.py:8893
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 8909 of file z3py.py.

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

8909 def RTZ(ctx=None):
8910  ctx = _get_ctx(ctx)
8911  return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
8912 
def RTZ(ctx=None)
Definition: z3py.py:8909
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 4427 of file z3py.py.

4427 def Select(a, i):
4428  """Return a Z3 select array expression.
4429 
4430  >>> a = Array('a', IntSort(), IntSort())
4431  >>> i = Int('i')
4432  >>> Select(a, i)
4433  a[i]
4434  >>> eq(Select(a, i), a[i])
4435  True
4436  """
4437  if __debug__:
4438  _z3_assert(is_array(a), "First argument must be a Z3 array expression")
4439  return a[i]
4440 
4441 
def is_array(a)
Definition: z3py.py:4257
def Select(a, i)
Definition: z3py.py:4427

◆ 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 9878 of file z3py.py.

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

9878 def SeqSort(s):
9879  """Create a sequence sort over elements provided in the argument
9880  >>> s = SeqSort(IntSort())
9881  >>> s == Unit(IntVal(1)).sort()
9882  True
9883  """
9884  return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
9885 
def SeqSort(s)
Definition: z3py.py:9878
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.

◆ set_default_fp_sort()

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

Definition at line 8548 of file z3py.py.

8548 def set_default_fp_sort(ebits, sbits, ctx=None):
8549  global _dflt_fpsort_ebits
8550  global _dflt_fpsort_sbits
8551  _dflt_fpsort_ebits = ebits
8552  _dflt_fpsort_sbits = sbits
8553 
def set_default_fp_sort(ebits, sbits, ctx=None)
Definition: z3py.py:8548

◆ set_default_rounding_mode()

def z3py.set_default_rounding_mode (   rm,
  ctx = None 
)

Definition at line 8532 of file z3py.py.

8532 def set_default_rounding_mode(rm, ctx=None):
8533  global _dflt_rounding_mode
8534  if is_fprm_value(rm):
8535  _dflt_rounding_mode = rm.decl().kind()
8536  else:
8537  _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO or
8538  _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE or
8539  _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE or
8540  _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN or
8541  _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY,
8542  "illegal rounding mode")
8543  _dflt_rounding_mode = rm
8544 
def set_default_rounding_mode(rm, ctx=None)
Definition: z3py.py:8532
def is_fprm_value(a)
Definition: z3py.py:8925

◆ set_option()

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

Definition at line 261 of file z3py.py.

261 def set_option(*args, **kws):
262  """Alias for 'set_param' for backward compatibility.
263  """
264  return set_param(*args, **kws)
265 
def set_option(args, kws)
Definition: z3py.py:261
def set_param(args, kws)
Definition: z3py.py:233

◆ set_param()

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

>>> set_param(precision=10)

Definition at line 233 of file z3py.py.

Referenced by set_option().

233 def set_param(*args, **kws):
234  """Set Z3 global (or module) parameters.
235 
236  >>> set_param(precision=10)
237  """
238  if __debug__:
239  _z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
240  new_kws = {}
241  for k in kws:
242  v = kws[k]
243  if not set_pp_option(k, v):
244  new_kws[k] = v
245  for key in new_kws:
246  value = new_kws[key]
247  Z3_global_param_set(str(key).upper(), _to_param_value(value))
248  prev = None
249  for a in args:
250  if prev is None:
251  prev = a
252  else:
253  Z3_global_param_set(str(prev), _to_param_value(a))
254  prev = None
255 
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:233

◆ SetAdd()

def z3py.SetAdd (   s,
  e 
)
Add element e to set s
>>> a = Const('a', SetSort(IntSort()))
>>> SetAdd(a, 1)
Store(a, 1, True)

Definition at line 4566 of file z3py.py.

4566 def SetAdd(s, e):
4567  """ Add element e to set s
4568  >>> a = Const('a', SetSort(IntSort()))
4569  >>> SetAdd(a, 1)
4570  Store(a, 1, True)
4571  """
4572  ctx = _ctx_from_ast_arg_list([s,e])
4573  e = _py2expr(e, ctx)
4574  return ArrayRef(Z3_mk_set_add(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
4575 
Z3_ast Z3_API Z3_mk_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.
def SetAdd(s, e)
Definition: z3py.py:4566

◆ SetComplement()

def z3py.SetComplement (   s)
The complement of set s
>>> a = Const('a', SetSort(IntSort()))
>>> SetComplement(a)
complement(a)

Definition at line 4586 of file z3py.py.

4586 def SetComplement(s):
4587  """ The complement of set s
4588  >>> a = Const('a', SetSort(IntSort()))
4589  >>> SetComplement(a)
4590  complement(a)
4591  """
4592  ctx = s.ctx
4593  return ArrayRef(Z3_mk_set_complement(ctx.ref(), s.as_ast()), ctx)
4594 
Z3_ast Z3_API Z3_mk_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.
def SetComplement(s)
Definition: z3py.py:4586

◆ SetDel()

def z3py.SetDel (   s,
  e 
)
Remove element e to set s
>>> a = Const('a', SetSort(IntSort()))
>>> SetDel(a, 1)
Store(a, 1, False)

Definition at line 4576 of file z3py.py.

4576 def SetDel(s, e):
4577  """ Remove element e to set s
4578  >>> a = Const('a', SetSort(IntSort()))
4579  >>> SetDel(a, 1)
4580  Store(a, 1, False)
4581  """
4582  ctx = _ctx_from_ast_arg_list([s,e])
4583  e = _py2expr(e, ctx)
4584  return ArrayRef(Z3_mk_set_del(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
4585 
Z3_ast Z3_API Z3_mk_set_del(Z3_context c, Z3_ast set, Z3_ast elem)
Remove an element to a set.
def SetDel(s, e)
Definition: z3py.py:4576

◆ SetDifference()

def z3py.SetDifference (   a,
  b 
)
The set difference of a and b
>>> a = Const('a', SetSort(IntSort()))
>>> b = Const('b', SetSort(IntSort()))
>>> SetDifference(a, b)
difference(a, b)

Definition at line 4595 of file z3py.py.

4595 def SetDifference(a, b):
4596  """ The set difference of a and b
4597  >>> a = Const('a', SetSort(IntSort()))
4598  >>> b = Const('b', SetSort(IntSort()))
4599  >>> SetDifference(a, b)
4600  difference(a, b)
4601  """
4602  ctx = _ctx_from_ast_arg_list([a, b])
4603  return ArrayRef(Z3_mk_set_difference(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4604 
def SetDifference(a, b)
Definition: z3py.py:4595
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.

◆ SetIntersect()

def z3py.SetIntersect (   args)
Take the union of sets
>>> a = Const('a', SetSort(IntSort()))
>>> b = Const('b', SetSort(IntSort()))
>>> SetIntersect(a, b)
intersect(a, b)

Definition at line 4554 of file z3py.py.

4554 def SetIntersect(*args):
4555  """ Take the union of sets
4556  >>> a = Const('a', SetSort(IntSort()))
4557  >>> b = Const('b', SetSort(IntSort()))
4558  >>> SetIntersect(a, b)
4559  intersect(a, b)
4560  """
4561  args = _get_args(args)
4562  ctx = _ctx_from_ast_arg_list(args)
4563  _args, sz = _to_ast_array(args)
4564  return ArrayRef(Z3_mk_set_intersect(ctx.ref(), sz, _args), ctx)
4565 
Z3_ast Z3_API Z3_mk_set_intersect(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the intersection of a list of sets.
def SetIntersect(args)
Definition: z3py.py:4554

◆ SetSort()

def z3py.SetSort (   s)

Sets.

Create a set sort over element sort s

Definition at line 4522 of file z3py.py.

Referenced by IsMember(), IsSubset(), Context.mkSetSort(), SetAdd(), SetComplement(), SetDel(), SetDifference(), SetIntersect(), and SetUnion().

4522 def SetSort(s):
4523  """ Create a set sort over element sort s"""
4524  return ArraySort(s, BoolSort())
4525 
def ArraySort(sig)
Definition: z3py.py:4334
def SetSort(s)
Sets.
Definition: z3py.py:4522
def BoolSort(ctx=None)
Definition: z3py.py:1512

◆ SetUnion()

def z3py.SetUnion (   args)
Take the union of sets
>>> a = Const('a', SetSort(IntSort()))
>>> b = Const('b', SetSort(IntSort()))
>>> SetUnion(a, b)
union(a, b)

Definition at line 4542 of file z3py.py.

4542 def SetUnion(*args):
4543  """ Take the union of sets
4544  >>> a = Const('a', SetSort(IntSort()))
4545  >>> b = Const('b', SetSort(IntSort()))
4546  >>> SetUnion(a, b)
4547  union(a, b)
4548  """
4549  args = _get_args(args)
4550  ctx = _ctx_from_ast_arg_list(args)
4551  _args, sz = _to_ast_array(args)
4552  return ArrayRef(Z3_mk_set_union(ctx.ref(), sz, _args), ctx)
4553 
def SetUnion(args)
Definition: z3py.py:4542
Z3_ast Z3_API Z3_mk_set_union(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the union of a list of sets.

◆ 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 4040 of file z3py.py.

4040 def SignExt(n, a):
4041  """Return a bit-vector expression with `n` extra sign-bits.
4042 
4043  >>> x = BitVec('x', 16)
4044  >>> n = SignExt(8, x)
4045  >>> n.size()
4046  24
4047  >>> n
4048  SignExt(8, x)
4049  >>> n.sort()
4050  BitVec(24)
4051  >>> v0 = BitVecVal(2, 2)
4052  >>> v0
4053  2
4054  >>> v0.size()
4055  2
4056  >>> v = simplify(SignExt(6, v0))
4057  >>> v
4058  254
4059  >>> v.size()
4060  8
4061  >>> print("%.x" % v.as_long())
4062  fe
4063  """
4064  if __debug__:
4065  _z3_assert(_is_int(n), "First argument must be an integer")
4066  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
4067  return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4068 
def SignExt(n, a)
Definition: z3py.py:4040
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:3649

◆ 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 6838 of file z3py.py.

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

6838 def SimpleSolver(ctx=None):
6839  """Return a simple general purpose solver with limited amount of preprocessing.
6840 
6841  >>> s = SimpleSolver()
6842  >>> x = Int('x')
6843  >>> s.add(x > 0)
6844  >>> s.check()
6845  sat
6846  """
6847  ctx = _get_ctx(ctx)
6848  return Solver(Z3_mk_simple_solver(ctx.ref()), ctx)
6849 
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
def SimpleSolver(ctx=None)
Definition: z3py.py:6838

◆ 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 8080 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().

8080 def simplify(a, *arguments, **keywords):
8081  """Simplify the expression `a` using the given options.
8082 
8083  This function has many options. Use `help_simplify` to obtain the complete list.
8084 
8085  >>> x = Int('x')
8086  >>> y = Int('y')
8087  >>> simplify(x + 1 + y + x + 1)
8088  2 + 2*x + y
8089  >>> simplify((x + 1)*(y + 1), som=True)
8090  1 + x + y + x*y
8091  >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8092  And(Not(x == y), Not(x == 1), Not(y == 1))
8093  >>> simplify(And(x == 0, y == 1), elim_and=True)
8094  Not(Or(Not(x == 0), Not(y == 1)))
8095  """
8096  if __debug__:
8097  _z3_assert(is_expr(a), "Z3 expression expected")
8098  if len(arguments) > 0 or len(keywords) > 0:
8099  p = args2params(arguments, keywords, a.ctx)
8100  return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8101  else:
8102  return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8103 
def simplify(a, arguments, keywords)
Utils.
Definition: z3py.py:8080
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:5001
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:1094

◆ simplify_param_descrs()

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

Definition at line 8108 of file z3py.py.

8108 def simplify_param_descrs():
8109  """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8110  return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
8111 
def main_ctx()
Definition: z3py.py:207
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:8108

◆ 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 8293 of file z3py.py.

Referenced by BV2Int(), and IsInt().

8293 def solve(*args, **keywords):
8294  """Solve the constraints `*args`.
8295 
8296  This is a simple function for creating demonstrations. It creates a solver,
8297  configure it using the options in `keywords`, adds the constraints
8298  in `args`, and invokes check.
8299 
8300  >>> a = Int('a')
8301  >>> solve(a > 0, a < 2)
8302  [a = 1]
8303  """
8304  s = Solver()
8305  s.set(**keywords)
8306  s.add(*args)
8307  if keywords.get('show', False):
8308  print(s)
8309  r = s.check()
8310  if r == unsat:
8311  print("no solution")
8312  elif r == unknown:
8313  print("failed to solve")
8314  try:
8315  print(s.model())
8316  except Z3Exception:
8317  return
8318  else:
8319  print(s.model())
8320 
def solve(args, keywords)
Definition: z3py.py:8293

◆ 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 8321 of file z3py.py.

8321 def solve_using(s, *args, **keywords):
8322  """Solve the constraints `*args` using solver `s`.
8323 
8324  This is a simple function for creating demonstrations. It is similar to `solve`,
8325  but it uses the given solver `s`.
8326  It configures solver `s` using the options in `keywords`, adds the constraints
8327  in `args`, and invokes check.
8328  """
8329  if __debug__:
8330  _z3_assert(isinstance(s, Solver), "Solver object expected")
8331  s.set(**keywords)
8332  s.add(*args)
8333  if keywords.get('show', False):
8334  print("Problem:")
8335  print(s)
8336  r = s.check()
8337  if r == unsat:
8338  print("no solution")
8339  elif r == unknown:
8340  print("failed to solve")
8341  try:
8342  print(s.model())
8343  except Z3Exception:
8344  return
8345  else:
8346  if keywords.get('show', False):
8347  print("Solution:")
8348  print(s.model())
8349 
def solve_using(s, args, keywords)
Definition: z3py.py:8321

◆ 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 6818 of file z3py.py.

6818 def SolverFor(logic, ctx=None):
6819  """Create a solver customized for the given logic.
6820 
6821  The parameter `logic` is a string. It should be contains
6822  the name of a SMT-LIB logic.
6823  See http://www.smtlib.org/ for the name of all available logics.
6824 
6825  >>> s = SolverFor("QF_LIA")
6826  >>> x = Int('x')
6827  >>> s.add(x > 0)
6828  >>> s.add(x < 2)
6829  >>> s.check()
6830  sat
6831  >>> s.model()
6832  [x = 1]
6833  """
6834  ctx = _get_ctx(ctx)
6835  logic = to_symbol(logic)
6836  return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx)
6837 
def to_symbol(s, ctx=None)
Definition: z3py.py:105
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:6818

◆ 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 3126 of file z3py.py.

Referenced by AlgebraicNumRef.approx(), AlgebraicNumRef.as_decimal(), and is_algebraic_value().

3126 def Sqrt(a, ctx=None):
3127  """ Return a Z3 expression which represents the square root of a.
3128 
3129  >>> x = Real('x')
3130  >>> Sqrt(x)
3131  x**(1/2)
3132  """
3133  if not is_expr(a):
3134  ctx = _get_ctx(ctx)
3135  a = RealVal(a, ctx)
3136  return a ** "1/2"
3137 
def RealVal(val, ctx=None)
Definition: z3py.py:2931
def is_expr(a)
Definition: z3py.py:1094
def Sqrt(a, ctx=None)
Definition: z3py.py:3126

◆ 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 3959 of file z3py.py.

Referenced by BitVecRef.__mod__(), BitVecRef.__rmod__(), and URem().

3959 def SRem(a, b):
3960  """Create the Z3 expression signed remainder.
3961 
3962  Use the operator % for signed modulus, and URem() for unsigned remainder.
3963 
3964  >>> x = BitVec('x', 32)
3965  >>> y = BitVec('y', 32)
3966  >>> SRem(x, y)
3967  SRem(x, y)
3968  >>> SRem(x, y).sort()
3969  BitVec(32)
3970  >>> (x % y).sexpr()
3971  '(bvsmod x y)'
3972  >>> SRem(x, y).sexpr()
3973  '(bvsrem x y)'
3974  """
3975  _check_bv_args(a, b)
3976  a, b = _coerce_exprs(a, b)
3977  return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3978 
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:3959

◆ 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 10237 of file z3py.py.

10237 def Star(re):
10238  """Create the regular expression accepting zero or more repetitions of argument.
10239  >>> re = Star(Re("a"))
10240  >>> print(simplify(InRe("aa", re)))
10241  True
10242  >>> print(simplify(InRe("ab", re)))
10243  False
10244  >>> print(simplify(InRe("", re)))
10245  True
10246  """
10247  return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
10248 
def Star(re)
Definition: z3py.py:10237
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 4411 of file z3py.py.

Referenced by is_array(), is_store(), SetAdd(), and SetDel().

4411 def Store(a, i, v):
4412  """Return a Z3 store array expression.
4413 
4414  >>> a = Array('a', IntSort(), IntSort())
4415  >>> i, v = Ints('i v')
4416  >>> s = Store(a, i, v)
4417  >>> s.sort()
4418  Array(Int, Int)
4419  >>> prove(s[i] == v)
4420  proved
4421  >>> j = Int('j')
4422  >>> prove(Implies(i != j, s[j] == a[j]))
4423  proved
4424  """
4425  return Update(a, i, v)
4426 
def Update(a, i, v)
Definition: z3py.py:4379
def Store(a, i, v)
Definition: z3py.py:4411

◆ 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 9964 of file z3py.py.

Referenced by 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(), Native.getProbeName(), Context.getProbeNames(), Native.getString(), Native.getSymbolString(), Native.getTacticName(), Context.getTacticNames(), Native.goalToDimacsString(), Native.goalToString(), 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(), and FuncInterp.toString().

9964 def String(name, ctx=None):
9965  """Return a string constant named `name`. If `ctx=None`, then the global context is used.
9966 
9967  >>> x = String('x')
9968  """
9969  ctx = _get_ctx(ctx)
9970  return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
9971 
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:105
def StringSort(ctx=None)
Definition: z3py.py:9868
def String(name, ctx=None)
Definition: z3py.py:9964

◆ Strings()

def z3py.Strings (   names,
  ctx = None 
)
Return a tuple of String constants. 

Definition at line 9980 of file z3py.py.

Referenced by Contains().

9980 def Strings(names, ctx=None):
9981  """Return a tuple of String constants. """
9982  ctx = _get_ctx(ctx)
9983  if isinstance(names, str):
9984  names = names.split(" ")
9985  return [String(name, ctx) for name in names]
9986 
def Strings(names, ctx=None)
Definition: z3py.py:9980
def String(name, ctx=None)
Definition: z3py.py:9964

◆ StringSort()

def z3py.StringSort (   ctx = None)
Create a string sort
>>> s = StringSort()
>>> print(s)
String

Definition at line 9868 of file z3py.py.

Referenced by Empty(), Full(), and SeqSortRef.is_string().

9868 def StringSort(ctx=None):
9869  """Create a string sort
9870  >>> s = StringSort()
9871  >>> print(s)
9872  String
9873  """
9874  ctx = _get_ctx(ctx)
9875  return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
9876 
9877 
def StringSort(ctx=None)
Definition: z3py.py:9868
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 9959 of file z3py.py.

Referenced by Empty(), Extract(), is_seq(), is_string(), is_string_value(), Length(), and Re().

9959 def StringVal(s, ctx=None):
9960  """create a string expression"""
9961  ctx = _get_ctx(ctx)
9962  return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
9963 
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:9959

◆ 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 10116 of file z3py.py.

10116 def StrToInt(s):
10117  """Convert string expression to integer
10118  >>> a = StrToInt("1")
10119  >>> simplify(1 == a)
10120  True
10121  >>> b = StrToInt("2")
10122  >>> simplify(1 == b)
10123  False
10124  >>> c = StrToInt(IntToStr(2))
10125  >>> simplify(1 == c)
10126  False
10127  """
10128  s = _coerce_seq(s)
10129  return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
10130 
10131 
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:10116

◆ SubSeq()

def z3py.SubSeq (   s,
  offset,
  length 
)
Extract substring or subsequence starting at offset

Definition at line 9976 of file z3py.py.

9976 def SubSeq(s, offset, length):
9977  """Extract substring or subsequence starting at offset"""
9978  return Extract(s, offset, length)
9979 
def SubSeq(s, offset, length)
Definition: z3py.py:9976
def Extract(high, low, a)
Definition: z3py.py:3824

◆ 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 8112 of file z3py.py.

8112 def substitute(t, *m):
8113  """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.
8114 
8115  >>> x = Int('x')
8116  >>> y = Int('y')
8117  >>> substitute(x + 1, (x, y + 1))
8118  y + 1 + 1
8119  >>> f = Function('f', IntSort(), IntSort())
8120  >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8121  1 + 1
8122  """
8123  if isinstance(m, tuple):
8124  m1 = _get_args(m)
8125  if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
8126  m = m1
8127  if __debug__:
8128  _z3_assert(is_expr(t), "Z3 expression expected")
8129  _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.")
8130  num = len(m)
8131  _from = (Ast * num)()
8132  _to = (Ast * num)()
8133  for i in range(num):
8134  _from[i] = m[i][0].as_ast()
8135  _to[i] = m[i][1].as_ast()
8136  return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8137 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
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:8112
def eq(a, b)
Definition: z3py.py:416
def is_expr(a)
Definition: z3py.py:1094

◆ 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 8138 of file z3py.py.

8138 def substitute_vars(t, *m):
8139  """Substitute the free variables in t with the expression in m.
8140 
8141  >>> v0 = Var(0, IntSort())
8142  >>> v1 = Var(1, IntSort())
8143  >>> x = Int('x')
8144  >>> f = Function('f', IntSort(), IntSort(), IntSort())
8145  >>> # replace v0 with x+1 and v1 with x
8146  >>> substitute_vars(f(v0, v1), x + 1, x)
8147  f(x + 1, x)
8148  """
8149  if __debug__:
8150  _z3_assert(is_expr(t), "Z3 expression expected")
8151  _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
8152  num = len(m)
8153  _to = (Ast * num)()
8154  for i in range(num):
8155  _to[i] = m[i].as_ast()
8156  return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
8157 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def substitute_vars(t, m)
Definition: z3py.py:8138
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:1094

◆ SubString()

def z3py.SubString (   s,
  offset,
  length 
)
Extract substring or subsequence starting at offset

Definition at line 9972 of file z3py.py.

9972 def SubString(s, offset, length):
9973  """Extract substring or subsequence starting at offset"""
9974  return Extract(s, offset, length)
9975 
def SubString(s, offset, length)
Definition: z3py.py:9972
def Extract(high, low, a)
Definition: z3py.py:3824

◆ 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 10040 of file z3py.py.

10040 def SuffixOf(a, b):
10041  """Check if 'a' is a suffix of 'b'
10042  >>> s1 = SuffixOf("ab", "abc")
10043  >>> simplify(s1)
10044  False
10045  >>> s2 = SuffixOf("bc", "abc")
10046  >>> simplify(s2)
10047  True
10048  """
10049  ctx = _get_ctx2(a, b)
10050  a = _coerce_seq(a, ctx)
10051  b = _coerce_seq(b, ctx)
10052  return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
10053 
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:10040

◆ 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 8158 of file z3py.py.

Referenced by BitVecs(), Ints(), IntVector(), Reals(), and RealVector().

8158 def Sum(*args):
8159  """Create the sum of the Z3 expressions.
8160 
8161  >>> a, b, c = Ints('a b c')
8162  >>> Sum(a, b, c)
8163  a + b + c
8164  >>> Sum([a, b, c])
8165  a + b + c
8166  >>> A = IntVector('a', 5)
8167  >>> Sum(A)
8168  a__0 + a__1 + a__2 + a__3 + a__4
8169  """
8170  args = _get_args(args)
8171  if len(args) == 0:
8172  return 0
8173  ctx = _ctx_from_ast_arg_list(args)
8174  if ctx is None:
8175  return _reduce(lambda a, b: a + b, args, 0)
8176  args = _coerce_expr_list(args, ctx)
8177  if is_bv(args[0]):
8178  return _reduce(lambda a, b: a + b, args, 0)
8179  else:
8180  _args, sz = _to_ast_array(args)
8181  return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
8182 
8183 
def Sum(args)
Definition: z3py.py:8158
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:3649

◆ 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 7795 of file z3py.py.

Referenced by describe_tactics().

7795 def tactic_description(name, ctx=None):
7796  """Return a short description for the tactic named `name`.
7797 
7798  >>> d = tactic_description('simplify')
7799  """
7800  ctx = _get_ctx(ctx)
7801  return Z3_tactic_get_descr(ctx.ref(), name)
7802 
def tactic_description(name, ctx=None)
Definition: z3py.py:7795
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 7785 of file z3py.py.

Referenced by describe_tactics(), and z3.par_or().

7785 def tactics(ctx=None):
7786  """Return a list of all available tactics in Z3.
7787 
7788  >>> l = tactics()
7789  >>> l.count('simplify') == 1
7790  True
7791  """
7792  ctx = _get_ctx(ctx)
7793  return [ Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref())) ]
7794 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
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:7785
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 7664 of file z3py.py.

Referenced by Statistics.__getattr__(), Statistics.__getitem__(), Statistics.__len__(), Goal.convert_model(), Goal.depth(), Statistics.get_key_value(), and Statistics.keys().

7664 def Then(*ts, **ks):
7665  """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
7666 
7667  >>> x, y = Ints('x y')
7668  >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
7669  >>> t(And(x == 0, y > x + 1))
7670  [[Not(y <= 1)]]
7671  >>> t(And(x == 0, y > x + 1)).as_expr()
7672  Not(y <= 1)
7673  """
7674  return AndThen(*ts, **ks)
7675 
def Then(ts, ks)
Definition: z3py.py:7664
def AndThen(ts, ks)
Definition: z3py.py:7645

◆ to_symbol()

def z3py.to_symbol (   s,
  ctx = None 
)
Convert an integer or string into a Z3 symbol.

Definition at line 105 of file z3py.py.

Referenced by Fixedpoint.add_rule(), Optimize.add_soft(), Const(), DeclareSort(), FiniteDomainSort(), Function(), prove(), RecFunction(), Fixedpoint.set_predicate_representation(), SolverFor(), and Fixedpoint.update_rule().

105 def to_symbol(s, ctx=None):
106  """Convert an integer or string into a Z3 symbol."""
107  if _is_int(s):
108  return Z3_mk_int_symbol(_get_ctx(ctx).ref(), s)
109  else:
110  return Z3_mk_string_symbol(_get_ctx(ctx).ref(), s)
111 
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:105
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 3093 of file z3py.py.

Referenced by is_to_int().

3093 def ToInt(a):
3094  """ Return the Z3 expression ToInt(a).
3095 
3096  >>> x = Real('x')
3097  >>> x.sort()
3098  Real
3099  >>> n = ToInt(x)
3100  >>> n
3101  ToInt(x)
3102  >>> n.sort()
3103  Int
3104  """
3105  if __debug__:
3106  _z3_assert(a.is_real(), "Z3 real expression expected.")
3107  ctx = a.ctx
3108  return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
3109 
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:3093

◆ 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 3076 of file z3py.py.

Referenced by ArithRef.__ge__(), ArithRef.__gt__(), ArithRef.__le__(), ArithRef.__lt__(), and is_to_real().

3076 def ToReal(a):
3077  """ Return the Z3 expression ToReal(a).
3078 
3079  >>> x = Int('x')
3080  >>> x.sort()
3081  Int
3082  >>> n = ToReal(x)
3083  >>> n
3084  ToReal(x)
3085  >>> n.sort()
3086  Real
3087  """
3088  if __debug__:
3089  _z3_assert(a.is_int(), "Z3 integer expression expected.")
3090  ctx = a.ctx
3091  return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
3092 
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:3076

◆ 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 7777 of file z3py.py.

7777 def TryFor(t, ms, ctx=None):
7778  """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
7779 
7780  If `t` does not terminate in `ms` milliseconds, then it fails.
7781  """
7782  t = _to_tactic(t, ctx)
7783  return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
7784 
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:7777

◆ 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 3919 of file z3py.py.

Referenced by BitVecRef.__div__(), and BitVecRef.__rdiv__().

3919 def UDiv(a, b):
3920  """Create the Z3 expression (unsigned) division `self / other`.
3921 
3922  Use the operator / for signed division.
3923 
3924  >>> x = BitVec('x', 32)
3925  >>> y = BitVec('y', 32)
3926  >>> UDiv(x, y)
3927  UDiv(x, y)
3928  >>> UDiv(x, y).sort()
3929  BitVec(32)
3930  >>> (x / y).sexpr()
3931  '(bvsdiv x y)'
3932  >>> UDiv(x, y).sexpr()
3933  '(bvudiv x y)'
3934  """
3935  _check_bv_args(a, b)
3936  a, b = _coerce_exprs(a, b)
3937  return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3938 
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:3919

◆ 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 3885 of file z3py.py.

Referenced by BitVecRef.__ge__().

3885 def UGE(a, b):
3886  """Create the Z3 expression (unsigned) `other >= self`.
3887 
3888  Use the operator >= for signed greater than or equal to.
3889 
3890  >>> x, y = BitVecs('x y', 32)
3891  >>> UGE(x, y)
3892  UGE(x, y)
3893  >>> (x >= y).sexpr()
3894  '(bvsge x y)'
3895  >>> UGE(x, y).sexpr()
3896  '(bvuge x y)'
3897  """
3898  _check_bv_args(a, b)
3899  a, b = _coerce_exprs(a, b)
3900  return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3901 
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:3885

◆ 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 3902 of file z3py.py.

Referenced by BitVecRef.__gt__().

3902 def UGT(a, b):
3903  """Create the Z3 expression (unsigned) `other > self`.
3904 
3905  Use the operator > for signed greater than.
3906 
3907  >>> x, y = BitVecs('x y', 32)
3908  >>> UGT(x, y)
3909  UGT(x, y)
3910  >>> (x > y).sexpr()
3911  '(bvsgt x y)'
3912  >>> UGT(x, y).sexpr()
3913  '(bvugt x y)'
3914  """
3915  _check_bv_args(a, b)
3916  a, b = _coerce_exprs(a, b)
3917  return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3918 
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:3902

◆ 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 3851 of file z3py.py.

Referenced by BitVecRef.__le__().

3851 def ULE(a, b):
3852  """Create the Z3 expression (unsigned) `other <= self`.
3853 
3854  Use the operator <= for signed less than or equal to.
3855 
3856  >>> x, y = BitVecs('x y', 32)
3857  >>> ULE(x, y)
3858  ULE(x, y)
3859  >>> (x <= y).sexpr()
3860  '(bvsle x y)'
3861  >>> ULE(x, y).sexpr()
3862  '(bvule x y)'
3863  """
3864  _check_bv_args(a, b)
3865  a, b = _coerce_exprs(a, b)
3866  return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3867 
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:3851

◆ 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 3868 of file z3py.py.

Referenced by BitVecRef.__lt__().

3868 def ULT(a, b):
3869  """Create the Z3 expression (unsigned) `other < self`.
3870 
3871  Use the operator < for signed less than.
3872 
3873  >>> x, y = BitVecs('x y', 32)
3874  >>> ULT(x, y)
3875  ULT(x, y)
3876  >>> (x < y).sexpr()
3877  '(bvslt x y)'
3878  >>> ULT(x, y).sexpr()
3879  '(bvult x y)'
3880  """
3881  _check_bv_args(a, b)
3882  a, b = _coerce_exprs(a, b)
3883  return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3884 
def ULT(a, b)
Definition: z3py.py:3868
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 10190 of file z3py.py.

Referenced by InRe().

10190 def Union(*args):
10191  """Create union of regular expressions.
10192  >>> re = Union(Re("a"), Re("b"), Re("c"))
10193  >>> print (simplify(InRe("d", re)))
10194  False
10195  """
10196  args = _get_args(args)
10197  sz = len(args)
10198  if __debug__:
10199  _z3_assert(sz > 0, "At least one argument expected.")
10200  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
10201  if sz == 1:
10202  return args[0]
10203  ctx = args[0].ctx
10204  v = (Ast * sz)()
10205  for i in range(sz):
10206  v[i] = args[i].as_ast()
10207  return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
10208 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
def Union(args)
Definition: z3py.py:10190
def is_re(s)
Definition: z3py.py:10173
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 10022 of file z3py.py.

Referenced by is_seq(), Re(), and SeqSort().

10022 def Unit(a):
10023  """Create a singleton sequence"""
10024  return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
10025 
def Unit(a)
Definition: z3py.py:10022
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 4379 of file z3py.py.

4379 def Update(a, i, v):
4380  """Return a Z3 store array expression.
4381 
4382  >>> a = Array('a', IntSort(), IntSort())
4383  >>> i, v = Ints('i v')
4384  >>> s = Update(a, i, v)
4385  >>> s.sort()
4386  Array(Int, Int)
4387  >>> prove(s[i] == v)
4388  proved
4389  >>> j = Int('j')
4390  >>> prove(Implies(i != j, s[j] == a[j]))
4391  proved
4392  """
4393  if __debug__:
4394  _z3_assert(is_array(a), "First argument must be a Z3 array expression")
4395  i = a.domain().cast(i)
4396  v = a.range().cast(v)
4397  ctx = a.ctx
4398  return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4399 
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:4257
def Update(a, i, v)
Definition: z3py.py:4379

◆ 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 3939 of file z3py.py.

Referenced by BitVecRef.__mod__(), BitVecRef.__rmod__(), and SRem().

3939 def URem(a, b):
3940  """Create the Z3 expression (unsigned) remainder `self % other`.
3941 
3942  Use the operator % for signed modulus, and SRem() for signed remainder.
3943 
3944  >>> x = BitVec('x', 32)
3945  >>> y = BitVec('y', 32)
3946  >>> URem(x, y)
3947  URem(x, y)
3948  >>> URem(x, y).sort()
3949  BitVec(32)
3950  >>> (x % y).sexpr()
3951  '(bvsmod x y)'
3952  >>> URem(x, y).sexpr()
3953  '(bvurem x y)'
3954  """
3955  _check_bv_args(a, b)
3956  a, b = _coerce_exprs(a, b)
3957  return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3958 
def URem(a, b)
Definition: z3py.py:3939
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 1310 of file z3py.py.

Referenced by QuantifierRef.body(), QuantifierRef.children(), is_pattern(), MultiPattern(), QuantifierRef.pattern(), and RealVar().

1310 def Var(idx, s):
1311  """Create a Z3 free variable. Free variables are used to create quantified formulas.
1312 
1313  >>> Var(0, IntSort())
1314  Var(0)
1315  >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1316  False
1317  """
1318  if __debug__:
1319  _z3_assert(is_sort(s), "Z3 sort expected")
1320  return _to_expr_ref(Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1321 
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:1310
def is_sort(s)
Definition: z3py.py:579

◆ 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 8046 of file z3py.py.

8046 def When(p, t, ctx=None):
8047  """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8048 
8049  >>> t = When(Probe('size') > 2, Tactic('simplify'))
8050  >>> x, y = Ints('x y')
8051  >>> g = Goal()
8052  >>> g.add(x > 0)
8053  >>> g.add(y > 0)
8054  >>> t(g)
8055  [[x > 0, y > 0]]
8056  >>> g.add(x == y + 1)
8057  >>> t(g)
8058  [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8059  """
8060  p = _to_probe(p, ctx)
8061  t = _to_tactic(t, ctx)
8062  return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
8063 
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:8046

◆ 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 7732 of file z3py.py.

Referenced by Goal.prec().

7732 def With(t, *args, **keys):
7733  """Return a tactic that applies tactic `t` using the given configuration options.
7734 
7735  >>> x, y = Ints('x y')
7736  >>> t = With(Tactic('simplify'), som=True)
7737  >>> t((x + 1)*(y + 2) == 0)
7738  [[2*x + y + x*y == -2]]
7739  """
7740  ctx = keys.pop('ctx', None)
7741  t = _to_tactic(t, ctx)
7742  p = args2params(args, keys, t.ctx)
7743  return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
7744 
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:5001
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:7732

◆ 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 7745 of file z3py.py.

7745 def WithParams(t, p):
7746  """Return a tactic that applies tactic `t` using the given configuration options.
7747 
7748  >>> x, y = Ints('x y')
7749  >>> p = ParamsRef()
7750  >>> p.set("som", True)
7751  >>> t = WithParams(Tactic('simplify'), p)
7752  >>> t((x + 1)*(y + 2) == 0)
7753  [[2*x + y + x*y == -2]]
7754  """
7755  t = _to_tactic(t, None)
7756  return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
7757 
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:7745

◆ 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 1615 of file z3py.py.

1615 def Xor(a, b, ctx=None):
1616  """Create a Z3 Xor expression.
1617 
1618  >>> p, q = Bools('p q')
1619  >>> Xor(p, q)
1620  Xor(p, q)
1621  >>> simplify(Xor(p, q))
1622  Not(p) == q
1623  """
1624  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1625  s = BoolSort(ctx)
1626  a = s.cast(a)
1627  b = s.cast(b)
1628  return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1629 
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:1615
def BoolSort(ctx=None)
Definition: z3py.py:1512

◆ z3_error_handler()

def z3py.z3_error_handler (   c,
  e 
)

Definition at line 152 of file z3py.py.

152 def z3_error_handler(c, e):
153  # Do nothing error handler, just avoid exit(0)
154  # The wrappers in z3core.py will raise a Z3Exception if an error is detected
155  return
156 
def z3_error_handler(c, e)
Definition: z3py.py:152

◆ 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 4069 of file z3py.py.

4069 def ZeroExt(n, a):
4070  """Return a bit-vector expression with `n` extra zero-bits.
4071 
4072  >>> x = BitVec('x', 16)
4073  >>> n = ZeroExt(8, x)
4074  >>> n.size()
4075  24
4076  >>> n
4077  ZeroExt(8, x)
4078  >>> n.sort()
4079  BitVec(24)
4080  >>> v0 = BitVecVal(2, 2)
4081  >>> v0
4082  2
4083  >>> v0.size()
4084  2
4085  >>> v = simplify(ZeroExt(6, v0))
4086  >>> v
4087  2
4088  >>> v.size()
4089  8
4090  """
4091  if __debug__:
4092  _z3_assert(_is_int(n), "First argument must be an integer")
4093  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
4094  return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4095 
def ZeroExt(n, a)
Definition: z3py.py:4069
def is_bv(a)
Definition: z3py.py:3649
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 6356 of file z3py.py.

◆ unknown

Definition at line 6358 of file z3py.py.

◆ unsat

Definition at line 6357 of file z3py.py.