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 z3_debug ()
 
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 get_ctx (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 mk_not (a)
 
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_sort (a)
 
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 SetHasSize (a, k)
 
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 TupleSort (name, sorts, ctx=None)
 
def DisjointSum (name, sorts, ctx=None)
 
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 Strings (names, ctx=None)
 
def SubString (s, offset, length)
 
def SubSeq (s, offset, length)
 
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 LastIndexOf (s, substr)
 
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 Intersect (*args)
 
def Plus (re)
 
def Option (re)
 
def Complement (re)
 
def Star (re)
 
def Loop (re, lo, hi=0)
 
def Range (lo, hi, ctx=None)
 
def PartialOrder (a, index)
 
def LinearOrder (a, index)
 
def TreeOrder (a, index)
 
def PiecewiseLinearOrder (a, index)
 
def TransitiveClosure (f)
 

Variables

 Z3_DEBUG = __debug__
 
 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 1684 of file z3py.py.

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

Referenced by Fixedpoint.add_rule(), Goal.as_expr(), Fixedpoint.query(), Fixedpoint.query_from_lvl(), and Fixedpoint.update_rule().

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

7749 def AndThen(*ts, **ks):
7750  """Return a tactic that applies the tactics in `*ts` in sequence.
7751 
7752  >>> x, y = Ints('x y')
7753  >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
7754  >>> t(And(x == 0, y > x + 1))
7755  [[Not(y <= 1)]]
7756  >>> t(And(x == 0, y > x + 1)).as_expr()
7757  Not(y <= 1)
7758  """
7759  if z3_debug():
7760  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7761  ctx = ks.get('ctx', None)
7762  num = len(ts)
7763  r = ts[0]
7764  for i in range(num - 1):
7765  r = _and_then(r, ts[i+1], ctx)
7766  return r
7767 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def z3_debug()
Definition: z3py.py:58
def AndThen(*ts, **ks)
Definition: z3py.py:7749

Referenced by Then().

◆ append_log()

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

Definition at line 107 of file z3py.py.

107 def append_log(s):
108  """Append user-defined string to interaction log. """
109  Z3_append_log(s)
110 
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.
def append_log(s)
Definition: z3py.py:107

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

5074 def args2params(arguments, keywords, ctx=None):
5075  """Convert python arguments into a Z3_params object.
5076  A ':' is added to the keywords, and '_' is replaced with '-'
5077 
5078  >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5079  (params model true relevancy 2 elim_and true)
5080  """
5081  if z3_debug():
5082  _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
5083  prev = None
5084  r = ParamsRef(ctx)
5085  for a in arguments:
5086  if prev is None:
5087  prev = a
5088  else:
5089  r.set(prev, a)
5090  prev = None
5091  for k in keywords:
5092  v = keywords[k]
5093  r.set(k, v)
5094  return r
5095 
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:5074
def z3_debug()
Definition: z3py.py:58

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

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

4407 def Array(name, dom, rng):
4408  """Return an array constant named `name` with the given domain and range sorts.
4409 
4410  >>> a = Array('a', IntSort(), IntSort())
4411  >>> a.sort()
4412  Array(Int, Int)
4413  >>> a[0]
4414  a[0]
4415  """
4416  s = ArraySort(dom, rng)
4417  ctx = s.ctx
4418  return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4419 
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:111
def Array(name, dom, rng)
Definition: z3py.py:4407
def ArraySort(*sig)
Definition: z3py.py:4375

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

4375 def ArraySort(*sig):
4376  """Return the Z3 array sort with the given domain and range sorts.
4377 
4378  >>> A = ArraySort(IntSort(), BoolSort())
4379  >>> A
4380  Array(Int, Bool)
4381  >>> A.domain()
4382  Int
4383  >>> A.range()
4384  Bool
4385  >>> AA = ArraySort(IntSort(), A)
4386  >>> AA
4387  Array(Int, Array(Int, Bool))
4388  """
4389  sig = _get_args(sig)
4390  if z3_debug():
4391  _z3_assert(len(sig) > 1, "At least two arguments expected")
4392  arity = len(sig) - 1
4393  r = sig[arity]
4394  d = sig[0]
4395  if z3_debug():
4396  for s in sig:
4397  _z3_assert(is_sort(s), "Z3 sort expected")
4398  _z3_assert(s.ctx == r.ctx, "Context mismatch")
4399  ctx = d.ctx
4400  if len(sig) == 2:
4401  return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4402  dom = (Sort * arity)()
4403  for i in range(arity):
4404  dom[i] = sig[i].ast
4405  return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
4406 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
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:598
def z3_debug()
Definition: z3py.py:58
def ArraySort(*sig)
Definition: z3py.py:4375

Referenced by Array(), Context.mkArraySort(), and SetSort().

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

8330 def AtLeast(*args):
8331  """Create an at-most Pseudo-Boolean k constraint.
8332 
8333  >>> a, b, c = Bools('a b c')
8334  >>> f = AtLeast(a, b, c, 2)
8335  """
8336  args = _get_args(args)
8337  if z3_debug():
8338  _z3_assert(len(args) > 1, "Non empty list of arguments expected")
8339  ctx = _ctx_from_ast_arg_list(args)
8340  if z3_debug():
8341  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
8342  args1 = _coerce_expr_list(args[:-1], ctx)
8343  k = args[-1]
8344  _args, sz = _to_ast_array(args1)
8345  return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
8346 
def AtLeast(*args)
Definition: z3py.py:8330
def z3_debug()
Definition: z3py.py:58
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 8313 of file z3py.py.

8313 def AtMost(*args):
8314  """Create an at-most Pseudo-Boolean k constraint.
8315 
8316  >>> a, b, c = Bools('a b c')
8317  >>> f = AtMost(a, b, c, 2)
8318  """
8319  args = _get_args(args)
8320  if z3_debug():
8321  _z3_assert(len(args) > 1, "Non empty list of arguments expected")
8322  ctx = _ctx_from_ast_arg_list(args)
8323  if z3_debug():
8324  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
8325  args1 = _coerce_expr_list(args[:-1], ctx)
8326  k = args[-1]
8327  _args, sz = _to_ast_array(args1)
8328  return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
8329 
def AtMost(*args)
Definition: z3py.py:8313
def z3_debug()
Definition: z3py.py:58
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 3774 of file z3py.py.

3774 def BitVec(name, bv, ctx=None):
3775  """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
3776  If `ctx=None`, then the global context is used.
3777 
3778  >>> x = BitVec('x', 16)
3779  >>> is_bv(x)
3780  True
3781  >>> x.size()
3782  16
3783  >>> x.sort()
3784  BitVec(16)
3785  >>> word = BitVecSort(16)
3786  >>> x2 = BitVec('x', word)
3787  >>> eq(x, x2)
3788  True
3789  """
3790  if isinstance(bv, BitVecSortRef):
3791  ctx = bv.ctx
3792  else:
3793  ctx = _get_ctx(ctx)
3794  bv = BitVecSort(bv, ctx)
3795  return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
3796 
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:111
def BitVec(name, bv, ctx=None)
Definition: z3py.py:3774
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3744

Referenced by BitVecs().

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

3797 def BitVecs(names, bv, ctx=None):
3798  """Return a tuple of bit-vector constants of size bv.
3799 
3800  >>> x, y, z = BitVecs('x y z', 16)
3801  >>> x.size()
3802  16
3803  >>> x.sort()
3804  BitVec(16)
3805  >>> Sum(x, y, z)
3806  0 + x + y + z
3807  >>> Product(x, y, z)
3808  1*x*y*z
3809  >>> simplify(Product(x, y, z))
3810  x*y*z
3811  """
3812  ctx = _get_ctx(ctx)
3813  if isinstance(names, str):
3814  names = names.split(" ")
3815  return [BitVec(name, bv, ctx) for name in names]
3816 
def BitVec(name, bv, ctx=None)
Definition: z3py.py:3774
def BitVecs(names, bv, ctx=None)
Definition: z3py.py:3797

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

3744 def BitVecSort(sz, ctx=None):
3745  """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3746 
3747  >>> Byte = BitVecSort(8)
3748  >>> Word = BitVecSort(16)
3749  >>> Byte
3750  BitVec(8)
3751  >>> x = Const('x', Byte)
3752  >>> eq(x, BitVec('x', 8))
3753  True
3754  """
3755  ctx = _get_ctx(ctx)
3756  return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
3757 
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:3744

Referenced by BitVec(), BitVecVal(), and Context.mkBitVecSort().

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

3758 def BitVecVal(val, bv, ctx=None):
3759  """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3760 
3761  >>> v = BitVecVal(10, 32)
3762  >>> v
3763  10
3764  >>> print("0x%.8x" % v.as_long())
3765  0x0000000a
3766  """
3767  if is_bv_sort(bv):
3768  ctx = bv.ctx
3769  return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
3770  else:
3771  ctx = _get_ctx(ctx)
3772  return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
3773 
def BitVecVal(val, bv, ctx=None)
Definition: z3py.py:3758
def is_bv_sort(s)
Definition: z3py.py:3226
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3744
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 1570 of file z3py.py.

1570 def Bool(name, ctx=None):
1571  """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1572 
1573  >>> p = Bool('p')
1574  >>> q = Bool('q')
1575  >>> And(p, q)
1576  And(p, q)
1577  """
1578  ctx = _get_ctx(ctx)
1579  return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
1580 
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:111
def Bool(name, ctx=None)
Definition: z3py.py:1570
def BoolSort(ctx=None)
Definition: z3py.py:1535

Referenced by Solver.assert_and_track(), Optimize.assert_and_track(), Bools(), and BoolVector().

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

1581 def Bools(names, ctx=None):
1582  """Return a tuple of Boolean constants.
1583 
1584  `names` is a single string containing all names separated by blank spaces.
1585  If `ctx=None`, then the global context is used.
1586 
1587  >>> p, q, r = Bools('p q r')
1588  >>> And(p, Or(q, r))
1589  And(p, Or(q, r))
1590  """
1591  ctx = _get_ctx(ctx)
1592  if isinstance(names, str):
1593  names = names.split(" ")
1594  return [Bool(name, ctx) for name in names]
1595 
def Bools(names, ctx=None)
Definition: z3py.py:1581
def Bool(name, ctx=None)
Definition: z3py.py:1570

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

1535 def BoolSort(ctx=None):
1536  """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1537 
1538  >>> BoolSort()
1539  Bool
1540  >>> p = Const('p', BoolSort())
1541  >>> is_bool(p)
1542  True
1543  >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1544  >>> r(0, 1)
1545  r(0, 1)
1546  >>> is_bool(r(0, 1))
1547  True
1548  """
1549  ctx = _get_ctx(ctx)
1550  return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
1551 
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.
def BoolSort(ctx=None)
Definition: z3py.py:1535

Referenced by Goal.assert_exprs(), Solver.assert_exprs(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Bool(), FreshBool(), Context.getBoolSort(), If(), Implies(), Context.mkBoolSort(), Not(), SetSort(), QuantifierRef.sort(), and Xor().

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

1552 def BoolVal(val, ctx=None):
1553  """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1554 
1555  >>> BoolVal(True)
1556  True
1557  >>> is_true(BoolVal(True))
1558  True
1559  >>> is_true(True)
1560  False
1561  >>> is_false(BoolVal(False))
1562  True
1563  """
1564  ctx = _get_ctx(ctx)
1565  if val == False:
1566  return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1567  else:
1568  return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1569 
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:1552

Referenced by AlgebraicNumRef.as_decimal(), Goal.as_expr(), ApplyResult.as_expr(), BoolSortRef.cast(), is_quantifier(), and Solver.to_smt2().

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

1596 def BoolVector(prefix, sz, ctx=None):
1597  """Return a list of Boolean constants of size `sz`.
1598 
1599  The constants are named using the given prefix.
1600  If `ctx=None`, then the global context is used.
1601 
1602  >>> P = BoolVector('p', 3)
1603  >>> P
1604  [p__0, p__1, p__2]
1605  >>> And(P)
1606  And(p__0, p__1, p__2)
1607  """
1608  return [ Bool('%s__%s' % (prefix, i)) for i in range(sz) ]
1609 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def BoolVector(prefix, sz, ctx=None)
Definition: z3py.py:1596
def Bool(name, ctx=None)
Definition: z3py.py:1570

◆ 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)
[x = 2, b = 1]

Definition at line 3714 of file z3py.py.

3714 def BV2Int(a, is_signed=False):
3715  """Return the Z3 expression BV2Int(a).
3716 
3717  >>> b = BitVec('b', 3)
3718  >>> BV2Int(b).sort()
3719  Int
3720  >>> x = Int('x')
3721  >>> x > BV2Int(b)
3722  x > BV2Int(b)
3723  >>> x > BV2Int(b, is_signed=False)
3724  x > BV2Int(b)
3725  >>> x > BV2Int(b, is_signed=True)
3726  x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3727  >>> solve(x > BV2Int(b), b == 1, x < 3)
3728  [x = 2, b = 1]
3729  """
3730  if z3_debug():
3731  _z3_assert(is_bv(a), "Z3 bit-vector expression expected")
3732  ctx = a.ctx
3733 
3734  return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
3735 
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast t1, 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 z3_debug()
Definition: z3py.py:58
def BV2Int(a, is_signed=False)
Definition: z3py.py:3714
def is_bv(a)
Definition: z3py.py:3687

◆ BVAddNoOverflow()

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

Definition at line 4169 of file z3py.py.

4169 def BVAddNoOverflow(a, b, signed):
4170  """A predicate the determines that bit-vector addition does not overflow"""
4171  _check_bv_args(a, b)
4172  a, b = _coerce_exprs(a, b)
4173  return BoolRef(Z3_mk_bvadd_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4174 
def BVAddNoOverflow(a, b, signed)
Definition: z3py.py:4169
Z3_ast Z3_API Z3_mk_bvadd_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, 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 4175 of file z3py.py.

4175 def BVAddNoUnderflow(a, b):
4176  """A predicate the determines that signed bit-vector addition does not underflow"""
4177  _check_bv_args(a, b)
4178  a, b = _coerce_exprs(a, b)
4179  return BoolRef(Z3_mk_bvadd_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4180 
def BVAddNoUnderflow(a, b)
Definition: z3py.py:4175
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 4206 of file z3py.py.

4206 def BVMulNoOverflow(a, b, signed):
4207  """A predicate the determines that bit-vector multiplication does not overflow"""
4208  _check_bv_args(a, b)
4209  a, b = _coerce_exprs(a, b)
4210  return BoolRef(Z3_mk_bvmul_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4211 
4212 
def BVMulNoOverflow(a, b, signed)
Definition: z3py.py:4206
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise multiplication of t1 and t2 does not overflow.

◆ BVMulNoUnderflow()

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

Definition at line 4213 of file z3py.py.

4213 def BVMulNoUnderflow(a, b):
4214  """A predicate the determines that bit-vector signed multiplication does not underflow"""
4215  _check_bv_args(a, b)
4216  a, b = _coerce_exprs(a, b)
4217  return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4218 
4219 
4220 
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:4213

◆ BVRedAnd()

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

Definition at line 4157 of file z3py.py.

4157 def BVRedAnd(a):
4158  """Return the reduction-and expression of `a`."""
4159  if z3_debug():
4160  _z3_assert(is_bv(a), "First argument must be a Z3 Bitvector expression")
4161  return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
4162 
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:4157
def z3_debug()
Definition: z3py.py:58
def is_bv(a)
Definition: z3py.py:3687

◆ BVRedOr()

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

Definition at line 4163 of file z3py.py.

4163 def BVRedOr(a):
4164  """Return the reduction-or expression of `a`."""
4165  if z3_debug():
4166  _z3_assert(is_bv(a), "First argument must be a Z3 Bitvector expression")
4167  return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
4168 
def BVRedOr(a)
Definition: z3py.py:4163
def z3_debug()
Definition: z3py.py:58
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:3687

◆ BVSDivNoOverflow()

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

Definition at line 4194 of file z3py.py.

4194 def BVSDivNoOverflow(a, b):
4195  """A predicate the determines that bit-vector signed division does not overflow"""
4196  _check_bv_args(a, b)
4197  a, b = _coerce_exprs(a, b)
4198  return BoolRef(Z3_mk_bvsdiv_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4199 
def BVSDivNoOverflow(a, b)
Definition: z3py.py:4194
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 4200 of file z3py.py.

4200 def BVSNegNoOverflow(a):
4201  """A predicate the determines that bit-vector unary negation does not overflow"""
4202  if z3_debug():
4203  _z3_assert(is_bv(a), "Argument should be a bit-vector")
4204  return BoolRef(Z3_mk_bvneg_no_overflow(a.ctx_ref(), a.as_ast()), a.ctx)
4205 
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 z3_debug()
Definition: z3py.py:58
def BVSNegNoOverflow(a)
Definition: z3py.py:4200
def is_bv(a)
Definition: z3py.py:3687

◆ BVSubNoOverflow()

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

Definition at line 4181 of file z3py.py.

4181 def BVSubNoOverflow(a, b):
4182  """A predicate the determines that bit-vector subtraction does not overflow"""
4183  _check_bv_args(a, b)
4184  a, b = _coerce_exprs(a, b)
4185  return BoolRef(Z3_mk_bvsub_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4186 
4187 
def BVSubNoOverflow(a, b)
Definition: z3py.py:4181
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 4188 of file z3py.py.

4188 def BVSubNoUnderflow(a, b, signed):
4189  """A predicate the determines that bit-vector subtraction does not underflow"""
4190  _check_bv_args(a, b)
4191  a, b = _coerce_exprs(a, b)
4192  return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4193 
def BVSubNoUnderflow(a, b, signed)
Definition: z3py.py:4188
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, 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 3176 of file z3py.py.

3176 def Cbrt(a, ctx=None):
3177  """ Return a Z3 expression which represents the cubic root of a.
3178 
3179  >>> x = Real('x')
3180  >>> Cbrt(x)
3181  x**(1/3)
3182  """
3183  if not is_expr(a):
3184  ctx = _get_ctx(ctx)
3185  a = RealVal(a, ctx)
3186  return a ** "1/3"
3187 
def Cbrt(a, ctx=None)
Definition: z3py.py:3176
def RealVal(val, ctx=None)
Definition: z3py.py:2969
def is_expr(a)
Definition: z3py.py:1117

◆ Complement()

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

Definition at line 10388 of file z3py.py.

10388 def Complement(re):
10389  """Create the complement regular expression."""
10390  return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
10391 
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:10388

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

3817 def Concat(*args):
3818  """Create a Z3 bit-vector concatenation expression.
3819 
3820  >>> v = BitVecVal(1, 4)
3821  >>> Concat(v, v+1, v)
3822  Concat(Concat(1, 1 + 1), 1)
3823  >>> simplify(Concat(v, v+1, v))
3824  289
3825  >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
3826  121
3827  """
3828  args = _get_args(args)
3829  sz = len(args)
3830  if z3_debug():
3831  _z3_assert(sz >= 2, "At least two arguments expected.")
3832 
3833  ctx = None
3834  for a in args:
3835  if is_expr(a):
3836  ctx = a.ctx
3837  break
3838  if is_seq(args[0]) or isinstance(args[0], str):
3839  args = [_coerce_seq(s, ctx) for s in args]
3840  if z3_debug():
3841  _z3_assert(all([is_seq(a) for a in args]), "All arguments must be sequence expressions.")
3842  v = (Ast * sz)()
3843  for i in range(sz):
3844  v[i] = args[i].as_ast()
3845  return SeqRef(Z3_mk_seq_concat(ctx.ref(), sz, v), ctx)
3846 
3847  if is_re(args[0]):
3848  if z3_debug():
3849  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
3850  v = (Ast * sz)()
3851  for i in range(sz):
3852  v[i] = args[i].as_ast()
3853  return ReRef(Z3_mk_re_concat(ctx.ref(), sz, v), ctx)
3854 
3855  if z3_debug():
3856  _z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.")
3857  r = args[0]
3858  for i in range(sz - 1):
3859  r = BitVecRef(Z3_mk_concat(ctx.ref(), r.as_ast(), args[i+1].as_ast()), ctx)
3860  return r
3861 
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:3370
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:10311
def Concat(*args)
Definition: z3py.py:3817
def z3_debug()
Definition: z3py.py:58
def is_expr(a)
Definition: z3py.py:1117
def is_bv(a)
Definition: z3py.py:3687
def is_seq(a)
Definition: z3py.py:10056

Referenced by SeqRef.__add__(), and SeqRef.__radd__().

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

8168 def Cond(p, t1, t2, ctx=None):
8169  """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8170 
8171  >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8172  """
8173  p = _to_probe(p, ctx)
8174  t1 = _to_tactic(t1, ctx)
8175  t2 = _to_tactic(t2, ctx)
8176  return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
8177 
def Cond(p, t1, t2, ctx=None)
Definition: z3py.py:8168
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...

Referenced by If().

◆ Const()

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

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

Definition at line 1303 of file z3py.py.

1303 def Const(name, sort):
1304  """Create a constant of the given sort.
1305 
1306  >>> Const('x', IntSort())
1307  x
1308  """
1309  if z3_debug():
1310  _z3_assert(isinstance(sort, SortRef), "Z3 sort expected")
1311  ctx = sort.ctx
1312  return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
1313 
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:111
def Const(name, sort)
Definition: z3py.py:1303
def z3_debug()
Definition: z3py.py:58

Referenced by Consts().

◆ Consts()

def z3py.Consts (   names,
  sort 
)
Create 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 1314 of file z3py.py.

1314 def Consts(names, sort):
1315  """Create several constants of the given sort.
1316 
1317  `names` is a string containing the names of all constants to be created.
1318  Blank spaces separate the names of different constants.
1319 
1320  >>> x, y, z = Consts('x y z', IntSort())
1321  >>> x + y + z
1322  x + y + z
1323  """
1324  if isinstance(names, str):
1325  names = names.split(" ")
1326  return [Const(name, sort) for name in names]
1327 
def Consts(names, sort)
Definition: z3py.py:1314
def Const(name, sort)
Definition: z3py.py:1303

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

10182 def Contains(a, b):
10183  """Check if 'a' contains 'b'
10184  >>> s1 = Contains("abc", "ab")
10185  >>> simplify(s1)
10186  True
10187  >>> s2 = Contains("abc", "bc")
10188  >>> simplify(s2)
10189  True
10190  >>> x, y, z = Strings('x y z')
10191  >>> s3 = Contains(Concat(x,y,z), y)
10192  >>> simplify(s3)
10193  True
10194  """
10195  ctx = _get_ctx2(a, b)
10196  a = _coerce_seq(a, ctx)
10197  b = _coerce_seq(b, ctx)
10198  return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
10199 
10200 
def Contains(a, b)
Definition: z3py.py:10182
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 4786 of file z3py.py.

4786 def CreateDatatypes(*ds):
4787  """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
4788 
4789  In the following example we define a Tree-List using two mutually recursive datatypes.
4790 
4791  >>> TreeList = Datatype('TreeList')
4792  >>> Tree = Datatype('Tree')
4793  >>> # Tree has two constructors: leaf and node
4794  >>> Tree.declare('leaf', ('val', IntSort()))
4795  >>> # a node contains a list of trees
4796  >>> Tree.declare('node', ('children', TreeList))
4797  >>> TreeList.declare('nil')
4798  >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
4799  >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
4800  >>> Tree.val(Tree.leaf(10))
4801  val(leaf(10))
4802  >>> simplify(Tree.val(Tree.leaf(10)))
4803  10
4804  >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
4805  >>> n1
4806  node(cons(leaf(10), cons(leaf(20), nil)))
4807  >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
4808  >>> simplify(n2 == n1)
4809  False
4810  >>> simplify(TreeList.car(Tree.children(n2)) == n1)
4811  True
4812  """
4813  ds = _get_args(ds)
4814  if z3_debug():
4815  _z3_assert(len(ds) > 0, "At least one Datatype must be specified")
4816  _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
4817  _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
4818  _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
4819  ctx = ds[0].ctx
4820  num = len(ds)
4821  names = (Symbol * num)()
4822  out = (Sort * num)()
4823  clists = (ConstructorList * num)()
4824  to_delete = []
4825  for i in range(num):
4826  d = ds[i]
4827  names[i] = to_symbol(d.name, ctx)
4828  num_cs = len(d.constructors)
4829  cs = (Constructor * num_cs)()
4830  for j in range(num_cs):
4831  c = d.constructors[j]
4832  cname = to_symbol(c[0], ctx)
4833  rname = to_symbol(c[1], ctx)
4834  fs = c[2]
4835  num_fs = len(fs)
4836  fnames = (Symbol * num_fs)()
4837  sorts = (Sort * num_fs)()
4838  refs = (ctypes.c_uint * num_fs)()
4839  for k in range(num_fs):
4840  fname = fs[k][0]
4841  ftype = fs[k][1]
4842  fnames[k] = to_symbol(fname, ctx)
4843  if isinstance(ftype, Datatype):
4844  if z3_debug():
4845  _z3_assert(ds.count(ftype) == 1, "One and only one occurrence of each datatype is expected")
4846  sorts[k] = None
4847  refs[k] = ds.index(ftype)
4848  else:
4849  if z3_debug():
4850  _z3_assert(is_sort(ftype), "Z3 sort expected")
4851  sorts[k] = ftype.ast
4852  refs[k] = 0
4853  cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
4854  to_delete.append(ScopedConstructor(cs[j], ctx))
4855  clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs)
4856  to_delete.append(ScopedConstructorList(clists[i], ctx))
4857  Z3_mk_datatypes(ctx.ref(), num, names, out, clists)
4858  result = []
4859 
4860  for i in range(num):
4861  dref = DatatypeSortRef(out[i], ctx)
4862  num_cs = dref.num_constructors()
4863  for j in range(num_cs):
4864  cref = dref.constructor(j)
4865  cref_name = cref.name()
4866  cref_arity = cref.arity()
4867  if cref.arity() == 0:
4868  cref = cref()
4869  setattr(dref, cref_name, cref)
4870  rref = dref.recognizer(j)
4871  setattr(dref, "is_" + cref_name, rref)
4872  for k in range(cref_arity):
4873  aref = dref.accessor(j, k)
4874  setattr(dref, aref.name(), aref)
4875  result.append(dref)
4876  return tuple(result)
4877 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def to_symbol(s, ctx=None)
Definition: z3py.py:111
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:4786
def is_sort(s)
Definition: z3py.py:598
def z3_debug()
Definition: z3py.py:58
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.

Referenced by Datatype.create().

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

639 def DeclareSort(name, ctx=None):
640  """Create a new uninterpreted sort named `name`.
641 
642  If `ctx=None`, then the new sort is declared in the global Z3Py context.
643 
644  >>> A = DeclareSort('A')
645  >>> a = Const('a', A)
646  >>> b = Const('b', A)
647  >>> a.sort() == A
648  True
649  >>> b.sort() == A
650  True
651  >>> a == b
652  a == b
653  """
654  ctx = _get_ctx(ctx)
655  return SortRef(Z3_mk_uninterpreted_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
656 
def to_symbol(s, ctx=None)
Definition: z3py.py:111
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:639

◆ Default()

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

Definition at line 4441 of file z3py.py.

4441 def Default(a):
4442  """ Return a default value for array expression.
4443  >>> b = K(IntSort(), 1)
4444  >>> prove(Default(b) == 1)
4445  proved
4446  """
4447  if z3_debug():
4448  _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4449  return a.default()
4450 
4451 
def is_array_sort(a)
Definition: z3py.py:4294
def Default(a)
Definition: z3py.py:4441
def z3_debug()
Definition: z3py.py:58

◆ describe_probes()

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

Definition at line 8098 of file z3py.py.

8098 def describe_probes():
8099  """Display a (tabular) description of all available probes in Z3."""
8100  if in_html_mode():
8101  even = True
8102  print('<table border="1" cellpadding="2" cellspacing="0">')
8103  for p in probes():
8104  if even:
8105  print('<tr style="background-color:#CFCFCF">')
8106  even = False
8107  else:
8108  print('<tr>')
8109  even = True
8110  print('<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(probe_description(p), 40)))
8111  print('</table>')
8112  else:
8113  for p in probes():
8114  print('%s : %s' % (p, probe_description(p)))
8115 
def probes(ctx=None)
Definition: z3py.py:8080
def probe_description(name, ctx=None)
Definition: z3py.py:8090
def describe_probes()
Definition: z3py.py:8098

◆ describe_tactics()

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

Definition at line 7907 of file z3py.py.

7907 def describe_tactics():
7908  """Display a (tabular) description of all available tactics in Z3."""
7909  if in_html_mode():
7910  even = True
7911  print('<table border="1" cellpadding="2" cellspacing="0">')
7912  for t in tactics():
7913  if even:
7914  print('<tr style="background-color:#CFCFCF">')
7915  even = False
7916  else:
7917  print('<tr>')
7918  even = True
7919  print('<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(tactic_description(t), 40)))
7920  print('</table>')
7921  else:
7922  for t in tactics():
7923  print('%s : %s' % (t, tactic_description(t)))
7924 
def tactics(ctx=None)
Definition: z3py.py:7889
def tactic_description(name, ctx=None)
Definition: z3py.py:7899
def describe_tactics()
Definition: z3py.py:7907

◆ disable_trace()

def z3py.disable_trace (   msg)

Definition at line 72 of file z3py.py.

72 def disable_trace(msg):
73  Z3_disable_trace(msg)
74 
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:72

◆ DisjointSum()

def z3py.DisjointSum (   name,
  sorts,
  ctx = None 
)
Create a named tagged union sort base on a set of underlying sorts
Example:
    >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])

Definition at line 4986 of file z3py.py.

4986 def DisjointSum(name, sorts, ctx=None):
4987  """Create a named tagged union sort base on a set of underlying sorts
4988  Example:
4989  >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
4990  """
4991  sum = Datatype(name, ctx)
4992  for i in range(len(sorts)):
4993  sum.declare("inject%d" % i, ("project%d" % i, sorts[i]))
4994  sum = sum.create()
4995  return sum, [(sum.constructor(i), sum.accessor(i, 0)) for i in range(len(sorts))]
4996 
4997 
def DisjointSum(name, sorts, ctx=None)
Definition: z3py.py:4986
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370

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

1272 def Distinct(*args):
1273  """Create a Z3 distinct expression.
1274 
1275  >>> x = Int('x')
1276  >>> y = Int('y')
1277  >>> Distinct(x, y)
1278  x != y
1279  >>> z = Int('z')
1280  >>> Distinct(x, y, z)
1281  Distinct(x, y, z)
1282  >>> simplify(Distinct(x, y, z))
1283  Distinct(x, y, z)
1284  >>> simplify(Distinct(x, y, z), blast_distinct=True)
1285  And(Not(x == y), Not(x == z), Not(y == z))
1286  """
1287  args = _get_args(args)
1288  ctx = _ctx_from_ast_arg_list(args)
1289  if z3_debug():
1290  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
1291  args = _coerce_expr_list(args, ctx)
1292  _args, sz = _to_ast_array(args)
1293  return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
1294 
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:1272
def z3_debug()
Definition: z3py.py:58

◆ Empty()

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

Definition at line 10117 of file z3py.py.

10117 def Empty(s):
10118  """Create the empty sequence of the given sort
10119  >>> e = Empty(StringSort())
10120  >>> e2 = StringVal("")
10121  >>> print(e.eq(e2))
10122  True
10123  >>> e3 = Empty(SeqSort(IntSort()))
10124  >>> print(e3)
10125  Empty(Seq(Int))
10126  >>> e4 = Empty(ReSort(SeqSort(IntSort())))
10127  >>> print(e4)
10128  Empty(ReSort(Seq(Int)))
10129  """
10130  if isinstance(s, SeqSortRef):
10131  return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
10132  if isinstance(s, ReSortRef):
10133  return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
10134  raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
10135 
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:10117

◆ EmptySet()

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

Definition at line 4576 of file z3py.py.

4576 def EmptySet(s):
4577  """Create the empty set
4578  >>> EmptySet(IntSort())
4579  K(Int, False)
4580  """
4581  ctx = s.ctx
4582  return ArrayRef(Z3_mk_empty_set(ctx.ref(), s.ast), ctx)
4583 
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
def EmptySet(s)
Definition: z3py.py:4576

◆ enable_trace()

def z3py.enable_trace (   msg)

Definition at line 69 of file z3py.py.

69 def enable_trace(msg):
70  Z3_enable_trace(msg)
71 
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:69

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

4998 def EnumSort(name, values, ctx=None):
4999  """Return a new enumeration sort named `name` containing the given values.
5000 
5001  The result is a pair (sort, list of constants).
5002  Example:
5003  >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5004  """
5005  if z3_debug():
5006  _z3_assert(isinstance(name, str), "Name must be a string")
5007  _z3_assert(all([isinstance(v, str) for v in values]), "Eumeration sort values must be strings")
5008  _z3_assert(len(values) > 0, "At least one value expected")
5009  ctx = _get_ctx(ctx)
5010  num = len(values)
5011  _val_names = (Symbol * num)()
5012  for i in range(num):
5013  _val_names[i] = to_symbol(values[i])
5014  _values = (FuncDecl * num)()
5015  _testers = (FuncDecl * num)()
5016  name = to_symbol(name)
5017  S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
5018  V = []
5019  for i in range(num):
5020  V.append(FuncDeclRef(_values[i], ctx))
5021  V = [a() for a in V]
5022  return S, V
5023 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def to_symbol(s, ctx=None)
Definition: z3py.py:111
def z3_debug()
Definition: z3py.py:58
def EnumSort(name, values, ctx=None)
Definition: z3py.py:4998
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.

Referenced by Context.mkEnumSort().

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

434 def eq(a, b):
435  """Return `True` if `a` and `b` are structurally identical AST nodes.
436 
437  >>> x = Int('x')
438  >>> y = Int('y')
439  >>> eq(x, y)
440  False
441  >>> eq(x + 1, x + 1)
442  True
443  >>> eq(x + 1, 1 + x)
444  False
445  >>> eq(simplify(x + 1), simplify(1 + x))
446  True
447  """
448  if z3_debug():
449  _z3_assert(is_ast(a) and is_ast(b), "Z3 ASTs expected")
450  return a.eq(b)
451 
def eq(a, b)
Definition: z3py.py:434
def z3_debug()
Definition: z3py.py:58
def is_ast(a)
Definition: z3py.py:414

Referenced by substitute().

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

2065 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2066  """Create a Z3 exists formula.
2067 
2068  The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2069 
2070 
2071  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2072  >>> x = Int('x')
2073  >>> y = Int('y')
2074  >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2075  >>> q
2076  Exists([x, y], f(x, y) >= x)
2077  >>> is_quantifier(q)
2078  True
2079  >>> r = Tactic('nnf')(q).as_expr()
2080  >>> is_quantifier(r)
2081  False
2082  """
2083  return _mk_quantifier(False, vs, body, weight, qid, skid, patterns, no_patterns)
2084 
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Definition: z3py.py:2065

Referenced by Fixedpoint.abstract().

◆ Ext()

def z3py.Ext (   a,
  b 
)
Return extensionality index for one-dimensional arrays.
>> a, b = Consts('a b', SetSort(IntSort()))
>> Ext(a, b)
Ext(a, b)

Definition at line 4526 of file z3py.py.

4526 def Ext(a, b):
4527  """Return extensionality index for one-dimensional arrays.
4528  >> a, b = Consts('a b', SetSort(IntSort()))
4529  >> Ext(a, b)
4530  Ext(a, b)
4531  """
4532  ctx = a.ctx
4533  if z3_debug():
4534  _z3_assert(is_array_sort(a) and is_array(b), "arguments must be arrays")
4535  return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4536 
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_sort(a)
Definition: z3py.py:4294
def is_array(a)
Definition: z3py.py:4298
def z3_debug()
Definition: z3py.py:58
def Ext(a, b)
Definition: z3py.py:4526

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

3862 def Extract(high, low, a):
3863  """Create a Z3 bit-vector extraction expression, or create a string extraction expression.
3864 
3865  >>> x = BitVec('x', 8)
3866  >>> Extract(6, 2, x)
3867  Extract(6, 2, x)
3868  >>> Extract(6, 2, x).sort()
3869  BitVec(5)
3870  >>> simplify(Extract(StringVal("abcd"),2,1))
3871  "c"
3872  """
3873  if isinstance(high, str):
3874  high = StringVal(high)
3875  if is_seq(high):
3876  s = high
3877  offset, length = _coerce_exprs(low, a, s.ctx)
3878  return SeqRef(Z3_mk_seq_extract(s.ctx_ref(), s.as_ast(), offset.as_ast(), length.as_ast()), s.ctx)
3879  if z3_debug():
3880  _z3_assert(low <= high, "First argument must be greater than or equal to second argument")
3881  _z3_assert(_is_int(high) and high >= 0 and _is_int(low) and low >= 0, "First and second arguments must be non negative integers")
3882  _z3_assert(is_bv(a), "Third argument must be a Z3 Bitvector expression")
3883  return BitVecRef(Z3_mk_extract(a.ctx_ref(), high, low, a.as_ast()), a.ctx)
3884 
def Extract(high, low, a)
Definition: z3py.py:3862
def StringVal(s, ctx=None)
Definition: z3py.py:10082
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.
def z3_debug()
Definition: z3py.py:58
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:3687
def is_seq(a)
Definition: z3py.py:10056

Referenced by SubSeq(), and SubString().

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

8131 def FailIf(p, ctx=None):
8132  """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8133 
8134  In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal.
8135 
8136  >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8137  >>> x, y = Ints('x y')
8138  >>> g = Goal()
8139  >>> g.add(x > 0)
8140  >>> g.add(y > 0)
8141  >>> t(g)
8142  [[x > 0, y > 0]]
8143  >>> g.add(x == y + 1)
8144  >>> t(g)
8145  [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8146  """
8147  p = _to_probe(p, ctx)
8148  return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
8149 
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:8131

◆ FiniteDomainSort()

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

Definition at line 7223 of file z3py.py.

7223 def FiniteDomainSort(name, sz, ctx=None):
7224  """Create a named finite domain sort of a given size sz"""
7225  if not isinstance(name, Symbol):
7226  name = to_symbol(name)
7227  ctx = _get_ctx(ctx)
7228  return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
7229 
def to_symbol(s, ctx=None)
Definition: z3py.py:111
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:7223

Referenced by Context.mkFiniteDomainSort().

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

7291 def FiniteDomainVal(val, sort, ctx=None):
7292  """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7293 
7294  >>> s = FiniteDomainSort('S', 256)
7295  >>> FiniteDomainVal(255, s)
7296  255
7297  >>> FiniteDomainVal('100', s)
7298  100
7299  """
7300  if z3_debug():
7301  _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort" )
7302  ctx = sort.ctx
7303  return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
7304 
def is_finite_domain_sort(s)
Definition: z3py.py:7230
def FiniteDomainVal(val, sort, ctx=None)
Definition: z3py.py:7291
def z3_debug()
Definition: z3py.py:58
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 8761 of file z3py.py.

8761 def Float128(ctx=None):
8762  """Floating-point 128-bit (quadruple) sort."""
8763  ctx = _get_ctx(ctx)
8764  return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
8765 
def Float128(ctx=None)
Definition: z3py.py:8761
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 8731 of file z3py.py.

8731 def Float16(ctx=None):
8732  """Floating-point 16-bit (half) sort."""
8733  ctx = _get_ctx(ctx)
8734  return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
8735 
def Float16(ctx=None)
Definition: z3py.py:8731
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 8741 of file z3py.py.

8741 def Float32(ctx=None):
8742  """Floating-point 32-bit (single) sort."""
8743  ctx = _get_ctx(ctx)
8744  return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
8745 
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:8741

◆ Float64()

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

Definition at line 8751 of file z3py.py.

8751 def Float64(ctx=None):
8752  """Floating-point 64-bit (double) sort."""
8753  ctx = _get_ctx(ctx)
8754  return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
8755 
def Float64(ctx=None)
Definition: z3py.py:8751
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 8756 of file z3py.py.

8756 def FloatDouble(ctx=None):
8757  """Floating-point 64-bit (double) sort."""
8758  ctx = _get_ctx(ctx)
8759  return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
8760 
def FloatDouble(ctx=None)
Definition: z3py.py:8756
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 8736 of file z3py.py.

8736 def FloatHalf(ctx=None):
8737  """Floating-point 16-bit (half) sort."""
8738  ctx = _get_ctx(ctx)
8739  return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
8740 
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:8736

◆ FloatQuadruple()

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

Definition at line 8766 of file z3py.py.

8766 def FloatQuadruple(ctx=None):
8767  """Floating-point 128-bit (quadruple) sort."""
8768  ctx = _get_ctx(ctx)
8769  return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
8770 
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:8766

◆ FloatSingle()

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

Definition at line 8746 of file z3py.py.

8746 def FloatSingle(ctx=None):
8747  """Floating-point 32-bit (single) sort."""
8748  ctx = _get_ctx(ctx)
8749  return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
8750 
def FloatSingle(ctx=None)
Definition: z3py.py:8746
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`, `qid`, `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 2048 of file z3py.py.

2048 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2049  """Create a Z3 forall formula.
2050 
2051  The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2052 
2053  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2054  >>> x = Int('x')
2055  >>> y = Int('y')
2056  >>> ForAll([x, y], f(x, y) >= x)
2057  ForAll([x, y], f(x, y) >= x)
2058  >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2059  ForAll([x, y], f(x, y) >= x)
2060  >>> ForAll([x, y], f(x, y) >= x, weight=10)
2061  ForAll([x, y], f(x, y) >= x)
2062  """
2063  return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
2064 
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Definition: z3py.py:2048

Referenced by Fixedpoint.abstract().

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

9346 def FP(name, fpsort, ctx=None):
9347  """Return a floating-point constant named `name`.
9348  `fpsort` is the floating-point sort.
9349  If `ctx=None`, then the global context is used.
9350 
9351  >>> x = FP('x', FPSort(8, 24))
9352  >>> is_fp(x)
9353  True
9354  >>> x.ebits()
9355  8
9356  >>> x.sort()
9357  FPSort(8, 24)
9358  >>> word = FPSort(8, 24)
9359  >>> x2 = FP('x', word)
9360  >>> eq(x, x2)
9361  True
9362  """
9363  if isinstance(fpsort, FPSortRef) and ctx is None:
9364  ctx = fpsort.ctx
9365  else:
9366  ctx = _get_ctx(ctx)
9367  return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
9368 
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:111
def FP(name, fpsort, ctx=None)
Definition: z3py.py:9346

Referenced by FPs().

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

9387 def fpAbs(a, ctx=None):
9388  """Create a Z3 floating-point absolute value expression.
9389 
9390  >>> s = FPSort(8, 24)
9391  >>> rm = RNE()
9392  >>> x = FPVal(1.0, s)
9393  >>> fpAbs(x)
9394  fpAbs(1)
9395  >>> y = FPVal(-20.0, s)
9396  >>> y
9397  -1.25*(2**4)
9398  >>> fpAbs(y)
9399  fpAbs(-1.25*(2**4))
9400  >>> fpAbs(-1.25*(2**4))
9401  fpAbs(-1.25*(2**4))
9402  >>> fpAbs(x).sort()
9403  FPSort(8, 24)
9404  """
9405  ctx = _get_ctx(ctx)
9406  [a] = _coerce_fp_expr_list([a], ctx)
9407  return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
9408 
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:9387

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

9469 def fpAdd(rm, a, b, ctx=None):
9470  """Create a Z3 floating-point addition expression.
9471 
9472  >>> s = FPSort(8, 24)
9473  >>> rm = RNE()
9474  >>> x = FP('x', s)
9475  >>> y = FP('y', s)
9476  >>> fpAdd(rm, x, y)
9477  fpAdd(RNE(), x, y)
9478  >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
9479  x + y
9480  >>> fpAdd(rm, x, y).sort()
9481  FPSort(8, 24)
9482  """
9483  return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
9484 
def fpAdd(rm, a, b, ctx=None)
Definition: z3py.py:9469

Referenced by FPRef.__add__(), and FPRef.__radd__().

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

9765 def fpBVToFP(v, sort, ctx=None):
9766  """Create a Z3 floating-point conversion expression that represents the
9767  conversion from a bit-vector term to a floating-point term.
9768 
9769  >>> x_bv = BitVecVal(0x3F800000, 32)
9770  >>> x_fp = fpBVToFP(x_bv, Float32())
9771  >>> x_fp
9772  fpToFP(1065353216)
9773  >>> simplify(x_fp)
9774  1
9775  """
9776  _z3_assert(is_bv(v), "First argument must be a Z3 floating-point rounding mode expression.")
9777  _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
9778  ctx = _get_ctx(ctx)
9779  return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
9780 
def fpBVToFP(v, sort, ctx=None)
Definition: z3py.py:9765
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:8775
def is_bv(a)
Definition: z3py.py:3687

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

9513 def fpDiv(rm, a, b, ctx=None):
9514  """Create a Z3 floating-point division expression.
9515 
9516  >>> s = FPSort(8, 24)
9517  >>> rm = RNE()
9518  >>> x = FP('x', s)
9519  >>> y = FP('y', s)
9520  >>> fpDiv(rm, x, y)
9521  fpDiv(RNE(), x, y)
9522  >>> fpDiv(rm, x, y).sort()
9523  FPSort(8, 24)
9524  """
9525  return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
9526 
def fpDiv(rm, a, b, ctx=None)
Definition: z3py.py:9513

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

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

9677 def fpEQ(a, b, ctx=None):
9678  """Create the Z3 floating-point expression `fpEQ(other, self)`.
9679 
9680  >>> x, y = FPs('x y', FPSort(8, 24))
9681  >>> fpEQ(x, y)
9682  fpEQ(x, y)
9683  >>> fpEQ(x, y).sexpr()
9684  '(fp.eq x y)'
9685  """
9686  return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
9687 
def fpEQ(a, b, ctx=None)
Definition: z3py.py:9677

Referenced by fpNEQ().

◆ fpFMA()

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

Definition at line 9568 of file z3py.py.

9568 def fpFMA(rm, a, b, c, ctx=None):
9569  """Create a Z3 floating-point fused multiply-add expression.
9570  """
9571  return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
9572 
def fpFMA(rm, a, b, c, ctx=None)
Definition: z3py.py:9568

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

9699 def fpFP(sgn, exp, sig, ctx=None):
9700  """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
9701 
9702  >>> s = FPSort(8, 24)
9703  >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
9704  >>> print(x)
9705  fpFP(1, 127, 4194304)
9706  >>> xv = FPVal(-1.5, s)
9707  >>> print(xv)
9708  -1.5
9709  >>> slvr = Solver()
9710  >>> slvr.add(fpEQ(x, xv))
9711  >>> slvr.check()
9712  sat
9713  >>> xv = FPVal(+1.5, s)
9714  >>> print(xv)
9715  1.5
9716  >>> slvr = Solver()
9717  >>> slvr.add(fpEQ(x, xv))
9718  >>> slvr.check()
9719  unsat
9720  """
9721  _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
9722  _z3_assert(sgn.sort().size() == 1, "sort mismatch")
9723  ctx = _get_ctx(ctx)
9724  _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
9725  return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
9726 
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:9699
def is_bv(a)
Definition: z3py.py:3687

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

9781 def fpFPToFP(rm, v, sort, ctx=None):
9782  """Create a Z3 floating-point conversion expression that represents the
9783  conversion from a floating-point term to a floating-point term of different precision.
9784 
9785  >>> x_sgl = FPVal(1.0, Float32())
9786  >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
9787  >>> x_dbl
9788  fpToFP(RNE(), 1)
9789  >>> simplify(x_dbl)
9790  1
9791  >>> x_dbl.sort()
9792  FPSort(11, 53)
9793  """
9794  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9795  _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
9796  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9797  ctx = _get_ctx(ctx)
9798  return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9799 
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:8775
def fpFPToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9781
def is_fprm(a)
Definition: z3py.py:9022
def is_fp(a)
Definition: z3py.py:9158

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

9666 def fpGEQ(a, b, ctx=None):
9667  """Create the Z3 floating-point expression `other >= self`.
9668 
9669  >>> x, y = FPs('x y', FPSort(8, 24))
9670  >>> fpGEQ(x, y)
9671  x >= y
9672  >>> (x >= y).sexpr()
9673  '(fp.geq x y)'
9674  """
9675  return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
9676 
def fpGEQ(a, b, ctx=None)
Definition: z3py.py:9666

Referenced by FPRef.__ge__().

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

9655 def fpGT(a, b, ctx=None):
9656  """Create the Z3 floating-point expression `other > self`.
9657 
9658  >>> x, y = FPs('x y', FPSort(8, 24))
9659  >>> fpGT(x, y)
9660  x > y
9661  >>> (x > y).sexpr()
9662  '(fp.gt x y)'
9663  """
9664  return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
9665 
def fpGT(a, b, ctx=None)
Definition: z3py.py:9655

Referenced by FPRef.__gt__().

◆ fpInfinity()

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

Definition at line 9280 of file z3py.py.

9280 def fpInfinity(s, negative):
9281  """Create a Z3 floating-point +oo or -oo term."""
9282  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9283  _z3_assert(isinstance(negative, bool), "expected Boolean flag")
9284  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
9285 
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.
def fpInfinity(s, negative)
Definition: z3py.py:9280

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

9594 def fpIsInf(a, ctx=None):
9595  """Create a Z3 floating-point isInfinite expression.
9596 
9597  >>> s = FPSort(8, 24)
9598  >>> x = FP('x', s)
9599  >>> fpIsInf(x)
9600  fpIsInf(x)
9601  """
9602  return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
9603 
def fpIsInf(a, ctx=None)
Definition: z3py.py:9594

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

9583 def fpIsNaN(a, ctx=None):
9584  """Create a Z3 floating-point isNaN expression.
9585 
9586  >>> s = FPSort(8, 24)
9587  >>> x = FP('x', s)
9588  >>> y = FP('y', s)
9589  >>> fpIsNaN(x)
9590  fpIsNaN(x)
9591  """
9592  return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
9593 
def fpIsNaN(a, ctx=None)
Definition: z3py.py:9583

◆ fpIsNegative()

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

Definition at line 9619 of file z3py.py.

9619 def fpIsNegative(a, ctx=None):
9620  """Create a Z3 floating-point isNegative expression.
9621  """
9622  return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
9623 
def fpIsNegative(a, ctx=None)
Definition: z3py.py:9619

◆ fpIsNormal()

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

Definition at line 9609 of file z3py.py.

9609 def fpIsNormal(a, ctx=None):
9610  """Create a Z3 floating-point isNormal expression.
9611  """
9612  return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
9613 
def fpIsNormal(a, ctx=None)
Definition: z3py.py:9609

◆ fpIsPositive()

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

Definition at line 9624 of file z3py.py.

9624 def fpIsPositive(a, ctx=None):
9625  """Create a Z3 floating-point isPositive expression.
9626  """
9627  return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
9628 
def fpIsPositive(a, ctx=None)
Definition: z3py.py:9624

◆ fpIsSubnormal()

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

Definition at line 9614 of file z3py.py.

9614 def fpIsSubnormal(a, ctx=None):
9615  """Create a Z3 floating-point isSubnormal expression.
9616  """
9617  return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
9618 
def fpIsSubnormal(a, ctx=None)
Definition: z3py.py:9614

◆ fpIsZero()

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

Definition at line 9604 of file z3py.py.

9604 def fpIsZero(a, ctx=None):
9605  """Create a Z3 floating-point isZero expression.
9606  """
9607  return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
9608 
def fpIsZero(a, ctx=None)
Definition: z3py.py:9604

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

9644 def fpLEQ(a, b, ctx=None):
9645  """Create the Z3 floating-point expression `other <= self`.
9646 
9647  >>> x, y = FPs('x y', FPSort(8, 24))
9648  >>> fpLEQ(x, y)
9649  x <= y
9650  >>> (x <= y).sexpr()
9651  '(fp.leq x y)'
9652  """
9653  return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
9654 
def fpLEQ(a, b, ctx=None)
Definition: z3py.py:9644

Referenced by FPRef.__le__().

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

9633 def fpLT(a, b, ctx=None):
9634  """Create the Z3 floating-point expression `other < self`.
9635 
9636  >>> x, y = FPs('x y', FPSort(8, 24))
9637  >>> fpLT(x, y)
9638  x < y
9639  >>> (x < y).sexpr()
9640  '(fp.lt x y)'
9641  """
9642  return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
9643 
def fpLT(a, b, ctx=None)
Definition: z3py.py:9633

Referenced by FPRef.__lt__().

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

9554 def fpMax(a, b, ctx=None):
9555  """Create a Z3 floating-point maximum expression.
9556 
9557  >>> s = FPSort(8, 24)
9558  >>> rm = RNE()
9559  >>> x = FP('x', s)
9560  >>> y = FP('y', s)
9561  >>> fpMax(x, y)
9562  fpMax(x, y)
9563  >>> fpMax(x, y).sort()
9564  FPSort(8, 24)
9565  """
9566  return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
9567 
def fpMax(a, b, ctx=None)
Definition: z3py.py:9554

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

9540 def fpMin(a, b, ctx=None):
9541  """Create a Z3 floating-point minimum expression.
9542 
9543  >>> s = FPSort(8, 24)
9544  >>> rm = RNE()
9545  >>> x = FP('x', s)
9546  >>> y = FP('y', s)
9547  >>> fpMin(x, y)
9548  fpMin(x, y)
9549  >>> fpMin(x, y).sort()
9550  FPSort(8, 24)
9551  """
9552  return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
9553 
def fpMin(a, b, ctx=None)
Definition: z3py.py:9540

◆ fpMinusInfinity()

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

Definition at line 9275 of file z3py.py.

9275 def fpMinusInfinity(s):
9276  """Create a Z3 floating-point -oo term."""
9277  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9278  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
9279 
def fpMinusInfinity(s)
Definition: z3py.py:9275
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.

Referenced by FPVal().

◆ fpMinusZero()

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

Definition at line 9291 of file z3py.py.

9291 def fpMinusZero(s):
9292  """Create a Z3 floating-point -0.0 term."""
9293  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9294  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
9295 
def fpMinusZero(s)
Definition: z3py.py:9291
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.

Referenced by FPVal().

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

9499 def fpMul(rm, a, b, ctx=None):
9500  """Create a Z3 floating-point multiplication expression.
9501 
9502  >>> s = FPSort(8, 24)
9503  >>> rm = RNE()
9504  >>> x = FP('x', s)
9505  >>> y = FP('y', s)
9506  >>> fpMul(rm, x, y)
9507  fpMul(RNE(), x, y)
9508  >>> fpMul(rm, x, y).sort()
9509  FPSort(8, 24)
9510  """
9511  return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
9512 
def fpMul(rm, a, b, ctx=None)
Definition: z3py.py:9499

Referenced by FPRef.__mul__(), and FPRef.__rmul__().

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

9243 def fpNaN(s):
9244  """Create a Z3 floating-point NaN term.
9245 
9246  >>> s = FPSort(8, 24)
9247  >>> set_fpa_pretty(True)
9248  >>> fpNaN(s)
9249  NaN
9250  >>> pb = get_fpa_pretty()
9251  >>> set_fpa_pretty(False)
9252  >>> fpNaN(s)
9253  fpNaN(FPSort(8, 24))
9254  >>> set_fpa_pretty(pb)
9255  """
9256  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9257  return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
9258 
def fpNaN(s)
Definition: z3py.py:9243
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.

Referenced by FPVal().

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

9409 def fpNeg(a, ctx=None):
9410  """Create a Z3 floating-point addition expression.
9411 
9412  >>> s = FPSort(8, 24)
9413  >>> rm = RNE()
9414  >>> x = FP('x', s)
9415  >>> fpNeg(x)
9416  -x
9417  >>> fpNeg(x).sort()
9418  FPSort(8, 24)
9419  """
9420  ctx = _get_ctx(ctx)
9421  [a] = _coerce_fp_expr_list([a], ctx)
9422  return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
9423 
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:9409

Referenced by FPRef.__neg__().

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

9688 def fpNEQ(a, b, ctx=None):
9689  """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
9690 
9691  >>> x, y = FPs('x y', FPSort(8, 24))
9692  >>> fpNEQ(x, y)
9693  Not(fpEQ(x, y))
9694  >>> (x != y).sexpr()
9695  '(distinct x y)'
9696  """
9697  return Not(fpEQ(a, b, ctx))
9698 
def fpEQ(a, b, ctx=None)
Definition: z3py.py:9677
def Not(a, ctx=None)
Definition: z3py.py:1653
def fpNEQ(a, b, ctx=None)
Definition: z3py.py:9688

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

9259 def fpPlusInfinity(s):
9260  """Create a Z3 floating-point +oo term.
9261 
9262  >>> s = FPSort(8, 24)
9263  >>> pb = get_fpa_pretty()
9264  >>> set_fpa_pretty(True)
9265  >>> fpPlusInfinity(s)
9266  +oo
9267  >>> set_fpa_pretty(False)
9268  >>> fpPlusInfinity(s)
9269  fpPlusInfinity(FPSort(8, 24))
9270  >>> set_fpa_pretty(pb)
9271  """
9272  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9273  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
9274 
def fpPlusInfinity(s)
Definition: z3py.py:9259
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.

Referenced by FPVal().

◆ fpPlusZero()

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

Definition at line 9286 of file z3py.py.

9286 def fpPlusZero(s):
9287  """Create a Z3 floating-point +0.0 term."""
9288  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9289  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
9290 
def fpPlusZero(s)
Definition: z3py.py:9286
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.

Referenced by FPVal().

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

9800 def fpRealToFP(rm, v, sort, ctx=None):
9801  """Create a Z3 floating-point conversion expression that represents the
9802  conversion from a real term to a floating-point term.
9803 
9804  >>> x_r = RealVal(1.5)
9805  >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
9806  >>> x_fp
9807  fpToFP(RNE(), 3/2)
9808  >>> simplify(x_fp)
9809  1.5
9810  """
9811  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9812  _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
9813  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9814  ctx = _get_ctx(ctx)
9815  return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9816 
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:2519
def is_fp_sort(s)
Definition: z3py.py:8775
def fpRealToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9800
def is_fprm(a)
Definition: z3py.py:9022

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

9527 def fpRem(a, b, ctx=None):
9528  """Create a Z3 floating-point remainder expression.
9529 
9530  >>> s = FPSort(8, 24)
9531  >>> x = FP('x', s)
9532  >>> y = FP('y', s)
9533  >>> fpRem(x, y)
9534  fpRem(x, y)
9535  >>> fpRem(x, y).sort()
9536  FPSort(8, 24)
9537  """
9538  return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
9539 
def fpRem(a, b, ctx=None)
Definition: z3py.py:9527

Referenced by FPRef.__mod__(), and FPRef.__rmod__().

◆ fpRoundToIntegral()

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

Definition at line 9578 of file z3py.py.

9578 def fpRoundToIntegral(rm, a, ctx=None):
9579  """Create a Z3 floating-point roundToIntegral expression.
9580  """
9581  return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
9582 
def fpRoundToIntegral(rm, a, ctx=None)
Definition: z3py.py:9578

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

9369 def FPs(names, fpsort, ctx=None):
9370  """Return an array of floating-point constants.
9371 
9372  >>> x, y, z = FPs('x y z', FPSort(8, 24))
9373  >>> x.sort()
9374  FPSort(8, 24)
9375  >>> x.sbits()
9376  24
9377  >>> x.ebits()
9378  8
9379  >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
9380  fpMul(RNE(), fpAdd(RNE(), x, y), z)
9381  """
9382  ctx = _get_ctx(ctx)
9383  if isinstance(names, str):
9384  names = names.split(" ")
9385  return [FP(name, fpsort, ctx) for name in names]
9386 
def FPs(names, fpsort, ctx=None)
Definition: z3py.py:9369
def FP(name, fpsort, ctx=None)
Definition: z3py.py:9346

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

9817 def fpSignedToFP(rm, v, sort, ctx=None):
9818  """Create a Z3 floating-point conversion expression that represents the
9819  conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
9820 
9821  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9822  >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
9823  >>> x_fp
9824  fpToFP(RNE(), 4294967291)
9825  >>> simplify(x_fp)
9826  -1.25*(2**2)
9827  """
9828  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9829  _z3_assert(is_bv(v), "Second argument must be a Z3 expression or real sort.")
9830  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9831  ctx = _get_ctx(ctx)
9832  return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9833 
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's complement signed bit-vector term into a term of FloatingPoint sort.
def fpSignedToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9817
def is_fp_sort(s)
Definition: z3py.py:8775
def is_bv(a)
Definition: z3py.py:3687
def is_fprm(a)
Definition: z3py.py:9022

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

9185 def FPSort(ebits, sbits, ctx=None):
9186  """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9187 
9188  >>> Single = FPSort(8, 24)
9189  >>> Double = FPSort(11, 53)
9190  >>> Single
9191  FPSort(8, 24)
9192  >>> x = Const('x', Single)
9193  >>> eq(x, FP('x', FPSort(8, 24)))
9194  True
9195  """
9196  ctx = _get_ctx(ctx)
9197  return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
9198 
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:9185

Referenced by get_default_fp_sort(), Context.mkFPSort(), Context.mkFPSort128(), Context.mkFPSort16(), Context.mkFPSort32(), Context.mkFPSort64(), Context.mkFPSortDouble(), Context.mkFPSortHalf(), Context.mkFPSortQuadruple(), and Context.mkFPSortSingle().

◆ fpSqrt()

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

Definition at line 9573 of file z3py.py.

9573 def fpSqrt(rm, a, ctx=None):
9574  """Create a Z3 floating-point square root expression.
9575  """
9576  return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
9577 
def fpSqrt(rm, a, ctx=None)
Definition: z3py.py:9573

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

9485 def fpSub(rm, a, b, ctx=None):
9486  """Create a Z3 floating-point subtraction expression.
9487 
9488  >>> s = FPSort(8, 24)
9489  >>> rm = RNE()
9490  >>> x = FP('x', s)
9491  >>> y = FP('y', s)
9492  >>> fpSub(rm, x, y)
9493  fpSub(RNE(), x, y)
9494  >>> fpSub(rm, x, y).sort()
9495  FPSort(8, 24)
9496  """
9497  return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
9498 
def fpSub(rm, a, b, ctx=None)
Definition: z3py.py:9485

Referenced by FPRef.__rsub__(), and FPRef.__sub__().

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

9727 def fpToFP(a1, a2=None, a3=None, ctx=None):
9728  """Create a Z3 floating-point conversion expression from other term sorts
9729  to floating-point.
9730 
9731  From a bit-vector term in IEEE 754-2008 format:
9732  >>> x = FPVal(1.0, Float32())
9733  >>> x_bv = fpToIEEEBV(x)
9734  >>> simplify(fpToFP(x_bv, Float32()))
9735  1
9736 
9737  From a floating-point term with different precision:
9738  >>> x = FPVal(1.0, Float32())
9739  >>> x_db = fpToFP(RNE(), x, Float64())
9740  >>> x_db.sort()
9741  FPSort(11, 53)
9742 
9743  From a real term:
9744  >>> x_r = RealVal(1.5)
9745  >>> simplify(fpToFP(RNE(), x_r, Float32()))
9746  1.5
9747 
9748  From a signed bit-vector term:
9749  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9750  >>> simplify(fpToFP(RNE(), x_signed, Float32()))
9751  -1.25*(2**2)
9752  """
9753  ctx = _get_ctx(ctx)
9754  if is_bv(a1) and is_fp_sort(a2):
9755  return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
9756  elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
9757  return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9758  elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
9759  return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9760  elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
9761  return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9762  else:
9763  raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
9764 
def fpToFP(a1, a2=None, a3=None, ctx=None)
Definition: z3py.py:9727
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's complement signed bit-vector term into a term of FloatingPoint sort.
def is_real(a)
Definition: z3py.py:2519
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:8775
def is_bv(a)
Definition: z3py.py:3687
def is_fprm(a)
Definition: z3py.py:9022
def is_fp(a)
Definition: z3py.py:9158

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

9851 def fpToFPUnsigned(rm, x, s, ctx=None):
9852  """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
9853  if z3_debug():
9854  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9855  _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
9856  _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
9857  ctx = _get_ctx(ctx)
9858  return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
9859 
def fpToFPUnsigned(rm, x, s, ctx=None)
Definition: z3py.py:9851
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's complement unsigned bit-vector term into a term of FloatingPoint sort.
def z3_debug()
Definition: z3py.py:58
def is_fp_sort(s)
Definition: z3py.py:8775
def is_bv(a)
Definition: z3py.py:3687
def is_fprm(a)
Definition: z3py.py:9022

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

9921 def fpToIEEEBV(x, ctx=None):
9922  """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
9923 
9924  The size of the resulting bit-vector is automatically determined.
9925 
9926  Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
9927  knows only one NaN and it will always produce the same bit-vector representation of
9928  that NaN.
9929 
9930  >>> x = FP('x', FPSort(8, 24))
9931  >>> y = fpToIEEEBV(x)
9932  >>> print(is_fp(x))
9933  True
9934  >>> print(is_bv(y))
9935  True
9936  >>> print(is_fp(y))
9937  False
9938  >>> print(is_bv(x))
9939  False
9940  """
9941  if z3_debug():
9942  _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
9943  ctx = _get_ctx(ctx)
9944  return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
9945 
9946 
9947 
def fpToIEEEBV(x, ctx=None)
Definition: z3py.py:9921
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 z3_debug()
Definition: z3py.py:58
def is_fp(a)
Definition: z3py.py:9158

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

9902 def fpToReal(x, ctx=None):
9903  """Create a Z3 floating-point conversion expression, from floating-point expression to real.
9904 
9905  >>> x = FP('x', FPSort(8, 24))
9906  >>> y = fpToReal(x)
9907  >>> print(is_fp(x))
9908  True
9909  >>> print(is_real(y))
9910  True
9911  >>> print(is_fp(y))
9912  False
9913  >>> print(is_real(x))
9914  False
9915  """
9916  if z3_debug():
9917  _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
9918  ctx = _get_ctx(ctx)
9919  return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
9920 
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 z3_debug()
Definition: z3py.py:58
def fpToReal(x, ctx=None)
Definition: z3py.py:9902
def is_fp(a)
Definition: z3py.py:9158

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

9860 def fpToSBV(rm, x, s, ctx=None):
9861  """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
9862 
9863  >>> x = FP('x', FPSort(8, 24))
9864  >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
9865  >>> print(is_fp(x))
9866  True
9867  >>> print(is_bv(y))
9868  True
9869  >>> print(is_fp(y))
9870  False
9871  >>> print(is_bv(x))
9872  False
9873  """
9874  if z3_debug():
9875  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9876  _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
9877  _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
9878  ctx = _get_ctx(ctx)
9879  return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
9880 
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:9860
def z3_debug()
Definition: z3py.py:58
def is_bv_sort(s)
Definition: z3py.py:3226
def is_fprm(a)
Definition: z3py.py:9022
def is_fp(a)
Definition: z3py.py:9158

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

9881 def fpToUBV(rm, x, s, ctx=None):
9882  """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
9883 
9884  >>> x = FP('x', FPSort(8, 24))
9885  >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
9886  >>> print(is_fp(x))
9887  True
9888  >>> print(is_bv(y))
9889  True
9890  >>> print(is_fp(y))
9891  False
9892  >>> print(is_bv(x))
9893  False
9894  """
9895  if z3_debug():
9896  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9897  _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
9898  _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
9899  ctx = _get_ctx(ctx)
9900  return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
9901 
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:9881
def z3_debug()
Definition: z3py.py:58
def is_bv_sort(s)
Definition: z3py.py:3226
def is_fprm(a)
Definition: z3py.py:9022
def is_fp(a)
Definition: z3py.py:9158

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

9834 def fpUnsignedToFP(rm, v, sort, ctx=None):
9835  """Create a Z3 floating-point conversion expression that represents the
9836  conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
9837 
9838  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9839  >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
9840  >>> x_fp
9841  fpToFPUnsigned(RNE(), 4294967291)
9842  >>> simplify(x_fp)
9843  1*(2**32)
9844  """
9845  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9846  _z3_assert(is_bv(v), "Second argument must be a Z3 expression or real sort.")
9847  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9848  ctx = _get_ctx(ctx)
9849  return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9850 
def fpUnsignedToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9834
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's complement unsigned bit-vector term into a term of FloatingPoint sort.
def is_fp_sort(s)
Definition: z3py.py:8775
def is_bv(a)
Definition: z3py.py:3687
def is_fprm(a)
Definition: z3py.py:9022

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

9302 def FPVal(sig, exp=None, fps=None, ctx=None):
9303  """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used.
9304 
9305  >>> v = FPVal(20.0, FPSort(8, 24))
9306  >>> v
9307  1.25*(2**4)
9308  >>> print("0x%.8x" % v.exponent_as_long(False))
9309  0x00000004
9310  >>> v = FPVal(2.25, FPSort(8, 24))
9311  >>> v
9312  1.125*(2**1)
9313  >>> v = FPVal(-2.25, FPSort(8, 24))
9314  >>> v
9315  -1.125*(2**1)
9316  >>> FPVal(-0.0, FPSort(8, 24))
9317  -0.0
9318  >>> FPVal(0.0, FPSort(8, 24))
9319  +0.0
9320  >>> FPVal(+0.0, FPSort(8, 24))
9321  +0.0
9322  """
9323  ctx = _get_ctx(ctx)
9324  if is_fp_sort(exp):
9325  fps = exp
9326  exp = None
9327  elif fps is None:
9328  fps = _dflt_fps(ctx)
9329  _z3_assert(is_fp_sort(fps), "sort mismatch")
9330  if exp is None:
9331  exp = 0
9332  val = _to_float_str(sig)
9333  if val == "NaN" or val == "nan":
9334  return fpNaN(fps)
9335  elif val == "-0.0":
9336  return fpMinusZero(fps)
9337  elif val == "0.0" or val == "+0.0":
9338  return fpPlusZero(fps)
9339  elif val == "+oo" or val == "+inf" or val == "+Inf":
9340  return fpPlusInfinity(fps)
9341  elif val == "-oo" or val == "-inf" or val == "-Inf":
9342  return fpMinusInfinity(fps)
9343  else:
9344  return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
9345 
def FPVal(sig, exp=None, fps=None, ctx=None)
Definition: z3py.py:9302
def fpMinusInfinity(s)
Definition: z3py.py:9275
def fpMinusZero(s)
Definition: z3py.py:9291
def fpPlusZero(s)
Definition: z3py.py:9286
def fpPlusInfinity(s)
Definition: z3py.py:9259
def fpNaN(s)
Definition: z3py.py:9243
def is_fp_sort(s)
Definition: z3py.py:8775
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.

Referenced by set_default_fp_sort().

◆ fpZero()

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

Definition at line 9296 of file z3py.py.

9296 def fpZero(s, negative):
9297  """Create a Z3 floating-point +0.0 or -0.0 term."""
9298  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9299  _z3_assert(isinstance(negative, bool), "expected Boolean flag")
9300  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
9301 
def fpZero(s, negative)
Definition: z3py.py:9296
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, 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 1610 of file z3py.py.

1610 def FreshBool(prefix='b', ctx=None):
1611  """Return a fresh Boolean constant in the given context using the given prefix.
1612 
1613  If `ctx=None`, then the global context is used.
1614 
1615  >>> b1 = FreshBool()
1616  >>> b2 = FreshBool()
1617  >>> eq(b1, b2)
1618  False
1619  """
1620  ctx = _get_ctx(ctx)
1621  return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1622 
def FreshBool(prefix='b', ctx=None)
Definition: z3py.py:1610
def BoolSort(ctx=None)
Definition: z3py.py:1535
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 1328 of file z3py.py.

1328 def FreshConst(sort, prefix='c'):
1329  """Create a fresh constant of a specified sort"""
1330  ctx = _get_ctx(sort.ctx)
1331  return _to_expr_ref(Z3_mk_fresh_const(ctx.ref(), prefix, sort.ast), ctx)
1332 
def FreshConst(sort, prefix='c')
Definition: z3py.py:1328
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 3049 of file z3py.py.

3049 def FreshInt(prefix='x', ctx=None):
3050  """Return a fresh integer constant in the given context using the given prefix.
3051 
3052  >>> x = FreshInt()
3053  >>> y = FreshInt()
3054  >>> eq(x, y)
3055  False
3056  >>> x.sort()
3057  Int
3058  """
3059  ctx = _get_ctx(ctx)
3060  return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
3061 
def IntSort(ctx=None)
Definition: z3py.py:2911
def FreshInt(prefix='x', ctx=None)
Definition: z3py.py:3049
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 3101 of file z3py.py.

3101 def FreshReal(prefix='b', ctx=None):
3102  """Return a fresh real constant in the given context using the given prefix.
3103 
3104  >>> x = FreshReal()
3105  >>> y = FreshReal()
3106  >>> eq(x, y)
3107  False
3108  >>> x.sort()
3109  Real
3110  """
3111  ctx = _get_ctx(ctx)
3112  return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
3113 
def FreshReal(prefix='b', ctx=None)
Definition: z3py.py:3101
def RealSort(ctx=None)
Definition: z3py.py:2927
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)
Full(ReSort(Seq(Int)))
>>> e1 = Full(ReSort(StringSort()))
>>> print(e1)
Full(ReSort(String))

Definition at line 10136 of file z3py.py.

10136 def Full(s):
10137  """Create the regular expression that accepts the universal language
10138  >>> e = Full(ReSort(SeqSort(IntSort())))
10139  >>> print(e)
10140  Full(ReSort(Seq(Int)))
10141  >>> e1 = Full(ReSort(StringSort()))
10142  >>> print(e1)
10143  Full(ReSort(String))
10144  """
10145  if isinstance(s, ReSortRef):
10146  return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
10147  raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
10148 
10149 
def Full(s)
Definition: z3py.py:10136
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 4584 of file z3py.py.

4584 def FullSet(s):
4585  """Create the full set
4586  >>> FullSet(IntSort())
4587  K(Int, True)
4588  """
4589  ctx = s.ctx
4590  return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
4591 
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
def FullSet(s)
Definition: z3py.py:4584

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

801 def Function(name, *sig):
802  """Create a new Z3 uninterpreted function with the given sorts.
803 
804  >>> f = Function('f', IntSort(), IntSort())
805  >>> f(f(0))
806  f(f(0))
807  """
808  sig = _get_args(sig)
809  if z3_debug():
810  _z3_assert(len(sig) > 0, "At least two arguments expected")
811  arity = len(sig) - 1
812  rng = sig[arity]
813  if z3_debug():
814  _z3_assert(is_sort(rng), "Z3 sort expected")
815  dom = (Sort * arity)()
816  for i in range(arity):
817  if z3_debug():
818  _z3_assert(is_sort(sig[i]), "Z3 sort expected")
819  dom[i] = sig[i].ast
820  ctx = rng.ctx
821  return FuncDeclRef(Z3_mk_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
822 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def to_symbol(s, ctx=None)
Definition: z3py.py:111
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:598
def z3_debug()
Definition: z3py.py:58
def Function(name, *sig)
Definition: z3py.py:801

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

6248 def get_as_array_func(n):
6249  """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6250  if z3_debug():
6251  _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
6252  return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
6253 
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:6248
def z3_debug()
Definition: z3py.py:58
def is_as_array(n)
Definition: z3py.py:6244

Referenced by ModelRef.get_interp().

◆ get_ctx()

def z3py.get_ctx (   ctx)

Definition at line 239 of file z3py.py.

239 def get_ctx(ctx):
240  return _get_ctx(ctx)
241 
def get_ctx(ctx)
Definition: z3py.py:239

◆ get_default_fp_sort()

def z3py.get_default_fp_sort (   ctx = None)

Definition at line 8655 of file z3py.py.

8655 def get_default_fp_sort(ctx=None):
8656  return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
8657 
def FPSort(ebits, sbits, ctx=None)
Definition: z3py.py:9185
def get_default_fp_sort(ctx=None)
Definition: z3py.py:8655

Referenced by set_default_fp_sort().

◆ get_default_rounding_mode()

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

Definition at line 8628 of file z3py.py.

8628 def get_default_rounding_mode(ctx=None):
8629  """Retrieves the global default rounding mode."""
8630  global _dflt_rounding_mode
8631  if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
8632  return RTZ(ctx)
8633  elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
8634  return RTN(ctx)
8635  elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
8636  return RTP(ctx)
8637  elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
8638  return RNE(ctx)
8639  elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
8640  return RNA(ctx)
8641 
def RTN(ctx=None)
Definition: z3py.py:9010
def RTZ(ctx=None)
Definition: z3py.py:9018
def RTP(ctx=None)
Definition: z3py.py:9002
def RNA(ctx=None)
Definition: z3py.py:8994
def get_default_rounding_mode(ctx=None)
Definition: z3py.py:8628
def RNE(ctx=None)
Definition: z3py.py:8986

Referenced by set_default_fp_sort().

◆ get_full_version()

def z3py.get_full_version ( )

Definition at line 91 of file z3py.py.

91 def get_full_version():
92  return Z3_get_full_version()
93 
94 # We use _z3_assert instead of the assert command because we want to
95 # 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:91

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

4358 def get_map_func(a):
4359  """Return the function declaration associated with a Z3 map array expression.
4360 
4361  >>> f = Function('f', IntSort(), IntSort())
4362  >>> b = Array('b', IntSort(), IntSort())
4363  >>> a = Map(f, b)
4364  >>> eq(f, get_map_func(a))
4365  True
4366  >>> get_map_func(a)
4367  f
4368  >>> get_map_func(a)(0)
4369  f(0)
4370  """
4371  if z3_debug():
4372  _z3_assert(is_map(a), "Z3 array map expression expected.")
4373  return FuncDeclRef(Z3_to_func_decl(a.ctx_ref(), Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0)), a.ctx)
4374 
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:4335
def get_map_func(a)
Definition: z3py.py:4358
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.
def z3_debug()
Definition: z3py.py:58

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

275 def get_param(name):
276  """Return the value of a Z3 global (or module) parameter
277 
278  >>> get_param('nlsat.reorder')
279  'true'
280  """
281  ptr = (ctypes.c_char_p * 1)()
282  if Z3_global_param_get(str(name), ptr):
283  r = z3core._to_pystr(ptr[0])
284  return r
285  raise Z3Exception("failed to retrieve value for '%s'" % name)
286 
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:275

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

1206 def get_var_index(a):
1207  """Return the de-Bruijn index of the Z3 bounded variable `a`.
1208 
1209  >>> x = Int('x')
1210  >>> y = Int('y')
1211  >>> is_var(x)
1212  False
1213  >>> is_const(x)
1214  True
1215  >>> f = Function('f', IntSort(), IntSort(), IntSort())
1216  >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1217  >>> q = ForAll([x, y], f(x, y) == x + y)
1218  >>> q.body()
1219  f(Var(1), Var(0)) == Var(1) + Var(0)
1220  >>> b = q.body()
1221  >>> b.arg(0)
1222  f(Var(1), Var(0))
1223  >>> v1 = b.arg(0).arg(0)
1224  >>> v2 = b.arg(0).arg(1)
1225  >>> v1
1226  Var(1)
1227  >>> v2
1228  Var(0)
1229  >>> get_var_index(v1)
1230  1
1231  >>> get_var_index(v2)
1232  0
1233  """
1234  if z3_debug():
1235  _z3_assert(is_var(a), "Z3 bound variable expected")
1236  return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
1237 
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.
def z3_debug()
Definition: z3py.py:58
def get_var_index(a)
Definition: z3py.py:1206
def is_var(a)
Definition: z3py.py:1182

◆ get_version()

def z3py.get_version ( )

Definition at line 83 of file z3py.py.

83 def get_version():
84  major = ctypes.c_uint(0)
85  minor = ctypes.c_uint(0)
86  build = ctypes.c_uint(0)
87  rev = ctypes.c_uint(0)
88  Z3_get_version(major, minor, build, rev)
89  return (major.value, minor.value, build.value, rev.value)
90 
def get_version()
Definition: z3py.py:83
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 75 of file z3py.py.

75 def get_version_string():
76  major = ctypes.c_uint(0)
77  minor = ctypes.c_uint(0)
78  build = ctypes.c_uint(0)
79  rev = ctypes.c_uint(0)
80  Z3_get_version(major, minor, build, rev)
81  return "%s.%s.%s" % (major.value, minor.value, build.value)
82 
def get_version_string()
Definition: z3py.py:75
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 8208 of file z3py.py.

8208 def help_simplify():
8209  """Return a string describing all options available for Z3 `simplify` procedure."""
8210  print(Z3_simplify_get_help(main_ctx().ref()))
8211 
def main_ctx()
Definition: z3py.py:213
def help_simplify()
Definition: z3py.py:8208
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 1250 of file z3py.py.

1250 def If(a, b, c, ctx=None):
1251  """Create a Z3 if-then-else expression.
1252 
1253  >>> x = Int('x')
1254  >>> y = Int('y')
1255  >>> max = If(x > y, x, y)
1256  >>> max
1257  If(x > y, x, y)
1258  >>> simplify(max)
1259  If(x <= y, y, x)
1260  """
1261  if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1262  return Cond(a, b, c, ctx)
1263  else:
1264  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1265  s = BoolSort(ctx)
1266  a = s.cast(a)
1267  b, c = _coerce_exprs(b, c, ctx)
1268  if z3_debug():
1269  _z3_assert(a.ctx == b.ctx, "Context mismatch")
1270  return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1271 
def If(a, b, c, ctx=None)
Definition: z3py.py:1250
def Cond(p, t1, t2, ctx=None)
Definition: z3py.py:8168
def z3_debug()
Definition: z3py.py:58
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:1535

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

◆ 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(q, Not(p))

Definition at line 1623 of file z3py.py.

1623 def Implies(a, b, ctx=None):
1624  """Create a Z3 implies expression.
1625 
1626  >>> p, q = Bools('p q')
1627  >>> Implies(p, q)
1628  Implies(p, q)
1629  >>> simplify(Implies(p, q))
1630  Or(q, Not(p))
1631  """
1632  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1633  s = BoolSort(ctx)
1634  a = s.cast(a)
1635  b = s.cast(b)
1636  return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1637 
def Implies(a, b, ctx=None)
Definition: z3py.py:1623
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:1535

Referenced by Fixedpoint.add_rule(), and Fixedpoint.update_rule().

◆ IndexOf() [1/2]

def z3py.IndexOf (   s,
  substr 
)

Definition at line 10215 of file z3py.py.

10215 def IndexOf(s, substr):
10216  return IndexOf(s, substr, IntVal(0))
10217 
def IntVal(val, ctx=None)
Definition: z3py.py:2958
def IndexOf(s, substr)
Definition: z3py.py:10215

Referenced by IndexOf().

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

10218 def IndexOf(s, substr, offset):
10219  """Retrieve the index of substring within a string starting at a specified offset.
10220  >>> simplify(IndexOf("abcabc", "bc", 0))
10221  1
10222  >>> simplify(IndexOf("abcabc", "bc", 2))
10223  4
10224  """
10225  ctx = None
10226  if is_expr(offset):
10227  ctx = offset.ctx
10228  ctx = _get_ctx2(s, substr, ctx)
10229  s = _coerce_seq(s, ctx)
10230  substr = _coerce_seq(substr, ctx)
10231  if _is_int(offset):
10232  offset = IntVal(offset, ctx)
10233  return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
10234 
def IntVal(val, ctx=None)
Definition: z3py.py:2958
def IndexOf(s, substr)
Definition: z3py.py:10215
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:1117

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

10315 def InRe(s, re):
10316  """Create regular expression membership test
10317  >>> re = Union(Re("a"),Re("b"))
10318  >>> print (simplify(InRe("a", re)))
10319  True
10320  >>> print (simplify(InRe("b", re)))
10321  True
10322  >>> print (simplify(InRe("c", re)))
10323  False
10324  """
10325  s = _coerce_seq(s, re.ctx)
10326  return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
10327 
def InRe(s, re)
Definition: z3py.py:10315
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 3014 of file z3py.py.

3014 def Int(name, ctx=None):
3015  """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3016 
3017  >>> x = Int('x')
3018  >>> is_int(x)
3019  True
3020  >>> is_int(x + 1)
3021  True
3022  """
3023  ctx = _get_ctx(ctx)
3024  return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
3025 
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:111
def Int(name, ctx=None)
Definition: z3py.py:3014
def IntSort(ctx=None)
Definition: z3py.py:2911

Referenced by Ints(), and IntVector().

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

3736 def Int2BV(a, num_bits):
3737  """Return the z3 expression Int2BV(a, num_bits).
3738  It is a bit-vector of width num_bits and represents the
3739  modulo of a by 2^num_bits
3740  """
3741  ctx = a.ctx
3742  return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
3743 
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:3736

◆ Intersect()

def z3py.Intersect ( args)
Create intersection of regular expressions.
>>> re = Intersect(Re("a"), Re("b"), Re("c"))

Definition at line 10347 of file z3py.py.

10347 def Intersect(*args):
10348  """Create intersection of regular expressions.
10349  >>> re = Intersect(Re("a"), Re("b"), Re("c"))
10350  """
10351  args = _get_args(args)
10352  sz = len(args)
10353  if z3_debug():
10354  _z3_assert(sz > 0, "At least one argument expected.")
10355  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
10356  if sz == 1:
10357  return args[0]
10358  ctx = args[0].ctx
10359  v = (Ast * sz)()
10360  for i in range(sz):
10361  v[i] = args[i].as_ast()
10362  return ReRef(Z3_mk_re_intersect(ctx.ref(), sz, v), ctx)
10363 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
Z3_ast Z3_API Z3_mk_re_intersect(Z3_context c, unsigned n, Z3_ast const args[])
Create the intersection of the regular languages.
def Intersect(*args)
Definition: z3py.py:10347
def is_re(s)
Definition: z3py.py:10311
def z3_debug()
Definition: z3py.py:58

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

3026 def Ints(names, ctx=None):
3027  """Return a tuple of Integer constants.
3028 
3029  >>> x, y, z = Ints('x y z')
3030  >>> Sum(x, y, z)
3031  x + y + z
3032  """
3033  ctx = _get_ctx(ctx)
3034  if isinstance(names, str):
3035  names = names.split(" ")
3036  return [Int(name, ctx) for name in names]
3037 
def Int(name, ctx=None)
Definition: z3py.py:3014
def Ints(names, ctx=None)
Definition: z3py.py:3026

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

2911 def IntSort(ctx=None):
2912  """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
2913 
2914  >>> IntSort()
2915  Int
2916  >>> x = Const('x', IntSort())
2917  >>> is_int(x)
2918  True
2919  >>> x.sort() == IntSort()
2920  True
2921  >>> x.sort() == BoolSort()
2922  False
2923  """
2924  ctx = _get_ctx(ctx)
2925  return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
2926 
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
def IntSort(ctx=None)
Definition: z3py.py:2911

Referenced by FreshInt(), Context.getIntSort(), Int(), IntVal(), and Context.mkIntSort().

◆ IntToStr()

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

Definition at line 10269 of file z3py.py.

10269 def IntToStr(s):
10270  """Convert integer expression to string"""
10271  if not is_expr(s):
10272  s = _py2expr(s)
10273  return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
10274 
10275 
def IntToStr(s)
Definition: z3py.py:10269
def is_expr(a)
Definition: z3py.py:1117
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 2958 of file z3py.py.

2958 def IntVal(val, ctx=None):
2959  """Return a Z3 integer value. If `ctx=None`, then the global context is used.
2960 
2961  >>> IntVal(1)
2962  1
2963  >>> IntVal("100")
2964  100
2965  """
2966  ctx = _get_ctx(ctx)
2967  return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
2968 
def IntVal(val, ctx=None)
Definition: z3py.py:2958
def IntSort(ctx=None)
Definition: z3py.py:2911
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.

Referenced by SeqRef.__getitem__(), AlgebraicNumRef.as_decimal(), SeqRef.at(), and IndexOf().

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

3038 def IntVector(prefix, sz, ctx=None):
3039  """Return a list of integer constants of size `sz`.
3040 
3041  >>> X = IntVector('x', 3)
3042  >>> X
3043  [x__0, x__1, x__2]
3044  >>> Sum(X)
3045  x__0 + x__1 + x__2
3046  """
3047  return [ Int('%s__%s' % (prefix, i)) for i in range(sz) ]
3048 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def Int(name, ctx=None)
Definition: z3py.py:3014
def IntVector(prefix, sz, ctx=None)
Definition: z3py.py:3038

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

2600 def is_add(a):
2601  """Return `True` if `a` is an expression of the form b + c.
2602 
2603  >>> x, y = Ints('x y')
2604  >>> is_add(x + y)
2605  True
2606  >>> is_add(x - y)
2607  False
2608  """
2609  return is_app_of(a, Z3_OP_ADD)
2610 
def is_app_of(a, k)
Definition: z3py.py:1238
def is_add(a)
Definition: z3py.py:2600

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

2587 def is_algebraic_value(a):
2588  """Return `True` if `a` is an algebraic value of sort Real.
2589 
2590  >>> is_algebraic_value(RealVal("3/5"))
2591  False
2592  >>> n = simplify(Sqrt(2))
2593  >>> n
2594  1.4142135623?
2595  >>> is_algebraic_value(n)
2596  True
2597  """
2598  return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2599 
def is_arith(a)
Definition: z3py.py:2481
def is_algebraic_value(a)
Definition: z3py.py:2587

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

1471 def is_and(a):
1472  """Return `True` if `a` is a Z3 and expression.
1473 
1474  >>> p, q = Bools('p q')
1475  >>> is_and(And(p, q))
1476  True
1477  >>> is_and(Or(p, q))
1478  False
1479  """
1480  return is_app_of(a, Z3_OP_AND)
1481 
def is_and(a)
Definition: z3py.py:1471
def is_app_of(a, k)
Definition: z3py.py:1238

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

1139 def is_app(a):
1140  """Return `True` if `a` is a Z3 function application.
1141 
1142  Note that, constants are function applications with 0 arguments.
1143 
1144  >>> a = Int('a')
1145  >>> is_app(a)
1146  True
1147  >>> is_app(a + 1)
1148  True
1149  >>> is_app(IntSort())
1150  False
1151  >>> is_app(1)
1152  False
1153  >>> is_app(IntVal(1))
1154  True
1155  >>> x = Int('x')
1156  >>> is_app(ForAll(x, x >= 0))
1157  False
1158  """
1159  if not isinstance(a, ExprRef):
1160  return False
1161  k = _ast_kind(a.ctx, a)
1162  return k == Z3_NUMERAL_AST or k == Z3_APP_AST
1163 
def is_app(a)
Definition: z3py.py:1139

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

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

1238 def is_app_of(a, k):
1239  """Return `True` if `a` is an application of the given kind `k`.
1240 
1241  >>> x = Int('x')
1242  >>> n = x + 1
1243  >>> is_app_of(n, Z3_OP_ADD)
1244  True
1245  >>> is_app_of(n, Z3_OP_MUL)
1246  False
1247  """
1248  return is_app(a) and a.decl().kind() == k
1249 
def is_app(a)
Definition: z3py.py:1139
def is_app_of(a, k)
Definition: z3py.py:1238

Referenced by is_add(), is_and(), is_const_array(), is_default(), is_distinct(), is_div(), is_eq(), is_false(), is_ge(), is_gt(), is_idiv(), is_implies(), is_is_int(), is_K(), is_le(), is_lt(), is_map(), is_mod(), is_mul(), is_not(), is_or(), is_select(), is_store(), is_sub(), is_to_int(), is_to_real(), and is_true().

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

2481 def is_arith(a):
2482  """Return `True` if `a` is an arithmetical expression.
2483 
2484  >>> x = Int('x')
2485  >>> is_arith(x)
2486  True
2487  >>> is_arith(x + 1)
2488  True
2489  >>> is_arith(1)
2490  False
2491  >>> is_arith(IntVal(1))
2492  True
2493  >>> y = Real('y')
2494  >>> is_arith(y)
2495  True
2496  >>> is_arith(y + 1)
2497  True
2498  """
2499  return isinstance(a, ArithRef)
2500 
def is_arith(a)
Definition: z3py.py:2481

Referenced by is_algebraic_value(), is_int(), is_int_value(), is_rational_value(), and is_real().

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

2182 def is_arith_sort(s):
2183  """Return `True` if s is an arithmetical sort (type).
2184 
2185  >>> is_arith_sort(IntSort())
2186  True
2187  >>> is_arith_sort(RealSort())
2188  True
2189  >>> is_arith_sort(BoolSort())
2190  False
2191  >>> n = Int('x') + 1
2192  >>> is_arith_sort(n.sort())
2193  True
2194  """
2195  return isinstance(s, ArithSortRef)
2196 
def is_arith_sort(s)
Definition: z3py.py:2182

Referenced by ArithSortRef.subsort().

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

4298 def is_array(a):
4299  """Return `True` if `a` is a Z3 array expression.
4300 
4301  >>> a = Array('a', IntSort(), IntSort())
4302  >>> is_array(a)
4303  True
4304  >>> is_array(Store(a, 0, 1))
4305  True
4306  >>> is_array(a[0])
4307  False
4308  """
4309  return isinstance(a, ArrayRef)
4310 
def is_array(a)
Definition: z3py.py:4298

Referenced by Ext(), and Map().

◆ is_array_sort()

def z3py.is_array_sort (   a)

Definition at line 4294 of file z3py.py.

4294 def is_array_sort(a):
4295  return Z3_get_sort_kind(a.ctx.ref(), Z3_get_sort(a.ctx.ref(), a.ast)) == Z3_ARRAY_SORT
4296 
4297 
def is_array_sort(a)
Definition: z3py.py:4294
Z3_sort_kind Z3_API Z3_get_sort_kind(Z3_context c, Z3_sort t)
Return the sort kind (e.g., array, tuple, int, bool, etc).
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

Referenced by Default(), Ext(), Select(), and Update().

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

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

Referenced by get_as_array_func(), and ModelRef.get_interp().

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

414 def is_ast(a):
415  """Return `True` if `a` is an AST node.
416 
417  >>> is_ast(10)
418  False
419  >>> is_ast(IntVal(10))
420  True
421  >>> is_ast(Int('x'))
422  True
423  >>> is_ast(BoolSort())
424  True
425  >>> is_ast(Function('f', IntSort(), IntSort()))
426  True
427  >>> is_ast("x")
428  False
429  >>> is_ast(Solver())
430  False
431  """
432  return isinstance(a, AstRef)
433 
def is_ast(a)
Definition: z3py.py:414

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

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

1424 def is_bool(a):
1425  """Return `True` if `a` is a Z3 Boolean expression.
1426 
1427  >>> p = Bool('p')
1428  >>> is_bool(p)
1429  True
1430  >>> q = Bool('q')
1431  >>> is_bool(And(p, q))
1432  True
1433  >>> x = Real('x')
1434  >>> is_bool(x)
1435  False
1436  >>> is_bool(x == 0)
1437  True
1438  """
1439  return isinstance(a, BoolRef)
1440 
def is_bool(a)
Definition: z3py.py:1424

Referenced by is_quantifier(), and prove().

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

3687 def is_bv(a):
3688  """Return `True` if `a` is a Z3 bit-vector expression.
3689 
3690  >>> b = BitVec('b', 32)
3691  >>> is_bv(b)
3692  True
3693  >>> is_bv(b + 10)
3694  True
3695  >>> is_bv(Int('x'))
3696  False
3697  """
3698  return isinstance(a, BitVecRef)
3699 
def is_bv(a)
Definition: z3py.py:3687

Referenced by BV2Int(), BVRedAnd(), BVRedOr(), BVSNegNoOverflow(), Concat(), Extract(), fpBVToFP(), fpFP(), fpSignedToFP(), fpToFP(), fpToFPUnsigned(), fpUnsignedToFP(), is_bv_value(), Product(), RepeatBitVec(), SignExt(), Sum(), and ZeroExt().

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

3226 def is_bv_sort(s):
3227  """Return True if `s` is a Z3 bit-vector sort.
3228 
3229  >>> is_bv_sort(BitVecSort(32))
3230  True
3231  >>> is_bv_sort(IntSort())
3232  False
3233  """
3234  return isinstance(s, BitVecSortRef)
3235 
def is_bv_sort(s)
Definition: z3py.py:3226

Referenced by BitVecVal(), fpToSBV(), fpToUBV(), and BitVecSortRef.subsort().

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

3700 def is_bv_value(a):
3701  """Return `True` if `a` is a Z3 bit-vector numeral value.
3702 
3703  >>> b = BitVec('b', 32)
3704  >>> is_bv_value(b)
3705  False
3706  >>> b = BitVecVal(10, 32)
3707  >>> b
3708  10
3709  >>> is_bv_value(b)
3710  True
3711  """
3712  return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
3713 
def is_bv_value(a)
Definition: z3py.py:3700
def is_bv(a)
Definition: z3py.py:3687

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

1164 def is_const(a):
1165  """Return `True` if `a` is Z3 constant/variable expression.
1166 
1167  >>> a = Int('a')
1168  >>> is_const(a)
1169  True
1170  >>> is_const(a + 1)
1171  False
1172  >>> is_const(1)
1173  False
1174  >>> is_const(IntVal(1))
1175  True
1176  >>> x = Int('x')
1177  >>> is_const(ForAll(x, x >= 0))
1178  False
1179  """
1180  return is_app(a) and a.num_args() == 0
1181 
def is_app(a)
Definition: z3py.py:1139
def is_const(a)
Definition: z3py.py:1164

Referenced by ModelRef.__getitem__(), Solver.assert_and_track(), Optimize.assert_and_track(), ModelRef.get_interp(), is_quantifier(), and prove().

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

4311 def is_const_array(a):
4312  """Return `True` if `a` is a Z3 constant array.
4313 
4314  >>> a = K(IntSort(), 10)
4315  >>> is_const_array(a)
4316  True
4317  >>> a = Array('a', IntSort(), IntSort())
4318  >>> is_const_array(a)
4319  False
4320  """
4321  return is_app_of(a, Z3_OP_CONST_ARRAY)
4322 
def is_const_array(a)
Definition: z3py.py:4311
def is_app_of(a, k)
Definition: z3py.py:1238

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

4350 def is_default(a):
4351  """Return `True` if `a` is a Z3 default array expression.
4352  >>> d = Default(K(IntSort(), 10))
4353  >>> is_default(d)
4354  True
4355  """
4356  return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4357 
def is_default(a)
Definition: z3py.py:4350
def is_app_of(a, k)
Definition: z3py.py:1238

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

1524 def is_distinct(a):
1525  """Return `True` if `a` is a Z3 distinct expression.
1526 
1527  >>> x, y, z = Ints('x y z')
1528  >>> is_distinct(x == y)
1529  False
1530  >>> is_distinct(Distinct(x, y, z))
1531  True
1532  """
1533  return is_app_of(a, Z3_OP_DISTINCT)
1534 
def is_distinct(a)
Definition: z3py.py:1524
def is_app_of(a, k)
Definition: z3py.py:1238

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

2633 def is_div(a):
2634  """Return `True` if `a` is an expression of the form b / c.
2635 
2636  >>> x, y = Reals('x y')
2637  >>> is_div(x / y)
2638  True
2639  >>> is_div(x + y)
2640  False
2641  >>> x, y = Ints('x y')
2642  >>> is_div(x / y)
2643  False
2644  >>> is_idiv(x / y)
2645  True
2646  """
2647  return is_app_of(a, Z3_OP_DIV)
2648 
def is_div(a)
Definition: z3py.py:2633
def is_app_of(a, k)
Definition: z3py.py:1238

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

1515 def is_eq(a):
1516  """Return `True` if `a` is a Z3 equality expression.
1517 
1518  >>> x, y = Ints('x y')
1519  >>> is_eq(x == y)
1520  True
1521  """
1522  return is_app_of(a, Z3_OP_EQ)
1523 
def is_eq(a)
Definition: z3py.py:1515
def is_app_of(a, k)
Definition: z3py.py:1238

Referenced by AstRef.__bool__().

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

1117 def is_expr(a):
1118  """Return `True` if `a` is a Z3 expression.
1119 
1120  >>> a = Int('a')
1121  >>> is_expr(a)
1122  True
1123  >>> is_expr(a + 1)
1124  True
1125  >>> is_expr(IntSort())
1126  False
1127  >>> is_expr(1)
1128  False
1129  >>> is_expr(IntVal(1))
1130  True
1131  >>> x = Int('x')
1132  >>> is_expr(ForAll(x, x >= 0))
1133  True
1134  >>> is_expr(FPVal(1.0))
1135  True
1136  """
1137  return isinstance(a, ExprRef)
1138 
def is_expr(a)
Definition: z3py.py:1117

Referenced by SeqRef.__gt__(), AlgebraicNumRef.as_decimal(), SortRef.cast(), BoolSortRef.cast(), ArithSortRef.cast(), BitVecSortRef.cast(), FPSortRef.cast(), Cbrt(), ExprRef.children(), Concat(), IndexOf(), IntToStr(), is_quantifier(), is_var(), K(), MultiPattern(), Replace(), simplify(), Sqrt(), substitute(), and substitute_vars().

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

1458 def is_false(a):
1459  """Return `True` if `a` is the Z3 false expression.
1460 
1461  >>> p = Bool('p')
1462  >>> is_false(p)
1463  False
1464  >>> is_false(False)
1465  False
1466  >>> is_false(BoolVal(False))
1467  True
1468  """
1469  return is_app_of(a, Z3_OP_FALSE)
1470 
def is_app_of(a, k)
Definition: z3py.py:1238
def is_false(a)
Definition: z3py.py:1458

Referenced by AstRef.__bool__().

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

7252 def is_finite_domain(a):
7253  """Return `True` if `a` is a Z3 finite-domain expression.
7254 
7255  >>> s = FiniteDomainSort('S', 100)
7256  >>> b = Const('b', s)
7257  >>> is_finite_domain(b)
7258  True
7259  >>> is_finite_domain(Int('x'))
7260  False
7261  """
7262  return isinstance(a, FiniteDomainRef)
7263 
7264 
def is_finite_domain(a)
Definition: z3py.py:7252

Referenced by is_finite_domain_value().

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

7230 def is_finite_domain_sort(s):
7231  """Return True if `s` is a Z3 finite-domain sort.
7232 
7233  >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7234  True
7235  >>> is_finite_domain_sort(IntSort())
7236  False
7237  """
7238  return isinstance(s, FiniteDomainSortRef)
7239 
7240 
def is_finite_domain_sort(s)
Definition: z3py.py:7230

Referenced by FiniteDomainVal().

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

7305 def is_finite_domain_value(a):
7306  """Return `True` if `a` is a Z3 finite-domain value.
7307 
7308  >>> s = FiniteDomainSort('S', 100)
7309  >>> b = Const('b', s)
7310  >>> is_finite_domain_value(b)
7311  False
7312  >>> b = FiniteDomainVal(10, s)
7313  >>> b
7314  10
7315  >>> is_finite_domain_value(b)
7316  True
7317  """
7318  return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
7319 
7320 
def is_finite_domain_value(a)
Definition: z3py.py:7305
def is_finite_domain(a)
Definition: z3py.py:7252

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

9158 def is_fp(a):
9159  """Return `True` if `a` is a Z3 floating-point expression.
9160 
9161  >>> b = FP('b', FPSort(8, 24))
9162  >>> is_fp(b)
9163  True
9164  >>> is_fp(b + 1.0)
9165  True
9166  >>> is_fp(Int('x'))
9167  False
9168  """
9169  return isinstance(a, FPRef)
9170 
def is_fp(a)
Definition: z3py.py:9158

Referenced by fpFPToFP(), fpIsPositive(), fpNeg(), fpToFP(), fpToIEEEBV(), fpToReal(), fpToSBV(), fpToUBV(), is_fp_value(), and set_default_fp_sort().

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

8775 def is_fp_sort(s):
8776  """Return True if `s` is a Z3 floating-point sort.
8777 
8778  >>> is_fp_sort(FPSort(8, 24))
8779  True
8780  >>> is_fp_sort(IntSort())
8781  False
8782  """
8783  return isinstance(s, FPSortRef)
8784 
def is_fp_sort(s)
Definition: z3py.py:8775

Referenced by fpBVToFP(), fpFPToFP(), fpRealToFP(), fpSignedToFP(), fpToFP(), fpToFPUnsigned(), fpUnsignedToFP(), and FPVal().

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

9171 def is_fp_value(a):
9172  """Return `True` if `a` is a Z3 floating-point numeral value.
9173 
9174  >>> b = FP('b', FPSort(8, 24))
9175  >>> is_fp_value(b)
9176  False
9177  >>> b = FPVal(1.0, FPSort(8, 24))
9178  >>> b
9179  1
9180  >>> is_fp_value(b)
9181  True
9182  """
9183  return is_fp(a) and _is_numeral(a.ctx, a.ast)
9184 
def is_fp_value(a)
Definition: z3py.py:9171
def is_fp(a)
Definition: z3py.py:9158

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

9022 def is_fprm(a):
9023  """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9024 
9025  >>> rm = RNE()
9026  >>> is_fprm(rm)
9027  True
9028  >>> rm = 1.0
9029  >>> is_fprm(rm)
9030  False
9031  """
9032  return isinstance(a, FPRMRef)
9033 
def is_fprm(a)
Definition: z3py.py:9022

Referenced by fpFPToFP(), fpNeg(), fpRealToFP(), fpSignedToFP(), fpToFP(), fpToFPUnsigned(), fpToSBV(), fpToUBV(), fpUnsignedToFP(), and is_fprm_value().

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

8785 def is_fprm_sort(s):
8786  """Return True if `s` is a Z3 floating-point rounding mode sort.
8787 
8788  >>> is_fprm_sort(FPSort(8, 24))
8789  False
8790  >>> is_fprm_sort(RNE().sort())
8791  True
8792  """
8793  return isinstance(s, FPRMSortRef)
8794 
def is_fprm_sort(s)
Definition: z3py.py:8785

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

9034 def is_fprm_value(a):
9035  """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9036  return is_fprm(a) and _is_numeral(a.ctx, a.ast)
9037 
def is_fprm_value(a)
Definition: z3py.py:9034
def is_fprm(a)
Definition: z3py.py:9022

Referenced by set_default_rounding_mode().

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

789 def is_func_decl(a):
790  """Return `True` if `a` is a Z3 function declaration.
791 
792  >>> f = Function('f', IntSort(), IntSort())
793  >>> is_func_decl(f)
794  True
795  >>> x = Real('x')
796  >>> is_func_decl(x)
797  False
798  """
799  return isinstance(a, FuncDeclRef)
800 
def is_func_decl(a)
Definition: z3py.py:789

Referenced by Map(), and prove().

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

2693 def is_ge(a):
2694  """Return `True` if `a` is an expression of the form b >= c.
2695 
2696  >>> x, y = Ints('x y')
2697  >>> is_ge(x >= y)
2698  True
2699  >>> is_ge(x == y)
2700  False
2701  """
2702  return is_app_of(a, Z3_OP_GE)
2703 
def is_ge(a)
Definition: z3py.py:2693
def is_app_of(a, k)
Definition: z3py.py:1238

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

2704 def is_gt(a):
2705  """Return `True` if `a` is an expression of the form b > c.
2706 
2707  >>> x, y = Ints('x y')
2708  >>> is_gt(x > y)
2709  True
2710  >>> is_gt(x == y)
2711  False
2712  """
2713  return is_app_of(a, Z3_OP_GT)
2714 
def is_gt(a)
Definition: z3py.py:2704
def is_app_of(a, k)
Definition: z3py.py:1238

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

2649 def is_idiv(a):
2650  """Return `True` if `a` is an expression of the form b div c.
2651 
2652  >>> x, y = Ints('x y')
2653  >>> is_idiv(x / y)
2654  True
2655  >>> is_idiv(x + y)
2656  False
2657  """
2658  return is_app_of(a, Z3_OP_IDIV)
2659 
def is_idiv(a)
Definition: z3py.py:2649
def is_app_of(a, k)
Definition: z3py.py:1238

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

1493 def is_implies(a):
1494  """Return `True` if `a` is a Z3 implication expression.
1495 
1496  >>> p, q = Bools('p q')
1497  >>> is_implies(Implies(p, q))
1498  True
1499  >>> is_implies(And(p, q))
1500  False
1501  """
1502  return is_app_of(a, Z3_OP_IMPLIES)
1503 
def is_implies(a)
Definition: z3py.py:1493
def is_app_of(a, k)
Definition: z3py.py:1238

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

2501 def is_int(a):
2502  """Return `True` if `a` is an integer expression.
2503 
2504  >>> x = Int('x')
2505  >>> is_int(x + 1)
2506  True
2507  >>> is_int(1)
2508  False
2509  >>> is_int(IntVal(1))
2510  True
2511  >>> y = Real('y')
2512  >>> is_int(y)
2513  False
2514  >>> is_int(y + 1)
2515  False
2516  """
2517  return is_arith(a) and a.is_int()
2518 
def is_arith(a)
Definition: z3py.py:2481
def is_int(a)
Definition: z3py.py:2501

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

2543 def is_int_value(a):
2544  """Return `True` if `a` is an integer value of sort Int.
2545 
2546  >>> is_int_value(IntVal(1))
2547  True
2548  >>> is_int_value(1)
2549  False
2550  >>> is_int_value(Int('x'))
2551  False
2552  >>> n = Int('x') + 1
2553  >>> n
2554  x + 1
2555  >>> n.arg(1)
2556  1
2557  >>> is_int_value(n.arg(1))
2558  True
2559  >>> is_int_value(RealVal("1/3"))
2560  False
2561  >>> is_int_value(RealVal(1))
2562  False
2563  """
2564  return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
2565 
def is_int_value(a)
Definition: z3py.py:2543
def is_arith(a)
Definition: z3py.py:2481

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

2715 def is_is_int(a):
2716  """Return `True` if `a` is an expression of the form IsInt(b).
2717 
2718  >>> x = Real('x')
2719  >>> is_is_int(IsInt(x))
2720  True
2721  >>> is_is_int(x)
2722  False
2723  """
2724  return is_app_of(a, Z3_OP_IS_INT)
2725 
def is_app_of(a, k)
Definition: z3py.py:1238
def is_is_int(a)
Definition: z3py.py:2715

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

4323 def is_K(a):
4324  """Return `True` if `a` is a Z3 constant array.
4325 
4326  >>> a = K(IntSort(), 10)
4327  >>> is_K(a)
4328  True
4329  >>> a = Array('a', IntSort(), IntSort())
4330  >>> is_K(a)
4331  False
4332  """
4333  return is_app_of(a, Z3_OP_CONST_ARRAY)
4334 
def is_K(a)
Definition: z3py.py:4323
def is_app_of(a, k)
Definition: z3py.py:1238

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

2671 def is_le(a):
2672  """Return `True` if `a` is an expression of the form b <= c.
2673 
2674  >>> x, y = Ints('x y')
2675  >>> is_le(x <= y)
2676  True
2677  >>> is_le(x < y)
2678  False
2679  """
2680  return is_app_of(a, Z3_OP_LE)
2681 
def is_le(a)
Definition: z3py.py:2671
def is_app_of(a, k)
Definition: z3py.py:1238

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

2682 def is_lt(a):
2683  """Return `True` if `a` is an expression of the form b < c.
2684 
2685  >>> x, y = Ints('x y')
2686  >>> is_lt(x < y)
2687  True
2688  >>> is_lt(x == y)
2689  False
2690  """
2691  return is_app_of(a, Z3_OP_LT)
2692 
def is_lt(a)
Definition: z3py.py:2682
def is_app_of(a, k)
Definition: z3py.py:1238

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

4335 def is_map(a):
4336  """Return `True` if `a` is a Z3 map array expression.
4337 
4338  >>> f = Function('f', IntSort(), IntSort())
4339  >>> b = Array('b', IntSort(), IntSort())
4340  >>> a = Map(f, b)
4341  >>> a
4342  Map(f, b)
4343  >>> is_map(a)
4344  True
4345  >>> is_map(b)
4346  False
4347  """
4348  return is_app_of(a, Z3_OP_ARRAY_MAP)
4349 
def is_map(a)
Definition: z3py.py:4335
def is_app_of(a, k)
Definition: z3py.py:1238

Referenced by get_map_func().

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

2660 def is_mod(a):
2661  """Return `True` if `a` is an expression of the form b % c.
2662 
2663  >>> x, y = Ints('x y')
2664  >>> is_mod(x % y)
2665  True
2666  >>> is_mod(x + y)
2667  False
2668  """
2669  return is_app_of(a, Z3_OP_MOD)
2670 
def is_mod(a)
Definition: z3py.py:2660
def is_app_of(a, k)
Definition: z3py.py:1238

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

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

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

1504 def is_not(a):
1505  """Return `True` if `a` is a Z3 not expression.
1506 
1507  >>> p = Bool('p')
1508  >>> is_not(p)
1509  False
1510  >>> is_not(Not(p))
1511  True
1512  """
1513  return is_app_of(a, Z3_OP_NOT)
1514 
def is_not(a)
Definition: z3py.py:1504
def is_app_of(a, k)
Definition: z3py.py:1238

Referenced by mk_not().

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

1482 def is_or(a):
1483  """Return `True` if `a` is a Z3 or expression.
1484 
1485  >>> p, q = Bools('p q')
1486  >>> is_or(Or(p, q))
1487  True
1488  >>> is_or(And(p, q))
1489  False
1490  """
1491  return is_app_of(a, Z3_OP_OR)
1492 
def is_or(a)
Definition: z3py.py:1482
def is_app_of(a, k)
Definition: z3py.py:1238

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

1763 def is_pattern(a):
1764  """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1765 
1766  >>> f = Function('f', IntSort(), IntSort())
1767  >>> x = Int('x')
1768  >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1769  >>> q
1770  ForAll(x, f(x) == 0)
1771  >>> q.num_patterns()
1772  1
1773  >>> is_pattern(q.pattern(0))
1774  True
1775  >>> q.pattern(0)
1776  f(Var(0))
1777  """
1778  return isinstance(a, PatternRef)
1779 
def is_pattern(a)
Definition: z3py.py:1763

Referenced by is_quantifier(), and MultiPattern().

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

8064 def is_probe(p):
8065  """Return `True` if `p` is a Z3 probe.
8066 
8067  >>> is_probe(Int('x'))
8068  False
8069  >>> is_probe(Probe('memory'))
8070  True
8071  """
8072  return isinstance(p, Probe)
8073 
def is_probe(p)
Definition: z3py.py:8064

Referenced by eq(), mk_not(), and Not().

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

2001 def is_quantifier(a):
2002  """Return `True` if `a` is a Z3 quantifier.
2003 
2004  >>> f = Function('f', IntSort(), IntSort())
2005  >>> x = Int('x')
2006  >>> q = ForAll(x, f(x) == 0)
2007  >>> is_quantifier(q)
2008  True
2009  >>> is_quantifier(f(x))
2010  False
2011  """
2012  return isinstance(a, QuantifierRef)
2013 
def is_quantifier(a)
Definition: z3py.py:2001

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

2566 def is_rational_value(a):
2567  """Return `True` if `a` is rational value of sort Real.
2568 
2569  >>> is_rational_value(RealVal(1))
2570  True
2571  >>> is_rational_value(RealVal("3/5"))
2572  True
2573  >>> is_rational_value(IntVal(1))
2574  False
2575  >>> is_rational_value(1)
2576  False
2577  >>> n = Real('x') + 1
2578  >>> n.arg(1)
2579  1
2580  >>> is_rational_value(n.arg(1))
2581  True
2582  >>> is_rational_value(Real('x'))
2583  False
2584  """
2585  return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2586 
def is_arith(a)
Definition: z3py.py:2481
def is_rational_value(a)
Definition: z3py.py:2566

◆ is_re()

def z3py.is_re (   s)

Definition at line 10311 of file z3py.py.

10311 def is_re(s):
10312  return isinstance(s, ReRef)
10313 
10314 
def is_re(s)
Definition: z3py.py:10311

Referenced by Concat(), Intersect(), and Union().

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

2519 def is_real(a):
2520  """Return `True` if `a` is a real expression.
2521 
2522  >>> x = Int('x')
2523  >>> is_real(x + 1)
2524  False
2525  >>> y = Real('y')
2526  >>> is_real(y)
2527  True
2528  >>> is_real(y + 1)
2529  True
2530  >>> is_real(1)
2531  False
2532  >>> is_real(RealVal(1))
2533  True
2534  """
2535  return is_arith(a) and a.is_real()
2536 
def is_real(a)
Definition: z3py.py:2519
def is_arith(a)
Definition: z3py.py:2481

Referenced by fpRealToFP(), and fpToFP().

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

4542 def is_select(a):
4543  """Return `True` if `a` is a Z3 array select application.
4544 
4545  >>> a = Array('a', IntSort(), IntSort())
4546  >>> is_select(a)
4547  False
4548  >>> i = Int('i')
4549  >>> is_select(a[i])
4550  True
4551  """
4552  return is_app_of(a, Z3_OP_SELECT)
4553 
def is_select(a)
Definition: z3py.py:4542
def is_app_of(a, k)
Definition: z3py.py:1238

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

10056 def is_seq(a):
10057  """Return `True` if `a` is a Z3 sequence expression.
10058  >>> print (is_seq(Unit(IntVal(0))))
10059  True
10060  >>> print (is_seq(StringVal("abc")))
10061  True
10062  """
10063  return isinstance(a, SeqRef)
10064 
def is_seq(a)
Definition: z3py.py:10056

Referenced by SeqRef.__gt__(), Concat(), and Extract().

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

598 def is_sort(s):
599  """Return `True` if `s` is a Z3 sort.
600 
601  >>> is_sort(IntSort())
602  True
603  >>> is_sort(Int('x'))
604  False
605  >>> is_expr(Int('x'))
606  True
607  """
608  return isinstance(s, SortRef)
609 
def is_sort(s)
Definition: z3py.py:598

Referenced by ArraySort(), CreateDatatypes(), Function(), IsSubset(), K(), prove(), RecFunction(), and Var().

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

4554 def is_store(a):
4555  """Return `True` if `a` is a Z3 array store application.
4556 
4557  >>> a = Array('a', IntSort(), IntSort())
4558  >>> is_store(a)
4559  False
4560  >>> is_store(Store(a, 0, 1))
4561  True
4562  """
4563  return is_app_of(a, Z3_OP_STORE)
4564 
def is_store(a)
Definition: z3py.py:4554
def is_app_of(a, k)
Definition: z3py.py:1238

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

10065 def is_string(a):
10066  """Return `True` if `a` is a Z3 string expression.
10067  >>> print (is_string(StringVal("ab")))
10068  True
10069  """
10070  return isinstance(a, SeqRef) and a.is_string()
10071 
def is_string(a)
Definition: z3py.py:10065

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

10072 def is_string_value(a):
10073  """return 'True' if 'a' is a Z3 string constant expression.
10074  >>> print (is_string_value(StringVal("a")))
10075  True
10076  >>> print (is_string_value(StringVal("a") + StringVal("b")))
10077  False
10078  """
10079  return isinstance(a, SeqRef) and a.is_string_value()
10080 
10081 
def is_string_value(a)
Definition: z3py.py:10072

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

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

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

2740 def is_to_int(a):
2741  """Return `True` if `a` is an expression of the form ToInt(b).
2742 
2743  >>> x = Real('x')
2744  >>> n = ToInt(x)
2745  >>> n
2746  ToInt(x)
2747  >>> is_to_int(n)
2748  True
2749  >>> is_to_int(x)
2750  False
2751  """
2752  return is_app_of(a, Z3_OP_TO_INT)
2753 
def is_app_of(a, k)
Definition: z3py.py:1238
def is_to_int(a)
Definition: z3py.py:2740

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

2726 def is_to_real(a):
2727  """Return `True` if `a` is an expression of the form ToReal(b).
2728 
2729  >>> x = Int('x')
2730  >>> n = ToReal(x)
2731  >>> n
2732  ToReal(x)
2733  >>> is_to_real(n)
2734  True
2735  >>> is_to_real(x)
2736  False
2737  """
2738  return is_app_of(a, Z3_OP_TO_REAL)
2739 
def is_to_real(a)
Definition: z3py.py:2726
def is_app_of(a, k)
Definition: z3py.py:1238

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

1441 def is_true(a):
1442  """Return `True` if `a` is the Z3 true expression.
1443 
1444  >>> p = Bool('p')
1445  >>> is_true(p)
1446  False
1447  >>> is_true(simplify(p == p))
1448  True
1449  >>> x = Real('x')
1450  >>> is_true(x == 0)
1451  False
1452  >>> # True is a Python Boolean expression
1453  >>> is_true(True)
1454  False
1455  """
1456  return is_app_of(a, Z3_OP_TRUE)
1457 
def is_true(a)
Definition: z3py.py:1441
def is_app_of(a, k)
Definition: z3py.py:1238

Referenced by AstRef.__bool__().

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

1182 def is_var(a):
1183  """Return `True` if `a` is variable.
1184 
1185  Z3 uses de-Bruijn indices for representing bound variables in
1186  quantifiers.
1187 
1188  >>> x = Int('x')
1189  >>> is_var(x)
1190  False
1191  >>> is_const(x)
1192  True
1193  >>> f = Function('f', IntSort(), IntSort())
1194  >>> # Z3 replaces x with bound variables when ForAll is executed.
1195  >>> q = ForAll(x, f(x) == x)
1196  >>> b = q.body()
1197  >>> b
1198  f(Var(0)) == Var(0)
1199  >>> b.arg(1)
1200  Var(0)
1201  >>> is_var(b.arg(1))
1202  True
1203  """
1204  return is_expr(a) and _ast_kind(a.ctx, a) == Z3_VAR_AST
1205 
def is_expr(a)
Definition: z3py.py:1117
def is_var(a)
Definition: z3py.py:1182

Referenced by get_var_index().

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

3148 def IsInt(a):
3149  """ Return the Z3 predicate IsInt(a).
3150 
3151  >>> x = Real('x')
3152  >>> IsInt(x + "1/2")
3153  IsInt(x + 1/2)
3154  >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3155  [x = 1/2]
3156  >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3157  no solution
3158  """
3159  if z3_debug():
3160  _z3_assert(a.is_real(), "Z3 real expression expected.")
3161  ctx = a.ctx
3162  return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
3163 
def IsInt(a)
Definition: z3py.py:3148
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
def z3_debug()
Definition: z3py.py:58

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

4655 def IsMember(e, s):
4656  """ Check if e is a member of set s
4657  >>> a = Const('a', SetSort(IntSort()))
4658  >>> IsMember(1, a)
4659  a[1]
4660  """
4661  ctx = _ctx_from_ast_arg_list([s,e])
4662  e = _py2expr(e, ctx)
4663  return BoolRef(Z3_mk_set_member(ctx.ref(), e.as_ast(), s.as_ast()), ctx)
4664 
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:4655

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

4665 def IsSubset(a, b):
4666  """ Check if a is a subset of b
4667  >>> a = Const('a', SetSort(IntSort()))
4668  >>> b = Const('b', SetSort(IntSort()))
4669  >>> IsSubset(a, b)
4670  subset(a, b)
4671  """
4672  ctx = _ctx_from_ast_arg_list([a, b])
4673  return BoolRef(Z3_mk_set_subset(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4674 
4675 
def IsSubset(a, b)
Definition: z3py.py:4665
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 4505 of file z3py.py.

4505 def K(dom, v):
4506  """Return a Z3 constant array expression.
4507 
4508  >>> a = K(IntSort(), 10)
4509  >>> a
4510  K(Int, 10)
4511  >>> a.sort()
4512  Array(Int, Int)
4513  >>> i = Int('i')
4514  >>> a[i]
4515  K(Int, 10)[i]
4516  >>> simplify(a[i])
4517  10
4518  """
4519  if z3_debug():
4520  _z3_assert(is_sort(dom), "Z3 sort expected")
4521  ctx = dom.ctx
4522  if not is_expr(v):
4523  v = _py2expr(v, ctx)
4524  return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
4525 
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:598
def z3_debug()
Definition: z3py.py:58
def K(dom, v)
Definition: z3py.py:4505
def is_expr(a)
Definition: z3py.py:1117

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

2085 def Lambda(vs, body):
2086  """Create a Z3 lambda expression.
2087 
2088  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2089  >>> mem0 = Array('mem0', IntSort(), IntSort())
2090  >>> lo, hi, e, i = Ints('lo hi e i')
2091  >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2092  >>> mem1
2093  Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2094  """
2095  ctx = body.ctx
2096  if is_app(vs):
2097  vs = [vs]
2098  num_vars = len(vs)
2099  _vs = (Ast * num_vars)()
2100  for i in range(num_vars):
2101 
2102  _vs[i] = vs[i].as_ast()
2103  return QuantifierRef(Z3_mk_lambda_const(ctx.ref(), num_vars, _vs, body.as_ast()), ctx)
2104 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def is_app(a)
Definition: z3py.py:1139
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:2085

◆ LastIndexOf()

def z3py.LastIndexOf (   s,
  substr 
)
Retrieve the last index of substring within a string

Definition at line 10235 of file z3py.py.

10235 def LastIndexOf(s, substr):
10236  """Retrieve the last index of substring within a string"""
10237  ctx = None
10238  ctx = _get_ctx2(s, substr, ctx)
10239  s = _coerce_seq(s, ctx)
10240  substr = _coerce_seq(substr, ctx)
10241  return ArithRef(Z3_mk_seq_last_index(s.ctx_ref(), s.as_ast(), substr.as_ast()), s.ctx)
10242 
10243 
def LastIndexOf(s, substr)
Definition: z3py.py:10235
Z3_ast Z3_API Z3_mk_seq_last_index(Z3_context c, Z3_ast, Z3_ast substr)
Return the last occurrence of substr in s. If s does not contain substr, then the value is -1,...

◆ Length()

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

Definition at line 10244 of file z3py.py.

10244 def Length(s):
10245  """Obtain the length of a sequence 's'
10246  >>> l = Length(StringVal("abc"))
10247  >>> simplify(l)
10248  3
10249  """
10250  s = _coerce_seq(s)
10251  return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
10252 
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:10244

◆ LinearOrder()

def z3py.LinearOrder (   a,
  index 
)

Definition at line 10433 of file z3py.py.

10433 def LinearOrder(a, index):
10434  return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx);
10435 
def LinearOrder(a, index)
Definition: z3py.py:10433
Z3_func_decl Z3_API Z3_mk_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a linear ordering relation over signature a. The relation is identified by the index id.

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

10404 def Loop(re, lo, hi=0):
10405  """Create the regular expression accepting between a lower and upper bound repetitions
10406  >>> re = Loop(Re("a"), 1, 3)
10407  >>> print(simplify(InRe("aa", re)))
10408  True
10409  >>> print(simplify(InRe("aaaa", re)))
10410  False
10411  >>> print(simplify(InRe("", re)))
10412  False
10413  """
10414  return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
10415 
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:10404

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

4017 def LShR(a, b):
4018  """Create the Z3 expression logical right shift.
4019 
4020  Use the operator >> for the arithmetical right shift.
4021 
4022  >>> x, y = BitVecs('x y', 32)
4023  >>> LShR(x, y)
4024  LShR(x, y)
4025  >>> (x >> y).sexpr()
4026  '(bvashr x y)'
4027  >>> LShR(x, y).sexpr()
4028  '(bvlshr x y)'
4029  >>> BitVecVal(4, 3)
4030  4
4031  >>> BitVecVal(4, 3).as_signed_long()
4032  -4
4033  >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4034  -2
4035  >>> simplify(BitVecVal(4, 3) >> 1)
4036  6
4037  >>> simplify(LShR(BitVecVal(4, 3), 1))
4038  2
4039  >>> simplify(BitVecVal(2, 3) >> 1)
4040  1
4041  >>> simplify(LShR(BitVecVal(2, 3), 1))
4042  1
4043  """
4044  _check_bv_args(a, b)
4045  a, b = _coerce_exprs(a, b)
4046  return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4047 
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:4017

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

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

Referenced by SeqRef.__gt__(), And(), help_simplify(), Or(), and simplify_param_descrs().

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

4483 def Map(f, *args):
4484  """Return a Z3 map array expression.
4485 
4486  >>> f = Function('f', IntSort(), IntSort(), IntSort())
4487  >>> a1 = Array('a1', IntSort(), IntSort())
4488  >>> a2 = Array('a2', IntSort(), IntSort())
4489  >>> b = Map(f, a1, a2)
4490  >>> b
4491  Map(f, a1, a2)
4492  >>> prove(b[0] == f(a1[0], a2[0]))
4493  proved
4494  """
4495  args = _get_args(args)
4496  if z3_debug():
4497  _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
4498  _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
4499  _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
4500  _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
4501  _args, sz = _to_ast_array(args)
4502  ctx = f.ctx
4503  return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
4504 
def Map(f, *args)
Definition: z3py.py:4483
def is_array(a)
Definition: z3py.py:4298
def z3_debug()
Definition: z3py.py:58
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:789

Referenced by Context.Context().

◆ mk_not()

def z3py.mk_not (   a)

Definition at line 1671 of file z3py.py.

1671 def mk_not(a):
1672  if is_not(a):
1673  return a.arg(0)
1674  else:
1675  return Not(a)
1676 
def mk_not(a)
Definition: z3py.py:1671
def is_not(a)
Definition: z3py.py:1504
def Not(a, ctx=None)
Definition: z3py.py:1653

◆ Model()

def z3py.Model (   ctx = None)

Definition at line 6240 of file z3py.py.

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

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

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

1780 def MultiPattern(*args):
1781  """Create a Z3 multi-pattern using the given expressions `*args`
1782 
1783  >>> f = Function('f', IntSort(), IntSort())
1784  >>> g = Function('g', IntSort(), IntSort())
1785  >>> x = Int('x')
1786  >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
1787  >>> q
1788  ForAll(x, f(x) != g(x))
1789  >>> q.num_patterns()
1790  1
1791  >>> is_pattern(q.pattern(0))
1792  True
1793  >>> q.pattern(0)
1794  MultiPattern(f(Var(0)), g(Var(0)))
1795  """
1796  if z3_debug():
1797  _z3_assert(len(args) > 0, "At least one argument expected")
1798  _z3_assert(all([ is_expr(a) for a in args ]), "Z3 expressions expected")
1799  ctx = args[0].ctx
1800  args, sz = _to_ast_array(args)
1801  return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
1802 
def MultiPattern(*args)
Definition: z3py.py:1780
def z3_debug()
Definition: z3py.py:58
Z3_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[])
Create a pattern for quantifier instantiation.
def is_expr(a)
Definition: z3py.py:1117

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

1653 def Not(a, ctx=None):
1654  """Create a Z3 not expression or probe.
1655 
1656  >>> p = Bool('p')
1657  >>> Not(Not(p))
1658  Not(Not(p))
1659  >>> simplify(Not(Not(p)))
1660  p
1661  """
1662  ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1663  if is_probe(a):
1664  # Not is also used to build probes
1665  return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1666  else:
1667  s = BoolSort(ctx)
1668  a = s.cast(a)
1669  return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1670 
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:1653
def is_probe(p)
Definition: z3py.py:8064
def BoolSort(ctx=None)
Definition: z3py.py:1535

Referenced by fpNEQ(), mk_not(), and prove().

◆ open_log()

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

Definition at line 103 of file z3py.py.

103 def open_log(fname):
104  """Log interaction to a file. This function must be invoked immediately after init(). """
105  Z3_open_log(fname)
106 
def open_log(fname)
Definition: z3py.py:103
bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.

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

10376 def Option(re):
10377  """Create the regular expression that optionally accepts the argument.
10378  >>> re = Option(Re("a"))
10379  >>> print(simplify(InRe("a", re)))
10380  True
10381  >>> print(simplify(InRe("", re)))
10382  True
10383  >>> print(simplify(InRe("aa", re)))
10384  False
10385  """
10386  return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
10387 
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:10376

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

1717 def Or(*args):
1718  """Create a Z3 or-expression or or-probe.
1719 
1720  >>> p, q, r = Bools('p q r')
1721  >>> Or(p, q, r)
1722  Or(p, q, r)
1723  >>> P = BoolVector('p', 5)
1724  >>> Or(P)
1725  Or(p__0, p__1, p__2, p__3, p__4)
1726  """
1727  last_arg = None
1728  if len(args) > 0:
1729  last_arg = args[len(args)-1]
1730  if isinstance(last_arg, Context):
1731  ctx = args[len(args)-1]
1732  args = args[:len(args)-1]
1733  else:
1734  ctx = main_ctx()
1735  args = _get_args(args)
1736  ctx_args = _ctx_from_ast_arg_list(args, ctx)
1737  if z3_debug():
1738  _z3_assert(ctx_args is None or ctx_args == ctx, "context mismatch")
1739  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1740  if _has_probe(args):
1741  return _probe_or(args, ctx)
1742  else:
1743  args = _coerce_expr_list(args, ctx)
1744  _args, sz = _to_ast_array(args)
1745  return BoolRef(Z3_mk_or(ctx.ref(), sz, _args), ctx)
1746 
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 Or(*args)
Definition: z3py.py:1717
def main_ctx()
Definition: z3py.py:213
def z3_debug()
Definition: z3py.py:58

Referenced by ApplyResult.as_expr().

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

7780 def OrElse(*ts, **ks):
7781  """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
7782 
7783  >>> x = Int('x')
7784  >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
7785  >>> # Tactic split-clause fails if there is no clause in the given goal.
7786  >>> t(x == 0)
7787  [[x == 0]]
7788  >>> t(Or(x == 0, x == 1))
7789  [[x == 0], [x == 1]]
7790  """
7791  if z3_debug():
7792  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7793  ctx = ks.get('ctx', None)
7794  num = len(ts)
7795  r = ts[0]
7796  for i in range(num - 1):
7797  r = _or_else(r, ts[i+1], ctx)
7798  return r
7799 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def z3_debug()
Definition: z3py.py:58
def OrElse(*ts, **ks)
Definition: z3py.py:7780

◆ ParAndThen()

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

Definition at line 7832 of file z3py.py.

7832 def ParAndThen(t1, t2, ctx=None):
7833  """Alias for ParThen(t1, t2, ctx)."""
7834  return ParThen(t1, t2, ctx)
7835 
def ParAndThen(t1, t2, ctx=None)
Definition: z3py.py:7832
def ParThen(t1, t2, ctx=None)
Definition: z3py.py:7818

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

7800 def ParOr(*ts, **ks):
7801  """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
7802 
7803  >>> x = Int('x')
7804  >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
7805  >>> t(x + 1 == 2)
7806  [[x == 1]]
7807  """
7808  if z3_debug():
7809  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7810  ctx = _get_ctx(ks.get('ctx', None))
7811  ts = [ _to_tactic(t, ctx) for t in ts ]
7812  sz = len(ts)
7813  _args = (TacticObj * sz)()
7814  for i in range(sz):
7815  _args[i] = ts[i].tactic
7816  return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
7817 
def ParOr(*ts, **ks)
Definition: z3py.py:7800
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def z3_debug()
Definition: z3py.py:58
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.

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

8605 def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
8606  """Parse a file in SMT 2.0 format using the given sorts and decls.
8607 
8608  This function is similar to parse_smt2_string().
8609  """
8610  ctx = _get_ctx(ctx)
8611  ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8612  dsz, dnames, ddecls = _dict2darray(decls, ctx)
8613  return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
8614 
8615 
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
Definition: z3py.py:8605
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 8585 of file z3py.py.

8585 def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
8586  """Parse a string in SMT 2.0 format using the given sorts and decls.
8587 
8588  The arguments sorts and decls are Python dictionaries used to initialize
8589  the symbol table used for the SMT 2.0 parser.
8590 
8591  >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
8592  [x > 0, x < 10]
8593  >>> x, y = Ints('x y')
8594  >>> f = Function('f', IntSort(), IntSort())
8595  >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
8596  [x + f(y) > 0]
8597  >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
8598  [a > 0]
8599  """
8600  ctx = _get_ctx(ctx)
8601  ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8602  dsz, dnames, ddecls = _dict2darray(decls, ctx)
8603  return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
8604 
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
Definition: z3py.py:8585
Z3_ast_vector Z3_API Z3_parse_smtlib2_string(Z3_context c, Z3_string str, 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[])
Parse the given string using the SMT-LIB2 parser.

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

7818 def ParThen(t1, t2, ctx=None):
7819  """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.
7820 
7821  >>> x, y = Ints('x y')
7822  >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
7823  >>> t(And(Or(x == 1, x == 2), y == x + 1))
7824  [[x == 1, y == 2], [x == 2, y == 3]]
7825  """
7826  t1 = _to_tactic(t1, ctx)
7827  t2 = _to_tactic(t2, ctx)
7828  if z3_debug():
7829  _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
7830  return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
7831 
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 z3_debug()
Definition: z3py.py:58
def ParThen(t1, t2, ctx=None)
Definition: z3py.py:7818

Referenced by ParAndThen().

◆ PartialOrder()

def z3py.PartialOrder (   a,
  index 
)

Definition at line 10430 of file z3py.py.

10430 def PartialOrder(a, index):
10431  return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx);
10432 
Z3_func_decl Z3_API Z3_mk_partial_order(Z3_context c, Z3_sort a, unsigned id)
create a partial ordering relation over signature a and index id.
def PartialOrder(a, index)
Definition: z3py.py:10430

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

8392 def PbEq(args, k, ctx = None):
8393  """Create a Pseudo-Boolean inequality k constraint.
8394 
8395  >>> a, b, c = Bools('a b c')
8396  >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
8397  """
8398  _z3_check_cint_overflow(k, "k")
8399  ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8400  return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
8401 
8402 
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:8392

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

8382 def PbGe(args, k):
8383  """Create a Pseudo-Boolean inequality k constraint.
8384 
8385  >>> a, b, c = Bools('a b c')
8386  >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
8387  """
8388  _z3_check_cint_overflow(k, "k")
8389  ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8390  return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
8391 
def PbGe(args, k)
Definition: z3py.py:8382
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 8372 of file z3py.py.

8372 def PbLe(args, k):
8373  """Create a Pseudo-Boolean inequality k constraint.
8374 
8375  >>> a, b, c = Bools('a b c')
8376  >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
8377  """
8378  _z3_check_cint_overflow(k, "k")
8379  ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8380  return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
8381 
def PbLe(args, k)
Definition: z3py.py:8372
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.

◆ PiecewiseLinearOrder()

def z3py.PiecewiseLinearOrder (   a,
  index 
)

Definition at line 10439 of file z3py.py.

10439 def PiecewiseLinearOrder(a, index):
10440  return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx);
10441 
Z3_func_decl Z3_API Z3_mk_piecewise_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a piecewise linear ordering relation over signature a and index id.
def PiecewiseLinearOrder(a, index)
Definition: z3py.py:10439

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

10364 def Plus(re):
10365  """Create the regular expression accepting one or more repetitions of argument.
10366  >>> re = Plus(Re("a"))
10367  >>> print(simplify(InRe("aa", re)))
10368  True
10369  >>> print(simplify(InRe("ab", re)))
10370  False
10371  >>> print(simplify(InRe("", re)))
10372  False
10373  """
10374  return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
10375 
def Plus(re)
Definition: z3py.py:10364
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 10154 of file z3py.py.

10154 def PrefixOf(a, b):
10155  """Check if 'a' is a prefix of 'b'
10156  >>> s1 = PrefixOf("ab", "abc")
10157  >>> simplify(s1)
10158  True
10159  >>> s2 = PrefixOf("bc", "abc")
10160  >>> simplify(s2)
10161  False
10162  """
10163  ctx = _get_ctx2(a, b)
10164  a = _coerce_seq(a, ctx)
10165  b = _coerce_seq(b, ctx)
10166  return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
10167 
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:10154

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

8090 def probe_description(name, ctx=None):
8091  """Return a short description for the probe named `name`.
8092 
8093  >>> d = probe_description('memory')
8094  """
8095  ctx = _get_ctx(ctx)
8096  return Z3_probe_get_descr(ctx.ref(), name)
8097 
def probe_description(name, ctx=None)
Definition: z3py.py:8090
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.

Referenced by describe_probes().

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

8080 def probes(ctx=None):
8081  """Return a list of all available probes in Z3.
8082 
8083  >>> l = probes()
8084  >>> l.count('memory') == 1
8085  True
8086  """
8087  ctx = _get_ctx(ctx)
8088  return [ Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref())) ]
8089 
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:3370
def probes(ctx=None)
Definition: z3py.py:8080
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.

Referenced by describe_probes().

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

8288 def Product(*args):
8289  """Create the product of the Z3 expressions.
8290 
8291  >>> a, b, c = Ints('a b c')
8292  >>> Product(a, b, c)
8293  a*b*c
8294  >>> Product([a, b, c])
8295  a*b*c
8296  >>> A = IntVector('a', 5)
8297  >>> Product(A)
8298  a__0*a__1*a__2*a__3*a__4
8299  """
8300  args = _get_args(args)
8301  if len(args) == 0:
8302  return 1
8303  ctx = _ctx_from_ast_arg_list(args)
8304  if ctx is None:
8305  return _reduce(lambda a, b: a * b, args, 1)
8306  args = _coerce_expr_list(args, ctx)
8307  if is_bv(args[0]):
8308  return _reduce(lambda a, b: a * b, args, 1)
8309  else:
8310  _args, sz = _to_ast_array(args)
8311  return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
8312 
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:8288
def is_bv(a)
Definition: z3py.py:3687

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

8460 def prove(claim, **keywords):
8461  """Try to prove the given claim.
8462 
8463  This is a simple function for creating demonstrations. It tries to prove
8464  `claim` by showing the negation is unsatisfiable.
8465 
8466  >>> p, q = Bools('p q')
8467  >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
8468  proved
8469  """
8470  if z3_debug():
8471  _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
8472  s = Solver()
8473  s.set(**keywords)
8474  s.add(Not(claim))
8475  if keywords.get('show', False):
8476  print(s)
8477  r = s.check()
8478  if r == unsat:
8479  print("proved")
8480  elif r == unknown:
8481  print("failed to prove")
8482  print(s.model())
8483  else:
8484  print("counterexample")
8485  print(s.model())
8486 
def z3_debug()
Definition: z3py.py:58
def Not(a, ctx=None)
Definition: z3py.py:1653
def is_bool(a)
Definition: z3py.py:1424
def prove(claim, **keywords)
Definition: z3py.py:8460

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

3002 def Q(a, b, ctx=None):
3003  """Return a Z3 rational a/b.
3004 
3005  If `ctx=None`, then the global context is used.
3006 
3007  >>> Q(3,5)
3008  3/5
3009  >>> Q(3,5).sort()
3010  Real
3011  """
3012  return simplify(RatVal(a, b))
3013 
def RatVal(a, b, ctx=None)
Definition: z3py.py:2987
def simplify(a, *arguments, **keywords)
Utils.
Definition: z3py.py:8184
def Q(a, b, ctx=None)
Definition: z3py.py:3002

◆ Range()

def z3py.Range (   lo,
  hi,
  ctx = None 
)
Create the range regular expression over two sequences of length 1
>>> range = Range("a","z")
>>> print(simplify(InRe("b", range)))
True
>>> print(simplify(InRe("bb", range)))
False

Definition at line 10416 of file z3py.py.

10416 def Range(lo, hi, ctx = None):
10417  """Create the range regular expression over two sequences of length 1
10418  >>> range = Range("a","z")
10419  >>> print(simplify(InRe("b", range)))
10420  True
10421  >>> print(simplify(InRe("bb", range)))
10422  False
10423  """
10424  lo = _coerce_seq(lo, ctx)
10425  hi = _coerce_seq(hi, ctx)
10426  return ReRef(Z3_mk_re_range(lo.ctx_ref(), lo.ast, hi.ast), lo.ctx)
10427 
10428 # Special Relations
10429 
def Range(lo, hi, ctx=None)
Definition: z3py.py:10416
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.

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

2987 def RatVal(a, b, ctx=None):
2988  """Return a Z3 rational a/b.
2989 
2990  If `ctx=None`, then the global context is used.
2991 
2992  >>> RatVal(3,5)
2993  3/5
2994  >>> RatVal(3,5).sort()
2995  Real
2996  """
2997  if z3_debug():
2998  _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
2999  _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
3000  return simplify(RealVal(a, ctx)/RealVal(b, ctx))
3001 
def RatVal(a, b, ctx=None)
Definition: z3py.py:2987
def simplify(a, *arguments, **keywords)
Utils.
Definition: z3py.py:8184
def RealVal(val, ctx=None)
Definition: z3py.py:2969
def z3_debug()
Definition: z3py.py:58

Referenced by Q().

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

10276 def Re(s, ctx=None):
10277  """The regular expression that accepts sequence 's'
10278  >>> s1 = Re("ab")
10279  >>> s2 = Re(StringVal("ab"))
10280  >>> s3 = Re(Unit(BoolVal(True)))
10281  """
10282  s = _coerce_seq(s, ctx)
10283  return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
10284 
10285 
10286 
10287 
def Re(s, ctx=None)
Definition: z3py.py:10276
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 3062 of file z3py.py.

3062 def Real(name, ctx=None):
3063  """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3064 
3065  >>> x = Real('x')
3066  >>> is_real(x)
3067  True
3068  >>> is_real(x + 1)
3069  True
3070  """
3071  ctx = _get_ctx(ctx)
3072  return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
3073 
def RealSort(ctx=None)
Definition: z3py.py:2927
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:111
def Real(name, ctx=None)
Definition: z3py.py:3062

Referenced by Reals(), and RealVector().

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

3074 def Reals(names, ctx=None):
3075  """Return a tuple of real constants.
3076 
3077  >>> x, y, z = Reals('x y z')
3078  >>> Sum(x, y, z)
3079  x + y + z
3080  >>> Sum(x, y, z).sort()
3081  Real
3082  """
3083  ctx = _get_ctx(ctx)
3084  if isinstance(names, str):
3085  names = names.split(" ")
3086  return [Real(name, ctx) for name in names]
3087 
def Real(name, ctx=None)
Definition: z3py.py:3062
def Reals(names, ctx=None)
Definition: z3py.py:3074

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

2927 def RealSort(ctx=None):
2928  """Return the real sort in the given context. If `ctx=None`, then the global context is used.
2929 
2930  >>> RealSort()
2931  Real
2932  >>> x = Const('x', RealSort())
2933  >>> is_real(x)
2934  True
2935  >>> is_int(x)
2936  False
2937  >>> x.sort() == RealSort()
2938  True
2939  """
2940  ctx = _get_ctx(ctx)
2941  return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
2942 
def RealSort(ctx=None)
Definition: z3py.py:2927
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.

Referenced by FreshReal(), Context.getRealSort(), Context.mkRealSort(), Real(), RealVal(), and RealVar().

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

2969 def RealVal(val, ctx=None):
2970  """Return a Z3 real value.
2971 
2972  `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
2973  If `ctx=None`, then the global context is used.
2974 
2975  >>> RealVal(1)
2976  1
2977  >>> RealVal(1).sort()
2978  Real
2979  >>> RealVal("3/5")
2980  3/5
2981  >>> RealVal("1.5")
2982  3/2
2983  """
2984  ctx = _get_ctx(ctx)
2985  return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), RealSort(ctx).ast), ctx)
2986 
def RealSort(ctx=None)
Definition: z3py.py:2927
def RealVal(val, ctx=None)
Definition: z3py.py:2969
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.

Referenced by AlgebraicNumRef.as_decimal(), Cbrt(), RatVal(), and Sqrt().

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

1345 def RealVar(idx, ctx=None):
1346  """
1347  Create a real free variable. Free variables are used to create quantified formulas.
1348  They are also used to create polynomials.
1349 
1350  >>> RealVar(0)
1351  Var(0)
1352  """
1353  return Var(idx, RealSort(ctx))
1354 
def RealSort(ctx=None)
Definition: z3py.py:2927
def Var(idx, s)
Definition: z3py.py:1333
def RealVar(idx, ctx=None)
Definition: z3py.py:1345

Referenced by RealVarVector().

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

1355 def RealVarVector(n, ctx=None):
1356  """
1357  Create a list of Real free variables.
1358  The variables have ids: 0, 1, ..., n-1
1359 
1360  >>> x0, x1, x2, x3 = RealVarVector(4)
1361  >>> x2
1362  Var(2)
1363  """
1364  return [ RealVar(i, ctx) for i in range(n) ]
1365 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def RealVarVector(n, ctx=None)
Definition: z3py.py:1355
def RealVar(idx, ctx=None)
Definition: z3py.py:1345

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

3088 def RealVector(prefix, sz, ctx=None):
3089  """Return a list of real constants of size `sz`.
3090 
3091  >>> X = RealVector('x', 3)
3092  >>> X
3093  [x__0, x__1, x__2]
3094  >>> Sum(X)
3095  x__0 + x__1 + x__2
3096  >>> Sum(X).sort()
3097  Real
3098  """
3099  return [ Real('%s__%s' % (prefix, i)) for i in range(sz) ]
3100 
def RealVector(prefix, sz, ctx=None)
Definition: z3py.py:3088
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def Real(name, ctx=None)
Definition: z3py.py:3062

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

843 def RecAddDefinition(f, args, body):
844  """Set the body of a recursive function.
845  Recursive definitions are only unfolded during search.
846  >>> ctx = Context()
847  >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
848  >>> n = Int('n', ctx)
849  >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
850  >>> simplify(fac(5))
851  fac(5)
852  >>> s = Solver(ctx=ctx)
853  >>> s.add(fac(n) < 3)
854  >>> s.check()
855  sat
856  >>> s.model().eval(fac(5))
857  120
858  """
859  if is_app(args):
860  args = [args]
861  ctx = body.ctx
862  args = _get_args(args)
863  n = len(args)
864  _args = (Ast * n)()
865  for i in range(n):
866  _args[i] = args[i].ast
867  Z3_add_rec_def(ctx.ref(), f.ast, n, _args, body.ast)
868 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def is_app(a)
Definition: z3py.py:1139
def RecAddDefinition(f, args, body)
Definition: z3py.py:843
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 826 of file z3py.py.

826 def RecFunction(name, *sig):
827  """Create a new Z3 recursive with the given sorts."""
828  sig = _get_args(sig)
829  if z3_debug():
830  _z3_assert(len(sig) > 0, "At least two arguments expected")
831  arity = len(sig) - 1
832  rng = sig[arity]
833  if z3_debug():
834  _z3_assert(is_sort(rng), "Z3 sort expected")
835  dom = (Sort * arity)()
836  for i in range(arity):
837  if z3_debug():
838  _z3_assert(is_sort(sig[i]), "Z3 sort expected")
839  dom[i] = sig[i].ast
840  ctx = rng.ctx
841  return FuncDeclRef(Z3_mk_rec_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
842 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def to_symbol(s, ctx=None)
Definition: z3py.py:111
def is_sort(s)
Definition: z3py.py:598
def z3_debug()
Definition: z3py.py:58
def RecFunction(name, *sig)
Definition: z3py.py:826
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 7862 of file z3py.py.

7862 def Repeat(t, max=4294967295, ctx=None):
7863  """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.
7864 
7865  >>> x, y = Ints('x y')
7866  >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
7867  >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
7868  >>> r = t(c)
7869  >>> for subgoal in r: print(subgoal)
7870  [x == 0, y == 0, x > y]
7871  [x == 0, y == 1, x > y]
7872  [x == 1, y == 0, x > y]
7873  [x == 1, y == 1, x > y]
7874  >>> t = Then(t, Tactic('propagate-values'))
7875  >>> t(c)
7876  [[x == 1, y == 0]]
7877  """
7878  t = _to_tactic(t, ctx)
7879  return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
7880 
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:7862

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

4134 def RepeatBitVec(n, a):
4135  """Return an expression representing `n` copies of `a`.
4136 
4137  >>> x = BitVec('x', 8)
4138  >>> n = RepeatBitVec(4, x)
4139  >>> n
4140  RepeatBitVec(4, x)
4141  >>> n.size()
4142  32
4143  >>> v0 = BitVecVal(10, 4)
4144  >>> print("%.x" % v0.as_long())
4145  a
4146  >>> v = simplify(RepeatBitVec(4, v0))
4147  >>> v.size()
4148  16
4149  >>> print("%.x" % v.as_long())
4150  aaaa
4151  """
4152  if z3_debug():
4153  _z3_assert(_is_int(n), "First argument must be an integer")
4154  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
4155  return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
4156 
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
def z3_debug()
Definition: z3py.py:58
def is_bv(a)
Definition: z3py.py:3687
def RepeatBitVec(n, a)
Definition: z3py.py:4134

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

10201 def Replace(s, src, dst):
10202  """Replace the first occurrence of 'src' by 'dst' in 's'
10203  >>> r = Replace("aaa", "a", "b")
10204  >>> simplify(r)
10205  "baa"
10206  """
10207  ctx = _get_ctx2(dst, s)
10208  if ctx is None and is_expr(src):
10209  ctx = src.ctx
10210  src = _coerce_seq(src, ctx)
10211  dst = _coerce_seq(dst, ctx)
10212  s = _coerce_seq(s, ctx)
10213  return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
10214 
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:10201
def is_expr(a)
Definition: z3py.py:1117

◆ reset_params()

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

Definition at line 265 of file z3py.py.

265 def reset_params():
266  """Reset all global (or module) parameters.
267  """
269 
def reset_params()
Definition: z3py.py:265
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 10296 of file z3py.py.

10296 def ReSort(s):
10297  if is_ast(s):
10298  return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
10299  if s is None or isinstance(s, Context):
10300  ctx = _get_ctx(s)
10301  return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
10302  raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
10303 
10304 
def ReSort(s)
Definition: z3py.py:10296
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:414
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort seq)
Create a regular expression sort out of a sequence sort.

Referenced by Context.mkReSort().

◆ RNA()

def z3py.RNA (   ctx = None)

Definition at line 8994 of file z3py.py.

8994 def RNA (ctx=None):
8995  ctx = _get_ctx(ctx)
8996  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
8997 
def RNA(ctx=None)
Definition: z3py.py:8994
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.

Referenced by get_default_rounding_mode().

◆ RNE()

def z3py.RNE (   ctx = None)

Definition at line 8986 of file z3py.py.

8986 def RNE (ctx=None):
8987  ctx = _get_ctx(ctx)
8988  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
8989 
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:8986

Referenced by get_default_rounding_mode().

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

4048 def RotateLeft(a, b):
4049  """Return an expression representing `a` rotated to the left `b` times.
4050 
4051  >>> a, b = BitVecs('a b', 16)
4052  >>> RotateLeft(a, b)
4053  RotateLeft(a, b)
4054  >>> simplify(RotateLeft(a, 0))
4055  a
4056  >>> simplify(RotateLeft(a, 16))
4057  a
4058  """
4059  _check_bv_args(a, b)
4060  a, b = _coerce_exprs(a, b)
4061  return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4062 
def RotateLeft(a, b)
Definition: z3py.py:4048
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 4063 of file z3py.py.

4063 def RotateRight(a, b):
4064  """Return an expression representing `a` rotated to the right `b` times.
4065 
4066  >>> a, b = BitVecs('a b', 16)
4067  >>> RotateRight(a, b)
4068  RotateRight(a, b)
4069  >>> simplify(RotateRight(a, 0))
4070  a
4071  >>> simplify(RotateRight(a, 16))
4072  a
4073  """
4074  _check_bv_args(a, b)
4075  a, b = _coerce_exprs(a, b)
4076  return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4077 
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:4063

◆ RoundNearestTiesToAway()

def z3py.RoundNearestTiesToAway (   ctx = None)

Definition at line 8990 of file z3py.py.

8990 def RoundNearestTiesToAway(ctx=None):
8991  ctx = _get_ctx(ctx)
8992  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
8993 
def RoundNearestTiesToAway(ctx=None)
Definition: z3py.py:8990
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 8982 of file z3py.py.

8982 def RoundNearestTiesToEven(ctx=None):
8983  ctx = _get_ctx(ctx)
8984  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
8985 
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:8982

◆ RoundTowardNegative()

def z3py.RoundTowardNegative (   ctx = None)

Definition at line 9006 of file z3py.py.

9006 def RoundTowardNegative(ctx=None):
9007  ctx = _get_ctx(ctx)
9008  return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
9009 
def RoundTowardNegative(ctx=None)
Definition: z3py.py:9006
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 8998 of file z3py.py.

8998 def RoundTowardPositive(ctx=None):
8999  ctx = _get_ctx(ctx)
9000  return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
9001 
def RoundTowardPositive(ctx=None)
Definition: z3py.py:8998
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 9014 of file z3py.py.

9014 def RoundTowardZero(ctx=None):
9015  ctx = _get_ctx(ctx)
9016  return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
9017 
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:9014

◆ RTN()

def z3py.RTN (   ctx = None)

Definition at line 9010 of file z3py.py.

9010 def RTN(ctx=None):
9011  ctx = _get_ctx(ctx)
9012  return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
9013 
def RTN(ctx=None)
Definition: z3py.py:9010
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.

Referenced by get_default_rounding_mode().

◆ RTP()

def z3py.RTP (   ctx = None)

Definition at line 9002 of file z3py.py.

9002 def RTP(ctx=None):
9003  ctx = _get_ctx(ctx)
9004  return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
9005 
def RTP(ctx=None)
Definition: z3py.py:9002
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.

Referenced by get_default_rounding_mode().

◆ RTZ()

def z3py.RTZ (   ctx = None)

Definition at line 9018 of file z3py.py.

9018 def RTZ(ctx=None):
9019  ctx = _get_ctx(ctx)
9020  return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
9021 
def RTZ(ctx=None)
Definition: z3py.py:9018
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.

Referenced by get_default_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 4468 of file z3py.py.

4468 def Select(a, i):
4469  """Return a Z3 select array expression.
4470 
4471  >>> a = Array('a', IntSort(), IntSort())
4472  >>> i = Int('i')
4473  >>> Select(a, i)
4474  a[i]
4475  >>> eq(Select(a, i), a[i])
4476  True
4477  """
4478  if z3_debug():
4479  _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4480  return a[i]
4481 
4482 
def is_array_sort(a)
Definition: z3py.py:4294
def z3_debug()
Definition: z3py.py:58
def Select(a, i)
Definition: z3py.py:4468

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

9982 def SeqSort(s):
9983  """Create a sequence sort over elements provided in the argument
9984  >>> s = SeqSort(IntSort())
9985  >>> s == Unit(IntVal(1)).sort()
9986  True
9987  """
9988  return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
9989 
def SeqSort(s)
Definition: z3py.py:9982
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.

Referenced by Context.mkSeqSort(), and Context.mkStringSort().

◆ set_default_fp_sort()

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

Definition at line 8658 of file z3py.py.

8658 def set_default_fp_sort(ebits, sbits, ctx=None):
8659  global _dflt_fpsort_ebits
8660  global _dflt_fpsort_sbits
8661  _dflt_fpsort_ebits = ebits
8662  _dflt_fpsort_sbits = sbits
8663 
def set_default_fp_sort(ebits, sbits, ctx=None)
Definition: z3py.py:8658

◆ set_default_rounding_mode()

def z3py.set_default_rounding_mode (   rm,
  ctx = None 
)

Definition at line 8642 of file z3py.py.

8642 def set_default_rounding_mode(rm, ctx=None):
8643  global _dflt_rounding_mode
8644  if is_fprm_value(rm):
8645  _dflt_rounding_mode = rm.decl().kind()
8646  else:
8647  _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO or
8648  _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE or
8649  _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE or
8650  _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN or
8651  _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY,
8652  "illegal rounding mode")
8653  _dflt_rounding_mode = rm
8654 
def set_default_rounding_mode(rm, ctx=None)
Definition: z3py.py:8642
def is_fprm_value(a)
Definition: z3py.py:9034

◆ set_option()

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

Definition at line 270 of file z3py.py.

270 def set_option(*args, **kws):
271  """Alias for 'set_param' for backward compatibility.
272  """
273  return set_param(*args, **kws)
274 
def set_param(*args, **kws)
Definition: z3py.py:242
def set_option(*args, **kws)
Definition: z3py.py:270

◆ set_param()

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

>>> set_param(precision=10)

Definition at line 242 of file z3py.py.

242 def set_param(*args, **kws):
243  """Set Z3 global (or module) parameters.
244 
245  >>> set_param(precision=10)
246  """
247  if z3_debug():
248  _z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
249  new_kws = {}
250  for k in kws:
251  v = kws[k]
252  if not set_pp_option(k, v):
253  new_kws[k] = v
254  for key in new_kws:
255  value = new_kws[key]
256  Z3_global_param_set(str(key).upper(), _to_param_value(value))
257  prev = None
258  for a in args:
259  if prev is None:
260  prev = a
261  else:
262  Z3_global_param_set(str(prev), _to_param_value(a))
263  prev = None
264 
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:242
def z3_debug()
Definition: z3py.py:58

Referenced by set_option().

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

4616 def SetAdd(s, e):
4617  """ Add element e to set s
4618  >>> a = Const('a', SetSort(IntSort()))
4619  >>> SetAdd(a, 1)
4620  Store(a, 1, True)
4621  """
4622  ctx = _ctx_from_ast_arg_list([s,e])
4623  e = _py2expr(e, ctx)
4624  return ArrayRef(Z3_mk_set_add(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
4625 
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:4616

◆ SetComplement()

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

Definition at line 4636 of file z3py.py.

4636 def SetComplement(s):
4637  """ The complement of set s
4638  >>> a = Const('a', SetSort(IntSort()))
4639  >>> SetComplement(a)
4640  complement(a)
4641  """
4642  ctx = s.ctx
4643  return ArrayRef(Z3_mk_set_complement(ctx.ref(), s.as_ast()), ctx)
4644 
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:4636

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

4626 def SetDel(s, e):
4627  """ Remove element e to set s
4628  >>> a = Const('a', SetSort(IntSort()))
4629  >>> SetDel(a, 1)
4630  Store(a, 1, False)
4631  """
4632  ctx = _ctx_from_ast_arg_list([s,e])
4633  e = _py2expr(e, ctx)
4634  return ArrayRef(Z3_mk_set_del(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
4635 
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:4626

◆ 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)
setminus(a, b)

Definition at line 4645 of file z3py.py.

4645 def SetDifference(a, b):
4646  """ The set difference of a and b
4647  >>> a = Const('a', SetSort(IntSort()))
4648  >>> b = Const('b', SetSort(IntSort()))
4649  >>> SetDifference(a, b)
4650  setminus(a, b)
4651  """
4652  ctx = _ctx_from_ast_arg_list([a, b])
4653  return ArrayRef(Z3_mk_set_difference(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4654 
def SetDifference(a, b)
Definition: z3py.py:4645
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.

◆ SetHasSize()

def z3py.SetHasSize (   a,
  k 
)

Definition at line 4537 of file z3py.py.

4537 def SetHasSize(a, k):
4538  ctx = a.ctx
4539  k = _py2expr(k, ctx)
4540  return _to_expr_ref(Z3_mk_set_has_size(ctx.ref(), a.as_ast(), k.as_ast()), ctx)
4541 
def SetHasSize(a, k)
Definition: z3py.py:4537
Z3_ast Z3_API Z3_mk_set_has_size(Z3_context c, Z3_ast set, Z3_ast k)
Create predicate that holds if Boolean array set has k elements set to true.

◆ SetIntersect()

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

Definition at line 4604 of file z3py.py.

4604 def SetIntersect(*args):
4605  """ Take the union of sets
4606  >>> a = Const('a', SetSort(IntSort()))
4607  >>> b = Const('b', SetSort(IntSort()))
4608  >>> SetIntersect(a, b)
4609  intersection(a, b)
4610  """
4611  args = _get_args(args)
4612  ctx = _ctx_from_ast_arg_list(args)
4613  _args, sz = _to_ast_array(args)
4614  return ArrayRef(Z3_mk_set_intersect(ctx.ref(), sz, _args), ctx)
4615 
def SetIntersect(*args)
Definition: z3py.py:4604
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.

◆ SetSort()

def z3py.SetSort (   s)

Sets.

Create a set sort over element sort s

Definition at line 4572 of file z3py.py.

4572 def SetSort(s):
4573  """ Create a set sort over element sort s"""
4574  return ArraySort(s, BoolSort())
4575 
def SetSort(s)
Sets.
Definition: z3py.py:4572
def ArraySort(*sig)
Definition: z3py.py:4375
def BoolSort(ctx=None)
Definition: z3py.py:1535

Referenced by Context.mkSetSort().

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

4592 def SetUnion(*args):
4593  """ Take the union of sets
4594  >>> a = Const('a', SetSort(IntSort()))
4595  >>> b = Const('b', SetSort(IntSort()))
4596  >>> SetUnion(a, b)
4597  union(a, b)
4598  """
4599  args = _get_args(args)
4600  ctx = _ctx_from_ast_arg_list(args)
4601  _args, sz = _to_ast_array(args)
4602  return ArrayRef(Z3_mk_set_union(ctx.ref(), sz, _args), ctx)
4603 
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.
def SetUnion(*args)
Definition: z3py.py:4592

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

4078 def SignExt(n, a):
4079  """Return a bit-vector expression with `n` extra sign-bits.
4080 
4081  >>> x = BitVec('x', 16)
4082  >>> n = SignExt(8, x)
4083  >>> n.size()
4084  24
4085  >>> n
4086  SignExt(8, x)
4087  >>> n.sort()
4088  BitVec(24)
4089  >>> v0 = BitVecVal(2, 2)
4090  >>> v0
4091  2
4092  >>> v0.size()
4093  2
4094  >>> v = simplify(SignExt(6, v0))
4095  >>> v
4096  254
4097  >>> v.size()
4098  8
4099  >>> print("%.x" % v.as_long())
4100  fe
4101  """
4102  if z3_debug():
4103  _z3_assert(_is_int(n), "First argument must be an integer")
4104  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
4105  return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4106 
def SignExt(n, a)
Definition: z3py.py:4078
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 z3_debug()
Definition: z3py.py:58
def is_bv(a)
Definition: z3py.py:3687

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

6933 def SimpleSolver(ctx=None):
6934  """Return a simple general purpose solver with limited amount of preprocessing.
6935 
6936  >>> s = SimpleSolver()
6937  >>> x = Int('x')
6938  >>> s.add(x > 0)
6939  >>> s.check()
6940  sat
6941  """
6942  ctx = _get_ctx(ctx)
6943  return Solver(Z3_mk_simple_solver(ctx.ref()), ctx)
6944 
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
def SimpleSolver(ctx=None)
Definition: z3py.py:6933

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

8184 def simplify(a, *arguments, **keywords):
8185  """Simplify the expression `a` using the given options.
8186 
8187  This function has many options. Use `help_simplify` to obtain the complete list.
8188 
8189  >>> x = Int('x')
8190  >>> y = Int('y')
8191  >>> simplify(x + 1 + y + x + 1)
8192  2 + 2*x + y
8193  >>> simplify((x + 1)*(y + 1), som=True)
8194  1 + x + y + x*y
8195  >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8196  And(Not(x == y), Not(x == 1), Not(y == 1))
8197  >>> simplify(And(x == 0, y == 1), elim_and=True)
8198  Not(Or(Not(x == 0), Not(y == 1)))
8199  """
8200  if z3_debug():
8201  _z3_assert(is_expr(a), "Z3 expression expected")
8202  if len(arguments) > 0 or len(keywords) > 0:
8203  p = args2params(arguments, keywords, a.ctx)
8204  return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8205  else:
8206  return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8207 
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:5074
def simplify(a, *arguments, **keywords)
Utils.
Definition: z3py.py:8184
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 z3_debug()
Definition: z3py.py:58
def is_expr(a)
Definition: z3py.py:1117

Referenced by Q(), and RatVal().

◆ simplify_param_descrs()

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

Definition at line 8212 of file z3py.py.

8212 def simplify_param_descrs():
8213  """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8214  return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
8215 
def main_ctx()
Definition: z3py.py:213
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:8212

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

8403 def solve(*args, **keywords):
8404  """Solve the constraints `*args`.
8405 
8406  This is a simple function for creating demonstrations. It creates a solver,
8407  configure it using the options in `keywords`, adds the constraints
8408  in `args`, and invokes check.
8409 
8410  >>> a = Int('a')
8411  >>> solve(a > 0, a < 2)
8412  [a = 1]
8413  """
8414  s = Solver()
8415  s.set(**keywords)
8416  s.add(*args)
8417  if keywords.get('show', False):
8418  print(s)
8419  r = s.check()
8420  if r == unsat:
8421  print("no solution")
8422  elif r == unknown:
8423  print("failed to solve")
8424  try:
8425  print(s.model())
8426  except Z3Exception:
8427  return
8428  else:
8429  print(s.model())
8430 
def solve(*args, **keywords)
Definition: z3py.py:8403

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

8431 def solve_using(s, *args, **keywords):
8432  """Solve the constraints `*args` using solver `s`.
8433 
8434  This is a simple function for creating demonstrations. It is similar to `solve`,
8435  but it uses the given solver `s`.
8436  It configures solver `s` using the options in `keywords`, adds the constraints
8437  in `args`, and invokes check.
8438  """
8439  if z3_debug():
8440  _z3_assert(isinstance(s, Solver), "Solver object expected")
8441  s.set(**keywords)
8442  s.add(*args)
8443  if keywords.get('show', False):
8444  print("Problem:")
8445  print(s)
8446  r = s.check()
8447  if r == unsat:
8448  print("no solution")
8449  elif r == unknown:
8450  print("failed to solve")
8451  try:
8452  print(s.model())
8453  except Z3Exception:
8454  return
8455  else:
8456  if keywords.get('show', False):
8457  print("Solution:")
8458  print(s.model())
8459 
def solve_using(s, *args, **keywords)
Definition: z3py.py:8431
def z3_debug()
Definition: z3py.py:58

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

6913 def SolverFor(logic, ctx=None):
6914  """Create a solver customized for the given logic.
6915 
6916  The parameter `logic` is a string. It should be contains
6917  the name of a SMT-LIB logic.
6918  See http://www.smtlib.org/ for the name of all available logics.
6919 
6920  >>> s = SolverFor("QF_LIA")
6921  >>> x = Int('x')
6922  >>> s.add(x > 0)
6923  >>> s.add(x < 2)
6924  >>> s.check()
6925  sat
6926  >>> s.model()
6927  [x = 1]
6928  """
6929  ctx = _get_ctx(ctx)
6930  logic = to_symbol(logic)
6931  return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx)
6932 
def to_symbol(s, ctx=None)
Definition: z3py.py:111
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:6913

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

3164 def Sqrt(a, ctx=None):
3165  """ Return a Z3 expression which represents the square root of a.
3166 
3167  >>> x = Real('x')
3168  >>> Sqrt(x)
3169  x**(1/2)
3170  """
3171  if not is_expr(a):
3172  ctx = _get_ctx(ctx)
3173  a = RealVal(a, ctx)
3174  return a ** "1/2"
3175 
def RealVal(val, ctx=None)
Definition: z3py.py:2969
def is_expr(a)
Definition: z3py.py:1117
def Sqrt(a, ctx=None)
Definition: z3py.py:3164

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

3997 def SRem(a, b):
3998  """Create the Z3 expression signed remainder.
3999 
4000  Use the operator % for signed modulus, and URem() for unsigned remainder.
4001 
4002  >>> x = BitVec('x', 32)
4003  >>> y = BitVec('y', 32)
4004  >>> SRem(x, y)
4005  SRem(x, y)
4006  >>> SRem(x, y).sort()
4007  BitVec(32)
4008  >>> (x % y).sexpr()
4009  '(bvsmod x y)'
4010  >>> SRem(x, y).sexpr()
4011  '(bvsrem x y)'
4012  """
4013  _check_bv_args(a, b)
4014  a, b = _coerce_exprs(a, b)
4015  return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4016 
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).
def SRem(a, b)
Definition: z3py.py:3997

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

10392 def Star(re):
10393  """Create the regular expression accepting zero or more repetitions of argument.
10394  >>> re = Star(Re("a"))
10395  >>> print(simplify(InRe("aa", re)))
10396  True
10397  >>> print(simplify(InRe("ab", re)))
10398  False
10399  >>> print(simplify(InRe("", re)))
10400  True
10401  """
10402  return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
10403 
def Star(re)
Definition: z3py.py:10392
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 4452 of file z3py.py.

4452 def Store(a, i, v):
4453  """Return a Z3 store array expression.
4454 
4455  >>> a = Array('a', IntSort(), IntSort())
4456  >>> i, v = Ints('i v')
4457  >>> s = Store(a, i, v)
4458  >>> s.sort()
4459  Array(Int, Int)
4460  >>> prove(s[i] == v)
4461  proved
4462  >>> j = Int('j')
4463  >>> prove(Implies(i != j, s[j] == a[j]))
4464  proved
4465  """
4466  return Update(a, i, v)
4467 
def Update(a, i, v)
Definition: z3py.py:4420
def Store(a, i, v)
Definition: z3py.py:4452

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

10087 def String(name, ctx=None):
10088  """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10089 
10090  >>> x = String('x')
10091  """
10092  ctx = _get_ctx(ctx)
10093  return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
10094 
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:111
def StringSort(ctx=None)
Definition: z3py.py:9972
def String(name, ctx=None)
Definition: z3py.py:10087

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.getLstring(), 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.solverToDimacsString(), Native.solverToString(), Native.sortToString(), Native.statsGetKey(), Native.statsToString(), Strings(), SubSeq(), Native.tacticGetDescr(), Native.tacticGetHelp(), and FuncInterp.toString().

◆ Strings()

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

Definition at line 10095 of file z3py.py.

10095 def Strings(names, ctx=None):
10096  """Return string constants"""
10097  ctx = _get_ctx(ctx)
10098  if isinstance(names, str):
10099  names = names.split(" ")
10100  return [String(name, ctx) for name in names]
10101 
def Strings(names, ctx=None)
Definition: z3py.py:10095
def String(name, ctx=None)
Definition: z3py.py:10087

Referenced by SubSeq().

◆ StringSort()

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

Definition at line 9972 of file z3py.py.

9972 def StringSort(ctx=None):
9973  """Create a string sort
9974  >>> s = StringSort()
9975  >>> print(s)
9976  String
9977  """
9978  ctx = _get_ctx(ctx)
9979  return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
9980 
9981 
def StringSort(ctx=None)
Definition: z3py.py:9972
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for 8 bit strings.

Referenced by String().

◆ StringVal()

def z3py.StringVal (   s,
  ctx = None 
)
create a string expression

Definition at line 10082 of file z3py.py.

10082 def StringVal(s, ctx=None):
10083  """create a string expression"""
10084  ctx = _get_ctx(ctx)
10085  return SeqRef(Z3_mk_lstring(ctx.ref(), len(s), s), ctx)
10086 
def StringVal(s, ctx=None)
Definition: z3py.py:10082
Z3_ast Z3_API Z3_mk_lstring(Z3_context c, unsigned len, Z3_string s)
Create a string constant out of the string that is passed in It takes the length of the string as wel...

Referenced by SeqRef.__gt__(), and Extract().

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

10253 def StrToInt(s):
10254  """Convert string expression to integer
10255  >>> a = StrToInt("1")
10256  >>> simplify(1 == a)
10257  True
10258  >>> b = StrToInt("2")
10259  >>> simplify(1 == b)
10260  False
10261  >>> c = StrToInt(IntToStr(2))
10262  >>> simplify(1 == c)
10263  False
10264  """
10265  s = _coerce_seq(s)
10266  return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
10267 
10268 
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:10253

◆ SubSeq()

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

Definition at line 10106 of file z3py.py.

10106 def SubSeq(s, offset, length):
10107  """Extract substring or subsequence starting at offset"""
10108  return Extract(s, offset, length)
10109 
def SubSeq(s, offset, length)
Definition: z3py.py:10106
def Extract(high, low, a)
Definition: z3py.py:3862

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

8216 def substitute(t, *m):
8217  """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.
8218 
8219  >>> x = Int('x')
8220  >>> y = Int('y')
8221  >>> substitute(x + 1, (x, y + 1))
8222  y + 1 + 1
8223  >>> f = Function('f', IntSort(), IntSort())
8224  >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8225  1 + 1
8226  """
8227  if isinstance(m, tuple):
8228  m1 = _get_args(m)
8229  if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
8230  m = m1
8231  if z3_debug():
8232  _z3_assert(is_expr(t), "Z3 expression expected")
8233  _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.")
8234  num = len(m)
8235  _from = (Ast * num)()
8236  _to = (Ast * num)()
8237  for i in range(num):
8238  _from[i] = m[i][0].as_ast()
8239  _to[i] = m[i][1].as_ast()
8240  return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8241 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
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....
def substitute(t, *m)
Definition: z3py.py:8216
def eq(a, b)
Definition: z3py.py:434
def z3_debug()
Definition: z3py.py:58
def is_expr(a)
Definition: z3py.py:1117

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

8242 def substitute_vars(t, *m):
8243  """Substitute the free variables in t with the expression in m.
8244 
8245  >>> v0 = Var(0, IntSort())
8246  >>> v1 = Var(1, IntSort())
8247  >>> x = Int('x')
8248  >>> f = Function('f', IntSort(), IntSort(), IntSort())
8249  >>> # replace v0 with x+1 and v1 with x
8250  >>> substitute_vars(f(v0, v1), x + 1, x)
8251  f(x + 1, x)
8252  """
8253  if z3_debug():
8254  _z3_assert(is_expr(t), "Z3 expression expected")
8255  _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
8256  num = len(m)
8257  _to = (Ast * num)()
8258  for i in range(num):
8259  _to[i] = m[i].as_ast()
8260  return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
8261 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
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 substitute_vars(t, *m)
Definition: z3py.py:8242
def z3_debug()
Definition: z3py.py:58
def is_expr(a)
Definition: z3py.py:1117

◆ SubString()

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

Definition at line 10102 of file z3py.py.

10102 def SubString(s, offset, length):
10103  """Extract substring or subsequence starting at offset"""
10104  return Extract(s, offset, length)
10105 
def SubString(s, offset, length)
Definition: z3py.py:10102
def Extract(high, low, a)
Definition: z3py.py:3862

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

10168 def SuffixOf(a, b):
10169  """Check if 'a' is a suffix of 'b'
10170  >>> s1 = SuffixOf("ab", "abc")
10171  >>> simplify(s1)
10172  False
10173  >>> s2 = SuffixOf("bc", "abc")
10174  >>> simplify(s2)
10175  True
10176  """
10177  ctx = _get_ctx2(a, b)
10178  a = _coerce_seq(a, ctx)
10179  b = _coerce_seq(b, ctx)
10180  return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
10181 
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:10168

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

8262 def Sum(*args):
8263  """Create the sum of the Z3 expressions.
8264 
8265  >>> a, b, c = Ints('a b c')
8266  >>> Sum(a, b, c)
8267  a + b + c
8268  >>> Sum([a, b, c])
8269  a + b + c
8270  >>> A = IntVector('a', 5)
8271  >>> Sum(A)
8272  a__0 + a__1 + a__2 + a__3 + a__4
8273  """
8274  args = _get_args(args)
8275  if len(args) == 0:
8276  return 0
8277  ctx = _ctx_from_ast_arg_list(args)
8278  if ctx is None:
8279  return _reduce(lambda a, b: a + b, args, 0)
8280  args = _coerce_expr_list(args, ctx)
8281  if is_bv(args[0]):
8282  return _reduce(lambda a, b: a + b, args, 0)
8283  else:
8284  _args, sz = _to_ast_array(args)
8285  return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
8286 
8287 
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 Sum(*args)
Definition: z3py.py:8262
def is_bv(a)
Definition: z3py.py:3687

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

7899 def tactic_description(name, ctx=None):
7900  """Return a short description for the tactic named `name`.
7901 
7902  >>> d = tactic_description('simplify')
7903  """
7904  ctx = _get_ctx(ctx)
7905  return Z3_tactic_get_descr(ctx.ref(), name)
7906 
def tactic_description(name, ctx=None)
Definition: z3py.py:7899
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.

Referenced by describe_tactics().

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

7889 def tactics(ctx=None):
7890  """Return a list of all available tactics in Z3.
7891 
7892  >>> l = tactics()
7893  >>> l.count('simplify') == 1
7894  True
7895  """
7896  ctx = _get_ctx(ctx)
7897  return [ Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref())) ]
7898 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
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:7889
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.

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

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

7768 def Then(*ts, **ks):
7769  """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
7770 
7771  >>> x, y = Ints('x y')
7772  >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
7773  >>> t(And(x == 0, y > x + 1))
7774  [[Not(y <= 1)]]
7775  >>> t(And(x == 0, y > x + 1)).as_expr()
7776  Not(y <= 1)
7777  """
7778  return AndThen(*ts, **ks)
7779 
def Then(*ts, **ks)
Definition: z3py.py:7768
def AndThen(*ts, **ks)
Definition: z3py.py:7749

◆ to_symbol()

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

Definition at line 111 of file z3py.py.

111 def to_symbol(s, ctx=None):
112  """Convert an integer or string into a Z3 symbol."""
113  if _is_int(s):
114  return Z3_mk_int_symbol(_get_ctx(ctx).ref(), s)
115  else:
116  return Z3_mk_string_symbol(_get_ctx(ctx).ref(), s)
117 
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:111
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.

Referenced by Fixedpoint.add_rule(), Optimize.add_soft(), Array(), BitVec(), Bool(), Const(), CreateDatatypes(), DeclareSort(), EnumSort(), FiniteDomainSort(), FP(), Function(), ParamDescrsRef.get_documentation(), ParamDescrsRef.get_kind(), Int(), is_quantifier(), prove(), Real(), RecFunction(), ParamsRef.set(), Fixedpoint.set_predicate_representation(), SolverFor(), String(), and Fixedpoint.update_rule().

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

3131 def ToInt(a):
3132  """ Return the Z3 expression ToInt(a).
3133 
3134  >>> x = Real('x')
3135  >>> x.sort()
3136  Real
3137  >>> n = ToInt(x)
3138  >>> n
3139  ToInt(x)
3140  >>> n.sort()
3141  Int
3142  """
3143  if z3_debug():
3144  _z3_assert(a.is_real(), "Z3 real expression expected.")
3145  ctx = a.ctx
3146  return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
3147 
Z3_ast Z3_API Z3_mk_real2int(Z3_context c, Z3_ast t1)
Coerce a real to an integer.
def z3_debug()
Definition: z3py.py:58
def ToInt(a)
Definition: z3py.py:3131

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

3114 def ToReal(a):
3115  """ Return the Z3 expression ToReal(a).
3116 
3117  >>> x = Int('x')
3118  >>> x.sort()
3119  Int
3120  >>> n = ToReal(x)
3121  >>> n
3122  ToReal(x)
3123  >>> n.sort()
3124  Real
3125  """
3126  if z3_debug():
3127  _z3_assert(a.is_int(), "Z3 integer expression expected.")
3128  ctx = a.ctx
3129  return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
3130 
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:3114
def z3_debug()
Definition: z3py.py:58

◆ TransitiveClosure()

def z3py.TransitiveClosure (   f)
Given a binary relation R, such that the two arguments have the same sort
create the transitive closure relation R+.
The transitive closure R+ is a new relation.

Definition at line 10442 of file z3py.py.

10442 def TransitiveClosure(f):
10443  """Given a binary relation R, such that the two arguments have the same sort
10444  create the transitive closure relation R+.
10445  The transitive closure R+ is a new relation.
10446  """
10447  return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
def TransitiveClosure(f)
Definition: z3py.py:10442
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.

◆ TreeOrder()

def z3py.TreeOrder (   a,
  index 
)

Definition at line 10436 of file z3py.py.

10436 def TreeOrder(a, index):
10437  return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx);
10438 
def TreeOrder(a, index)
Definition: z3py.py:10436
Z3_func_decl Z3_API Z3_mk_tree_order(Z3_context c, Z3_sort a, unsigned id)
create a tree ordering relation over signature a identified using index id.

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

7881 def TryFor(t, ms, ctx=None):
7882  """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
7883 
7884  If `t` does not terminate in `ms` milliseconds, then it fails.
7885  """
7886  t = _to_tactic(t, ctx)
7887  return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
7888 
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:7881

◆ TupleSort()

def z3py.TupleSort (   name,
  sorts,
  ctx = None 
)
Create a named tuple sort base on a set of underlying sorts
Example:
    >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])

Definition at line 4975 of file z3py.py.

4975 def TupleSort(name, sorts, ctx = None):
4976  """Create a named tuple sort base on a set of underlying sorts
4977  Example:
4978  >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
4979  """
4980  tuple = Datatype(name, ctx)
4981  projects = [ ('project%d' % i, sorts[i]) for i in range(len(sorts)) ]
4982  tuple.declare(name, *projects)
4983  tuple = tuple.create()
4984  return tuple, tuple.constructor(0), [tuple.accessor(0, i) for i in range(len(sorts))]
4985 
def TupleSort(name, sorts, ctx=None)
Definition: z3py.py:4975
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370

Referenced by Context.mkTupleSort().

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

3957 def UDiv(a, b):
3958  """Create the Z3 expression (unsigned) division `self / other`.
3959 
3960  Use the operator / for signed division.
3961 
3962  >>> x = BitVec('x', 32)
3963  >>> y = BitVec('y', 32)
3964  >>> UDiv(x, y)
3965  UDiv(x, y)
3966  >>> UDiv(x, y).sort()
3967  BitVec(32)
3968  >>> (x / y).sexpr()
3969  '(bvsdiv x y)'
3970  >>> UDiv(x, y).sexpr()
3971  '(bvudiv x y)'
3972  """
3973  _check_bv_args(a, b)
3974  a, b = _coerce_exprs(a, b)
3975  return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3976 
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:3957

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

3923 def UGE(a, b):
3924  """Create the Z3 expression (unsigned) `other >= self`.
3925 
3926  Use the operator >= for signed greater than or equal to.
3927 
3928  >>> x, y = BitVecs('x y', 32)
3929  >>> UGE(x, y)
3930  UGE(x, y)
3931  >>> (x >= y).sexpr()
3932  '(bvsge x y)'
3933  >>> UGE(x, y).sexpr()
3934  '(bvuge x y)'
3935  """
3936  _check_bv_args(a, b)
3937  a, b = _coerce_exprs(a, b)
3938  return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3939 
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:3923

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

3940 def UGT(a, b):
3941  """Create the Z3 expression (unsigned) `other > self`.
3942 
3943  Use the operator > for signed greater than.
3944 
3945  >>> x, y = BitVecs('x y', 32)
3946  >>> UGT(x, y)
3947  UGT(x, y)
3948  >>> (x > y).sexpr()
3949  '(bvsgt x y)'
3950  >>> UGT(x, y).sexpr()
3951  '(bvugt x y)'
3952  """
3953  _check_bv_args(a, b)
3954  a, b = _coerce_exprs(a, b)
3955  return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3956 
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:3940

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

3889 def ULE(a, b):
3890  """Create the Z3 expression (unsigned) `other <= self`.
3891 
3892  Use the operator <= for signed less than or equal to.
3893 
3894  >>> x, y = BitVecs('x y', 32)
3895  >>> ULE(x, y)
3896  ULE(x, y)
3897  >>> (x <= y).sexpr()
3898  '(bvsle x y)'
3899  >>> ULE(x, y).sexpr()
3900  '(bvule x y)'
3901  """
3902  _check_bv_args(a, b)
3903  a, b = _coerce_exprs(a, b)
3904  return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3905 
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:3889

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

3906 def ULT(a, b):
3907  """Create the Z3 expression (unsigned) `other < self`.
3908 
3909  Use the operator < for signed less than.
3910 
3911  >>> x, y = BitVecs('x y', 32)
3912  >>> ULT(x, y)
3913  ULT(x, y)
3914  >>> (x < y).sexpr()
3915  '(bvslt x y)'
3916  >>> ULT(x, y).sexpr()
3917  '(bvult x y)'
3918  """
3919  _check_bv_args(a, b)
3920  a, b = _coerce_exprs(a, b)
3921  return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3922 
def ULT(a, b)
Definition: z3py.py:3906
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 10328 of file z3py.py.

10328 def Union(*args):
10329  """Create union of regular expressions.
10330  >>> re = Union(Re("a"), Re("b"), Re("c"))
10331  >>> print (simplify(InRe("d", re)))
10332  False
10333  """
10334  args = _get_args(args)
10335  sz = len(args)
10336  if z3_debug():
10337  _z3_assert(sz > 0, "At least one argument expected.")
10338  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
10339  if sz == 1:
10340  return args[0]
10341  ctx = args[0].ctx
10342  v = (Ast * sz)()
10343  for i in range(sz):
10344  v[i] = args[i].as_ast()
10345  return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
10346 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
def Union(*args)
Definition: z3py.py:10328
def is_re(s)
Definition: z3py.py:10311
def z3_debug()
Definition: z3py.py:58
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.

Referenced by ReRef.__add__().

◆ Unit()

def z3py.Unit (   a)
Create a singleton sequence

Definition at line 10150 of file z3py.py.

10150 def Unit(a):
10151  """Create a singleton sequence"""
10152  return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
10153 
def Unit(a)
Definition: z3py.py:10150
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 4420 of file z3py.py.

4420 def Update(a, i, v):
4421  """Return a Z3 store array expression.
4422 
4423  >>> a = Array('a', IntSort(), IntSort())
4424  >>> i, v = Ints('i v')
4425  >>> s = Update(a, i, v)
4426  >>> s.sort()
4427  Array(Int, Int)
4428  >>> prove(s[i] == v)
4429  proved
4430  >>> j = Int('j')
4431  >>> prove(Implies(i != j, s[j] == a[j]))
4432  proved
4433  """
4434  if z3_debug():
4435  _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4436  i = a.domain().cast(i)
4437  v = a.range().cast(v)
4438  ctx = a.ctx
4439  return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4440 
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
def is_array_sort(a)
Definition: z3py.py:4294
def z3_debug()
Definition: z3py.py:58
def Update(a, i, v)
Definition: z3py.py:4420

Referenced by Store().

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

3977 def URem(a, b):
3978  """Create the Z3 expression (unsigned) remainder `self % other`.
3979 
3980  Use the operator % for signed modulus, and SRem() for signed remainder.
3981 
3982  >>> x = BitVec('x', 32)
3983  >>> y = BitVec('y', 32)
3984  >>> URem(x, y)
3985  URem(x, y)
3986  >>> URem(x, y).sort()
3987  BitVec(32)
3988  >>> (x % y).sexpr()
3989  '(bvsmod x y)'
3990  >>> URem(x, y).sexpr()
3991  '(bvurem x y)'
3992  """
3993  _check_bv_args(a, b)
3994  a, b = _coerce_exprs(a, b)
3995  return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3996 
def URem(a, b)
Definition: z3py.py:3977
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 1333 of file z3py.py.

1333 def Var(idx, s):
1334  """Create a Z3 free variable. Free variables are used to create quantified formulas.
1335 
1336  >>> Var(0, IntSort())
1337  Var(0)
1338  >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1339  False
1340  """
1341  if z3_debug():
1342  _z3_assert(is_sort(s), "Z3 sort expected")
1343  return _to_expr_ref(Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1344 
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:1333
def is_sort(s)
Definition: z3py.py:598
def z3_debug()
Definition: z3py.py:58

Referenced by RealVar().

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

8150 def When(p, t, ctx=None):
8151  """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8152 
8153  >>> t = When(Probe('size') > 2, Tactic('simplify'))
8154  >>> x, y = Ints('x y')
8155  >>> g = Goal()
8156  >>> g.add(x > 0)
8157  >>> g.add(y > 0)
8158  >>> t(g)
8159  [[x > 0, y > 0]]
8160  >>> g.add(x == y + 1)
8161  >>> t(g)
8162  [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8163  """
8164  p = _to_probe(p, ctx)
8165  t = _to_tactic(t, ctx)
8166  return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
8167 
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:8150

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

7836 def With(t, *args, **keys):
7837  """Return a tactic that applies tactic `t` using the given configuration options.
7838 
7839  >>> x, y = Ints('x y')
7840  >>> t = With(Tactic('simplify'), som=True)
7841  >>> t((x + 1)*(y + 2) == 0)
7842  [[2*x + y + x*y == -2]]
7843  """
7844  ctx = keys.pop('ctx', None)
7845  t = _to_tactic(t, ctx)
7846  p = args2params(args, keys, t.ctx)
7847  return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
7848 
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:5074
def With(t, *args, **keys)
Definition: z3py.py:7836
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.

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

7849 def WithParams(t, p):
7850  """Return a tactic that applies tactic `t` using the given configuration options.
7851 
7852  >>> x, y = Ints('x y')
7853  >>> p = ParamsRef()
7854  >>> p.set("som", True)
7855  >>> t = WithParams(Tactic('simplify'), p)
7856  >>> t((x + 1)*(y + 2) == 0)
7857  [[2*x + y + x*y == -2]]
7858  """
7859  t = _to_tactic(t, None)
7860  return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
7861 
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:7849

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

1638 def Xor(a, b, ctx=None):
1639  """Create a Z3 Xor expression.
1640 
1641  >>> p, q = Bools('p q')
1642  >>> Xor(p, q)
1643  Xor(p, q)
1644  >>> simplify(Xor(p, q))
1645  Not(p) == q
1646  """
1647  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1648  s = BoolSort(ctx)
1649  a = s.cast(a)
1650  b = s.cast(b)
1651  return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1652 
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:1638
def BoolSort(ctx=None)
Definition: z3py.py:1535

◆ z3_debug()

def z3py.z3_debug ( )

Definition at line 58 of file z3py.py.

58 def z3_debug():
59  global Z3_DEBUG
60  return Z3_DEBUG
61 
def z3_debug()
Definition: z3py.py:58

Referenced by FuncDeclRef.__call__(), Probe.__call__(), QuantifierRef.__getitem__(), ModelRef.__getitem__(), Context.__init__(), Goal.__init__(), ArithRef.__mod__(), ArithRef.__rmod__(), DatatypeSortRef.accessor(), And(), AndThen(), Tactic.apply(), ExprRef.arg(), args2params(), ArraySort(), AlgebraicNumRef.as_decimal(), IntNumRef.as_long(), AtLeast(), AtMost(), BV2Int(), BVRedAnd(), BVRedOr(), BVSNegNoOverflow(), SortRef.cast(), BoolSortRef.cast(), ArithSortRef.cast(), BitVecSortRef.cast(), FPSortRef.cast(), ExprRef.children(), Concat(), Const(), DatatypeSortRef.constructor(), Goal.convert_model(), CreateDatatypes(), ExprRef.decl(), Datatype.declare(), Datatype.declare_core(), Default(), describe_probes(), Distinct(), FuncDeclRef.domain(), EnumSort(), AstRef.eq(), eq(), Ext(), Extract(), FiniteDomainVal(), fpIsPositive(), fpNeg(), FPSort(), fpToFPUnsigned(), fpToIEEEBV(), fpToReal(), fpToSBV(), fpToUBV(), Function(), get_as_array_func(), ModelRef.get_interp(), get_map_func(), ModelRef.get_universe(), get_var_index(), If(), Intersect(), is_quantifier(), is_sort(), IsInt(), K(), Map(), MultiPattern(), QuantifierRef.no_pattern(), ExprRef.num_args(), Or(), OrElse(), Tactic.param_descrs(), ParOr(), ParThen(), QuantifierRef.pattern(), prove(), RatVal(), RealSort(), RecFunction(), DatatypeSortRef.recognizer(), RepeatBitVec(), Select(), ParamsRef.set(), set_param(), SignExt(), simplify(), solve_using(), substitute(), substitute_vars(), ToInt(), ToReal(), AstRef.translate(), Goal.translate(), ModelRef.translate(), Solver.translate(), Union(), Update(), Var(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and ZeroExt().

◆ z3_error_handler()

def z3py.z3_error_handler (   c,
  e 
)

Definition at line 158 of file z3py.py.

158 def z3_error_handler(c, e):
159  # Do nothing error handler, just avoid exit(0)
160  # The wrappers in z3core.py will raise a Z3Exception if an error is detected
161  return
162 
def z3_error_handler(c, e)
Definition: z3py.py:158

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

4107 def ZeroExt(n, a):
4108  """Return a bit-vector expression with `n` extra zero-bits.
4109 
4110  >>> x = BitVec('x', 16)
4111  >>> n = ZeroExt(8, x)
4112  >>> n.size()
4113  24
4114  >>> n
4115  ZeroExt(8, x)
4116  >>> n.sort()
4117  BitVec(24)
4118  >>> v0 = BitVecVal(2, 2)
4119  >>> v0
4120  2
4121  >>> v0.size()
4122  2
4123  >>> v = simplify(ZeroExt(6, v0))
4124  >>> v
4125  2
4126  >>> v.size()
4127  8
4128  """
4129  if z3_debug():
4130  _z3_assert(_is_int(n), "First argument must be an integer")
4131  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
4132  return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4133 
def ZeroExt(n, a)
Definition: z3py.py:4107
def z3_debug()
Definition: z3py.py:58
def is_bv(a)
Definition: z3py.py:3687
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 6436 of file z3py.py.

◆ unknown

Definition at line 6438 of file z3py.py.

◆ unsat

Definition at line 6437 of file z3py.py.

◆ Z3_DEBUG

Z3_DEBUG = __debug__

Definition at line 56 of file z3py.py.