Z3
Data Structures | Functions | Variables
z3py Namespace Reference

Data Structures

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

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 FreshFunction (*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, *sorts)
 
def Update (a, *args)
 
def Default (a)
 
def Store (a, *args)
 
def Select (a, *args)
 
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, logFile=None)
 
def SimpleSolver (ctx=None, logFile=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 Abs (arg)
 
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, show=False, **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 CharSort (ctx=None)
 
def SeqSort (s)
 
def CharVal (ch, ctx=None)
 
def CharFromBv (ch, ctx=None)
 
def CharToBv (ch, ctx=None)
 
def CharToInt (ch, ctx=None)
 
def CharIsDigit (ch, ctx=None)
 
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, offset=None)
 
def LastIndexOf (s, substr)
 
def Length (s)
 
def StrToInt (s)
 
def IntToStr (s)
 
def StrToCode (s)
 
def StrFromCode (c)
 
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 Diff (a, b, ctx=None)
 
def AllChar (regex_sort, ctx=None)
 
def PartialOrder (a, index)
 
def LinearOrder (a, index)
 
def TreeOrder (a, index)
 
def PiecewiseLinearOrder (a, index)
 
def TransitiveClosure (f)
 
def ensure_prop_closures ()
 
def user_prop_push (ctx)
 
def user_prop_pop (ctx, num_scopes)
 
def user_prop_fresh (id, ctx)
 
def to_Ast (ptr)
 
def user_prop_fixed (ctx, cb, id, value)
 
def user_prop_final (ctx, cb)
 
def user_prop_eq (ctx, cb, x, y)
 
def user_prop_diseq (ctx, cb, x, y)
 

Variables

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

Function Documentation

◆ Abs()

def z3py.Abs (   arg)
Create the absolute value of an arithmetic expression

Definition at line 8816 of file z3py.py.

8816 def Abs(arg):
8817  """Create the absolute value of an arithmetic expression"""
8818  return If(arg > 0, arg, -arg)
8819 
8820 
def Abs(arg)
Definition: z3py.py:8816
def If(a, b, c, ctx=None)
Definition: z3py.py:1348

◆ AllChar()

def z3py.AllChar (   regex_sort,
  ctx = None 
)
Create a regular expression that accepts all single character strings

Definition at line 11163 of file z3py.py.

11163 def AllChar(regex_sort, ctx=None):
11164  """Create a regular expression that accepts all single character strings
11165  """
11166  return ReRef(Z3_mk_re_allchar(regex_sort.ctx_ref(), regex_sort.ast), regex_sort.ctx)
11167 
11168 # Special Relations
11169 
11170 
Z3_ast Z3_API Z3_mk_re_allchar(Z3_context c, Z3_sort regex_sort)
Create a regular expression that accepts all singleton sequences of the regular expression sort.
def AllChar(regex_sort, ctx=None)
Definition: z3py.py:11163

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

1812 def And(*args):
1813  """Create a Z3 and-expression or and-probe.
1814 
1815  >>> p, q, r = Bools('p q r')
1816  >>> And(p, q, r)
1817  And(p, q, r)
1818  >>> P = BoolVector('p', 5)
1819  >>> And(P)
1820  And(p__0, p__1, p__2, p__3, p__4)
1821  """
1822  last_arg = None
1823  if len(args) > 0:
1824  last_arg = args[len(args) - 1]
1825  if isinstance(last_arg, Context):
1826  ctx = args[len(args) - 1]
1827  args = args[:len(args) - 1]
1828  elif len(args) == 1 and isinstance(args[0], AstVector):
1829  ctx = args[0].ctx
1830  args = [a for a in args[0]]
1831  else:
1832  ctx = None
1833  args = _get_args(args)
1834  ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1835  if z3_debug():
1836  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1837  if _has_probe(args):
1838  return _probe_and(args, ctx)
1839  else:
1840  args = _coerce_expr_list(args, ctx)
1841  _args, sz = _to_ast_array(args)
1842  return BoolRef(Z3_mk_and(ctx.ref(), sz, _args), ctx)
1843 
1844 
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:62
def And(*args)
Definition: z3py.py:1812

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

8206 def AndThen(*ts, **ks):
8207  """Return a tactic that applies the tactics in `*ts` in sequence.
8208 
8209  >>> x, y = Ints('x y')
8210  >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
8211  >>> t(And(x == 0, y > x + 1))
8212  [[Not(y <= 1)]]
8213  >>> t(And(x == 0, y > x + 1)).as_expr()
8214  Not(y <= 1)
8215  """
8216  if z3_debug():
8217  _z3_assert(len(ts) >= 2, "At least two arguments expected")
8218  ctx = ks.get("ctx", None)
8219  num = len(ts)
8220  r = ts[0]
8221  for i in range(num - 1):
8222  r = _and_then(r, ts[i + 1], ctx)
8223  return r
8224 
8225 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3823
def AndThen(*ts, **ks)
Definition: z3py.py:8206

Referenced by Then().

◆ append_log()

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

Definition at line 119 of file z3py.py.

119 def append_log(s):
120  """Append user-defined string to interaction log. """
121  Z3_append_log(s)
122 
123 
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.
def append_log(s)
Definition: z3py.py:119

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

5422 def args2params(arguments, keywords, ctx=None):
5423  """Convert python arguments into a Z3_params object.
5424  A ':' is added to the keywords, and '_' is replaced with '-'
5425 
5426  >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5427  (params model true relevancy 2 elim_and true)
5428  """
5429  if z3_debug():
5430  _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
5431  prev = None
5432  r = ParamsRef(ctx)
5433  for a in arguments:
5434  if prev is None:
5435  prev = a
5436  else:
5437  r.set(prev, a)
5438  prev = None
5439  for k in keywords:
5440  v = keywords[k]
5441  r.set(k, v)
5442  return r
5443 
5444 
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:5422

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

◆ Array()

def z3py.Array (   name,
sorts 
)
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 4693 of file z3py.py.

4693 def Array(name, *sorts):
4694  """Return an array constant named `name` with the given domain and range sorts.
4695 
4696  >>> a = Array('a', IntSort(), IntSort())
4697  >>> a.sort()
4698  Array(Int, Int)
4699  >>> a[0]
4700  a[0]
4701  """
4702  s = ArraySort(sorts)
4703  ctx = s.ctx
4704  return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4705 
4706 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def ArraySort(*sig)
Definition: z3py.py:4660
def Array(name, *sorts)
Definition: z3py.py:4693
def to_symbol(s, ctx=None)
Definition: z3py.py:124

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

4660 def ArraySort(*sig):
4661  """Return the Z3 array sort with the given domain and range sorts.
4662 
4663  >>> A = ArraySort(IntSort(), BoolSort())
4664  >>> A
4665  Array(Int, Bool)
4666  >>> A.domain()
4667  Int
4668  >>> A.range()
4669  Bool
4670  >>> AA = ArraySort(IntSort(), A)
4671  >>> AA
4672  Array(Int, Array(Int, Bool))
4673  """
4674  sig = _get_args(sig)
4675  if z3_debug():
4676  _z3_assert(len(sig) > 1, "At least two arguments expected")
4677  arity = len(sig) - 1
4678  r = sig[arity]
4679  d = sig[0]
4680  if z3_debug():
4681  for s in sig:
4682  _z3_assert(is_sort(s), "Z3 sort expected")
4683  _z3_assert(s.ctx == r.ctx, "Context mismatch")
4684  ctx = d.ctx
4685  if len(sig) == 2:
4686  return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4687  dom = (Sort * arity)()
4688  for i in range(arity):
4689  dom[i] = sig[i].ast
4690  return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
4691 
4692 
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.
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
def is_sort(s)
Definition: z3py.py:641

Referenced by Array(), 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 8839 of file z3py.py.

8839 def AtLeast(*args):
8840  """Create an at-most Pseudo-Boolean k constraint.
8841 
8842  >>> a, b, c = Bools('a b c')
8843  >>> f = AtLeast(a, b, c, 2)
8844  """
8845  args = _get_args(args)
8846  if z3_debug():
8847  _z3_assert(len(args) > 1, "Non empty list of arguments expected")
8848  ctx = _ctx_from_ast_arg_list(args)
8849  if z3_debug():
8850  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
8851  args1 = _coerce_expr_list(args[:-1], ctx)
8852  k = args[-1]
8853  _args, sz = _to_ast_array(args1)
8854  return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
8855 
8856 
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
def AtLeast(*args)
Definition: z3py.py:8839

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

8821 def AtMost(*args):
8822  """Create an at-most Pseudo-Boolean k constraint.
8823 
8824  >>> a, b, c = Bools('a b c')
8825  >>> f = AtMost(a, b, c, 2)
8826  """
8827  args = _get_args(args)
8828  if z3_debug():
8829  _z3_assert(len(args) > 1, "Non empty list of arguments expected")
8830  ctx = _ctx_from_ast_arg_list(args)
8831  if z3_debug():
8832  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
8833  args1 = _coerce_expr_list(args[:-1], ctx)
8834  k = args[-1]
8835  _args, sz = _to_ast_array(args1)
8836  return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
8837 
8838 
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
def AtMost(*args)
Definition: z3py.py:8821

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

3997 def BitVec(name, bv, ctx=None):
3998  """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
3999  If `ctx=None`, then the global context is used.
4000 
4001  >>> x = BitVec('x', 16)
4002  >>> is_bv(x)
4003  True
4004  >>> x.size()
4005  16
4006  >>> x.sort()
4007  BitVec(16)
4008  >>> word = BitVecSort(16)
4009  >>> x2 = BitVec('x', word)
4010  >>> eq(x, x2)
4011  True
4012  """
4013  if isinstance(bv, BitVecSortRef):
4014  ctx = bv.ctx
4015  else:
4016  ctx = _get_ctx(ctx)
4017  bv = BitVecSort(bv, ctx)
4018  return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
4019 
4020 
def BitVec(name, bv, ctx=None)
Definition: z3py.py:3997
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3965

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

4021 def BitVecs(names, bv, ctx=None):
4022  """Return a tuple of bit-vector constants of size bv.
4023 
4024  >>> x, y, z = BitVecs('x y z', 16)
4025  >>> x.size()
4026  16
4027  >>> x.sort()
4028  BitVec(16)
4029  >>> Sum(x, y, z)
4030  0 + x + y + z
4031  >>> Product(x, y, z)
4032  1*x*y*z
4033  >>> simplify(Product(x, y, z))
4034  x*y*z
4035  """
4036  ctx = _get_ctx(ctx)
4037  if isinstance(names, str):
4038  names = names.split(" ")
4039  return [BitVec(name, bv, ctx) for name in names]
4040 
4041 
def BitVecs(names, bv, ctx=None)
Definition: z3py.py:4021

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

3965 def BitVecSort(sz, ctx=None):
3966  """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3967 
3968  >>> Byte = BitVecSort(8)
3969  >>> Word = BitVecSort(16)
3970  >>> Byte
3971  BitVec(8)
3972  >>> x = Const('x', Byte)
3973  >>> eq(x, BitVec('x', 8))
3974  True
3975  """
3976  ctx = _get_ctx(ctx)
3977  return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
3978 
3979 
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.

Referenced by BitVec(), and BitVecVal().

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

3980 def BitVecVal(val, bv, ctx=None):
3981  """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3982 
3983  >>> v = BitVecVal(10, 32)
3984  >>> v
3985  10
3986  >>> print("0x%.8x" % v.as_long())
3987  0x0000000a
3988  """
3989  if is_bv_sort(bv):
3990  ctx = bv.ctx
3991  return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
3992  else:
3993  ctx = _get_ctx(ctx)
3994  return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
3995 
3996 
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.
def is_bv_sort(s)
Definition: z3py.py:3436
def BitVecVal(val, bv, ctx=None)
Definition: z3py.py:3980

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

1691 def Bool(name, ctx=None):
1692  """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1693 
1694  >>> p = Bool('p')
1695  >>> q = Bool('q')
1696  >>> And(p, q)
1697  And(p, q)
1698  """
1699  ctx = _get_ctx(ctx)
1700  return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
1701 
1702 
def BoolSort(ctx=None)
Definition: z3py.py:1654
def Bool(name, ctx=None)
Definition: z3py.py:1691

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

1703 def Bools(names, ctx=None):
1704  """Return a tuple of Boolean constants.
1705 
1706  `names` is a single string containing all names separated by blank spaces.
1707  If `ctx=None`, then the global context is used.
1708 
1709  >>> p, q, r = Bools('p q r')
1710  >>> And(p, Or(q, r))
1711  And(p, Or(q, r))
1712  """
1713  ctx = _get_ctx(ctx)
1714  if isinstance(names, str):
1715  names = names.split(" ")
1716  return [Bool(name, ctx) for name in names]
1717 
1718 
def Bools(names, ctx=None)
Definition: z3py.py:1703

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

1654 def BoolSort(ctx=None):
1655  """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1656 
1657  >>> BoolSort()
1658  Bool
1659  >>> p = Const('p', BoolSort())
1660  >>> is_bool(p)
1661  True
1662  >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1663  >>> r(0, 1)
1664  r(0, 1)
1665  >>> is_bool(r(0, 1))
1666  True
1667  """
1668  ctx = _get_ctx(ctx)
1669  return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
1670 
1671 
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.

Referenced by Goal.assert_exprs(), Solver.assert_exprs(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Bool(), Solver.check(), FreshBool(), If(), Implies(), 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 1672 of file z3py.py.

1672 def BoolVal(val, ctx=None):
1673  """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1674 
1675  >>> BoolVal(True)
1676  True
1677  >>> is_true(BoolVal(True))
1678  True
1679  >>> is_true(True)
1680  False
1681  >>> is_false(BoolVal(False))
1682  True
1683  """
1684  ctx = _get_ctx(ctx)
1685  if val:
1686  return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1687  else:
1688  return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1689 
1690 
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:1672

Referenced by Goal.as_expr(), ApplyResult.as_expr(), BoolSortRef.cast(), UserPropagateBase.conflict(), AlgebraicNumRef.index(), 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 1719 of file z3py.py.

1719 def BoolVector(prefix, sz, ctx=None):
1720  """Return a list of Boolean constants of size `sz`.
1721 
1722  The constants are named using the given prefix.
1723  If `ctx=None`, then the global context is used.
1724 
1725  >>> P = BoolVector('p', 3)
1726  >>> P
1727  [p__0, p__1, p__2]
1728  >>> And(P)
1729  And(p__0, p__1, p__2)
1730  """
1731  return [Bool("%s__%s" % (prefix, i)) for i in range(sz)]
1732 
1733 
def BoolVector(prefix, sz, ctx=None)
Definition: z3py.py:1719

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

3933 def BV2Int(a, is_signed=False):
3934  """Return the Z3 expression BV2Int(a).
3935 
3936  >>> b = BitVec('b', 3)
3937  >>> BV2Int(b).sort()
3938  Int
3939  >>> x = Int('x')
3940  >>> x > BV2Int(b)
3941  x > BV2Int(b)
3942  >>> x > BV2Int(b, is_signed=False)
3943  x > BV2Int(b)
3944  >>> x > BV2Int(b, is_signed=True)
3945  x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3946  >>> solve(x > BV2Int(b), b == 1, x < 3)
3947  [x = 2, b = 1]
3948  """
3949  if z3_debug():
3950  _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
3951  ctx = a.ctx
3952  # investigate problem with bv2int
3953  return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
3954 
3955 
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 is_bv(a)
Definition: z3py.py:3904
def BV2Int(a, is_signed=False)
Definition: z3py.py:3933

◆ BVAddNoOverflow()

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

Definition at line 4419 of file z3py.py.

4419 def BVAddNoOverflow(a, b, signed):
4420  """A predicate the determines that bit-vector addition does not overflow"""
4421  _check_bv_args(a, b)
4422  a, b = _coerce_exprs(a, b)
4423  return BoolRef(Z3_mk_bvadd_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4424 
4425 
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.
def BVAddNoOverflow(a, b, signed)
Definition: z3py.py:4419

◆ BVAddNoUnderflow()

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

Definition at line 4426 of file z3py.py.

4426 def BVAddNoUnderflow(a, b):
4427  """A predicate the determines that signed bit-vector addition does not underflow"""
4428  _check_bv_args(a, b)
4429  a, b = _coerce_exprs(a, b)
4430  return BoolRef(Z3_mk_bvadd_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4431 
4432 
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.
def BVAddNoUnderflow(a, b)
Definition: z3py.py:4426

◆ BVMulNoOverflow()

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

Definition at line 4461 of file z3py.py.

4461 def BVMulNoOverflow(a, b, signed):
4462  """A predicate the determines that bit-vector multiplication does not overflow"""
4463  _check_bv_args(a, b)
4464  a, b = _coerce_exprs(a, b)
4465  return BoolRef(Z3_mk_bvmul_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4466 
4467 
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.
def BVMulNoOverflow(a, b, signed)
Definition: z3py.py:4461

◆ BVMulNoUnderflow()

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

Definition at line 4468 of file z3py.py.

4468 def BVMulNoUnderflow(a, b):
4469  """A predicate the determines that bit-vector signed multiplication does not underflow"""
4470  _check_bv_args(a, b)
4471  a, b = _coerce_exprs(a, b)
4472  return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4473 
4474 
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:4468

◆ BVRedAnd()

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

Definition at line 4405 of file z3py.py.

4405 def BVRedAnd(a):
4406  """Return the reduction-and expression of `a`."""
4407  if z3_debug():
4408  _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4409  return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
4410 
4411 
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:4405

◆ BVRedOr()

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

Definition at line 4412 of file z3py.py.

4412 def BVRedOr(a):
4413  """Return the reduction-or expression of `a`."""
4414  if z3_debug():
4415  _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4416  return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
4417 
4418 
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 BVRedOr(a)
Definition: z3py.py:4412

◆ BVSDivNoOverflow()

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

Definition at line 4447 of file z3py.py.

4447 def BVSDivNoOverflow(a, b):
4448  """A predicate the determines that bit-vector signed division does not overflow"""
4449  _check_bv_args(a, b)
4450  a, b = _coerce_exprs(a, b)
4451  return BoolRef(Z3_mk_bvsdiv_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4452 
4453 
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.
def BVSDivNoOverflow(a, b)
Definition: z3py.py:4447

◆ BVSNegNoOverflow()

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

Definition at line 4454 of file z3py.py.

4454 def BVSNegNoOverflow(a):
4455  """A predicate the determines that bit-vector unary negation does not overflow"""
4456  if z3_debug():
4457  _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4458  return BoolRef(Z3_mk_bvneg_no_overflow(a.ctx_ref(), a.as_ast()), a.ctx)
4459 
4460 
Z3_ast Z3_API Z3_mk_bvneg_no_overflow(Z3_context c, Z3_ast t1)
Check that bit-wise negation does not overflow when t1 is interpreted as a signed bit-vector.
def BVSNegNoOverflow(a)
Definition: z3py.py:4454

◆ BVSubNoOverflow()

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

Definition at line 4433 of file z3py.py.

4433 def BVSubNoOverflow(a, b):
4434  """A predicate the determines that bit-vector subtraction does not overflow"""
4435  _check_bv_args(a, b)
4436  a, b = _coerce_exprs(a, b)
4437  return BoolRef(Z3_mk_bvsub_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4438 
4439 
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.
def BVSubNoOverflow(a, b)
Definition: z3py.py:4433

◆ BVSubNoUnderflow()

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

Definition at line 4440 of file z3py.py.

4440 def BVSubNoUnderflow(a, b, signed):
4441  """A predicate the determines that bit-vector subtraction does not underflow"""
4442  _check_bv_args(a, b)
4443  a, b = _coerce_exprs(a, b)
4444  return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4445 
4446 
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.
def BVSubNoUnderflow(a, b, signed)
Definition: z3py.py:4440

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

3384 def Cbrt(a, ctx=None):
3385  """ Return a Z3 expression which represents the cubic root of a.
3386 
3387  >>> x = Real('x')
3388  >>> Cbrt(x)
3389  x**(1/3)
3390  """
3391  if not is_expr(a):
3392  ctx = _get_ctx(ctx)
3393  a = RealVal(a, ctx)
3394  return a ** "1/3"
3395 
def is_expr(a)
Definition: z3py.py:1209
def Cbrt(a, ctx=None)
Definition: z3py.py:3384
def RealVal(val, ctx=None)
Definition: z3py.py:3160

◆ CharFromBv()

def z3py.CharFromBv (   ch,
  ctx = None 
)

Definition at line 10721 of file z3py.py.

10721 def CharFromBv(ch, ctx=None):
10722  if not is_expr(ch):
10723  raise Z3Expression("Bit-vector expression needed")
10724  return _to_expr_ref(Z3_mk_char_from_bv(ch.ctx_ref(), ch.as_ast()), ch.ctx)
10725 
Z3_ast Z3_API Z3_mk_char_from_bv(Z3_context c, Z3_ast bv)
Create a character from a bit-vector (code point).
def CharFromBv(ch, ctx=None)
Definition: z3py.py:10721

◆ CharIsDigit()

def z3py.CharIsDigit (   ch,
  ctx = None 
)

Definition at line 10734 of file z3py.py.

10734 def CharIsDigit(ch, ctx=None):
10735  ch = _coerce_char(ch, ctx)
10736  return ch.is_digit()
10737 
def CharIsDigit(ch, ctx=None)
Definition: z3py.py:10734

◆ CharSort()

def z3py.CharSort (   ctx = None)
Create a character sort
>>> ch = CharSort()
>>> print(ch)
Char

Definition at line 10620 of file z3py.py.

10620 def CharSort(ctx=None):
10621  """Create a character sort
10622  >>> ch = CharSort()
10623  >>> print(ch)
10624  Char
10625  """
10626  ctx = _get_ctx(ctx)
10627  return CharSortRef(Z3_mk_char_sort(ctx.ref()), ctx)
10628 
10629 
Z3_sort Z3_API Z3_mk_char_sort(Z3_context c)
Create a sort for unicode characters.
def CharSort(ctx=None)
Definition: z3py.py:10620

◆ CharToBv()

def z3py.CharToBv (   ch,
  ctx = None 
)

Definition at line 10726 of file z3py.py.

10726 def CharToBv(ch, ctx=None):
10727  ch = _coerce_char(ch, ctx)
10728  return ch.to_bv()
10729 
def CharToBv(ch, ctx=None)
Definition: z3py.py:10726

◆ CharToInt()

def z3py.CharToInt (   ch,
  ctx = None 
)

Definition at line 10730 of file z3py.py.

10730 def CharToInt(ch, ctx=None):
10731  ch = _coerce_char(ch, ctx)
10732  return ch.to_int()
10733 
def CharToInt(ch, ctx=None)
Definition: z3py.py:10730

◆ CharVal()

def z3py.CharVal (   ch,
  ctx = None 
)

Definition at line 10713 of file z3py.py.

10713 def CharVal(ch, ctx=None):
10714  ctx = _get_ctx(ctx)
10715  if isinstance(ch, str):
10716  ch = ord(ch)
10717  if not isinstance(ch, int):
10718  raise Z3Exception("character value should be an ordinal")
10719  return _to_expr_ref(Z3_mk_char(ctx.ref(), ch), ctx)
10720 
Z3_ast Z3_API Z3_mk_char(Z3_context c, unsigned ch)
Create a character literal.
def CharVal(ch, ctx=None)
Definition: z3py.py:10713

Referenced by SeqRef.__gt__().

◆ Complement()

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

Definition at line 11115 of file z3py.py.

11115 def Complement(re):
11116  """Create the complement regular expression."""
11117  return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
11118 
11119 
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:11115

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

4042 def Concat(*args):
4043  """Create a Z3 bit-vector concatenation expression.
4044 
4045  >>> v = BitVecVal(1, 4)
4046  >>> Concat(v, v+1, v)
4047  Concat(Concat(1, 1 + 1), 1)
4048  >>> simplify(Concat(v, v+1, v))
4049  289
4050  >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
4051  121
4052  """
4053  args = _get_args(args)
4054  sz = len(args)
4055  if z3_debug():
4056  _z3_assert(sz >= 2, "At least two arguments expected.")
4057 
4058  ctx = None
4059  for a in args:
4060  if is_expr(a):
4061  ctx = a.ctx
4062  break
4063  if is_seq(args[0]) or isinstance(args[0], str):
4064  args = [_coerce_seq(s, ctx) for s in args]
4065  if z3_debug():
4066  _z3_assert(all([is_seq(a) for a in args]), "All arguments must be sequence expressions.")
4067  v = (Ast * sz)()
4068  for i in range(sz):
4069  v[i] = args[i].as_ast()
4070  return SeqRef(Z3_mk_seq_concat(ctx.ref(), sz, v), ctx)
4071 
4072  if is_re(args[0]):
4073  if z3_debug():
4074  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
4075  v = (Ast * sz)()
4076  for i in range(sz):
4077  v[i] = args[i].as_ast()
4078  return ReRef(Z3_mk_re_concat(ctx.ref(), sz, v), ctx)
4079 
4080  if z3_debug():
4081  _z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.")
4082  r = args[0]
4083  for i in range(sz - 1):
4084  r = BitVecRef(Z3_mk_concat(ctx.ref(), r.as_ast(), args[i + 1].as_ast()), ctx)
4085  return r
4086 
4087 
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
Z3_ast Z3_API Z3_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
def Concat(*args)
Definition: z3py.py:4042
def is_seq(a)
Definition: z3py.py:10759
def is_re(s)
Definition: z3py.py:11033

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

8663 def Cond(p, t1, t2, ctx=None):
8664  """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8665 
8666  >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8667  """
8668  p = _to_probe(p, ctx)
8669  t1 = _to_tactic(t1, ctx)
8670  t2 = _to_tactic(t2, ctx)
8671  return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
8672 
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...
def Cond(p, t1, t2, ctx=None)
Definition: z3py.py:8663

Referenced by If().

◆ Const()

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

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

Definition at line 1404 of file z3py.py.

1404 def Const(name, sort):
1405  """Create a constant of the given sort.
1406 
1407  >>> Const('x', IntSort())
1408  x
1409  """
1410  if z3_debug():
1411  _z3_assert(isinstance(sort, SortRef), "Z3 sort expected")
1412  ctx = sort.ctx
1413  return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
1414 
1415 
def Const(name, sort)
Definition: z3py.py:1404

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

1416 def Consts(names, sort):
1417  """Create several constants of the given sort.
1418 
1419  `names` is a string containing the names of all constants to be created.
1420  Blank spaces separate the names of different constants.
1421 
1422  >>> x, y, z = Consts('x y z', IntSort())
1423  >>> x + y + z
1424  x + y + z
1425  """
1426  if isinstance(names, str):
1427  names = names.split(" ")
1428  return [Const(name, sort) for name in names]
1429 
1430 
def Consts(names, sort)
Definition: z3py.py:1416

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

10890 def Contains(a, b):
10891  """Check if 'a' contains 'b'
10892  >>> s1 = Contains("abc", "ab")
10893  >>> simplify(s1)
10894  True
10895  >>> s2 = Contains("abc", "bc")
10896  >>> simplify(s2)
10897  True
10898  >>> x, y, z = Strings('x y z')
10899  >>> s3 = Contains(Concat(x,y,z), y)
10900  >>> simplify(s3)
10901  True
10902  """
10903  ctx = _get_ctx2(a, b)
10904  a = _coerce_seq(a, ctx)
10905  b = _coerce_seq(b, ctx)
10906  return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
10907 
10908 
Z3_ast Z3_API Z3_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.
def Contains(a, b)
Definition: z3py.py:10890

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

5118 def CreateDatatypes(*ds):
5119  """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5120 
5121  In the following example we define a Tree-List using two mutually recursive datatypes.
5122 
5123  >>> TreeList = Datatype('TreeList')
5124  >>> Tree = Datatype('Tree')
5125  >>> # Tree has two constructors: leaf and node
5126  >>> Tree.declare('leaf', ('val', IntSort()))
5127  >>> # a node contains a list of trees
5128  >>> Tree.declare('node', ('children', TreeList))
5129  >>> TreeList.declare('nil')
5130  >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
5131  >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
5132  >>> Tree.val(Tree.leaf(10))
5133  val(leaf(10))
5134  >>> simplify(Tree.val(Tree.leaf(10)))
5135  10
5136  >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5137  >>> n1
5138  node(cons(leaf(10), cons(leaf(20), nil)))
5139  >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5140  >>> simplify(n2 == n1)
5141  False
5142  >>> simplify(TreeList.car(Tree.children(n2)) == n1)
5143  True
5144  """
5145  ds = _get_args(ds)
5146  if z3_debug():
5147  _z3_assert(len(ds) > 0, "At least one Datatype must be specified")
5148  _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
5149  _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
5150  _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
5151  ctx = ds[0].ctx
5152  num = len(ds)
5153  names = (Symbol * num)()
5154  out = (Sort * num)()
5155  clists = (ConstructorList * num)()
5156  to_delete = []
5157  for i in range(num):
5158  d = ds[i]
5159  names[i] = to_symbol(d.name, ctx)
5160  num_cs = len(d.constructors)
5161  cs = (Constructor * num_cs)()
5162  for j in range(num_cs):
5163  c = d.constructors[j]
5164  cname = to_symbol(c[0], ctx)
5165  rname = to_symbol(c[1], ctx)
5166  fs = c[2]
5167  num_fs = len(fs)
5168  fnames = (Symbol * num_fs)()
5169  sorts = (Sort * num_fs)()
5170  refs = (ctypes.c_uint * num_fs)()
5171  for k in range(num_fs):
5172  fname = fs[k][0]
5173  ftype = fs[k][1]
5174  fnames[k] = to_symbol(fname, ctx)
5175  if isinstance(ftype, Datatype):
5176  if z3_debug():
5177  _z3_assert(
5178  ds.count(ftype) == 1,
5179  "One and only one occurrence of each datatype is expected",
5180  )
5181  sorts[k] = None
5182  refs[k] = ds.index(ftype)
5183  else:
5184  if z3_debug():
5185  _z3_assert(is_sort(ftype), "Z3 sort expected")
5186  sorts[k] = ftype.ast
5187  refs[k] = 0
5188  cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
5189  to_delete.append(ScopedConstructor(cs[j], ctx))
5190  clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs)
5191  to_delete.append(ScopedConstructorList(clists[i], ctx))
5192  Z3_mk_datatypes(ctx.ref(), num, names, out, clists)
5193  result = []
5194  # Create a field for every constructor, recognizer and accessor
5195  for i in range(num):
5196  dref = DatatypeSortRef(out[i], ctx)
5197  num_cs = dref.num_constructors()
5198  for j in range(num_cs):
5199  cref = dref.constructor(j)
5200  cref_name = cref.name()
5201  cref_arity = cref.arity()
5202  if cref.arity() == 0:
5203  cref = cref()
5204  setattr(dref, cref_name, cref)
5205  rref = dref.recognizer(j)
5206  setattr(dref, "is_" + cref_name, rref)
5207  for k in range(cref_arity):
5208  aref = dref.accessor(j, k)
5209  setattr(dref, aref.name(), aref)
5210  result.append(dref)
5211  return tuple(result)
5212 
5213 
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.
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.
def CreateDatatypes(*ds)
Definition: z3py.py:5118

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

687 def DeclareSort(name, ctx=None):
688  """Create a new uninterpreted sort named `name`.
689 
690  If `ctx=None`, then the new sort is declared in the global Z3Py context.
691 
692  >>> A = DeclareSort('A')
693  >>> a = Const('a', A)
694  >>> b = Const('b', A)
695  >>> a.sort() == A
696  True
697  >>> b.sort() == A
698  True
699  >>> a == b
700  a == b
701  """
702  ctx = _get_ctx(ctx)
703  return SortRef(Z3_mk_uninterpreted_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
704 
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:687

◆ Default()

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

Definition at line 4739 of file z3py.py.

4739 def Default(a):
4740  """ Return a default value for array expression.
4741  >>> b = K(IntSort(), 1)
4742  >>> prove(Default(b) == 1)
4743  proved
4744  """
4745  if z3_debug():
4746  _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4747  return a.default()
4748 
4749 
def is_array_sort(a)
Definition: z3py.py:4567
def Default(a)
Definition: z3py.py:4739

◆ describe_probes()

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

Definition at line 8584 of file z3py.py.

8584 def describe_probes():
8585  """Display a (tabular) description of all available probes in Z3."""
8586  if in_html_mode():
8587  even = True
8588  print('<table border="1" cellpadding="2" cellspacing="0">')
8589  for p in probes():
8590  if even:
8591  print('<tr style="background-color:#CFCFCF">')
8592  even = False
8593  else:
8594  print("<tr>")
8595  even = True
8596  print("<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(probe_description(p), 40)))
8597  print("</table>")
8598  else:
8599  for p in probes():
8600  print("%s : %s" % (p, probe_description(p)))
8601 
8602 
def probe_description(name, ctx=None)
Definition: z3py.py:8575
def describe_probes()
Definition: z3py.py:8584
def probes(ctx=None)
Definition: z3py.py:8564

◆ describe_tactics()

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

Definition at line 8378 of file z3py.py.

8378 def describe_tactics():
8379  """Display a (tabular) description of all available tactics in Z3."""
8380  if in_html_mode():
8381  even = True
8382  print('<table border="1" cellpadding="2" cellspacing="0">')
8383  for t in tactics():
8384  if even:
8385  print('<tr style="background-color:#CFCFCF">')
8386  even = False
8387  else:
8388  print("<tr>")
8389  even = True
8390  print("<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(tactic_description(t), 40)))
8391  print("</table>")
8392  else:
8393  for t in tactics():
8394  print("%s : %s" % (t, tactic_description(t)))
8395 
8396 
def tactics(ctx=None)
Definition: z3py.py:8358
def tactic_description(name, ctx=None)
Definition: z3py.py:8369
def describe_tactics()
Definition: z3py.py:8378

◆ Diff()

def z3py.Diff (   a,
  b,
  ctx = None 
)
Create the difference regular epression

Definition at line 11158 of file z3py.py.

11158 def Diff(a, b, ctx=None):
11159  """Create the difference regular epression
11160  """
11161  return ReRef(Z3_mk_re_diff(a.ctx_ref(), a.ast, b.ast), a.ctx)
11162 
Z3_ast Z3_API Z3_mk_re_diff(Z3_context c, Z3_ast re1, Z3_ast re2)
Create the difference of regular expressions.
def Diff(a, b, ctx=None)
Definition: z3py.py:11158

◆ disable_trace()

def z3py.disable_trace (   msg)

Definition at line 79 of file z3py.py.

79 def disable_trace(msg):
80  Z3_disable_trace(msg)
81 
82 
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:79

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

5331 def DisjointSum(name, sorts, ctx=None):
5332  """Create a named tagged union sort base on a set of underlying sorts
5333  Example:
5334  >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5335  """
5336  sum = Datatype(name, ctx)
5337  for i in range(len(sorts)):
5338  sum.declare("inject%d" % i, ("project%d" % i, sorts[i]))
5339  sum = sum.create()
5340  return sum, [(sum.constructor(i), sum.accessor(i, 0)) for i in range(len(sorts))]
5341 
5342 
def DisjointSum(name, sorts, ctx=None)
Definition: z3py.py:5331

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

1371 def Distinct(*args):
1372  """Create a Z3 distinct expression.
1373 
1374  >>> x = Int('x')
1375  >>> y = Int('y')
1376  >>> Distinct(x, y)
1377  x != y
1378  >>> z = Int('z')
1379  >>> Distinct(x, y, z)
1380  Distinct(x, y, z)
1381  >>> simplify(Distinct(x, y, z))
1382  Distinct(x, y, z)
1383  >>> simplify(Distinct(x, y, z), blast_distinct=True)
1384  And(Not(x == y), Not(x == z), Not(y == z))
1385  """
1386  args = _get_args(args)
1387  ctx = _ctx_from_ast_arg_list(args)
1388  if z3_debug():
1389  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
1390  args = _coerce_expr_list(args, ctx)
1391  _args, sz = _to_ast_array(args)
1392  return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
1393 
1394 
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:1371

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

10820 def Empty(s):
10821  """Create the empty sequence of the given sort
10822  >>> e = Empty(StringSort())
10823  >>> e2 = StringVal("")
10824  >>> print(e.eq(e2))
10825  True
10826  >>> e3 = Empty(SeqSort(IntSort()))
10827  >>> print(e3)
10828  Empty(Seq(Int))
10829  >>> e4 = Empty(ReSort(SeqSort(IntSort())))
10830  >>> print(e4)
10831  Empty(ReSort(Seq(Int)))
10832  """
10833  if isinstance(s, SeqSortRef):
10834  return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
10835  if isinstance(s, ReSortRef):
10836  return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
10837  raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
10838 
10839 
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
def Empty(s)
Definition: z3py.py:10820

◆ EmptySet()

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

Definition at line 4882 of file z3py.py.

4882 def EmptySet(s):
4883  """Create the empty set
4884  >>> EmptySet(IntSort())
4885  K(Int, False)
4886  """
4887  ctx = s.ctx
4888  return ArrayRef(Z3_mk_empty_set(ctx.ref(), s.ast), ctx)
4889 
4890 
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
def EmptySet(s)
Definition: z3py.py:4882

◆ enable_trace()

def z3py.enable_trace (   msg)

Definition at line 75 of file z3py.py.

75 def enable_trace(msg):
76  Z3_enable_trace(msg)
77 
78 
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:75

◆ ensure_prop_closures()

def z3py.ensure_prop_closures ( )

Definition at line 11234 of file z3py.py.

11234 def ensure_prop_closures():
11235  global _prop_closures
11236  if _prop_closures is None:
11237  _prop_closures = PropClosures()
11238 
11239 
def ensure_prop_closures()
Definition: z3py.py:11234

Referenced by UserPropagateBase.__init__().

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

5343 def EnumSort(name, values, ctx=None):
5344  """Return a new enumeration sort named `name` containing the given values.
5345 
5346  The result is a pair (sort, list of constants).
5347  Example:
5348  >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5349  """
5350  if z3_debug():
5351  _z3_assert(isinstance(name, str), "Name must be a string")
5352  _z3_assert(all([isinstance(v, str) for v in values]), "Eumeration sort values must be strings")
5353  _z3_assert(len(values) > 0, "At least one value expected")
5354  ctx = _get_ctx(ctx)
5355  num = len(values)
5356  _val_names = (Symbol * num)()
5357  for i in range(num):
5358  _val_names[i] = to_symbol(values[i])
5359  _values = (FuncDecl * num)()
5360  _testers = (FuncDecl * num)()
5361  name = to_symbol(name)
5362  S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
5363  V = []
5364  for i in range(num):
5365  V.append(FuncDeclRef(_values[i], ctx))
5366  V = [a() for a in V]
5367  return S, V
5368 
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.
def EnumSort(name, values, ctx=None)
Definition: z3py.py:5343

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

466 def eq(a, b):
467  """Return `True` if `a` and `b` are structurally identical AST nodes.
468 
469  >>> x = Int('x')
470  >>> y = Int('y')
471  >>> eq(x, y)
472  False
473  >>> eq(x + 1, x + 1)
474  True
475  >>> eq(x + 1, 1 + x)
476  False
477  >>> eq(simplify(x + 1), simplify(1 + x))
478  True
479  """
480  if z3_debug():
481  _z3_assert(is_ast(a) and is_ast(b), "Z3 ASTs expected")
482  return a.eq(b)
483 
484 
def is_ast(a)
Definition: z3py.py:445
def eq(a, b)
Definition: z3py.py:466

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

2203 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2204  """Create a Z3 exists formula.
2205 
2206  The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2207 
2208 
2209  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2210  >>> x = Int('x')
2211  >>> y = Int('y')
2212  >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2213  >>> q
2214  Exists([x, y], f(x, y) >= x)
2215  >>> is_quantifier(q)
2216  True
2217  >>> r = Tactic('nnf')(q).as_expr()
2218  >>> is_quantifier(r)
2219  False
2220  """
2221  return _mk_quantifier(False, vs, body, weight, qid, skid, patterns, no_patterns)
2222 
2223 
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Definition: z3py.py:2203

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

4828 def Ext(a, b):
4829  """Return extensionality index for one-dimensional arrays.
4830  >> a, b = Consts('a b', SetSort(IntSort()))
4831  >> Ext(a, b)
4832  Ext(a, b)
4833  """
4834  ctx = a.ctx
4835  if z3_debug():
4836  _z3_assert(is_array_sort(a) and (is_array(b) or b.is_lambda()), "arguments must be arrays")
4837  return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4838 
4839 
Z3_ast Z3_API Z3_mk_array_ext(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create array extensionality index given two arrays with the same sort. The meaning is given by the ax...
def is_array(a)
Definition: z3py.py:4571
def Ext(a, b)
Definition: z3py.py:4828

◆ Extract()

def z3py.Extract (   high,
  low,
  a 
)
Create a Z3 bit-vector extraction expression.
Extract is overloaded to also work on sequence extraction.
The functions SubString and SubSeq are redirected to Extract.
For this case, the arguments are reinterpreted as:
    high - is a sequence (string)
    low  - is an offset
    a    - is the length to be extracted

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

4088 def Extract(high, low, a):
4089  """Create a Z3 bit-vector extraction expression.
4090  Extract is overloaded to also work on sequence extraction.
4091  The functions SubString and SubSeq are redirected to Extract.
4092  For this case, the arguments are reinterpreted as:
4093  high - is a sequence (string)
4094  low - is an offset
4095  a - is the length to be extracted
4096 
4097  >>> x = BitVec('x', 8)
4098  >>> Extract(6, 2, x)
4099  Extract(6, 2, x)
4100  >>> Extract(6, 2, x).sort()
4101  BitVec(5)
4102  >>> simplify(Extract(StringVal("abcd"),2,1))
4103  "c"
4104  """
4105  if isinstance(high, str):
4106  high = StringVal(high)
4107  if is_seq(high):
4108  s = high
4109  offset, length = _coerce_exprs(low, a, s.ctx)
4110  return SeqRef(Z3_mk_seq_extract(s.ctx_ref(), s.as_ast(), offset.as_ast(), length.as_ast()), s.ctx)
4111  if z3_debug():
4112  _z3_assert(low <= high, "First argument must be greater than or equal to second argument")
4113  _z3_assert(_is_int(high) and high >= 0 and _is_int(low) and low >= 0,
4114  "First and second arguments must be non negative integers")
4115  _z3_assert(is_bv(a), "Third argument must be a Z3 bit-vector expression")
4116  return BitVecRef(Z3_mk_extract(a.ctx_ref(), high, low, a.as_ast()), a.ctx)
4117 
4118 
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,...
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 Extract(high, low, a)
Definition: z3py.py:4088
def StringVal(s, ctx=None)
Definition: z3py.py:10786

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

8621 def FailIf(p, ctx=None):
8622  """Return a tactic that fails if the probe `p` evaluates to true.
8623  Otherwise, it returns the input goal unmodified.
8624 
8625  In the following example, the tactic applies 'simplify' if and only if there are
8626  more than 2 constraints in the goal.
8627 
8628  >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8629  >>> x, y = Ints('x y')
8630  >>> g = Goal()
8631  >>> g.add(x > 0)
8632  >>> g.add(y > 0)
8633  >>> t(g)
8634  [[x > 0, y > 0]]
8635  >>> g.add(x == y + 1)
8636  >>> t(g)
8637  [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8638  """
8639  p = _to_probe(p, ctx)
8640  return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
8641 
8642 
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:8621

◆ FiniteDomainSort()

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

Definition at line 7625 of file z3py.py.

7625 def FiniteDomainSort(name, sz, ctx=None):
7626  """Create a named finite domain sort of a given size sz"""
7627  if not isinstance(name, Symbol):
7628  name = to_symbol(name)
7629  ctx = _get_ctx(ctx)
7630  return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
7631 
7632 
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:7625

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

7695 def FiniteDomainVal(val, sort, ctx=None):
7696  """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7697 
7698  >>> s = FiniteDomainSort('S', 256)
7699  >>> FiniteDomainVal(255, s)
7700  255
7701  >>> FiniteDomainVal('100', s)
7702  100
7703  """
7704  if z3_debug():
7705  _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort")
7706  ctx = sort.ctx
7707  return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
7708 
7709 
def FiniteDomainVal(val, sort, ctx=None)
Definition: z3py.py:7695
def is_finite_domain_sort(s)
Definition: z3py.py:7633

◆ Float128()

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

Definition at line 9305 of file z3py.py.

9305 def Float128(ctx=None):
9306  """Floating-point 128-bit (quadruple) sort."""
9307  ctx = _get_ctx(ctx)
9308  return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
9309 
9310 
Z3_sort Z3_API Z3_mk_fpa_sort_128(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
def Float128(ctx=None)
Definition: z3py.py:9305

◆ Float16()

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

Definition at line 9269 of file z3py.py.

9269 def Float16(ctx=None):
9270  """Floating-point 16-bit (half) sort."""
9271  ctx = _get_ctx(ctx)
9272  return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
9273 
9274 
Z3_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
def Float16(ctx=None)
Definition: z3py.py:9269

◆ Float32()

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

Definition at line 9281 of file z3py.py.

9281 def Float32(ctx=None):
9282  """Floating-point 32-bit (single) sort."""
9283  ctx = _get_ctx(ctx)
9284  return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
9285 
9286 
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:9281

◆ Float64()

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

Definition at line 9293 of file z3py.py.

9293 def Float64(ctx=None):
9294  """Floating-point 64-bit (double) sort."""
9295  ctx = _get_ctx(ctx)
9296  return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
9297 
9298 
Z3_sort Z3_API Z3_mk_fpa_sort_64(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
def Float64(ctx=None)
Definition: z3py.py:9293

◆ FloatDouble()

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

Definition at line 9299 of file z3py.py.

9299 def FloatDouble(ctx=None):
9300  """Floating-point 64-bit (double) sort."""
9301  ctx = _get_ctx(ctx)
9302  return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
9303 
9304 
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
def FloatDouble(ctx=None)
Definition: z3py.py:9299

◆ FloatHalf()

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

Definition at line 9275 of file z3py.py.

9275 def FloatHalf(ctx=None):
9276  """Floating-point 16-bit (half) sort."""
9277  ctx = _get_ctx(ctx)
9278  return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
9279 
9280 
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:9275

◆ FloatQuadruple()

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

Definition at line 9311 of file z3py.py.

9311 def FloatQuadruple(ctx=None):
9312  """Floating-point 128-bit (quadruple) sort."""
9313  ctx = _get_ctx(ctx)
9314  return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
9315 
9316 
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:9311

◆ FloatSingle()

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

Definition at line 9287 of file z3py.py.

9287 def FloatSingle(ctx=None):
9288  """Floating-point 32-bit (single) sort."""
9289  ctx = _get_ctx(ctx)
9290  return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
9291 
9292 
Z3_sort Z3_API Z3_mk_fpa_sort_single(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
def FloatSingle(ctx=None)
Definition: z3py.py:9287

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

2185 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2186  """Create a Z3 forall formula.
2187 
2188  The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2189 
2190  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2191  >>> x = Int('x')
2192  >>> y = Int('y')
2193  >>> ForAll([x, y], f(x, y) >= x)
2194  ForAll([x, y], f(x, y) >= x)
2195  >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2196  ForAll([x, y], f(x, y) >= x)
2197  >>> ForAll([x, y], f(x, y) >= x, weight=10)
2198  ForAll([x, y], f(x, y) >= x)
2199  """
2200  return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
2201 
2202 
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Definition: z3py.py:2185

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

9937 def FP(name, fpsort, ctx=None):
9938  """Return a floating-point constant named `name`.
9939  `fpsort` is the floating-point sort.
9940  If `ctx=None`, then the global context is used.
9941 
9942  >>> x = FP('x', FPSort(8, 24))
9943  >>> is_fp(x)
9944  True
9945  >>> x.ebits()
9946  8
9947  >>> x.sort()
9948  FPSort(8, 24)
9949  >>> word = FPSort(8, 24)
9950  >>> x2 = FP('x', word)
9951  >>> eq(x, x2)
9952  True
9953  """
9954  if isinstance(fpsort, FPSortRef) and ctx is None:
9955  ctx = fpsort.ctx
9956  else:
9957  ctx = _get_ctx(ctx)
9958  return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
9959 
9960 
def FP(name, fpsort, ctx=None)
Definition: z3py.py:9937

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

9980 def fpAbs(a, ctx=None):
9981  """Create a Z3 floating-point absolute value expression.
9982 
9983  >>> s = FPSort(8, 24)
9984  >>> rm = RNE()
9985  >>> x = FPVal(1.0, s)
9986  >>> fpAbs(x)
9987  fpAbs(1)
9988  >>> y = FPVal(-20.0, s)
9989  >>> y
9990  -1.25*(2**4)
9991  >>> fpAbs(y)
9992  fpAbs(-1.25*(2**4))
9993  >>> fpAbs(-1.25*(2**4))
9994  fpAbs(-1.25*(2**4))
9995  >>> fpAbs(x).sort()
9996  FPSort(8, 24)
9997  """
9998  ctx = _get_ctx(ctx)
9999  [a] = _coerce_fp_expr_list([a], ctx)
10000  return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
10001 
10002 
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:9980

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

10071 def fpAdd(rm, a, b, ctx=None):
10072  """Create a Z3 floating-point addition expression.
10073 
10074  >>> s = FPSort(8, 24)
10075  >>> rm = RNE()
10076  >>> x = FP('x', s)
10077  >>> y = FP('y', s)
10078  >>> fpAdd(rm, x, y)
10079  fpAdd(RNE(), x, y)
10080  >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
10081  x + y
10082  >>> fpAdd(rm, x, y).sort()
10083  FPSort(8, 24)
10084  """
10085  return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10086 
10087 
def fpAdd(rm, a, b, ctx=None)
Definition: z3py.py:10071

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

10393 def fpBVToFP(v, sort, ctx=None):
10394  """Create a Z3 floating-point conversion expression that represents the
10395  conversion from a bit-vector term to a floating-point term.
10396 
10397  >>> x_bv = BitVecVal(0x3F800000, 32)
10398  >>> x_fp = fpBVToFP(x_bv, Float32())
10399  >>> x_fp
10400  fpToFP(1065353216)
10401  >>> simplify(x_fp)
10402  1
10403  """
10404  _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
10405  _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
10406  ctx = _get_ctx(ctx)
10407  return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
10408 
10409 
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:9321
def fpBVToFP(v, sort, ctx=None)
Definition: z3py.py:10393

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

10118 def fpDiv(rm, a, b, ctx=None):
10119  """Create a Z3 floating-point division expression.
10120 
10121  >>> s = FPSort(8, 24)
10122  >>> rm = RNE()
10123  >>> x = FP('x', s)
10124  >>> y = FP('y', s)
10125  >>> fpDiv(rm, x, y)
10126  fpDiv(RNE(), x, y)
10127  >>> fpDiv(rm, x, y).sort()
10128  FPSort(8, 24)
10129  """
10130  return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10131 
10132 
def fpDiv(rm, a, b, ctx=None)
Definition: z3py.py:10118

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

10301 def fpEQ(a, b, ctx=None):
10302  """Create the Z3 floating-point expression `fpEQ(other, self)`.
10303 
10304  >>> x, y = FPs('x y', FPSort(8, 24))
10305  >>> fpEQ(x, y)
10306  fpEQ(x, y)
10307  >>> fpEQ(x, y).sexpr()
10308  '(fp.eq x y)'
10309  """
10310  return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10311 
10312 
def fpEQ(a, b, ctx=None)
Definition: z3py.py:10301

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

10177 def fpFMA(rm, a, b, c, ctx=None):
10178  """Create a Z3 floating-point fused multiply-add expression.
10179  """
10180  return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10181 
10182 
def fpFMA(rm, a, b, c, ctx=None)
Definition: z3py.py:10177

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

10325 def fpFP(sgn, exp, sig, ctx=None):
10326  """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10327 
10328  >>> s = FPSort(8, 24)
10329  >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
10330  >>> print(x)
10331  fpFP(1, 127, 4194304)
10332  >>> xv = FPVal(-1.5, s)
10333  >>> print(xv)
10334  -1.5
10335  >>> slvr = Solver()
10336  >>> slvr.add(fpEQ(x, xv))
10337  >>> slvr.check()
10338  sat
10339  >>> xv = FPVal(+1.5, s)
10340  >>> print(xv)
10341  1.5
10342  >>> slvr = Solver()
10343  >>> slvr.add(fpEQ(x, xv))
10344  >>> slvr.check()
10345  unsat
10346  """
10347  _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
10348  _z3_assert(sgn.sort().size() == 1, "sort mismatch")
10349  ctx = _get_ctx(ctx)
10350  _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
10351  return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
10352 
10353 
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:10325

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

10410 def fpFPToFP(rm, v, sort, ctx=None):
10411  """Create a Z3 floating-point conversion expression that represents the
10412  conversion from a floating-point term to a floating-point term of different precision.
10413 
10414  >>> x_sgl = FPVal(1.0, Float32())
10415  >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
10416  >>> x_dbl
10417  fpToFP(RNE(), 1)
10418  >>> simplify(x_dbl)
10419  1
10420  >>> x_dbl.sort()
10421  FPSort(11, 53)
10422  """
10423  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10424  _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
10425  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10426  ctx = _get_ctx(ctx)
10427  return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10428 
10429 
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 fpFPToFP(rm, v, sort, ctx=None)
Definition: z3py.py:10410
def is_fprm(a)
Definition: z3py.py:9581
def is_fp(a)
Definition: z3py.py:9737

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

10289 def fpGEQ(a, b, ctx=None):
10290  """Create the Z3 floating-point expression `other >= self`.
10291 
10292  >>> x, y = FPs('x y', FPSort(8, 24))
10293  >>> fpGEQ(x, y)
10294  x >= y
10295  >>> (x >= y).sexpr()
10296  '(fp.geq x y)'
10297  """
10298  return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10299 
10300 
def fpGEQ(a, b, ctx=None)
Definition: z3py.py:10289

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

10277 def fpGT(a, b, ctx=None):
10278  """Create the Z3 floating-point expression `other > self`.
10279 
10280  >>> x, y = FPs('x y', FPSort(8, 24))
10281  >>> fpGT(x, y)
10282  x > y
10283  >>> (x > y).sexpr()
10284  '(fp.gt x y)'
10285  """
10286  return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10287 
10288 
def fpGT(a, b, ctx=None)
Definition: z3py.py:10277

Referenced by FPRef.__gt__().

◆ fpInfinity()

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

Definition at line 9865 of file z3py.py.

9865 def fpInfinity(s, negative):
9866  """Create a Z3 floating-point +oo or -oo term."""
9867  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9868  _z3_assert(isinstance(negative, bool), "expected Boolean flag")
9869  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
9870 
9871 
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:9865

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

10207 def fpIsInf(a, ctx=None):
10208  """Create a Z3 floating-point isInfinite expression.
10209 
10210  >>> s = FPSort(8, 24)
10211  >>> x = FP('x', s)
10212  >>> fpIsInf(x)
10213  fpIsInf(x)
10214  """
10215  return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10216 
10217 
def fpIsInf(a, ctx=None)
Definition: z3py.py:10207

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

10195 def fpIsNaN(a, ctx=None):
10196  """Create a Z3 floating-point isNaN expression.
10197 
10198  >>> s = FPSort(8, 24)
10199  >>> x = FP('x', s)
10200  >>> y = FP('y', s)
10201  >>> fpIsNaN(x)
10202  fpIsNaN(x)
10203  """
10204  return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10205 
10206 
def fpIsNaN(a, ctx=None)
Definition: z3py.py:10195

◆ fpIsNegative()

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

Definition at line 10236 of file z3py.py.

10236 def fpIsNegative(a, ctx=None):
10237  """Create a Z3 floating-point isNegative expression.
10238  """
10239  return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10240 
10241 
def fpIsNegative(a, ctx=None)
Definition: z3py.py:10236

◆ fpIsNormal()

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

Definition at line 10224 of file z3py.py.

10224 def fpIsNormal(a, ctx=None):
10225  """Create a Z3 floating-point isNormal expression.
10226  """
10227  return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10228 
10229 
def fpIsNormal(a, ctx=None)
Definition: z3py.py:10224

◆ fpIsPositive()

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

Definition at line 10242 of file z3py.py.

10242 def fpIsPositive(a, ctx=None):
10243  """Create a Z3 floating-point isPositive expression.
10244  """
10245  return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10246 
10247 
def fpIsPositive(a, ctx=None)
Definition: z3py.py:10242

◆ fpIsSubnormal()

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

Definition at line 10230 of file z3py.py.

10230 def fpIsSubnormal(a, ctx=None):
10231  """Create a Z3 floating-point isSubnormal expression.
10232  """
10233  return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10234 
10235 
def fpIsSubnormal(a, ctx=None)
Definition: z3py.py:10230

◆ fpIsZero()

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

Definition at line 10218 of file z3py.py.

10218 def fpIsZero(a, ctx=None):
10219  """Create a Z3 floating-point isZero expression.
10220  """
10221  return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10222 
10223 
def fpIsZero(a, ctx=None)
Definition: z3py.py:10218

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

10265 def fpLEQ(a, b, ctx=None):
10266  """Create the Z3 floating-point expression `other <= self`.
10267 
10268  >>> x, y = FPs('x y', FPSort(8, 24))
10269  >>> fpLEQ(x, y)
10270  x <= y
10271  >>> (x <= y).sexpr()
10272  '(fp.leq x y)'
10273  """
10274  return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10275 
10276 
def fpLEQ(a, b, ctx=None)
Definition: z3py.py:10265

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

10253 def fpLT(a, b, ctx=None):
10254  """Create the Z3 floating-point expression `other < self`.
10255 
10256  >>> x, y = FPs('x y', FPSort(8, 24))
10257  >>> fpLT(x, y)
10258  x < y
10259  >>> (x < y).sexpr()
10260  '(fp.lt x y)'
10261  """
10262  return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10263 
10264 
def fpLT(a, b, ctx=None)
Definition: z3py.py:10253

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

10162 def fpMax(a, b, ctx=None):
10163  """Create a Z3 floating-point maximum expression.
10164 
10165  >>> s = FPSort(8, 24)
10166  >>> rm = RNE()
10167  >>> x = FP('x', s)
10168  >>> y = FP('y', s)
10169  >>> fpMax(x, y)
10170  fpMax(x, y)
10171  >>> fpMax(x, y).sort()
10172  FPSort(8, 24)
10173  """
10174  return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10175 
10176 
def fpMax(a, b, ctx=None)
Definition: z3py.py:10162

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

10147 def fpMin(a, b, ctx=None):
10148  """Create a Z3 floating-point minimum expression.
10149 
10150  >>> s = FPSort(8, 24)
10151  >>> rm = RNE()
10152  >>> x = FP('x', s)
10153  >>> y = FP('y', s)
10154  >>> fpMin(x, y)
10155  fpMin(x, y)
10156  >>> fpMin(x, y).sort()
10157  FPSort(8, 24)
10158  """
10159  return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10160 
10161 
def fpMin(a, b, ctx=None)
Definition: z3py.py:10147

◆ fpMinusInfinity()

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

Definition at line 9859 of file z3py.py.

9859 def fpMinusInfinity(s):
9860  """Create a Z3 floating-point -oo term."""
9861  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9862  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
9863 
9864 
def fpMinusInfinity(s)
Definition: z3py.py:9859

Referenced by FPVal().

◆ fpMinusZero()

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

Definition at line 9878 of file z3py.py.

9878 def fpMinusZero(s):
9879  """Create a Z3 floating-point -0.0 term."""
9880  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9881  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
9882 
9883 
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.
def fpMinusZero(s)
Definition: z3py.py:9878

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

10103 def fpMul(rm, a, b, ctx=None):
10104  """Create a Z3 floating-point multiplication expression.
10105 
10106  >>> s = FPSort(8, 24)
10107  >>> rm = RNE()
10108  >>> x = FP('x', s)
10109  >>> y = FP('y', s)
10110  >>> fpMul(rm, x, y)
10111  fpMul(RNE(), x, y)
10112  >>> fpMul(rm, x, y).sort()
10113  FPSort(8, 24)
10114  """
10115  return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10116 
10117 
def fpMul(rm, a, b, ctx=None)
Definition: z3py.py:10103

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

9825 def fpNaN(s):
9826  """Create a Z3 floating-point NaN term.
9827 
9828  >>> s = FPSort(8, 24)
9829  >>> set_fpa_pretty(True)
9830  >>> fpNaN(s)
9831  NaN
9832  >>> pb = get_fpa_pretty()
9833  >>> set_fpa_pretty(False)
9834  >>> fpNaN(s)
9835  fpNaN(FPSort(8, 24))
9836  >>> set_fpa_pretty(pb)
9837  """
9838  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9839  return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
9840 
9841 
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.
def fpNaN(s)
Definition: z3py.py:9825

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

10003 def fpNeg(a, ctx=None):
10004  """Create a Z3 floating-point addition expression.
10005 
10006  >>> s = FPSort(8, 24)
10007  >>> rm = RNE()
10008  >>> x = FP('x', s)
10009  >>> fpNeg(x)
10010  -x
10011  >>> fpNeg(x).sort()
10012  FPSort(8, 24)
10013  """
10014  ctx = _get_ctx(ctx)
10015  [a] = _coerce_fp_expr_list([a], ctx)
10016  return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
10017 
10018 
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:10003

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

10313 def fpNEQ(a, b, ctx=None):
10314  """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10315 
10316  >>> x, y = FPs('x y', FPSort(8, 24))
10317  >>> fpNEQ(x, y)
10318  Not(fpEQ(x, y))
10319  >>> (x != y).sexpr()
10320  '(distinct x y)'
10321  """
10322  return Not(fpEQ(a, b, ctx))
10323 
10324 
def Not(a, ctx=None)
Definition: z3py.py:1778
def fpNEQ(a, b, ctx=None)
Definition: z3py.py:10313

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

9842 def fpPlusInfinity(s):
9843  """Create a Z3 floating-point +oo term.
9844 
9845  >>> s = FPSort(8, 24)
9846  >>> pb = get_fpa_pretty()
9847  >>> set_fpa_pretty(True)
9848  >>> fpPlusInfinity(s)
9849  +oo
9850  >>> set_fpa_pretty(False)
9851  >>> fpPlusInfinity(s)
9852  fpPlusInfinity(FPSort(8, 24))
9853  >>> set_fpa_pretty(pb)
9854  """
9855  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9856  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
9857 
9858 
def fpPlusInfinity(s)
Definition: z3py.py:9842

Referenced by FPVal().

◆ fpPlusZero()

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

Definition at line 9872 of file z3py.py.

9872 def fpPlusZero(s):
9873  """Create a Z3 floating-point +0.0 term."""
9874  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9875  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
9876 
9877 
def fpPlusZero(s)
Definition: z3py.py:9872

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

10430 def fpRealToFP(rm, v, sort, ctx=None):
10431  """Create a Z3 floating-point conversion expression that represents the
10432  conversion from a real term to a floating-point term.
10433 
10434  >>> x_r = RealVal(1.5)
10435  >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
10436  >>> x_fp
10437  fpToFP(RNE(), 3/2)
10438  >>> simplify(x_fp)
10439  1.5
10440  """
10441  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10442  _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
10443  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10444  ctx = _get_ctx(ctx)
10445  return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10446 
10447 
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 fpRealToFP(rm, v, sort, ctx=None)
Definition: z3py.py:10430
def is_real(a)
Definition: z3py.py:2665

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

10133 def fpRem(a, b, ctx=None):
10134  """Create a Z3 floating-point remainder expression.
10135 
10136  >>> s = FPSort(8, 24)
10137  >>> x = FP('x', s)
10138  >>> y = FP('y', s)
10139  >>> fpRem(x, y)
10140  fpRem(x, y)
10141  >>> fpRem(x, y).sort()
10142  FPSort(8, 24)
10143  """
10144  return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10145 
10146 
def fpRem(a, b, ctx=None)
Definition: z3py.py:10133

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

10189 def fpRoundToIntegral(rm, a, ctx=None):
10190  """Create a Z3 floating-point roundToIntegral expression.
10191  """
10192  return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10193 
10194 
def fpRoundToIntegral(rm, a, ctx=None)
Definition: z3py.py:10189

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

9961 def FPs(names, fpsort, ctx=None):
9962  """Return an array of floating-point constants.
9963 
9964  >>> x, y, z = FPs('x y z', FPSort(8, 24))
9965  >>> x.sort()
9966  FPSort(8, 24)
9967  >>> x.sbits()
9968  24
9969  >>> x.ebits()
9970  8
9971  >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
9972  fpMul(RNE(), fpAdd(RNE(), x, y), z)
9973  """
9974  ctx = _get_ctx(ctx)
9975  if isinstance(names, str):
9976  names = names.split(" ")
9977  return [FP(name, fpsort, ctx) for name in names]
9978 
9979 
def FPs(names, fpsort, ctx=None)
Definition: z3py.py:9961

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

10448 def fpSignedToFP(rm, v, sort, ctx=None):
10449  """Create a Z3 floating-point conversion expression that represents the
10450  conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10451 
10452  >>> x_signed = BitVecVal(-5, BitVecSort(32))
10453  >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
10454  >>> x_fp
10455  fpToFP(RNE(), 4294967291)
10456  >>> simplify(x_fp)
10457  -1.25*(2**2)
10458  """
10459  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10460  _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10461  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10462  ctx = _get_ctx(ctx)
10463  return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10464 
10465 
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:10448

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

9766 def FPSort(ebits, sbits, ctx=None):
9767  """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9768 
9769  >>> Single = FPSort(8, 24)
9770  >>> Double = FPSort(11, 53)
9771  >>> Single
9772  FPSort(8, 24)
9773  >>> x = Const('x', Single)
9774  >>> eq(x, FP('x', FPSort(8, 24)))
9775  True
9776  """
9777  ctx = _get_ctx(ctx)
9778  return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
9779 
9780 
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:9766

Referenced by get_default_fp_sort().

◆ fpSqrt()

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

Definition at line 10183 of file z3py.py.

10183 def fpSqrt(rm, a, ctx=None):
10184  """Create a Z3 floating-point square root expression.
10185  """
10186  return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10187 
10188 
def fpSqrt(rm, a, ctx=None)
Definition: z3py.py:10183

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

10088 def fpSub(rm, a, b, ctx=None):
10089  """Create a Z3 floating-point subtraction expression.
10090 
10091  >>> s = FPSort(8, 24)
10092  >>> rm = RNE()
10093  >>> x = FP('x', s)
10094  >>> y = FP('y', s)
10095  >>> fpSub(rm, x, y)
10096  fpSub(RNE(), x, y)
10097  >>> fpSub(rm, x, y).sort()
10098  FPSort(8, 24)
10099  """
10100  return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10101 
10102 
def fpSub(rm, a, b, ctx=None)
Definition: z3py.py:10088

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

10354 def fpToFP(a1, a2=None, a3=None, ctx=None):
10355  """Create a Z3 floating-point conversion expression from other term sorts
10356  to floating-point.
10357 
10358  From a bit-vector term in IEEE 754-2008 format:
10359  >>> x = FPVal(1.0, Float32())
10360  >>> x_bv = fpToIEEEBV(x)
10361  >>> simplify(fpToFP(x_bv, Float32()))
10362  1
10363 
10364  From a floating-point term with different precision:
10365  >>> x = FPVal(1.0, Float32())
10366  >>> x_db = fpToFP(RNE(), x, Float64())
10367  >>> x_db.sort()
10368  FPSort(11, 53)
10369 
10370  From a real term:
10371  >>> x_r = RealVal(1.5)
10372  >>> simplify(fpToFP(RNE(), x_r, Float32()))
10373  1.5
10374 
10375  From a signed bit-vector term:
10376  >>> x_signed = BitVecVal(-5, BitVecSort(32))
10377  >>> simplify(fpToFP(RNE(), x_signed, Float32()))
10378  -1.25*(2**2)
10379  """
10380  ctx = _get_ctx(ctx)
10381  if is_bv(a1) and is_fp_sort(a2):
10382  return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
10383  elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
10384  return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10385  elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
10386  return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10387  elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
10388  return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10389  else:
10390  raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
10391 
10392 
def fpToFP(a1, a2=None, a3=None, ctx=None)
Definition: z3py.py:10354

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

10484 def fpToFPUnsigned(rm, x, s, ctx=None):
10485  """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
10486  if z3_debug():
10487  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10488  _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
10489  _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
10490  ctx = _get_ctx(ctx)
10491  return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
10492 
10493 
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 fpToFPUnsigned(rm, x, s, ctx=None)
Definition: z3py.py:10484

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

10558 def fpToIEEEBV(x, ctx=None):
10559  """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
10560 
10561  The size of the resulting bit-vector is automatically determined.
10562 
10563  Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
10564  knows only one NaN and it will always produce the same bit-vector representation of
10565  that NaN.
10566 
10567  >>> x = FP('x', FPSort(8, 24))
10568  >>> y = fpToIEEEBV(x)
10569  >>> print(is_fp(x))
10570  True
10571  >>> print(is_bv(y))
10572  True
10573  >>> print(is_fp(y))
10574  False
10575  >>> print(is_bv(x))
10576  False
10577  """
10578  if z3_debug():
10579  _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
10580  ctx = _get_ctx(ctx)
10581  return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
10582 
10583 
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 fpToIEEEBV(x, ctx=None)
Definition: z3py.py:10558

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

10538 def fpToReal(x, ctx=None):
10539  """Create a Z3 floating-point conversion expression, from floating-point expression to real.
10540 
10541  >>> x = FP('x', FPSort(8, 24))
10542  >>> y = fpToReal(x)
10543  >>> print(is_fp(x))
10544  True
10545  >>> print(is_real(y))
10546  True
10547  >>> print(is_fp(y))
10548  False
10549  >>> print(is_real(x))
10550  False
10551  """
10552  if z3_debug():
10553  _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
10554  ctx = _get_ctx(ctx)
10555  return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
10556 
10557 
Z3_ast Z3_API Z3_mk_fpa_to_real(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a real-numbered term.
def fpToReal(x, ctx=None)
Definition: z3py.py:10538

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

10494 def fpToSBV(rm, x, s, ctx=None):
10495  """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
10496 
10497  >>> x = FP('x', FPSort(8, 24))
10498  >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
10499  >>> print(is_fp(x))
10500  True
10501  >>> print(is_bv(y))
10502  True
10503  >>> print(is_fp(y))
10504  False
10505  >>> print(is_bv(x))
10506  False
10507  """
10508  if z3_debug():
10509  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10510  _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
10511  _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
10512  ctx = _get_ctx(ctx)
10513  return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
10514 
10515 
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:10494

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

10516 def fpToUBV(rm, x, s, ctx=None):
10517  """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
10518 
10519  >>> x = FP('x', FPSort(8, 24))
10520  >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
10521  >>> print(is_fp(x))
10522  True
10523  >>> print(is_bv(y))
10524  True
10525  >>> print(is_fp(y))
10526  False
10527  >>> print(is_bv(x))
10528  False
10529  """
10530  if z3_debug():
10531  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10532  _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
10533  _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
10534  ctx = _get_ctx(ctx)
10535  return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
10536 
10537 
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:10516

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

10466 def fpUnsignedToFP(rm, v, sort, ctx=None):
10467  """Create a Z3 floating-point conversion expression that represents the
10468  conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10469 
10470  >>> x_signed = BitVecVal(-5, BitVecSort(32))
10471  >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
10472  >>> x_fp
10473  fpToFPUnsigned(RNE(), 4294967291)
10474  >>> simplify(x_fp)
10475  1*(2**32)
10476  """
10477  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10478  _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10479  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10480  ctx = _get_ctx(ctx)
10481  return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10482 
10483 
def fpUnsignedToFP(rm, v, sort, ctx=None)
Definition: z3py.py:10466

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

9891 def FPVal(sig, exp=None, fps=None, ctx=None):
9892  """Return a floating-point value of value `val` and sort `fps`.
9893  If `ctx=None`, then the global context is used.
9894 
9895  >>> v = FPVal(20.0, FPSort(8, 24))
9896  >>> v
9897  1.25*(2**4)
9898  >>> print("0x%.8x" % v.exponent_as_long(False))
9899  0x00000004
9900  >>> v = FPVal(2.25, FPSort(8, 24))
9901  >>> v
9902  1.125*(2**1)
9903  >>> v = FPVal(-2.25, FPSort(8, 24))
9904  >>> v
9905  -1.125*(2**1)
9906  >>> FPVal(-0.0, FPSort(8, 24))
9907  -0.0
9908  >>> FPVal(0.0, FPSort(8, 24))
9909  +0.0
9910  >>> FPVal(+0.0, FPSort(8, 24))
9911  +0.0
9912  """
9913  ctx = _get_ctx(ctx)
9914  if is_fp_sort(exp):
9915  fps = exp
9916  exp = None
9917  elif fps is None:
9918  fps = _dflt_fps(ctx)
9919  _z3_assert(is_fp_sort(fps), "sort mismatch")
9920  if exp is None:
9921  exp = 0
9922  val = _to_float_str(sig)
9923  if val == "NaN" or val == "nan":
9924  return fpNaN(fps)
9925  elif val == "-0.0":
9926  return fpMinusZero(fps)
9927  elif val == "0.0" or val == "+0.0":
9928  return fpPlusZero(fps)
9929  elif val == "+oo" or val == "+inf" or val == "+Inf":
9930  return fpPlusInfinity(fps)
9931  elif val == "-oo" or val == "-inf" or val == "-Inf":
9932  return fpMinusInfinity(fps)
9933  else:
9934  return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
9935 
9936 
def FPVal(sig, exp=None, fps=None, ctx=None)
Definition: z3py.py:9891

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

9884 def fpZero(s, negative):
9885  """Create a Z3 floating-point +0.0 or -0.0 term."""
9886  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9887  _z3_assert(isinstance(negative, bool), "expected Boolean flag")
9888  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
9889 
9890 
def fpZero(s, negative)
Definition: z3py.py:9884

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

1734 def FreshBool(prefix="b", ctx=None):
1735  """Return a fresh Boolean constant in the given context using the given prefix.
1736 
1737  If `ctx=None`, then the global context is used.
1738 
1739  >>> b1 = FreshBool()
1740  >>> b2 = FreshBool()
1741  >>> eq(b1, b2)
1742  False
1743  """
1744  ctx = _get_ctx(ctx)
1745  return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1746 
1747 
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.
def FreshBool(prefix="b", ctx=None)
Definition: z3py.py:1734

◆ FreshConst()

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

Definition at line 1431 of file z3py.py.

1431 def FreshConst(sort, prefix="c"):
1432  """Create a fresh constant of a specified sort"""
1433  ctx = _get_ctx(sort.ctx)
1434  return _to_expr_ref(Z3_mk_fresh_const(ctx.ref(), prefix, sort.ast), ctx)
1435 
1436 
def FreshConst(sort, prefix="c")
Definition: z3py.py:1431

◆ FreshFunction()

def z3py.FreshFunction ( sig)
Create a new fresh Z3 uninterpreted function with the given sorts.

Definition at line 880 of file z3py.py.

880 def FreshFunction(*sig):
881  """Create a new fresh Z3 uninterpreted function with the given sorts.
882  """
883  sig = _get_args(sig)
884  if z3_debug():
885  _z3_assert(len(sig) > 0, "At least two arguments expected")
886  arity = len(sig) - 1
887  rng = sig[arity]
888  if z3_debug():
889  _z3_assert(is_sort(rng), "Z3 sort expected")
890  dom = (z3.Sort * arity)()
891  for i in range(arity):
892  if z3_debug():
893  _z3_assert(is_sort(sig[i]), "Z3 sort expected")
894  dom[i] = sig[i].ast
895  ctx = rng.ctx
896  return FuncDeclRef(Z3_mk_fresh_func_decl(ctx.ref(), "f", arity, dom, rng.ast), ctx)
897 
898 
Z3_func_decl Z3_API Z3_mk_fresh_func_decl(Z3_context c, Z3_string prefix, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a fresh constant or function.
def FreshFunction(*sig)
Definition: z3py.py:880

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

3247 def FreshInt(prefix="x", ctx=None):
3248  """Return a fresh integer constant in the given context using the given prefix.
3249 
3250  >>> x = FreshInt()
3251  >>> y = FreshInt()
3252  >>> eq(x, y)
3253  False
3254  >>> x.sort()
3255  Int
3256  """
3257  ctx = _get_ctx(ctx)
3258  return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
3259 
3260 
def IntSort(ctx=None)
Definition: z3py.py:3098
def FreshInt(prefix="x", ctx=None)
Definition: z3py.py:3247

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

3304 def FreshReal(prefix="b", ctx=None):
3305  """Return a fresh real constant in the given context using the given prefix.
3306 
3307  >>> x = FreshReal()
3308  >>> y = FreshReal()
3309  >>> eq(x, y)
3310  False
3311  >>> x.sort()
3312  Real
3313  """
3314  ctx = _get_ctx(ctx)
3315  return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
3316 
3317 
def RealSort(ctx=None)
Definition: z3py.py:3115
def FreshReal(prefix="b", ctx=None)
Definition: z3py.py:3304

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

10840 def Full(s):
10841  """Create the regular expression that accepts the universal language
10842  >>> e = Full(ReSort(SeqSort(IntSort())))
10843  >>> print(e)
10844  Full(ReSort(Seq(Int)))
10845  >>> e1 = Full(ReSort(StringSort()))
10846  >>> print(e1)
10847  Full(ReSort(String))
10848  """
10849  if isinstance(s, ReSortRef):
10850  return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
10851  raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
10852 
10853 
10854 
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.
def Full(s)
Definition: z3py.py:10840

◆ FullSet()

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

Definition at line 4891 of file z3py.py.

4891 def FullSet(s):
4892  """Create the full set
4893  >>> FullSet(IntSort())
4894  K(Int, True)
4895  """
4896  ctx = s.ctx
4897  return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
4898 
4899 
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
def FullSet(s)
Definition: z3py.py:4891

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

857 def Function(name, *sig):
858  """Create a new Z3 uninterpreted function with the given sorts.
859 
860  >>> f = Function('f', IntSort(), IntSort())
861  >>> f(f(0))
862  f(f(0))
863  """
864  sig = _get_args(sig)
865  if z3_debug():
866  _z3_assert(len(sig) > 0, "At least two arguments expected")
867  arity = len(sig) - 1
868  rng = sig[arity]
869  if z3_debug():
870  _z3_assert(is_sort(rng), "Z3 sort expected")
871  dom = (Sort * arity)()
872  for i in range(arity):
873  if z3_debug():
874  _z3_assert(is_sort(sig[i]), "Z3 sort expected")
875  dom[i] = sig[i].ast
876  ctx = rng.ctx
877  return FuncDeclRef(Z3_mk_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
878 
879 
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 Function(name, *sig)
Definition: z3py.py:857

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

6624 def get_as_array_func(n):
6625  """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6626  if z3_debug():
6627  _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
6628  return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
6629 
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 is_as_array(n)
Definition: z3py.py:6619
def get_as_array_func(n)
Definition: z3py.py:6624

Referenced by ModelRef.get_interp().

◆ get_ctx()

def z3py.get_ctx (   ctx)

Definition at line 261 of file z3py.py.

261 def get_ctx(ctx):
262  return _get_ctx(ctx)
263 
264 
def get_ctx(ctx)
Definition: z3py.py:261

◆ get_default_fp_sort()

def z3py.get_default_fp_sort (   ctx = None)

Definition at line 9188 of file z3py.py.

9188 def get_default_fp_sort(ctx=None):
9189  return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9190 
9191 
def get_default_fp_sort(ctx=None)
Definition: z3py.py:9188

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

9155 def get_default_rounding_mode(ctx=None):
9156  """Retrieves the global default rounding mode."""
9157  global _dflt_rounding_mode
9158  if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9159  return RTZ(ctx)
9160  elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9161  return RTN(ctx)
9162  elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9163  return RTP(ctx)
9164  elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9165  return RNE(ctx)
9166  elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9167  return RNA(ctx)
9168 
9169 
def RNE(ctx=None)
Definition: z3py.py:9536
def get_default_rounding_mode(ctx=None)
Definition: z3py.py:9155
def RTZ(ctx=None)
Definition: z3py.py:9576
def RTN(ctx=None)
Definition: z3py.py:9566
def RTP(ctx=None)
Definition: z3py.py:9556
def RNA(ctx=None)
Definition: z3py.py:9546

Referenced by set_default_fp_sort().

◆ get_full_version()

def z3py.get_full_version ( )

Definition at line 101 of file z3py.py.

101 def get_full_version():
102  return Z3_get_full_version()
103 
104 
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:101

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

4636 def get_map_func(a):
4637  """Return the function declaration associated with a Z3 map array expression.
4638 
4639  >>> f = Function('f', IntSort(), IntSort())
4640  >>> b = Array('b', IntSort(), IntSort())
4641  >>> a = Map(f, b)
4642  >>> eq(f, get_map_func(a))
4643  True
4644  >>> get_map_func(a)
4645  f
4646  >>> get_map_func(a)(0)
4647  f(0)
4648  """
4649  if z3_debug():
4650  _z3_assert(is_map(a), "Z3 array map expression expected.")
4651  return FuncDeclRef(
4653  a.ctx_ref(),
4654  Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0),
4655  ),
4656  ctx=a.ctx,
4657  )
4658 
4659 
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.
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 is_map(a)
Definition: z3py.py:4611
def get_map_func(a)
Definition: z3py.py:4636

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

301 def get_param(name):
302  """Return the value of a Z3 global (or module) parameter
303 
304  >>> get_param('nlsat.reorder')
305  'true'
306  """
307  ptr = (ctypes.c_char_p * 1)()
308  if Z3_global_param_get(str(name), ptr):
309  r = z3core._to_pystr(ptr[0])
310  return r
311  raise Z3Exception("failed to retrieve value for '%s'" % name)
312 
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:301

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

1302 def get_var_index(a):
1303  """Return the de-Bruijn index of the Z3 bounded variable `a`.
1304 
1305  >>> x = Int('x')
1306  >>> y = Int('y')
1307  >>> is_var(x)
1308  False
1309  >>> is_const(x)
1310  True
1311  >>> f = Function('f', IntSort(), IntSort(), IntSort())
1312  >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1313  >>> q = ForAll([x, y], f(x, y) == x + y)
1314  >>> q.body()
1315  f(Var(1), Var(0)) == Var(1) + Var(0)
1316  >>> b = q.body()
1317  >>> b.arg(0)
1318  f(Var(1), Var(0))
1319  >>> v1 = b.arg(0).arg(0)
1320  >>> v2 = b.arg(0).arg(1)
1321  >>> v1
1322  Var(1)
1323  >>> v2
1324  Var(0)
1325  >>> get_var_index(v1)
1326  1
1327  >>> get_var_index(v2)
1328  0
1329  """
1330  if z3_debug():
1331  _z3_assert(is_var(a), "Z3 bound variable expected")
1332  return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
1333 
1334 
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.
def is_var(a)
Definition: z3py.py:1277
def get_var_index(a)
Definition: z3py.py:1302

◆ get_version()

def z3py.get_version ( )

Definition at line 92 of file z3py.py.

92 def get_version():
93  major = ctypes.c_uint(0)
94  minor = ctypes.c_uint(0)
95  build = ctypes.c_uint(0)
96  rev = ctypes.c_uint(0)
97  Z3_get_version(major, minor, build, rev)
98  return (major.value, minor.value, build.value, rev.value)
99 
100 
void Z3_API Z3_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.
def get_version()
Definition: z3py.py:92

◆ get_version_string()

def z3py.get_version_string ( )

Definition at line 83 of file z3py.py.

83 def get_version_string():
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 "%s.%s.%s" % (major.value, minor.value, build.value)
90 
91 
def get_version_string()
Definition: z3py.py:83

◆ help_simplify()

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

Definition at line 8705 of file z3py.py.

8705 def help_simplify():
8706  """Return a string describing all options available for Z3 `simplify` procedure."""
8707  print(Z3_simplify_get_help(main_ctx().ref()))
8708 
8709 
Z3_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.
def help_simplify()
Definition: z3py.py:8705
def main_ctx()
Definition: z3py.py:233

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

1348 def If(a, b, c, ctx=None):
1349  """Create a Z3 if-then-else expression.
1350 
1351  >>> x = Int('x')
1352  >>> y = Int('y')
1353  >>> max = If(x > y, x, y)
1354  >>> max
1355  If(x > y, x, y)
1356  >>> simplify(max)
1357  If(x <= y, y, x)
1358  """
1359  if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1360  return Cond(a, b, c, ctx)
1361  else:
1362  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1363  s = BoolSort(ctx)
1364  a = s.cast(a)
1365  b, c = _coerce_exprs(b, c, ctx)
1366  if z3_debug():
1367  _z3_assert(a.ctx == b.ctx, "Context mismatch")
1368  return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1369 
1370 
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).

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

◆ Implies()

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

>>> p, q = Bools('p q')
>>> Implies(p, q)
Implies(p, q)

Definition at line 1748 of file z3py.py.

1748 def Implies(a, b, ctx=None):
1749  """Create a Z3 implies expression.
1750 
1751  >>> p, q = Bools('p q')
1752  >>> Implies(p, q)
1753  Implies(p, q)
1754  """
1755  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1756  s = BoolSort(ctx)
1757  a = s.cast(a)
1758  b = s.cast(b)
1759  return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1760 
1761 
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 Implies(a, b, ctx=None)
Definition: z3py.py:1748

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

◆ IndexOf()

def z3py.IndexOf (   s,
  substr,
  offset = None 
)
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 10924 of file z3py.py.

10924 def IndexOf(s, substr, offset=None):
10925  """Retrieve the index of substring within a string starting at a specified offset.
10926  >>> simplify(IndexOf("abcabc", "bc", 0))
10927  1
10928  >>> simplify(IndexOf("abcabc", "bc", 2))
10929  4
10930  """
10931  if offset is None:
10932  offset = IntVal(0)
10933  ctx = None
10934  if is_expr(offset):
10935  ctx = offset.ctx
10936  ctx = _get_ctx2(s, substr, ctx)
10937  s = _coerce_seq(s, ctx)
10938  substr = _coerce_seq(substr, ctx)
10939  if _is_int(offset):
10940  offset = IntVal(offset, ctx)
10941  return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
10942 
10943 
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 IndexOf(s, substr, offset=None)
Definition: z3py.py:10924
def IntVal(val, ctx=None)
Definition: z3py.py:3148

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

11037 def InRe(s, re):
11038  """Create regular expression membership test
11039  >>> re = Union(Re("a"),Re("b"))
11040  >>> print (simplify(InRe("a", re)))
11041  True
11042  >>> print (simplify(InRe("b", re)))
11043  True
11044  >>> print (simplify(InRe("c", re)))
11045  False
11046  """
11047  s = _coerce_seq(s, re.ctx)
11048  return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
11049 
11050 
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.
def InRe(s, re)
Definition: z3py.py:11037

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

3208 def Int(name, ctx=None):
3209  """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3210 
3211  >>> x = Int('x')
3212  >>> is_int(x)
3213  True
3214  >>> is_int(x + 1)
3215  True
3216  """
3217  ctx = _get_ctx(ctx)
3218  return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
3219 
3220 
def Int(name, ctx=None)
Definition: z3py.py:3208

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

3956 def Int2BV(a, num_bits):
3957  """Return the z3 expression Int2BV(a, num_bits).
3958  It is a bit-vector of width num_bits and represents the
3959  modulo of a by 2^num_bits
3960  """
3961  ctx = a.ctx
3962  return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
3963 
3964 
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:3956

◆ Intersect()

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

Definition at line 11071 of file z3py.py.

11071 def Intersect(*args):
11072  """Create intersection of regular expressions.
11073  >>> re = Intersect(Re("a"), Re("b"), Re("c"))
11074  """
11075  args = _get_args(args)
11076  sz = len(args)
11077  if z3_debug():
11078  _z3_assert(sz > 0, "At least one argument expected.")
11079  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11080  if sz == 1:
11081  return args[0]
11082  ctx = args[0].ctx
11083  v = (Ast * sz)()
11084  for i in range(sz):
11085  v[i] = args[i].as_ast()
11086  return ReRef(Z3_mk_re_intersect(ctx.ref(), sz, v), ctx)
11087 
11088 
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:11071

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

3221 def Ints(names, ctx=None):
3222  """Return a tuple of Integer constants.
3223 
3224  >>> x, y, z = Ints('x y z')
3225  >>> Sum(x, y, z)
3226  x + y + z
3227  """
3228  ctx = _get_ctx(ctx)
3229  if isinstance(names, str):
3230  names = names.split(" ")
3231  return [Int(name, ctx) for name in names]
3232 
3233 
def Ints(names, ctx=None)
Definition: z3py.py:3221

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

3098 def IntSort(ctx=None):
3099  """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3100 
3101  >>> IntSort()
3102  Int
3103  >>> x = Const('x', IntSort())
3104  >>> is_int(x)
3105  True
3106  >>> x.sort() == IntSort()
3107  True
3108  >>> x.sort() == BoolSort()
3109  False
3110  """
3111  ctx = _get_ctx(ctx)
3112  return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
3113 
3114 
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.

Referenced by FreshInt(), Int(), and IntVal().

◆ IntToStr()

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

Definition at line 10979 of file z3py.py.

10979 def IntToStr(s):
10980  """Convert integer expression to string"""
10981  if not is_expr(s):
10982  s = _py2expr(s)
10983  return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
10984 
10985 
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.
def IntToStr(s)
Definition: z3py.py:10979

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

3148 def IntVal(val, ctx=None):
3149  """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3150 
3151  >>> IntVal(1)
3152  1
3153  >>> IntVal("100")
3154  100
3155  """
3156  ctx = _get_ctx(ctx)
3157  return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
3158 
3159 

Referenced by SeqRef.__getitem__(), SeqRef.at(), AlgebraicNumRef.index(), 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 3234 of file z3py.py.

3234 def IntVector(prefix, sz, ctx=None):
3235  """Return a list of integer constants of size `sz`.
3236 
3237  >>> X = IntVector('x', 3)
3238  >>> X
3239  [x__0, x__1, x__2]
3240  >>> Sum(X)
3241  x__0 + x__1 + x__2
3242  """
3243  ctx = _get_ctx(ctx)
3244  return [Int("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3245 
3246 
def IntVector(prefix, sz, ctx=None)
Definition: z3py.py:3234

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

2752 def is_add(a):
2753  """Return `True` if `a` is an expression of the form b + c.
2754 
2755  >>> x, y = Ints('x y')
2756  >>> is_add(x + y)
2757  True
2758  >>> is_add(x - y)
2759  False
2760  """
2761  return is_app_of(a, Z3_OP_ADD)
2762 
2763 
def is_add(a)
Definition: z3py.py:2752
def is_app_of(a, k)
Definition: z3py.py:1335

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

2738 def is_algebraic_value(a):
2739  """Return `True` if `a` is an algebraic value of sort Real.
2740 
2741  >>> is_algebraic_value(RealVal("3/5"))
2742  False
2743  >>> n = simplify(Sqrt(2))
2744  >>> n
2745  1.4142135623?
2746  >>> is_algebraic_value(n)
2747  True
2748  """
2749  return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2750 
2751 
def is_algebraic_value(a)
Definition: z3py.py:2738
def is_arith(a)
Definition: z3py.py:2625

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

1584 def is_and(a):
1585  """Return `True` if `a` is a Z3 and expression.
1586 
1587  >>> p, q = Bools('p q')
1588  >>> is_and(And(p, q))
1589  True
1590  >>> is_and(Or(p, q))
1591  False
1592  """
1593  return is_app_of(a, Z3_OP_AND)
1594 
1595 
def is_and(a)
Definition: z3py.py:1584

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

1232 def is_app(a):
1233  """Return `True` if `a` is a Z3 function application.
1234 
1235  Note that, constants are function applications with 0 arguments.
1236 
1237  >>> a = Int('a')
1238  >>> is_app(a)
1239  True
1240  >>> is_app(a + 1)
1241  True
1242  >>> is_app(IntSort())
1243  False
1244  >>> is_app(1)
1245  False
1246  >>> is_app(IntVal(1))
1247  True
1248  >>> x = Int('x')
1249  >>> is_app(ForAll(x, x >= 0))
1250  False
1251  """
1252  if not isinstance(a, ExprRef):
1253  return False
1254  k = _ast_kind(a.ctx, a)
1255  return k == Z3_NUMERAL_AST or k == Z3_APP_AST
1256 
1257 
def is_app(a)
Definition: z3py.py:1232

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

1335 def is_app_of(a, k):
1336  """Return `True` if `a` is an application of the given kind `k`.
1337 
1338  >>> x = Int('x')
1339  >>> n = x + 1
1340  >>> is_app_of(n, Z3_OP_ADD)
1341  True
1342  >>> is_app_of(n, Z3_OP_MUL)
1343  False
1344  """
1345  return is_app(a) and a.decl().kind() == k
1346 
1347 

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

2625 def is_arith(a):
2626  """Return `True` if `a` is an arithmetical expression.
2627 
2628  >>> x = Int('x')
2629  >>> is_arith(x)
2630  True
2631  >>> is_arith(x + 1)
2632  True
2633  >>> is_arith(1)
2634  False
2635  >>> is_arith(IntVal(1))
2636  True
2637  >>> y = Real('y')
2638  >>> is_arith(y)
2639  True
2640  >>> is_arith(y + 1)
2641  True
2642  """
2643  return isinstance(a, ArithRef)
2644 
2645 

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

2324 def is_arith_sort(s):
2325  """Return `True` if s is an arithmetical sort (type).
2326 
2327  >>> is_arith_sort(IntSort())
2328  True
2329  >>> is_arith_sort(RealSort())
2330  True
2331  >>> is_arith_sort(BoolSort())
2332  False
2333  >>> n = Int('x') + 1
2334  >>> is_arith_sort(n.sort())
2335  True
2336  """
2337  return isinstance(s, ArithSortRef)
2338 
2339 
def is_arith_sort(s)
Definition: z3py.py:2324

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

4571 def is_array(a):
4572  """Return `True` if `a` is a Z3 array expression.
4573 
4574  >>> a = Array('a', IntSort(), IntSort())
4575  >>> is_array(a)
4576  True
4577  >>> is_array(Store(a, 0, 1))
4578  True
4579  >>> is_array(a[0])
4580  False
4581  """
4582  return isinstance(a, ArrayRef)
4583 
4584 

Referenced by Ext(), and Map().

◆ is_array_sort()

def z3py.is_array_sort (   a)

Definition at line 4567 of file z3py.py.

4567 def is_array_sort(a):
4568  return Z3_get_sort_kind(a.ctx.ref(), Z3_get_sort(a.ctx.ref(), a.ast)) == Z3_ARRAY_SORT
4569 
4570 
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 6619 of file z3py.py.

6619 def is_as_array(n):
6620  """Return true if n is a Z3 expression of the form (_ as-array f)."""
6621  return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6622 
6623 
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 445 of file z3py.py.

445 def is_ast(a):
446  """Return `True` if `a` is an AST node.
447 
448  >>> is_ast(10)
449  False
450  >>> is_ast(IntVal(10))
451  True
452  >>> is_ast(Int('x'))
453  True
454  >>> is_ast(BoolSort())
455  True
456  >>> is_ast(Function('f', IntSort(), IntSort()))
457  True
458  >>> is_ast("x")
459  False
460  >>> is_ast(Solver())
461  False
462  """
463  return isinstance(a, AstRef)
464 
465 

Referenced by eq(), AstRef.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 1534 of file z3py.py.

1534 def is_bool(a):
1535  """Return `True` if `a` is a Z3 Boolean expression.
1536 
1537  >>> p = Bool('p')
1538  >>> is_bool(p)
1539  True
1540  >>> q = Bool('q')
1541  >>> is_bool(And(p, q))
1542  True
1543  >>> x = Real('x')
1544  >>> is_bool(x)
1545  False
1546  >>> is_bool(x == 0)
1547  True
1548  """
1549  return isinstance(a, BoolRef)
1550 
1551 
def is_bool(a)
Definition: z3py.py:1534

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

3904 def is_bv(a):
3905  """Return `True` if `a` is a Z3 bit-vector expression.
3906 
3907  >>> b = BitVec('b', 32)
3908  >>> is_bv(b)
3909  True
3910  >>> is_bv(b + 10)
3911  True
3912  >>> is_bv(Int('x'))
3913  False
3914  """
3915  return isinstance(a, BitVecRef)
3916 
3917 

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

3436 def is_bv_sort(s):
3437  """Return True if `s` is a Z3 bit-vector sort.
3438 
3439  >>> is_bv_sort(BitVecSort(32))
3440  True
3441  >>> is_bv_sort(IntSort())
3442  False
3443  """
3444  return isinstance(s, BitVecSortRef)
3445 
3446 

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

3918 def is_bv_value(a):
3919  """Return `True` if `a` is a Z3 bit-vector numeral value.
3920 
3921  >>> b = BitVec('b', 32)
3922  >>> is_bv_value(b)
3923  False
3924  >>> b = BitVecVal(10, 32)
3925  >>> b
3926  10
3927  >>> is_bv_value(b)
3928  True
3929  """
3930  return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
3931 
3932 
def is_bv_value(a)
Definition: z3py.py:3918

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

1258 def is_const(a):
1259  """Return `True` if `a` is Z3 constant/variable expression.
1260 
1261  >>> a = Int('a')
1262  >>> is_const(a)
1263  True
1264  >>> is_const(a + 1)
1265  False
1266  >>> is_const(1)
1267  False
1268  >>> is_const(IntVal(1))
1269  True
1270  >>> x = Int('x')
1271  >>> is_const(ForAll(x, x >= 0))
1272  False
1273  """
1274  return is_app(a) and a.num_args() == 0
1275 
1276 
def is_const(a)
Definition: z3py.py:1258

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

4585 def is_const_array(a):
4586  """Return `True` if `a` is a Z3 constant array.
4587 
4588  >>> a = K(IntSort(), 10)
4589  >>> is_const_array(a)
4590  True
4591  >>> a = Array('a', IntSort(), IntSort())
4592  >>> is_const_array(a)
4593  False
4594  """
4595  return is_app_of(a, Z3_OP_CONST_ARRAY)
4596 
4597 
def is_const_array(a)
Definition: z3py.py:4585

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

4627 def is_default(a):
4628  """Return `True` if `a` is a Z3 default array expression.
4629  >>> d = Default(K(IntSort(), 10))
4630  >>> is_default(d)
4631  True
4632  """
4633  return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4634 
4635 
def is_default(a)
Definition: z3py.py:4627

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

1642 def is_distinct(a):
1643  """Return `True` if `a` is a Z3 distinct expression.
1644 
1645  >>> x, y, z = Ints('x y z')
1646  >>> is_distinct(x == y)
1647  False
1648  >>> is_distinct(Distinct(x, y, z))
1649  True
1650  """
1651  return is_app_of(a, Z3_OP_DISTINCT)
1652 
1653 
def is_distinct(a)
Definition: z3py.py:1642

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

2788 def is_div(a):
2789  """Return `True` if `a` is an expression of the form b / c.
2790 
2791  >>> x, y = Reals('x y')
2792  >>> is_div(x / y)
2793  True
2794  >>> is_div(x + y)
2795  False
2796  >>> x, y = Ints('x y')
2797  >>> is_div(x / y)
2798  False
2799  >>> is_idiv(x / y)
2800  True
2801  """
2802  return is_app_of(a, Z3_OP_DIV)
2803 
2804 
def is_div(a)
Definition: z3py.py:2788

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

1632 def is_eq(a):
1633  """Return `True` if `a` is a Z3 equality expression.
1634 
1635  >>> x, y = Ints('x y')
1636  >>> is_eq(x == y)
1637  True
1638  """
1639  return is_app_of(a, Z3_OP_EQ)
1640 
1641 
def is_eq(a)
Definition: z3py.py:1632

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

1209 def is_expr(a):
1210  """Return `True` if `a` is a Z3 expression.
1211 
1212  >>> a = Int('a')
1213  >>> is_expr(a)
1214  True
1215  >>> is_expr(a + 1)
1216  True
1217  >>> is_expr(IntSort())
1218  False
1219  >>> is_expr(1)
1220  False
1221  >>> is_expr(IntVal(1))
1222  True
1223  >>> x = Int('x')
1224  >>> is_expr(ForAll(x, x >= 0))
1225  True
1226  >>> is_expr(FPVal(1.0))
1227  True
1228  """
1229  return isinstance(a, ExprRef)
1230 
1231 

Referenced by SeqRef.__gt__(), SortRef.cast(), BoolSortRef.cast(), ArithSortRef.cast(), BitVecSortRef.cast(), FPSortRef.cast(), Cbrt(), CharFromBv(), CharIsDigit(), ExprRef.children(), Concat(), AlgebraicNumRef.index(), IndexOf(), IntToStr(), is_quantifier(), is_var(), K(), MultiPattern(), Replace(), simplify(), Sqrt(), StrFromCode(), StrToCode(), substitute(), substitute_vars(), and ModelRef.update_value().

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

1570 def is_false(a):
1571  """Return `True` if `a` is the Z3 false expression.
1572 
1573  >>> p = Bool('p')
1574  >>> is_false(p)
1575  False
1576  >>> is_false(False)
1577  False
1578  >>> is_false(BoolVal(False))
1579  True
1580  """
1581  return is_app_of(a, Z3_OP_FALSE)
1582 
1583 
def is_false(a)
Definition: z3py.py:1570

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

7656 def is_finite_domain(a):
7657  """Return `True` if `a` is a Z3 finite-domain expression.
7658 
7659  >>> s = FiniteDomainSort('S', 100)
7660  >>> b = Const('b', s)
7661  >>> is_finite_domain(b)
7662  True
7663  >>> is_finite_domain(Int('x'))
7664  False
7665  """
7666  return isinstance(a, FiniteDomainRef)
7667 
7668 
def is_finite_domain(a)
Definition: z3py.py:7656

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

7633 def is_finite_domain_sort(s):
7634  """Return True if `s` is a Z3 finite-domain sort.
7635 
7636  >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7637  True
7638  >>> is_finite_domain_sort(IntSort())
7639  False
7640  """
7641  return isinstance(s, FiniteDomainSortRef)
7642 
7643 

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

7710 def is_finite_domain_value(a):
7711  """Return `True` if `a` is a Z3 finite-domain value.
7712 
7713  >>> s = FiniteDomainSort('S', 100)
7714  >>> b = Const('b', s)
7715  >>> is_finite_domain_value(b)
7716  False
7717  >>> b = FiniteDomainVal(10, s)
7718  >>> b
7719  10
7720  >>> is_finite_domain_value(b)
7721  True
7722  """
7723  return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
7724 
7725 
def is_finite_domain_value(a)
Definition: z3py.py:7710

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

9737 def is_fp(a):
9738  """Return `True` if `a` is a Z3 floating-point expression.
9739 
9740  >>> b = FP('b', FPSort(8, 24))
9741  >>> is_fp(b)
9742  True
9743  >>> is_fp(b + 1.0)
9744  True
9745  >>> is_fp(Int('x'))
9746  False
9747  """
9748  return isinstance(a, FPRef)
9749 
9750 

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

9321 def is_fp_sort(s):
9322  """Return True if `s` is a Z3 floating-point sort.
9323 
9324  >>> is_fp_sort(FPSort(8, 24))
9325  True
9326  >>> is_fp_sort(IntSort())
9327  False
9328  """
9329  return isinstance(s, FPSortRef)
9330 
9331 

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

9751 def is_fp_value(a):
9752  """Return `True` if `a` is a Z3 floating-point numeral value.
9753 
9754  >>> b = FP('b', FPSort(8, 24))
9755  >>> is_fp_value(b)
9756  False
9757  >>> b = FPVal(1.0, FPSort(8, 24))
9758  >>> b
9759  1
9760  >>> is_fp_value(b)
9761  True
9762  """
9763  return is_fp(a) and _is_numeral(a.ctx, a.ast)
9764 
9765 
def is_fp_value(a)
Definition: z3py.py:9751

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

9581 def is_fprm(a):
9582  """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9583 
9584  >>> rm = RNE()
9585  >>> is_fprm(rm)
9586  True
9587  >>> rm = 1.0
9588  >>> is_fprm(rm)
9589  False
9590  """
9591  return isinstance(a, FPRMRef)
9592 
9593 

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

9332 def is_fprm_sort(s):
9333  """Return True if `s` is a Z3 floating-point rounding mode sort.
9334 
9335  >>> is_fprm_sort(FPSort(8, 24))
9336  False
9337  >>> is_fprm_sort(RNE().sort())
9338  True
9339  """
9340  return isinstance(s, FPRMSortRef)
9341 
9342 # FP Expressions
9343 
9344 
def is_fprm_sort(s)
Definition: z3py.py:9332

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

9594 def is_fprm_value(a):
9595  """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9596  return is_fprm(a) and _is_numeral(a.ctx, a.ast)
9597 
9598 # FP Numerals
9599 
9600 
def is_fprm_value(a)
Definition: z3py.py:9594

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

844 def is_func_decl(a):
845  """Return `True` if `a` is a Z3 function declaration.
846 
847  >>> f = Function('f', IntSort(), IntSort())
848  >>> is_func_decl(f)
849  True
850  >>> x = Real('x')
851  >>> is_func_decl(x)
852  False
853  """
854  return isinstance(a, FuncDeclRef)
855 
856 
def is_func_decl(a)
Definition: z3py.py:844

Referenced by Map(), prove(), and ModelRef.update_value().

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

2853 def is_ge(a):
2854  """Return `True` if `a` is an expression of the form b >= c.
2855 
2856  >>> x, y = Ints('x y')
2857  >>> is_ge(x >= y)
2858  True
2859  >>> is_ge(x == y)
2860  False
2861  """
2862  return is_app_of(a, Z3_OP_GE)
2863 
2864 
def is_ge(a)
Definition: z3py.py:2853

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

2865 def is_gt(a):
2866  """Return `True` if `a` is an expression of the form b > c.
2867 
2868  >>> x, y = Ints('x y')
2869  >>> is_gt(x > y)
2870  True
2871  >>> is_gt(x == y)
2872  False
2873  """
2874  return is_app_of(a, Z3_OP_GT)
2875 
2876 
def is_gt(a)
Definition: z3py.py:2865

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

2805 def is_idiv(a):
2806  """Return `True` if `a` is an expression of the form b div c.
2807 
2808  >>> x, y = Ints('x y')
2809  >>> is_idiv(x / y)
2810  True
2811  >>> is_idiv(x + y)
2812  False
2813  """
2814  return is_app_of(a, Z3_OP_IDIV)
2815 
2816 
def is_idiv(a)
Definition: z3py.py:2805

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

1608 def is_implies(a):
1609  """Return `True` if `a` is a Z3 implication expression.
1610 
1611  >>> p, q = Bools('p q')
1612  >>> is_implies(Implies(p, q))
1613  True
1614  >>> is_implies(And(p, q))
1615  False
1616  """
1617  return is_app_of(a, Z3_OP_IMPLIES)
1618 
1619 
def is_implies(a)
Definition: z3py.py:1608

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

2646 def is_int(a):
2647  """Return `True` if `a` is an integer expression.
2648 
2649  >>> x = Int('x')
2650  >>> is_int(x + 1)
2651  True
2652  >>> is_int(1)
2653  False
2654  >>> is_int(IntVal(1))
2655  True
2656  >>> y = Real('y')
2657  >>> is_int(y)
2658  False
2659  >>> is_int(y + 1)
2660  False
2661  """
2662  return is_arith(a) and a.is_int()
2663 
2664 
def is_int(a)
Definition: z3py.py:2646

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

2692 def is_int_value(a):
2693  """Return `True` if `a` is an integer value of sort Int.
2694 
2695  >>> is_int_value(IntVal(1))
2696  True
2697  >>> is_int_value(1)
2698  False
2699  >>> is_int_value(Int('x'))
2700  False
2701  >>> n = Int('x') + 1
2702  >>> n
2703  x + 1
2704  >>> n.arg(1)
2705  1
2706  >>> is_int_value(n.arg(1))
2707  True
2708  >>> is_int_value(RealVal("1/3"))
2709  False
2710  >>> is_int_value(RealVal(1))
2711  False
2712  """
2713  return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
2714 
2715 
def is_int_value(a)
Definition: z3py.py:2692

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

2877 def is_is_int(a):
2878  """Return `True` if `a` is an expression of the form IsInt(b).
2879 
2880  >>> x = Real('x')
2881  >>> is_is_int(IsInt(x))
2882  True
2883  >>> is_is_int(x)
2884  False
2885  """
2886  return is_app_of(a, Z3_OP_IS_INT)
2887 
2888 
def is_is_int(a)
Definition: z3py.py:2877

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

4598 def is_K(a):
4599  """Return `True` if `a` is a Z3 constant array.
4600 
4601  >>> a = K(IntSort(), 10)
4602  >>> is_K(a)
4603  True
4604  >>> a = Array('a', IntSort(), IntSort())
4605  >>> is_K(a)
4606  False
4607  """
4608  return is_app_of(a, Z3_OP_CONST_ARRAY)
4609 
4610 
def is_K(a)
Definition: z3py.py:4598

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

2829 def is_le(a):
2830  """Return `True` if `a` is an expression of the form b <= c.
2831 
2832  >>> x, y = Ints('x y')
2833  >>> is_le(x <= y)
2834  True
2835  >>> is_le(x < y)
2836  False
2837  """
2838  return is_app_of(a, Z3_OP_LE)
2839 
2840 
def is_le(a)
Definition: z3py.py:2829

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

2841 def is_lt(a):
2842  """Return `True` if `a` is an expression of the form b < c.
2843 
2844  >>> x, y = Ints('x y')
2845  >>> is_lt(x < y)
2846  True
2847  >>> is_lt(x == y)
2848  False
2849  """
2850  return is_app_of(a, Z3_OP_LT)
2851 
2852 
def is_lt(a)
Definition: z3py.py:2841

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

4611 def is_map(a):
4612  """Return `True` if `a` is a Z3 map array expression.
4613 
4614  >>> f = Function('f', IntSort(), IntSort())
4615  >>> b = Array('b', IntSort(), IntSort())
4616  >>> a = Map(f, b)
4617  >>> a
4618  Map(f, b)
4619  >>> is_map(a)
4620  True
4621  >>> is_map(b)
4622  False
4623  """
4624  return is_app_of(a, Z3_OP_ARRAY_MAP)
4625 
4626 

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

2817 def is_mod(a):
2818  """Return `True` if `a` is an expression of the form b % c.
2819 
2820  >>> x, y = Ints('x y')
2821  >>> is_mod(x % y)
2822  True
2823  >>> is_mod(x + y)
2824  False
2825  """
2826  return is_app_of(a, Z3_OP_MOD)
2827 
2828 
def is_mod(a)
Definition: z3py.py:2817

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

2764 def is_mul(a):
2765  """Return `True` if `a` is an expression of the form b * c.
2766 
2767  >>> x, y = Ints('x y')
2768  >>> is_mul(x * y)
2769  True
2770  >>> is_mul(x - y)
2771  False
2772  """
2773  return is_app_of(a, Z3_OP_MUL)
2774 
2775 
def is_mul(a)
Definition: z3py.py:2764

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

1620 def is_not(a):
1621  """Return `True` if `a` is a Z3 not expression.
1622 
1623  >>> p = Bool('p')
1624  >>> is_not(p)
1625  False
1626  >>> is_not(Not(p))
1627  True
1628  """
1629  return is_app_of(a, Z3_OP_NOT)
1630 
1631 
def is_not(a)
Definition: z3py.py:1620

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

1596 def is_or(a):
1597  """Return `True` if `a` is a Z3 or expression.
1598 
1599  >>> p, q = Bools('p q')
1600  >>> is_or(Or(p, q))
1601  True
1602  >>> is_or(And(p, q))
1603  False
1604  """
1605  return is_app_of(a, Z3_OP_OR)
1606 
1607 
def is_or(a)
Definition: z3py.py:1596

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

1896 def is_pattern(a):
1897  """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1898 
1899  >>> f = Function('f', IntSort(), IntSort())
1900  >>> x = Int('x')
1901  >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1902  >>> q
1903  ForAll(x, f(x) == 0)
1904  >>> q.num_patterns()
1905  1
1906  >>> is_pattern(q.pattern(0))
1907  True
1908  >>> q.pattern(0)
1909  f(Var(0))
1910  """
1911  return isinstance(a, PatternRef)
1912 
1913 
def is_pattern(a)
Definition: z3py.py:1896

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

8546 def is_probe(p):
8547  """Return `True` if `p` is a Z3 probe.
8548 
8549  >>> is_probe(Int('x'))
8550  False
8551  >>> is_probe(Probe('memory'))
8552  True
8553  """
8554  return isinstance(p, Probe)
8555 
8556 
def is_probe(p)
Definition: z3py.py:8546

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

2136 def is_quantifier(a):
2137  """Return `True` if `a` is a Z3 quantifier.
2138 
2139  >>> f = Function('f', IntSort(), IntSort())
2140  >>> x = Int('x')
2141  >>> q = ForAll(x, f(x) == 0)
2142  >>> is_quantifier(q)
2143  True
2144  >>> is_quantifier(f(x))
2145  False
2146  """
2147  return isinstance(a, QuantifierRef)
2148 
2149 
def is_quantifier(a)
Definition: z3py.py:2136

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

2716 def is_rational_value(a):
2717  """Return `True` if `a` is rational value of sort Real.
2718 
2719  >>> is_rational_value(RealVal(1))
2720  True
2721  >>> is_rational_value(RealVal("3/5"))
2722  True
2723  >>> is_rational_value(IntVal(1))
2724  False
2725  >>> is_rational_value(1)
2726  False
2727  >>> n = Real('x') + 1
2728  >>> n.arg(1)
2729  1
2730  >>> is_rational_value(n.arg(1))
2731  True
2732  >>> is_rational_value(Real('x'))
2733  False
2734  """
2735  return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2736 
2737 
def is_rational_value(a)
Definition: z3py.py:2716

◆ is_re()

def z3py.is_re (   s)

Definition at line 11033 of file z3py.py.

11033 def is_re(s):
11034  return isinstance(s, ReRef)
11035 
11036 

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

2665 def is_real(a):
2666  """Return `True` if `a` is a real expression.
2667 
2668  >>> x = Int('x')
2669  >>> is_real(x + 1)
2670  False
2671  >>> y = Real('y')
2672  >>> is_real(y)
2673  True
2674  >>> is_real(y + 1)
2675  True
2676  >>> is_real(1)
2677  False
2678  >>> is_real(RealVal(1))
2679  True
2680  """
2681  return is_arith(a) and a.is_real()
2682 
2683 

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

4846 def is_select(a):
4847  """Return `True` if `a` is a Z3 array select application.
4848 
4849  >>> a = Array('a', IntSort(), IntSort())
4850  >>> is_select(a)
4851  False
4852  >>> i = Int('i')
4853  >>> is_select(a[i])
4854  True
4855  """
4856  return is_app_of(a, Z3_OP_SELECT)
4857 
4858 
def is_select(a)
Definition: z3py.py:4846

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

10759 def is_seq(a):
10760  """Return `True` if `a` is a Z3 sequence expression.
10761  >>> print (is_seq(Unit(IntVal(0))))
10762  True
10763  >>> print (is_seq(StringVal("abc")))
10764  True
10765  """
10766  return isinstance(a, SeqRef)
10767 
10768 

Referenced by CharIsDigit(), 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 641 of file z3py.py.

641 def is_sort(s):
642  """Return `True` if `s` is a Z3 sort.
643 
644  >>> is_sort(IntSort())
645  True
646  >>> is_sort(Int('x'))
647  False
648  >>> is_expr(Int('x'))
649  True
650  """
651  return isinstance(s, SortRef)
652 
653 

Referenced by ArraySort(), CreateDatatypes(), FreshFunction(), 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 4859 of file z3py.py.

4859 def is_store(a):
4860  """Return `True` if `a` is a Z3 array store application.
4861 
4862  >>> a = Array('a', IntSort(), IntSort())
4863  >>> is_store(a)
4864  False
4865  >>> is_store(Store(a, 0, 1))
4866  True
4867  """
4868  return is_app_of(a, Z3_OP_STORE)
4869 
def is_store(a)
Definition: z3py.py:4859

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

10769 def is_string(a):
10770  """Return `True` if `a` is a Z3 string expression.
10771  >>> print (is_string(StringVal("ab")))
10772  True
10773  """
10774  return isinstance(a, SeqRef) and a.is_string()
10775 
10776 
def is_string(a)
Definition: z3py.py:10769

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

10777 def is_string_value(a):
10778  """return 'True' if 'a' is a Z3 string constant expression.
10779  >>> print (is_string_value(StringVal("a")))
10780  True
10781  >>> print (is_string_value(StringVal("a") + StringVal("b")))
10782  False
10783  """
10784  return isinstance(a, SeqRef) and a.is_string_value()
10785 
def is_string_value(a)
Definition: z3py.py:10777

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

2776 def is_sub(a):
2777  """Return `True` if `a` is an expression of the form b - c.
2778 
2779  >>> x, y = Ints('x y')
2780  >>> is_sub(x - y)
2781  True
2782  >>> is_sub(x + y)
2783  False
2784  """
2785  return is_app_of(a, Z3_OP_SUB)
2786 
2787 
def is_sub(a)
Definition: z3py.py:2776

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

2904 def is_to_int(a):
2905  """Return `True` if `a` is an expression of the form ToInt(b).
2906 
2907  >>> x = Real('x')
2908  >>> n = ToInt(x)
2909  >>> n
2910  ToInt(x)
2911  >>> is_to_int(n)
2912  True
2913  >>> is_to_int(x)
2914  False
2915  """
2916  return is_app_of(a, Z3_OP_TO_INT)
2917 
2918 
def is_to_int(a)
Definition: z3py.py:2904

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

2889 def is_to_real(a):
2890  """Return `True` if `a` is an expression of the form ToReal(b).
2891 
2892  >>> x = Int('x')
2893  >>> n = ToReal(x)
2894  >>> n
2895  ToReal(x)
2896  >>> is_to_real(n)
2897  True
2898  >>> is_to_real(x)
2899  False
2900  """
2901  return is_app_of(a, Z3_OP_TO_REAL)
2902 
2903 
def is_to_real(a)
Definition: z3py.py:2889

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

1552 def is_true(a):
1553  """Return `True` if `a` is the Z3 true expression.
1554 
1555  >>> p = Bool('p')
1556  >>> is_true(p)
1557  False
1558  >>> is_true(simplify(p == p))
1559  True
1560  >>> x = Real('x')
1561  >>> is_true(x == 0)
1562  False
1563  >>> # True is a Python Boolean expression
1564  >>> is_true(True)
1565  False
1566  """
1567  return is_app_of(a, Z3_OP_TRUE)
1568 
1569 
def is_true(a)
Definition: z3py.py:1552

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

1277 def is_var(a):
1278  """Return `True` if `a` is variable.
1279 
1280  Z3 uses de-Bruijn indices for representing bound variables in
1281  quantifiers.
1282 
1283  >>> x = Int('x')
1284  >>> is_var(x)
1285  False
1286  >>> is_const(x)
1287  True
1288  >>> f = Function('f', IntSort(), IntSort())
1289  >>> # Z3 replaces x with bound variables when ForAll is executed.
1290  >>> q = ForAll(x, f(x) == x)
1291  >>> b = q.body()
1292  >>> b
1293  f(Var(0)) == Var(0)
1294  >>> b.arg(1)
1295  Var(0)
1296  >>> is_var(b.arg(1))
1297  True
1298  """
1299  return is_expr(a) and _ast_kind(a.ctx, a) == Z3_VAR_AST
1300 
1301 

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

3354 def IsInt(a):
3355  """ Return the Z3 predicate IsInt(a).
3356 
3357  >>> x = Real('x')
3358  >>> IsInt(x + "1/2")
3359  IsInt(x + 1/2)
3360  >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3361  [x = 1/2]
3362  >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3363  no solution
3364  """
3365  if z3_debug():
3366  _z3_assert(a.is_real(), "Z3 real expression expected.")
3367  ctx = a.ctx
3368  return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
3369 
3370 
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
def IsInt(a)
Definition: z3py.py:3354

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

4969 def IsMember(e, s):
4970  """ Check if e is a member of set s
4971  >>> a = Const('a', SetSort(IntSort()))
4972  >>> IsMember(1, a)
4973  a[1]
4974  """
4975  ctx = _ctx_from_ast_arg_list([s, e])
4976  e = _py2expr(e, ctx)
4977  return BoolRef(Z3_mk_set_member(ctx.ref(), e.as_ast(), s.as_ast()), ctx)
4978 
4979 
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:4969

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

4980 def IsSubset(a, b):
4981  """ Check if a is a subset of b
4982  >>> a = Const('a', SetSort(IntSort()))
4983  >>> b = Const('b', SetSort(IntSort()))
4984  >>> IsSubset(a, b)
4985  subset(a, b)
4986  """
4987  ctx = _ctx_from_ast_arg_list([a, b])
4988  return BoolRef(Z3_mk_set_subset(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4989 
4990 
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.
def IsSubset(a, b)
Definition: z3py.py:4980

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

4806 def K(dom, v):
4807  """Return a Z3 constant array expression.
4808 
4809  >>> a = K(IntSort(), 10)
4810  >>> a
4811  K(Int, 10)
4812  >>> a.sort()
4813  Array(Int, Int)
4814  >>> i = Int('i')
4815  >>> a[i]
4816  K(Int, 10)[i]
4817  >>> simplify(a[i])
4818  10
4819  """
4820  if z3_debug():
4821  _z3_assert(is_sort(dom), "Z3 sort expected")
4822  ctx = dom.ctx
4823  if not is_expr(v):
4824  v = _py2expr(v, ctx)
4825  return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
4826 
4827 
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
def K(dom, v)
Definition: z3py.py:4806

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

2224 def Lambda(vs, body):
2225  """Create a Z3 lambda expression.
2226 
2227  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2228  >>> mem0 = Array('mem0', IntSort(), IntSort())
2229  >>> lo, hi, e, i = Ints('lo hi e i')
2230  >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2231  >>> mem1
2232  Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2233  """
2234  ctx = body.ctx
2235  if is_app(vs):
2236  vs = [vs]
2237  num_vars = len(vs)
2238  _vs = (Ast * num_vars)()
2239  for i in range(num_vars):
2240  # TODO: Check if is constant
2241  _vs[i] = vs[i].as_ast()
2242  return QuantifierRef(Z3_mk_lambda_const(ctx.ref(), num_vars, _vs, body.as_ast()), ctx)
2243 
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:2224

◆ LastIndexOf()

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

Definition at line 10944 of file z3py.py.

10944 def LastIndexOf(s, substr):
10945  """Retrieve the last index of substring within a string"""
10946  ctx = None
10947  ctx = _get_ctx2(s, substr, ctx)
10948  s = _coerce_seq(s, ctx)
10949  substr = _coerce_seq(substr, ctx)
10950  return ArithRef(Z3_mk_seq_last_index(s.ctx_ref(), s.as_ast(), substr.as_ast()), s.ctx)
10951 
10952 
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,...
def LastIndexOf(s, substr)
Definition: z3py.py:10944

◆ Length()

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

Definition at line 10953 of file z3py.py.

10953 def Length(s):
10954  """Obtain the length of a sequence 's'
10955  >>> l = Length(StringVal("abc"))
10956  >>> simplify(l)
10957  3
10958  """
10959  s = _coerce_seq(s)
10960  return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
10961 
10962 
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:10953

◆ LinearOrder()

def z3py.LinearOrder (   a,
  index 
)

Definition at line 11175 of file z3py.py.

11175 def LinearOrder(a, index):
11176  return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11177 
11178 
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.
def LinearOrder(a, index)
Definition: z3py.py:11175

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

11133 def Loop(re, lo, hi=0):
11134  """Create the regular expression accepting between a lower and upper bound repetitions
11135  >>> re = Loop(Re("a"), 1, 3)
11136  >>> print(simplify(InRe("aa", re)))
11137  True
11138  >>> print(simplify(InRe("aaaa", re)))
11139  False
11140  >>> print(simplify(InRe("", re)))
11141  False
11142  """
11143  return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
11144 
11145 
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:11133

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

4259 def LShR(a, b):
4260  """Create the Z3 expression logical right shift.
4261 
4262  Use the operator >> for the arithmetical right shift.
4263 
4264  >>> x, y = BitVecs('x y', 32)
4265  >>> LShR(x, y)
4266  LShR(x, y)
4267  >>> (x >> y).sexpr()
4268  '(bvashr x y)'
4269  >>> LShR(x, y).sexpr()
4270  '(bvlshr x y)'
4271  >>> BitVecVal(4, 3)
4272  4
4273  >>> BitVecVal(4, 3).as_signed_long()
4274  -4
4275  >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4276  -2
4277  >>> simplify(BitVecVal(4, 3) >> 1)
4278  6
4279  >>> simplify(LShR(BitVecVal(4, 3), 1))
4280  2
4281  >>> simplify(BitVecVal(2, 3) >> 1)
4282  1
4283  >>> simplify(LShR(BitVecVal(2, 3), 1))
4284  1
4285  """
4286  _check_bv_args(a, b)
4287  a, b = _coerce_exprs(a, b)
4288  return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4289 
4290 
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:4259

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

233 def main_ctx():
234  """Return a reference to the global Z3 context.
235 
236  >>> x = Real('x')
237  >>> x.ctx == main_ctx()
238  True
239  >>> c = Context()
240  >>> c == main_ctx()
241  False
242  >>> x2 = Real('x', c)
243  >>> x2.ctx == c
244  True
245  >>> eq(x, x2)
246  False
247  """
248  global _main_ctx
249  if _main_ctx is None:
250  _main_ctx = Context()
251  return _main_ctx
252 
253 

Referenced by CharIsDigit(), help_simplify(), 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 4783 of file z3py.py.

4783 def Map(f, *args):
4784  """Return a Z3 map array expression.
4785 
4786  >>> f = Function('f', IntSort(), IntSort(), IntSort())
4787  >>> a1 = Array('a1', IntSort(), IntSort())
4788  >>> a2 = Array('a2', IntSort(), IntSort())
4789  >>> b = Map(f, a1, a2)
4790  >>> b
4791  Map(f, a1, a2)
4792  >>> prove(b[0] == f(a1[0], a2[0]))
4793  proved
4794  """
4795  args = _get_args(args)
4796  if z3_debug():
4797  _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
4798  _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
4799  _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
4800  _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
4801  _args, sz = _to_ast_array(args)
4802  ctx = f.ctx
4803  return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
4804 
4805 
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 Map(f, *args)
Definition: z3py.py:4783

◆ mk_not()

def z3py.mk_not (   a)

Definition at line 1797 of file z3py.py.

1797 def mk_not(a):
1798  if is_not(a):
1799  return a.arg(0)
1800  else:
1801  return Not(a)
1802 
1803 
def mk_not(a)
Definition: z3py.py:1797

◆ Model()

def z3py.Model (   ctx = None)

Definition at line 6614 of file z3py.py.

6614 def Model(ctx=None):
6615  ctx = _get_ctx(ctx)
6616  return ModelRef(Z3_mk_model(ctx.ref()), ctx)
6617 
6618 
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.
def Model(ctx=None)
Definition: z3py.py:6614

Referenced by Optimize.set_on_model().

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

1914 def MultiPattern(*args):
1915  """Create a Z3 multi-pattern using the given expressions `*args`
1916 
1917  >>> f = Function('f', IntSort(), IntSort())
1918  >>> g = Function('g', IntSort(), IntSort())
1919  >>> x = Int('x')
1920  >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
1921  >>> q
1922  ForAll(x, f(x) != g(x))
1923  >>> q.num_patterns()
1924  1
1925  >>> is_pattern(q.pattern(0))
1926  True
1927  >>> q.pattern(0)
1928  MultiPattern(f(Var(0)), g(Var(0)))
1929  """
1930  if z3_debug():
1931  _z3_assert(len(args) > 0, "At least one argument expected")
1932  _z3_assert(all([is_expr(a) for a in args]), "Z3 expressions expected")
1933  ctx = args[0].ctx
1934  args, sz = _to_ast_array(args)
1935  return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
1936 
1937 
Z3_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[])
Create a pattern for quantifier instantiation.
def MultiPattern(*args)
Definition: z3py.py:1914

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

1778 def Not(a, ctx=None):
1779  """Create a Z3 not expression or probe.
1780 
1781  >>> p = Bool('p')
1782  >>> Not(Not(p))
1783  Not(Not(p))
1784  >>> simplify(Not(Not(p)))
1785  p
1786  """
1787  ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1788  if is_probe(a):
1789  # Not is also used to build probes
1790  return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1791  else:
1792  s = BoolSort(ctx)
1793  a = s.cast(a)
1794  return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1795 
1796 
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).

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

114 def open_log(fname):
115  """Log interaction to a file. This function must be invoked immediately after init(). """
116  Z3_open_log(fname)
117 
118 
bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.
def open_log(fname)
Definition: z3py.py:114

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

11102 def Option(re):
11103  """Create the regular expression that optionally accepts the argument.
11104  >>> re = Option(Re("a"))
11105  >>> print(simplify(InRe("a", re)))
11106  True
11107  >>> print(simplify(InRe("", re)))
11108  True
11109  >>> print(simplify(InRe("aa", re)))
11110  False
11111  """
11112  return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
11113 
11114 
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:11102

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

1845 def Or(*args):
1846  """Create a Z3 or-expression or or-probe.
1847 
1848  >>> p, q, r = Bools('p q r')
1849  >>> Or(p, q, r)
1850  Or(p, q, r)
1851  >>> P = BoolVector('p', 5)
1852  >>> Or(P)
1853  Or(p__0, p__1, p__2, p__3, p__4)
1854  """
1855  last_arg = None
1856  if len(args) > 0:
1857  last_arg = args[len(args) - 1]
1858  if isinstance(last_arg, Context):
1859  ctx = args[len(args) - 1]
1860  args = args[:len(args) - 1]
1861  elif len(args) == 1 and isinstance(args[0], AstVector):
1862  ctx = args[0].ctx
1863  args = [a for a in args[0]]
1864  else:
1865  ctx = None
1866  args = _get_args(args)
1867  ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1868  if z3_debug():
1869  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1870  if _has_probe(args):
1871  return _probe_or(args, ctx)
1872  else:
1873  args = _coerce_expr_list(args, ctx)
1874  _args, sz = _to_ast_array(args)
1875  return BoolRef(Z3_mk_or(ctx.ref(), sz, _args), ctx)
1876 
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:1845

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

8239 def OrElse(*ts, **ks):
8240  """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8241 
8242  >>> x = Int('x')
8243  >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
8244  >>> # Tactic split-clause fails if there is no clause in the given goal.
8245  >>> t(x == 0)
8246  [[x == 0]]
8247  >>> t(Or(x == 0, x == 1))
8248  [[x == 0], [x == 1]]
8249  """
8250  if z3_debug():
8251  _z3_assert(len(ts) >= 2, "At least two arguments expected")
8252  ctx = ks.get("ctx", None)
8253  num = len(ts)
8254  r = ts[0]
8255  for i in range(num - 1):
8256  r = _or_else(r, ts[i + 1], ctx)
8257  return r
8258 
8259 
def OrElse(*ts, **ks)
Definition: z3py.py:8239

◆ ParAndThen()

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

Definition at line 8295 of file z3py.py.

8295 def ParAndThen(t1, t2, ctx=None):
8296  """Alias for ParThen(t1, t2, ctx)."""
8297  return ParThen(t1, t2, ctx)
8298 
8299 
def ParThen(t1, t2, ctx=None)
Definition: z3py.py:8279
def ParAndThen(t1, t2, ctx=None)
Definition: z3py.py:8295

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

8260 def ParOr(*ts, **ks):
8261  """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8262 
8263  >>> x = Int('x')
8264  >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
8265  >>> t(x + 1 == 2)
8266  [[x == 1]]
8267  """
8268  if z3_debug():
8269  _z3_assert(len(ts) >= 2, "At least two arguments expected")
8270  ctx = _get_ctx(ks.get("ctx", None))
8271  ts = [_to_tactic(t, ctx) for t in ts]
8272  sz = len(ts)
8273  _args = (TacticObj * sz)()
8274  for i in range(sz):
8275  _args[i] = ts[i].tactic
8276  return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
8277 
8278 
Z3_tactic Z3_API Z3_tactic_par_or(Z3_context c, unsigned num, Z3_tactic const ts[])
Return a tactic that applies the given tactics in parallel.
def ParOr(*ts, **ks)
Definition: z3py.py:8260

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

9131 def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
9132  """Parse a file in SMT 2.0 format using the given sorts and decls.
9133 
9134  This function is similar to parse_smt2_string().
9135  """
9136  ctx = _get_ctx(ctx)
9137  ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9138  dsz, dnames, ddecls = _dict2darray(decls, ctx)
9139  return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9140 
9141 
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.
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
Definition: z3py.py:9131

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

9110 def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
9111  """Parse a string in SMT 2.0 format using the given sorts and decls.
9112 
9113  The arguments sorts and decls are Python dictionaries used to initialize
9114  the symbol table used for the SMT 2.0 parser.
9115 
9116  >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9117  [x > 0, x < 10]
9118  >>> x, y = Ints('x y')
9119  >>> f = Function('f', IntSort(), IntSort())
9120  >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
9121  [x + f(y) > 0]
9122  >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
9123  [a > 0]
9124  """
9125  ctx = _get_ctx(ctx)
9126  ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9127  dsz, dnames, ddecls = _dict2darray(decls, ctx)
9128  return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9129 
9130 
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.
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
Definition: z3py.py:9110

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

8279 def ParThen(t1, t2, ctx=None):
8280  """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8281  The subgoals are processed in parallel.
8282 
8283  >>> x, y = Ints('x y')
8284  >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
8285  >>> t(And(Or(x == 1, x == 2), y == x + 1))
8286  [[x == 1, y == 2], [x == 2, y == 3]]
8287  """
8288  t1 = _to_tactic(t1, ctx)
8289  t2 = _to_tactic(t2, ctx)
8290  if z3_debug():
8291  _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8292  return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8293 
8294 
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....

Referenced by ParAndThen().

◆ PartialOrder()

def z3py.PartialOrder (   a,
  index 
)

Definition at line 11171 of file z3py.py.

11171 def PartialOrder(a, index):
11172  return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx)
11173 
11174 
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:11171

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

8906 def PbEq(args, k, ctx=None):
8907  """Create a Pseudo-Boolean inequality k constraint.
8908 
8909  >>> a, b, c = Bools('a b c')
8910  >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
8911  """
8912  _z3_check_cint_overflow(k, "k")
8913  ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8914  return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
8915 
8916 
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:8906

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

8895 def PbGe(args, k):
8896  """Create a Pseudo-Boolean inequality k constraint.
8897 
8898  >>> a, b, c = Bools('a b c')
8899  >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
8900  """
8901  _z3_check_cint_overflow(k, "k")
8902  ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8903  return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
8904 
8905 
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.
def PbGe(args, k)
Definition: z3py.py:8895

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

8884 def PbLe(args, k):
8885  """Create a Pseudo-Boolean inequality k constraint.
8886 
8887  >>> a, b, c = Bools('a b c')
8888  >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
8889  """
8890  _z3_check_cint_overflow(k, "k")
8891  ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8892  return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
8893 
8894 
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.
def PbLe(args, k)
Definition: z3py.py:8884

◆ PiecewiseLinearOrder()

def z3py.PiecewiseLinearOrder (   a,
  index 
)

Definition at line 11183 of file z3py.py.

11183 def PiecewiseLinearOrder(a, index):
11184  return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11185 
11186 
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:11183

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

11089 def Plus(re):
11090  """Create the regular expression accepting one or more repetitions of argument.
11091  >>> re = Plus(Re("a"))
11092  >>> print(simplify(InRe("aa", re)))
11093  True
11094  >>> print(simplify(InRe("ab", re)))
11095  False
11096  >>> print(simplify(InRe("", re)))
11097  False
11098  """
11099  return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
11100 
11101 
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.
def Plus(re)
Definition: z3py.py:11089

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

10860 def PrefixOf(a, b):
10861  """Check if 'a' is a prefix of 'b'
10862  >>> s1 = PrefixOf("ab", "abc")
10863  >>> simplify(s1)
10864  True
10865  >>> s2 = PrefixOf("bc", "abc")
10866  >>> simplify(s2)
10867  False
10868  """
10869  ctx = _get_ctx2(a, b)
10870  a = _coerce_seq(a, ctx)
10871  b = _coerce_seq(b, ctx)
10872  return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
10873 
10874 
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:10860

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

8575 def probe_description(name, ctx=None):
8576  """Return a short description for the probe named `name`.
8577 
8578  >>> d = probe_description('memory')
8579  """
8580  ctx = _get_ctx(ctx)
8581  return Z3_probe_get_descr(ctx.ref(), name)
8582 
8583 
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 8564 of file z3py.py.

8564 def probes(ctx=None):
8565  """Return a list of all available probes in Z3.
8566 
8567  >>> l = probes()
8568  >>> l.count('memory') == 1
8569  True
8570  """
8571  ctx = _get_ctx(ctx)
8572  return [Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref()))]
8573 
8574 
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.
Z3_string Z3_API Z3_get_probe_name(Z3_context c, unsigned i)
Return the name of the i probe.

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

8791 def Product(*args):
8792  """Create the product of the Z3 expressions.
8793 
8794  >>> a, b, c = Ints('a b c')
8795  >>> Product(a, b, c)
8796  a*b*c
8797  >>> Product([a, b, c])
8798  a*b*c
8799  >>> A = IntVector('a', 5)
8800  >>> Product(A)
8801  a__0*a__1*a__2*a__3*a__4
8802  """
8803  args = _get_args(args)
8804  if len(args) == 0:
8805  return 1
8806  ctx = _ctx_from_ast_arg_list(args)
8807  if ctx is None:
8808  return _reduce(lambda a, b: a * b, args, 1)
8809  args = _coerce_expr_list(args, ctx)
8810  if is_bv(args[0]):
8811  return _reduce(lambda a, b: a * b, args, 1)
8812  else:
8813  _args, sz = _to_ast_array(args)
8814  return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
8815 
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:8791

◆ prove()

def z3py.prove (   claim,
  show = False,
**  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 8978 of file z3py.py.

8978 def prove(claim, show=False, **keywords):
8979  """Try to prove the given claim.
8980 
8981  This is a simple function for creating demonstrations. It tries to prove
8982  `claim` by showing the negation is unsatisfiable.
8983 
8984  >>> p, q = Bools('p q')
8985  >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
8986  proved
8987  """
8988  if z3_debug():
8989  _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
8990  s = Solver()
8991  s.set(**keywords)
8992  s.add(Not(claim))
8993  if show:
8994  print(s)
8995  r = s.check()
8996  if r == unsat:
8997  print("proved")
8998  elif r == unknown:
8999  print("failed to prove")
9000  print(s.model())
9001  else:
9002  print("counterexample")
9003  print(s.model())
9004 
9005 
def prove(claim, show=False, **keywords)
Definition: z3py.py:8978

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

3195 def Q(a, b, ctx=None):
3196  """Return a Z3 rational a/b.
3197 
3198  If `ctx=None`, then the global context is used.
3199 
3200  >>> Q(3,5)
3201  3/5
3202  >>> Q(3,5).sort()
3203  Real
3204  """
3205  return simplify(RatVal(a, b, ctx=ctx))
3206 
3207 
def simplify(a, *arguments, **keywords)
Utils.
Definition: z3py.py:8680
def Q(a, b, ctx=None)
Definition: z3py.py:3195
def RatVal(a, b, ctx=None)
Definition: z3py.py:3179

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

11146 def Range(lo, hi, ctx=None):
11147  """Create the range regular expression over two sequences of length 1
11148  >>> range = Range("a","z")
11149  >>> print(simplify(InRe("b", range)))
11150  True
11151  >>> print(simplify(InRe("bb", range)))
11152  False
11153  """
11154  lo = _coerce_seq(lo, ctx)
11155  hi = _coerce_seq(hi, ctx)
11156  return ReRef(Z3_mk_re_range(lo.ctx_ref(), lo.ast, hi.ast), lo.ctx)
11157 
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.
def Range(lo, hi, ctx=None)
Definition: z3py.py:11146

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

3179 def RatVal(a, b, ctx=None):
3180  """Return a Z3 rational a/b.
3181 
3182  If `ctx=None`, then the global context is used.
3183 
3184  >>> RatVal(3,5)
3185  3/5
3186  >>> RatVal(3,5).sort()
3187  Real
3188  """
3189  if z3_debug():
3190  _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
3191  _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
3192  return simplify(RealVal(a, ctx) / RealVal(b, ctx))
3193 
3194 

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

10998 def Re(s, ctx=None):
10999  """The regular expression that accepts sequence 's'
11000  >>> s1 = Re("ab")
11001  >>> s2 = Re(StringVal("ab"))
11002  >>> s3 = Re(Unit(BoolVal(True)))
11003  """
11004  s = _coerce_seq(s, ctx)
11005  return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
11006 
11007 
11008 # Regular expressions
11009 
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.
def Re(s, ctx=None)
Definition: z3py.py:10998

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

3261 def Real(name, ctx=None):
3262  """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3263 
3264  >>> x = Real('x')
3265  >>> is_real(x)
3266  True
3267  >>> is_real(x + 1)
3268  True
3269  """
3270  ctx = _get_ctx(ctx)
3271  return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
3272 
3273 
def Real(name, ctx=None)
Definition: z3py.py:3261

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

3274 def Reals(names, ctx=None):
3275  """Return a tuple of real constants.
3276 
3277  >>> x, y, z = Reals('x y z')
3278  >>> Sum(x, y, z)
3279  x + y + z
3280  >>> Sum(x, y, z).sort()
3281  Real
3282  """
3283  ctx = _get_ctx(ctx)
3284  if isinstance(names, str):
3285  names = names.split(" ")
3286  return [Real(name, ctx) for name in names]
3287 
3288 
def Reals(names, ctx=None)
Definition: z3py.py:3274

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

3115 def RealSort(ctx=None):
3116  """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3117 
3118  >>> RealSort()
3119  Real
3120  >>> x = Const('x', RealSort())
3121  >>> is_real(x)
3122  True
3123  >>> is_int(x)
3124  False
3125  >>> x.sort() == RealSort()
3126  True
3127  """
3128  ctx = _get_ctx(ctx)
3129  return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
3130 
3131 
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.

Referenced by FreshReal(), 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 3160 of file z3py.py.

3160 def RealVal(val, ctx=None):
3161  """Return a Z3 real value.
3162 
3163  `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3164  If `ctx=None`, then the global context is used.
3165 
3166  >>> RealVal(1)
3167  1
3168  >>> RealVal(1).sort()
3169  Real
3170  >>> RealVal("3/5")
3171  3/5
3172  >>> RealVal("1.5")
3173  3/2
3174  """
3175  ctx = _get_ctx(ctx)
3176  return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), RealSort(ctx).ast), ctx)
3177 
3178 

Referenced by Cbrt(), AlgebraicNumRef.index(), 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 1450 of file z3py.py.

1450 def RealVar(idx, ctx=None):
1451  """
1452  Create a real free variable. Free variables are used to create quantified formulas.
1453  They are also used to create polynomials.
1454 
1455  >>> RealVar(0)
1456  Var(0)
1457  """
1458  return Var(idx, RealSort(ctx))
1459 
1460 
def Var(idx, s)
Definition: z3py.py:1437
def RealVar(idx, ctx=None)
Definition: z3py.py:1450

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

1461 def RealVarVector(n, ctx=None):
1462  """
1463  Create a list of Real free variables.
1464  The variables have ids: 0, 1, ..., n-1
1465 
1466  >>> x0, x1, x2, x3 = RealVarVector(4)
1467  >>> x2
1468  Var(2)
1469  """
1470  return [RealVar(i, ctx) for i in range(n)]
1471 
def RealVarVector(n, ctx=None)
Definition: z3py.py:1461

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

3289 def RealVector(prefix, sz, ctx=None):
3290  """Return a list of real constants of size `sz`.
3291 
3292  >>> X = RealVector('x', 3)
3293  >>> X
3294  [x__0, x__1, x__2]
3295  >>> Sum(X)
3296  x__0 + x__1 + x__2
3297  >>> Sum(X).sort()
3298  Real
3299  """
3300  ctx = _get_ctx(ctx)
3301  return [Real("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3302 
3303 
def RealVector(prefix, sz, ctx=None)
Definition: z3py.py:3289

◆ RecAddDefinition()

def z3py.RecAddDefinition (   f,
  args,
  body 
)
Set the body of a recursive function.
   Recursive definitions can be simplified if they are applied to ground
   arguments.
>>> 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))
120
>>> s = Solver(ctx=ctx)
>>> s.add(fac(n) < 3)
>>> s.check()
sat
>>> s.model().eval(fac(5))
120

Definition at line 921 of file z3py.py.

921 def RecAddDefinition(f, args, body):
922  """Set the body of a recursive function.
923  Recursive definitions can be simplified if they are applied to ground
924  arguments.
925  >>> ctx = Context()
926  >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
927  >>> n = Int('n', ctx)
928  >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
929  >>> simplify(fac(5))
930  120
931  >>> s = Solver(ctx=ctx)
932  >>> s.add(fac(n) < 3)
933  >>> s.check()
934  sat
935  >>> s.model().eval(fac(5))
936  120
937  """
938  if is_app(args):
939  args = [args]
940  ctx = body.ctx
941  args = _get_args(args)
942  n = len(args)
943  _args = (Ast * n)()
944  for i in range(n):
945  _args[i] = args[i].ast
946  Z3_add_rec_def(ctx.ref(), f.ast, n, _args, body.ast)
947 
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.
def RecAddDefinition(f, args, body)
Definition: z3py.py:921

◆ RecFunction()

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

Definition at line 903 of file z3py.py.

903 def RecFunction(name, *sig):
904  """Create a new Z3 recursive with the given sorts."""
905  sig = _get_args(sig)
906  if z3_debug():
907  _z3_assert(len(sig) > 0, "At least two arguments expected")
908  arity = len(sig) - 1
909  rng = sig[arity]
910  if z3_debug():
911  _z3_assert(is_sort(rng), "Z3 sort expected")
912  dom = (Sort * arity)()
913  for i in range(arity):
914  if z3_debug():
915  _z3_assert(is_sort(sig[i]), "Z3 sort expected")
916  dom[i] = sig[i].ast
917  ctx = rng.ctx
918  return FuncDeclRef(Z3_mk_rec_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
919 
920 
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.
def RecFunction(name, *sig)
Definition: z3py.py:903

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

8328 def Repeat(t, max=4294967295, ctx=None):
8329  """Return a tactic that keeps applying `t` until the goal is not modified anymore
8330  or the maximum number of iterations `max` is reached.
8331 
8332  >>> x, y = Ints('x y')
8333  >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
8334  >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
8335  >>> r = t(c)
8336  >>> for subgoal in r: print(subgoal)
8337  [x == 0, y == 0, x > y]
8338  [x == 0, y == 1, x > y]
8339  [x == 1, y == 0, x > y]
8340  [x == 1, y == 1, x > y]
8341  >>> t = Then(t, Tactic('propagate-values'))
8342  >>> t(c)
8343  [[x == 1, y == 0]]
8344  """
8345  t = _to_tactic(t, ctx)
8346  return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
8347 
8348 
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:8328

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

4381 def RepeatBitVec(n, a):
4382  """Return an expression representing `n` copies of `a`.
4383 
4384  >>> x = BitVec('x', 8)
4385  >>> n = RepeatBitVec(4, x)
4386  >>> n
4387  RepeatBitVec(4, x)
4388  >>> n.size()
4389  32
4390  >>> v0 = BitVecVal(10, 4)
4391  >>> print("%.x" % v0.as_long())
4392  a
4393  >>> v = simplify(RepeatBitVec(4, v0))
4394  >>> v.size()
4395  16
4396  >>> print("%.x" % v.as_long())
4397  aaaa
4398  """
4399  if z3_debug():
4400  _z3_assert(_is_int(n), "First argument must be an integer")
4401  _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4402  return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
4403 
4404 
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
def RepeatBitVec(n, a)
Definition: z3py.py:4381

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

10909 def Replace(s, src, dst):
10910  """Replace the first occurrence of 'src' by 'dst' in 's'
10911  >>> r = Replace("aaa", "a", "b")
10912  >>> simplify(r)
10913  "baa"
10914  """
10915  ctx = _get_ctx2(dst, s)
10916  if ctx is None and is_expr(src):
10917  ctx = src.ctx
10918  src = _coerce_seq(src, ctx)
10919  dst = _coerce_seq(dst, ctx)
10920  s = _coerce_seq(s, ctx)
10921  return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
10922 
10923 
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:10909

◆ reset_params()

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

Definition at line 289 of file z3py.py.

289 def reset_params():
290  """Reset all global (or module) parameters.
291  """
293 
294 
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...
def reset_params()
Definition: z3py.py:289

◆ ReSort()

def z3py.ReSort (   s)

Definition at line 11017 of file z3py.py.

11017 def ReSort(s):
11018  if is_ast(s):
11019  return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
11020  if s is None or isinstance(s, Context):
11021  ctx = _get_ctx(s)
11022  return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
11023  raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
11024 
11025 
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort seq)
Create a regular expression sort out of a sequence sort.
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for unicode strings.
def ReSort(s)
Definition: z3py.py:11017

◆ RNA()

def z3py.RNA (   ctx = None)

Definition at line 9546 of file z3py.py.

9546 def RNA(ctx=None):
9547  ctx = _get_ctx(ctx)
9548  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
9549 
9550 
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 9536 of file z3py.py.

9536 def RNE(ctx=None):
9537  ctx = _get_ctx(ctx)
9538  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
9539 
9540 
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.

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

4291 def RotateLeft(a, b):
4292  """Return an expression representing `a` rotated to the left `b` times.
4293 
4294  >>> a, b = BitVecs('a b', 16)
4295  >>> RotateLeft(a, b)
4296  RotateLeft(a, b)
4297  >>> simplify(RotateLeft(a, 0))
4298  a
4299  >>> simplify(RotateLeft(a, 16))
4300  a
4301  """
4302  _check_bv_args(a, b)
4303  a, b = _coerce_exprs(a, b)
4304  return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4305 
4306 
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.
def RotateLeft(a, b)
Definition: z3py.py:4291

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

4307 def RotateRight(a, b):
4308  """Return an expression representing `a` rotated to the right `b` times.
4309 
4310  >>> a, b = BitVecs('a b', 16)
4311  >>> RotateRight(a, b)
4312  RotateRight(a, b)
4313  >>> simplify(RotateRight(a, 0))
4314  a
4315  >>> simplify(RotateRight(a, 16))
4316  a
4317  """
4318  _check_bv_args(a, b)
4319  a, b = _coerce_exprs(a, b)
4320  return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4321 
4322 
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:4307

◆ RoundNearestTiesToAway()

def z3py.RoundNearestTiesToAway (   ctx = None)

Definition at line 9541 of file z3py.py.

9541 def RoundNearestTiesToAway(ctx=None):
9542  ctx = _get_ctx(ctx)
9543  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
9544 
9545 
def RoundNearestTiesToAway(ctx=None)
Definition: z3py.py:9541

◆ RoundNearestTiesToEven()

def z3py.RoundNearestTiesToEven (   ctx = None)

Definition at line 9531 of file z3py.py.

9531 def RoundNearestTiesToEven(ctx=None):
9532  ctx = _get_ctx(ctx)
9533  return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
9534 
9535 
def RoundNearestTiesToEven(ctx=None)
Definition: z3py.py:9531

◆ RoundTowardNegative()

def z3py.RoundTowardNegative (   ctx = None)

Definition at line 9561 of file z3py.py.

9561 def RoundTowardNegative(ctx=None):
9562  ctx = _get_ctx(ctx)
9563  return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
9564 
9565 
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.
def RoundTowardNegative(ctx=None)
Definition: z3py.py:9561

◆ RoundTowardPositive()

def z3py.RoundTowardPositive (   ctx = None)

Definition at line 9551 of file z3py.py.

9551 def RoundTowardPositive(ctx=None):
9552  ctx = _get_ctx(ctx)
9553  return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
9554 
9555 
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.
def RoundTowardPositive(ctx=None)
Definition: z3py.py:9551

◆ RoundTowardZero()

def z3py.RoundTowardZero (   ctx = None)

Definition at line 9571 of file z3py.py.

9571 def RoundTowardZero(ctx=None):
9572  ctx = _get_ctx(ctx)
9573  return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
9574 
9575 
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:9571

◆ RTN()

def z3py.RTN (   ctx = None)

Definition at line 9566 of file z3py.py.

9566 def RTN(ctx=None):
9567  ctx = _get_ctx(ctx)
9568  return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
9569 
9570 

Referenced by get_default_rounding_mode().

◆ RTP()

def z3py.RTP (   ctx = None)

Definition at line 9556 of file z3py.py.

9556 def RTP(ctx=None):
9557  ctx = _get_ctx(ctx)
9558  return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
9559 
9560 

Referenced by get_default_rounding_mode().

◆ RTZ()

def z3py.RTZ (   ctx = None)

Definition at line 9576 of file z3py.py.

9576 def RTZ(ctx=None):
9577  ctx = _get_ctx(ctx)
9578  return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
9579 
9580 

Referenced by get_default_rounding_mode().

◆ Select()

def z3py.Select (   a,
args 
)
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 4767 of file z3py.py.

4767 def Select(a, *args):
4768  """Return a Z3 select array expression.
4769 
4770  >>> a = Array('a', IntSort(), IntSort())
4771  >>> i = Int('i')
4772  >>> Select(a, i)
4773  a[i]
4774  >>> eq(Select(a, i), a[i])
4775  True
4776  """
4777  args = _get_args(args)
4778  if z3_debug():
4779  _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4780  return a[args]
4781 
4782 
def Select(a, *args)
Definition: z3py.py:4767

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

10630 def SeqSort(s):
10631  """Create a sequence sort over elements provided in the argument
10632  >>> s = SeqSort(IntSort())
10633  >>> s == Unit(IntVal(1)).sort()
10634  True
10635  """
10636  return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
10637 
10638 
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.
def SeqSort(s)
Definition: z3py.py:10630

◆ set_default_fp_sort()

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

Definition at line 9192 of file z3py.py.

9192 def set_default_fp_sort(ebits, sbits, ctx=None):
9193  global _dflt_fpsort_ebits
9194  global _dflt_fpsort_sbits
9195  _dflt_fpsort_ebits = ebits
9196  _dflt_fpsort_sbits = sbits
9197 
9198 
def set_default_fp_sort(ebits, sbits, ctx=None)
Definition: z3py.py:9192

◆ set_default_rounding_mode()

def z3py.set_default_rounding_mode (   rm,
  ctx = None 
)

Definition at line 9179 of file z3py.py.

9179 def set_default_rounding_mode(rm, ctx=None):
9180  global _dflt_rounding_mode
9181  if is_fprm_value(rm):
9182  _dflt_rounding_mode = rm.decl().kind()
9183  else:
9184  _z3_assert(_dflt_rounding_mode in _ROUNDING_MODES, "illegal rounding mode")
9185  _dflt_rounding_mode = rm
9186 
9187 
def set_default_rounding_mode(rm, ctx=None)
Definition: z3py.py:9179

◆ set_option()

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

Definition at line 295 of file z3py.py.

295 def set_option(*args, **kws):
296  """Alias for 'set_param' for backward compatibility.
297  """
298  return set_param(*args, **kws)
299 
300 
def set_option(*args, **kws)
Definition: z3py.py:295
def set_param(*args, **kws)
Definition: z3py.py:265

◆ set_param()

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

>>> set_param(precision=10)

Definition at line 265 of file z3py.py.

265 def set_param(*args, **kws):
266  """Set Z3 global (or module) parameters.
267 
268  >>> set_param(precision=10)
269  """
270  if z3_debug():
271  _z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
272  new_kws = {}
273  for k in kws:
274  v = kws[k]
275  if not set_pp_option(k, v):
276  new_kws[k] = v
277  for key in new_kws:
278  value = new_kws[key]
279  Z3_global_param_set(str(key).upper(), _to_param_value(value))
280  prev = None
281  for a in args:
282  if prev is None:
283  prev = a
284  else:
285  Z3_global_param_set(str(prev), _to_param_value(a))
286  prev = None
287 
288 
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.

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

4926 def SetAdd(s, e):
4927  """ Add element e to set s
4928  >>> a = Const('a', SetSort(IntSort()))
4929  >>> SetAdd(a, 1)
4930  Store(a, 1, True)
4931  """
4932  ctx = _ctx_from_ast_arg_list([s, e])
4933  e = _py2expr(e, ctx)
4934  return ArrayRef(Z3_mk_set_add(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
4935 
4936 
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:4926

◆ SetComplement()

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

Definition at line 4948 of file z3py.py.

4948 def SetComplement(s):
4949  """ The complement of set s
4950  >>> a = Const('a', SetSort(IntSort()))
4951  >>> SetComplement(a)
4952  complement(a)
4953  """
4954  ctx = s.ctx
4955  return ArrayRef(Z3_mk_set_complement(ctx.ref(), s.as_ast()), ctx)
4956 
4957 
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:4948

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

4937 def SetDel(s, e):
4938  """ Remove element e to set s
4939  >>> a = Const('a', SetSort(IntSort()))
4940  >>> SetDel(a, 1)
4941  Store(a, 1, False)
4942  """
4943  ctx = _ctx_from_ast_arg_list([s, e])
4944  e = _py2expr(e, ctx)
4945  return ArrayRef(Z3_mk_set_del(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
4946 
4947 
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:4937

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

4958 def SetDifference(a, b):
4959  """ The set difference of a and b
4960  >>> a = Const('a', SetSort(IntSort()))
4961  >>> b = Const('b', SetSort(IntSort()))
4962  >>> SetDifference(a, b)
4963  setminus(a, b)
4964  """
4965  ctx = _ctx_from_ast_arg_list([a, b])
4966  return ArrayRef(Z3_mk_set_difference(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4967 
4968 
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.
def SetDifference(a, b)
Definition: z3py.py:4958

◆ SetHasSize()

def z3py.SetHasSize (   a,
  k 
)

Definition at line 4840 of file z3py.py.

4840 def SetHasSize(a, k):
4841  ctx = a.ctx
4842  k = _py2expr(k, ctx)
4843  return _to_expr_ref(Z3_mk_set_has_size(ctx.ref(), a.as_ast(), k.as_ast()), ctx)
4844 
4845 
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.
def SetHasSize(a, k)
Definition: z3py.py:4840

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

4913 def SetIntersect(*args):
4914  """ Take the union of sets
4915  >>> a = Const('a', SetSort(IntSort()))
4916  >>> b = Const('b', SetSort(IntSort()))
4917  >>> SetIntersect(a, b)
4918  intersection(a, b)
4919  """
4920  args = _get_args(args)
4921  ctx = _ctx_from_ast_arg_list(args)
4922  _args, sz = _to_ast_array(args)
4923  return ArrayRef(Z3_mk_set_intersect(ctx.ref(), sz, _args), ctx)
4924 
4925 
Z3_ast Z3_API Z3_mk_set_intersect(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the intersection of a list of sets.
def SetIntersect(*args)
Definition: z3py.py:4913

◆ SetSort()

def z3py.SetSort (   s)

Sets.

 Create a set sort over element sort s

Definition at line 4877 of file z3py.py.

4877 def SetSort(s):
4878  """ Create a set sort over element sort s"""
4879  return ArraySort(s, BoolSort())
4880 
4881 
def SetSort(s)
Sets.
Definition: z3py.py:4877

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

4900 def SetUnion(*args):
4901  """ Take the union of sets
4902  >>> a = Const('a', SetSort(IntSort()))
4903  >>> b = Const('b', SetSort(IntSort()))
4904  >>> SetUnion(a, b)
4905  union(a, b)
4906  """
4907  args = _get_args(args)
4908  ctx = _ctx_from_ast_arg_list(args)
4909  _args, sz = _to_ast_array(args)
4910  return ArrayRef(Z3_mk_set_union(ctx.ref(), sz, _args), ctx)
4911 
4912 
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:4900

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

4323 def SignExt(n, a):
4324  """Return a bit-vector expression with `n` extra sign-bits.
4325 
4326  >>> x = BitVec('x', 16)
4327  >>> n = SignExt(8, x)
4328  >>> n.size()
4329  24
4330  >>> n
4331  SignExt(8, x)
4332  >>> n.sort()
4333  BitVec(24)
4334  >>> v0 = BitVecVal(2, 2)
4335  >>> v0
4336  2
4337  >>> v0.size()
4338  2
4339  >>> v = simplify(SignExt(6, v0))
4340  >>> v
4341  254
4342  >>> v.size()
4343  8
4344  >>> print("%.x" % v.as_long())
4345  fe
4346  """
4347  if z3_debug():
4348  _z3_assert(_is_int(n), "First argument must be an integer")
4349  _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4350  return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4351 
4352 
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 SignExt(n, a)
Definition: z3py.py:4323

◆ SimpleSolver()

def z3py.SimpleSolver (   ctx = None,
  logFile = 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 7328 of file z3py.py.

7328 def SimpleSolver(ctx=None, logFile=None):
7329  """Return a simple general purpose solver with limited amount of preprocessing.
7330 
7331  >>> s = SimpleSolver()
7332  >>> x = Int('x')
7333  >>> s.add(x > 0)
7334  >>> s.check()
7335  sat
7336  """
7337  ctx = _get_ctx(ctx)
7338  return Solver(Z3_mk_simple_solver(ctx.ref()), ctx, logFile)
7339 
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
def SimpleSolver(ctx=None, logFile=None)
Definition: z3py.py:7328

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

8680 def simplify(a, *arguments, **keywords):
8681  """Simplify the expression `a` using the given options.
8682 
8683  This function has many options. Use `help_simplify` to obtain the complete list.
8684 
8685  >>> x = Int('x')
8686  >>> y = Int('y')
8687  >>> simplify(x + 1 + y + x + 1)
8688  2 + 2*x + y
8689  >>> simplify((x + 1)*(y + 1), som=True)
8690  1 + x + y + x*y
8691  >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8692  And(Not(x == y), Not(x == 1), Not(y == 1))
8693  >>> simplify(And(x == 0, y == 1), elim_and=True)
8694  Not(Or(Not(x == 0), Not(y == 1)))
8695  """
8696  if z3_debug():
8697  _z3_assert(is_expr(a), "Z3 expression expected")
8698  if len(arguments) > 0 or len(keywords) > 0:
8699  p = args2params(arguments, keywords, a.ctx)
8700  return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8701  else:
8702  return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8703 
8704 
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.

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

8710 def simplify_param_descrs():
8711  """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8712  return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
8713 
8714 
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:8710

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

8917 def solve(*args, **keywords):
8918  """Solve the constraints `*args`.
8919 
8920  This is a simple function for creating demonstrations. It creates a solver,
8921  configure it using the options in `keywords`, adds the constraints
8922  in `args`, and invokes check.
8923 
8924  >>> a = Int('a')
8925  >>> solve(a > 0, a < 2)
8926  [a = 1]
8927  """
8928  show = keywords.pop("show", False)
8929  s = Solver()
8930  s.set(**keywords)
8931  s.add(*args)
8932  if show:
8933  print(s)
8934  r = s.check()
8935  if r == unsat:
8936  print("no solution")
8937  elif r == unknown:
8938  print("failed to solve")
8939  try:
8940  print(s.model())
8941  except Z3Exception:
8942  return
8943  else:
8944  print(s.model())
8945 
8946 
def solve(*args, **keywords)
Definition: z3py.py:8917

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

8947 def solve_using(s, *args, **keywords):
8948  """Solve the constraints `*args` using solver `s`.
8949 
8950  This is a simple function for creating demonstrations. It is similar to `solve`,
8951  but it uses the given solver `s`.
8952  It configures solver `s` using the options in `keywords`, adds the constraints
8953  in `args`, and invokes check.
8954  """
8955  show = keywords.pop("show", False)
8956  if z3_debug():
8957  _z3_assert(isinstance(s, Solver), "Solver object expected")
8958  s.set(**keywords)
8959  s.add(*args)
8960  if show:
8961  print("Problem:")
8962  print(s)
8963  r = s.check()
8964  if r == unsat:
8965  print("no solution")
8966  elif r == unknown:
8967  print("failed to solve")
8968  try:
8969  print(s.model())
8970  except Z3Exception:
8971  return
8972  else:
8973  if show:
8974  print("Solution:")
8975  print(s.model())
8976 
8977 
def solve_using(s, *args, **keywords)
Definition: z3py.py:8947

◆ SolverFor()

def z3py.SolverFor (   logic,
  ctx = None,
  logFile = 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 7307 of file z3py.py.

7307 def SolverFor(logic, ctx=None, logFile=None):
7308  """Create a solver customized for the given logic.
7309 
7310  The parameter `logic` is a string. It should be contains
7311  the name of a SMT-LIB logic.
7312  See http://www.smtlib.org/ for the name of all available logics.
7313 
7314  >>> s = SolverFor("QF_LIA")
7315  >>> x = Int('x')
7316  >>> s.add(x > 0)
7317  >>> s.add(x < 2)
7318  >>> s.check()
7319  sat
7320  >>> s.model()
7321  [x = 1]
7322  """
7323  ctx = _get_ctx(ctx)
7324  logic = to_symbol(logic)
7325  return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx, logFile)
7326 
7327 
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, logFile=None)
Definition: z3py.py:7307

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

3371 def Sqrt(a, ctx=None):
3372  """ Return a Z3 expression which represents the square root of a.
3373 
3374  >>> x = Real('x')
3375  >>> Sqrt(x)
3376  x**(1/2)
3377  """
3378  if not is_expr(a):
3379  ctx = _get_ctx(ctx)
3380  a = RealVal(a, ctx)
3381  return a ** "1/2"
3382 
3383 
def Sqrt(a, ctx=None)
Definition: z3py.py:3371

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

4238 def SRem(a, b):
4239  """Create the Z3 expression signed remainder.
4240 
4241  Use the operator % for signed modulus, and URem() for unsigned remainder.
4242 
4243  >>> x = BitVec('x', 32)
4244  >>> y = BitVec('y', 32)
4245  >>> SRem(x, y)
4246  SRem(x, y)
4247  >>> SRem(x, y).sort()
4248  BitVec(32)
4249  >>> (x % y).sexpr()
4250  '(bvsmod x y)'
4251  >>> SRem(x, y).sexpr()
4252  '(bvsrem x y)'
4253  """
4254  _check_bv_args(a, b)
4255  a, b = _coerce_exprs(a, b)
4256  return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4257 
4258 
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:4238

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

11120 def Star(re):
11121  """Create the regular expression accepting zero or more repetitions of argument.
11122  >>> re = Star(Re("a"))
11123  >>> print(simplify(InRe("aa", re)))
11124  True
11125  >>> print(simplify(InRe("ab", re)))
11126  False
11127  >>> print(simplify(InRe("", re)))
11128  True
11129  """
11130  return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
11131 
11132 
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.
def Star(re)
Definition: z3py.py:11120

◆ Store()

def z3py.Store (   a,
args 
)
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 4750 of file z3py.py.

4750 def Store(a, *args):
4751  """Return a Z3 store array expression.
4752 
4753  >>> a = Array('a', IntSort(), IntSort())
4754  >>> i, v = Ints('i v')
4755  >>> s = Store(a, i, v)
4756  >>> s.sort()
4757  Array(Int, Int)
4758  >>> prove(s[i] == v)
4759  proved
4760  >>> j = Int('j')
4761  >>> prove(Implies(i != j, s[j] == a[j]))
4762  proved
4763  """
4764  return Update(a, args)
4765 
4766 
def Update(a, *args)
Definition: z3py.py:4707
def Store(a, *args)
Definition: z3py.py:4750

◆ StrFromCode()

def z3py.StrFromCode (   c)
Convert code to a string

Definition at line 10992 of file z3py.py.

10992 def StrFromCode(c):
10993  """Convert code to a string"""
10994  if not is_expr(c):
10995  c = _py2expr(c)
10996  return SeqRef(Z3_mk_string_from_code(c.ctx_ref(), c.as_ast()), c.ctx)
10997 
Z3_ast Z3_API Z3_mk_string_from_code(Z3_context c, Z3_ast a)
Code to string conversion.
def StrFromCode(c)
Definition: z3py.py:10992

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

10793 def String(name, ctx=None):
10794  """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10795 
10796  >>> x = String('x')
10797  """
10798  ctx = _get_ctx(ctx)
10799  return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
10800 
10801 
def StringSort(ctx=None)
Definition: z3py.py:10611
def String(name, ctx=None)
Definition: z3py.py:10793

Referenced by Strings().

◆ Strings()

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

Definition at line 10802 of file z3py.py.

10802 def Strings(names, ctx=None):
10803  """Return a tuple of String constants. """
10804  ctx = _get_ctx(ctx)
10805  if isinstance(names, str):
10806  names = names.split(" ")
10807  return [String(name, ctx) for name in names]
10808 
10809 
def Strings(names, ctx=None)
Definition: z3py.py:10802

◆ StringSort()

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

Definition at line 10611 of file z3py.py.

10611 def StringSort(ctx=None):
10612  """Create a string sort
10613  >>> s = StringSort()
10614  >>> print(s)
10615  String
10616  """
10617  ctx = _get_ctx(ctx)
10618  return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
10619 

Referenced by String().

◆ StringVal()

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

Definition at line 10786 of file z3py.py.

10786 def StringVal(s, ctx=None):
10787  """create a string expression"""
10788  s = "".join(str(ch) if 32 <= ord(ch) and ord(ch) < 127 else "\\u{%x}" % (ord(ch)) for ch in s)
10789  ctx = _get_ctx(ctx)
10790  return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
10791 
10792 
Z3_ast Z3_API Z3_mk_string(Z3_context c, Z3_string s)
Create a string constant out of the string that is passed in The string may contain escape encoding f...

Referenced by CharIsDigit(), ExprRef.children(), Extract(), and AlgebraicNumRef.index().

◆ StrToCode()

def z3py.StrToCode (   s)
Convert a unit length string to integer code

Definition at line 10986 of file z3py.py.

10986 def StrToCode(s):
10987  """Convert a unit length string to integer code"""
10988  if not is_expr(s):
10989  s = _py2expr(s)
10990  return ArithRef(Z3_mk_string_to_code(s.ctx_ref(), s.as_ast()), s.ctx)
10991 
Z3_ast Z3_API Z3_mk_string_to_code(Z3_context c, Z3_ast a)
String to code conversion.
def StrToCode(s)
Definition: z3py.py:10986

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

10963 def StrToInt(s):
10964  """Convert string expression to integer
10965  >>> a = StrToInt("1")
10966  >>> simplify(1 == a)
10967  True
10968  >>> b = StrToInt("2")
10969  >>> simplify(1 == b)
10970  False
10971  >>> c = StrToInt(IntToStr(2))
10972  >>> simplify(1 == c)
10973  False
10974  """
10975  s = _coerce_seq(s)
10976  return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
10977 
10978 
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:10963

◆ SubSeq()

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

Definition at line 10815 of file z3py.py.

10815 def SubSeq(s, offset, length):
10816  """Extract substring or subsequence starting at offset"""
10817  return Extract(s, offset, length)
10818 
10819 
def SubSeq(s, offset, length)
Definition: z3py.py:10815

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

8715 def substitute(t, *m):
8716  """Apply substitution m on t, m is a list of pairs of the form (from, to).
8717  Every occurrence in t of from is replaced with to.
8718 
8719  >>> x = Int('x')
8720  >>> y = Int('y')
8721  >>> substitute(x + 1, (x, y + 1))
8722  y + 1 + 1
8723  >>> f = Function('f', IntSort(), IntSort())
8724  >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8725  1 + 1
8726  """
8727  if isinstance(m, tuple):
8728  m1 = _get_args(m)
8729  if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
8730  m = m1
8731  if z3_debug():
8732  _z3_assert(is_expr(t), "Z3 expression expected")
8733  _z3_assert(all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) and p[0].sort().eq(
8734  p[1].sort()) for p in m]), "Z3 invalid substitution, expression pairs expected.")
8735  num = len(m)
8736  _from = (Ast * num)()
8737  _to = (Ast * num)()
8738  for i in range(num):
8739  _from[i] = m[i][0].as_ast()
8740  _to[i] = m[i][1].as_ast()
8741  return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8742 
8743 
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:8715

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

8744 def substitute_vars(t, *m):
8745  """Substitute the free variables in t with the expression in m.
8746 
8747  >>> v0 = Var(0, IntSort())
8748  >>> v1 = Var(1, IntSort())
8749  >>> x = Int('x')
8750  >>> f = Function('f', IntSort(), IntSort(), IntSort())
8751  >>> # replace v0 with x+1 and v1 with x
8752  >>> substitute_vars(f(v0, v1), x + 1, x)
8753  f(x + 1, x)
8754  """
8755  if z3_debug():
8756  _z3_assert(is_expr(t), "Z3 expression expected")
8757  _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
8758  num = len(m)
8759  _to = (Ast * num)()
8760  for i in range(num):
8761  _to[i] = m[i].as_ast()
8762  return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
8763 
8764 
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:8744

◆ SubString()

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

Definition at line 10810 of file z3py.py.

10810 def SubString(s, offset, length):
10811  """Extract substring or subsequence starting at offset"""
10812  return Extract(s, offset, length)
10813 
10814 
def SubString(s, offset, length)
Definition: z3py.py:10810

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

10875 def SuffixOf(a, b):
10876  """Check if 'a' is a suffix of 'b'
10877  >>> s1 = SuffixOf("ab", "abc")
10878  >>> simplify(s1)
10879  False
10880  >>> s2 = SuffixOf("bc", "abc")
10881  >>> simplify(s2)
10882  True
10883  """
10884  ctx = _get_ctx2(a, b)
10885  a = _coerce_seq(a, ctx)
10886  b = _coerce_seq(b, ctx)
10887  return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
10888 
10889 
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:10875

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

8765 def Sum(*args):
8766  """Create the sum of the Z3 expressions.
8767 
8768  >>> a, b, c = Ints('a b c')
8769  >>> Sum(a, b, c)
8770  a + b + c
8771  >>> Sum([a, b, c])
8772  a + b + c
8773  >>> A = IntVector('a', 5)
8774  >>> Sum(A)
8775  a__0 + a__1 + a__2 + a__3 + a__4
8776  """
8777  args = _get_args(args)
8778  if len(args) == 0:
8779  return 0
8780  ctx = _ctx_from_ast_arg_list(args)
8781  if ctx is None:
8782  return _reduce(lambda a, b: a + b, args, 0)
8783  args = _coerce_expr_list(args, ctx)
8784  if is_bv(args[0]):
8785  return _reduce(lambda a, b: a + b, args, 0)
8786  else:
8787  _args, sz = _to_ast_array(args)
8788  return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
8789 
8790 
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:8765

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

8369 def tactic_description(name, ctx=None):
8370  """Return a short description for the tactic named `name`.
8371 
8372  >>> d = tactic_description('simplify')
8373  """
8374  ctx = _get_ctx(ctx)
8375  return Z3_tactic_get_descr(ctx.ref(), name)
8376 
8377 
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 8358 of file z3py.py.

8358 def tactics(ctx=None):
8359  """Return a list of all available tactics in Z3.
8360 
8361  >>> l = tactics()
8362  >>> l.count('simplify') == 1
8363  True
8364  """
8365  ctx = _get_ctx(ctx)
8366  return [Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref()))]
8367 
8368 
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.
Z3_string Z3_API Z3_get_tactic_name(Z3_context c, unsigned i)
Return the name of the idx tactic.

Referenced by describe_tactics().

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

8226 def Then(*ts, **ks):
8227  """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8228 
8229  >>> x, y = Ints('x y')
8230  >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
8231  >>> t(And(x == 0, y > x + 1))
8232  [[Not(y <= 1)]]
8233  >>> t(And(x == 0, y > x + 1)).as_expr()
8234  Not(y <= 1)
8235  """
8236  return AndThen(*ts, **ks)
8237 
8238 
def Then(*ts, **ks)
Definition: z3py.py:8226

◆ to_Ast()

def z3py.to_Ast (   ptr)

Definition at line 11255 of file z3py.py.

11255 def to_Ast(ptr,):
11256  ast = Ast(ptr)
11257  super(ctypes.c_void_p, ast).__init__(ptr)
11258  return ast
11259 
def to_Ast(ptr)
Definition: z3py.py:11255

Referenced by user_prop_diseq(), user_prop_eq(), and user_prop_fixed().

◆ to_symbol()

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

Definition at line 124 of file z3py.py.

124 def to_symbol(s, ctx=None):
125  """Convert an integer or string into a Z3 symbol."""
126  if _is_int(s):
127  return Z3_mk_int_symbol(_get_ctx(ctx).ref(), s)
128  else:
129  return Z3_mk_string_symbol(_get_ctx(ctx).ref(), s)
130 
131 
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
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 3336 of file z3py.py.

3336 def ToInt(a):
3337  """ Return the Z3 expression ToInt(a).
3338 
3339  >>> x = Real('x')
3340  >>> x.sort()
3341  Real
3342  >>> n = ToInt(x)
3343  >>> n
3344  ToInt(x)
3345  >>> n.sort()
3346  Int
3347  """
3348  if z3_debug():
3349  _z3_assert(a.is_real(), "Z3 real expression expected.")
3350  ctx = a.ctx
3351  return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
3352 
3353 
Z3_ast Z3_API Z3_mk_real2int(Z3_context c, Z3_ast t1)
Coerce a real to an integer.
def ToInt(a)
Definition: z3py.py:3336

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

3318 def ToReal(a):
3319  """ Return the Z3 expression ToReal(a).
3320 
3321  >>> x = Int('x')
3322  >>> x.sort()
3323  Int
3324  >>> n = ToReal(x)
3325  >>> n
3326  ToReal(x)
3327  >>> n.sort()
3328  Real
3329  """
3330  if z3_debug():
3331  _z3_assert(a.is_int(), "Z3 integer expression expected.")
3332  ctx = a.ctx
3333  return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
3334 
3335 
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:3318

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

11187 def TransitiveClosure(f):
11188  """Given a binary relation R, such that the two arguments have the same sort
11189  create the transitive closure relation R+.
11190  The transitive closure R+ is a new relation.
11191  """
11192  return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
11193 
11194 
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.
def TransitiveClosure(f)
Definition: z3py.py:11187

◆ TreeOrder()

def z3py.TreeOrder (   a,
  index 
)

Definition at line 11179 of file z3py.py.

11179 def TreeOrder(a, index):
11180  return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx)
11181 
11182 
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.
def TreeOrder(a, index)
Definition: z3py.py:11179

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

8349 def TryFor(t, ms, ctx=None):
8350  """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8351 
8352  If `t` does not terminate in `ms` milliseconds, then it fails.
8353  """
8354  t = _to_tactic(t, ctx)
8355  return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
8356 
8357 
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:8349

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

5319 def TupleSort(name, sorts, ctx=None):
5320  """Create a named tuple sort base on a set of underlying sorts
5321  Example:
5322  >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5323  """
5324  tuple = Datatype(name, ctx)
5325  projects = [("project%d" % i, sorts[i]) for i in range(len(sorts))]
5326  tuple.declare(name, *projects)
5327  tuple = tuple.create()
5328  return tuple, tuple.constructor(0), [tuple.accessor(0, i) for i in range(len(sorts))]
5329 
5330 
def TupleSort(name, sorts, ctx=None)
Definition: z3py.py:5319

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

4196 def UDiv(a, b):
4197  """Create the Z3 expression (unsigned) division `self / other`.
4198 
4199  Use the operator / for signed division.
4200 
4201  >>> x = BitVec('x', 32)
4202  >>> y = BitVec('y', 32)
4203  >>> UDiv(x, y)
4204  UDiv(x, y)
4205  >>> UDiv(x, y).sort()
4206  BitVec(32)
4207  >>> (x / y).sexpr()
4208  '(bvsdiv x y)'
4209  >>> UDiv(x, y).sexpr()
4210  '(bvudiv x y)'
4211  """
4212  _check_bv_args(a, b)
4213  a, b = _coerce_exprs(a, b)
4214  return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4215 
4216 
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:4196

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

4160 def UGE(a, b):
4161  """Create the Z3 expression (unsigned) `other >= self`.
4162 
4163  Use the operator >= for signed greater than or equal to.
4164 
4165  >>> x, y = BitVecs('x y', 32)
4166  >>> UGE(x, y)
4167  UGE(x, y)
4168  >>> (x >= y).sexpr()
4169  '(bvsge x y)'
4170  >>> UGE(x, y).sexpr()
4171  '(bvuge x y)'
4172  """
4173  _check_bv_args(a, b)
4174  a, b = _coerce_exprs(a, b)
4175  return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4176 
4177 
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:4160

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

4178 def UGT(a, b):
4179  """Create the Z3 expression (unsigned) `other > self`.
4180 
4181  Use the operator > for signed greater than.
4182 
4183  >>> x, y = BitVecs('x y', 32)
4184  >>> UGT(x, y)
4185  UGT(x, y)
4186  >>> (x > y).sexpr()
4187  '(bvsgt x y)'
4188  >>> UGT(x, y).sexpr()
4189  '(bvugt x y)'
4190  """
4191  _check_bv_args(a, b)
4192  a, b = _coerce_exprs(a, b)
4193  return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4194 
4195 
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:4178

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

4124 def ULE(a, b):
4125  """Create the Z3 expression (unsigned) `other <= self`.
4126 
4127  Use the operator <= for signed less than or equal to.
4128 
4129  >>> x, y = BitVecs('x y', 32)
4130  >>> ULE(x, y)
4131  ULE(x, y)
4132  >>> (x <= y).sexpr()
4133  '(bvsle x y)'
4134  >>> ULE(x, y).sexpr()
4135  '(bvule x y)'
4136  """
4137  _check_bv_args(a, b)
4138  a, b = _coerce_exprs(a, b)
4139  return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4140 
4141 
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:4124

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

4142 def ULT(a, b):
4143  """Create the Z3 expression (unsigned) `other < self`.
4144 
4145  Use the operator < for signed less than.
4146 
4147  >>> x, y = BitVecs('x y', 32)
4148  >>> ULT(x, y)
4149  ULT(x, y)
4150  >>> (x < y).sexpr()
4151  '(bvslt x y)'
4152  >>> ULT(x, y).sexpr()
4153  '(bvult x y)'
4154  """
4155  _check_bv_args(a, b)
4156  a, b = _coerce_exprs(a, b)
4157  return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4158 
4159 
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.
def ULT(a, b)
Definition: z3py.py:4142

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

11051 def Union(*args):
11052  """Create union of regular expressions.
11053  >>> re = Union(Re("a"), Re("b"), Re("c"))
11054  >>> print (simplify(InRe("d", re)))
11055  False
11056  """
11057  args = _get_args(args)
11058  sz = len(args)
11059  if z3_debug():
11060  _z3_assert(sz > 0, "At least one argument expected.")
11061  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11062  if sz == 1:
11063  return args[0]
11064  ctx = args[0].ctx
11065  v = (Ast * sz)()
11066  for i in range(sz):
11067  v[i] = args[i].as_ast()
11068  return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
11069 
11070 
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.
def Union(*args)
Definition: z3py.py:11051

Referenced by ReRef.__add__().

◆ Unit()

def z3py.Unit (   a)
Create a singleton sequence

Definition at line 10855 of file z3py.py.

10855 def Unit(a):
10856  """Create a singleton sequence"""
10857  return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
10858 
10859 
Z3_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.
def Unit(a)
Definition: z3py.py:10855

◆ Update()

def z3py.Update (   a,
args 
)
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 4707 of file z3py.py.

4707 def Update(a, *args):
4708  """Return a Z3 store array expression.
4709 
4710  >>> a = Array('a', IntSort(), IntSort())
4711  >>> i, v = Ints('i v')
4712  >>> s = Update(a, i, v)
4713  >>> s.sort()
4714  Array(Int, Int)
4715  >>> prove(s[i] == v)
4716  proved
4717  >>> j = Int('j')
4718  >>> prove(Implies(i != j, s[j] == a[j]))
4719  proved
4720  """
4721  if z3_debug():
4722  _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4723  args = _get_args(args)
4724  ctx = a.ctx
4725  if len(args) <= 1:
4726  raise Z3Exception("array update requires index and value arguments")
4727  if len(args) == 2:
4728  i = args[0]
4729  v = args[1]
4730  i = a.sort().domain().cast(i)
4731  v = a.sort().range().cast(v)
4732  return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4733  v = a.sort().range().cast(args[-1])
4734  idxs = [a.sort().domain_n(i).cast(args[i]) for i in range(len(args)-1)]
4735  _args, sz = _to_ast_array(idxs)
4736  return _to_expr_ref(Z3_mk_store_n(ctx.ref(), a.as_ast(), sz, _args, v.as_ast()), ctx)
4737 
4738 
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
Z3_ast Z3_API Z3_mk_store_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs, Z3_ast v)
n-ary Array update.

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

4217 def URem(a, b):
4218  """Create the Z3 expression (unsigned) remainder `self % other`.
4219 
4220  Use the operator % for signed modulus, and SRem() for signed remainder.
4221 
4222  >>> x = BitVec('x', 32)
4223  >>> y = BitVec('y', 32)
4224  >>> URem(x, y)
4225  URem(x, y)
4226  >>> URem(x, y).sort()
4227  BitVec(32)
4228  >>> (x % y).sexpr()
4229  '(bvsmod x y)'
4230  >>> URem(x, y).sexpr()
4231  '(bvurem x y)'
4232  """
4233  _check_bv_args(a, b)
4234  a, b = _coerce_exprs(a, b)
4235  return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4236 
4237 
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.
def URem(a, b)
Definition: z3py.py:4217

◆ user_prop_diseq()

def z3py.user_prop_diseq (   ctx,
  cb,
  x,
  y 
)

Definition at line 11282 of file z3py.py.

11282 def user_prop_diseq(ctx, cb, x, y):
11283  prop = _prop_closures.get(ctx)
11284  prop.cb = cb
11285  x = _to_expr_ref(to_Ast(x), prop.ctx())
11286  y = _to_expr_ref(to_Ast(y), prop.ctx())
11287  prop.diseq(x, y)
11288  prop.cb = None
11289 
11290 
def user_prop_diseq(ctx, cb, x, y)
Definition: z3py.py:11282

◆ user_prop_eq()

def z3py.user_prop_eq (   ctx,
  cb,
  x,
  y 
)

Definition at line 11274 of file z3py.py.

11274 def user_prop_eq(ctx, cb, x, y):
11275  prop = _prop_closures.get(ctx)
11276  prop.cb = cb
11277  x = _to_expr_ref(to_Ast(x), prop.ctx())
11278  y = _to_expr_ref(to_Ast(y), prop.ctx())
11279  prop.eq(x, y)
11280  prop.cb = None
11281 
def user_prop_eq(ctx, cb, x, y)
Definition: z3py.py:11274

◆ user_prop_final()

def z3py.user_prop_final (   ctx,
  cb 
)

Definition at line 11268 of file z3py.py.

11268 def user_prop_final(ctx, cb):
11269  prop = _prop_closures.get(ctx)
11270  prop.cb = cb
11271  prop.final()
11272  prop.cb = None
11273 
def user_prop_final(ctx, cb)
Definition: z3py.py:11268

◆ user_prop_fixed()

def z3py.user_prop_fixed (   ctx,
  cb,
  id,
  value 
)

Definition at line 11260 of file z3py.py.

11260 def user_prop_fixed(ctx, cb, id, value):
11261  prop = _prop_closures.get(ctx)
11262  prop.cb = cb
11263  id = _to_expr_ref(to_Ast(id), prop.ctx())
11264  value = _to_expr_ref(to_Ast(value), prop.ctx())
11265  prop.fixed(id, value)
11266  prop.cb = None
11267 
def user_prop_fixed(ctx, cb, id, value)
Definition: z3py.py:11260

◆ user_prop_fresh()

def z3py.user_prop_fresh (   id,
  ctx 
)

Definition at line 11248 of file z3py.py.

11248 def user_prop_fresh(id, ctx):
11249  _prop_closures.set_threaded()
11250  prop = _prop_closures.get(id)
11251  new_prop = prop.fresh()
11252  _prop_closures.set(new_prop.id, new_prop)
11253  return ctypes.c_void_p(new_prop.id)
11254 
def user_prop_fresh(id, ctx)
Definition: z3py.py:11248

◆ user_prop_pop()

def z3py.user_prop_pop (   ctx,
  num_scopes 
)

Definition at line 11244 of file z3py.py.

11244 def user_prop_pop(ctx, num_scopes):
11245  _prop_closures.get(ctx).pop(num_scopes)
11246 
11247 
def user_prop_pop(ctx, num_scopes)
Definition: z3py.py:11244

◆ user_prop_push()

def z3py.user_prop_push (   ctx)

Definition at line 11240 of file z3py.py.

11240 def user_prop_push(ctx):
11241  _prop_closures.get(ctx).push()
11242 
11243 
def user_prop_push(ctx)
Definition: z3py.py:11240

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

1437 def Var(idx, s):
1438  """Create a Z3 free variable. Free variables are used to create quantified formulas.
1439 
1440  >>> Var(0, IntSort())
1441  Var(0)
1442  >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1443  False
1444  """
1445  if z3_debug():
1446  _z3_assert(is_sort(s), "Z3 sort expected")
1447  return _to_expr_ref(Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1448 
1449 
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a bound variable.

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

8643 def When(p, t, ctx=None):
8644  """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
8645  Otherwise, it returns the input goal unmodified.
8646 
8647  >>> t = When(Probe('size') > 2, Tactic('simplify'))
8648  >>> x, y = Ints('x y')
8649  >>> g = Goal()
8650  >>> g.add(x > 0)
8651  >>> g.add(y > 0)
8652  >>> t(g)
8653  [[x > 0, y > 0]]
8654  >>> g.add(x == y + 1)
8655  >>> t(g)
8656  [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8657  """
8658  p = _to_probe(p, ctx)
8659  t = _to_tactic(t, ctx)
8660  return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
8661 
8662 
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:8643

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

8300 def With(t, *args, **keys):
8301  """Return a tactic that applies tactic `t` using the given configuration options.
8302 
8303  >>> x, y = Ints('x y')
8304  >>> t = With(Tactic('simplify'), som=True)
8305  >>> t((x + 1)*(y + 2) == 0)
8306  [[2*x + y + x*y == -2]]
8307  """
8308  ctx = keys.pop("ctx", None)
8309  t = _to_tactic(t, ctx)
8310  p = args2params(args, keys, t.ctx)
8311  return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8312 
8313 
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p)
Return a tactic that applies t using the given set of parameters.
def With(t, *args, **keys)
Definition: z3py.py:8300

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

8314 def WithParams(t, p):
8315  """Return a tactic that applies tactic `t` using the given configuration options.
8316 
8317  >>> x, y = Ints('x y')
8318  >>> p = ParamsRef()
8319  >>> p.set("som", True)
8320  >>> t = WithParams(Tactic('simplify'), p)
8321  >>> t((x + 1)*(y + 2) == 0)
8322  [[2*x + y + x*y == -2]]
8323  """
8324  t = _to_tactic(t, None)
8325  return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8326 
8327 
def WithParams(t, p)
Definition: z3py.py:8314

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

1762 def Xor(a, b, ctx=None):
1763  """Create a Z3 Xor expression.
1764 
1765  >>> p, q = Bools('p q')
1766  >>> Xor(p, q)
1767  Xor(p, q)
1768  >>> simplify(Xor(p, q))
1769  Not(p == q)
1770  """
1771  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1772  s = BoolSort(ctx)
1773  a = s.cast(a)
1774  b = s.cast(b)
1775  return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1776 
1777 
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:1762

◆ z3_debug()

def z3py.z3_debug ( )

Definition at line 62 of file z3py.py.

62 def z3_debug():
63  global Z3_DEBUG
64  return Z3_DEBUG
65 
66 

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(), 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(), eq(), AstRef.eq(), Ext(), Extract(), FiniteDomainVal(), fpIsPositive(), fpNeg(), FPSort(), fpToFPUnsigned(), fpToIEEEBV(), fpToReal(), fpToSBV(), fpToUBV(), FreshFunction(), Function(), get_as_array_func(), ModelRef.get_interp(), get_map_func(), ModelRef.get_universe(), get_var_index(), If(), AlgebraicNumRef.index(), 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 174 of file z3py.py.

174 def z3_error_handler(c, e):
175  # Do nothing error handler, just avoid exit(0)
176  # The wrappers in z3core.py will raise a Z3Exception if an error is detected
177  return
178 
179 
def z3_error_handler(c, e)
Definition: z3py.py:174

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

4353 def ZeroExt(n, a):
4354  """Return a bit-vector expression with `n` extra zero-bits.
4355 
4356  >>> x = BitVec('x', 16)
4357  >>> n = ZeroExt(8, x)
4358  >>> n.size()
4359  24
4360  >>> n
4361  ZeroExt(8, x)
4362  >>> n.sort()
4363  BitVec(24)
4364  >>> v0 = BitVecVal(2, 2)
4365  >>> v0
4366  2
4367  >>> v0.size()
4368  2
4369  >>> v = simplify(ZeroExt(6, v0))
4370  >>> v
4371  2
4372  >>> v.size()
4373  8
4374  """
4375  if z3_debug():
4376  _z3_assert(_is_int(n), "First argument must be an integer")
4377  _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4378  return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4379 
4380 
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,...
def ZeroExt(n, a)
Definition: z3py.py:4353

Variable Documentation

◆ sat

Definition at line 6817 of file z3py.py.

◆ unknown

Definition at line 6819 of file z3py.py.

◆ unsat

Definition at line 6818 of file z3py.py.

◆ Z3_DEBUG

Z3_DEBUG = __debug__

Definition at line 59 of file z3py.py.