Z3
Data Structures | Functions | Variables
z3py Namespace Reference

Data Structures

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

Functions

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

Variables

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

Function Documentation

§ And()

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

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

Definition at line 1550 of file z3py.py.

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

1550 def And(*args):
1551  """Create a Z3 and-expression or and-probe.
1552 
1553  >>> p, q, r = Bools('p q r')
1554  >>> And(p, q, r)
1555  And(p, q, r)
1556  >>> P = BoolVector('p', 5)
1557  >>> And(P)
1558  And(p__0, p__1, p__2, p__3, p__4)
1559  """
1560  last_arg = None
1561  if len(args) > 0:
1562  last_arg = args[len(args)-1]
1563  if isinstance(last_arg, Context):
1564  ctx = args[len(args)-1]
1565  args = args[:len(args)-1]
1566  elif len(args) == 1 and isinstance(args[0], AstVector):
1567  ctx = args[0].ctx
1568  args = [a for a in args[0]]
1569  else:
1570  ctx = main_ctx()
1571  args = _get_args(args)
1572  ctx_args = _ctx_from_ast_arg_list(args, ctx)
1573  if __debug__:
1574  _z3_assert(ctx_args is None or ctx_args == ctx, "context mismatch")
1575  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1576  if _has_probe(args):
1577  return _probe_and(args, ctx)
1578  else:
1579  args = _coerce_expr_list(args, ctx)
1580  _args, sz = _to_ast_array(args)
1581  return BoolRef(Z3_mk_and(ctx.ref(), sz, _args), ctx)
1582 
def And(args)
Definition: z3py.py:1550
def main_ctx()
Definition: z3py.py:197
Z3_ast Z3_API Z3_mk_and(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] and ... and args[num_args-1].

§ AndThen()

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

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

Definition at line 7049 of file z3py.py.

Referenced by Context.Then(), and Then().

7049 def AndThen(*ts, **ks):
7050  """Return a tactic that applies the tactics in `*ts` in sequence.
7051 
7052  >>> x, y = Ints('x y')
7053  >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
7054  >>> t(And(x == 0, y > x + 1))
7055  [[Not(y <= 1)]]
7056  >>> t(And(x == 0, y > x + 1)).as_expr()
7057  Not(y <= 1)
7058  """
7059  if __debug__:
7060  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7061  ctx = ks.get('ctx', None)
7062  num = len(ts)
7063  r = ts[0]
7064  for i in range(num - 1):
7065  r = _and_then(r, ts[i+1], ctx)
7066  return r
7067 
def AndThen(ts, ks)
Definition: z3py.py:7049

§ append_log()

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

Definition at line 96 of file z3py.py.

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

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

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

4644 def args2params(arguments, keywords, ctx=None):
4645  """Convert python arguments into a Z3_params object.
4646  A ':' is added to the keywords, and '_' is replaced with '-'
4647 
4648  >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
4649  (params model true relevancy 2 elim_and true)
4650  """
4651  if __debug__:
4652  _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
4653  prev = None
4654  r = ParamsRef(ctx)
4655  for a in arguments:
4656  if prev is None:
4657  prev = a
4658  else:
4659  r.set(prev, a)
4660  prev = None
4661  for k in keywords:
4662  v = keywords[k]
4663  r.set(k, v)
4664  return r
4665 
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:4644

§ Array()

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

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

Definition at line 4131 of file z3py.py.

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

4131 def Array(name, dom, rng):
4132  """Return an array constant named `name` with the given domain and range sorts.
4133 
4134  >>> a = Array('a', IntSort(), IntSort())
4135  >>> a.sort()
4136  Array(Int, Int)
4137  >>> a[0]
4138  a[0]
4139  """
4140  s = ArraySort(dom, rng)
4141  ctx = s.ctx
4142  return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4143 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:100
def Array(name, dom, rng)
Definition: z3py.py:4131
def ArraySort(d, r)
Definition: z3py.py:4110

§ ArraySort()

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

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

Definition at line 4110 of file z3py.py.

Referenced by ArraySortRef.domain(), Context.mkArraySort(), Context.MkArraySort(), ArraySortRef.range(), Sort.toString(), and Sort.ToString().

4110 def ArraySort(d, r):
4111  """Return the Z3 array sort with the given domain and range sorts.
4112 
4113  >>> A = ArraySort(IntSort(), BoolSort())
4114  >>> A
4115  Array(Int, Bool)
4116  >>> A.domain()
4117  Int
4118  >>> A.range()
4119  Bool
4120  >>> AA = ArraySort(IntSort(), A)
4121  >>> AA
4122  Array(Int, Array(Int, Bool))
4123  """
4124  if __debug__:
4125  _z3_assert(is_sort(d), "Z3 sort expected")
4126  _z3_assert(is_sort(r), "Z3 sort expected")
4127  _z3_assert(d.ctx == r.ctx, "Context mismatch")
4128  ctx = d.ctx
4129  return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4130 
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:563
def ArraySort(d, r)
Definition: z3py.py:4110

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

7614 def AtLeast(*args):
7615  """Create an at-most Pseudo-Boolean k constraint.
7616 
7617  >>> a, b, c = Bools('a b c')
7618  >>> f = AtLeast(a, b, c, 2)
7619  """
7620  def mk_not(a):
7621  if is_not(a):
7622  return a.arg(0)
7623  else:
7624  return Not(a)
7625  args = _get_args(args)
7626  if __debug__:
7627  _z3_assert(len(args) > 1, "Non empty list of arguments expected")
7628  ctx = _ctx_from_ast_arg_list(args)
7629  if __debug__:
7630  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
7631  args1 = _coerce_expr_list(args[:-1], ctx)
7632  args1 = [ mk_not(a) for a in args1 ]
7633  k = len(args1) - args[-1]
7634  _args, sz = _to_ast_array(args1)
7635  return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
7636 
def AtLeast(args)
Definition: z3py.py:7614
def is_not(a)
Definition: z3py.py:1376
def Not(a, ctx=None)
Definition: z3py.py:1525

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

7597 def AtMost(*args):
7598  """Create an at-most Pseudo-Boolean k constraint.
7599 
7600  >>> a, b, c = Bools('a b c')
7601  >>> f = AtMost(a, b, c, 2)
7602  """
7603  args = _get_args(args)
7604  if __debug__:
7605  _z3_assert(len(args) > 1, "Non empty list of arguments expected")
7606  ctx = _ctx_from_ast_arg_list(args)
7607  if __debug__:
7608  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
7609  args1 = _coerce_expr_list(args[:-1], ctx)
7610  k = args[-1]
7611  _args, sz = _to_ast_array(args1)
7612  return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
7613 
def AtMost(args)
Definition: z3py.py:7597

§ binary_interpolant()

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

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

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

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

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

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

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

Definition at line 7968 of file z3py.py.

7968 def binary_interpolant(a,b,p=None,ctx=None):
7969  """Compute an interpolant for a binary conjunction.
7970 
7971  If a & b is unsatisfiable, returns an interpolant for a & b.
7972  This is a formula phi such that
7973 
7974  1) a implies phi
7975  2) b implies not phi
7976  3) All the uninterpreted symbols of phi occur in both a and b.
7977 
7978  If a & b is satisfiable, raises an object of class ModelRef
7979  that represents a model of a &b.
7980 
7981  If neither a proof of unsatisfiability nor a model is obtained
7982  (for example, because of a timeout, or because models are disabled)
7983  then None is returned.
7984 
7985  If parameters p are supplied, these are used in creating the
7986  solver that determines satisfiability.
7987 
7988  x = Int('x')
7989  print(binary_interpolant(x<0,x>2))
7990  Not(x >= 0)
7991  """
7992  f = And(Interpolant(a),b)
7993  ti = tree_interpolant(f,p,ctx)
7994  return ti[0] if ti is not None else None
7995 
def And(args)
Definition: z3py.py:1550
def binary_interpolant(a, b, p=None, ctx=None)
Definition: z3py.py:7968
def Interpolant(a, ctx=None)
Definition: z3py.py:7889
def tree_interpolant(pat, p=None, ctx=None)
Definition: z3py.py:7903

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

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

3560 def BitVec(name, bv, ctx=None):
3561  """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
3562  If `ctx=None`, then the global context is used.
3563 
3564  >>> x = BitVec('x', 16)
3565  >>> is_bv(x)
3566  True
3567  >>> x.size()
3568  16
3569  >>> x.sort()
3570  BitVec(16)
3571  >>> word = BitVecSort(16)
3572  >>> x2 = BitVec('x', word)
3573  >>> eq(x, x2)
3574  True
3575  """
3576  if isinstance(bv, BitVecSortRef):
3577  ctx = bv.ctx
3578  else:
3579  ctx = _get_ctx(ctx)
3580  bv = BitVecSort(bv, ctx)
3581  return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
3582 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:100
def BitVec(name, bv, ctx=None)
Definition: z3py.py:3560
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3530

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

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

3583 def BitVecs(names, bv, ctx=None):
3584  """Return a tuple of bit-vector constants of size bv.
3585 
3586  >>> x, y, z = BitVecs('x y z', 16)
3587  >>> x.size()
3588  16
3589  >>> x.sort()
3590  BitVec(16)
3591  >>> Sum(x, y, z)
3592  0 + x + y + z
3593  >>> Product(x, y, z)
3594  1*x*y*z
3595  >>> simplify(Product(x, y, z))
3596  x*y*z
3597  """
3598  ctx = _get_ctx(ctx)
3599  if isinstance(names, str):
3600  names = names.split(" ")
3601  return [BitVec(name, bv, ctx) for name in names]
3602 
def BitVec(name, bv, ctx=None)
Definition: z3py.py:3560
def BitVecs(names, bv, ctx=None)
Definition: z3py.py:3583

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

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

3530 def BitVecSort(sz, ctx=None):
3531  """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3532 
3533  >>> Byte = BitVecSort(8)
3534  >>> Word = BitVecSort(16)
3535  >>> Byte
3536  BitVec(8)
3537  >>> x = Const('x', Byte)
3538  >>> eq(x, BitVec('x', 8))
3539  True
3540  """
3541  ctx = _get_ctx(ctx)
3542  return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
3543 
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3530

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

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

3544 def BitVecVal(val, bv, ctx=None):
3545  """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3546 
3547  >>> v = BitVecVal(10, 32)
3548  >>> v
3549  10
3550  >>> print("0x%.8x" % v.as_long())
3551  0x0000000a
3552  """
3553  if is_bv_sort(bv):
3554  ctx = bv.ctx
3555  return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
3556  else:
3557  ctx = _get_ctx(ctx)
3558  return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
3559 
def BitVecVal(val, bv, ctx=None)
Definition: z3py.py:3544
def is_bv_sort(s)
Definition: z3py.py:3020
def BitVecSort(sz, ctx=None)
Definition: z3py.py:3530

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

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

1442 def Bool(name, ctx=None):
1443  """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1444 
1445  >>> p = Bool('p')
1446  >>> q = Bool('q')
1447  >>> And(p, q)
1448  And(p, q)
1449  """
1450  ctx = _get_ctx(ctx)
1451  return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
1452 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:100
def Bool(name, ctx=None)
Definition: z3py.py:1442
def BoolSort(ctx=None)
Definition: z3py.py:1407

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

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

1453 def Bools(names, ctx=None):
1454  """Return a tuple of Boolean constants.
1455 
1456  `names` is a single string containing all names separated by blank spaces.
1457  If `ctx=None`, then the global context is used.
1458 
1459  >>> p, q, r = Bools('p q r')
1460  >>> And(p, Or(q, r))
1461  And(p, Or(q, r))
1462  """
1463  ctx = _get_ctx(ctx)
1464  if isinstance(names, str):
1465  names = names.split(" ")
1466  return [Bool(name, ctx) for name in names]
1467 
def Bools(names, ctx=None)
Definition: z3py.py:1453
def Bool(name, ctx=None)
Definition: z3py.py:1442

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

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

1407 def BoolSort(ctx=None):
1408  """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1409 
1410  >>> BoolSort()
1411  Bool
1412  >>> p = Const('p', BoolSort())
1413  >>> is_bool(p)
1414  True
1415  >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1416  >>> r(0, 1)
1417  r(0, 1)
1418  >>> is_bool(r(0, 1))
1419  True
1420  """
1421  ctx = _get_ctx(ctx)
1422  return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
1423 
def is_bool(a)
Definition: z3py.py:1307
def BoolSort(ctx=None)
Definition: z3py.py:1407

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

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

1424 def BoolVal(val, ctx=None):
1425  """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1426 
1427  >>> BoolVal(True)
1428  True
1429  >>> is_true(BoolVal(True))
1430  True
1431  >>> is_true(True)
1432  False
1433  >>> is_false(BoolVal(False))
1434  True
1435  """
1436  ctx = _get_ctx(ctx)
1437  if val == False:
1438  return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1439  else:
1440  return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1441 
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:1424

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

Referenced by And(), and Or().

1468 def BoolVector(prefix, sz, ctx=None):
1469  """Return a list of Boolean constants of size `sz`.
1470 
1471  The constants are named using the given prefix.
1472  If `ctx=None`, then the global context is used.
1473 
1474  >>> P = BoolVector('p', 3)
1475  >>> P
1476  [p__0, p__1, p__2]
1477  >>> And(P)
1478  And(p__0, p__1, p__2)
1479  """
1480  return [ Bool('%s__%s' % (prefix, i)) for i in range(sz) ]
1481 
def BoolVector(prefix, sz, ctx=None)
Definition: z3py.py:1468
def Bool(name, ctx=None)
Definition: z3py.py:1442

§ BV2Int()

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

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

Definition at line 3508 of file z3py.py.

3508 def BV2Int(a, is_signed=False):
3509  """Return the Z3 expression BV2Int(a).
3510 
3511  >>> b = BitVec('b', 3)
3512  >>> BV2Int(b).sort()
3513  Int
3514  >>> x = Int('x')
3515  >>> x > BV2Int(b)
3516  x > BV2Int(b)
3517  >>> x > BV2Int(b, is_signed=False)
3518  x > BV2Int(b)
3519  >>> x > BV2Int(b, is_signed=True)
3520  x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3521  >>> solve(x > BV2Int(b), b == 1, x < 3)
3522  [b = 1, x = 2]
3523  """
3524  if __debug__:
3525  _z3_assert(is_bv(a), "Z3 bit-vector expression expected")
3526  ctx = a.ctx
3527 
3528  return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
3529 
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast t1, Z3_bool is_signed)
Create an integer from the bit-vector argument t1. If is_signed is false, then the bit-vector t1 is t...
def BV2Int(a, is_signed=False)
Definition: z3py.py:3508
def is_bv(a)
Definition: z3py.py:3481

§ BVRedAnd()

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

Definition at line 3947 of file z3py.py.

3947 def BVRedAnd(a):
3948  """Return the reduction-and expression of `a`."""
3949  if __debug__:
3950  _z3_assert(is_bv(a), "First argument must be a Z3 Bitvector expression")
3951  return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
3952 
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:3947
def is_bv(a)
Definition: z3py.py:3481

§ BVRedOr()

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

Definition at line 3953 of file z3py.py.

3953 def BVRedOr(a):
3954  """Return the reduction-or expression of `a`."""
3955  if __debug__:
3956  _z3_assert(is_bv(a), "First argument must be a Z3 Bitvector expression")
3957  return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
3958 
def BVRedOr(a)
Definition: z3py.py:3953
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
def is_bv(a)
Definition: z3py.py:3481

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

2970 def Cbrt(a, ctx=None):
2971  """ Return a Z3 expression which represents the cubic root of a.
2972 
2973  >>> x = Real('x')
2974  >>> Cbrt(x)
2975  x**(1/3)
2976  """
2977  if not is_expr(a):
2978  ctx = _get_ctx(ctx)
2979  a = RealVal(a, ctx)
2980  return a ** "1/3"
2981 
def Cbrt(a, ctx=None)
Definition: z3py.py:2970
def RealVal(val, ctx=None)
Definition: z3py.py:2763
def is_expr(a)
Definition: z3py.py:1007

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

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

3603 def Concat(*args):
3604  """Create a Z3 bit-vector concatenation expression.
3605 
3606  >>> v = BitVecVal(1, 4)
3607  >>> Concat(v, v+1, v)
3608  Concat(Concat(1, 1 + 1), 1)
3609  >>> simplify(Concat(v, v+1, v))
3610  289
3611  >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
3612  121
3613  """
3614  args = _get_args(args)
3615  sz = len(args)
3616  if __debug__:
3617  _z3_assert(sz >= 2, "At least two arguments expected.")
3618 
3619  ctx = None
3620  for a in args:
3621  if is_expr(a):
3622  ctx = a.ctx
3623  break
3624  if is_seq(args[0]) or isinstance(args[0], str):
3625  args = [_coerce_seq(s, ctx) for s in args]
3626  if __debug__:
3627  _z3_assert(all([is_seq(a) for a in args]), "All arguments must be sequence expressions.")
3628  v = (Ast * sz)()
3629  for i in range(sz):
3630  v[i] = args[i].as_ast()
3631  return SeqRef(Z3_mk_seq_concat(ctx.ref(), sz, v), ctx)
3632 
3633  if is_re(args[0]):
3634  if __debug__:
3635  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
3636  v = (Ast * sz)()
3637  for i in range(sz):
3638  v[i] = args[i].as_ast()
3639  return ReRef(Z3_mk_re_concat(ctx.ref(), sz, v), ctx)
3640 
3641  if __debug__:
3642  _z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.")
3643  r = args[0]
3644  for i in range(sz - 1):
3645  r = BitVecRef(Z3_mk_concat(ctx.ref(), r.as_ast(), args[i+1].as_ast()), ctx)
3646  return r
3647 
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
def is_re(s)
Definition: z3py.py:9600
def is_expr(a)
Definition: z3py.py:1007
def is_bv(a)
Definition: z3py.py:3481
def Concat(args)
Definition: z3py.py:3603
def is_seq(a)
Definition: z3py.py:9412

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

Referenced by If().

7452 def Cond(p, t1, t2, ctx=None):
7453  """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
7454 
7455  >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
7456  """
7457  p = _to_probe(p, ctx)
7458  t1 = _to_tactic(t1, ctx)
7459  t2 = _to_tactic(t2, ctx)
7460  return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
7461 
def Cond(p, t1, t2, ctx=None)
Definition: z3py.py:7452
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluat...

§ Const()

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

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

Definition at line 1193 of file z3py.py.

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

1193 def Const(name, sort):
1194  """Create a constant of the given sort.
1195 
1196  >>> Const('x', IntSort())
1197  x
1198  """
1199  if __debug__:
1200  _z3_assert(isinstance(sort, SortRef), "Z3 sort expected")
1201  ctx = sort.ctx
1202  return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
1203 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:100
def Const(name, sort)
Definition: z3py.py:1193

§ Consts()

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

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

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

Definition at line 1204 of file z3py.py.

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

1204 def Consts(names, sort):
1205  """Create a several constants of the given sort.
1206 
1207  `names` is a string containing the names of all constants to be created.
1208  Blank spaces separate the names of different constants.
1209 
1210  >>> x, y, z = Consts('x y z', IntSort())
1211  >>> x + y + z
1212  x + y + z
1213  """
1214  if isinstance(names, str):
1215  names = names.split(" ")
1216  return [Const(name, sort) for name in names]
1217 
def Consts(names, sort)
Definition: z3py.py:1204
def Const(name, sort)
Definition: z3py.py:1193

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

9504 def Contains(a, b):
9505  """Check if 'a' contains 'b'
9506  >>> s1 = Contains("abc", "ab")
9507  >>> simplify(s1)
9508  True
9509  >>> s2 = Contains("abc", "bc")
9510  >>> simplify(s2)
9511  True
9512  >>> x, y, z = Strings('x y z')
9513  >>> s3 = Contains(Concat(x,y,z), y)
9514  >>> simplify(s3)
9515  True
9516  """
9517  ctx = _get_ctx2(a, b)
9518  a = _coerce_seq(a, ctx)
9519  b = _coerce_seq(b, ctx)
9520  return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
9521 
9522 
def Contains(a, b)
Definition: z3py.py:9504

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

Referenced by Datatype.create().

4385 def CreateDatatypes(*ds):
4386  """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
4387 
4388  In the following example we define a Tree-List using two mutually recursive datatypes.
4389 
4390  >>> TreeList = Datatype('TreeList')
4391  >>> Tree = Datatype('Tree')
4392  >>> # Tree has two constructors: leaf and node
4393  >>> Tree.declare('leaf', ('val', IntSort()))
4394  >>> # a node contains a list of trees
4395  >>> Tree.declare('node', ('children', TreeList))
4396  >>> TreeList.declare('nil')
4397  >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
4398  >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
4399  >>> Tree.val(Tree.leaf(10))
4400  val(leaf(10))
4401  >>> simplify(Tree.val(Tree.leaf(10)))
4402  10
4403  >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
4404  >>> n1
4405  node(cons(leaf(10), cons(leaf(20), nil)))
4406  >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
4407  >>> simplify(n2 == n1)
4408  False
4409  >>> simplify(TreeList.car(Tree.children(n2)) == n1)
4410  True
4411  """
4412  ds = _get_args(ds)
4413  if __debug__:
4414  _z3_assert(len(ds) > 0, "At least one Datatype must be specified")
4415  _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
4416  _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
4417  _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
4418  ctx = ds[0].ctx
4419  num = len(ds)
4420  names = (Symbol * num)()
4421  out = (Sort * num)()
4422  clists = (ConstructorList * num)()
4423  to_delete = []
4424  for i in range(num):
4425  d = ds[i]
4426  names[i] = to_symbol(d.name, ctx)
4427  num_cs = len(d.constructors)
4428  cs = (Constructor * num_cs)()
4429  for j in range(num_cs):
4430  c = d.constructors[j]
4431  cname = to_symbol(c[0], ctx)
4432  rname = to_symbol(c[1], ctx)
4433  fs = c[2]
4434  num_fs = len(fs)
4435  fnames = (Symbol * num_fs)()
4436  sorts = (Sort * num_fs)()
4437  refs = (ctypes.c_uint * num_fs)()
4438  for k in range(num_fs):
4439  fname = fs[k][0]
4440  ftype = fs[k][1]
4441  fnames[k] = to_symbol(fname, ctx)
4442  if isinstance(ftype, Datatype):
4443  if __debug__:
4444  _z3_assert(ds.count(ftype) == 1, "One and only one occurrence of each datatype is expected")
4445  sorts[k] = None
4446  refs[k] = ds.index(ftype)
4447  else:
4448  if __debug__:
4449  _z3_assert(is_sort(ftype), "Z3 sort expected")
4450  sorts[k] = ftype.ast
4451  refs[k] = 0
4452  cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
4453  to_delete.append(ScopedConstructor(cs[j], ctx))
4454  clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs)
4455  to_delete.append(ScopedConstructorList(clists[i], ctx))
4456  Z3_mk_datatypes(ctx.ref(), num, names, out, clists)
4457  result = []
4458 
4459  for i in range(num):
4460  dref = DatatypeSortRef(out[i], ctx)
4461  num_cs = dref.num_constructors()
4462  for j in range(num_cs):
4463  cref = dref.constructor(j)
4464  cref_name = cref.name()
4465  cref_arity = cref.arity()
4466  if cref.arity() == 0:
4467  cref = cref()
4468  setattr(dref, cref_name, cref)
4469  rref = dref.recognizer(j)
4470  setattr(dref, rref.name(), rref)
4471  for k in range(cref_arity):
4472  aref = dref.accessor(j, k)
4473  setattr(dref, aref.name(), aref)
4474  result.append(dref)
4475  return tuple(result)
4476 
def to_symbol(s, ctx=None)
Definition: z3py.py:100
Z3_constructor Z3_API Z3_mk_constructor(Z3_context c, Z3_symbol name, Z3_symbol recognizer, unsigned num_fields, Z3_symbol const field_names[], Z3_sort_opt const sorts[], unsigned sort_refs[])
Create a constructor.
def CreateDatatypes(ds)
Definition: z3py.py:4385
def is_sort(s)
Definition: z3py.py:563
void Z3_API Z3_mk_datatypes(Z3_context c, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort sorts[], Z3_constructor_list constructor_lists[])
Create mutually recursive datatypes.
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.

§ DeclareSort()

def z3py.DeclareSort (   name,
  ctx = None 
)
Create a new uninterpred 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 600 of file z3py.py.

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

600 def DeclareSort(name, ctx=None):
601  """Create a new uninterpred sort named `name`.
602 
603  If `ctx=None`, then the new sort is declared in the global Z3Py context.
604 
605  >>> A = DeclareSort('A')
606  >>> a = Const('a', A)
607  >>> b = Const('b', A)
608  >>> a.sort() == A
609  True
610  >>> b.sort() == A
611  True
612  >>> a == b
613  a == b
614  """
615  ctx = _get_ctx(ctx)
616  return SortRef(Z3_mk_uninterpreted_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
617 
def to_symbol(s, ctx=None)
Definition: z3py.py:100
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:600

§ Default()

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

Definition at line 4165 of file z3py.py.

Referenced by is_default().

4165 def Default(a):
4166  """ Return a default value for array expression.
4167  >>> b = K(IntSort(), 1)
4168  >>> prove(Default(b) == 1)
4169  proved
4170  """
4171  if __debug__:
4172  _z3_assert(is_array(a), "First argument must be a Z3 array expression")
4173  return a.default()
4174 
4175 
def is_array(a)
Definition: z3py.py:4033
def Default(a)
Definition: z3py.py:4165

§ describe_probes()

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

Definition at line 7382 of file z3py.py.

7382 def describe_probes():
7383  """Display a (tabular) description of all available probes in Z3."""
7384  if in_html_mode():
7385  even = True
7386  print('<table border="1" cellpadding="2" cellspacing="0">')
7387  for p in probes():
7388  if even:
7389  print('<tr style="background-color:#CFCFCF">')
7390  even = False
7391  else:
7392  print('<tr>')
7393  even = True
7394  print('<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(probe_description(p), 40)))
7395  print('</table>')
7396  else:
7397  for p in probes():
7398  print('%s : %s' % (p, probe_description(p)))
7399 
def probes(ctx=None)
Definition: z3py.py:7364
def probe_description(name, ctx=None)
Definition: z3py.py:7374
def describe_probes()
Definition: z3py.py:7382

§ describe_tactics()

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

Definition at line 7194 of file z3py.py.

7194 def describe_tactics():
7195  """Display a (tabular) description of all available tactics in Z3."""
7196  if in_html_mode():
7197  even = True
7198  print('<table border="1" cellpadding="2" cellspacing="0">')
7199  for t in tactics():
7200  if even:
7201  print('<tr style="background-color:#CFCFCF">')
7202  even = False
7203  else:
7204  print('<tr>')
7205  even = True
7206  print('<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(tactic_description(t), 40)))
7207  print('</table>')
7208  else:
7209  for t in tactics():
7210  print('%s : %s' % (t, tactic_description(t)))
7211 
def tactics(ctx=None)
Definition: z3py.py:7176
def tactic_description(name, ctx=None)
Definition: z3py.py:7186
def describe_tactics()
Definition: z3py.py:7194

§ disable_trace()

def z3py.disable_trace (   msg)

Definition at line 64 of file z3py.py.

64 def disable_trace(msg):
65  Z3_disable_trace(msg)
66 
def disable_trace(msg)
Definition: z3py.py:64
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...

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

1162 def Distinct(*args):
1163  """Create a Z3 distinct expression.
1164 
1165  >>> x = Int('x')
1166  >>> y = Int('y')
1167  >>> Distinct(x, y)
1168  x != y
1169  >>> z = Int('z')
1170  >>> Distinct(x, y, z)
1171  Distinct(x, y, z)
1172  >>> simplify(Distinct(x, y, z))
1173  Distinct(x, y, z)
1174  >>> simplify(Distinct(x, y, z), blast_distinct=True)
1175  And(Not(x == y), Not(x == z), Not(y == z))
1176  """
1177  args = _get_args(args)
1178  ctx = _ctx_from_ast_arg_list(args)
1179  if __debug__:
1180  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
1181  args = _coerce_expr_list(args, ctx)
1182  _args, sz = _to_ast_array(args)
1183  return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
1184 
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:1162

§ Empty()

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

Definition at line 9458 of file z3py.py.

9458 def Empty(s):
9459  """Create the empty sequence of the given sort
9460  >>> e = Empty(StringSort())
9461  >>> print(e)
9462  ""
9463  >>> e2 = StringVal("")
9464  >>> print(e.eq(e2))
9465  True
9466  >>> e3 = Empty(SeqSort(IntSort()))
9467  >>> print(e3)
9468  seq.empty
9469  """
9470  return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
9471 
def Empty(s)
Definition: z3py.py:9458

§ enable_trace()

def z3py.enable_trace (   msg)

Definition at line 61 of file z3py.py.

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

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

Referenced by Context.mkEnumSort(), Context.MkEnumSort(), and EnumSort.TesterDecl().

4574 def EnumSort(name, values, ctx=None):
4575  """Return a new enumeration sort named `name` containing the given values.
4576 
4577  The result is a pair (sort, list of constants).
4578  Example:
4579  >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
4580  """
4581  if __debug__:
4582  _z3_assert(isinstance(name, str), "Name must be a string")
4583  _z3_assert(all([isinstance(v, str) for v in values]), "Eumeration sort values must be strings")
4584  _z3_assert(len(values) > 0, "At least one value expected")
4585  ctx = _get_ctx(ctx)
4586  num = len(values)
4587  _val_names = (Symbol * num)()
4588  for i in range(num):
4589  _val_names[i] = to_symbol(values[i])
4590  _values = (FuncDecl * num)()
4591  _testers = (FuncDecl * num)()
4592  name = to_symbol(name)
4593  S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
4594  V = []
4595  for i in range(num):
4596  V.append(FuncDeclRef(_values[i], ctx))
4597  V = [a() for a in V]
4598  return S, V
4599 
def to_symbol(s, ctx=None)
Definition: z3py.py:100
def EnumSort(name, values, ctx=None)
Definition: z3py.py:4574
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c, Z3_symbol name, unsigned n, Z3_symbol const enum_names[], Z3_func_decl enum_consts[], Z3_func_decl enum_testers[])
Create a enumeration sort.

§ eq()

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

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

Definition at line 400 of file z3py.py.

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

400 def eq(a, b):
401  """Return `True` if `a` and `b` are structurally identical AST nodes.
402 
403  >>> x = Int('x')
404  >>> y = Int('y')
405  >>> eq(x, y)
406  False
407  >>> eq(x + 1, x + 1)
408  True
409  >>> eq(x + 1, 1 + x)
410  False
411  >>> eq(simplify(x + 1), simplify(1 + x))
412  True
413  """
414  if __debug__:
415  _z3_assert(is_ast(a) and is_ast(b), "Z3 ASTs expected")
416  return a.eq(b)
417 
def eq(a, b)
Definition: z3py.py:400
def is_ast(a)
Definition: z3py.py:380

§ Exists()

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

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

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

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

Definition at line 1895 of file z3py.py.

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

1895 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
1896  """Create a Z3 exists formula.
1897 
1898  The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
1899 
1900  See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
1901 
1902  >>> f = Function('f', IntSort(), IntSort(), IntSort())
1903  >>> x = Int('x')
1904  >>> y = Int('y')
1905  >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
1906  >>> q
1907  Exists([x, y], f(x, y) >= x)
1908  >>> is_quantifier(q)
1909  True
1910  >>> r = Tactic('nnf')(q).as_expr()
1911  >>> is_quantifier(r)
1912  False
1913  """
1914  return _mk_quantifier(False, vs, body, weight, qid, skid, patterns, no_patterns)
1915 
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Definition: z3py.py:1895

§ Ext()

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

Definition at line 4250 of file z3py.py.

4250 def Ext(a, b):
4251  """Return extensionality index for arrays.
4252  """
4253  if __debug__:
4254  _z3_assert(is_array(a) and is_array(b))
4255  return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()));
4256 
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:4033
def Ext(a, b)
Definition: z3py.py:4250

§ Extract()

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

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

Definition at line 3648 of file z3py.py.

3648 def Extract(high, low, a):
3649  """Create a Z3 bit-vector extraction expression, or create a string extraction expression.
3650 
3651  >>> x = BitVec('x', 8)
3652  >>> Extract(6, 2, x)
3653  Extract(6, 2, x)
3654  >>> Extract(6, 2, x).sort()
3655  BitVec(5)
3656  >>> simplify(Extract(StringVal("abcd"),2,1))
3657  "c"
3658  """
3659  if isinstance(high, str):
3660  high = StringVal(high)
3661  if is_seq(high):
3662  s = high
3663  offset = _py2expr(low, high.ctx)
3664  length = _py2expr(a, high.ctx)
3665 
3666  if __debug__:
3667  _z3_assert(is_int(offset) and is_int(length), "Second and third arguments must be integers")
3668  return SeqRef(Z3_mk_seq_extract(s.ctx_ref(), s.as_ast(), offset.as_ast(), length.as_ast()), s.ctx)
3669  if __debug__:
3670  _z3_assert(low <= high, "First argument must be greater than or equal to second argument")
3671  _z3_assert(_is_int(high) and high >= 0 and _is_int(low) and low >= 0, "First and second arguments must be non negative integers")
3672  _z3_assert(is_bv(a), "Third argument must be a Z3 Bitvector expression")
3673  return BitVecRef(Z3_mk_extract(a.ctx_ref(), high, low, a.as_ast()), a.ctx)
3674 
def Extract(high, low, a)
Definition: z3py.py:3648
def is_int(a)
Definition: z3py.py:2310
def StringVal(s, ctx=None)
Definition: z3py.py:9438
Z3_ast Z3_API Z3_mk_extract(Z3_context c, unsigned high, unsigned low, Z3_ast t1)
Extract the bits high down to low from a bit-vector of size m to yield a new bit-vector of size n...
def is_bv(a)
Definition: z3py.py:3481
def is_seq(a)
Definition: z3py.py:9412

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

7415 def FailIf(p, ctx=None):
7416  """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
7417 
7418  In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal.
7419 
7420  >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
7421  >>> x, y = Ints('x y')
7422  >>> g = Goal()
7423  >>> g.add(x > 0)
7424  >>> g.add(y > 0)
7425  >>> t(g)
7426  [[x > 0, y > 0]]
7427  >>> g.add(x == y + 1)
7428  >>> t(g)
7429  [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
7430  """
7431  p = _to_probe(p, ctx)
7432  return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
7433 
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:7415

§ FiniteDomainSort()

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

Definition at line 6563 of file z3py.py.

Referenced by Context.mkFiniteDomainSort(), Context.MkFiniteDomainSort(), Sort.toString(), and Sort.ToString().

6563 def FiniteDomainSort(name, sz, ctx=None):
6564  """Create a named finite domain sort of a given size sz"""
6565  if not isinstance(name, Symbol):
6566  name = to_symbol(name)
6567  ctx = _get_ctx(ctx)
6568  return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
6569 
def to_symbol(s, ctx=None)
Definition: z3py.py:100
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, unsigned __int64 size)
Create a named finite domain sort.
def FiniteDomainSort(name, sz, ctx=None)
Definition: z3py.py:6563

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

6631 def FiniteDomainVal(val, sort, ctx=None):
6632  """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
6633 
6634  >>> s = FiniteDomainSort('S', 256)
6635  >>> FiniteDomainVal(255, s)
6636  255
6637  >>> FiniteDomainVal('100', s)
6638  100
6639  """
6640  if __debug__:
6641  _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort" )
6642  ctx = sort.ctx
6643  return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
6644 
def is_finite_domain_sort(s)
Definition: z3py.py:6570
def FiniteDomainVal(val, sort, ctx=None)
Definition: z3py.py:6631

§ Float128()

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

Definition at line 8175 of file z3py.py.

8175 def Float128(ctx=None):
8176  """Floating-point 128-bit (quadruple) sort."""
8177  ctx = _get_ctx(ctx)
8178  return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
8179 
def Float128(ctx=None)
Definition: z3py.py:8175
Z3_sort Z3_API Z3_mk_fpa_sort_128(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.

§ Float16()

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

Definition at line 8145 of file z3py.py.

8145 def Float16(ctx=None):
8146  """Floating-point 16-bit (half) sort."""
8147  ctx = _get_ctx(ctx)
8148  return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
8149 
def Float16(ctx=None)
Definition: z3py.py:8145
Z3_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.

§ Float32()

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

Definition at line 8155 of file z3py.py.

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

8155 def Float32(ctx=None):
8156  """Floating-point 32-bit (single) sort."""
8157  ctx = _get_ctx(ctx)
8158  return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
8159 
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:8155

§ Float64()

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

Definition at line 8165 of file z3py.py.

Referenced by fpFPToFP(), and fpToFP().

8165 def Float64(ctx=None):
8166  """Floating-point 64-bit (double) sort."""
8167  ctx = _get_ctx(ctx)
8168  return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
8169 
def Float64(ctx=None)
Definition: z3py.py:8165
Z3_sort Z3_API Z3_mk_fpa_sort_64(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.

§ FloatDouble()

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

Definition at line 8170 of file z3py.py.

8170 def FloatDouble(ctx=None):
8171  """Floating-point 64-bit (double) sort."""
8172  ctx = _get_ctx(ctx)
8173  return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
8174 
def FloatDouble(ctx=None)
Definition: z3py.py:8170
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.

§ FloatHalf()

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

Definition at line 8150 of file z3py.py.

8150 def FloatHalf(ctx=None):
8151  """Floating-point 16-bit (half) sort."""
8152  ctx = _get_ctx(ctx)
8153  return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
8154 
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:8150

§ FloatQuadruple()

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

Definition at line 8180 of file z3py.py.

8180 def FloatQuadruple(ctx=None):
8181  """Floating-point 128-bit (quadruple) sort."""
8182  ctx = _get_ctx(ctx)
8183  return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
8184 
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:8180

§ FloatSingle()

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

Definition at line 8160 of file z3py.py.

8160 def FloatSingle(ctx=None):
8161  """Floating-point 32-bit (single) sort."""
8162  ctx = _get_ctx(ctx)
8163  return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
8164 
def FloatSingle(ctx=None)
Definition: z3py.py:8160
Z3_sort Z3_API Z3_mk_fpa_sort_single(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.

§ ForAll()

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

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

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

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

Definition at line 1876 of file z3py.py.

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

1876 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
1877  """Create a Z3 forall formula.
1878 
1879  The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
1880 
1881  See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
1882 
1883  >>> f = Function('f', IntSort(), IntSort(), IntSort())
1884  >>> x = Int('x')
1885  >>> y = Int('y')
1886  >>> ForAll([x, y], f(x, y) >= x)
1887  ForAll([x, y], f(x, y) >= x)
1888  >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
1889  ForAll([x, y], f(x, y) >= x)
1890  >>> ForAll([x, y], f(x, y) >= x, weight=10)
1891  ForAll([x, y], f(x, y) >= x)
1892  """
1893  return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
1894 
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Definition: z3py.py:1876

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

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

8717 def FP(name, fpsort, ctx=None):
8718  """Return a floating-point constant named `name`.
8719  `fpsort` is the floating-point sort.
8720  If `ctx=None`, then the global context is used.
8721 
8722  >>> x = FP('x', FPSort(8, 24))
8723  >>> is_fp(x)
8724  True
8725  >>> x.ebits()
8726  8
8727  >>> x.sort()
8728  FPSort(8, 24)
8729  >>> word = FPSort(8, 24)
8730  >>> x2 = FP('x', word)
8731  >>> eq(x, x2)
8732  True
8733  """
8734  if isinstance(fpsort, FPSortRef) and ctx is None:
8735  ctx = fpsort.ctx
8736  else:
8737  ctx = _get_ctx(ctx)
8738  return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
8739 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:100
def FP(name, fpsort, ctx=None)
Definition: z3py.py:8717

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

8758 def fpAbs(a, ctx=None):
8759  """Create a Z3 floating-point absolute value expression.
8760 
8761  >>> s = FPSort(8, 24)
8762  >>> rm = RNE()
8763  >>> x = FPVal(1.0, s)
8764  >>> fpAbs(x)
8765  fpAbs(1)
8766  >>> y = FPVal(-20.0, s)
8767  >>> y
8768  -1.25*(2**4)
8769  >>> fpAbs(y)
8770  fpAbs(-1.25*(2**4))
8771  >>> fpAbs(-1.25*(2**4))
8772  fpAbs(-1.25*(2**4))
8773  >>> fpAbs(x).sort()
8774  FPSort(8, 24)
8775  """
8776  ctx = _get_ctx(ctx)
8777  [a] = _coerce_fp_expr_list([a], ctx)
8778  return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
8779 
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:8758

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

Referenced by FPs().

8847 def fpAdd(rm, a, b, ctx=None):
8848  """Create a Z3 floating-point addition expression.
8849 
8850  >>> s = FPSort(8, 24)
8851  >>> rm = RNE()
8852  >>> x = FP('x', s)
8853  >>> y = FP('y', s)
8854  >>> fpAdd(rm, x, y)
8855  fpAdd(RNE(), x, y)
8856  >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
8857  x + y
8858  >>> fpAdd(rm, x, y).sort()
8859  FPSort(8, 24)
8860  """
8861  return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
8862 
def fpAdd(rm, a, b, ctx=None)
Definition: z3py.py:8847

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

9144 def fpBVToFP(v, sort, ctx=None):
9145  """Create a Z3 floating-point conversion expression that represents the
9146  conversion from a bit-vector term to a floating-point term.
9147 
9148  >>> x_bv = BitVecVal(0x3F800000, 32)
9149  >>> x_fp = fpBVToFP(x_bv, Float32())
9150  >>> x_fp
9151  fpToFP(1065353216)
9152  >>> simplify(x_fp)
9153  1
9154  """
9155  _z3_assert(is_bv(v), "First argument must be a Z3 floating-point rounding mode expression.")
9156  _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
9157  ctx = _get_ctx(ctx)
9158  return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
9159 
def fpBVToFP(v, sort, ctx=None)
Definition: z3py.py:9144
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:8189
def is_bv(a)
Definition: z3py.py:3481

§ fpDiv()

def z3py.fpDiv (   rm,
  a,
  b,
  ctx = None 
)
Create a Z3 floating-point divison 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 8891 of file z3py.py.

8891 def fpDiv(rm, a, b, ctx=None):
8892  """Create a Z3 floating-point divison expression.
8893 
8894  >>> s = FPSort(8, 24)
8895  >>> rm = RNE()
8896  >>> x = FP('x', s)
8897  >>> y = FP('y', s)
8898  >>> fpDiv(rm, x, y)
8899  fpDiv(RNE(), x, y)
8900  >>> fpDiv(rm, x, y).sort()
8901  FPSort(8, 24)
8902  """
8903  return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
8904 
def fpDiv(rm, a, b, ctx=None)
Definition: z3py.py:8891

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

Referenced by fpFP(), and fpNEQ().

9056 def fpEQ(a, b, ctx=None):
9057  """Create the Z3 floating-point expression `fpEQ(other, self)`.
9058 
9059  >>> x, y = FPs('x y', FPSort(8, 24))
9060  >>> fpEQ(x, y)
9061  fpEQ(x, y)
9062  >>> fpEQ(x, y).sexpr()
9063  '(fp.eq x y)'
9064  """
9065  return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
9066 
def fpEQ(a, b, ctx=None)
Definition: z3py.py:9056

§ fpFMA()

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

Definition at line 8946 of file z3py.py.

8946 def fpFMA(rm, a, b, c, ctx=None):
8947  """Create a Z3 floating-point fused multiply-add expression.
8948  """
8949  return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
8950 
def fpFMA(rm, a, b, c, ctx=None)
Definition: z3py.py:8946

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

9078 def fpFP(sgn, exp, sig, ctx=None):
9079  """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
9080 
9081  >>> s = FPSort(8, 24)
9082  >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
9083  >>> print(x)
9084  fpFP(1, 127, 4194304)
9085  >>> xv = FPVal(-1.5, s)
9086  >>> print(xv)
9087  -1.5
9088  >>> slvr = Solver()
9089  >>> slvr.add(fpEQ(x, xv))
9090  >>> slvr.check()
9091  sat
9092  >>> xv = FPVal(+1.5, s)
9093  >>> print(xv)
9094  1.5
9095  >>> slvr = Solver()
9096  >>> slvr.add(fpEQ(x, xv))
9097  >>> slvr.check()
9098  unsat
9099  """
9100  _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
9101  _z3_assert(sgn.sort().size() == 1, "sort mismatch")
9102  ctx = _get_ctx(ctx)
9103  _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
9104  return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
9105 
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:9078
def is_bv(a)
Definition: z3py.py:3481

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

9160 def fpFPToFP(rm, v, sort, ctx=None):
9161  """Create a Z3 floating-point conversion expression that represents the
9162  conversion from a floating-point term to a floating-point term of different precision.
9163 
9164  >>> x_sgl = FPVal(1.0, Float32())
9165  >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
9166  >>> x_dbl
9167  fpToFP(RNE(), 1)
9168  >>> simplify(x_dbl)
9169  1
9170  >>> x_dbl.sort()
9171  FPSort(11, 53)
9172  """
9173  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9174  _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
9175  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9176  ctx = _get_ctx(ctx)
9177  return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9178 
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
def is_fp_sort(s)
Definition: z3py.py:8189
def fpFPToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9160
def is_fprm(a)
Definition: z3py.py:8437
def is_fp(a)
Definition: z3py.py:8529

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

9045 def fpGEQ(a, b, ctx=None):
9046  """Create the Z3 floating-point expression `other >= self`.
9047 
9048  >>> x, y = FPs('x y', FPSort(8, 24))
9049  >>> fpGEQ(x, y)
9050  x >= y
9051  >>> (x >= y).sexpr()
9052  '(fp.geq x y)'
9053  """
9054  return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
9055 
def fpGEQ(a, b, ctx=None)
Definition: z3py.py:9045

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

9034 def fpGT(a, b, ctx=None):
9035  """Create the Z3 floating-point expression `other > self`.
9036 
9037  >>> x, y = FPs('x y', FPSort(8, 24))
9038  >>> fpGT(x, y)
9039  x > y
9040  >>> (x > y).sexpr()
9041  '(fp.gt x y)'
9042  """
9043  return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
9044 
def fpGT(a, b, ctx=None)
Definition: z3py.py:9034

§ fpInfinity()

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

Definition at line 8651 of file z3py.py.

8651 def fpInfinity(s, negative):
8652  """Create a Z3 floating-point +oo or -oo term."""
8653  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
8654  _z3_assert(isinstance(negative, bool), "expected Boolean flag")
8655  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
8656 
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, Z3_bool negative)
Create a floating-point infinity of sort s.
def fpInfinity(s, negative)
Definition: z3py.py:8651

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

8972 def fpIsInf(a, ctx=None):
8973  """Create a Z3 floating-point isInfinite expression.
8974 
8975  >>> s = FPSort(8, 24)
8976  >>> x = FP('x', s)
8977  >>> fpIsInf(x)
8978  fpIsInf(x)
8979  """
8980  return _mk_fp_unary_norm(Z3_mk_fpa_is_infinite, a, ctx)
8981 
def fpIsInf(a, ctx=None)
Definition: z3py.py:8972

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

8961 def fpIsNaN(a, ctx=None):
8962  """Create a Z3 floating-point isNaN expression.
8963 
8964  >>> s = FPSort(8, 24)
8965  >>> x = FP('x', s)
8966  >>> y = FP('y', s)
8967  >>> fpIsNaN(x)
8968  fpIsNaN(x)
8969  """
8970  return _mk_fp_unary_norm(Z3_mk_fpa_is_nan, a, ctx)
8971 
def fpIsNaN(a, ctx=None)
Definition: z3py.py:8961

§ fpIsNegative()

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

Definition at line 8997 of file z3py.py.

8997 def fpIsNegative(a, ctx=None):
8998  """Create a Z3 floating-point isNegative expression.
8999  """
9000  return _mk_fp_unary_norm(Z3_mk_fpa_is_negative, a, ctx)
9001 
def fpIsNegative(a, ctx=None)
Definition: z3py.py:8997

§ fpIsNormal()

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

Definition at line 8987 of file z3py.py.

8987 def fpIsNormal(a, ctx=None):
8988  """Create a Z3 floating-point isNormal expression.
8989  """
8990  return _mk_fp_unary_norm(Z3_mk_fpa_is_normal, a, ctx)
8991 
def fpIsNormal(a, ctx=None)
Definition: z3py.py:8987

§ fpIsPositive()

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

Definition at line 9002 of file z3py.py.

9002 def fpIsPositive(a, ctx=None):
9003  """Create a Z3 floating-point isPositive expression.
9004  """
9005  return _mk_fp_unary_norm(Z3_mk_fpa_is_positive, a, ctx)
9006  return FPRef(Z3_mk_fpa_is_positive(a.ctx_ref(), a.as_ast()), a.ctx)
9007 
Z3_ast Z3_API Z3_mk_fpa_is_positive(Z3_context c, Z3_ast t)
Predicate indicating whether t is a positive floating-point number.
def fpIsPositive(a, ctx=None)
Definition: z3py.py:9002

§ fpIsSubnormal()

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

Definition at line 8992 of file z3py.py.

8992 def fpIsSubnormal(a, ctx=None):
8993  """Create a Z3 floating-point isSubnormal expression.
8994  """
8995  return _mk_fp_unary_norm(Z3_mk_fpa_is_subnormal, a, ctx)
8996 
def fpIsSubnormal(a, ctx=None)
Definition: z3py.py:8992

§ fpIsZero()

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

Definition at line 8982 of file z3py.py.

8982 def fpIsZero(a, ctx=None):
8983  """Create a Z3 floating-point isZero expression.
8984  """
8985  return _mk_fp_unary_norm(Z3_mk_fpa_is_zero, a, ctx)
8986 
def fpIsZero(a, ctx=None)
Definition: z3py.py:8982

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

9023 def fpLEQ(a, b, ctx=None):
9024  """Create the Z3 floating-point expression `other <= self`.
9025 
9026  >>> x, y = FPs('x y', FPSort(8, 24))
9027  >>> fpLEQ(x, y)
9028  x <= y
9029  >>> (x <= y).sexpr()
9030  '(fp.leq x y)'
9031  """
9032  return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
9033 
def fpLEQ(a, b, ctx=None)
Definition: z3py.py:9023

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

9012 def fpLT(a, b, ctx=None):
9013  """Create the Z3 floating-point expression `other < self`.
9014 
9015  >>> x, y = FPs('x y', FPSort(8, 24))
9016  >>> fpLT(x, y)
9017  x < y
9018  >>> (x < y).sexpr()
9019  '(fp.lt x y)'
9020  """
9021  return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
9022 
def fpLT(a, b, ctx=None)
Definition: z3py.py:9012

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

8932 def fpMax(a, b, ctx=None):
8933  """Create a Z3 floating-point maximum expression.
8934 
8935  >>> s = FPSort(8, 24)
8936  >>> rm = RNE()
8937  >>> x = FP('x', s)
8938  >>> y = FP('y', s)
8939  >>> fpMax(x, y)
8940  fpMax(x, y)
8941  >>> fpMax(x, y).sort()
8942  FPSort(8, 24)
8943  """
8944  return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
8945 
def fpMax(a, b, ctx=None)
Definition: z3py.py:8932

§ fpMin()

def z3py.fpMin (   a,
  b,
  ctx = None 
)
Create a Z3 floating-point minimium 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 8918 of file z3py.py.

8918 def fpMin(a, b, ctx=None):
8919  """Create a Z3 floating-point minimium expression.
8920 
8921  >>> s = FPSort(8, 24)
8922  >>> rm = RNE()
8923  >>> x = FP('x', s)
8924  >>> y = FP('y', s)
8925  >>> fpMin(x, y)
8926  fpMin(x, y)
8927  >>> fpMin(x, y).sort()
8928  FPSort(8, 24)
8929  """
8930  return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
8931 
def fpMin(a, b, ctx=None)
Definition: z3py.py:8918

§ fpMinusInfinity()

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

Definition at line 8646 of file z3py.py.

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

§ fpMinusZero()

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

Definition at line 8662 of file z3py.py.

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

§ fpMul()

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

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

Definition at line 8877 of file z3py.py.

Referenced by FPs().

8877 def fpMul(rm, a, b, ctx=None):
8878  """Create a Z3 floating-point multiplication expression.
8879 
8880  >>> s = FPSort(8, 24)
8881  >>> rm = RNE()
8882  >>> x = FP('x', s)
8883  >>> y = FP('y', s)
8884  >>> fpMul(rm, x, y)
8885  fpMul(RNE(), x, y)
8886  >>> fpMul(rm, x, y).sort()
8887  FPSort(8, 24)
8888  """
8889  return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
8890 
def fpMul(rm, a, b, ctx=None)
Definition: z3py.py:8877

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

8614 def fpNaN(s):
8615  """Create a Z3 floating-point NaN term.
8616 
8617  >>> s = FPSort(8, 24)
8618  >>> set_fpa_pretty(True)
8619  >>> fpNaN(s)
8620  NaN
8621  >>> pb = get_fpa_pretty()
8622  >>> set_fpa_pretty(False)
8623  >>> fpNaN(s)
8624  fpNaN(FPSort(8, 24))
8625  >>> set_fpa_pretty(pb)
8626  """
8627  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
8628  return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
8629 
def fpNaN(s)
Definition: z3py.py:8614
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.

§ fpNeg()

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

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

Definition at line 8780 of file z3py.py.

8780 def fpNeg(a, ctx=None):
8781  """Create a Z3 floating-point addition expression.
8782 
8783  >>> s = FPSort(8, 24)
8784  >>> rm = RNE()
8785  >>> x = FP('x', s)
8786  >>> fpNeg(x)
8787  -x
8788  >>> fpNeg(x).sort()
8789  FPSort(8, 24)
8790  """
8791  ctx = _get_ctx(ctx)
8792  [a] = _coerce_fp_expr_list([a], ctx)
8793  return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
8794 
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:8780

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

9067 def fpNEQ(a, b, ctx=None):
9068  """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
9069 
9070  >>> x, y = FPs('x y', FPSort(8, 24))
9071  >>> fpNEQ(x, y)
9072  Not(fpEQ(x, y))
9073  >>> (x != y).sexpr()
9074  '(distinct x y)'
9075  """
9076  return Not(fpEQ(a, b, ctx))
9077 
def fpEQ(a, b, ctx=None)
Definition: z3py.py:9056
def Not(a, ctx=None)
Definition: z3py.py:1525
def fpNEQ(a, b, ctx=None)
Definition: z3py.py:9067

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

8630 def fpPlusInfinity(s):
8631  """Create a Z3 floating-point +oo term.
8632 
8633  >>> s = FPSort(8, 24)
8634  >>> pb = get_fpa_pretty()
8635  >>> set_fpa_pretty(True)
8636  >>> fpPlusInfinity(s)
8637  +oo
8638  >>> set_fpa_pretty(False)
8639  >>> fpPlusInfinity(s)
8640  fpPlusInfinity(FPSort(8, 24))
8641  >>> set_fpa_pretty(pb)
8642  """
8643  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
8644  return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
8645 
def fpPlusInfinity(s)
Definition: z3py.py:8630
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, Z3_bool negative)
Create a floating-point infinity of sort s.

§ fpPlusZero()

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

Definition at line 8657 of file z3py.py.

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

§ fpRealToFP()

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

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

Definition at line 9179 of file z3py.py.

9179 def fpRealToFP(rm, v, sort, ctx=None):
9180  """Create a Z3 floating-point conversion expression that represents the
9181  conversion from a real term to a floating-point term.
9182 
9183  >>> x_r = RealVal(1.5)
9184  >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
9185  >>> x_fp
9186  fpToFP(RNE(), 3/2)
9187  >>> simplify(x_fp)
9188  1.5
9189  """
9190  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9191  _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
9192  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9193  ctx = _get_ctx(ctx)
9194  return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9195 
Z3_ast Z3_API Z3_mk_fpa_to_fp_real(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a term of real sort into a term of FloatingPoint sort.
def is_real(a)
Definition: z3py.py:2328
def is_fp_sort(s)
Definition: z3py.py:8189
def fpRealToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9179
def is_fprm(a)
Definition: z3py.py:8437

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

8905 def fpRem(a, b, ctx=None):
8906  """Create a Z3 floating-point remainder expression.
8907 
8908  >>> s = FPSort(8, 24)
8909  >>> x = FP('x', s)
8910  >>> y = FP('y', s)
8911  >>> fpRem(x, y)
8912  fpRem(x, y)
8913  >>> fpRem(x, y).sort()
8914  FPSort(8, 24)
8915  """
8916  return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
8917 
def fpRem(a, b, ctx=None)
Definition: z3py.py:8905

§ fpRoundToIntegral()

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

Definition at line 8956 of file z3py.py.

8956 def fpRoundToIntegral(rm, a, ctx=None):
8957  """Create a Z3 floating-point roundToIntegral expression.
8958  """
8959  return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
8960 
def fpRoundToIntegral(rm, a, ctx=None)
Definition: z3py.py:8956

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

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

8740 def FPs(names, fpsort, ctx=None):
8741  """Return an array of floating-point constants.
8742 
8743  >>> x, y, z = FPs('x y z', FPSort(8, 24))
8744  >>> x.sort()
8745  FPSort(8, 24)
8746  >>> x.sbits()
8747  24
8748  >>> x.ebits()
8749  8
8750  >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
8751  fpMul(RNE(), fpAdd(RNE(), x, y), z)
8752  """
8753  ctx = _get_ctx(ctx)
8754  if isinstance(names, str):
8755  names = names.split(" ")
8756  return [FP(name, fpsort, ctx) for name in names]
8757 
def FPs(names, fpsort, ctx=None)
Definition: z3py.py:8740
def FP(name, fpsort, ctx=None)
Definition: z3py.py:8717

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

9196 def fpSignedToFP(rm, v, sort, ctx=None):
9197  """Create a Z3 floating-point conversion expression that represents the
9198  conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
9199 
9200  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9201  >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
9202  >>> x_fp
9203  fpToFP(RNE(), 4294967291)
9204  >>> simplify(x_fp)
9205  -1.25*(2**2)
9206  """
9207  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9208  _z3_assert(is_bv(v), "Second argument must be a Z3 expression or real sort.")
9209  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9210  ctx = _get_ctx(ctx)
9211  return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9212 
Z3_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2&#39;s complement signed bit-vector term into a term of FloatingPoint sort...
def fpSignedToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9196
def is_fp_sort(s)
Definition: z3py.py:8189
def is_bv(a)
Definition: z3py.py:3481
def is_fprm(a)
Definition: z3py.py:8437

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

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

8556 def FPSort(ebits, sbits, ctx=None):
8557  """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
8558 
8559  >>> Single = FPSort(8, 24)
8560  >>> Double = FPSort(11, 53)
8561  >>> Single
8562  FPSort(8, 24)
8563  >>> x = Const('x', Single)
8564  >>> eq(x, FP('x', FPSort(8, 24)))
8565  True
8566  """
8567  ctx = _get_ctx(ctx)
8568  return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
8569 
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:8556

§ fpSqrt()

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

Definition at line 8951 of file z3py.py.

8951 def fpSqrt(rm, a, ctx=None):
8952  """Create a Z3 floating-point square root expression.
8953  """
8954  return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
8955 
def fpSqrt(rm, a, ctx=None)
Definition: z3py.py:8951

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

8863 def fpSub(rm, a, b, ctx=None):
8864  """Create a Z3 floating-point subtraction expression.
8865 
8866  >>> s = FPSort(8, 24)
8867  >>> rm = RNE()
8868  >>> x = FP('x', s)
8869  >>> y = FP('y', s)
8870  >>> fpSub(rm, x, y)
8871  fpSub(RNE(), x, y)
8872  >>> fpSub(rm, x, y).sort()
8873  FPSort(8, 24)
8874  """
8875  return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
8876 
def fpSub(rm, a, b, ctx=None)
Definition: z3py.py:8863

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

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

9106 def fpToFP(a1, a2=None, a3=None, ctx=None):
9107  """Create a Z3 floating-point conversion expression from other term sorts
9108  to floating-point.
9109 
9110  From a bit-vector term in IEEE 754-2008 format:
9111  >>> x = FPVal(1.0, Float32())
9112  >>> x_bv = fpToIEEEBV(x)
9113  >>> simplify(fpToFP(x_bv, Float32()))
9114  1
9115 
9116  From a floating-point term with different precision:
9117  >>> x = FPVal(1.0, Float32())
9118  >>> x_db = fpToFP(RNE(), x, Float64())
9119  >>> x_db.sort()
9120  FPSort(11, 53)
9121 
9122  From a real term:
9123  >>> x_r = RealVal(1.5)
9124  >>> simplify(fpToFP(RNE(), x_r, Float32()))
9125  1.5
9126 
9127  From a signed bit-vector term:
9128  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9129  >>> simplify(fpToFP(RNE(), x_signed, Float32()))
9130  -1.25*(2**2)
9131  """
9132  ctx = _get_ctx(ctx)
9133  if is_bv(a1) and is_fp_sort(a2):
9134  return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
9135  elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
9136  return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9137  elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
9138  return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9139  elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
9140  return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
9141  else:
9142  raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
9143 
def fpToFP(a1, a2=None, a3=None, ctx=None)
Definition: z3py.py:9106
Z3_ast Z3_API Z3_mk_fpa_to_fp_bv(Z3_context c, Z3_ast bv, Z3_sort s)
Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.
Z3_ast Z3_API Z3_mk_fpa_to_fp_real(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a term of real sort into a term of FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2&#39;s complement signed bit-vector term into a term of FloatingPoint sort...
def is_real(a)
Definition: z3py.py:2328
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
def is_fp_sort(s)
Definition: z3py.py:8189
def is_bv(a)
Definition: z3py.py:3481
def is_fprm(a)
Definition: z3py.py:8437
def is_fp(a)
Definition: z3py.py:8529

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

Referenced by fpUnsignedToFP().

9230 def fpToFPUnsigned(rm, x, s, ctx=None):
9231  """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
9232  if __debug__:
9233  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9234  _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
9235  _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
9236  ctx = _get_ctx(ctx)
9237  return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
9238 
def fpToFPUnsigned(rm, x, s, ctx=None)
Definition: z3py.py:9230
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2&#39;s complement unsigned bit-vector term into a term of FloatingPoint sort...
def is_fp_sort(s)
Definition: z3py.py:8189
def is_bv(a)
Definition: z3py.py:3481
def is_fprm(a)
Definition: z3py.py:8437

§ 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 represenatation 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 9300 of file z3py.py.

Referenced by fpToFP().

9300 def fpToIEEEBV(x, ctx=None):
9301  """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
9302 
9303  The size of the resulting bit-vector is automatically determined.
9304 
9305  Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
9306  knows only one NaN and it will always produce the same bit-vector represenatation of
9307  that NaN.
9308 
9309  >>> x = FP('x', FPSort(8, 24))
9310  >>> y = fpToIEEEBV(x)
9311  >>> print(is_fp(x))
9312  True
9313  >>> print(is_bv(y))
9314  True
9315  >>> print(is_fp(y))
9316  False
9317  >>> print(is_bv(x))
9318  False
9319  """
9320  if __debug__:
9321  _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
9322  ctx = _get_ctx(ctx)
9323  return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
9324 
9325 
9326 
def fpToIEEEBV(x, ctx=None)
Definition: z3py.py:9300
Z3_ast Z3_API Z3_mk_fpa_to_ieee_bv(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
def is_fp(a)
Definition: z3py.py:8529

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

9281 def fpToReal(x, ctx=None):
9282  """Create a Z3 floating-point conversion expression, from floating-point expression to real.
9283 
9284  >>> x = FP('x', FPSort(8, 24))
9285  >>> y = fpToReal(x)
9286  >>> print(is_fp(x))
9287  True
9288  >>> print(is_real(y))
9289  True
9290  >>> print(is_fp(y))
9291  False
9292  >>> print(is_real(x))
9293  False
9294  """
9295  if __debug__:
9296  _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
9297  ctx = _get_ctx(ctx)
9298  return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
9299 
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:9281
def is_fp(a)
Definition: z3py.py:8529

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

9239 def fpToSBV(rm, x, s, ctx=None):
9240  """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
9241 
9242  >>> x = FP('x', FPSort(8, 24))
9243  >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
9244  >>> print(is_fp(x))
9245  True
9246  >>> print(is_bv(y))
9247  True
9248  >>> print(is_fp(y))
9249  False
9250  >>> print(is_bv(x))
9251  False
9252  """
9253  if __debug__:
9254  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9255  _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
9256  _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
9257  ctx = _get_ctx(ctx)
9258  return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
9259 
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:9239
def is_bv_sort(s)
Definition: z3py.py:3020
def is_fprm(a)
Definition: z3py.py:8437
def is_fp(a)
Definition: z3py.py:8529

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

9260 def fpToUBV(rm, x, s, ctx=None):
9261  """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
9262 
9263  >>> x = FP('x', FPSort(8, 24))
9264  >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
9265  >>> print(is_fp(x))
9266  True
9267  >>> print(is_bv(y))
9268  True
9269  >>> print(is_fp(y))
9270  False
9271  >>> print(is_bv(x))
9272  False
9273  """
9274  if __debug__:
9275  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
9276  _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
9277  _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
9278  ctx = _get_ctx(ctx)
9279  return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
9280 
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:9260
def is_bv_sort(s)
Definition: z3py.py:3020
def is_fprm(a)
Definition: z3py.py:8437
def is_fp(a)
Definition: z3py.py:8529

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

9213 def fpUnsignedToFP(rm, v, sort, ctx=None):
9214  """Create a Z3 floating-point conversion expression that represents the
9215  conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
9216 
9217  >>> x_signed = BitVecVal(-5, BitVecSort(32))
9218  >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
9219  >>> x_fp
9220  fpToFPUnsigned(RNE(), 4294967291)
9221  >>> simplify(x_fp)
9222  1*(2**32)
9223  """
9224  _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
9225  _z3_assert(is_bv(v), "Second argument must be a Z3 expression or real sort.")
9226  _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
9227  ctx = _get_ctx(ctx)
9228  return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
9229 
def fpUnsignedToFP(rm, v, sort, ctx=None)
Definition: z3py.py:9213
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2&#39;s complement unsigned bit-vector term into a term of FloatingPoint sort...
def is_fp_sort(s)
Definition: z3py.py:8189
def is_bv(a)
Definition: z3py.py:3481
def is_fprm(a)
Definition: z3py.py:8437

§ 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())
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 8673 of file z3py.py.

Referenced by fpAbs(), fpFP(), fpFPToFP(), fpToFP(), and is_fp_value().

8673 def FPVal(sig, exp=None, fps=None, ctx=None):
8674  """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used.
8675 
8676  >>> v = FPVal(20.0, FPSort(8, 24))
8677  >>> v
8678  1.25*(2**4)
8679  >>> print("0x%.8x" % v.exponent_as_long())
8680  0x00000004
8681  >>> v = FPVal(2.25, FPSort(8, 24))
8682  >>> v
8683  1.125*(2**1)
8684  >>> v = FPVal(-2.25, FPSort(8, 24))
8685  >>> v
8686  -1.125*(2**1)
8687  >>> FPVal(-0.0, FPSort(8, 24))
8688  -0.0
8689  >>> FPVal(0.0, FPSort(8, 24))
8690  +0.0
8691  >>> FPVal(+0.0, FPSort(8, 24))
8692  +0.0
8693  """
8694  ctx = _get_ctx(ctx)
8695  if is_fp_sort(exp):
8696  fps = exp
8697  exp = None
8698  elif fps is None:
8699  fps = _dflt_fps(ctx)
8700  _z3_assert(is_fp_sort(fps), "sort mismatch")
8701  if exp is None:
8702  exp = 0
8703  val = _to_float_str(sig)
8704  if val == "NaN" or val == "nan":
8705  return fpNaN(fps)
8706  elif val == "-0.0":
8707  return fpMinusZero(fps)
8708  elif val == "0.0" or val == "+0.0":
8709  return fpPlusZero(fps)
8710  elif val == "+oo" or val == "+inf" or val == "+Inf":
8711  return fpPlusInfinity(fps)
8712  elif val == "-oo" or val == "-inf" or val == "-Inf":
8713  return fpMinusInfinity(fps)
8714  else:
8715  return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
8716 
def FPVal(sig, exp=None, fps=None, ctx=None)
Definition: z3py.py:8673
def fpMinusInfinity(s)
Definition: z3py.py:8646
def fpMinusZero(s)
Definition: z3py.py:8662
def fpPlusZero(s)
Definition: z3py.py:8657
def fpPlusInfinity(s)
Definition: z3py.py:8630
def fpNaN(s)
Definition: z3py.py:8614
def is_fp_sort(s)
Definition: z3py.py:8189

§ fpZero()

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

Definition at line 8667 of file z3py.py.

8667 def fpZero(s, negative):
8668  """Create a Z3 floating-point +0.0 or -0.0 term."""
8669  _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
8670  _z3_assert(isinstance(negative, bool), "expected Boolean flag")
8671  return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
8672 
def fpZero(s, negative)
Definition: z3py.py:8667
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, Z3_bool negative)
Create a floating-point zero of sort s.

§ FreshBool()

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

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

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

Definition at line 1482 of file z3py.py.

1482 def FreshBool(prefix='b', ctx=None):
1483  """Return a fresh Boolean constant in the given context using the given prefix.
1484 
1485  If `ctx=None`, then the global context is used.
1486 
1487  >>> b1 = FreshBool()
1488  >>> b2 = FreshBool()
1489  >>> eq(b1, b2)
1490  False
1491  """
1492  ctx = _get_ctx(ctx)
1493  return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1494 
def FreshBool(prefix='b', ctx=None)
Definition: z3py.py:1482
def BoolSort(ctx=None)
Definition: z3py.py:1407
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.

§ FreshInt()

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

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

Definition at line 2843 of file z3py.py.

2843 def FreshInt(prefix='x', ctx=None):
2844  """Return a fresh integer constant in the given context using the given prefix.
2845 
2846  >>> x = FreshInt()
2847  >>> y = FreshInt()
2848  >>> eq(x, y)
2849  False
2850  >>> x.sort()
2851  Int
2852  """
2853  ctx = _get_ctx(ctx)
2854  return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
2855 
def IntSort(ctx=None)
Definition: z3py.py:2705
def FreshInt(prefix='x', ctx=None)
Definition: z3py.py:2843
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.

§ FreshReal()

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

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

Definition at line 2895 of file z3py.py.

2895 def FreshReal(prefix='b', ctx=None):
2896  """Return a fresh real constant in the given context using the given prefix.
2897 
2898  >>> x = FreshReal()
2899  >>> y = FreshReal()
2900  >>> eq(x, y)
2901  False
2902  >>> x.sort()
2903  Real
2904  """
2905  ctx = _get_ctx(ctx)
2906  return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
2907 
def FreshReal(prefix='b', ctx=None)
Definition: z3py.py:2895
def RealSort(ctx=None)
Definition: z3py.py:2721
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.

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

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

738 def Function(name, *sig):
739  """Create a new Z3 uninterpreted function with the given sorts.
740 
741  >>> f = Function('f', IntSort(), IntSort())
742  >>> f(f(0))
743  f(f(0))
744  """
745  sig = _get_args(sig)
746  if __debug__:
747  _z3_assert(len(sig) > 0, "At least two arguments expected")
748  arity = len(sig) - 1
749  rng = sig[arity]
750  if __debug__:
751  _z3_assert(is_sort(rng), "Z3 sort expected")
752  dom = (Sort * arity)()
753  for i in range(arity):
754  if __debug__:
755  _z3_assert(is_sort(sig[i]), "Z3 sort expected")
756  dom[i] = sig[i].ast
757  ctx = rng.ctx
758  return FuncDeclRef(Z3_mk_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
759 
def Function(name, sig)
Definition: z3py.py:738
def to_symbol(s, ctx=None)
Definition: z3py.py:100
Z3_func_decl Z3_API Z3_mk_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a constant or function.
def is_sort(s)
Definition: z3py.py:563

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

5721 def get_as_array_func(n):
5722  """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
5723  if __debug__:
5724  _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
5725  return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
5726 
Z3_func_decl Z3_API Z3_get_as_array_func_decl(Z3_context c, Z3_ast a)
Return the function declaration f associated with a (_ as_array f) node.
def get_as_array_func(n)
Definition: z3py.py:5721
def is_as_array(n)
Definition: z3py.py:5717

§ get_default_fp_sort()

def z3py.get_default_fp_sort (   ctx = None)

Definition at line 8069 of file z3py.py.

8069 def get_default_fp_sort(ctx=None):
8070  return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
8071 
def FPSort(ebits, sbits, ctx=None)
Definition: z3py.py:8556
def get_default_fp_sort(ctx=None)
Definition: z3py.py:8069

§ get_default_rounding_mode()

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

Definition at line 8042 of file z3py.py.

8042 def get_default_rounding_mode(ctx=None):
8043  """Retrieves the global default rounding mode."""
8044  global _dflt_rounding_mode
8045  if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
8046  return RTZ(ctx)
8047  elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
8048  return RTN(ctx)
8049  elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
8050  return RTP(ctx)
8051  elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
8052  return RNE(ctx)
8053  elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
8054  return RNA(ctx)
8055 
def RTN(ctx=None)
Definition: z3py.py:8425
def RTZ(ctx=None)
Definition: z3py.py:8433
def RTP(ctx=None)
Definition: z3py.py:8417
def RNA(ctx=None)
Definition: z3py.py:8409
def get_default_rounding_mode(ctx=None)
Definition: z3py.py:8042
def RNE(ctx=None)
Definition: z3py.py:8401

§ get_full_version()

def z3py.get_full_version ( )

Definition at line 83 of file z3py.py.

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

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

4093 def get_map_func(a):
4094  """Return the function declaration associated with a Z3 map array expression.
4095 
4096  >>> f = Function('f', IntSort(), IntSort())
4097  >>> b = Array('b', IntSort(), IntSort())
4098  >>> a = Map(f, b)
4099  >>> eq(f, get_map_func(a))
4100  True
4101  >>> get_map_func(a)
4102  f
4103  >>> get_map_func(a)(0)
4104  f(0)
4105  """
4106  if __debug__:
4107  _z3_assert(is_map(a), "Z3 array map expression expected.")
4108  return FuncDeclRef(Z3_to_func_decl(a.ctx_ref(), Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0)), a.ctx)
4109 
Z3_func_decl Z3_API Z3_to_func_decl(Z3_context c, Z3_ast a)
Convert an AST into a FUNC_DECL_AST. This is just type casting.
def is_map(a)
Definition: z3py.py:4070
def get_map_func(a)
Definition: z3py.py:4093

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

256 def get_param(name):
257  """Return the value of a Z3 global (or module) parameter
258 
259  >>> get_param('nlsat.reorder')
260  'true'
261  """
262  ptr = (ctypes.c_char_p * 1)()
263  if Z3_global_param_get(str(name), ptr):
264  r = z3core._to_pystr(ptr[0])
265  return r
266  raise Z3Exception("failed to retrieve value for '%s'" % name)
267 
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:256

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

1096 def get_var_index(a):
1097  """Return the de-Bruijn index of the Z3 bounded variable `a`.
1098 
1099  >>> x = Int('x')
1100  >>> y = Int('y')
1101  >>> is_var(x)
1102  False
1103  >>> is_const(x)
1104  True
1105  >>> f = Function('f', IntSort(), IntSort(), IntSort())
1106  >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1107  >>> q = ForAll([x, y], f(x, y) == x + y)
1108  >>> q.body()
1109  f(Var(1), Var(0)) == Var(1) + Var(0)
1110  >>> b = q.body()
1111  >>> b.arg(0)
1112  f(Var(1), Var(0))
1113  >>> v1 = b.arg(0).arg(0)
1114  >>> v2 = b.arg(0).arg(1)
1115  >>> v1
1116  Var(1)
1117  >>> v2
1118  Var(0)
1119  >>> get_var_index(v1)
1120  1
1121  >>> get_var_index(v2)
1122  0
1123  """
1124  if __debug__:
1125  _z3_assert(is_var(a), "Z3 bound variable expected")
1126  return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
1127 
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Brujin bound variable.
def get_var_index(a)
Definition: z3py.py:1096
def is_var(a)
Definition: z3py.py:1072

§ get_version()

def z3py.get_version ( )

Definition at line 75 of file z3py.py.

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

§ get_version_string()

def z3py.get_version_string ( )

Definition at line 67 of file z3py.py.

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

§ help_simplify()

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

Definition at line 7492 of file z3py.py.

7492 def help_simplify():
7493  """Return a string describing all options available for Z3 `simplify` procedure."""
7494  print(Z3_simplify_get_help(main_ctx().ref()))
7495 
def main_ctx()
Definition: z3py.py:197
def help_simplify()
Definition: z3py.py:7492
Z3_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.

§ If()

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

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

Definition at line 1140 of file z3py.py.

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

1140 def If(a, b, c, ctx=None):
1141  """Create a Z3 if-then-else expression.
1142 
1143  >>> x = Int('x')
1144  >>> y = Int('y')
1145  >>> max = If(x > y, x, y)
1146  >>> max
1147  If(x > y, x, y)
1148  >>> simplify(max)
1149  If(x <= y, y, x)
1150  """
1151  if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1152  return Cond(a, b, c, ctx)
1153  else:
1154  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1155  s = BoolSort(ctx)
1156  a = s.cast(a)
1157  b, c = _coerce_exprs(b, c, ctx)
1158  if __debug__:
1159  _z3_assert(a.ctx == b.ctx, "Context mismatch")
1160  return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1161 
def If(a, b, c, ctx=None)
Definition: z3py.py:1140
def Cond(p, t1, t2, ctx=None)
Definition: z3py.py:7452
Z3_ast Z3_API Z3_mk_ite(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Create an AST node representing an if-then-else: ite(t1, t2, t3).
def BoolSort(ctx=None)
Definition: z3py.py:1407

§ Implies()

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

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

Definition at line 1495 of file z3py.py.

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

1495 def Implies(a, b, ctx=None):
1496  """Create a Z3 implies expression.
1497 
1498  >>> p, q = Bools('p q')
1499  >>> Implies(p, q)
1500  Implies(p, q)
1501  >>> simplify(Implies(p, q))
1502  Or(Not(p), q)
1503  """
1504  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1505  s = BoolSort(ctx)
1506  a = s.cast(a)
1507  b = s.cast(b)
1508  return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1509 
def Implies(a, b, ctx=None)
Definition: z3py.py:1495
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
def BoolSort(ctx=None)
Definition: z3py.py:1407

§ IndexOf() [1/2]

def z3py.IndexOf (   s,
  substr 
)

Definition at line 9537 of file z3py.py.

Referenced by IndexOf().

9537 def IndexOf(s, substr):
9538  return IndexOf(s, substr, IntVal(0))
9539 
def IntVal(val, ctx=None)
Definition: z3py.py:2752
def IndexOf(s, substr)
Definition: z3py.py:9537

§ IndexOf() [2/2]

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

Definition at line 9540 of file z3py.py.

9540 def IndexOf(s, substr, offset):
9541  """Retrieve the index of substring within a string starting at a specified offset.
9542  >>> simplify(IndexOf("abcabc", "bc", 0))
9543  1
9544  >>> simplify(IndexOf("abcabc", "bc", 2))
9545  4
9546  """
9547  ctx = None
9548  if is_expr(offset):
9549  ctx = offset.ctx
9550  ctx = _get_ctx2(s, substr, ctx)
9551  s = _coerce_seq(s, ctx)
9552  substr = _coerce_seq(substr, ctx)
9553  if _is_int(offset):
9554  offset = IntVal(offset, ctx)
9555  return SeqRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
9556 
def IntVal(val, ctx=None)
Definition: z3py.py:2752
def IndexOf(s, substr)
Definition: z3py.py:9537
def is_expr(a)
Definition: z3py.py:1007

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

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

9604 def InRe(s, re):
9605  """Create regular expression membership test
9606  >>> re = Union(Re("a"),Re("b"))
9607  >>> print (simplify(InRe("a", re)))
9608  True
9609  >>> print (simplify(InRe("b", re)))
9610  True
9611  >>> print (simplify(InRe("c", re)))
9612  False
9613  """
9614  s = _coerce_seq(s, re.ctx)
9615  return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
9616 
def InRe(s, re)
Definition: z3py.py:9604

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

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

2808 def Int(name, ctx=None):
2809  """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
2810 
2811  >>> x = Int('x')
2812  >>> is_int(x)
2813  True
2814  >>> is_int(x + 1)
2815  True
2816  """
2817  ctx = _get_ctx(ctx)
2818  return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
2819 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:100
def Int(name, ctx=None)
Definition: z3py.py:2808
def IntSort(ctx=None)
Definition: z3py.py:2705

§ Interpolant()

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

The argument is an interpolation pattern (see tree_interpolant).

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

Definition at line 7889 of file z3py.py.

Referenced by tree_interpolant().

7889 def Interpolant(a,ctx=None):
7890  """Create an interpolation operator.
7891 
7892  The argument is an interpolation pattern (see tree_interpolant).
7893 
7894  >>> x = Int('x')
7895  >>> print(Interpolant(x>0))
7896  interp(x > 0)
7897  """
7898  ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
7899  s = BoolSort(ctx)
7900  a = s.cast(a)
7901  return BoolRef(Z3_mk_interpolant(ctx.ref(), a.as_ast()), ctx)
7902 
Z3_ast Z3_API Z3_mk_interpolant(Z3_context c, Z3_ast a)
Create an AST node marking a formula position for interpolation.
def Interpolant(a, ctx=None)
Definition: z3py.py:7889
def BoolSort(ctx=None)
Definition: z3py.py:1407

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

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

2820 def Ints(names, ctx=None):
2821  """Return a tuple of Integer constants.
2822 
2823  >>> x, y, z = Ints('x y z')
2824  >>> Sum(x, y, z)
2825  x + y + z
2826  """
2827  ctx = _get_ctx(ctx)
2828  if isinstance(names, str):
2829  names = names.split(" ")
2830  return [Int(name, ctx) for name in names]
2831 
def Int(name, ctx=None)
Definition: z3py.py:2808
def Ints(names, ctx=None)
Definition: z3py.py:2820

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

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

2705 def IntSort(ctx=None):
2706  """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
2707 
2708  >>> IntSort()
2709  Int
2710  >>> x = Const('x', IntSort())
2711  >>> is_int(x)
2712  True
2713  >>> x.sort() == IntSort()
2714  True
2715  >>> x.sort() == BoolSort()
2716  False
2717  """
2718  ctx = _get_ctx(ctx)
2719  return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
2720 
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
def IntSort(ctx=None)
Definition: z3py.py:2705

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

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

2752 def IntVal(val, ctx=None):
2753  """Return a Z3 integer value. If `ctx=None`, then the global context is used.
2754 
2755  >>> IntVal(1)
2756  1
2757  >>> IntVal("100")
2758  100
2759  """
2760  ctx = _get_ctx(ctx)
2761  return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
2762 
def IntVal(val, ctx=None)
Definition: z3py.py:2752
def IntSort(ctx=None)
Definition: z3py.py:2705

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

2832 def IntVector(prefix, sz, ctx=None):
2833  """Return a list of integer constants of size `sz`.
2834 
2835  >>> X = IntVector('x', 3)
2836  >>> X
2837  [x__0, x__1, x__2]
2838  >>> Sum(X)
2839  x__0 + x__1 + x__2
2840  """
2841  return [ Int('%s__%s' % (prefix, i)) for i in range(sz) ]
2842 
def Int(name, ctx=None)
Definition: z3py.py:2808
def IntVector(prefix, sz, ctx=None)
Definition: z3py.py:2832

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

2409 def is_add(a):
2410  """Return `True` if `a` is an expression of the form b + c.
2411 
2412  >>> x, y = Ints('x y')
2413  >>> is_add(x + y)
2414  True
2415  >>> is_add(x - y)
2416  False
2417  """
2418  return is_app_of(a, Z3_OP_ADD)
2419 
def is_app_of(a, k)
Definition: z3py.py:1128
def is_add(a)
Definition: z3py.py:2409

§ is_algebraic_value()

def z3py.is_algebraic_value (   a)
Return `True` if `a` is an algerbraic 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 2396 of file z3py.py.

2396 def is_algebraic_value(a):
2397  """Return `True` if `a` is an algerbraic value of sort Real.
2398 
2399  >>> is_algebraic_value(RealVal("3/5"))
2400  False
2401  >>> n = simplify(Sqrt(2))
2402  >>> n
2403  1.4142135623?
2404  >>> is_algebraic_value(n)
2405  True
2406  """
2407  return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2408 
def is_arith(a)
Definition: z3py.py:2290
def is_algebraic_value(a)
Definition: z3py.py:2396

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

1354 def is_and(a):
1355  """Return `True` if `a` is a Z3 and expression.
1356 
1357  >>> p, q = Bools('p q')
1358  >>> is_and(And(p, q))
1359  True
1360  >>> is_and(Or(p, q))
1361  False
1362  """
1363  return is_app_of(a, Z3_OP_AND)
1364 
def is_and(a)
Definition: z3py.py:1354
def is_app_of(a, k)
Definition: z3py.py:1128

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

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

1029 def is_app(a):
1030  """Return `True` if `a` is a Z3 function application.
1031 
1032  Note that, constants are function applications with 0 arguments.
1033 
1034  >>> a = Int('a')
1035  >>> is_app(a)
1036  True
1037  >>> is_app(a + 1)
1038  True
1039  >>> is_app(IntSort())
1040  False
1041  >>> is_app(1)
1042  False
1043  >>> is_app(IntVal(1))
1044  True
1045  >>> x = Int('x')
1046  >>> is_app(ForAll(x, x >= 0))
1047  False
1048  """
1049  if not isinstance(a, ExprRef):
1050  return False
1051  k = _ast_kind(a.ctx, a)
1052  return k == Z3_NUMERAL_AST or k == Z3_APP_AST
1053 
def is_app(a)
Definition: z3py.py:1029

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

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

1128 def is_app_of(a, k):
1129  """Return `True` if `a` is an application of the given kind `k`.
1130 
1131  >>> x = Int('x')
1132  >>> n = x + 1
1133  >>> is_app_of(n, Z3_OP_ADD)
1134  True
1135  >>> is_app_of(n, Z3_OP_MUL)
1136  False
1137  """
1138  return is_app(a) and a.decl().kind() == k
1139 
def is_app(a)
Definition: z3py.py:1029
def is_app_of(a, k)
Definition: z3py.py:1128

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

2290 def is_arith(a):
2291  """Return `True` if `a` is an arithmetical expression.
2292 
2293  >>> x = Int('x')
2294  >>> is_arith(x)
2295  True
2296  >>> is_arith(x + 1)
2297  True
2298  >>> is_arith(1)
2299  False
2300  >>> is_arith(IntVal(1))
2301  True
2302  >>> y = Real('y')
2303  >>> is_arith(y)
2304  True
2305  >>> is_arith(y + 1)
2306  True
2307  """
2308  return isinstance(a, ArithRef)
2309 
def is_arith(a)
Definition: z3py.py:2290

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

1993 def is_arith_sort(s):
1994  """Return `True` if s is an arithmetical sort (type).
1995 
1996  >>> is_arith_sort(IntSort())
1997  True
1998  >>> is_arith_sort(RealSort())
1999  True
2000  >>> is_arith_sort(BoolSort())
2001  False
2002  >>> n = Int('x') + 1
2003  >>> is_arith_sort(n.sort())
2004  True
2005  """
2006  return isinstance(s, ArithSortRef)
2007 
def is_arith_sort(s)
Definition: z3py.py:1993

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

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

4033 def is_array(a):
4034  """Return `True` if `a` is a Z3 array expression.
4035 
4036  >>> a = Array('a', IntSort(), IntSort())
4037  >>> is_array(a)
4038  True
4039  >>> is_array(Store(a, 0, 1))
4040  True
4041  >>> is_array(a[0])
4042  False
4043  """
4044  return isinstance(a, ArrayRef)
4045 
def is_array(a)
Definition: z3py.py:4033

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

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

§ is_ast()

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

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

Definition at line 380 of file z3py.py.

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

380 def is_ast(a):
381  """Return `True` if `a` is an AST node.
382 
383  >>> is_ast(10)
384  False
385  >>> is_ast(IntVal(10))
386  True
387  >>> is_ast(Int('x'))
388  True
389  >>> is_ast(BoolSort())
390  True
391  >>> is_ast(Function('f', IntSort(), IntSort()))
392  True
393  >>> is_ast("x")
394  False
395  >>> is_ast(Solver())
396  False
397  """
398  return isinstance(a, AstRef)
399 
def is_ast(a)
Definition: z3py.py:380

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

Referenced by BoolSort(), and prove().

1307 def is_bool(a):
1308  """Return `True` if `a` is a Z3 Boolean expression.
1309 
1310  >>> p = Bool('p')
1311  >>> is_bool(p)
1312  True
1313  >>> q = Bool('q')
1314  >>> is_bool(And(p, q))
1315  True
1316  >>> x = Real('x')
1317  >>> is_bool(x)
1318  False
1319  >>> is_bool(x == 0)
1320  True
1321  """
1322  return isinstance(a, BoolRef)
1323 
def is_bool(a)
Definition: z3py.py:1307

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

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

3481 def is_bv(a):
3482  """Return `True` if `a` is a Z3 bit-vector expression.
3483 
3484  >>> b = BitVec('b', 32)
3485  >>> is_bv(b)
3486  True
3487  >>> is_bv(b + 10)
3488  True
3489  >>> is_bv(Int('x'))
3490  False
3491  """
3492  return isinstance(a, BitVecRef)
3493 
def is_bv(a)
Definition: z3py.py:3481

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

3020 def is_bv_sort(s):
3021  """Return True if `s` is a Z3 bit-vector sort.
3022 
3023  >>> is_bv_sort(BitVecSort(32))
3024  True
3025  >>> is_bv_sort(IntSort())
3026  False
3027  """
3028  return isinstance(s, BitVecSortRef)
3029 
def is_bv_sort(s)
Definition: z3py.py:3020

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

3494 def is_bv_value(a):
3495  """Return `True` if `a` is a Z3 bit-vector numeral value.
3496 
3497  >>> b = BitVec('b', 32)
3498  >>> is_bv_value(b)
3499  False
3500  >>> b = BitVecVal(10, 32)
3501  >>> b
3502  10
3503  >>> is_bv_value(b)
3504  True
3505  """
3506  return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
3507 
def is_bv_value(a)
Definition: z3py.py:3494
def is_bv(a)
Definition: z3py.py:3481

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

Referenced by prove().

1054 def is_const(a):
1055  """Return `True` if `a` is Z3 constant/variable expression.
1056 
1057  >>> a = Int('a')
1058  >>> is_const(a)
1059  True
1060  >>> is_const(a + 1)
1061  False
1062  >>> is_const(1)
1063  False
1064  >>> is_const(IntVal(1))
1065  True
1066  >>> x = Int('x')
1067  >>> is_const(ForAll(x, x >= 0))
1068  False
1069  """
1070  return is_app(a) and a.num_args() == 0
1071 
def is_app(a)
Definition: z3py.py:1029
def is_const(a)
Definition: z3py.py:1054

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

4046 def is_const_array(a):
4047  """Return `True` if `a` is a Z3 constant array.
4048 
4049  >>> a = K(IntSort(), 10)
4050  >>> is_const_array(a)
4051  True
4052  >>> a = Array('a', IntSort(), IntSort())
4053  >>> is_const_array(a)
4054  False
4055  """
4056  return is_app_of(a, Z3_OP_CONST_ARRAY)
4057 
def is_const_array(a)
Definition: z3py.py:4046
def is_app_of(a, k)
Definition: z3py.py:1128

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

4085 def is_default(a):
4086  """Return `True` if `a` is a Z3 default array expression.
4087  >>> d = Default(K(IntSort(), 10))
4088  >>> is_default(d)
4089  True
4090  """
4091  return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4092 
def is_default(a)
Definition: z3py.py:4085
def is_app_of(a, k)
Definition: z3py.py:1128

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

1396 def is_distinct(a):
1397  """Return `True` if `a` is a Z3 distinct expression.
1398 
1399  >>> x, y, z = Ints('x y z')
1400  >>> is_distinct(x == y)
1401  False
1402  >>> is_distinct(Distinct(x, y, z))
1403  True
1404  """
1405  return is_app_of(a, Z3_OP_DISTINCT)
1406 
def is_distinct(a)
Definition: z3py.py:1396
def is_app_of(a, k)
Definition: z3py.py:1128

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

2442 def is_div(a):
2443  """Return `True` if `a` is an expression of the form b / c.
2444 
2445  >>> x, y = Reals('x y')
2446  >>> is_div(x / y)
2447  True
2448  >>> is_div(x + y)
2449  False
2450  >>> x, y = Ints('x y')
2451  >>> is_div(x / y)
2452  False
2453  >>> is_idiv(x / y)
2454  True
2455  """
2456  return is_app_of(a, Z3_OP_DIV)
2457 
def is_div(a)
Definition: z3py.py:2442
def is_app_of(a, k)
Definition: z3py.py:1128

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

Referenced by AstRef.__bool__().

1387 def is_eq(a):
1388  """Return `True` if `a` is a Z3 equality expression.
1389 
1390  >>> x, y = Ints('x y')
1391  >>> is_eq(x == y)
1392  True
1393  """
1394  return is_app_of(a, Z3_OP_EQ)
1395 
def is_eq(a)
Definition: z3py.py:1387
def is_app_of(a, k)
Definition: z3py.py:1128

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

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

1007 def is_expr(a):
1008  """Return `True` if `a` is a Z3 expression.
1009 
1010  >>> a = Int('a')
1011  >>> is_expr(a)
1012  True
1013  >>> is_expr(a + 1)
1014  True
1015  >>> is_expr(IntSort())
1016  False
1017  >>> is_expr(1)
1018  False
1019  >>> is_expr(IntVal(1))
1020  True
1021  >>> x = Int('x')
1022  >>> is_expr(ForAll(x, x >= 0))
1023  True
1024  >>> is_expr(FPVal(1.0))
1025  True
1026  """
1027  return isinstance(a, ExprRef)
1028 
def is_expr(a)
Definition: z3py.py:1007

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

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

1341 def is_false(a):
1342  """Return `True` if `a` is the Z3 false expression.
1343 
1344  >>> p = Bool('p')
1345  >>> is_false(p)
1346  False
1347  >>> is_false(False)
1348  False
1349  >>> is_false(BoolVal(False))
1350  True
1351  """
1352  return is_app_of(a, Z3_OP_FALSE)
1353 
def is_app_of(a, k)
Definition: z3py.py:1128
def is_false(a)
Definition: z3py.py:1341

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

Referenced by is_finite_domain_value().

6592 def is_finite_domain(a):
6593  """Return `True` if `a` is a Z3 finite-domain expression.
6594 
6595  >>> s = FiniteDomainSort('S', 100)
6596  >>> b = Const('b', s)
6597  >>> is_finite_domain(b)
6598  True
6599  >>> is_finite_domain(Int('x'))
6600  False
6601  """
6602  return isinstance(a, FiniteDomainRef)
6603 
6604 
def is_finite_domain(a)
Definition: z3py.py:6592

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

Referenced by FiniteDomainVal().

6570 def is_finite_domain_sort(s):
6571  """Return True if `s` is a Z3 finite-domain sort.
6572 
6573  >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
6574  True
6575  >>> is_finite_domain_sort(IntSort())
6576  False
6577  """
6578  return isinstance(s, FiniteDomainSortRef)
6579 
6580 
def is_finite_domain_sort(s)
Definition: z3py.py:6570

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

6645 def is_finite_domain_value(a):
6646  """Return `True` if `a` is a Z3 finite-domain value.
6647 
6648  >>> s = FiniteDomainSort('S', 100)
6649  >>> b = Const('b', s)
6650  >>> is_finite_domain_value(b)
6651  False
6652  >>> b = FiniteDomainVal(10, s)
6653  >>> b
6654  10
6655  >>> is_finite_domain_value(b)
6656  True
6657  """
6658  return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
6659 
6660 
def is_finite_domain_value(a)
Definition: z3py.py:6645
def is_finite_domain(a)
Definition: z3py.py:6592

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

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

8529 def is_fp(a):
8530  """Return `True` if `a` is a Z3 floating-point expression.
8531 
8532  >>> b = FP('b', FPSort(8, 24))
8533  >>> is_fp(b)
8534  True
8535  >>> is_fp(b + 1.0)
8536  True
8537  >>> is_fp(Int('x'))
8538  False
8539  """
8540  return isinstance(a, FPRef)
8541 
def is_fp(a)
Definition: z3py.py:8529

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

8189 def is_fp_sort(s):
8190  """Return True if `s` is a Z3 floating-point sort.
8191 
8192  >>> is_fp_sort(FPSort(8, 24))
8193  True
8194  >>> is_fp_sort(IntSort())
8195  False
8196  """
8197  return isinstance(s, FPSortRef)
8198 
def is_fp_sort(s)
Definition: z3py.py:8189

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

8542 def is_fp_value(a):
8543  """Return `True` if `a` is a Z3 floating-point numeral value.
8544 
8545  >>> b = FP('b', FPSort(8, 24))
8546  >>> is_fp_value(b)
8547  False
8548  >>> b = FPVal(1.0, FPSort(8, 24))
8549  >>> b
8550  1
8551  >>> is_fp_value(b)
8552  True
8553  """
8554  return is_fp(a) and _is_numeral(a.ctx, a.ast)
8555 
def is_fp_value(a)
Definition: z3py.py:8542
def is_fp(a)
Definition: z3py.py:8529

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

8437 def is_fprm(a):
8438  """Return `True` if `a` is a Z3 floating-point rounding mode expression.
8439 
8440  >>> rm = RNE()
8441  >>> is_fprm(rm)
8442  True
8443  >>> rm = 1.0
8444  >>> is_fprm(rm)
8445  False
8446  """
8447  return isinstance(a, FPRMRef)
8448 
def is_fprm(a)
Definition: z3py.py:8437

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

8199 def is_fprm_sort(s):
8200  """Return True if `s` is a Z3 floating-point rounding mode sort.
8201 
8202  >>> is_fprm_sort(FPSort(8, 24))
8203  False
8204  >>> is_fprm_sort(RNE().sort())
8205  True
8206  """
8207  return isinstance(s, FPRMSortRef)
8208 
def is_fprm_sort(s)
Definition: z3py.py:8199

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

8449 def is_fprm_value(a):
8450  """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
8451  return is_fprm(a) and _is_numeral(a.ctx, a.ast)
8452 
def is_fprm_value(a)
Definition: z3py.py:8449
def is_fprm(a)
Definition: z3py.py:8437

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

Referenced by prove().

726 def is_func_decl(a):
727  """Return `True` if `a` is a Z3 function declaration.
728 
729  >>> f = Function('f', IntSort(), IntSort())
730  >>> is_func_decl(f)
731  True
732  >>> x = Real('x')
733  >>> is_func_decl(x)
734  False
735  """
736  return isinstance(a, FuncDeclRef)
737 
def is_func_decl(a)
Definition: z3py.py:726

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

2502 def is_ge(a):
2503  """Return `True` if `a` is an expression of the form b >= c.
2504 
2505  >>> x, y = Ints('x y')
2506  >>> is_ge(x >= y)
2507  True
2508  >>> is_ge(x == y)
2509  False
2510  """
2511  return is_app_of(a, Z3_OP_GE)
2512 
def is_ge(a)
Definition: z3py.py:2502
def is_app_of(a, k)
Definition: z3py.py:1128

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

2513 def is_gt(a):
2514  """Return `True` if `a` is an expression of the form b > c.
2515 
2516  >>> x, y = Ints('x y')
2517  >>> is_gt(x > y)
2518  True
2519  >>> is_gt(x == y)
2520  False
2521  """
2522  return is_app_of(a, Z3_OP_GT)
2523 
def is_gt(a)
Definition: z3py.py:2513
def is_app_of(a, k)
Definition: z3py.py:1128

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

Referenced by is_div().

2458 def is_idiv(a):
2459  """Return `True` if `a` is an expression of the form b div c.
2460 
2461  >>> x, y = Ints('x y')
2462  >>> is_idiv(x / y)
2463  True
2464  >>> is_idiv(x + y)
2465  False
2466  """
2467  return is_app_of(a, Z3_OP_IDIV)
2468 
def is_idiv(a)
Definition: z3py.py:2458
def is_app_of(a, k)
Definition: z3py.py:1128

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

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

2310 def is_int(a):
2311  """Return `True` if `a` is an integer expression.
2312 
2313  >>> x = Int('x')
2314  >>> is_int(x + 1)
2315  True
2316  >>> is_int(1)
2317  False
2318  >>> is_int(IntVal(1))
2319  True
2320  >>> y = Real('y')
2321  >>> is_int(y)
2322  False
2323  >>> is_int(y + 1)
2324  False
2325  """
2326  return is_arith(a) and a.is_int()
2327 
def is_arith(a)
Definition: z3py.py:2290
def is_int(a)
Definition: z3py.py:2310

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

2352 def is_int_value(a):
2353  """Return `True` if `a` is an integer value of sort Int.
2354 
2355  >>> is_int_value(IntVal(1))
2356  True
2357  >>> is_int_value(1)
2358  False
2359  >>> is_int_value(Int('x'))
2360  False
2361  >>> n = Int('x') + 1
2362  >>> n
2363  x + 1
2364  >>> n.arg(1)
2365  1
2366  >>> is_int_value(n.arg(1))
2367  True
2368  >>> is_int_value(RealVal("1/3"))
2369  False
2370  >>> is_int_value(RealVal(1))
2371  False
2372  """
2373  return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
2374 
def is_int_value(a)
Definition: z3py.py:2352
def is_arith(a)
Definition: z3py.py:2290

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

2524 def is_is_int(a):
2525  """Return `True` if `a` is an expression of the form IsInt(b).
2526 
2527  >>> x = Real('x')
2528  >>> is_is_int(IsInt(x))
2529  True
2530  >>> is_is_int(x)
2531  False
2532  """
2533  return is_app_of(a, Z3_OP_IS_INT)
2534 
def is_app_of(a, k)
Definition: z3py.py:1128
def is_is_int(a)
Definition: z3py.py:2524

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

4058 def is_K(a):
4059  """Return `True` if `a` is a Z3 constant array.
4060 
4061  >>> a = K(IntSort(), 10)
4062  >>> is_K(a)
4063  True
4064  >>> a = Array('a', IntSort(), IntSort())
4065  >>> is_K(a)
4066  False
4067  """
4068  return is_app_of(a, Z3_OP_CONST_ARRAY)
4069 
def is_K(a)
Definition: z3py.py:4058
def is_app_of(a, k)
Definition: z3py.py:1128

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

2480 def is_le(a):
2481  """Return `True` if `a` is an expression of the form b <= c.
2482 
2483  >>> x, y = Ints('x y')
2484  >>> is_le(x <= y)
2485  True
2486  >>> is_le(x < y)
2487  False
2488  """
2489  return is_app_of(a, Z3_OP_LE)
2490 
def is_le(a)
Definition: z3py.py:2480
def is_app_of(a, k)
Definition: z3py.py:1128

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

2491 def is_lt(a):
2492  """Return `True` if `a` is an expression of the form b < c.
2493 
2494  >>> x, y = Ints('x y')
2495  >>> is_lt(x < y)
2496  True
2497  >>> is_lt(x == y)
2498  False
2499  """
2500  return is_app_of(a, Z3_OP_LT)
2501 
def is_lt(a)
Definition: z3py.py:2491
def is_app_of(a, k)
Definition: z3py.py:1128

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

4070 def is_map(a):
4071  """Return `True` if `a` is a Z3 map array expression.
4072 
4073  >>> f = Function('f', IntSort(), IntSort())
4074  >>> b = Array('b', IntSort(), IntSort())
4075  >>> a = Map(f, b)
4076  >>> a
4077  Map(f, b)
4078  >>> is_map(a)
4079  True
4080  >>> is_map(b)
4081  False
4082  """
4083  return is_app_of(a, Z3_OP_ARRAY_MAP)
4084 
def is_map(a)
Definition: z3py.py:4070
def is_app_of(a, k)
Definition: z3py.py:1128

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

2469 def is_mod(a):
2470  """Return `True` if `a` is an expression of the form b % c.
2471 
2472  >>> x, y = Ints('x y')
2473  >>> is_mod(x % y)
2474  True
2475  >>> is_mod(x + y)
2476  False
2477  """
2478  return is_app_of(a, Z3_OP_MOD)
2479 
def is_mod(a)
Definition: z3py.py:2469
def is_app_of(a, k)
Definition: z3py.py:1128

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

2420 def is_mul(a):
2421  """Return `True` if `a` is an expression of the form b * c.
2422 
2423  >>> x, y = Ints('x y')
2424  >>> is_mul(x * y)
2425  True
2426  >>> is_mul(x - y)
2427  False
2428  """
2429  return is_app_of(a, Z3_OP_MUL)
2430 
def is_app_of(a, k)
Definition: z3py.py:1128
def is_mul(a)
Definition: z3py.py:2420

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

Referenced by AtLeast().

1376 def is_not(a):
1377  """Return `True` if `a` is a Z3 not expression.
1378 
1379  >>> p = Bool('p')
1380  >>> is_not(p)
1381  False
1382  >>> is_not(Not(p))
1383  True
1384  """
1385  return is_app_of(a, Z3_OP_NOT)
1386 
def is_not(a)
Definition: z3py.py:1376
def is_app_of(a, k)
Definition: z3py.py:1128

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

1365 def is_or(a):
1366  """Return `True` if `a` is a Z3 or expression.
1367 
1368  >>> p, q = Bools('p q')
1369  >>> is_or(Or(p, q))
1370  True
1371  >>> is_or(And(p, q))
1372  False
1373  """
1374  return is_app_of(a, Z3_OP_OR)
1375 
def is_or(a)
Definition: z3py.py:1365
def is_app_of(a, k)
Definition: z3py.py:1128

§ is_pattern()

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

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

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

Definition at line 1630 of file z3py.py.

Referenced by MultiPattern().

1630 def is_pattern(a):
1631  """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1632 
1633  See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
1634 
1635  >>> f = Function('f', IntSort(), IntSort())
1636  >>> x = Int('x')
1637  >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1638  >>> q
1639  ForAll(x, f(x) == 0)
1640  >>> q.num_patterns()
1641  1
1642  >>> is_pattern(q.pattern(0))
1643  True
1644  >>> q.pattern(0)
1645  f(Var(0))
1646  """
1647  return isinstance(a, PatternRef)
1648 
def is_pattern(a)
Definition: z3py.py:1630

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

Referenced by eq().

7348 def is_probe(p):
7349  """Return `True` if `p` is a Z3 probe.
7350 
7351  >>> is_probe(Int('x'))
7352  False
7353  >>> is_probe(Probe('memory'))
7354  True
7355  """
7356  return isinstance(p, Probe)
7357 
def is_probe(p)
Definition: z3py.py:7348

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

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

1833 def is_quantifier(a):
1834  """Return `True` if `a` is a Z3 quantifier.
1835 
1836  >>> f = Function('f', IntSort(), IntSort())
1837  >>> x = Int('x')
1838  >>> q = ForAll(x, f(x) == 0)
1839  >>> is_quantifier(q)
1840  True
1841  >>> is_quantifier(f(x))
1842  False
1843  """
1844  return isinstance(a, QuantifierRef)
1845 
def is_quantifier(a)
Definition: z3py.py:1833

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

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

2375 def is_rational_value(a):
2376  """Return `True` if `a` is rational value of sort Real.
2377 
2378  >>> is_rational_value(RealVal(1))
2379  True
2380  >>> is_rational_value(RealVal("3/5"))
2381  True
2382  >>> is_rational_value(IntVal(1))
2383  False
2384  >>> is_rational_value(1)
2385  False
2386  >>> n = Real('x') + 1
2387  >>> n.arg(1)
2388  1
2389  >>> is_rational_value(n.arg(1))
2390  True
2391  >>> is_rational_value(Real('x'))
2392  False
2393  """
2394  return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2395 
def is_arith(a)
Definition: z3py.py:2290
def is_rational_value(a)
Definition: z3py.py:2375

§ is_re()

def z3py.is_re (   s)

Definition at line 9600 of file z3py.py.

9600 def is_re(s):
9601  return isinstance(s, ReRef)
9602 
9603 
def is_re(s)
Definition: z3py.py:9600

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

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

2328 def is_real(a):
2329  """Return `True` if `a` is a real expression.
2330 
2331  >>> x = Int('x')
2332  >>> is_real(x + 1)
2333  False
2334  >>> y = Real('y')
2335  >>> is_real(y)
2336  True
2337  >>> is_real(y + 1)
2338  True
2339  >>> is_real(1)
2340  False
2341  >>> is_real(RealVal(1))
2342  True
2343  """
2344  return is_arith(a) and a.is_real()
2345 
def is_real(a)
Definition: z3py.py:2328
def is_arith(a)
Definition: z3py.py:2290

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

4257 def is_select(a):
4258  """Return `True` if `a` is a Z3 array select application.
4259 
4260  >>> a = Array('a', IntSort(), IntSort())
4261  >>> is_select(a)
4262  False
4263  >>> i = Int('i')
4264  >>> is_select(a[i])
4265  True
4266  """
4267  return is_app_of(a, Z3_OP_SELECT)
4268 
def is_select(a)
Definition: z3py.py:4257
def is_app_of(a, k)
Definition: z3py.py:1128

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

9412 def is_seq(a):
9413  """Return `True` if `a` is a Z3 sequence expression.
9414  >>> print (is_seq(Unit(IntVal(0))))
9415  True
9416  >>> print (is_seq(StringVal("abc")))
9417  True
9418  """
9419  return isinstance(a, SeqRef)
9420 
def is_seq(a)
Definition: z3py.py:9412

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

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

563 def is_sort(s):
564  """Return `True` if `s` is a Z3 sort.
565 
566  >>> is_sort(IntSort())
567  True
568  >>> is_sort(Int('x'))
569  False
570  >>> is_expr(Int('x'))
571  True
572  """
573  return isinstance(s, SortRef)
574 
def is_sort(s)
Definition: z3py.py:563

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

4269 def is_store(a):
4270  """Return `True` if `a` is a Z3 array store application.
4271 
4272  >>> a = Array('a', IntSort(), IntSort())
4273  >>> is_store(a)
4274  False
4275  >>> is_store(Store(a, 0, 1))
4276  True
4277  """
4278  return is_app_of(a, Z3_OP_STORE)
4279 
def is_store(a)
Definition: z3py.py:4269
def is_app_of(a, k)
Definition: z3py.py:1128

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

9421 def is_string(a):
9422  """Return `True` if `a` is a Z3 string expression.
9423  >>> print (is_string(StringVal("ab")))
9424  True
9425  """
9426  return isinstance(a, SeqRef) and a.is_string()
9427 
def is_string(a)
Definition: z3py.py:9421

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

9428 def is_string_value(a):
9429  """return 'True' if 'a' is a Z3 string constant expression.
9430  >>> print (is_string_value(StringVal("a")))
9431  True
9432  >>> print (is_string_value(StringVal("a") + StringVal("b")))
9433  False
9434  """
9435  return isinstance(a, SeqRef) and a.is_string_value()
9436 
9437 
def is_string_value(a)
Definition: z3py.py:9428

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

2431 def is_sub(a):
2432  """Return `True` if `a` is an expression of the form b - c.
2433 
2434  >>> x, y = Ints('x y')
2435  >>> is_sub(x - y)
2436  True
2437  >>> is_sub(x + y)
2438  False
2439  """
2440  return is_app_of(a, Z3_OP_SUB)
2441 
def is_app_of(a, k)
Definition: z3py.py:1128
def is_sub(a)
Definition: z3py.py:2431

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

2549 def is_to_int(a):
2550  """Return `True` if `a` is an expression of the form ToInt(b).
2551 
2552  >>> x = Real('x')
2553  >>> n = ToInt(x)
2554  >>> n
2555  ToInt(x)
2556  >>> is_to_int(n)
2557  True
2558  >>> is_to_int(x)
2559  False
2560  """
2561  return is_app_of(a, Z3_OP_TO_INT)
2562 
def is_app_of(a, k)
Definition: z3py.py:1128
def is_to_int(a)
Definition: z3py.py:2549

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

2535 def is_to_real(a):
2536  """Return `True` if `a` is an expression of the form ToReal(b).
2537 
2538  >>> x = Int('x')
2539  >>> n = ToReal(x)
2540  >>> n
2541  ToReal(x)
2542  >>> is_to_real(n)
2543  True
2544  >>> is_to_real(x)
2545  False
2546  """
2547  return is_app_of(a, Z3_OP_TO_REAL)
2548 
def is_to_real(a)
Definition: z3py.py:2535
def is_app_of(a, k)
Definition: z3py.py:1128

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

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

1324 def is_true(a):
1325  """Return `True` if `a` is the Z3 true expression.
1326 
1327  >>> p = Bool('p')
1328  >>> is_true(p)
1329  False
1330  >>> is_true(simplify(p == p))
1331  True
1332  >>> x = Real('x')
1333  >>> is_true(x == 0)
1334  False
1335  >>> # True is a Python Boolean expression
1336  >>> is_true(True)
1337  False
1338  """
1339  return is_app_of(a, Z3_OP_TRUE)
1340 
def is_true(a)
Definition: z3py.py:1324
def is_app_of(a, k)
Definition: z3py.py:1128

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

Referenced by get_var_index().

1072 def is_var(a):
1073  """Return `True` if `a` is variable.
1074 
1075  Z3 uses de-Bruijn indices for representing bound variables in
1076  quantifiers.
1077 
1078  >>> x = Int('x')
1079  >>> is_var(x)
1080  False
1081  >>> is_const(x)
1082  True
1083  >>> f = Function('f', IntSort(), IntSort())
1084  >>> # Z3 replaces x with bound variables when ForAll is executed.
1085  >>> q = ForAll(x, f(x) == x)
1086  >>> b = q.body()
1087  >>> b
1088  f(Var(0)) == Var(0)
1089  >>> b.arg(1)
1090  Var(0)
1091  >>> is_var(b.arg(1))
1092  True
1093  """
1094  return is_expr(a) and _ast_kind(a.ctx, a) == Z3_VAR_AST
1095 
def is_expr(a)
Definition: z3py.py:1007
def is_var(a)
Definition: z3py.py:1072

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

Referenced by is_is_int().

2942 def IsInt(a):
2943  """ Return the Z3 predicate IsInt(a).
2944 
2945  >>> x = Real('x')
2946  >>> IsInt(x + "1/2")
2947  IsInt(x + 1/2)
2948  >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
2949  [x = 1/2]
2950  >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
2951  no solution
2952  """
2953  if __debug__:
2954  _z3_assert(a.is_real(), "Z3 real expression expected.")
2955  ctx = a.ctx
2956  return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
2957 
def IsInt(a)
Definition: z3py.py:2942
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.

§ K()

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

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

Definition at line 4229 of file z3py.py.

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

4229 def K(dom, v):
4230  """Return a Z3 constant array expression.
4231 
4232  >>> a = K(IntSort(), 10)
4233  >>> a
4234  K(Int, 10)
4235  >>> a.sort()
4236  Array(Int, Int)
4237  >>> i = Int('i')
4238  >>> a[i]
4239  K(Int, 10)[i]
4240  >>> simplify(a[i])
4241  10
4242  """
4243  if __debug__:
4244  _z3_assert(is_sort(dom), "Z3 sort expected")
4245  ctx = dom.ctx
4246  if not is_expr(v):
4247  v = _py2expr(v, ctx)
4248  return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
4249 
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
def is_sort(s)
Definition: z3py.py:563
def K(dom, v)
Definition: z3py.py:4229
def is_expr(a)
Definition: z3py.py:1007

§ Length()

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

Definition at line 9557 of file z3py.py.

9557 def Length(s):
9558  """Obtain the length of a sequence 's'
9559  >>> l = Length(StringVal("abc"))
9560  >>> simplify(l)
9561  3
9562  """
9563  s = _coerce_seq(s)
9564  return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
9565 
def Length(s)
Definition: z3py.py:9557

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

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

3807 def LShR(a, b):
3808  """Create the Z3 expression logical right shift.
3809 
3810  Use the operator >> for the arithmetical right shift.
3811 
3812  >>> x, y = BitVecs('x y', 32)
3813  >>> LShR(x, y)
3814  LShR(x, y)
3815  >>> (x >> y).sexpr()
3816  '(bvashr x y)'
3817  >>> LShR(x, y).sexpr()
3818  '(bvlshr x y)'
3819  >>> BitVecVal(4, 3)
3820  4
3821  >>> BitVecVal(4, 3).as_signed_long()
3822  -4
3823  >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3824  -2
3825  >>> simplify(BitVecVal(4, 3) >> 1)
3826  6
3827  >>> simplify(LShR(BitVecVal(4, 3), 1))
3828  2
3829  >>> simplify(BitVecVal(2, 3) >> 1)
3830  1
3831  >>> simplify(LShR(BitVecVal(2, 3), 1))
3832  1
3833  """
3834  _check_bv_args(a, b)
3835  a, b = _coerce_exprs(a, b)
3836  return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3837 
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:3807

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

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

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

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

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

4207 def Map(f, *args):
4208  """Return a Z3 map array expression.
4209 
4210  >>> f = Function('f', IntSort(), IntSort(), IntSort())
4211  >>> a1 = Array('a1', IntSort(), IntSort())
4212  >>> a2 = Array('a2', IntSort(), IntSort())
4213  >>> b = Map(f, a1, a2)
4214  >>> b
4215  Map(f, a1, a2)
4216  >>> prove(b[0] == f(a1[0], a2[0]))
4217  proved
4218  """
4219  args = _get_args(args)
4220  if __debug__:
4221  _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
4222  _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
4223  _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
4224  _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
4225  _args, sz = _to_ast_array(args)
4226  ctx = f.ctx
4227  return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
4228 
def is_array(a)
Definition: z3py.py:4033
def Map(f, args)
Definition: z3py.py:4207
Z3_ast Z3_API Z3_mk_map(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast const *args)
Map f on the argument arrays.
def is_func_decl(a)
Definition: z3py.py:726

§ MultiPattern()

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

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

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

Definition at line 1649 of file z3py.py.

1649 def MultiPattern(*args):
1650  """Create a Z3 multi-pattern using the given expressions `*args`
1651 
1652  See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
1653 
1654  >>> f = Function('f', IntSort(), IntSort())
1655  >>> g = Function('g', IntSort(), IntSort())
1656  >>> x = Int('x')
1657  >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
1658  >>> q
1659  ForAll(x, f(x) != g(x))
1660  >>> q.num_patterns()
1661  1
1662  >>> is_pattern(q.pattern(0))
1663  True
1664  >>> q.pattern(0)
1665  MultiPattern(f(Var(0)), g(Var(0)))
1666  """
1667  if __debug__:
1668  _z3_assert(len(args) > 0, "At least one argument expected")
1669  _z3_assert(all([ is_expr(a) for a in args ]), "Z3 expressions expected")
1670  ctx = args[0].ctx
1671  args, sz = _to_ast_array(args)
1672  return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
1673 
def MultiPattern(args)
Definition: z3py.py:1649
def is_expr(a)
Definition: z3py.py:1007

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

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

1525 def Not(a, ctx=None):
1526  """Create a Z3 not expression or probe.
1527 
1528  >>> p = Bool('p')
1529  >>> Not(Not(p))
1530  Not(Not(p))
1531  >>> simplify(Not(Not(p)))
1532  p
1533  """
1534  ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1535  if is_probe(a):
1536  # Not is also used to build probes
1537  return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1538  else:
1539  s = BoolSort(ctx)
1540  a = s.cast(a)
1541  return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1542 
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
def Not(a, ctx=None)
Definition: z3py.py:1525
def is_probe(p)
Definition: z3py.py:7348
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.
def BoolSort(ctx=None)
Definition: z3py.py:1407

§ open_log()

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

Definition at line 92 of file z3py.py.

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

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

9648 def Option(re):
9649  """Create the regular expression that optionally accepts the argument.
9650  >>> re = Option(Re("a"))
9651  >>> print(simplify(InRe("a", re)))
9652  True
9653  >>> print(simplify(InRe("", re)))
9654  True
9655  >>> print(simplify(InRe("aa", re)))
9656  False
9657  """
9658  return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
9659 
def Option(re)
Definition: z3py.py:9648

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

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

1583 def Or(*args):
1584  """Create a Z3 or-expression or or-probe.
1585 
1586  >>> p, q, r = Bools('p q r')
1587  >>> Or(p, q, r)
1588  Or(p, q, r)
1589  >>> P = BoolVector('p', 5)
1590  >>> Or(P)
1591  Or(p__0, p__1, p__2, p__3, p__4)
1592  """
1593  last_arg = None
1594  if len(args) > 0:
1595  last_arg = args[len(args)-1]
1596  if isinstance(last_arg, Context):
1597  ctx = args[len(args)-1]
1598  args = args[:len(args)-1]
1599  else:
1600  ctx = main_ctx()
1601  args = _get_args(args)
1602  ctx_args = _ctx_from_ast_arg_list(args, ctx)
1603  if __debug__:
1604  _z3_assert(ctx_args is None or ctx_args == ctx, "context mismatch")
1605  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1606  if _has_probe(args):
1607  return _probe_or(args, ctx)
1608  else:
1609  args = _coerce_expr_list(args, ctx)
1610  _args, sz = _to_ast_array(args)
1611  return BoolRef(Z3_mk_or(ctx.ref(), sz, _args), ctx)
1612 
Z3_ast Z3_API Z3_mk_or(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] or ... or args[num_args-1].
def main_ctx()
Definition: z3py.py:197
def Or(args)
Definition: z3py.py:1583

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

7080 def OrElse(*ts, **ks):
7081  """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
7082 
7083  >>> x = Int('x')
7084  >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
7085  >>> # Tactic split-clause fails if there is no clause in the given goal.
7086  >>> t(x == 0)
7087  [[x == 0]]
7088  >>> t(Or(x == 0, x == 1))
7089  [[x == 0], [x == 1]]
7090  """
7091  if __debug__:
7092  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7093  ctx = ks.get('ctx', None)
7094  num = len(ts)
7095  r = ts[0]
7096  for i in range(num - 1):
7097  r = _or_else(r, ts[i+1], ctx)
7098  return r
7099 
def OrElse(ts, ks)
Definition: z3py.py:7080

§ ParAndThen()

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

Definition at line 7132 of file z3py.py.

7132 def ParAndThen(t1, t2, ctx=None):
7133  """Alias for ParThen(t1, t2, ctx)."""
7134  return ParThen(t1, t2, ctx)
7135 
def ParAndThen(t1, t2, ctx=None)
Definition: z3py.py:7132
def ParThen(t1, t2, ctx=None)
Definition: z3py.py:7118

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

7100 def ParOr(*ts, **ks):
7101  """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
7102 
7103  >>> x = Int('x')
7104  >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
7105  >>> t(x + 1 == 2)
7106  [[x == 1]]
7107  """
7108  if __debug__:
7109  _z3_assert(len(ts) >= 2, "At least two arguments expected")
7110  ctx = _get_ctx(ks.get('ctx', None))
7111  ts = [ _to_tactic(t, ctx) for t in ts ]
7112  sz = len(ts)
7113  _args = (TacticObj * sz)()
7114  for i in range(sz):
7115  _args[i] = ts[i].tactic
7116  return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
7117 
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:7100

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

7879 def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
7880  """Parse a file in SMT 2.0 format using the given sorts and decls.
7881 
7882  This function is similar to parse_smt2_string().
7883  """
7884  ctx = _get_ctx(ctx)
7885  ssz, snames, ssorts = _dict2sarray(sorts, ctx)
7886  dsz, dnames, ddecls = _dict2darray(decls, ctx)
7887  return _to_expr_ref(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
7888 
Z3_ast Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Similar to Z3_parse_smtlib2_string, but reads the benchmark from a file.
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
Definition: z3py.py:7879

§ parse_smt2_string()

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

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

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

Definition at line 7859 of file z3py.py.

Referenced by parse_smt2_file().

7859 def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
7860  """Parse a string in SMT 2.0 format using the given sorts and decls.
7861 
7862  The arguments sorts and decls are Python dictionaries used to initialize
7863  the symbol table used for the SMT 2.0 parser.
7864 
7865  >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
7866  And(x > 0, x < 10)
7867  >>> x, y = Ints('x y')
7868  >>> f = Function('f', IntSort(), IntSort())
7869  >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
7870  x + f(y) > 0
7871  >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() }) a > 0
7872  """
7873  ctx = _get_ctx(ctx)
7874  ssz, snames, ssorts = _dict2sarray(sorts, ctx)
7875  dsz, dnames, ddecls = _dict2darray(decls, ctx)
7876  return _to_expr_ref(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
7877 
7878 
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
Definition: z3py.py:7859

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

Referenced by ParAndThen().

7118 def ParThen(t1, t2, ctx=None):
7119  """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.
7120 
7121  >>> x, y = Ints('x y')
7122  >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
7123  >>> t(And(Or(x == 1, x == 2), y == x + 1))
7124  [[x == 1, y == 2], [x == 2, y == 3]]
7125  """
7126  t1 = _to_tactic(t1, ctx)
7127  t2 = _to_tactic(t2, ctx)
7128  if __debug__:
7129  _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
7130  return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
7131 
Z3_tactic Z3_API Z3_tactic_par_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and then t2 to every subgoal produced by t1...
def ParThen(t1, t2, ctx=None)
Definition: z3py.py:7118

§ PbEq()

def z3py.PbEq (   args,
  k 
)
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 7657 of file z3py.py.

7657 def PbEq(args, k):
7658  """Create a Pseudo-Boolean inequality k constraint.
7659 
7660  >>> a, b, c = Bools('a b c')
7661  >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
7662  """
7663  args = _get_args(args)
7664  args, coeffs = zip(*args)
7665  if __debug__:
7666  _z3_assert(len(args) > 0, "Non empty list of arguments expected")
7667  ctx = _ctx_from_ast_arg_list(args)
7668  if __debug__:
7669  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
7670  args = _coerce_expr_list(args, ctx)
7671  _args, sz = _to_ast_array(args)
7672  _coeffs = (ctypes.c_int * len(coeffs))()
7673  for i in range(len(coeffs)):
7674  _coeffs[i] = coeffs[i]
7675  return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
7676 
7677 
def PbEq(args, k)
Definition: z3py.py:7657

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

7637 def PbLe(args, k):
7638  """Create a Pseudo-Boolean inequality k constraint.
7639 
7640  >>> a, b, c = Bools('a b c')
7641  >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
7642  """
7643  args = _get_args(args)
7644  args, coeffs = zip(*args)
7645  if __debug__:
7646  _z3_assert(len(args) > 0, "Non empty list of arguments expected")
7647  ctx = _ctx_from_ast_arg_list(args)
7648  if __debug__:
7649  _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
7650  args = _coerce_expr_list(args, ctx)
7651  _args, sz = _to_ast_array(args)
7652  _coeffs = (ctypes.c_int * len(coeffs))()
7653  for i in range(len(coeffs)):
7654  _coeffs[i] = coeffs[i]
7655  return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
7656 
def PbLe(args, k)
Definition: z3py.py:7637

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

9636 def Plus(re):
9637  """Create the regular expression accepting one or more repetitions of argument.
9638  >>> re = Plus(Re("a"))
9639  >>> print(simplify(InRe("aa", re)))
9640  True
9641  >>> print(simplify(InRe("ab", re)))
9642  False
9643  >>> print(simplify(InRe("", re)))
9644  False
9645  """
9646  return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
9647 
def Plus(re)
Definition: z3py.py:9636

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

9476 def PrefixOf(a, b):
9477  """Check if 'a' is a prefix of 'b'
9478  >>> s1 = PrefixOf("ab", "abc")
9479  >>> simplify(s1)
9480  True
9481  >>> s2 = PrefixOf("bc", "abc")
9482  >>> simplify(s2)
9483  False
9484  """
9485  ctx = _get_ctx2(a, b)
9486  a = _coerce_seq(a, ctx)
9487  b = _coerce_seq(b, ctx)
9488  return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
9489 
def PrefixOf(a, b)
Definition: z3py.py:9476

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

Referenced by describe_probes().

7374 def probe_description(name, ctx=None):
7375  """Return a short description for the probe named `name`.
7376 
7377  >>> d = probe_description('memory')
7378  """
7379  ctx = _get_ctx(ctx)
7380  return Z3_probe_get_descr(ctx.ref(), name)
7381 
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.
def probe_description(name, ctx=None)
Definition: z3py.py:7374

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

Referenced by describe_probes().

7364 def probes(ctx=None):
7365  """Return a list of all available probes in Z3.
7366 
7367  >>> l = probes()
7368  >>> l.count('memory') == 1
7369  True
7370  """
7371  ctx = _get_ctx(ctx)
7372  return [ Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref())) ]
7373 
Z3_string Z3_API Z3_get_probe_name(Z3_context c, unsigned i)
Return the name of the i probe.
def probes(ctx=None)
Definition: z3py.py:7364
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.

§ Product()

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

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

Definition at line 7572 of file z3py.py.

Referenced by BitVecs().

7572 def Product(*args):
7573  """Create the product of the Z3 expressions.
7574 
7575  >>> a, b, c = Ints('a b c')
7576  >>> Product(a, b, c)
7577  a*b*c
7578  >>> Product([a, b, c])
7579  a*b*c
7580  >>> A = IntVector('a', 5)
7581  >>> Product(A)
7582  a__0*a__1*a__2*a__3*a__4
7583  """
7584  args = _get_args(args)
7585  if len(args) == 0:
7586  return 1
7587  ctx = _ctx_from_ast_arg_list(args)
7588  if ctx is None:
7589  return _reduce(lambda a, b: a * b, args, 1)
7590  args = _coerce_expr_list(args, ctx)
7591  if is_bv(args[0]):
7592  return _reduce(lambda a, b: a * b, args, 1)
7593  else:
7594  _args, sz = _to_ast_array(args)
7595  return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
7596 
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:7572
def is_bv(a)
Definition: z3py.py:3481

§ prove()

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

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

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

Definition at line 7735 of file z3py.py.

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

7735 def prove(claim, **keywords):
7736  """Try to prove the given claim.
7737 
7738  This is a simple function for creating demonstrations. It tries to prove
7739  `claim` by showing the negation is unsatisfiable.
7740 
7741  >>> p, q = Bools('p q')
7742  >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
7743  proved
7744  """
7745  if __debug__:
7746  _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
7747  s = Solver()
7748  s.set(**keywords)
7749  s.add(Not(claim))
7750  if keywords.get('show', False):
7751  print(s)
7752  r = s.check()
7753  if r == unsat:
7754  print("proved")
7755  elif r == unknown:
7756  print("failed to prove")
7757  print(s.model())
7758  else:
7759  print("counterexample")
7760  print(s.model())
7761 
def prove(claim, keywords)
Definition: z3py.py:7735
def Not(a, ctx=None)
Definition: z3py.py:1525
def is_bool(a)
Definition: z3py.py:1307

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

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

2796 def Q(a, b, ctx=None):
2797  """Return a Z3 rational a/b.
2798 
2799  If `ctx=None`, then the global context is used.
2800 
2801  >>> Q(3,5)
2802  3/5
2803  >>> Q(3,5).sort()
2804  Real
2805  """
2806  return simplify(RatVal(a, b))
2807 
def simplify(a, arguments, keywords)
Utils.
Definition: z3py.py:7468
def RatVal(a, b, ctx=None)
Definition: z3py.py:2781
def Q(a, b, ctx=None)
Definition: z3py.py:2796

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

2781 def RatVal(a, b, ctx=None):
2782  """Return a Z3 rational a/b.
2783 
2784  If `ctx=None`, then the global context is used.
2785 
2786  >>> RatVal(3,5)
2787  3/5
2788  >>> RatVal(3,5).sort()
2789  Real
2790  """
2791  if __debug__:
2792  _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
2793  _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
2794  return simplify(RealVal(a, ctx)/RealVal(b, ctx))
2795 
def simplify(a, arguments, keywords)
Utils.
Definition: z3py.py:7468
def RatVal(a, b, ctx=None)
Definition: z3py.py:2781
def RealVal(val, ctx=None)
Definition: z3py.py:2763

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

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

9566 def Re(s, ctx=None):
9567  """The regular expression that accepts sequence 's'
9568  >>> s1 = Re("ab")
9569  >>> s2 = Re(StringVal("ab"))
9570  >>> s3 = Re(Unit(BoolVal(True)))
9571  """
9572  s = _coerce_seq(s, ctx)
9573  return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
9574 
9575 
9576 
9577 
def Re(s, ctx=None)
Definition: z3py.py:9566

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

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

2856 def Real(name, ctx=None):
2857  """Return a real constant named `name`. If `ctx=None`, then the global context is used.
2858 
2859  >>> x = Real('x')
2860  >>> is_real(x)
2861  True
2862  >>> is_real(x + 1)
2863  True
2864  """
2865  ctx = _get_ctx(ctx)
2866  return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
2867 
def RealSort(ctx=None)
Definition: z3py.py:2721
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:100
def Real(name, ctx=None)
Definition: z3py.py:2856

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

Referenced by is_div().

2868 def Reals(names, ctx=None):
2869  """Return a tuple of real constants.
2870 
2871  >>> x, y, z = Reals('x y z')
2872  >>> Sum(x, y, z)
2873  x + y + z
2874  >>> Sum(x, y, z).sort()
2875  Real
2876  """
2877  ctx = _get_ctx(ctx)
2878  if isinstance(names, str):
2879  names = names.split(" ")
2880  return [Real(name, ctx) for name in names]
2881 
def Real(name, ctx=None)
Definition: z3py.py:2856
def Reals(names, ctx=None)
Definition: z3py.py:2868

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

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

2721 def RealSort(ctx=None):
2722  """Return the real sort in the given context. If `ctx=None`, then the global context is used.
2723 
2724  >>> RealSort()
2725  Real
2726  >>> x = Const('x', RealSort())
2727  >>> is_real(x)
2728  True
2729  >>> is_int(x)
2730  False
2731  >>> x.sort() == RealSort()
2732  True
2733  """
2734  ctx = _get_ctx(ctx)
2735  return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
2736 
def RealSort(ctx=None)
Definition: z3py.py:2721
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.

§ RealVal()

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

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

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

Definition at line 2763 of file z3py.py.

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

2763 def RealVal(val, ctx=None):
2764  """Return a Z3 real value.
2765 
2766  `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
2767  If `ctx=None`, then the global context is used.
2768 
2769  >>> RealVal(1)
2770  1
2771  >>> RealVal(1).sort()
2772  Real
2773  >>> RealVal("3/5")
2774  3/5
2775  >>> RealVal("1.5")
2776  3/2
2777  """
2778  ctx = _get_ctx(ctx)
2779  return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), RealSort(ctx).ast), ctx)
2780 
def RealSort(ctx=None)
Definition: z3py.py:2721
def RealVal(val, ctx=None)
Definition: z3py.py:2763

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

Referenced by RealVarVector().

1230 def RealVar(idx, ctx=None):
1231  """
1232  Create a real free variable. Free variables are used to create quantified formulas.
1233  They are also used to create polynomials.
1234 
1235  >>> RealVar(0)
1236  Var(0)
1237  """
1238  return Var(idx, RealSort(ctx))
1239 
def RealSort(ctx=None)
Definition: z3py.py:2721
def Var(idx, s)
Definition: z3py.py:1218
def RealVar(idx, ctx=None)
Definition: z3py.py:1230

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

1240 def RealVarVector(n, ctx=None):
1241  """
1242  Create a list of Real free variables.
1243  The variables have ids: 0, 1, ..., n-1
1244 
1245  >>> x0, x1, x2, x3 = RealVarVector(4)
1246  >>> x2
1247  Var(2)
1248  """
1249  return [ RealVar(i, ctx) for i in range(n) ]
1250 
def RealVarVector(n, ctx=None)
Definition: z3py.py:1240
def RealVar(idx, ctx=None)
Definition: z3py.py:1230

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

2882 def RealVector(prefix, sz, ctx=None):
2883  """Return a list of real constants of size `sz`.
2884 
2885  >>> X = RealVector('x', 3)
2886  >>> X
2887  [x__0, x__1, x__2]
2888  >>> Sum(X)
2889  x__0 + x__1 + x__2
2890  >>> Sum(X).sort()
2891  Real
2892  """
2893  return [ Real('%s__%s' % (prefix, i)) for i in range(sz) ]
2894 
def RealVector(prefix, sz, ctx=None)
Definition: z3py.py:2882
def Real(name, ctx=None)
Definition: z3py.py:2856

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

7149 def Repeat(t, max=4294967295, ctx=None):
7150  """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.
7151 
7152  >>> x, y = Ints('x y')
7153  >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
7154  >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
7155  >>> r = t(c)
7156  >>> for subgoal in r: print(subgoal)
7157  [x == 0, y == 0, x > y]
7158  [x == 0, y == 1, x > y]
7159  [x == 1, y == 0, x > y]
7160  [x == 1, y == 1, x > y]
7161  >>> t = Then(t, Tactic('propagate-values'))
7162  >>> t(c)
7163  [[x == 1, y == 0]]
7164  """
7165  t = _to_tactic(t, ctx)
7166  return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
7167 
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:7149

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

3924 def RepeatBitVec(n, a):
3925  """Return an expression representing `n` copies of `a`.
3926 
3927  >>> x = BitVec('x', 8)
3928  >>> n = RepeatBitVec(4, x)
3929  >>> n
3930  RepeatBitVec(4, x)
3931  >>> n.size()
3932  32
3933  >>> v0 = BitVecVal(10, 4)
3934  >>> print("%.x" % v0.as_long())
3935  a
3936  >>> v = simplify(RepeatBitVec(4, v0))
3937  >>> v.size()
3938  16
3939  >>> print("%.x" % v.as_long())
3940  aaaa
3941  """
3942  if __debug__:
3943  _z3_assert(_is_int(n), "First argument must be an integer")
3944  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
3945  return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
3946 
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
def is_bv(a)
Definition: z3py.py:3481
def RepeatBitVec(n, a)
Definition: z3py.py:3924

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

9523 def Replace(s, src, dst):
9524  """Replace the first occurrence of 'src' by 'dst' in 's'
9525  >>> r = Replace("aaa", "a", "b")
9526  >>> simplify(r)
9527  "baa"
9528  """
9529  ctx = _get_ctx2(dst, s)
9530  if ctx is None and is_expr(src):
9531  ctx = src.ctx
9532  src = _coerce_seq(src, ctx)
9533  dst = _coerce_seq(dst, ctx)
9534  s = _coerce_seq(s, ctx)
9535  return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
9536 
def Replace(s, src, dst)
Definition: z3py.py:9523
def is_expr(a)
Definition: z3py.py:1007

§ reset_params()

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

Definition at line 246 of file z3py.py.

246 def reset_params():
247  """Reset all global (or module) parameters.
248  """
250 
def reset_params()
Definition: z3py.py:246
void Z3_API Z3_global_param_reset_all(void)
Restore the value of all global (and module) parameters. This command will not affect already created...

§ ReSort()

def z3py.ReSort (   s)

Definition at line 9584 of file z3py.py.

Referenced by Context.mkReSort(), Context.MkReSort(), Sort.toString(), and Sort.ToString().

9584 def ReSort(s):
9585  if is_ast(s):
9586  return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.as_ast()), ctx)
9587  if s is None or isinstance(s, Context):
9588  ctx = _get_ctx(s)
9589  return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), ctx)
9590  raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
9591 
9592 
def ReSort(s)
Definition: z3py.py:9584
def is_ast(a)
Definition: z3py.py:380

§ RNA()

def z3py.RNA (   ctx = None)

Definition at line 8409 of file z3py.py.

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

§ RNE()

def z3py.RNE (   ctx = None)

Definition at line 8401 of file z3py.py.

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

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

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

3838 def RotateLeft(a, b):
3839  """Return an expression representing `a` rotated to the left `b` times.
3840 
3841  >>> a, b = BitVecs('a b', 16)
3842  >>> RotateLeft(a, b)
3843  RotateLeft(a, b)
3844  >>> simplify(RotateLeft(a, 0))
3845  a
3846  >>> simplify(RotateLeft(a, 16))
3847  a
3848  """
3849  _check_bv_args(a, b)
3850  a, b = _coerce_exprs(a, b)
3851  return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3852 
def RotateLeft(a, b)
Definition: z3py.py:3838
Z3_ast Z3_API Z3_mk_ext_rotate_left(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the left t2 times.

§ RotateRight()

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

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

Definition at line 3853 of file z3py.py.

3853 def RotateRight(a, b):
3854  """Return an expression representing `a` rotated to the right `b` times.
3855 
3856  >>> a, b = BitVecs('a b', 16)
3857  >>> RotateRight(a, b)
3858  RotateRight(a, b)
3859  >>> simplify(RotateRight(a, 0))
3860  a
3861  >>> simplify(RotateRight(a, 16))
3862  a
3863  """
3864  _check_bv_args(a, b)
3865  a, b = _coerce_exprs(a, b)
3866  return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3867 
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:3853

§ RoundNearestTiesToAway()

def z3py.RoundNearestTiesToAway (   ctx = None)

Definition at line 8405 of file z3py.py.

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

§ RoundNearestTiesToEven()

def z3py.RoundNearestTiesToEven (   ctx = None)

Definition at line 8397 of file z3py.py.

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

§ RoundTowardNegative()

def z3py.RoundTowardNegative (   ctx = None)

Definition at line 8421 of file z3py.py.

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

§ RoundTowardPositive()

def z3py.RoundTowardPositive (   ctx = None)

Definition at line 8413 of file z3py.py.

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

§ RoundTowardZero()

def z3py.RoundTowardZero (   ctx = None)

Definition at line 8429 of file z3py.py.

8429 def RoundTowardZero(ctx=None):
8430  ctx = _get_ctx(ctx)
8431  return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
8432 
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:8429

§ RTN()

def z3py.RTN (   ctx = None)

Definition at line 8425 of file z3py.py.

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

§ RTP()

def z3py.RTP (   ctx = None)

Definition at line 8417 of file z3py.py.

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

§ RTZ()

def z3py.RTZ (   ctx = None)

Definition at line 8433 of file z3py.py.

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

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

§ Select()

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

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

Definition at line 4192 of file z3py.py.

4192 def Select(a, i):
4193  """Return a Z3 select array expression.
4194 
4195  >>> a = Array('a', IntSort(), IntSort())
4196  >>> i = Int('i')
4197  >>> Select(a, i)
4198  a[i]
4199  >>> eq(Select(a, i), a[i])
4200  True
4201  """
4202  if __debug__:
4203  _z3_assert(is_array(a), "First argument must be a Z3 array expression")
4204  return a[i]
4205 
4206 
def is_array(a)
Definition: z3py.py:4033
def Select(a, i)
Definition: z3py.py:4192

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

Referenced by Empty(), SeqSortRef.is_string(), Context.mkSeqSort(), Context.MkSeqSort(), Context.mkStringSort(), Sort.toString(), and Sort.ToString().

9357 def SeqSort(s):
9358  """Create a sequence sort over elements provided in the argument
9359  >>> s = SeqSort(IntSort())
9360  >>> s == Unit(IntVal(1)).sort()
9361  True
9362  """
9363  return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
9364 
def SeqSort(s)
Definition: z3py.py:9357

§ sequence_interpolant()

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

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

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

Requires len(v) >= 1.

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

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

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

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

Definition at line 7996 of file z3py.py.

7996 def sequence_interpolant(v,p=None,ctx=None):
7997  """Compute interpolant for a sequence of formulas.
7998 
7999  If len(v) == N, and if the conjunction of the formulas in v is
8000  unsatisfiable, the interpolant is a sequence of formulas w
8001  such that len(w) = N-1 and v[0] implies w[0] and for i in 0..N-1:
8002 
8003  1) w[i] & v[i+1] implies w[i+1] (or false if i+1 = N)
8004  2) All uninterpreted symbols in w[i] occur in both v[0]..v[i]
8005  and v[i+1]..v[n]
8006 
8007  Requires len(v) >= 1.
8008 
8009  If a & b is satisfiable, raises an object of class ModelRef
8010  that represents a model of a & b.
8011 
8012  If neither a proof of unsatisfiability nor a model is obtained
8013  (for example, because of a timeout, or because models are disabled)
8014  then None is returned.
8015 
8016  If parameters p are supplied, these are used in creating the
8017  solver that determines satisfiability.
8018 
8019  >>> x = Int('x')
8020  >>> y = Int('y')
8021  >>> print(sequence_interpolant([x < 0, y == x , y > 2]))
8022  [Not(x >= 0), Not(y >= 0)]
8023  """
8024  f = v[0]
8025  for i in range(1,len(v)):
8026  f = And(Interpolant(f),v[i])
8027  return tree_interpolant(f,p,ctx)
8028 
8029 
def And(args)
Definition: z3py.py:1550
def Interpolant(a, ctx=None)
Definition: z3py.py:7889
def sequence_interpolant(v, p=None, ctx=None)
Definition: z3py.py:7996
def tree_interpolant(pat, p=None, ctx=None)
Definition: z3py.py:7903

§ set_default_fp_sort()

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

Definition at line 8072 of file z3py.py.

8072 def set_default_fp_sort(ebits, sbits, ctx=None):
8073  global _dflt_fpsort_ebits
8074  global _dflt_fpsort_sbits
8075  _dflt_fpsort_ebits = ebits
8076  _dflt_fpsort_sbits = sbits
8077 
def set_default_fp_sort(ebits, sbits, ctx=None)
Definition: z3py.py:8072

§ set_default_rounding_mode()

def z3py.set_default_rounding_mode (   rm,
  ctx = None 
)

Definition at line 8056 of file z3py.py.

8056 def set_default_rounding_mode(rm, ctx=None):
8057  global _dflt_rounding_mode
8058  if is_fprm_value(rm):
8059  _dflt_rounding_mode = rm.decl().kind()
8060  else:
8061  _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO or
8062  _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE or
8063  _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE or
8064  _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN or
8065  _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY,
8066  "illegal rounding mode")
8067  _dflt_rounding_mode = rm
8068 
def set_default_rounding_mode(rm, ctx=None)
Definition: z3py.py:8056
def is_fprm_value(a)
Definition: z3py.py:8449

§ set_option()

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

Definition at line 251 of file z3py.py.

251 def set_option(*args, **kws):
252  """Alias for 'set_param' for backward compatibility.
253  """
254  return set_param(*args, **kws)
255 
def set_option(args, kws)
Definition: z3py.py:251
def set_param(args, kws)
Definition: z3py.py:223

§ set_param()

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

>>> set_param(precision=10)

Definition at line 223 of file z3py.py.

Referenced by set_option().

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

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

3868 def SignExt(n, a):
3869  """Return a bit-vector expression with `n` extra sign-bits.
3870 
3871  >>> x = BitVec('x', 16)
3872  >>> n = SignExt(8, x)
3873  >>> n.size()
3874  24
3875  >>> n
3876  SignExt(8, x)
3877  >>> n.sort()
3878  BitVec(24)
3879  >>> v0 = BitVecVal(2, 2)
3880  >>> v0
3881  2
3882  >>> v0.size()
3883  2
3884  >>> v = simplify(SignExt(6, v0))
3885  >>> v
3886  254
3887  >>> v.size()
3888  8
3889  >>> print("%.x" % v.as_long())
3890  fe
3891  """
3892  if __debug__:
3893  _z3_assert(_is_int(n), "First argument must be an integer")
3894  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
3895  return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
3896 
def SignExt(n, a)
Definition: z3py.py:3868
Z3_ast Z3_API Z3_mk_sign_ext(Z3_context c, unsigned i, Z3_ast t1)
Sign-extend of the given bit-vector to the (signed) equivalent bit-vector of size m+i...
def is_bv(a)
Definition: z3py.py:3481

§ SimpleSolver()

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

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

Definition at line 6301 of file z3py.py.

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

6301 def SimpleSolver(ctx=None):
6302  """Return a simple general purpose solver with limited amount of preprocessing.
6303 
6304  >>> s = SimpleSolver()
6305  >>> x = Int('x')
6306  >>> s.add(x > 0)
6307  >>> s.check()
6308  sat
6309  """
6310  ctx = _get_ctx(ctx)
6311  return Solver(Z3_mk_simple_solver(ctx.ref()), ctx)
6312 
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new (incremental) solver.
def SimpleSolver(ctx=None)
Definition: z3py.py:6301

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

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

7468 def simplify(a, *arguments, **keywords):
7469  """Simplify the expression `a` using the given options.
7470 
7471  This function has many options. Use `help_simplify` to obtain the complete list.
7472 
7473  >>> x = Int('x')
7474  >>> y = Int('y')
7475  >>> simplify(x + 1 + y + x + 1)
7476  2 + 2*x + y
7477  >>> simplify((x + 1)*(y + 1), som=True)
7478  1 + x + y + x*y
7479  >>> simplify(Distinct(x, y, 1), blast_distinct=True)
7480  And(Not(x == y), Not(x == 1), Not(y == 1))
7481  >>> simplify(And(x == 0, y == 1), elim_and=True)
7482  Not(Or(Not(x == 0), Not(y == 1)))
7483  """
7484  if __debug__:
7485  _z3_assert(is_expr(a), "Z3 expression expected")
7486  if len(arguments) > 0 or len(keywords) > 0:
7487  p = args2params(arguments, keywords, a.ctx)
7488  return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
7489  else:
7490  return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
7491 
def simplify(a, arguments, keywords)
Utils.
Definition: z3py.py:7468
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:4644
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
def is_expr(a)
Definition: z3py.py:1007

§ simplify_param_descrs()

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

Definition at line 7496 of file z3py.py.

7496 def simplify_param_descrs():
7497  """Return the set of parameter descriptions for Z3 `simplify` procedure."""
7498  return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
7499 
def main_ctx()
Definition: z3py.py:197
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:7496

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

Referenced by BV2Int(), and IsInt().

7678 def solve(*args, **keywords):
7679  """Solve the constraints `*args`.
7680 
7681  This is a simple function for creating demonstrations. It creates a solver,
7682  configure it using the options in `keywords`, adds the constraints
7683  in `args`, and invokes check.
7684 
7685  >>> a = Int('a')
7686  >>> solve(a > 0, a < 2)
7687  [a = 1]
7688  """
7689  s = Solver()
7690  s.set(**keywords)
7691  s.add(*args)
7692  if keywords.get('show', False):
7693  print(s)
7694  r = s.check()
7695  if r == unsat:
7696  print("no solution")
7697  elif r == unknown:
7698  print("failed to solve")
7699  try:
7700  print(s.model())
7701  except Z3Exception:
7702  return
7703  else:
7704  print(s.model())
7705 
def solve(args, keywords)
Definition: z3py.py:7678

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

7706 def solve_using(s, *args, **keywords):
7707  """Solve the constraints `*args` using solver `s`.
7708 
7709  This is a simple function for creating demonstrations. It is similar to `solve`,
7710  but it uses the given solver `s`.
7711  It configures solver `s` using the options in `keywords`, adds the constraints
7712  in `args`, and invokes check.
7713  """
7714  if __debug__:
7715  _z3_assert(isinstance(s, Solver), "Solver object expected")
7716  s.set(**keywords)
7717  s.add(*args)
7718  if keywords.get('show', False):
7719  print("Problem:")
7720  print(s)
7721  r = s.check()
7722  if r == unsat:
7723  print("no solution")
7724  elif r == unknown:
7725  print("failed to solve")
7726  try:
7727  print(s.model())
7728  except Z3Exception:
7729  return
7730  else:
7731  if keywords.get('show', False):
7732  print("Solution:")
7733  print(s.model())
7734 
def solve_using(s, args, keywords)
Definition: z3py.py:7706

§ SolverFor()

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

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

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

Definition at line 6281 of file z3py.py.

6281 def SolverFor(logic, ctx=None):
6282  """Create a solver customized for the given logic.
6283 
6284  The parameter `logic` is a string. It should be contains
6285  the name of a SMT-LIB logic.
6286  See http://www.smtlib.org/ for the name of all available logics.
6287 
6288  >>> s = SolverFor("QF_LIA")
6289  >>> x = Int('x')
6290  >>> s.add(x > 0)
6291  >>> s.add(x < 2)
6292  >>> s.check()
6293  sat
6294  >>> s.model()
6295  [x = 1]
6296  """
6297  ctx = _get_ctx(ctx)
6298  logic = to_symbol(logic)
6299  return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx)
6300 
def to_symbol(s, ctx=None)
Definition: z3py.py:100
Z3_solver Z3_API Z3_mk_solver_for_logic(Z3_context c, Z3_symbol logic)
Create a new solver customized for the given logic. It behaves like Z3_mk_solver if the logic is unkn...
def SolverFor(logic, ctx=None)
Definition: z3py.py:6281

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

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

2958 def Sqrt(a, ctx=None):
2959  """ Return a Z3 expression which represents the square root of a.
2960 
2961  >>> x = Real('x')
2962  >>> Sqrt(x)
2963  x**(1/2)
2964  """
2965  if not is_expr(a):
2966  ctx = _get_ctx(ctx)
2967  a = RealVal(a, ctx)
2968  return a ** "1/2"
2969 
def RealVal(val, ctx=None)
Definition: z3py.py:2763
def is_expr(a)
Definition: z3py.py:1007
def Sqrt(a, ctx=None)
Definition: z3py.py:2958

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

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

3787 def SRem(a, b):
3788  """Create the Z3 expression signed remainder.
3789 
3790  Use the operator % for signed modulus, and URem() for unsigned remainder.
3791 
3792  >>> x = BitVec('x', 32)
3793  >>> y = BitVec('y', 32)
3794  >>> SRem(x, y)
3795  SRem(x, y)
3796  >>> SRem(x, y).sort()
3797  BitVec(32)
3798  >>> (x % y).sexpr()
3799  '(bvsmod x y)'
3800  >>> SRem(x, y).sexpr()
3801  '(bvsrem x y)'
3802  """
3803  _check_bv_args(a, b)
3804  a, b = _coerce_exprs(a, b)
3805  return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3806 
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two&#39;s complement signed remainder (sign follows dividend).
def SRem(a, b)
Definition: z3py.py:3787

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

9660 def Star(re):
9661  """Create the regular expression accepting zero or more repetitions of argument.
9662  >>> re = Star(Re("a"))
9663  >>> print(simplify(InRe("aa", re)))
9664  True
9665  >>> print(simplify(InRe("ab", re)))
9666  False
9667  >>> print(simplify(InRe("", re)))
9668  True
9669  """
9670  return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
9671 
def Star(re)
Definition: z3py.py:9660

§ Store()

def z3py.Store (   a,
  i,
  v 
)
Return a Z3 store array expression.

>>> a    = Array('a', IntSort(), IntSort())
>>> i, v = Ints('i v')
>>> s    = Store(a, i, v)
>>> s.sort()
Array(Int, Int)
>>> prove(s[i] == v)
proved
>>> j    = Int('j')
>>> prove(Implies(i != j, s[j] == a[j]))
proved

Definition at line 4176 of file z3py.py.

Referenced by is_array(), and is_store().

4176 def Store(a, i, v):
4177  """Return a Z3 store array expression.
4178 
4179  >>> a = Array('a', IntSort(), IntSort())
4180  >>> i, v = Ints('i v')
4181  >>> s = Store(a, i, v)
4182  >>> s.sort()
4183  Array(Int, Int)
4184  >>> prove(s[i] == v)
4185  proved
4186  >>> j = Int('j')
4187  >>> prove(Implies(i != j, s[j] == a[j]))
4188  proved
4189  """
4190  return Update(a, i, v)
4191 
def Update(a, i, v)
Definition: z3py.py:4144
def Store(a, i, v)
Definition: z3py.py:4176

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

Referenced by Probe.apply(), Native.applyResultToString(), Native.astMapToString(), Native.astToString(), Native.astVectorToString(), Native.benchmarkToSmtlibString(), Context.Context(), Native.fixedpointGetHelp(), Native.fixedpointGetReasonUnknown(), Native.fixedpointToString(), Native.fpaGetNumeralExponentString(), Native.fpaGetNumeralSignificandString(), Native.funcDeclToString(), Native.getDeclRationalParameter(), Statistics.getEntries(), Native.getErrorMsg(), Native.getFullVersion(), Statistics.getKeys(), Native.getNumeralDecimalString(), Native.getNumeralString(), FuncDecl.Parameter.getParameterKind(), Native.getProbeName(), Context.getProbeNames(), Native.getSmtlibError(), Tactic.getSolver(), StringSymbol.getString(), Native.getString(), Native.getSymbolString(), Native.getTacticName(), Context.getTacticNames(), Native.goalToString(), Native.interpolationProfile(), InterpolationContext.mkContext(), Optimize.MkMinimize(), Context.mkSymbol(), Native.modelToString(), Native.optimizeGetHelp(), Native.optimizeGetReasonUnknown(), Native.optimizeToString(), Native.paramDescrsGetDocumentation(), Native.paramDescrsToString(), Native.paramsToString(), Native.patternToString(), Native.probeGetDescr(), Native.rcfNumToDecimalString(), Native.rcfNumToString(), Native.simplifyGetHelp(), Native.solverGetHelp(), Native.solverGetReasonUnknown(), Native.solverToString(), Native.sortToString(), Native.statsGetKey(), Native.statsToString(), Native.tacticGetDescr(), Native.tacticGetHelp(), Statistics.Entry.toString(), and FuncInterp.toString().

9443 def String(name, ctx=None):
9444  """Return a string constant named `name`. If `ctx=None`, then the global context is used.
9445 
9446  >>> x = String('x')
9447  """
9448  ctx = _get_ctx(ctx)
9449  return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
9450 
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
def to_symbol(s, ctx=None)
Definition: z3py.py:100
def StringSort(ctx=None)
Definition: z3py.py:9347
def String(name, ctx=None)
Definition: z3py.py:9443

§ Strings()

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

Definition at line 9451 of file z3py.py.

Referenced by Contains().

9451 def Strings(names, ctx=None):
9452  """Return a tuple of String constants. """
9453  ctx = _get_ctx(ctx)
9454  if isinstance(names, str):
9455  names = names.split(" ")
9456  return [String(name, ctx) for name in names]
9457 
def Strings(names, ctx=None)
Definition: z3py.py:9451
def String(name, ctx=None)
Definition: z3py.py:9443

§ StringSort()

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

Definition at line 9347 of file z3py.py.

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

9347 def StringSort(ctx=None):
9348  """Create a string sort
9349  >>> s = StringSort()
9350  >>> print(s)
9351  String
9352  """
9353  ctx = _get_ctx(ctx)
9354  return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
9355 
9356 
def StringSort(ctx=None)
Definition: z3py.py:9347

§ StringVal()

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

Definition at line 9438 of file z3py.py.

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

9438 def StringVal(s, ctx=None):
9439  """create a string expression"""
9440  ctx = _get_ctx(ctx)
9441  return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
9442 
def StringVal(s, ctx=None)
Definition: z3py.py:9438

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

Referenced by expr.simplify().

7500 def substitute(t, *m):
7501  """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.
7502 
7503  >>> x = Int('x')
7504  >>> y = Int('y')
7505  >>> substitute(x + 1, (x, y + 1))
7506  y + 1 + 1
7507  >>> f = Function('f', IntSort(), IntSort())
7508  >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
7509  1 + 1
7510  """
7511  if isinstance(m, tuple):
7512  m1 = _get_args(m)
7513  if isinstance(m1, list):
7514  m = m1
7515  if __debug__:
7516  _z3_assert(is_expr(t), "Z3 expression expected")
7517  _z3_assert(all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) and p[0].sort().eq(p[1].sort()) for p in m]), "Z3 invalid substitution, expression pairs expected.")
7518  num = len(m)
7519  _from = (Ast * num)()
7520  _to = (Ast * num)()
7521  for i in range(num):
7522  _from[i] = m[i][0].as_ast()
7523  _to[i] = m[i][1].as_ast()
7524  return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
7525 
Z3_ast Z3_API Z3_substitute(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const from[], Z3_ast const to[])
Substitute every occurrence of from[i] in a with to[i], for i smaller than num_exprs. The result is the new AST. The arrays from and to must have size num_exprs. For every i smaller than num_exprs, we must have that sort of from[i] must be equal to sort of to[i].
def substitute(t, m)
Definition: z3py.py:7500
def eq(a, b)
Definition: z3py.py:400
def is_expr(a)
Definition: z3py.py:1007

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

7526 def substitute_vars(t, *m):
7527  """Substitute the free variables in t with the expression in m.
7528 
7529  >>> v0 = Var(0, IntSort())
7530  >>> v1 = Var(1, IntSort())
7531  >>> x = Int('x')
7532  >>> f = Function('f', IntSort(), IntSort(), IntSort())
7533  >>> # replace v0 with x+1 and v1 with x
7534  >>> substitute_vars(f(v0, v1), x + 1, x)
7535  f(x + 1, x)
7536  """
7537  if __debug__:
7538  _z3_assert(is_expr(t), "Z3 expression expected")
7539  _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
7540  num = len(m)
7541  _to = (Ast * num)()
7542  for i in range(num):
7543  _to[i] = m[i].as_ast()
7544  return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
7545 
def substitute_vars(t, m)
Definition: z3py.py:7526
Z3_ast Z3_API Z3_substitute_vars(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const to[])
Substitute the free variables in a with the expressions in to. For every i smaller than num_exprs...
def is_expr(a)
Definition: z3py.py:1007

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

9490 def SuffixOf(a, b):
9491  """Check if 'a' is a suffix of 'b'
9492  >>> s1 = SuffixOf("ab", "abc")
9493  >>> simplify(s1)
9494  False
9495  >>> s2 = SuffixOf("bc", "abc")
9496  >>> simplify(s2)
9497  True
9498  """
9499  ctx = _get_ctx2(a, b)
9500  a = _coerce_seq(a, ctx)
9501  b = _coerce_seq(b, ctx)
9502  return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
9503 
def SuffixOf(a, b)
Definition: z3py.py:9490

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

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

7546 def Sum(*args):
7547  """Create the sum of the Z3 expressions.
7548 
7549  >>> a, b, c = Ints('a b c')
7550  >>> Sum(a, b, c)
7551  a + b + c
7552  >>> Sum([a, b, c])
7553  a + b + c
7554  >>> A = IntVector('a', 5)
7555  >>> Sum(A)
7556  a__0 + a__1 + a__2 + a__3 + a__4
7557  """
7558  args = _get_args(args)
7559  if len(args) == 0:
7560  return 0
7561  ctx = _ctx_from_ast_arg_list(args)
7562  if ctx is None:
7563  return _reduce(lambda a, b: a + b, args, 0)
7564  args = _coerce_expr_list(args, ctx)
7565  if is_bv(args[0]):
7566  return _reduce(lambda a, b: a + b, args, 0)
7567  else:
7568  _args, sz = _to_ast_array(args)
7569  return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
7570 
7571 
def Sum(args)
Definition: z3py.py:7546
Z3_ast Z3_API Z3_mk_add(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] + ... + args[num_args-1].
def is_bv(a)
Definition: z3py.py:3481

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

Referenced by describe_tactics().

7186 def tactic_description(name, ctx=None):
7187  """Return a short description for the tactic named `name`.
7188 
7189  >>> d = tactic_description('simplify')
7190  """
7191  ctx = _get_ctx(ctx)
7192  return Z3_tactic_get_descr(ctx.ref(), name)
7193 
def tactic_description(name, ctx=None)
Definition: z3py.py:7186
Z3_string Z3_API Z3_tactic_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the tactic with the given name.

§ tactics()

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

>>> l = tactics()
>>> l.count('simplify') == 1
True

Definition at line 7176 of file z3py.py.

Referenced by describe_tactics().

7176 def tactics(ctx=None):
7177  """Return a list of all available tactics in Z3.
7178 
7179  >>> l = tactics()
7180  >>> l.count('simplify') == 1
7181  True
7182  """
7183  ctx = _get_ctx(ctx)
7184  return [ Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref())) ]
7185 
Z3_string Z3_API Z3_get_tactic_name(Z3_context c, unsigned i)
Return the name of the idx tactic.
def tactics(ctx=None)
Definition: z3py.py:7176
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.

§ Then()

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

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

Definition at line 7068 of file z3py.py.

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

7068 def Then(*ts, **ks):
7069  """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
7070 
7071  >>> x, y = Ints('x y')
7072  >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
7073  >>> t(And(x == 0, y > x + 1))
7074  [[Not(y <= 1)]]
7075  >>> t(And(x == 0, y > x + 1)).as_expr()
7076  Not(y <= 1)
7077  """
7078  return AndThen(*ts, **ks)
7079 
def Then(ts, ks)
Definition: z3py.py:7068
def AndThen(ts, ks)
Definition: z3py.py:7049

§ to_symbol()

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

Definition at line 100 of file z3py.py.

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

100 def to_symbol(s, ctx=None):
101  """Convert an integer or string into a Z3 symbol."""
102  if _is_int(s):
103  return Z3_mk_int_symbol(_get_ctx(ctx).ref(), s)
104  else:
105  return Z3_mk_string_symbol(_get_ctx(ctx).ref(), s)
106 
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
def to_symbol(s, ctx=None)
Definition: z3py.py:100
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.

§ ToInt()

def z3py.ToInt (   a)
Return the Z3 expression ToInt(a).

>>> x = Real('x')
>>> x.sort()
Real
>>> n = ToInt(x)
>>> n
ToInt(x)
>>> n.sort()
Int

Definition at line 2925 of file z3py.py.

Referenced by is_to_int().

2925 def ToInt(a):
2926  """ Return the Z3 expression ToInt(a).
2927 
2928  >>> x = Real('x')
2929  >>> x.sort()
2930  Real
2931  >>> n = ToInt(x)
2932  >>> n
2933  ToInt(x)
2934  >>> n.sort()
2935  Int
2936  """
2937  if __debug__:
2938  _z3_assert(a.is_real(), "Z3 real expression expected.")
2939  ctx = a.ctx
2940  return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
2941 
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:2925

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

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

2908 def ToReal(a):
2909  """ Return the Z3 expression ToReal(a).
2910 
2911  >>> x = Int('x')
2912  >>> x.sort()
2913  Int
2914  >>> n = ToReal(x)
2915  >>> n
2916  ToReal(x)
2917  >>> n.sort()
2918  Real
2919  """
2920  if __debug__:
2921  _z3_assert(a.is_int(), "Z3 integer expression expected.")
2922  ctx = a.ctx
2923  return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
2924 
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:2908

§ tree_interpolant()

def z3py.tree_interpolant (   pat,
  p = None,
  ctx = None 
)
Compute interpolant for a tree of formulas.

The input is an interpolation pattern over a set of formulas C.
The pattern pat is a formula combining the formulas in C using
logical conjunction and the "interp" operator (see Interp). This
interp operator is logically the identity operator. It marks the
sub-formulas of the pattern for which interpolants should be
computed. The interpolant is a map sigma from marked subformulas
to formulas, such that, for each marked subformula phi of pat
(where phi sigma is phi with sigma(psi) substituted for each
subformula psi of phi such that psi in dom(sigma)):

  1) phi sigma implies sigma(phi), and

  2) sigma(phi) is in the common uninterpreted vocabulary between
  the formulas of C occurring in phi and those not occurring in
  phi

  and moreover pat sigma implies false. In the simplest case
  an interpolant for the pattern "(and (interp A) B)" maps A
  to an interpolant for A /\ B.

  The return value is a vector of formulas representing sigma. This
  vector contains sigma(phi) for each marked subformula of pat, in
  pre-order traversal. This means that subformulas of phi occur before phi
  in the vector. Also, subformulas that occur multiply in pat will
  occur multiply in the result vector.

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

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

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

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

# >>> g = And(Interpolant(x<0),x<2)
# >>> try:
# ...     print tree_interpolant(g).sexpr()
# ... except ModelRef as m:
# ...     print m.sexpr()
(define-fun x () Int
  (- 1))

Definition at line 7903 of file z3py.py.

7903 def tree_interpolant(pat,p=None,ctx=None):
7904  """Compute interpolant for a tree of formulas.
7905 
7906  The input is an interpolation pattern over a set of formulas C.
7907  The pattern pat is a formula combining the formulas in C using
7908  logical conjunction and the "interp" operator (see Interp). This
7909  interp operator is logically the identity operator. It marks the
7910  sub-formulas of the pattern for which interpolants should be
7911  computed. The interpolant is a map sigma from marked subformulas
7912  to formulas, such that, for each marked subformula phi of pat
7913  (where phi sigma is phi with sigma(psi) substituted for each
7914  subformula psi of phi such that psi in dom(sigma)):
7915 
7916  1) phi sigma implies sigma(phi), and
7917 
7918  2) sigma(phi) is in the common uninterpreted vocabulary between
7919  the formulas of C occurring in phi and those not occurring in
7920  phi
7921 
7922  and moreover pat sigma implies false. In the simplest case
7923  an interpolant for the pattern "(and (interp A) B)" maps A
7924  to an interpolant for A /\ B.
7925 
7926  The return value is a vector of formulas representing sigma. This
7927  vector contains sigma(phi) for each marked subformula of pat, in
7928  pre-order traversal. This means that subformulas of phi occur before phi
7929  in the vector. Also, subformulas that occur multiply in pat will
7930  occur multiply in the result vector.
7931 
7932  If pat is satisfiable, raises an object of class ModelRef
7933  that represents a model of pat.
7934 
7935  If neither a proof of unsatisfiability nor a model is obtained
7936  (for example, because of a timeout, or because models are disabled)
7937  then None is returned.
7938 
7939  If parameters p are supplied, these are used in creating the
7940  solver that determines satisfiability.
7941 
7942  >>> x = Int('x')
7943  >>> y = Int('y')
7944  >>> print(tree_interpolant(And(Interpolant(x < 0), Interpolant(y > 2), x == y)))
7945  [Not(x >= 0), Not(y <= 2)]
7946 
7947  # >>> g = And(Interpolant(x<0),x<2)
7948  # >>> try:
7949  # ... print tree_interpolant(g).sexpr()
7950  # ... except ModelRef as m:
7951  # ... print m.sexpr()
7952  (define-fun x () Int
7953  (- 1))
7954  """
7955  f = pat
7956  ctx = _get_ctx(_ctx_from_ast_arg_list([f], ctx))
7957  ptr = (AstVectorObj * 1)()
7958  mptr = (Model * 1)()
7959  if p is None:
7960  p = ParamsRef(ctx)
7961  res = Z3_compute_interpolant(ctx.ref(),f.as_ast(),p.params,ptr,mptr)
7962  if res == Z3_L_FALSE:
7963  return AstVector(ptr[0],ctx)
7964  if mptr[0]:
7965  raise ModelRef(mptr[0], ctx)
7966  return None
7967 
Z3_lbool Z3_API Z3_compute_interpolant(Z3_context c, Z3_ast pat, Z3_params p, Z3_ast_vector *interp, Z3_model *model)
def tree_interpolant(pat, p=None, ctx=None)
Definition: z3py.py:7903

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

7168 def TryFor(t, ms, ctx=None):
7169  """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
7170 
7171  If `t` does not terminate in `ms` milliseconds, then it fails.
7172  """
7173  t = _to_tactic(t, ctx)
7174  return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
7175 
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:7168

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

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

3747 def UDiv(a, b):
3748  """Create the Z3 expression (unsigned) division `self / other`.
3749 
3750  Use the operator / for signed division.
3751 
3752  >>> x = BitVec('x', 32)
3753  >>> y = BitVec('y', 32)
3754  >>> UDiv(x, y)
3755  UDiv(x, y)
3756  >>> UDiv(x, y).sort()
3757  BitVec(32)
3758  >>> (x / y).sexpr()
3759  '(bvsdiv x y)'
3760  >>> UDiv(x, y).sexpr()
3761  '(bvudiv x y)'
3762  """
3763  _check_bv_args(a, b)
3764  a, b = _coerce_exprs(a, b)
3765  return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3766 
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:3747

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

Referenced by BitVecRef.__ge__().

3713 def UGE(a, b):
3714  """Create the Z3 expression (unsigned) `other >= self`.
3715 
3716  Use the operator >= for signed greater than or equal to.
3717 
3718  >>> x, y = BitVecs('x y', 32)
3719  >>> UGE(x, y)
3720  UGE(x, y)
3721  >>> (x >= y).sexpr()
3722  '(bvsge x y)'
3723  >>> UGE(x, y).sexpr()
3724  '(bvuge x y)'
3725  """
3726  _check_bv_args(a, b)
3727  a, b = _coerce_exprs(a, b)
3728  return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3729 
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:3713

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

Referenced by BitVecRef.__gt__().

3730 def UGT(a, b):
3731  """Create the Z3 expression (unsigned) `other > self`.
3732 
3733  Use the operator > for signed greater than.
3734 
3735  >>> x, y = BitVecs('x y', 32)
3736  >>> UGT(x, y)
3737  UGT(x, y)
3738  >>> (x > y).sexpr()
3739  '(bvsgt x y)'
3740  >>> UGT(x, y).sexpr()
3741  '(bvugt x y)'
3742  """
3743  _check_bv_args(a, b)
3744  a, b = _coerce_exprs(a, b)
3745  return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3746 
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:3730

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

Referenced by BitVecRef.__le__().

3679 def ULE(a, b):
3680  """Create the Z3 expression (unsigned) `other <= self`.
3681 
3682  Use the operator <= for signed less than or equal to.
3683 
3684  >>> x, y = BitVecs('x y', 32)
3685  >>> ULE(x, y)
3686  ULE(x, y)
3687  >>> (x <= y).sexpr()
3688  '(bvsle x y)'
3689  >>> ULE(x, y).sexpr()
3690  '(bvule x y)'
3691  """
3692  _check_bv_args(a, b)
3693  a, b = _coerce_exprs(a, b)
3694  return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3695 
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:3679

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

Referenced by BitVecRef.__lt__().

3696 def ULT(a, b):
3697  """Create the Z3 expression (unsigned) `other < self`.
3698 
3699  Use the operator < for signed less than.
3700 
3701  >>> x, y = BitVecs('x y', 32)
3702  >>> ULT(x, y)
3703  ULT(x, y)
3704  >>> (x < y).sexpr()
3705  '(bvslt x y)'
3706  >>> ULT(x, y).sexpr()
3707  '(bvult x y)'
3708  """
3709  _check_bv_args(a, b)
3710  a, b = _coerce_exprs(a, b)
3711  return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3712 
def ULT(a, b)
Definition: z3py.py:3696
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.

§ Union()

def z3py.Union (   args)
Create union of regular expressions.
>>> re = Union(Re("a"), Re("b"), Re("c"))
>>> print (simplify(InRe("d", re)))
False

Definition at line 9617 of file z3py.py.

Referenced by InRe().

9617 def Union(*args):
9618  """Create union of regular expressions.
9619  >>> re = Union(Re("a"), Re("b"), Re("c"))
9620  >>> print (simplify(InRe("d", re)))
9621  False
9622  """
9623  args = _get_args(args)
9624  sz = len(args)
9625  if __debug__:
9626  _z3_assert(sz > 0, "At least one argument expected.")
9627  _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
9628  if sz == 1:
9629  return args[0]
9630  ctx = args[0].ctx
9631  v = (Ast * sz)()
9632  for i in range(sz):
9633  v[i] = args[i].as_ast()
9634  return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
9635 
def Union(args)
Definition: z3py.py:9617
def is_re(s)
Definition: z3py.py:9600

§ Unit()

def z3py.Unit (   a)
Create a singleton sequence

Definition at line 9472 of file z3py.py.

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

9472 def Unit(a):
9473  """Create a singleton sequence"""
9474  return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
9475 
def Unit(a)
Definition: z3py.py:9472

§ Update()

def z3py.Update (   a,
  i,
  v 
)
Return a Z3 store array expression.

>>> a    = Array('a', IntSort(), IntSort())
>>> i, v = Ints('i v')
>>> s    = Update(a, i, v)
>>> s.sort()
Array(Int, Int)
>>> prove(s[i] == v)
proved
>>> j    = Int('j')
>>> prove(Implies(i != j, s[j] == a[j]))
proved

Definition at line 4144 of file z3py.py.

4144 def Update(a, i, v):
4145  """Return a Z3 store array expression.
4146 
4147  >>> a = Array('a', IntSort(), IntSort())
4148  >>> i, v = Ints('i v')
4149  >>> s = Update(a, i, v)
4150  >>> s.sort()
4151  Array(Int, Int)
4152  >>> prove(s[i] == v)
4153  proved
4154  >>> j = Int('j')
4155  >>> prove(Implies(i != j, s[j] == a[j]))
4156  proved
4157  """
4158  if __debug__:
4159  _z3_assert(is_array(a), "First argument must be a Z3 array expression")
4160  i = a.domain().cast(i)
4161  v = a.range().cast(v)
4162  ctx = a.ctx
4163  return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4164 
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
def is_array(a)
Definition: z3py.py:4033
def Update(a, i, v)
Definition: z3py.py:4144

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

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

3767 def URem(a, b):
3768  """Create the Z3 expression (unsigned) remainder `self % other`.
3769 
3770  Use the operator % for signed modulus, and SRem() for signed remainder.
3771 
3772  >>> x = BitVec('x', 32)
3773  >>> y = BitVec('y', 32)
3774  >>> URem(x, y)
3775  URem(x, y)
3776  >>> URem(x, y).sort()
3777  BitVec(32)
3778  >>> (x % y).sexpr()
3779  '(bvsmod x y)'
3780  >>> URem(x, y).sexpr()
3781  '(bvurem x y)'
3782  """
3783  _check_bv_args(a, b)
3784  a, b = _coerce_exprs(a, b)
3785  return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
3786 
def URem(a, b)
Definition: z3py.py:3767
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.

§ Var()

def z3py.Var (   idx,
  s 
)
Create a Z3 free variable. Free variables are used to create quantified formulas.

>>> Var(0, IntSort())
Var(0)
>>> eq(Var(0, IntSort()), Var(0, BoolSort()))
False

Definition at line 1218 of file z3py.py.

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

1218 def Var(idx, s):
1219  """Create a Z3 free variable. Free variables are used to create quantified formulas.
1220 
1221  >>> Var(0, IntSort())
1222  Var(0)
1223  >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1224  False
1225  """
1226  if __debug__:
1227  _z3_assert(is_sort(s), "Z3 sort expected")
1228  return _to_expr_ref(Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1229 
def Var(idx, s)
Definition: z3py.py:1218
def is_sort(s)
Definition: z3py.py:563

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

7434 def When(p, t, ctx=None):
7435  """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
7436 
7437  >>> t = When(Probe('size') > 2, Tactic('simplify'))
7438  >>> x, y = Ints('x y')
7439  >>> g = Goal()
7440  >>> g.add(x > 0)
7441  >>> g.add(y > 0)
7442  >>> t(g)
7443  [[x > 0, y > 0]]
7444  >>> g.add(x == y + 1)
7445  >>> t(g)
7446  [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
7447  """
7448  p = _to_probe(p, ctx)
7449  t = _to_tactic(t, ctx)
7450  return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
7451 
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:7434

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

Referenced by Goal.prec().

7136 def With(t, *args, **keys):
7137  """Return a tactic that applies tactic `t` using the given configuration options.
7138 
7139  >>> x, y = Ints('x y')
7140  >>> t = With(Tactic('simplify'), som=True)
7141  >>> t((x + 1)*(y + 2) == 0)
7142  [[2*x + y + x*y == -2]]
7143  """
7144  ctx = keys.get('ctx', None)
7145  t = _to_tactic(t, ctx)
7146  p = args2params(args, keys, t.ctx)
7147  return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
7148 
def args2params(arguments, keywords, ctx=None)
Definition: z3py.py:4644
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:7136

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

1510 def Xor(a, b, ctx=None):
1511  """Create a Z3 Xor expression.
1512 
1513  >>> p, q = Bools('p q')
1514  >>> Xor(p, q)
1515  Xor(p, q)
1516  >>> simplify(Xor(p, q))
1517  Not(p) == q
1518  """
1519  ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1520  s = BoolSort(ctx)
1521  a = s.cast(a)
1522  b = s.cast(b)
1523  return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1524 
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:1510
def BoolSort(ctx=None)
Definition: z3py.py:1407

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

3897 def ZeroExt(n, a):
3898  """Return a bit-vector expression with `n` extra zero-bits.
3899 
3900  >>> x = BitVec('x', 16)
3901  >>> n = ZeroExt(8, x)
3902  >>> n.size()
3903  24
3904  >>> n
3905  ZeroExt(8, x)
3906  >>> n.sort()
3907  BitVec(24)
3908  >>> v0 = BitVecVal(2, 2)
3909  >>> v0
3910  2
3911  >>> v0.size()
3912  2
3913  >>> v = simplify(ZeroExt(6, v0))
3914  >>> v
3915  2
3916  >>> v.size()
3917  8
3918  """
3919  if __debug__:
3920  _z3_assert(_is_int(n), "First argument must be an integer")
3921  _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression")
3922  return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
3923 
def ZeroExt(n, a)
Definition: z3py.py:3897
def is_bv(a)
Definition: z3py.py:3481
Z3_ast Z3_API Z3_mk_zero_ext(Z3_context c, unsigned i, Z3_ast t1)
Extend the given bit-vector with zeros to the (unsigned) equivalent bit-vector of size m+i...

Variable Documentation

§ sat

Definition at line 5896 of file z3py.py.

§ unknown

Definition at line 5898 of file z3py.py.

§ unsat

Definition at line 5897 of file z3py.py.