Z3
 
Loading...
Searching...
No Matches
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  CharRef
 
class  CharSortRef
 
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
 
class  FPRef
 
class  FPRMRef
 
class  FPRMSortRef
 
class  FPSortRef
 
class  FuncDeclRef
 Function Declarations. More...
 
class  FuncEntry
 
class  FuncInterp
 
class  Goal
 
class  IntNumRef
 
class  ModelRef
 
class  OnClause
 
class  Optimize
 
class  OptimizeObjective
 Optimize. More...
 
class  ParamDescrsRef
 
class  ParamsRef
 Parameter Sets. More...
 
class  ParserContext
 
class  PatternRef
 Patterns. More...
 
class  Probe
 
class  PropClosures
 
class  QuantifierRef
 Quantifiers. More...
 
class  RatNumRef
 
class  ReRef
 
class  ReSortRef
 
class  ScopedConstructor
 
class  ScopedConstructorList
 
class  SeqRef
 
class  SeqSortRef
 Strings, Sequences and Regular expressions. More...
 
class  Simplifier
 
class  Solver
 
class  SortRef
 
class  Statistics
 Statistics. More...
 
class  Tactic
 
class  TypeVarRef
 
class  UserPropagateBase
 
class  Z3PPObject
 ASTs base class. More...
 

Functions

 z3_debug ()
 
 _is_int (v)
 
 enable_trace (msg)
 
 disable_trace (msg)
 
 get_version_string ()
 
 get_version ()
 
 get_full_version ()
 
 _z3_assert (cond, msg)
 
 _z3_check_cint_overflow (n, name)
 
 open_log (fname)
 
 append_log (s)
 
 to_symbol (s, ctx=None)
 
 _symbol2py (ctx, s)
 
 _get_args (args)
 
 _get_args_ast_list (args)
 
 _to_param_value (val)
 
 z3_error_handler (c, e)
 
Context main_ctx ()
 
Context _get_ctx (ctx)
 
Context get_ctx (ctx)
 
 set_param (*args, **kws)
 
None reset_params ()
 
 set_option (*args, **kws)
 
 get_param (name)
 
bool is_ast (Any a)
 
bool eq (AstRef a, AstRef b)
 
int _ast_kind (Context ctx, Any a)
 
 _ctx_from_ast_arg_list (args, default_ctx=None)
 
 _ctx_from_ast_args (*args)
 
 _to_func_decl_array (args)
 
 _to_ast_array (args)
 
 _to_ref_array (ref, args)
 
 _to_ast_ref (a, ctx)
 
 _sort_kind (ctx, s)
 Sorts.
 
bool is_sort (Any s)
 
 _to_sort_ref (s, ctx)
 
SortRef _sort (Context ctx, Any a)
 
SortRef DeclareSort (name, ctx=None)
 
 DeclareTypeVar (name, ctx=None)
 
 is_func_decl (a)
 
 Function (name, *sig)
 
 FreshFunction (*sig)
 
 _to_func_decl_ref (a, ctx)
 
 RecFunction (name, *sig)
 
 RecAddDefinition (f, args, body)
 
 deserialize (st)
 
 _to_expr_ref (a, ctx)
 
 _coerce_expr_merge (s, a)
 
 _check_same_sort (a, b, ctx=None)
 
 _coerce_exprs (a, b, ctx=None)
 
 _reduce (func, sequence, initial)
 
 _coerce_expr_list (alist, ctx=None)
 
 is_expr (a)
 
 is_app (a)
 
 is_const (a)
 
 is_var (a)
 
 get_var_index (a)
 
 is_app_of (a, k)
 
 If (a, b, c, ctx=None)
 
 Distinct (*args)
 
 _mk_bin (f, a, b)
 
 Const (name, sort)
 
 Consts (names, sort)
 
 FreshConst (sort, prefix="c")
 
ExprRef Var (int idx, SortRef s)
 
ExprRef RealVar (int idx, ctx=None)
 
 RealVarVector (int n, ctx=None)
 
bool is_bool (Any a)
 
bool is_true (Any a)
 
bool is_false (Any a)
 
bool is_and (Any a)
 
bool is_or (Any a)
 
bool is_implies (Any a)
 
bool is_not (Any a)
 
bool is_eq (Any a)
 
bool is_distinct (Any a)
 
 BoolSort (ctx=None)
 
 BoolVal (val, ctx=None)
 
 Bool (name, ctx=None)
 
 Bools (names, ctx=None)
 
 BoolVector (prefix, sz, ctx=None)
 
 FreshBool (prefix="b", ctx=None)
 
 Implies (a, b, ctx=None)
 
 Xor (a, b, ctx=None)
 
 Not (a, ctx=None)
 
 mk_not (a)
 
 _has_probe (args)
 
 And (*args)
 
 Or (*args)
 
 is_pattern (a)
 
 MultiPattern (*args)
 
 _to_pattern (arg)
 
 is_quantifier (a)
 
 _mk_quantifier (is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
 
 ForAll (vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
 
 Exists (vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
 
 Lambda (vs, body)
 
bool is_arith_sort (Any s)
 
 is_arith (a)
 
bool is_int (a)
 
 is_real (a)
 
 _is_numeral (ctx, a)
 
 _is_algebraic (ctx, a)
 
 is_int_value (a)
 
 is_rational_value (a)
 
 is_algebraic_value (a)
 
bool is_add (Any a)
 
bool is_mul (Any a)
 
bool is_sub (Any a)
 
bool is_div (Any a)
 
bool is_idiv (Any a)
 
bool is_mod (Any a)
 
bool is_le (Any a)
 
bool is_lt (Any a)
 
bool is_ge (Any a)
 
bool is_gt (Any a)
 
bool is_is_int (Any a)
 
bool is_to_real (Any a)
 
bool is_to_int (Any a)
 
 _py2expr (a, ctx=None)
 
 IntSort (ctx=None)
 
 RealSort (ctx=None)
 
 _to_int_str (val)
 
 IntVal (val, ctx=None)
 
 RealVal (val, ctx=None)
 
 RatVal (a, b, ctx=None)
 
 Q (a, b, ctx=None)
 
 Int (name, ctx=None)
 
 Ints (names, ctx=None)
 
 IntVector (prefix, sz, ctx=None)
 
 FreshInt (prefix="x", ctx=None)
 
 Real (name, ctx=None)
 
 Reals (names, ctx=None)
 
 RealVector (prefix, sz, ctx=None)
 
 FreshReal (prefix="b", ctx=None)
 
 ToReal (a)
 
 ToInt (a)
 
 IsInt (a)
 
 Sqrt (a, ctx=None)
 
 Cbrt (a, ctx=None)
 
 is_bv_sort (s)
 
 is_bv (a)
 
 is_bv_value (a)
 
 BV2Int (a, is_signed=False)
 
 Int2BV (a, num_bits)
 
 BitVecSort (sz, ctx=None)
 
 BitVecVal (val, bv, ctx=None)
 
 BitVec (name, bv, ctx=None)
 
 BitVecs (names, bv, ctx=None)
 
 Concat (*args)
 
 Extract (high, low, a)
 
 _check_bv_args (a, b)
 
 ULE (a, b)
 
 ULT (a, b)
 
 UGE (a, b)
 
 UGT (a, b)
 
 UDiv (a, b)
 
 URem (a, b)
 
 SRem (a, b)
 
 LShR (a, b)
 
 RotateLeft (a, b)
 
 RotateRight (a, b)
 
 SignExt (n, a)
 
 ZeroExt (n, a)
 
 RepeatBitVec (n, a)
 
 BVRedAnd (a)
 
 BVRedOr (a)
 
 BVAddNoOverflow (a, b, signed)
 
 BVAddNoUnderflow (a, b)
 
 BVSubNoOverflow (a, b)
 
 BVSubNoUnderflow (a, b, signed)
 
 BVSDivNoOverflow (a, b)
 
 BVSNegNoOverflow (a)
 
 BVMulNoOverflow (a, b, signed)
 
 BVMulNoUnderflow (a, b)
 
 _array_select (ar, arg)
 
 is_array_sort (a)
 
bool is_array (Any a)
 
 is_const_array (a)
 
 is_K (a)
 
 is_map (a)
 
 is_default (a)
 
 get_map_func (a)
 
 ArraySort (*sig)
 
 Array (name, *sorts)
 
 Update (a, *args)
 
 Default (a)
 
 Store (a, *args)
 
 Select (a, *args)
 
 Map (f, *args)
 
 K (dom, v)
 
 Ext (a, b)
 
 is_select (a)
 
 is_store (a)
 
 SetSort (s)
 Sets.
 
 EmptySet (s)
 
 FullSet (s)
 
 SetUnion (*args)
 
 SetIntersect (*args)
 
 SetAdd (s, e)
 
 SetDel (s, e)
 
 SetComplement (s)
 
 SetDifference (a, b)
 
 IsMember (e, s)
 
 IsSubset (a, b)
 
 _valid_accessor (acc)
 Datatypes.
 
 CreateDatatypes (*ds)
 
 DatatypeSort (name, params=None, ctx=None)
 
 TupleSort (name, sorts, ctx=None)
 
 DisjointSum (name, sorts, ctx=None)
 
 EnumSort (name, values, ctx=None)
 
 args2params (arguments, keywords, ctx=None)
 
 Model (ctx=None, eval={})
 
 is_as_array (n)
 
 get_as_array_func (n)
 
 SolverFor (logic, ctx=None, logFile=None)
 
 SimpleSolver (ctx=None, logFile=None)
 
 FiniteDomainSort (name, sz, ctx=None)
 
 is_finite_domain_sort (s)
 
 is_finite_domain (a)
 
 FiniteDomainVal (val, sort, ctx=None)
 
 is_finite_domain_value (a)
 
 _global_on_model (ctx)
 
 _to_goal (a)
 
 _to_tactic (t, ctx=None)
 
 _and_then (t1, t2, ctx=None)
 
 _or_else (t1, t2, ctx=None)
 
 AndThen (*ts, **ks)
 
 Then (*ts, **ks)
 
 OrElse (*ts, **ks)
 
 ParOr (*ts, **ks)
 
 ParThen (t1, t2, ctx=None)
 
 ParAndThen (t1, t2, ctx=None)
 
 With (t, *args, **keys)
 
 WithParams (t, p)
 
 Repeat (t, max=4294967295, ctx=None)
 
 TryFor (t, ms, ctx=None)
 
 tactics (ctx=None)
 
 tactic_description (name, ctx=None)
 
 describe_tactics ()
 
 is_probe (p)
 
 _to_probe (p, ctx=None)
 
 probes (ctx=None)
 
 probe_description (name, ctx=None)
 
 describe_probes ()
 
 _probe_nary (f, args, ctx)
 
 _probe_and (args, ctx)
 
 _probe_or (args, ctx)
 
 FailIf (p, ctx=None)
 
 When (p, t, ctx=None)
 
 Cond (p, t1, t2, ctx=None)
 
 simplify (a, *arguments, **keywords)
 Utils.
 
 help_simplify ()
 
 simplify_param_descrs ()
 
 substitute (t, *m)
 
 substitute_vars (t, *m)
 
 substitute_funs (t, *m)
 
 Sum (*args)
 
 Product (*args)
 
 Abs (arg)
 
 AtMost (*args)
 
 AtLeast (*args)
 
 _reorder_pb_arg (arg)
 
 _pb_args_coeffs (args, default_ctx=None)
 
 PbLe (args, k)
 
 PbGe (args, k)
 
 PbEq (args, k, ctx=None)
 
 solve (*args, **keywords)
 
 solve_using (s, *args, **keywords)
 
 prove (claim, show=False, **keywords)
 
 _solve_html (*args, **keywords)
 
 _solve_using_html (s, *args, **keywords)
 
 _prove_html (claim, show=False, **keywords)
 
 _dict2sarray (sorts, ctx)
 
 _dict2darray (decls, ctx)
 
 parse_smt2_string (s, sorts={}, decls={}, ctx=None)
 
 parse_smt2_file (f, sorts={}, decls={}, ctx=None)
 
 get_default_rounding_mode (ctx=None)
 
 set_default_rounding_mode (rm, ctx=None)
 
 get_default_fp_sort (ctx=None)
 
 set_default_fp_sort (ebits, sbits, ctx=None)
 
 _dflt_rm (ctx=None)
 
 _dflt_fps (ctx=None)
 
 _coerce_fp_expr_list (alist, ctx)
 
 Float16 (ctx=None)
 
 FloatHalf (ctx=None)
 
 Float32 (ctx=None)
 
 FloatSingle (ctx=None)
 
 Float64 (ctx=None)
 
 FloatDouble (ctx=None)
 
 Float128 (ctx=None)
 
 FloatQuadruple (ctx=None)
 
 is_fp_sort (s)
 
 is_fprm_sort (s)
 
 RoundNearestTiesToEven (ctx=None)
 
 RNE (ctx=None)
 
 RoundNearestTiesToAway (ctx=None)
 
 RNA (ctx=None)
 
 RoundTowardPositive (ctx=None)
 
 RTP (ctx=None)
 
 RoundTowardNegative (ctx=None)
 
 RTN (ctx=None)
 
 RoundTowardZero (ctx=None)
 
 RTZ (ctx=None)
 
 is_fprm (a)
 
 is_fprm_value (a)
 
 is_fp (a)
 
 is_fp_value (a)
 
 FPSort (ebits, sbits, ctx=None)
 
 _to_float_str (val, exp=0)
 
 fpNaN (s)
 
 fpPlusInfinity (s)
 
 fpMinusInfinity (s)
 
 fpInfinity (s, negative)
 
 fpPlusZero (s)
 
 fpMinusZero (s)
 
 fpZero (s, negative)
 
 FPVal (sig, exp=None, fps=None, ctx=None)
 
 FP (name, fpsort, ctx=None)
 
 FPs (names, fpsort, ctx=None)
 
 fpAbs (a, ctx=None)
 
 fpNeg (a, ctx=None)
 
 _mk_fp_unary (f, rm, a, ctx)
 
 _mk_fp_unary_pred (f, a, ctx)
 
 _mk_fp_bin (f, rm, a, b, ctx)
 
 _mk_fp_bin_norm (f, a, b, ctx)
 
 _mk_fp_bin_pred (f, a, b, ctx)
 
 _mk_fp_tern (f, rm, a, b, c, ctx)
 
 fpAdd (rm, a, b, ctx=None)
 
 fpSub (rm, a, b, ctx=None)
 
 fpMul (rm, a, b, ctx=None)
 
 fpDiv (rm, a, b, ctx=None)
 
 fpRem (a, b, ctx=None)
 
 fpMin (a, b, ctx=None)
 
 fpMax (a, b, ctx=None)
 
 fpFMA (rm, a, b, c, ctx=None)
 
 fpSqrt (rm, a, ctx=None)
 
 fpRoundToIntegral (rm, a, ctx=None)
 
 fpIsNaN (a, ctx=None)
 
 fpIsInf (a, ctx=None)
 
 fpIsZero (a, ctx=None)
 
 fpIsNormal (a, ctx=None)
 
 fpIsSubnormal (a, ctx=None)
 
 fpIsNegative (a, ctx=None)
 
 fpIsPositive (a, ctx=None)
 
 _check_fp_args (a, b)
 
 fpLT (a, b, ctx=None)
 
 fpLEQ (a, b, ctx=None)
 
 fpGT (a, b, ctx=None)
 
 fpGEQ (a, b, ctx=None)
 
 fpEQ (a, b, ctx=None)
 
 fpNEQ (a, b, ctx=None)
 
 fpFP (sgn, exp, sig, ctx=None)
 
 fpToFP (a1, a2=None, a3=None, ctx=None)
 
 fpBVToFP (v, sort, ctx=None)
 
 fpFPToFP (rm, v, sort, ctx=None)
 
 fpRealToFP (rm, v, sort, ctx=None)
 
 fpSignedToFP (rm, v, sort, ctx=None)
 
 fpUnsignedToFP (rm, v, sort, ctx=None)
 
 fpToFPUnsigned (rm, x, s, ctx=None)
 
 fpToSBV (rm, x, s, ctx=None)
 
 fpToUBV (rm, x, s, ctx=None)
 
 fpToReal (x, ctx=None)
 
 fpToIEEEBV (x, ctx=None)
 
 StringSort (ctx=None)
 
 CharSort (ctx=None)
 
 SeqSort (s)
 
 _coerce_char (ch, ctx=None)
 
 CharVal (ch, ctx=None)
 
 CharFromBv (bv)
 
 CharToBv (ch, ctx=None)
 
 CharToInt (ch, ctx=None)
 
 CharIsDigit (ch, ctx=None)
 
 _coerce_seq (s, ctx=None)
 
 _get_ctx2 (a, b, ctx=None)
 
 is_seq (a)
 
bool is_string (Any a)
 
bool is_string_value (Any a)
 
 StringVal (s, ctx=None)
 
 String (name, ctx=None)
 
 Strings (names, ctx=None)
 
 SubString (s, offset, length)
 
 SubSeq (s, offset, length)
 
 Empty (s)
 
 Full (s)
 
 Unit (a)
 
 PrefixOf (a, b)
 
 SuffixOf (a, b)
 
 Contains (a, b)
 
 Replace (s, src, dst)
 
 IndexOf (s, substr, offset=None)
 
 LastIndexOf (s, substr)
 
 Length (s)
 
 SeqMap (f, s)
 
 SeqMapI (f, i, s)
 
 SeqFoldLeft (f, a, s)
 
 SeqFoldLeftI (f, i, a, s)
 
 StrToInt (s)
 
 IntToStr (s)
 
 StrToCode (s)
 
 StrFromCode (c)
 
 Re (s, ctx=None)
 
 ReSort (s)
 
 is_re (s)
 
 InRe (s, re)
 
 Union (*args)
 
 Intersect (*args)
 
 Plus (re)
 
 Option (re)
 
 Complement (re)
 
 Star (re)
 
 Loop (re, lo, hi=0)
 
 Range (lo, hi, ctx=None)
 
 Diff (a, b, ctx=None)
 
 AllChar (regex_sort, ctx=None)
 
 PartialOrder (a, index)
 
 LinearOrder (a, index)
 
 TreeOrder (a, index)
 
 PiecewiseLinearOrder (a, index)
 
 TransitiveClosure (f)
 
 to_Ast (ptr)
 
 to_ContextObj (ptr)
 
 to_AstVectorObj (ptr)
 
 on_clause_eh (ctx, p, n, dep, clause)
 
 ensure_prop_closures ()
 
 user_prop_push (ctx, cb)
 
 user_prop_pop (ctx, cb, num_scopes)
 
 user_prop_fresh (ctx, _new_ctx)
 
 user_prop_fixed (ctx, cb, id, value)
 
 user_prop_created (ctx, cb, id)
 
 user_prop_final (ctx, cb)
 
 user_prop_eq (ctx, cb, x, y)
 
 user_prop_diseq (ctx, cb, x, y)
 
 user_prop_decide (ctx, cb, t_ref, idx, phase)
 
 user_prop_binding (ctx, cb, q_ref, inst_ref)
 
 PropagateFunction (name, *sig)
 

Variables

 Z3_DEBUG = __debug__
 
 _main_ctx = None
 
 sat = CheckSatResult(Z3_L_TRUE)
 
 unsat = CheckSatResult(Z3_L_FALSE)
 
 unknown = CheckSatResult(Z3_L_UNDEF)
 
dict _on_models = {}
 
 _on_model_eh = on_model_eh_type(_global_on_model)
 
 _dflt_rounding_mode = Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN
 Floating-Point Arithmetic.
 
int _dflt_fpsort_ebits = 11
 
int _dflt_fpsort_sbits = 53
 
 _ROUNDING_MODES
 
 _my_hacky_class = None
 
 _on_clause_eh = Z3_on_clause_eh(on_clause_eh)
 
 _prop_closures = None
 
 _user_prop_push = Z3_push_eh(user_prop_push)
 
 _user_prop_pop = Z3_pop_eh(user_prop_pop)
 
 _user_prop_fresh = Z3_fresh_eh(user_prop_fresh)
 
 _user_prop_fixed = Z3_fixed_eh(user_prop_fixed)
 
 _user_prop_created = Z3_created_eh(user_prop_created)
 
 _user_prop_final = Z3_final_eh(user_prop_final)
 
 _user_prop_eq = Z3_eq_eh(user_prop_eq)
 
 _user_prop_diseq = Z3_eq_eh(user_prop_diseq)
 
 _user_prop_decide = Z3_decide_eh(user_prop_decide)
 
 _user_prop_binding = Z3_on_binding_eh(user_prop_binding)
 

Function Documentation

◆ _and_then()

_and_then (   t1,
  t2,
  ctx = None 
)
protected

Definition at line 8568 of file z3py.py.

8568def _and_then(t1, t2, ctx=None):
8569 t1 = _to_tactic(t1, ctx)
8570 t2 = _to_tactic(t2, ctx)
8571 if z3_debug():
8572 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8573 return Tactic(Z3_tactic_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8574
8575
Z3_tactic Z3_API Z3_tactic_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and t2 to every subgoal produced by t1.

◆ _array_select()

_array_select (   ar,
  arg 
)
protected

Definition at line 4732 of file z3py.py.

4732def _array_select(ar, arg):
4733 if isinstance(arg, tuple):
4734 args = [ar.sort().domain_n(i).cast(arg[i]) for i in range(len(arg))]
4735 _args, sz = _to_ast_array(args)
4736 return _to_expr_ref(Z3_mk_select_n(ar.ctx_ref(), ar.as_ast(), sz, _args), ar.ctx)
4737 arg = ar.sort().domain().cast(arg)
4738 return _to_expr_ref(Z3_mk_select(ar.ctx_ref(), ar.as_ast(), arg.as_ast()), ar.ctx)
4739
4740
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i)
Array read. The argument a is the array and i is the index of the array that gets read.
Z3_ast Z3_API Z3_mk_select_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs)
n-ary Array read. The argument a is the array and idxs are the indices of the array that gets read.

Referenced by QuantifierRef.__getitem__(), and ArrayRef.__getitem__().

◆ _ast_kind()

int _ast_kind ( Context  ctx,
Any  a 
)
protected

Definition at line 505 of file z3py.py.

505def _ast_kind(ctx : Context, a : Any) -> int:
506 if is_ast(a):
507 a = a.as_ast()
508 return Z3_get_ast_kind(ctx.ref(), a)
509
510
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.

Referenced by _to_ast_ref(), is_app(), and is_var().

◆ _check_bv_args()

_check_bv_args (   a,
  b 
)
protected

Definition at line 4293 of file z3py.py.

4293def _check_bv_args(a, b):
4294 if z3_debug():
4295 _z3_assert(is_bv(a) or is_bv(b), "First or second argument must be a Z3 bit-vector expression")
4296
4297

Referenced by BVAddNoOverflow(), BVAddNoUnderflow(), BVMulNoOverflow(), BVMulNoUnderflow(), BVSDivNoOverflow(), BVSubNoOverflow(), BVSubNoUnderflow(), LShR(), RotateLeft(), RotateRight(), SRem(), UDiv(), UGE(), UGT(), ULE(), ULT(), and URem().

◆ _check_fp_args()

_check_fp_args (   a,
  b 
)
protected

Definition at line 10680 of file z3py.py.

10680def _check_fp_args(a, b):
10681 if z3_debug():
10682 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10683
10684

◆ _check_same_sort()

_check_same_sort (   a,
  b,
  ctx = None 
)
protected

Definition at line 1248 of file z3py.py.

1248def _check_same_sort(a, b, ctx=None):
1249 if not isinstance(a, ExprRef):
1250 return False
1251 if not isinstance(b, ExprRef):
1252 return False
1253 if ctx is None:
1254 ctx = a.ctx
1255
1256 a_sort = Z3_get_sort(ctx.ctx, a.ast)
1257 b_sort = Z3_get_sort(ctx.ctx, b.ast)
1258 return Z3_is_eq_sort(ctx.ctx, a_sort, b_sort)
1259
1260
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

Referenced by _coerce_exprs().

◆ _coerce_char()

_coerce_char (   ch,
  ctx = None 
)
protected

Definition at line 11123 of file z3py.py.

11123def _coerce_char(ch, ctx=None):
11124 if isinstance(ch, str):
11125 ctx = _get_ctx(ctx)
11126 ch = CharVal(ch, ctx)
11127 if not is_expr(ch):
11128 raise Z3Exception("Character expression expected")
11129 return ch
11130

◆ _coerce_expr_list()

_coerce_expr_list (   alist,
  ctx = None 
)
protected

Definition at line 1292 of file z3py.py.

1292def _coerce_expr_list(alist, ctx=None):
1293 has_expr = False
1294 for a in alist:
1295 if is_expr(a):
1296 has_expr = True
1297 break
1298 if not has_expr:
1299 alist = [_py2expr(a, ctx) for a in alist]
1300 s = _reduce(_coerce_expr_merge, alist, None)
1301 return [s.cast(a) for a in alist]
1302
1303

Referenced by And(), Distinct(), and Or().

◆ _coerce_expr_merge()

_coerce_expr_merge (   s,
  a 
)
protected

Definition at line 1230 of file z3py.py.

1230def _coerce_expr_merge(s, a):
1231 if is_expr(a):
1232 s1 = a.sort()
1233 if s is None:
1234 return s1
1235 if s1.eq(s):
1236 return s
1237 elif s.subsort(s1):
1238 return s1
1239 elif s1.subsort(s):
1240 return s
1241 else:
1242 if z3_debug():
1243 _z3_assert(s1.ctx == s.ctx, "context mismatch")
1244 _z3_assert(False, "sort mismatch")
1245 else:
1246 return s
1247

Referenced by _coerce_exprs().

◆ _coerce_exprs()

_coerce_exprs (   a,
  b,
  ctx = None 
)
protected

Definition at line 1261 of file z3py.py.

1261def _coerce_exprs(a, b, ctx=None):
1262 if not is_expr(a) and not is_expr(b):
1263 a = _py2expr(a, ctx)
1264 b = _py2expr(b, ctx)
1265 if isinstance(a, str) and isinstance(b, SeqRef):
1266 a = StringVal(a, b.ctx)
1267 if isinstance(b, str) and isinstance(a, SeqRef):
1268 b = StringVal(b, a.ctx)
1269 if isinstance(a, float) and isinstance(b, ArithRef):
1270 a = RealVal(a, b.ctx)
1271 if isinstance(b, float) and isinstance(a, ArithRef):
1272 b = RealVal(b, a.ctx)
1273
1274 if _check_same_sort(a, b, ctx):
1275 return (a, b)
1276
1277 s = None
1278 s = _coerce_expr_merge(s, a)
1279 s = _coerce_expr_merge(s, b)
1280 a = s.cast(a)
1281 b = s.cast(b)
1282 return (a, b)
1283
1284

Referenced by ArithRef.__add__(), BitVecRef.__add__(), BitVecRef.__and__(), ArithRef.__div__(), BitVecRef.__div__(), ExprRef.__eq__(), ArithRef.__ge__(), BitVecRef.__ge__(), ArithRef.__gt__(), BitVecRef.__gt__(), ArithRef.__le__(), BitVecRef.__le__(), BitVecRef.__lshift__(), ArithRef.__lt__(), BitVecRef.__lt__(), ArithRef.__mod__(), BitVecRef.__mod__(), ArithRef.__mul__(), BitVecRef.__mul__(), ExprRef.__ne__(), BitVecRef.__or__(), ArithRef.__pow__(), ArithRef.__radd__(), BitVecRef.__radd__(), BitVecRef.__rand__(), ArithRef.__rdiv__(), BitVecRef.__rdiv__(), BitVecRef.__rlshift__(), ArithRef.__rmod__(), BitVecRef.__rmod__(), ArithRef.__rmul__(), BitVecRef.__rmul__(), BitVecRef.__ror__(), ArithRef.__rpow__(), BitVecRef.__rrshift__(), BitVecRef.__rshift__(), ArithRef.__rsub__(), BitVecRef.__rsub__(), BitVecRef.__rxor__(), ArithRef.__sub__(), BitVecRef.__sub__(), BitVecRef.__xor__(), BVAddNoOverflow(), BVAddNoUnderflow(), BVMulNoOverflow(), BVMulNoUnderflow(), BVSDivNoOverflow(), BVSubNoOverflow(), BVSubNoUnderflow(), Extract(), If(), LShR(), RotateLeft(), RotateRight(), SRem(), UDiv(), UGE(), UGT(), ULE(), ULT(), and URem().

◆ _coerce_fp_expr_list()

_coerce_fp_expr_list (   alist,
  ctx 
)
protected

Definition at line 9629 of file z3py.py.

9629def _coerce_fp_expr_list(alist, ctx):
9630 first_fp_sort = None
9631 for a in alist:
9632 if is_fp(a):
9633 if first_fp_sort is None:
9634 first_fp_sort = a.sort()
9635 elif first_fp_sort == a.sort():
9636 pass # OK, same as before
9637 else:
9638 # we saw at least 2 different float sorts; something will
9639 # throw a sort mismatch later, for now assume None.
9640 first_fp_sort = None
9641 break
9642
9643 r = []
9644 for i in range(len(alist)):
9645 a = alist[i]
9646 is_repr = isinstance(a, str) and a.contains("2**(") and a.endswith(")")
9647 if is_repr or _is_int(a) or isinstance(a, (float, bool)):
9648 r.append(FPVal(a, None, first_fp_sort, ctx))
9649 else:
9650 r.append(a)
9651 return _coerce_expr_list(r, ctx)
9652
9653
9654# FP Sorts
9655

◆ _coerce_seq()

_coerce_seq (   s,
  ctx = None 
)
protected

Definition at line 11173 of file z3py.py.

11173def _coerce_seq(s, ctx=None):
11174 if isinstance(s, str):
11175 ctx = _get_ctx(ctx)
11176 s = StringVal(s, ctx)
11177 if not is_expr(s):
11178 raise Z3Exception("Non-expression passed as a sequence")
11179 if not is_seq(s):
11180 raise Z3Exception("Non-sequence passed as a sequence")
11181 return s
11182
11183

Referenced by Concat().

◆ _ctx_from_ast_arg_list()

_ctx_from_ast_arg_list (   args,
  default_ctx = None 
)
protected

Definition at line 511 of file z3py.py.

511def _ctx_from_ast_arg_list(args, default_ctx=None):
512 ctx = None
513 for a in args:
514 if is_ast(a) or is_probe(a):
515 if ctx is None:
516 ctx = a.ctx
517 else:
518 if z3_debug():
519 _z3_assert(ctx == a.ctx, "Context mismatch")
520 if ctx is None:
521 ctx = default_ctx
522 return ctx
523
524

Referenced by _ctx_from_ast_args(), And(), Distinct(), If(), Implies(), IsMember(), IsSubset(), Not(), Or(), SetAdd(), SetDel(), SetDifference(), SetIntersect(), SetUnion(), and Xor().

◆ _ctx_from_ast_args()

_ctx_from_ast_args ( args)
protected

Definition at line 525 of file z3py.py.

525def _ctx_from_ast_args(*args):
526 return _ctx_from_ast_arg_list(args)
527
528

◆ _dflt_fps()

_dflt_fps (   ctx = None)
protected

Definition at line 9625 of file z3py.py.

9625def _dflt_fps(ctx=None):
9626 return get_default_fp_sort(ctx)
9627
9628

◆ _dflt_rm()

_dflt_rm (   ctx = None)
protected

Definition at line 9621 of file z3py.py.

9621def _dflt_rm(ctx=None):
9622 return get_default_rounding_mode(ctx)
9623
9624

◆ _dict2darray()

_dict2darray (   decls,
  ctx 
)
protected

Definition at line 9494 of file z3py.py.

9494def _dict2darray(decls, ctx):
9495 sz = len(decls)
9496 _names = (Symbol * sz)()
9497 _decls = (FuncDecl * sz)()
9498 i = 0
9499 for k in decls:
9500 v = decls[k]
9501 if z3_debug():
9502 _z3_assert(isinstance(k, str), "String expected")
9503 _z3_assert(is_func_decl(v) or is_const(v), "Z3 declaration or constant expected")
9504 _names[i] = to_symbol(k, ctx)
9505 if is_const(v):
9506 _decls[i] = v.decl().ast
9507 else:
9508 _decls[i] = v.ast
9509 i = i + 1
9510 return sz, _names, _decls
9511

◆ _dict2sarray()

_dict2sarray (   sorts,
  ctx 
)
protected

Definition at line 9478 of file z3py.py.

9478def _dict2sarray(sorts, ctx):
9479 sz = len(sorts)
9480 _names = (Symbol * sz)()
9481 _sorts = (Sort * sz)()
9482 i = 0
9483 for k in sorts:
9484 v = sorts[k]
9485 if z3_debug():
9486 _z3_assert(isinstance(k, str), "String expected")
9487 _z3_assert(is_sort(v), "Z3 sort expected")
9488 _names[i] = to_symbol(k, ctx)
9489 _sorts[i] = v.ast
9490 i = i + 1
9491 return sz, _names, _sorts
9492
9493

◆ _get_args()

_get_args (   args)
protected

Definition at line 152 of file z3py.py.

152def _get_args(args):
153 try:
154 if len(args) == 1 and (isinstance(args[0], tuple) or isinstance(args[0], list)):
155 return args[0]
156 elif len(args) == 1 and (isinstance(args[0], set) or isinstance(args[0], AstVector)):
157 return [arg for arg in args[0]]
158 elif len(args) == 1 and isinstance(args[0], Iterator):
159 return list(args[0])
160 else:
161 return args
162 except TypeError: # len is not necessarily defined when args is not a sequence (use reflection?)
163 return args
164
165# Use this when function takes multiple arguments
166
167

Referenced by FuncDeclRef.__call__(), And(), ArraySort(), Goal.assert_exprs(), Solver.assert_exprs(), Solver.check(), Concat(), CreateDatatypes(), Distinct(), FreshFunction(), Function(), Map(), Or(), RecAddDefinition(), RecFunction(), Select(), SetIntersect(), SetUnion(), and Update().

◆ _get_args_ast_list()

_get_args_ast_list (   args)
protected

Definition at line 168 of file z3py.py.

168def _get_args_ast_list(args):
169 try:
170 if isinstance(args, (set, AstVector, tuple)):
171 return [arg for arg in args]
172 else:
173 return args
174 except Exception:
175 return args
176
177

◆ _get_ctx()

Context _get_ctx (   ctx)
protected

Definition at line 270 of file z3py.py.

270def _get_ctx(ctx) -> Context:
271 if ctx is None:
272 return main_ctx()
273 else:
274 return ctx
275
276

Referenced by And(), BitVec(), BitVecs(), BitVecSort(), BitVecVal(), Bool(), Bools(), BoolSort(), BoolVal(), Cbrt(), DatatypeSort(), DeclareSort(), DeclareTypeVar(), EnumSort(), FreshBool(), FreshConst(), FreshInt(), FreshReal(), get_ctx(), If(), Implies(), Int(), Ints(), IntSort(), IntVal(), IntVector(), Model(), Not(), Or(), Real(), Reals(), RealSort(), RealVal(), RealVector(), Sqrt(), to_symbol(), and Xor().

◆ _get_ctx2()

_get_ctx2 (   a,
  b,
  ctx = None 
)
protected

Definition at line 11184 of file z3py.py.

11184def _get_ctx2(a, b, ctx=None):
11185 if is_expr(a):
11186 return a.ctx
11187 if is_expr(b):
11188 return b.ctx
11189 if ctx is None:
11190 ctx = main_ctx()
11191 return ctx
11192
11193

◆ _global_on_model()

_global_on_model (   ctx)
protected

Definition at line 8072 of file z3py.py.

8072def _global_on_model(ctx):
8073 (fn, mdl) = _on_models[ctx]
8074 fn(mdl)
8075
8076

◆ _has_probe()

_has_probe (   args)
protected
Return `True` if one of the elements of the given collection is a Z3 probe.

Definition at line 1933 of file z3py.py.

1933def _has_probe(args):
1934 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1935 for arg in args:
1936 if is_probe(arg):
1937 return True
1938 return False
1939
1940

Referenced by And(), and Or().

◆ _is_algebraic()

_is_algebraic (   ctx,
  a 
)
protected

Definition at line 2830 of file z3py.py.

2830def _is_algebraic(ctx, a):
2831 return Z3_is_algebraic_number(ctx.ref(), a)
2832
2833
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.

Referenced by _to_expr_ref(), and is_algebraic_value().

◆ _is_int()

_is_int (   v)
protected

Definition at line 76 of file z3py.py.

76 def _is_int(v):
77 return isinstance(v, (int, long))

Referenced by ParamDescrsRef.__getitem__(), ModelRef.__getitem__(), _py2expr(), Extract(), RatVal(), RepeatBitVec(), ParamsRef.set(), SignExt(), to_symbol(), and ZeroExt().

◆ _is_numeral()

_is_numeral (   ctx,
  a 
)
protected

Definition at line 2826 of file z3py.py.

2826def _is_numeral(ctx, a):
2827 return Z3_is_numeral_ast(ctx.ref(), a)
2828
2829
bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a)

Referenced by _to_expr_ref(), is_bv_value(), is_int_value(), and is_rational_value().

◆ _mk_bin()

_mk_bin (   f,
  a,
  b 
)
protected

Definition at line 1490 of file z3py.py.

1490def _mk_bin(f, a, b):
1491 args = (Ast * 2)()
1492 if z3_debug():
1493 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1494 args[0] = a.as_ast()
1495 args[1] = b.as_ast()
1496 return f(a.ctx.ref(), 2, args)
1497
1498

Referenced by ArithRef.__add__(), ArithRef.__mul__(), ArithRef.__radd__(), ArithRef.__rmul__(), ArithRef.__rsub__(), and ArithRef.__sub__().

◆ _mk_fp_bin()

_mk_fp_bin (   f,
  rm,
  a,
  b,
  ctx 
)
protected

Definition at line 10468 of file z3py.py.

10468def _mk_fp_bin(f, rm, a, b, ctx):
10469 ctx = _get_ctx(ctx)
10470 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10471 if z3_debug():
10472 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10473 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression")
10474 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10475
10476

◆ _mk_fp_bin_norm()

_mk_fp_bin_norm (   f,
  a,
  b,
  ctx 
)
protected

Definition at line 10477 of file z3py.py.

10477def _mk_fp_bin_norm(f, a, b, ctx):
10478 ctx = _get_ctx(ctx)
10479 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10480 if z3_debug():
10481 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10482 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10483
10484

◆ _mk_fp_bin_pred()

_mk_fp_bin_pred (   f,
  a,
  b,
  ctx 
)
protected

Definition at line 10485 of file z3py.py.

10485def _mk_fp_bin_pred(f, a, b, ctx):
10486 ctx = _get_ctx(ctx)
10487 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10488 if z3_debug():
10489 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10490 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10491
10492

◆ _mk_fp_tern()

_mk_fp_tern (   f,
  rm,
  a,
  b,
  c,
  ctx 
)
protected

Definition at line 10493 of file z3py.py.

10493def _mk_fp_tern(f, rm, a, b, c, ctx):
10494 ctx = _get_ctx(ctx)
10495 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10496 if z3_debug():
10497 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10498 _z3_assert(is_fp(a) or is_fp(b) or is_fp(
10499 c), "Second, third or fourth argument must be a Z3 floating-point expression")
10500 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10501
10502

◆ _mk_fp_unary()

_mk_fp_unary (   f,
  rm,
  a,
  ctx 
)
protected

Definition at line 10451 of file z3py.py.

10451def _mk_fp_unary(f, rm, a, ctx):
10452 ctx = _get_ctx(ctx)
10453 [a] = _coerce_fp_expr_list([a], ctx)
10454 if z3_debug():
10455 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10456 _z3_assert(is_fp(a), "Second argument must be a Z3 floating-point expression")
10457 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
10458
10459

◆ _mk_fp_unary_pred()

_mk_fp_unary_pred (   f,
  a,
  ctx 
)
protected

Definition at line 10460 of file z3py.py.

10460def _mk_fp_unary_pred(f, a, ctx):
10461 ctx = _get_ctx(ctx)
10462 [a] = _coerce_fp_expr_list([a], ctx)
10463 if z3_debug():
10464 _z3_assert(is_fp(a), "First argument must be a Z3 floating-point expression")
10465 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
10466
10467

◆ _mk_quantifier()

_mk_quantifier (   is_forall,
  vs,
  body,
  weight = 1,
  qid = "",
  skid = "",
  patterns = [],
  no_patterns = [] 
)
protected

Definition at line 2289 of file z3py.py.

2289def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2290 if z3_debug():
2291 _z3_assert(is_bool(body) or is_app(vs) or (len(vs) > 0 and is_app(vs[0])), "Z3 expression expected")
2292 _z3_assert(is_const(vs) or (len(vs) > 0 and all([is_const(v) for v in vs])), "Invalid bounded variable(s)")
2293 _z3_assert(all([is_pattern(a) or is_expr(a) for a in patterns]), "Z3 patterns expected")
2294 _z3_assert(all([is_expr(p) for p in no_patterns]), "no patterns are Z3 expressions")
2295 if is_app(vs):
2296 ctx = vs.ctx
2297 vs = [vs]
2298 else:
2299 ctx = vs[0].ctx
2300 if not is_expr(body):
2301 body = BoolVal(body, ctx)
2302 num_vars = len(vs)
2303 if num_vars == 0:
2304 return body
2305 _vs = (Ast * num_vars)()
2306 for i in range(num_vars):
2307 # TODO: Check if is constant
2308 _vs[i] = vs[i].as_ast()
2309 patterns = [_to_pattern(p) for p in patterns]
2310 num_pats = len(patterns)
2311 _pats = (Pattern * num_pats)()
2312 for i in range(num_pats):
2313 _pats[i] = patterns[i].ast
2314 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2315 qid = to_symbol(qid, ctx)
2316 skid = to_symbol(skid, ctx)
2317 return QuantifierRef(Z3_mk_quantifier_const_ex(ctx.ref(), is_forall, weight, qid, skid,
2318 num_vars, _vs,
2319 num_pats, _pats,
2320 num_no_pats, _no_pats,
2321 body.as_ast()), ctx)
2322
2323
Z3_ast Z3_API Z3_mk_quantifier_const_ex(Z3_context c, bool is_forall, unsigned weight, Z3_symbol quantifier_id, Z3_symbol skolem_id, unsigned num_bound, Z3_app const bound[], unsigned num_patterns, Z3_pattern const patterns[], unsigned num_no_patterns, Z3_ast const no_patterns[], Z3_ast body)
Create a universal or existential quantifier using a list of constants that will form the set of boun...

Referenced by Exists(), and ForAll().

◆ _or_else()

_or_else (   t1,
  t2,
  ctx = None 
)
protected

Definition at line 8576 of file z3py.py.

8576def _or_else(t1, t2, ctx=None):
8577 t1 = _to_tactic(t1, ctx)
8578 t2 = _to_tactic(t2, ctx)
8579 if z3_debug():
8580 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8581 return Tactic(Z3_tactic_or_else(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8582
8583
Z3_tactic Z3_API Z3_tactic_or_else(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that first applies t1 to a given goal, if it fails then returns the result of t2 appl...

◆ _pb_args_coeffs()

_pb_args_coeffs (   args,
  default_ctx = None 
)
protected

Definition at line 9267 of file z3py.py.

9267def _pb_args_coeffs(args, default_ctx=None):
9268 args = _get_args_ast_list(args)
9269 if len(args) == 0:
9270 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
9271 args = [_reorder_pb_arg(arg) for arg in args]
9272 args, coeffs = zip(*args)
9273 if z3_debug():
9274 _z3_assert(len(args) > 0, "Non empty list of arguments expected")
9275 ctx = _ctx_from_ast_arg_list(args)
9276 if z3_debug():
9277 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9278 args = _coerce_expr_list(args, ctx)
9279 _args, sz = _to_ast_array(args)
9280 _coeffs = (ctypes.c_int * len(coeffs))()
9281 for i in range(len(coeffs)):
9282 _z3_check_cint_overflow(coeffs[i], "coefficient")
9283 _coeffs[i] = coeffs[i]
9284 return ctx, sz, _args, _coeffs, args
9285
9286

◆ _probe_and()

_probe_and (   args,
  ctx 
)
protected

Definition at line 8991 of file z3py.py.

8991def _probe_and(args, ctx):
8992 return _probe_nary(Z3_probe_and, args, ctx)
8993
8994

Referenced by And().

◆ _probe_nary()

_probe_nary (   f,
  args,
  ctx 
)
protected

Definition at line 8981 of file z3py.py.

8981def _probe_nary(f, args, ctx):
8982 if z3_debug():
8983 _z3_assert(len(args) > 0, "At least one argument expected")
8984 num = len(args)
8985 r = _to_probe(args[0], ctx)
8986 for i in range(num - 1):
8987 r = Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
8988 return r
8989
8990

◆ _probe_or()

_probe_or (   args,
  ctx 
)
protected

Definition at line 8995 of file z3py.py.

8995def _probe_or(args, ctx):
8996 return _probe_nary(Z3_probe_or, args, ctx)
8997
8998

Referenced by Or().

◆ _prove_html()

_prove_html (   claim,
  show = False,
**  keywords 
)
protected
Version of function `prove` that renders HTML.

Definition at line 9458 of file z3py.py.

9458def _prove_html(claim, show=False, **keywords):
9459 """Version of function `prove` that renders HTML."""
9460 if z3_debug():
9461 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9462 s = Solver()
9463 s.set(**keywords)
9464 s.add(Not(claim))
9465 if show:
9466 print(s)
9467 r = s.check()
9468 if r == unsat:
9469 print("<b>proved</b>")
9470 elif r == unknown:
9471 print("<b>failed to prove</b>")
9472 print(s.model())
9473 else:
9474 print("<b>counterexample</b>")
9475 print(s.model())
9476
9477

◆ _py2expr()

_py2expr (   a,
  ctx = None 
)
protected

Definition at line 3231 of file z3py.py.

3231def _py2expr(a, ctx=None):
3232 if isinstance(a, bool):
3233 return BoolVal(a, ctx)
3234 if _is_int(a):
3235 return IntVal(a, ctx)
3236 if isinstance(a, float):
3237 return RealVal(a, ctx)
3238 if isinstance(a, str):
3239 return StringVal(a, ctx)
3240 if is_expr(a):
3241 return a
3242 if z3_debug():
3243 _z3_assert(False, "Python bool, int, long or float expected")
3244
3245

Referenced by _coerce_expr_list(), _coerce_exprs(), IsMember(), K(), SetAdd(), SetDel(), and ModelRef.update_value().

◆ _reduce()

_reduce (   func,
  sequence,
  initial 
)
protected

Definition at line 1285 of file z3py.py.

1285def _reduce(func, sequence, initial):
1286 result = initial
1287 for element in sequence:
1288 result = func(result, element)
1289 return result
1290
1291

Referenced by _coerce_expr_list().

◆ _reorder_pb_arg()

_reorder_pb_arg (   arg)
protected

Definition at line 9260 of file z3py.py.

9260def _reorder_pb_arg(arg):
9261 a, b = arg
9262 if not _is_int(b) and _is_int(a):
9263 return b, a
9264 return arg
9265
9266

◆ _solve_html()

_solve_html ( args,
**  keywords 
)
protected
Version of function `solve` that renders HTML output.

Definition at line 9409 of file z3py.py.

9409def _solve_html(*args, **keywords):
9410 """Version of function `solve` that renders HTML output."""
9411 show = keywords.pop("show", False)
9412 s = Solver()
9413 s.set(**keywords)
9414 s.add(*args)
9415 if show:
9416 print("<b>Problem:</b>")
9417 print(s)
9418 r = s.check()
9419 if r == unsat:
9420 print("<b>no solution</b>")
9421 elif r == unknown:
9422 print("<b>failed to solve</b>")
9423 try:
9424 print(s.model())
9425 except Z3Exception:
9426 return
9427 else:
9428 if show:
9429 print("<b>Solution:</b>")
9430 print(s.model())
9431
9432

◆ _solve_using_html()

_solve_using_html (   s,
args,
**  keywords 
)
protected
Version of function `solve_using` that renders HTML.

Definition at line 9433 of file z3py.py.

9433def _solve_using_html(s, *args, **keywords):
9434 """Version of function `solve_using` that renders HTML."""
9435 show = keywords.pop("show", False)
9436 if z3_debug():
9437 _z3_assert(isinstance(s, Solver), "Solver object expected")
9438 s.set(**keywords)
9439 s.add(*args)
9440 if show:
9441 print("<b>Problem:</b>")
9442 print(s)
9443 r = s.check()
9444 if r == unsat:
9445 print("<b>no solution</b>")
9446 elif r == unknown:
9447 print("<b>failed to solve</b>")
9448 try:
9449 print(s.model())
9450 except Z3Exception:
9451 return
9452 else:
9453 if show:
9454 print("<b>Solution:</b>")
9455 print(s.model())
9456
9457

◆ _sort()

SortRef _sort ( Context  ctx,
Any  a 
)
protected

Definition at line 709 of file z3py.py.

709def _sort(ctx : Context, a : Any) -> SortRef:
710 return _to_sort_ref(Z3_get_sort(ctx.ref(), a), ctx)
711
712

◆ _sort_kind()

_sort_kind (   ctx,
  s 
)
protected

Sorts.

Definition at line 569 of file z3py.py.

569def _sort_kind(ctx, s):
570 return Z3_get_sort_kind(ctx.ref(), s)
571
572
Z3_sort_kind Z3_API Z3_get_sort_kind(Z3_context c, Z3_sort t)
Return the sort kind (e.g., array, tuple, int, bool, etc).

Referenced by _to_sort_ref().

◆ _symbol2py()

_symbol2py (   ctx,
  s 
)
protected
Convert a Z3 symbol back into a Python object. 

Definition at line 140 of file z3py.py.

140def _symbol2py(ctx, s):
141 """Convert a Z3 symbol back into a Python object. """
142 if Z3_get_symbol_kind(ctx.ref(), s) == Z3_INT_SYMBOL:
143 return "k!%s" % Z3_get_symbol_int(ctx.ref(), s)
144 else:
145 return Z3_get_symbol_string(ctx.ref(), s)
146
147# Hack for having nary functions that can receive one argument that is the
148# list of arguments.
149# Use this when function takes a single list of arguments
150
151
int Z3_API Z3_get_symbol_int(Z3_context c, Z3_symbol s)
Return the symbol int value.
Z3_symbol_kind Z3_API Z3_get_symbol_kind(Z3_context c, Z3_symbol s)
Return Z3_INT_SYMBOL if the symbol was constructed using Z3_mk_int_symbol, and Z3_STRING_SYMBOL if th...
Z3_string Z3_API Z3_get_symbol_string(Z3_context c, Z3_symbol s)
Return the symbol name.

Referenced by ParamDescrsRef.get_name(), SortRef.name(), QuantifierRef.qid(), QuantifierRef.skolem_id(), and QuantifierRef.var_name().

◆ _to_ast_array()

_to_ast_array (   args)
protected

Definition at line 537 of file z3py.py.

537def _to_ast_array(args):
538 sz = len(args)
539 _args = (Ast * sz)()
540 for i in range(sz):
541 _args[i] = args[i].as_ast()
542 return _args, sz
543
544

Referenced by ExprRef.__ne__(), _array_select(), _mk_quantifier(), And(), Distinct(), Map(), MultiPattern(), Or(), SetIntersect(), SetUnion(), and Update().

◆ _to_ast_ref()

_to_ast_ref (   a,
  ctx 
)
protected

Definition at line 553 of file z3py.py.

553def _to_ast_ref(a, ctx):
554 k = _ast_kind(ctx, a)
555 if k == Z3_SORT_AST:
556 return _to_sort_ref(a, ctx)
557 elif k == Z3_FUNC_DECL_AST:
558 return _to_func_decl_ref(a, ctx)
559 else:
560 return _to_expr_ref(a, ctx)
561
562

Referenced by AstRef.__deepcopy__(), AstVector.__getitem__(), AstMap.__getitem__(), and AstRef.translate().

◆ _to_expr_ref()

_to_expr_ref (   a,
  ctx 
)
protected

Definition at line 1180 of file z3py.py.

1180def _to_expr_ref(a, ctx):
1181 if isinstance(a, Pattern):
1182 return PatternRef(a, ctx)
1183 ctx_ref = ctx.ref()
1184 k = Z3_get_ast_kind(ctx_ref, a)
1185 if k == Z3_QUANTIFIER_AST:
1186 return QuantifierRef(a, ctx)
1187 sk = Z3_get_sort_kind(ctx_ref, Z3_get_sort(ctx_ref, a))
1188 if sk == Z3_BOOL_SORT:
1189 return BoolRef(a, ctx)
1190 if sk == Z3_INT_SORT:
1191 if k == Z3_NUMERAL_AST:
1192 return IntNumRef(a, ctx)
1193 return ArithRef(a, ctx)
1194 if sk == Z3_REAL_SORT:
1195 if k == Z3_NUMERAL_AST:
1196 return RatNumRef(a, ctx)
1197 if _is_algebraic(ctx, a):
1198 return AlgebraicNumRef(a, ctx)
1199 return ArithRef(a, ctx)
1200 if sk == Z3_BV_SORT:
1201 if k == Z3_NUMERAL_AST:
1202 return BitVecNumRef(a, ctx)
1203 else:
1204 return BitVecRef(a, ctx)
1205 if sk == Z3_ARRAY_SORT:
1206 return ArrayRef(a, ctx)
1207 if sk == Z3_DATATYPE_SORT:
1208 return DatatypeRef(a, ctx)
1209 if sk == Z3_FLOATING_POINT_SORT:
1210 if k == Z3_APP_AST and _is_numeral(ctx, a):
1211 return FPNumRef(a, ctx)
1212 else:
1213 return FPRef(a, ctx)
1214 if sk == Z3_FINITE_DOMAIN_SORT:
1215 if k == Z3_NUMERAL_AST:
1216 return FiniteDomainNumRef(a, ctx)
1217 else:
1218 return FiniteDomainRef(a, ctx)
1219 if sk == Z3_ROUNDING_MODE_SORT:
1220 return FPRMRef(a, ctx)
1221 if sk == Z3_SEQ_SORT:
1222 return SeqRef(a, ctx)
1223 if sk == Z3_CHAR_SORT:
1224 return CharRef(a, ctx)
1225 if sk == Z3_RE_SORT:
1226 return ReRef(a, ctx)
1227 return ExprRef(a, ctx)
1228
1229

Referenced by FuncDeclRef.__call__(), _array_select(), _to_ast_ref(), ExprRef.arg(), FuncEntry.arg_value(), QuantifierRef.body(), Const(), ArrayRef.default(), FuncInterp.else_value(), ModelRef.eval(), Ext(), FreshConst(), Goal.get(), ModelRef.get_interp(), If(), QuantifierRef.no_pattern(), ModelRef.project(), ModelRef.project_with_witness(), Update(), FuncEntry.value(), and Var().

◆ _to_float_str()

_to_float_str (   val,
  exp = 0 
)
protected

Definition at line 10213 of file z3py.py.

10213def _to_float_str(val, exp=0):
10214 if isinstance(val, float):
10215 if math.isnan(val):
10216 res = "NaN"
10217 elif val == 0.0:
10218 sone = math.copysign(1.0, val)
10219 if sone < 0.0:
10220 return "-0.0"
10221 else:
10222 return "+0.0"
10223 elif val == float("+inf"):
10224 res = "+oo"
10225 elif val == float("-inf"):
10226 res = "-oo"
10227 else:
10228 v = val.as_integer_ratio()
10229 num = v[0]
10230 den = v[1]
10231 rvs = str(num) + "/" + str(den)
10232 res = rvs + "p" + _to_int_str(exp)
10233 elif isinstance(val, bool):
10234 if val:
10235 res = "1.0"
10236 else:
10237 res = "0.0"
10238 elif _is_int(val):
10239 res = str(val)
10240 elif isinstance(val, str):
10241 inx = val.find("*(2**")
10242 if inx == -1:
10243 res = val
10244 elif val[-1] == ")":
10245 res = val[0:inx]
10246 exp = str(int(val[inx + 5:-1]) + int(exp))
10247 else:
10248 _z3_assert(False, "String does not have floating-point numeral form.")
10249 elif z3_debug():
10250 _z3_assert(False, "Python value cannot be used to create floating-point numerals.")
10251 if exp == 0:
10252 return res
10253 else:
10254 return res + "p" + exp
10255
10256

◆ _to_func_decl_array()

_to_func_decl_array (   args)
protected

Definition at line 529 of file z3py.py.

529def _to_func_decl_array(args):
530 sz = len(args)
531 _args = (FuncDecl * sz)()
532 for i in range(sz):
533 _args[i] = args[i].as_func_decl()
534 return _args, sz
535
536

◆ _to_func_decl_ref()

_to_func_decl_ref (   a,
  ctx 
)
protected

Definition at line 945 of file z3py.py.

945def _to_func_decl_ref(a, ctx):
946 return FuncDeclRef(a, ctx)
947
948

Referenced by _to_ast_ref().

◆ _to_goal()

_to_goal (   a)
protected

Definition at line 8552 of file z3py.py.

8552def _to_goal(a):
8553 if isinstance(a, BoolRef):
8554 goal = Goal(ctx=a.ctx)
8555 goal.add(a)
8556 return goal
8557 else:
8558 return a
8559
8560

◆ _to_int_str()

_to_int_str (   val)
protected

Definition at line 3280 of file z3py.py.

3280def _to_int_str(val):
3281 if isinstance(val, float):
3282 return str(int(val))
3283 elif isinstance(val, bool):
3284 if val:
3285 return "1"
3286 else:
3287 return "0"
3288 else:
3289 return str(val)
3290
3291

Referenced by BitVecVal(), and IntVal().

◆ _to_param_value()

_to_param_value (   val)
protected

Definition at line 178 of file z3py.py.

178def _to_param_value(val):
179 if isinstance(val, bool):
180 return "true" if val else "false"
181 return str(val)
182
183

Referenced by Context.__init__(), and set_param().

◆ _to_pattern()

_to_pattern (   arg)
protected

Definition at line 2067 of file z3py.py.

2067def _to_pattern(arg):
2068 if is_pattern(arg):
2069 return arg
2070 else:
2071 return MultiPattern(arg)
2072

Referenced by _mk_quantifier().

◆ _to_probe()

_to_probe (   p,
  ctx = None 
)
protected

Definition at line 8935 of file z3py.py.

8935def _to_probe(p, ctx=None):
8936 if is_probe(p):
8937 return p
8938 else:
8939 return Probe(p, ctx)
8940
8941

◆ _to_ref_array()

_to_ref_array (   ref,
  args 
)
protected

Definition at line 545 of file z3py.py.

545def _to_ref_array(ref, args):
546 sz = len(args)
547 _args = (ref * sz)()
548 for i in range(sz):
549 _args[i] = args[i].as_ast()
550 return _args, sz
551
552

◆ _to_sort_ref()

_to_sort_ref (   s,
  ctx 
)
protected

Definition at line 678 of file z3py.py.

678def _to_sort_ref(s, ctx):
679 if z3_debug():
680 _z3_assert(isinstance(s, Sort), "Z3 Sort expected")
681 k = _sort_kind(ctx, s)
682 if k == Z3_BOOL_SORT:
683 return BoolSortRef(s, ctx)
684 elif k == Z3_INT_SORT or k == Z3_REAL_SORT:
685 return ArithSortRef(s, ctx)
686 elif k == Z3_BV_SORT:
687 return BitVecSortRef(s, ctx)
688 elif k == Z3_ARRAY_SORT:
689 return ArraySortRef(s, ctx)
690 elif k == Z3_DATATYPE_SORT:
691 return DatatypeSortRef(s, ctx)
692 elif k == Z3_FINITE_DOMAIN_SORT:
693 return FiniteDomainSortRef(s, ctx)
694 elif k == Z3_FLOATING_POINT_SORT:
695 return FPSortRef(s, ctx)
696 elif k == Z3_ROUNDING_MODE_SORT:
697 return FPRMSortRef(s, ctx)
698 elif k == Z3_RE_SORT:
699 return ReSortRef(s, ctx)
700 elif k == Z3_SEQ_SORT:
701 return SeqSortRef(s, ctx)
702 elif k == Z3_CHAR_SORT:
703 return CharSortRef(s, ctx)
704 elif k == Z3_TYPE_VAR:
705 return TypeVarRef(s, ctx)
706 return SortRef(s, ctx)
707
708

Referenced by _sort(), _to_ast_ref(), FuncDeclRef.domain(), ArraySortRef.domain_n(), ModelRef.get_sort(), FuncDeclRef.range(), ArraySortRef.range(), and QuantifierRef.var_sort().

◆ _to_tactic()

_to_tactic (   t,
  ctx = None 
)
protected

Definition at line 8561 of file z3py.py.

8561def _to_tactic(t, ctx=None):
8562 if isinstance(t, Tactic):
8563 return t
8564 else:
8565 return Tactic(t, ctx)
8566
8567

◆ _valid_accessor()

_valid_accessor (   acc)
protected

Datatypes.

Return `True` if acc is pair of the form (String, Datatype or Sort). 

Definition at line 5164 of file z3py.py.

5164def _valid_accessor(acc):
5165 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
5166 if not isinstance(acc, tuple):
5167 return False
5168 if len(acc) != 2:
5169 return False
5170 return isinstance(acc[0], str) and (isinstance(acc[1], Datatype) or is_sort(acc[1]))
5171
5172

Referenced by Datatype.declare_core().

◆ _z3_assert()

_z3_assert (   cond,
  msg 
)
protected

◆ _z3_check_cint_overflow()

_z3_check_cint_overflow (   n,
  name 
)
protected

Definition at line 118 of file z3py.py.

118def _z3_check_cint_overflow(n, name):
119 _z3_assert(ctypes.c_int(n).value == n, name + " is too large")
120
121

◆ Abs()

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

Definition at line 9219 of file z3py.py.

9219def Abs(arg):
9220 """Create the absolute value of an arithmetic expression"""
9221 return If(arg > 0, arg, -arg)
9222
9223

◆ AllChar()

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

Definition at line 11656 of file z3py.py.

11656def AllChar(regex_sort, ctx=None):
11657 """Create a regular expression that accepts all single character strings
11658 """
11659 return ReRef(Z3_mk_re_allchar(regex_sort.ctx_ref(), regex_sort.ast), regex_sort.ctx)
11660
11661# Special Relations
11662
11663
Z3_ast Z3_API Z3_mk_re_allchar(Z3_context c, Z3_sort regex_sort)
Create a regular expression that accepts all singleton sequences of the regular expression sort.

◆ And()

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

1941def And(*args):
1942 """Create a Z3 and-expression or and-probe.
1943
1944 >>> p, q, r = Bools('p q r')
1945 >>> And(p, q, r)
1946 And(p, q, r)
1947 >>> P = BoolVector('p', 5)
1948 >>> And(P)
1949 And(p__0, p__1, p__2, p__3, p__4)
1950 """
1951 last_arg = None
1952 if len(args) > 0:
1953 last_arg = args[len(args) - 1]
1954 if isinstance(last_arg, Context):
1955 ctx = args[len(args) - 1]
1956 args = args[:len(args) - 1]
1957 elif len(args) == 1 and isinstance(args[0], AstVector):
1958 ctx = args[0].ctx
1959 args = [a for a in args[0]]
1960 else:
1961 ctx = None
1962 args = _get_args(args)
1963 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1964 if z3_debug():
1965 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1966 if _has_probe(args):
1967 return _probe_and(args, ctx)
1968 else:
1969 args = _coerce_expr_list(args, ctx)
1970 _args, sz = _to_ast_array(args)
1971 return BoolRef(Z3_mk_and(ctx.ref(), sz, _args), ctx)
1972
1973
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].

Referenced by BoolRef.__and__(), and Goal.as_expr().

◆ AndThen()

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

8584def AndThen(*ts, **ks):
8585 """Return a tactic that applies the tactics in `*ts` in sequence.
8586
8587 >>> x, y = Ints('x y')
8588 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
8589 >>> t(And(x == 0, y > x + 1))
8590 [[Not(y <= 1)]]
8591 >>> t(And(x == 0, y > x + 1)).as_expr()
8592 Not(y <= 1)
8593 """
8594 if z3_debug():
8595 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8596 ctx = ks.get("ctx", None)
8597 num = len(ts)
8598 r = ts[0]
8599 for i in range(num - 1):
8600 r = _and_then(r, ts[i + 1], ctx)
8601 return r
8602
8603

◆ append_log()

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

Definition at line 127 of file z3py.py.

127def append_log(s):
128 """Append user-defined string to interaction log. """
130
131
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.

◆ args2params()

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

5613def args2params(arguments, keywords, ctx=None):
5614 """Convert python arguments into a Z3_params object.
5615 A ':' is added to the keywords, and '_' is replaced with '-'
5616
5617 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5618 (params model true relevancy 2 elim_and true)
5619 """
5620 if z3_debug():
5621 _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
5622 prev = None
5623 r = ParamsRef(ctx)
5624 for a in arguments:
5625 if prev is None:
5626 prev = a
5627 else:
5628 r.set(prev, a)
5629 prev = None
5630 for k in keywords:
5631 v = keywords[k]
5632 r.set(k, v)
5633 return r
5634
5635

Referenced by Solver.set().

◆ Array()

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

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

Definition at line 4867 of file z3py.py.

4867def Array(name, *sorts):
4868 """Return an array constant named `name` with the given domain and range sorts.
4869
4870 >>> a = Array('a', IntSort(), IntSort())
4871 >>> a.sort()
4872 Array(Int, Int)
4873 >>> a[0]
4874 a[0]
4875 """
4876 s = ArraySort(sorts)
4877 ctx = s.ctx
4878 return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4879
4880
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.

◆ ArraySort()

ArraySort ( sig)
Return the Z3 array sort with the given domain and range sorts.

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

Definition at line 4834 of file z3py.py.

4834def ArraySort(*sig):
4835 """Return the Z3 array sort with the given domain and range sorts.
4836
4837 >>> A = ArraySort(IntSort(), BoolSort())
4838 >>> A
4839 Array(Int, Bool)
4840 >>> A.domain()
4841 Int
4842 >>> A.range()
4843 Bool
4844 >>> AA = ArraySort(IntSort(), A)
4845 >>> AA
4846 Array(Int, Array(Int, Bool))
4847 """
4848 sig = _get_args(sig)
4849 if z3_debug():
4850 _z3_assert(len(sig) > 1, "At least two arguments expected")
4851 arity = len(sig) - 1
4852 r = sig[arity]
4853 d = sig[0]
4854 if z3_debug():
4855 for s in sig:
4856 _z3_assert(is_sort(s), "Z3 sort expected")
4857 _z3_assert(s.ctx == r.ctx, "Context mismatch")
4858 ctx = d.ctx
4859 if len(sig) == 2:
4860 return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4861 dom = (Sort * arity)()
4862 for i in range(arity):
4863 dom[i] = sig[i].ast
4864 return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
4865
4866
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.

Referenced by SortRef.__gt__(), Array(), and SetSort().

◆ AtLeast()

AtLeast ( args)
Create an at-least Pseudo-Boolean k constraint.

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

Definition at line 9242 of file z3py.py.

9242def AtLeast(*args):
9243 """Create an at-least Pseudo-Boolean k constraint.
9244
9245 >>> a, b, c = Bools('a b c')
9246 >>> f = AtLeast(a, b, c, 2)
9247 """
9248 args = _get_args(args)
9249 if z3_debug():
9250 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9251 ctx = _ctx_from_ast_arg_list(args)
9252 if z3_debug():
9253 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9254 args1 = _coerce_expr_list(args[:-1], ctx)
9255 k = args[-1]
9256 _args, sz = _to_ast_array(args1)
9257 return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
9258
9259
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.

◆ AtMost()

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

9224def AtMost(*args):
9225 """Create an at-most Pseudo-Boolean k constraint.
9226
9227 >>> a, b, c = Bools('a b c')
9228 >>> f = AtMost(a, b, c, 2)
9229 """
9230 args = _get_args(args)
9231 if z3_debug():
9232 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9233 ctx = _ctx_from_ast_arg_list(args)
9234 if z3_debug():
9235 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9236 args1 = _coerce_expr_list(args[:-1], ctx)
9237 k = args[-1]
9238 _args, sz = _to_ast_array(args1)
9239 return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
9240
9241
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.

◆ BitVec()

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

4148def BitVec(name, bv, ctx=None):
4149 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
4150 If `ctx=None`, then the global context is used.
4151
4152 >>> x = BitVec('x', 16)
4153 >>> is_bv(x)
4154 True
4155 >>> x.size()
4156 16
4157 >>> x.sort()
4158 BitVec(16)
4159 >>> word = BitVecSort(16)
4160 >>> x2 = BitVec('x', word)
4161 >>> eq(x, x2)
4162 True
4163 """
4164 if isinstance(bv, BitVecSortRef):
4165 ctx = bv.ctx
4166 else:
4167 ctx = _get_ctx(ctx)
4168 bv = BitVecSort(bv, ctx)
4169 return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
4170
4171

Referenced by BitVecs().

◆ BitVecs()

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

4172def BitVecs(names, bv, ctx=None):
4173 """Return a tuple of bit-vector constants of size bv.
4174
4175 >>> x, y, z = BitVecs('x y z', 16)
4176 >>> x.size()
4177 16
4178 >>> x.sort()
4179 BitVec(16)
4180 >>> Sum(x, y, z)
4181 0 + x + y + z
4182 >>> Product(x, y, z)
4183 1*x*y*z
4184 >>> simplify(Product(x, y, z))
4185 x*y*z
4186 """
4187 ctx = _get_ctx(ctx)
4188 if isinstance(names, str):
4189 names = names.split(" ")
4190 return [BitVec(name, bv, ctx) for name in names]
4191
4192

◆ BitVecSort()

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

4116def BitVecSort(sz, ctx=None):
4117 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
4118
4119 >>> Byte = BitVecSort(8)
4120 >>> Word = BitVecSort(16)
4121 >>> Byte
4122 BitVec(8)
4123 >>> x = Const('x', Byte)
4124 >>> eq(x, BitVec('x', 8))
4125 True
4126 """
4127 ctx = _get_ctx(ctx)
4128 return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
4129
4130
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.

Referenced by BitVec(), and BitVecVal().

◆ BitVecVal()

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

4131def BitVecVal(val, bv, ctx=None):
4132 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
4133
4134 >>> v = BitVecVal(10, 32)
4135 >>> v
4136 10
4137 >>> print("0x%.8x" % v.as_long())
4138 0x0000000a
4139 """
4140 if is_bv_sort(bv):
4141 ctx = bv.ctx
4142 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
4143 else:
4144 ctx = _get_ctx(ctx)
4145 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
4146
4147
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.

◆ Bool()

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

1820def Bool(name, ctx=None):
1821 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1822
1823 >>> p = Bool('p')
1824 >>> q = Bool('q')
1825 >>> And(p, q)
1826 And(p, q)
1827 """
1828 ctx = _get_ctx(ctx)
1829 return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
1830
1831

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

◆ Bools()

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

1832def Bools(names, ctx=None):
1833 """Return a tuple of Boolean constants.
1834
1835 `names` is a single string containing all names separated by blank spaces.
1836 If `ctx=None`, then the global context is used.
1837
1838 >>> p, q, r = Bools('p q r')
1839 >>> And(p, Or(q, r))
1840 And(p, Or(q, r))
1841 """
1842 ctx = _get_ctx(ctx)
1843 if isinstance(names, str):
1844 names = names.split(" ")
1845 return [Bool(name, ctx) for name in names]
1846
1847

◆ BoolSort()

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

1783def BoolSort(ctx=None):
1784 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1785
1786 >>> BoolSort()
1787 Bool
1788 >>> p = Const('p', BoolSort())
1789 >>> is_bool(p)
1790 True
1791 >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1792 >>> r(0, 1)
1793 r(0, 1)
1794 >>> is_bool(r(0, 1))
1795 True
1796 """
1797 ctx = _get_ctx(ctx)
1798 return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
1799
1800
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.

Referenced by Goal.assert_exprs(), Solver.assert_exprs(), Bool(), Solver.check(), FreshBool(), If(), Implies(), Not(), SetSort(), and Xor().

◆ BoolVal()

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

1801def BoolVal(val, ctx=None):
1802 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1803
1804 >>> BoolVal(True)
1805 True
1806 >>> is_true(BoolVal(True))
1807 True
1808 >>> is_true(True)
1809 False
1810 >>> is_false(BoolVal(False))
1811 True
1812 """
1813 ctx = _get_ctx(ctx)
1814 if val:
1815 return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1816 else:
1817 return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1818
1819
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.

Referenced by _mk_quantifier(), _py2expr(), and Goal.as_expr().

◆ BoolVector()

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

1848def BoolVector(prefix, sz, ctx=None):
1849 """Return a list of Boolean constants of size `sz`.
1850
1851 The constants are named using the given prefix.
1852 If `ctx=None`, then the global context is used.
1853
1854 >>> P = BoolVector('p', 3)
1855 >>> P
1856 [p__0, p__1, p__2]
1857 >>> And(P)
1858 And(p__0, p__1, p__2)
1859 """
1860 return [Bool("%s__%s" % (prefix, i)) for i in range(sz)]
1861
1862

◆ BV2Int()

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

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

Definition at line 4084 of file z3py.py.

4084def BV2Int(a, is_signed=False):
4085 """Return the Z3 expression BV2Int(a).
4086
4087 >>> b = BitVec('b', 3)
4088 >>> BV2Int(b).sort()
4089 Int
4090 >>> x = Int('x')
4091 >>> x > BV2Int(b)
4092 x > BV2Int(b)
4093 >>> x > BV2Int(b, is_signed=False)
4094 x > BV2Int(b)
4095 >>> x > BV2Int(b, is_signed=True)
4096 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
4097 >>> solve(x > BV2Int(b), b == 1, x < 3)
4098 [x = 2, b = 1]
4099 """
4100 if z3_debug():
4101 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4102 ctx = a.ctx
4103 # investigate problem with bv2int
4104 return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
4105
4106
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast t1, bool is_signed)
Create an integer from the bit-vector argument t1. If is_signed is false, then the bit-vector t1 is t...

◆ BVAddNoOverflow()

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

Definition at line 4593 of file z3py.py.

4593def BVAddNoOverflow(a, b, signed):
4594 """A predicate the determines that bit-vector addition does not overflow"""
4595 _check_bv_args(a, b)
4596 a, b = _coerce_exprs(a, b)
4597 return BoolRef(Z3_mk_bvadd_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4598
4599
Z3_ast Z3_API Z3_mk_bvadd_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise addition of t1 and t2 does not overflow.

◆ BVAddNoUnderflow()

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

Definition at line 4600 of file z3py.py.

4600def BVAddNoUnderflow(a, b):
4601 """A predicate the determines that signed bit-vector addition does not underflow"""
4602 _check_bv_args(a, b)
4603 a, b = _coerce_exprs(a, b)
4604 return BoolRef(Z3_mk_bvadd_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4605
4606
Z3_ast Z3_API Z3_mk_bvadd_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed addition of t1 and t2 does not underflow.

◆ BVMulNoOverflow()

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

Definition at line 4635 of file z3py.py.

4635def BVMulNoOverflow(a, b, signed):
4636 """A predicate the determines that bit-vector multiplication does not overflow"""
4637 _check_bv_args(a, b)
4638 a, b = _coerce_exprs(a, b)
4639 return BoolRef(Z3_mk_bvmul_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4640
4641
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise multiplication of t1 and t2 does not overflow.

◆ BVMulNoUnderflow()

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

Definition at line 4642 of file z3py.py.

4642def BVMulNoUnderflow(a, b):
4643 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4644 _check_bv_args(a, b)
4645 a, b = _coerce_exprs(a, b)
4646 return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4647
4648
Z3_ast Z3_API Z3_mk_bvmul_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed multiplication of t1 and t2 does not underflo...

◆ BVRedAnd()

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

Definition at line 4579 of file z3py.py.

4579def BVRedAnd(a):
4580 """Return the reduction-and expression of `a`."""
4581 if z3_debug():
4582 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4583 return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
4584
4585
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.

◆ BVRedOr()

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

Definition at line 4586 of file z3py.py.

4586def BVRedOr(a):
4587 """Return the reduction-or expression of `a`."""
4588 if z3_debug():
4589 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4590 return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
4591
4592
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.

◆ BVSDivNoOverflow()

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

Definition at line 4621 of file z3py.py.

4621def BVSDivNoOverflow(a, b):
4622 """A predicate the determines that bit-vector signed division does not overflow"""
4623 _check_bv_args(a, b)
4624 a, b = _coerce_exprs(a, b)
4625 return BoolRef(Z3_mk_bvsdiv_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4626
4627
Z3_ast Z3_API Z3_mk_bvsdiv_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed division of t1 and t2 does not overflow.

◆ BVSNegNoOverflow()

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

Definition at line 4628 of file z3py.py.

4628def BVSNegNoOverflow(a):
4629 """A predicate the determines that bit-vector unary negation does not overflow"""
4630 if z3_debug():
4631 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4632 return BoolRef(Z3_mk_bvneg_no_overflow(a.ctx_ref(), a.as_ast()), a.ctx)
4633
4634
Z3_ast Z3_API Z3_mk_bvneg_no_overflow(Z3_context c, Z3_ast t1)
Check that bit-wise negation does not overflow when t1 is interpreted as a signed bit-vector.

◆ BVSubNoOverflow()

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

Definition at line 4607 of file z3py.py.

4607def BVSubNoOverflow(a, b):
4608 """A predicate the determines that bit-vector subtraction does not overflow"""
4609 _check_bv_args(a, b)
4610 a, b = _coerce_exprs(a, b)
4611 return BoolRef(Z3_mk_bvsub_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4612
4613
Z3_ast Z3_API Z3_mk_bvsub_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed subtraction of t1 and t2 does not overflow.

◆ BVSubNoUnderflow()

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

Definition at line 4614 of file z3py.py.

4614def BVSubNoUnderflow(a, b, signed):
4615 """A predicate the determines that bit-vector subtraction does not underflow"""
4616 _check_bv_args(a, b)
4617 a, b = _coerce_exprs(a, b)
4618 return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4619
4620
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise subtraction of t1 and t2 does not underflow.

◆ Cbrt()

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

3530def Cbrt(a, ctx=None):
3531 """ Return a Z3 expression which represents the cubic root of a.
3532
3533 >>> x = Real('x')
3534 >>> Cbrt(x)
3535 x**(1/3)
3536 """
3537 if not is_expr(a):
3538 ctx = _get_ctx(ctx)
3539 a = RealVal(a, ctx)
3540 return a ** "1/3"
3541

◆ CharFromBv()

CharFromBv (   bv)

Definition at line 11156 of file z3py.py.

11156def CharFromBv(bv):
11157 if not is_expr(bv):
11158 raise Z3Exception("Bit-vector expression needed")
11159 return _to_expr_ref(Z3_mk_char_from_bv(bv.ctx_ref(), bv.as_ast()), bv.ctx)
11160
Z3_ast Z3_API Z3_mk_char_from_bv(Z3_context c, Z3_ast bv)
Create a character from a bit-vector (code point).

◆ CharIsDigit()

CharIsDigit (   ch,
  ctx = None 
)

Definition at line 11169 of file z3py.py.

11169def CharIsDigit(ch, ctx=None):
11170 ch = _coerce_char(ch, ctx)
11171 return ch.is_digit()
11172

◆ CharSort()

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

Definition at line 11052 of file z3py.py.

11052def CharSort(ctx=None):
11053 """Create a character sort
11054 >>> ch = CharSort()
11055 >>> print(ch)
11056 Char
11057 """
11058 ctx = _get_ctx(ctx)
11059 return CharSortRef(Z3_mk_char_sort(ctx.ref()), ctx)
11060
11061
Z3_sort Z3_API Z3_mk_char_sort(Z3_context c)
Create a sort for unicode characters.

◆ CharToBv()

CharToBv (   ch,
  ctx = None 
)

Definition at line 11161 of file z3py.py.

11161def CharToBv(ch, ctx=None):
11162 ch = _coerce_char(ch, ctx)
11163 return ch.to_bv()
11164

◆ CharToInt()

CharToInt (   ch,
  ctx = None 
)

Definition at line 11165 of file z3py.py.

11165def CharToInt(ch, ctx=None):
11166 ch = _coerce_char(ch, ctx)
11167 return ch.to_int()
11168

◆ CharVal()

CharVal (   ch,
  ctx = None 
)

Definition at line 11148 of file z3py.py.

11148def CharVal(ch, ctx=None):
11149 ctx = _get_ctx(ctx)
11150 if isinstance(ch, str):
11151 ch = ord(ch)
11152 if not isinstance(ch, int):
11153 raise Z3Exception("character value should be an ordinal")
11154 return _to_expr_ref(Z3_mk_char(ctx.ref(), ch), ctx)
11155
Z3_ast Z3_API Z3_mk_char(Z3_context c, unsigned ch)
Create a character literal.

◆ Complement()

Complement (   re)
Create the complement regular expression.

Definition at line 11598 of file z3py.py.

11598def Complement(re):
11599 """Create the complement regular expression."""
11600 return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
11601
11602
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.

◆ Concat()

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

4193def Concat(*args):
4194 """Create a Z3 bit-vector concatenation expression.
4195
4196 >>> v = BitVecVal(1, 4)
4197 >>> Concat(v, v+1, v)
4198 Concat(Concat(1, 1 + 1), 1)
4199 >>> simplify(Concat(v, v+1, v))
4200 289
4201 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
4202 121
4203 """
4204 args = _get_args(args)
4205 sz = len(args)
4206 if z3_debug():
4207 _z3_assert(sz >= 2, "At least two arguments expected.")
4208
4209 ctx = None
4210 for a in args:
4211 if is_expr(a):
4212 ctx = a.ctx
4213 break
4214 if is_seq(args[0]) or isinstance(args[0], str):
4215 args = [_coerce_seq(s, ctx) for s in args]
4216 if z3_debug():
4217 _z3_assert(all([is_seq(a) for a in args]), "All arguments must be sequence expressions.")
4218 v = (Ast * sz)()
4219 for i in range(sz):
4220 v[i] = args[i].as_ast()
4221 return SeqRef(Z3_mk_seq_concat(ctx.ref(), sz, v), ctx)
4222
4223 if is_re(args[0]):
4224 if z3_debug():
4225 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
4226 v = (Ast * sz)()
4227 for i in range(sz):
4228 v[i] = args[i].as_ast()
4229 return ReRef(Z3_mk_re_concat(ctx.ref(), sz, v), ctx)
4230
4231 if z3_debug():
4232 _z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.")
4233 r = args[0]
4234 for i in range(sz - 1):
4235 r = BitVecRef(Z3_mk_concat(ctx.ref(), r.as_ast(), args[i + 1].as_ast()), ctx)
4236 return r
4237
4238
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
Z3_ast Z3_API Z3_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.

◆ Cond()

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

9041def Cond(p, t1, t2, ctx=None):
9042 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
9043
9044 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
9045 """
9046 p = _to_probe(p, ctx)
9047 t1 = _to_tactic(t1, ctx)
9048 t2 = _to_tactic(t2, ctx)
9049 return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
9050
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluat...

Referenced by If().

◆ Const()

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

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

Definition at line 1499 of file z3py.py.

1499def Const(name, sort):
1500 """Create a constant of the given sort.
1501
1502 >>> Const('x', IntSort())
1503 x
1504 """
1505 if z3_debug():
1506 _z3_assert(isinstance(sort, SortRef), "Z3 sort expected")
1507 ctx = sort.ctx
1508 return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
1509
1510

Referenced by Consts().

◆ Consts()

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

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

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

Definition at line 1511 of file z3py.py.

1511def Consts(names, sort):
1512 """Create several constants of the given sort.
1513
1514 `names` is a string containing the names of all constants to be created.
1515 Blank spaces separate the names of different constants.
1516
1517 >>> x, y, z = Consts('x y z', IntSort())
1518 >>> x + y + z
1519 x + y + z
1520 """
1521 if isinstance(names, str):
1522 names = names.split(" ")
1523 return [Const(name, sort) for name in names]
1524
1525

◆ Contains()

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

11343def Contains(a, b):
11344 """Check if 'a' contains 'b'
11345 >>> s1 = Contains("abc", "ab")
11346 >>> simplify(s1)
11347 True
11348 >>> s2 = Contains("abc", "bc")
11349 >>> simplify(s2)
11350 True
11351 >>> x, y, z = Strings('x y z')
11352 >>> s3 = Contains(Concat(x,y,z), y)
11353 >>> simplify(s3)
11354 True
11355 """
11356 ctx = _get_ctx2(a, b)
11357 a = _coerce_seq(a, ctx)
11358 b = _coerce_seq(b, ctx)
11359 return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11360
11361
Z3_ast Z3_API Z3_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.

◆ CreateDatatypes()

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

5285def CreateDatatypes(*ds):
5286 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5287
5288 In the following example we define a Tree-List using two mutually recursive datatypes.
5289
5290 >>> TreeList = Datatype('TreeList')
5291 >>> Tree = Datatype('Tree')
5292 >>> # Tree has two constructors: leaf and node
5293 >>> Tree.declare('leaf', ('val', IntSort()))
5294 >>> # a node contains a list of trees
5295 >>> Tree.declare('node', ('children', TreeList))
5296 >>> TreeList.declare('nil')
5297 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
5298 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
5299 >>> Tree.val(Tree.leaf(10))
5300 val(leaf(10))
5301 >>> simplify(Tree.val(Tree.leaf(10)))
5302 10
5303 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5304 >>> n1
5305 node(cons(leaf(10), cons(leaf(20), nil)))
5306 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5307 >>> simplify(n2 == n1)
5308 False
5309 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
5310 True
5311 """
5312 ds = _get_args(ds)
5313 if z3_debug():
5314 _z3_assert(len(ds) > 0, "At least one Datatype must be specified")
5315 _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
5316 _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
5317 _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
5318 ctx = ds[0].ctx
5319 num = len(ds)
5320 names = (Symbol * num)()
5321 out = (Sort * num)()
5322 clists = (ConstructorList * num)()
5323 to_delete = []
5324 for i in range(num):
5325 d = ds[i]
5326 names[i] = to_symbol(d.name, ctx)
5327 num_cs = len(d.constructors)
5328 cs = (Constructor * num_cs)()
5329 for j in range(num_cs):
5330 c = d.constructors[j]
5331 cname = to_symbol(c[0], ctx)
5332 rname = to_symbol(c[1], ctx)
5333 fs = c[2]
5334 num_fs = len(fs)
5335 fnames = (Symbol * num_fs)()
5336 sorts = (Sort * num_fs)()
5337 refs = (ctypes.c_uint * num_fs)()
5338 for k in range(num_fs):
5339 fname = fs[k][0]
5340 ftype = fs[k][1]
5341 fnames[k] = to_symbol(fname, ctx)
5342 if isinstance(ftype, Datatype):
5343 if z3_debug():
5344 _z3_assert(
5345 ds.count(ftype) == 1,
5346 "One and only one occurrence of each datatype is expected",
5347 )
5348 sorts[k] = None
5349 refs[k] = ds.index(ftype)
5350 else:
5351 if z3_debug():
5352 _z3_assert(is_sort(ftype), "Z3 sort expected")
5353 sorts[k] = ftype.ast
5354 refs[k] = 0
5355 cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
5356 to_delete.append(ScopedConstructor(cs[j], ctx))
5357 clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs)
5358 to_delete.append(ScopedConstructorList(clists[i], ctx))
5359 Z3_mk_datatypes(ctx.ref(), num, names, out, clists)
5360 result = []
5361 # Create a field for every constructor, recognizer and accessor
5362 for i in range(num):
5363 dref = DatatypeSortRef(out[i], ctx)
5364 num_cs = dref.num_constructors()
5365 for j in range(num_cs):
5366 cref = dref.constructor(j)
5367 cref_name = cref.name()
5368 cref_arity = cref.arity()
5369 if cref.arity() == 0:
5370 cref = cref()
5371 setattr(dref, cref_name, cref)
5372 rref = dref.recognizer(j)
5373 setattr(dref, "is_" + cref_name, rref)
5374 for k in range(cref_arity):
5375 aref = dref.accessor(j, k)
5376 setattr(dref, aref.name(), aref)
5377 result.append(dref)
5378 return tuple(result)
5379
5380
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.
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 const sorts[], unsigned sort_refs[])
Create a constructor.

Referenced by Datatype.create().

◆ DatatypeSort()

DatatypeSort (   name,
  params = None,
  ctx = None 
)
Create a reference to a sort that was declared, or will be declared, as a recursive datatype.

Args:
    name: name of the datatype sort
    params: optional list/tuple of sort parameters for parametric datatypes
    ctx: Z3 context (optional)

Example:
    >>> # Non-parametric datatype
    >>> TreeRef = DatatypeSort('Tree')
    >>> # Parametric datatype with one parameter
    >>> ListIntRef = DatatypeSort('List', [IntSort()])
    >>> # Parametric datatype with multiple parameters
    >>> PairRef = DatatypeSort('Pair', [IntSort(), BoolSort()])

Definition at line 5485 of file z3py.py.

5485def DatatypeSort(name, params=None, ctx=None):
5486 """Create a reference to a sort that was declared, or will be declared, as a recursive datatype.
5487
5488 Args:
5489 name: name of the datatype sort
5490 params: optional list/tuple of sort parameters for parametric datatypes
5491 ctx: Z3 context (optional)
5492
5493 Example:
5494 >>> # Non-parametric datatype
5495 >>> TreeRef = DatatypeSort('Tree')
5496 >>> # Parametric datatype with one parameter
5497 >>> ListIntRef = DatatypeSort('List', [IntSort()])
5498 >>> # Parametric datatype with multiple parameters
5499 >>> PairRef = DatatypeSort('Pair', [IntSort(), BoolSort()])
5500 """
5501 ctx = _get_ctx(ctx)
5502 if params is None or len(params) == 0:
5503 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), 0, (Sort * 0)()), ctx)
5504 else:
5505 _params = (Sort * len(params))()
5506 for i in range(len(params)):
5507 _params[i] = params[i].ast
5508 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), len(params), _params), ctx)
5509
Z3_sort Z3_API Z3_mk_datatype_sort(Z3_context c, Z3_symbol name, unsigned num_params, Z3_sort const params[])
create a forward reference to a recursive datatype being declared. The forward reference can be used ...

◆ DeclareSort()

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

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

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

Definition at line 713 of file z3py.py.

713def DeclareSort(name, ctx= None) -> SortRef:
714 """Create a new uninterpreted sort named `name`.
715
716 If `ctx=None`, then the new sort is declared in the global Z3Py context.
717
718 >>> A = DeclareSort('A')
719 >>> a = Const('a', A)
720 >>> b = Const('b', A)
721 >>> a.sort() == A
722 True
723 >>> b.sort() == A
724 True
725 >>> a == b
726 a == b
727 """
728 ctx = _get_ctx(ctx)
729 return SortRef(Z3_mk_uninterpreted_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
730
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).

◆ DeclareTypeVar()

DeclareTypeVar (   name,
  ctx = None 
)
Create a new type variable named `name`.

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

Definition at line 741 of file z3py.py.

741def DeclareTypeVar(name, ctx=None):
742 """Create a new type variable named `name`.
743
744 If `ctx=None`, then the new sort is declared in the global Z3Py context.
745
746 """
747 ctx = _get_ctx(ctx)
748 return TypeVarRef(Z3_mk_type_variable(ctx.ref(), to_symbol(name, ctx)), ctx)
749
750
Z3_sort Z3_API Z3_mk_type_variable(Z3_context c, Z3_symbol s)
Create a type variable.

◆ Default()

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

Definition at line 4913 of file z3py.py.

4913def Default(a):
4914 """ Return a default value for array expression.
4915 >>> b = K(IntSort(), 1)
4916 >>> prove(Default(b) == 1)
4917 proved
4918 """
4919 if z3_debug():
4920 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4921 return a.default()
4922
4923

◆ describe_probes()

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

Definition at line 8962 of file z3py.py.

8962def describe_probes():
8963 """Display a (tabular) description of all available probes in Z3."""
8964 if in_html_mode():
8965 even = True
8966 print('<table border="1" cellpadding="2" cellspacing="0">')
8967 for p in probes():
8968 if even:
8969 print('<tr style="background-color:#CFCFCF">')
8970 even = False
8971 else:
8972 print("<tr>")
8973 even = True
8974 print("<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(probe_description(p), 40)))
8975 print("</table>")
8976 else:
8977 for p in probes():
8978 print("%s : %s" % (p, probe_description(p)))
8979
8980

◆ describe_tactics()

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

Definition at line 8756 of file z3py.py.

8756def describe_tactics():
8757 """Display a (tabular) description of all available tactics in Z3."""
8758 if in_html_mode():
8759 even = True
8760 print('<table border="1" cellpadding="2" cellspacing="0">')
8761 for t in tactics():
8762 if even:
8763 print('<tr style="background-color:#CFCFCF">')
8764 even = False
8765 else:
8766 print("<tr>")
8767 even = True
8768 print("<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(tactic_description(t), 40)))
8769 print("</table>")
8770 else:
8771 for t in tactics():
8772 print("%s : %s" % (t, tactic_description(t)))
8773
8774

◆ deserialize()

deserialize (   st)
inverse function to the serialize method on ExprRef.
It is made available to make it easier for users to serialize expressions back and forth between
strings. Solvers can be serialized using the 'sexpr()' method.

Definition at line 1166 of file z3py.py.

1166def deserialize(st):
1167 """inverse function to the serialize method on ExprRef.
1168 It is made available to make it easier for users to serialize expressions back and forth between
1169 strings. Solvers can be serialized using the 'sexpr()' method.
1170 """
1171 s = Solver()
1172 s.from_string(st)
1173 if len(s.assertions()) != 1:
1174 raise Z3Exception("single assertion expected")
1175 fml = s.assertions()[0]
1176 if fml.num_args() != 1:
1177 raise Z3Exception("dummy function 'F' expected")
1178 return fml.arg(0)
1179

◆ Diff()

Diff (   a,
  b,
  ctx = None 
)
Create the difference regular expression

Definition at line 11648 of file z3py.py.

11648def Diff(a, b, ctx=None):
11649 """Create the difference regular expression
11650 """
11651 if z3_debug():
11652 _z3_assert(is_expr(a), "expression expected")
11653 _z3_assert(is_expr(b), "expression expected")
11654 return ReRef(Z3_mk_re_diff(a.ctx_ref(), a.ast, b.ast), a.ctx)
11655
Z3_ast Z3_API Z3_mk_re_diff(Z3_context c, Z3_ast re1, Z3_ast re2)
Create the difference of regular expressions.

◆ disable_trace()

disable_trace (   msg)

Definition at line 87 of file z3py.py.

87def disable_trace(msg):
89
90
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.

◆ DisjointSum()

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

Definition at line 5522 of file z3py.py.

5522def DisjointSum(name, sorts, ctx=None):
5523 """Create a named tagged union sort base on a set of underlying sorts
5524 Example:
5525 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5526 """
5527 sum = Datatype(name, ctx)
5528 for i in range(len(sorts)):
5529 sum.declare("inject%d" % i, ("project%d" % i, sorts[i]))
5530 sum = sum.create()
5531 return sum, [(sum.constructor(i), sum.accessor(i, 0)) for i in range(len(sorts))]
5532
5533

◆ Distinct()

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

1466def Distinct(*args):
1467 """Create a Z3 distinct expression.
1468
1469 >>> x = Int('x')
1470 >>> y = Int('y')
1471 >>> Distinct(x, y)
1472 x != y
1473 >>> z = Int('z')
1474 >>> Distinct(x, y, z)
1475 Distinct(x, y, z)
1476 >>> simplify(Distinct(x, y, z))
1477 Distinct(x, y, z)
1478 >>> simplify(Distinct(x, y, z), blast_distinct=True)
1479 And(Not(x == y), Not(x == z), Not(y == z))
1480 """
1481 args = _get_args(args)
1482 ctx = _ctx_from_ast_arg_list(args)
1483 if z3_debug():
1484 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
1485 args = _coerce_expr_list(args, ctx)
1486 _args, sz = _to_ast_array(args)
1487 return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
1488
1489
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]).

◆ Empty()

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

Definition at line 11273 of file z3py.py.

11273def Empty(s):
11274 """Create the empty sequence of the given sort
11275 >>> e = Empty(StringSort())
11276 >>> e2 = StringVal("")
11277 >>> print(e.eq(e2))
11278 True
11279 >>> e3 = Empty(SeqSort(IntSort()))
11280 >>> print(e3)
11281 Empty(Seq(Int))
11282 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
11283 >>> print(e4)
11284 Empty(ReSort(Seq(Int)))
11285 """
11286 if isinstance(s, SeqSortRef):
11287 return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
11288 if isinstance(s, ReSortRef):
11289 return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
11290 raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
11291
11292
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.

◆ EmptySet()

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

Definition at line 5049 of file z3py.py.

5049def EmptySet(s):
5050 """Create the empty set
5051 >>> EmptySet(IntSort())
5052 K(Int, False)
5053 """
5054 ctx = s.ctx
5055 return ArrayRef(Z3_mk_empty_set(ctx.ref(), s.ast), ctx)
5056
5057
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.

◆ enable_trace()

enable_trace (   msg)

Definition at line 83 of file z3py.py.

83def enable_trace(msg):
85
86
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.

◆ ensure_prop_closures()

ensure_prop_closures ( )

Definition at line 11767 of file z3py.py.

11767def ensure_prop_closures():
11768 global _prop_closures
11769 if _prop_closures is None:
11770 _prop_closures = PropClosures()
11771
11772

◆ EnumSort()

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

5534def EnumSort(name, values, ctx=None):
5535 """Return a new enumeration sort named `name` containing the given values.
5536
5537 The result is a pair (sort, list of constants).
5538 Example:
5539 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5540 """
5541 if z3_debug():
5542 _z3_assert(isinstance(name, str), "Name must be a string")
5543 _z3_assert(all([isinstance(v, str) for v in values]), "Enumeration sort values must be strings")
5544 _z3_assert(len(values) > 0, "At least one value expected")
5545 ctx = _get_ctx(ctx)
5546 num = len(values)
5547 _val_names = (Symbol * num)()
5548 for i in range(num):
5549 _val_names[i] = to_symbol(values[i], ctx)
5550 _values = (FuncDecl * num)()
5551 _testers = (FuncDecl * num)()
5552 name = to_symbol(name, ctx)
5553 S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
5554 V = []
5555 for i in range(num):
5556 V.append(FuncDeclRef(_values[i], ctx))
5557 V = [a() for a in V]
5558 return S, V
5559
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()

bool eq ( AstRef  a,
AstRef  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 486 of file z3py.py.

486def eq(a : AstRef, b : AstRef) -> bool:
487 """Return `True` if `a` and `b` are structurally identical AST nodes.
488
489 >>> x = Int('x')
490 >>> y = Int('y')
491 >>> eq(x, y)
492 False
493 >>> eq(x + 1, x + 1)
494 True
495 >>> eq(x + 1, 1 + x)
496 False
497 >>> eq(simplify(x + 1), simplify(1 + x))
498 True
499 """
500 if z3_debug():
501 _z3_assert(is_ast(a) and is_ast(b), "Z3 ASTs expected")
502 return a.eq(b)
503
504

◆ Exists()

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

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


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

Definition at line 2342 of file z3py.py.

2342def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2343 """Create a Z3 exists formula.
2344
2345 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2346
2347
2348 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2349 >>> x = Int('x')
2350 >>> y = Int('y')
2351 >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2352 >>> q
2353 Exists([x, y], f(x, y) >= x)
2354 >>> is_quantifier(q)
2355 True
2356 >>> r = Tactic('nnf')(q).as_expr()
2357 >>> is_quantifier(r)
2358 False
2359 """
2360 return _mk_quantifier(False, vs, body, weight, qid, skid, patterns, no_patterns)
2361
2362

◆ Ext()

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

Definition at line 5002 of file z3py.py.

5002def Ext(a, b):
5003 """Return extensionality index for one-dimensional arrays.
5004 >> a, b = Consts('a b', SetSort(IntSort()))
5005 >> Ext(a, b)
5006 Ext(a, b)
5007 """
5008 ctx = a.ctx
5009 if z3_debug():
5010 _z3_assert(is_array_sort(a) and (is_array(b) or b.is_lambda()), "arguments must be arrays")
5011 return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5012
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...

◆ Extract()

Extract (   high,
  low,
  a 
)
Create a Z3 bit-vector extraction expression or sequence extraction expression.

Extract is overloaded to work with both bit-vectors and sequences:

**Bit-vector extraction**: Extract(high, low, bitvector)
    Extracts bits from position `high` down to position `low` (both inclusive).
    - high: int - the highest bit position to extract (0-indexed from right)
    - low: int - the lowest bit position to extract (0-indexed from right)  
    - bitvector: BitVecRef - the bit-vector to extract from
    Returns a new bit-vector containing bits [high:low]

**Sequence extraction**: Extract(sequence, offset, length)
    Extracts a subsequence starting at the given offset with the specified length.
    The functions SubString and SubSeq are redirected to this form of Extract.
    - sequence: SeqRef or str - the sequence to extract from
    - offset: int - the starting position (0-indexed)
    - length: int - the number of elements to extract
    Returns a new sequence containing the extracted subsequence

>>> # Bit-vector extraction examples
>>> x = BitVec('x', 8)
>>> Extract(6, 2, x)  # Extract bits 6 down to 2 (5 bits total)
Extract(6, 2, x)
>>> Extract(6, 2, x).sort()  # Result is a 5-bit vector
BitVec(5)
>>> Extract(7, 0, x)  # Extract all 8 bits
Extract(7, 0, x)
>>> Extract(3, 3, x)  # Extract single bit at position 3
Extract(3, 3, x)

>>> # Sequence extraction examples  
>>> s = StringVal("hello")
>>> Extract(s, 1, 3)  # Extract 3 characters starting at position 1
str.substr("hello", 1, 3)
>>> simplify(Extract(StringVal("abcd"), 2, 1))  # Extract 1 character at position 2
"c"
>>> simplify(Extract(StringVal("abcd"), 0, 2))  # Extract first 2 characters  
"ab"

Definition at line 4239 of file z3py.py.

4239def Extract(high, low, a):
4240 """Create a Z3 bit-vector extraction expression or sequence extraction expression.
4241
4242 Extract is overloaded to work with both bit-vectors and sequences:
4243
4244 **Bit-vector extraction**: Extract(high, low, bitvector)
4245 Extracts bits from position `high` down to position `low` (both inclusive).
4246 - high: int - the highest bit position to extract (0-indexed from right)
4247 - low: int - the lowest bit position to extract (0-indexed from right)
4248 - bitvector: BitVecRef - the bit-vector to extract from
4249 Returns a new bit-vector containing bits [high:low]
4250
4251 **Sequence extraction**: Extract(sequence, offset, length)
4252 Extracts a subsequence starting at the given offset with the specified length.
4253 The functions SubString and SubSeq are redirected to this form of Extract.
4254 - sequence: SeqRef or str - the sequence to extract from
4255 - offset: int - the starting position (0-indexed)
4256 - length: int - the number of elements to extract
4257 Returns a new sequence containing the extracted subsequence
4258
4259 >>> # Bit-vector extraction examples
4260 >>> x = BitVec('x', 8)
4261 >>> Extract(6, 2, x) # Extract bits 6 down to 2 (5 bits total)
4262 Extract(6, 2, x)
4263 >>> Extract(6, 2, x).sort() # Result is a 5-bit vector
4264 BitVec(5)
4265 >>> Extract(7, 0, x) # Extract all 8 bits
4266 Extract(7, 0, x)
4267 >>> Extract(3, 3, x) # Extract single bit at position 3
4268 Extract(3, 3, x)
4269
4270 >>> # Sequence extraction examples
4271 >>> s = StringVal("hello")
4272 >>> Extract(s, 1, 3) # Extract 3 characters starting at position 1
4273 str.substr("hello", 1, 3)
4274 >>> simplify(Extract(StringVal("abcd"), 2, 1)) # Extract 1 character at position 2
4275 "c"
4276 >>> simplify(Extract(StringVal("abcd"), 0, 2)) # Extract first 2 characters
4277 "ab"
4278 """
4279 if isinstance(high, str):
4280 high = StringVal(high)
4281 if is_seq(high):
4282 s = high
4283 offset, length = _coerce_exprs(low, a, s.ctx)
4284 return SeqRef(Z3_mk_seq_extract(s.ctx_ref(), s.as_ast(), offset.as_ast(), length.as_ast()), s.ctx)
4285 if z3_debug():
4286 _z3_assert(low <= high, "First argument must be greater than or equal to second argument")
4287 _z3_assert(_is_int(high) and high >= 0 and _is_int(low) and low >= 0,
4288 "First and second arguments must be non negative integers")
4289 _z3_assert(is_bv(a), "Third argument must be a Z3 bit-vector expression")
4290 return BitVecRef(Z3_mk_extract(a.ctx_ref(), high, low, a.as_ast()), a.ctx)
4291
4292
Z3_ast Z3_API Z3_mk_extract(Z3_context c, unsigned high, unsigned low, Z3_ast t1)
Extract the bits high down to low from a bit-vector of size m to yield a new bit-vector of size n,...
Z3_ast Z3_API Z3_mk_seq_extract(Z3_context c, Z3_ast s, Z3_ast offset, Z3_ast length)
Extract subsequence starting at offset of length.

◆ FailIf()

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

8999def FailIf(p, ctx=None):
9000 """Return a tactic that fails if the probe `p` evaluates to true.
9001 Otherwise, it returns the input goal unmodified.
9002
9003 In the following example, the tactic applies 'simplify' if and only if there are
9004 more than 2 constraints in the goal.
9005
9006 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
9007 >>> x, y = Ints('x y')
9008 >>> g = Goal()
9009 >>> g.add(x > 0)
9010 >>> g.add(y > 0)
9011 >>> t(g)
9012 [[x > 0, y > 0]]
9013 >>> g.add(x == y + 1)
9014 >>> t(g)
9015 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9016 """
9017 p = _to_probe(p, ctx)
9018 return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
9019
9020
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.

◆ FiniteDomainSort()

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

Definition at line 7930 of file z3py.py.

7930def FiniteDomainSort(name, sz, ctx=None):
7931 """Create a named finite domain sort of a given size sz"""
7932 if not isinstance(name, Symbol):
7933 name = to_symbol(name)
7934 ctx = _get_ctx(ctx)
7935 return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
7936
7937
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, uint64_t size)
Create a named finite domain sort.

◆ FiniteDomainVal()

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

8000def FiniteDomainVal(val, sort, ctx=None):
8001 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
8002
8003 >>> s = FiniteDomainSort('S', 256)
8004 >>> FiniteDomainVal(255, s)
8005 255
8006 >>> FiniteDomainVal('100', s)
8007 100
8008 """
8009 if z3_debug():
8010 _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort")
8011 ctx = sort.ctx
8012 return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
8013
8014

◆ Float128()

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

Definition at line 9727 of file z3py.py.

9727def Float128(ctx=None):
9728 """Floating-point 128-bit (quadruple) sort."""
9729 ctx = _get_ctx(ctx)
9730 return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
9731
9732
Z3_sort Z3_API Z3_mk_fpa_sort_128(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.

◆ Float16()

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

Definition at line 9691 of file z3py.py.

9691def Float16(ctx=None):
9692 """Floating-point 16-bit (half) sort."""
9693 ctx = _get_ctx(ctx)
9694 return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
9695
9696
Z3_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.

◆ Float32()

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

Definition at line 9703 of file z3py.py.

9703def Float32(ctx=None):
9704 """Floating-point 32-bit (single) sort."""
9705 ctx = _get_ctx(ctx)
9706 return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
9707
9708
Z3_sort Z3_API Z3_mk_fpa_sort_32(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.

◆ Float64()

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

Definition at line 9715 of file z3py.py.

9715def Float64(ctx=None):
9716 """Floating-point 64-bit (double) sort."""
9717 ctx = _get_ctx(ctx)
9718 return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
9719
9720
Z3_sort Z3_API Z3_mk_fpa_sort_64(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.

◆ FloatDouble()

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

Definition at line 9721 of file z3py.py.

9721def FloatDouble(ctx=None):
9722 """Floating-point 64-bit (double) sort."""
9723 ctx = _get_ctx(ctx)
9724 return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
9725
9726
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.

◆ FloatHalf()

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

Definition at line 9697 of file z3py.py.

9697def FloatHalf(ctx=None):
9698 """Floating-point 16-bit (half) sort."""
9699 ctx = _get_ctx(ctx)
9700 return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
9701
9702
Z3_sort Z3_API Z3_mk_fpa_sort_half(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.

◆ FloatQuadruple()

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

Definition at line 9733 of file z3py.py.

9733def FloatQuadruple(ctx=None):
9734 """Floating-point 128-bit (quadruple) sort."""
9735 ctx = _get_ctx(ctx)
9736 return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
9737
9738
Z3_sort Z3_API Z3_mk_fpa_sort_quadruple(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.

◆ FloatSingle()

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

Definition at line 9709 of file z3py.py.

9709def FloatSingle(ctx=None):
9710 """Floating-point 32-bit (single) sort."""
9711 ctx = _get_ctx(ctx)
9712 return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
9713
9714
Z3_sort Z3_API Z3_mk_fpa_sort_single(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.

◆ ForAll()

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

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

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

Definition at line 2324 of file z3py.py.

2324def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2325 """Create a Z3 forall formula.
2326
2327 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2328
2329 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2330 >>> x = Int('x')
2331 >>> y = Int('y')
2332 >>> ForAll([x, y], f(x, y) >= x)
2333 ForAll([x, y], f(x, y) >= x)
2334 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2335 ForAll([x, y], f(x, y) >= x)
2336 >>> ForAll([x, y], f(x, y) >= x, weight=10)
2337 ForAll([x, y], f(x, y) >= x)
2338 """
2339 return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
2340
2341

◆ FP()

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

10369def FP(name, fpsort, ctx=None):
10370 """Return a floating-point constant named `name`.
10371 `fpsort` is the floating-point sort.
10372 If `ctx=None`, then the global context is used.
10373
10374 >>> x = FP('x', FPSort(8, 24))
10375 >>> is_fp(x)
10376 True
10377 >>> x.ebits()
10378 8
10379 >>> x.sort()
10380 FPSort(8, 24)
10381 >>> word = FPSort(8, 24)
10382 >>> x2 = FP('x', word)
10383 >>> eq(x, x2)
10384 True
10385 """
10386 if isinstance(fpsort, FPSortRef) and ctx is None:
10387 ctx = fpsort.ctx
10388 else:
10389 ctx = _get_ctx(ctx)
10390 return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
10391
10392

◆ fpAbs()

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

10412def fpAbs(a, ctx=None):
10413 """Create a Z3 floating-point absolute value expression.
10414
10415 >>> s = FPSort(8, 24)
10416 >>> rm = RNE()
10417 >>> x = FPVal(1.0, s)
10418 >>> fpAbs(x)
10419 fpAbs(1)
10420 >>> y = FPVal(-20.0, s)
10421 >>> y
10422 -1.25*(2**4)
10423 >>> fpAbs(y)
10424 fpAbs(-1.25*(2**4))
10425 >>> fpAbs(-1.25*(2**4))
10426 fpAbs(-1.25*(2**4))
10427 >>> fpAbs(x).sort()
10428 FPSort(8, 24)
10429 """
10430 ctx = _get_ctx(ctx)
10431 [a] = _coerce_fp_expr_list([a], ctx)
10432 return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
10433
10434
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.

◆ fpAdd()

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)
x + y
>>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
fpAdd(RTZ(), x, y)
>>> fpAdd(rm, x, y).sort()
FPSort(8, 24)

Definition at line 10503 of file z3py.py.

10503def fpAdd(rm, a, b, ctx=None):
10504 """Create a Z3 floating-point addition expression.
10505
10506 >>> s = FPSort(8, 24)
10507 >>> rm = RNE()
10508 >>> x = FP('x', s)
10509 >>> y = FP('y', s)
10510 >>> fpAdd(rm, x, y)
10511 x + y
10512 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
10513 fpAdd(RTZ(), x, y)
10514 >>> fpAdd(rm, x, y).sort()
10515 FPSort(8, 24)
10516 """
10517 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10518
10519

◆ fpBVToFP()

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

10825def fpBVToFP(v, sort, ctx=None):
10826 """Create a Z3 floating-point conversion expression that represents the
10827 conversion from a bit-vector term to a floating-point term.
10828
10829 >>> x_bv = BitVecVal(0x3F800000, 32)
10830 >>> x_fp = fpBVToFP(x_bv, Float32())
10831 >>> x_fp
10832 fpToFP(1065353216)
10833 >>> simplify(x_fp)
10834 1
10835 """
10836 _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
10837 _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
10838 ctx = _get_ctx(ctx)
10839 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
10840
10841
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.

◆ fpDiv()

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

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

Definition at line 10550 of file z3py.py.

10550def fpDiv(rm, a, b, ctx=None):
10551 """Create a Z3 floating-point division expression.
10552
10553 >>> s = FPSort(8, 24)
10554 >>> rm = RNE()
10555 >>> x = FP('x', s)
10556 >>> y = FP('y', s)
10557 >>> fpDiv(rm, x, y)
10558 x / y
10559 >>> fpDiv(rm, x, y).sort()
10560 FPSort(8, 24)
10561 """
10562 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10563
10564

◆ fpEQ()

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

10733def fpEQ(a, b, ctx=None):
10734 """Create the Z3 floating-point expression `fpEQ(other, self)`.
10735
10736 >>> x, y = FPs('x y', FPSort(8, 24))
10737 >>> fpEQ(x, y)
10738 fpEQ(x, y)
10739 >>> fpEQ(x, y).sexpr()
10740 '(fp.eq x y)'
10741 """
10742 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10743
10744

◆ fpFMA()

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

Definition at line 10609 of file z3py.py.

10609def fpFMA(rm, a, b, c, ctx=None):
10610 """Create a Z3 floating-point fused multiply-add expression.
10611 """
10612 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10613
10614

◆ fpFP()

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

10757def fpFP(sgn, exp, sig, ctx=None):
10758 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10759
10760 >>> s = FPSort(8, 24)
10761 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
10762 >>> print(x)
10763 fpFP(1, 127, 4194304)
10764 >>> xv = FPVal(-1.5, s)
10765 >>> print(xv)
10766 -1.5
10767 >>> slvr = Solver()
10768 >>> slvr.add(fpEQ(x, xv))
10769 >>> slvr.check()
10770 sat
10771 >>> xv = FPVal(+1.5, s)
10772 >>> print(xv)
10773 1.5
10774 >>> slvr = Solver()
10775 >>> slvr.add(fpEQ(x, xv))
10776 >>> slvr.check()
10777 unsat
10778 """
10779 _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
10780 _z3_assert(sgn.sort().size() == 1, "sort mismatch")
10781 ctx = _get_ctx(ctx)
10782 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
10783 return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
10784
10785
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.

◆ fpFPToFP()

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

10842def fpFPToFP(rm, v, sort, ctx=None):
10843 """Create a Z3 floating-point conversion expression that represents the
10844 conversion from a floating-point term to a floating-point term of different precision.
10845
10846 >>> x_sgl = FPVal(1.0, Float32())
10847 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
10848 >>> x_dbl
10849 fpToFP(RNE(), 1)
10850 >>> simplify(x_dbl)
10851 1
10852 >>> x_dbl.sort()
10853 FPSort(11, 53)
10854 """
10855 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10856 _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
10857 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10858 ctx = _get_ctx(ctx)
10859 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10860
10861
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.

◆ fpGEQ()

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

10721def fpGEQ(a, b, ctx=None):
10722 """Create the Z3 floating-point expression `other >= self`.
10723
10724 >>> x, y = FPs('x y', FPSort(8, 24))
10725 >>> fpGEQ(x, y)
10726 x >= y
10727 >>> (x >= y).sexpr()
10728 '(fp.geq x y)'
10729 """
10730 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10731
10732

◆ fpGT()

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

10709def fpGT(a, b, ctx=None):
10710 """Create the Z3 floating-point expression `other > self`.
10711
10712 >>> x, y = FPs('x y', FPSort(8, 24))
10713 >>> fpGT(x, y)
10714 x > y
10715 >>> (x > y).sexpr()
10716 '(fp.gt x y)'
10717 """
10718 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10719
10720

◆ fpInfinity()

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

Definition at line 10297 of file z3py.py.

10297def fpInfinity(s, negative):
10298 """Create a Z3 floating-point +oo or -oo term."""
10299 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10300 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10301 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
10302
10303
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.

◆ fpIsInf()

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

10639def fpIsInf(a, ctx=None):
10640 """Create a Z3 floating-point isInfinite expression.
10641
10642 >>> s = FPSort(8, 24)
10643 >>> x = FP('x', s)
10644 >>> fpIsInf(x)
10645 fpIsInf(x)
10646 """
10647 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10648
10649

◆ fpIsNaN()

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

10627def fpIsNaN(a, ctx=None):
10628 """Create a Z3 floating-point isNaN expression.
10629
10630 >>> s = FPSort(8, 24)
10631 >>> x = FP('x', s)
10632 >>> y = FP('y', s)
10633 >>> fpIsNaN(x)
10634 fpIsNaN(x)
10635 """
10636 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10637
10638

◆ fpIsNegative()

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

Definition at line 10668 of file z3py.py.

10668def fpIsNegative(a, ctx=None):
10669 """Create a Z3 floating-point isNegative expression.
10670 """
10671 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10672
10673

◆ fpIsNormal()

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

Definition at line 10656 of file z3py.py.

10656def fpIsNormal(a, ctx=None):
10657 """Create a Z3 floating-point isNormal expression.
10658 """
10659 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10660
10661

◆ fpIsPositive()

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

Definition at line 10674 of file z3py.py.

10674def fpIsPositive(a, ctx=None):
10675 """Create a Z3 floating-point isPositive expression.
10676 """
10677 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10678
10679

◆ fpIsSubnormal()

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

Definition at line 10662 of file z3py.py.

10662def fpIsSubnormal(a, ctx=None):
10663 """Create a Z3 floating-point isSubnormal expression.
10664 """
10665 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10666
10667

◆ fpIsZero()

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

Definition at line 10650 of file z3py.py.

10650def fpIsZero(a, ctx=None):
10651 """Create a Z3 floating-point isZero expression.
10652 """
10653 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10654
10655

◆ fpLEQ()

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

10697def fpLEQ(a, b, ctx=None):
10698 """Create the Z3 floating-point expression `other <= self`.
10699
10700 >>> x, y = FPs('x y', FPSort(8, 24))
10701 >>> fpLEQ(x, y)
10702 x <= y
10703 >>> (x <= y).sexpr()
10704 '(fp.leq x y)'
10705 """
10706 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10707
10708

◆ fpLT()

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

10685def fpLT(a, b, ctx=None):
10686 """Create the Z3 floating-point expression `other < self`.
10687
10688 >>> x, y = FPs('x y', FPSort(8, 24))
10689 >>> fpLT(x, y)
10690 x < y
10691 >>> (x < y).sexpr()
10692 '(fp.lt x y)'
10693 """
10694 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10695
10696

◆ fpMax()

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

10594def fpMax(a, b, ctx=None):
10595 """Create a Z3 floating-point maximum expression.
10596
10597 >>> s = FPSort(8, 24)
10598 >>> rm = RNE()
10599 >>> x = FP('x', s)
10600 >>> y = FP('y', s)
10601 >>> fpMax(x, y)
10602 fpMax(x, y)
10603 >>> fpMax(x, y).sort()
10604 FPSort(8, 24)
10605 """
10606 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10607
10608

◆ fpMin()

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

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

Definition at line 10579 of file z3py.py.

10579def fpMin(a, b, ctx=None):
10580 """Create a Z3 floating-point minimum expression.
10581
10582 >>> s = FPSort(8, 24)
10583 >>> rm = RNE()
10584 >>> x = FP('x', s)
10585 >>> y = FP('y', s)
10586 >>> fpMin(x, y)
10587 fpMin(x, y)
10588 >>> fpMin(x, y).sort()
10589 FPSort(8, 24)
10590 """
10591 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10592
10593

◆ fpMinusInfinity()

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

Definition at line 10291 of file z3py.py.

10291def fpMinusInfinity(s):
10292 """Create a Z3 floating-point -oo term."""
10293 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10294 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
10295
10296

◆ fpMinusZero()

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

Definition at line 10310 of file z3py.py.

10310def fpMinusZero(s):
10311 """Create a Z3 floating-point -0.0 term."""
10312 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10313 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
10314
10315
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.

◆ fpMul()

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)
x * y
>>> fpMul(rm, x, y).sort()
FPSort(8, 24)

Definition at line 10535 of file z3py.py.

10535def fpMul(rm, a, b, ctx=None):
10536 """Create a Z3 floating-point multiplication expression.
10537
10538 >>> s = FPSort(8, 24)
10539 >>> rm = RNE()
10540 >>> x = FP('x', s)
10541 >>> y = FP('y', s)
10542 >>> fpMul(rm, x, y)
10543 x * y
10544 >>> fpMul(rm, x, y).sort()
10545 FPSort(8, 24)
10546 """
10547 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10548
10549

◆ fpNaN()

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

10257def fpNaN(s):
10258 """Create a Z3 floating-point NaN term.
10259
10260 >>> s = FPSort(8, 24)
10261 >>> set_fpa_pretty(True)
10262 >>> fpNaN(s)
10263 NaN
10264 >>> pb = get_fpa_pretty()
10265 >>> set_fpa_pretty(False)
10266 >>> fpNaN(s)
10267 fpNaN(FPSort(8, 24))
10268 >>> set_fpa_pretty(pb)
10269 """
10270 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10271 return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
10272
10273
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.

◆ fpNeg()

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

10435def fpNeg(a, ctx=None):
10436 """Create a Z3 floating-point addition expression.
10437
10438 >>> s = FPSort(8, 24)
10439 >>> rm = RNE()
10440 >>> x = FP('x', s)
10441 >>> fpNeg(x)
10442 -x
10443 >>> fpNeg(x).sort()
10444 FPSort(8, 24)
10445 """
10446 ctx = _get_ctx(ctx)
10447 [a] = _coerce_fp_expr_list([a], ctx)
10448 return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
10449
10450
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.

◆ fpNEQ()

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

10745def fpNEQ(a, b, ctx=None):
10746 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10747
10748 >>> x, y = FPs('x y', FPSort(8, 24))
10749 >>> fpNEQ(x, y)
10750 Not(fpEQ(x, y))
10751 >>> (x != y).sexpr()
10752 '(distinct x y)'
10753 """
10754 return Not(fpEQ(a, b, ctx))
10755
10756

◆ fpPlusInfinity()

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

10274def fpPlusInfinity(s):
10275 """Create a Z3 floating-point +oo term.
10276
10277 >>> s = FPSort(8, 24)
10278 >>> pb = get_fpa_pretty()
10279 >>> set_fpa_pretty(True)
10280 >>> fpPlusInfinity(s)
10281 +oo
10282 >>> set_fpa_pretty(False)
10283 >>> fpPlusInfinity(s)
10284 fpPlusInfinity(FPSort(8, 24))
10285 >>> set_fpa_pretty(pb)
10286 """
10287 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10288 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
10289
10290

◆ fpPlusZero()

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

Definition at line 10304 of file z3py.py.

10304def fpPlusZero(s):
10305 """Create a Z3 floating-point +0.0 term."""
10306 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10307 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
10308
10309

◆ fpRealToFP()

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

10862def fpRealToFP(rm, v, sort, ctx=None):
10863 """Create a Z3 floating-point conversion expression that represents the
10864 conversion from a real term to a floating-point term.
10865
10866 >>> x_r = RealVal(1.5)
10867 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
10868 >>> x_fp
10869 fpToFP(RNE(), 3/2)
10870 >>> simplify(x_fp)
10871 1.5
10872 """
10873 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10874 _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
10875 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10876 ctx = _get_ctx(ctx)
10877 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10878
10879
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.

◆ fpRem()

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

10565def fpRem(a, b, ctx=None):
10566 """Create a Z3 floating-point remainder expression.
10567
10568 >>> s = FPSort(8, 24)
10569 >>> x = FP('x', s)
10570 >>> y = FP('y', s)
10571 >>> fpRem(x, y)
10572 fpRem(x, y)
10573 >>> fpRem(x, y).sort()
10574 FPSort(8, 24)
10575 """
10576 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10577
10578

◆ fpRoundToIntegral()

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

Definition at line 10621 of file z3py.py.

10621def fpRoundToIntegral(rm, a, ctx=None):
10622 """Create a Z3 floating-point roundToIntegral expression.
10623 """
10624 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10625
10626

◆ FPs()

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)
(x + y) * z

Definition at line 10393 of file z3py.py.

10393def FPs(names, fpsort, ctx=None):
10394 """Return an array of floating-point constants.
10395
10396 >>> x, y, z = FPs('x y z', FPSort(8, 24))
10397 >>> x.sort()
10398 FPSort(8, 24)
10399 >>> x.sbits()
10400 24
10401 >>> x.ebits()
10402 8
10403 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
10404 (x + y) * z
10405 """
10406 ctx = _get_ctx(ctx)
10407 if isinstance(names, str):
10408 names = names.split(" ")
10409 return [FP(name, fpsort, ctx) for name in names]
10410
10411

◆ fpSignedToFP()

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

10880def fpSignedToFP(rm, v, sort, ctx=None):
10881 """Create a Z3 floating-point conversion expression that represents the
10882 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10883
10884 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10885 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
10886 >>> x_fp
10887 fpToFP(RNE(), 4294967291)
10888 >>> simplify(x_fp)
10889 -1.25*(2**2)
10890 """
10891 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10892 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10893 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10894 ctx = _get_ctx(ctx)
10895 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10896
10897
Z3_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort.

◆ FPSort()

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

10198def FPSort(ebits, sbits, ctx=None):
10199 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
10200
10201 >>> Single = FPSort(8, 24)
10202 >>> Double = FPSort(11, 53)
10203 >>> Single
10204 FPSort(8, 24)
10205 >>> x = Const('x', Single)
10206 >>> eq(x, FP('x', FPSort(8, 24)))
10207 True
10208 """
10209 ctx = _get_ctx(ctx)
10210 return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
10211
10212
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.

◆ fpSqrt()

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

Definition at line 10615 of file z3py.py.

10615def fpSqrt(rm, a, ctx=None):
10616 """Create a Z3 floating-point square root expression.
10617 """
10618 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10619
10620

◆ fpSub()

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)
x - y
>>> fpSub(rm, x, y).sort()
FPSort(8, 24)

Definition at line 10520 of file z3py.py.

10520def fpSub(rm, a, b, ctx=None):
10521 """Create a Z3 floating-point subtraction expression.
10522
10523 >>> s = FPSort(8, 24)
10524 >>> rm = RNE()
10525 >>> x = FP('x', s)
10526 >>> y = FP('y', s)
10527 >>> fpSub(rm, x, y)
10528 x - y
10529 >>> fpSub(rm, x, y).sort()
10530 FPSort(8, 24)
10531 """
10532 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10533
10534

◆ fpToFP()

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

10786def fpToFP(a1, a2=None, a3=None, ctx=None):
10787 """Create a Z3 floating-point conversion expression from other term sorts
10788 to floating-point.
10789
10790 From a bit-vector term in IEEE 754-2008 format:
10791 >>> x = FPVal(1.0, Float32())
10792 >>> x_bv = fpToIEEEBV(x)
10793 >>> simplify(fpToFP(x_bv, Float32()))
10794 1
10795
10796 From a floating-point term with different precision:
10797 >>> x = FPVal(1.0, Float32())
10798 >>> x_db = fpToFP(RNE(), x, Float64())
10799 >>> x_db.sort()
10800 FPSort(11, 53)
10801
10802 From a real term:
10803 >>> x_r = RealVal(1.5)
10804 >>> simplify(fpToFP(RNE(), x_r, Float32()))
10805 1.5
10806
10807 From a signed bit-vector term:
10808 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10809 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
10810 -1.25*(2**2)
10811 """
10812 ctx = _get_ctx(ctx)
10813 if is_bv(a1) and is_fp_sort(a2):
10814 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
10815 elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
10816 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10817 elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
10818 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10819 elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
10820 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10821 else:
10822 raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
10823
10824

◆ fpToFPUnsigned()

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

Definition at line 10916 of file z3py.py.

10916def fpToFPUnsigned(rm, x, s, ctx=None):
10917 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
10918 if z3_debug():
10919 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10920 _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
10921 _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
10922 ctx = _get_ctx(ctx)
10923 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
10924
10925
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort.

◆ fpToIEEEBV()

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

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

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

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

Definition at line 10990 of file z3py.py.

10990def fpToIEEEBV(x, ctx=None):
10991 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
10992
10993 The size of the resulting bit-vector is automatically determined.
10994
10995 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
10996 knows only one NaN and it will always produce the same bit-vector representation of
10997 that NaN.
10998
10999 >>> x = FP('x', FPSort(8, 24))
11000 >>> y = fpToIEEEBV(x)
11001 >>> print(is_fp(x))
11002 True
11003 >>> print(is_bv(y))
11004 True
11005 >>> print(is_fp(y))
11006 False
11007 >>> print(is_bv(x))
11008 False
11009 """
11010 if z3_debug():
11011 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11012 ctx = _get_ctx(ctx)
11013 return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
11014
11015
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.

◆ fpToReal()

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

10970def fpToReal(x, ctx=None):
10971 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
10972
10973 >>> x = FP('x', FPSort(8, 24))
10974 >>> y = fpToReal(x)
10975 >>> print(is_fp(x))
10976 True
10977 >>> print(is_real(y))
10978 True
10979 >>> print(is_fp(y))
10980 False
10981 >>> print(is_real(x))
10982 False
10983 """
10984 if z3_debug():
10985 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
10986 ctx = _get_ctx(ctx)
10987 return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
10988
10989
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.

◆ fpToSBV()

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

10926def fpToSBV(rm, x, s, ctx=None):
10927 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
10928
10929 >>> x = FP('x', FPSort(8, 24))
10930 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
10931 >>> print(is_fp(x))
10932 True
10933 >>> print(is_bv(y))
10934 True
10935 >>> print(is_fp(y))
10936 False
10937 >>> print(is_bv(x))
10938 False
10939 """
10940 if z3_debug():
10941 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10942 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
10943 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
10944 ctx = _get_ctx(ctx)
10945 return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
10946
10947
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.

◆ fpToUBV()

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

10948def fpToUBV(rm, x, s, ctx=None):
10949 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
10950
10951 >>> x = FP('x', FPSort(8, 24))
10952 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
10953 >>> print(is_fp(x))
10954 True
10955 >>> print(is_bv(y))
10956 True
10957 >>> print(is_fp(y))
10958 False
10959 >>> print(is_bv(x))
10960 False
10961 """
10962 if z3_debug():
10963 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10964 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
10965 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
10966 ctx = _get_ctx(ctx)
10967 return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
10968
10969
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.

◆ fpUnsignedToFP()

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

10898def fpUnsignedToFP(rm, v, sort, ctx=None):
10899 """Create a Z3 floating-point conversion expression that represents the
10900 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10901
10902 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10903 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
10904 >>> x_fp
10905 fpToFPUnsigned(RNE(), 4294967291)
10906 >>> simplify(x_fp)
10907 1*(2**32)
10908 """
10909 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10910 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10911 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10912 ctx = _get_ctx(ctx)
10913 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10914
10915

◆ FPVal()

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

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

Definition at line 10323 of file z3py.py.

10323def FPVal(sig, exp=None, fps=None, ctx=None):
10324 """Return a floating-point value of value `val` and sort `fps`.
10325 If `ctx=None`, then the global context is used.
10326
10327 >>> v = FPVal(20.0, FPSort(8, 24))
10328 >>> v
10329 1.25*(2**4)
10330 >>> print("0x%.8x" % v.exponent_as_long(False))
10331 0x00000004
10332 >>> v = FPVal(2.25, FPSort(8, 24))
10333 >>> v
10334 1.125*(2**1)
10335 >>> v = FPVal(-2.25, FPSort(8, 24))
10336 >>> v
10337 -1.125*(2**1)
10338 >>> FPVal(-0.0, FPSort(8, 24))
10339 -0.0
10340 >>> FPVal(0.0, FPSort(8, 24))
10341 +0.0
10342 >>> FPVal(+0.0, FPSort(8, 24))
10343 +0.0
10344 """
10345 ctx = _get_ctx(ctx)
10346 if is_fp_sort(exp):
10347 fps = exp
10348 exp = None
10349 elif fps is None:
10350 fps = _dflt_fps(ctx)
10351 _z3_assert(is_fp_sort(fps), "sort mismatch")
10352 if exp is None:
10353 exp = 0
10354 val = _to_float_str(sig)
10355 if val == "NaN" or val == "nan":
10356 return fpNaN(fps)
10357 elif val == "-0.0":
10358 return fpMinusZero(fps)
10359 elif val == "0.0" or val == "+0.0":
10360 return fpPlusZero(fps)
10361 elif val == "+oo" or val == "+inf" or val == "+Inf":
10362 return fpPlusInfinity(fps)
10363 elif val == "-oo" or val == "-inf" or val == "-Inf":
10364 return fpMinusInfinity(fps)
10365 else:
10366 return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
10367
10368

◆ fpZero()

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

Definition at line 10316 of file z3py.py.

10316def fpZero(s, negative):
10317 """Create a Z3 floating-point +0.0 or -0.0 term."""
10318 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10319 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10320 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
10321
10322

◆ FreshBool()

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

1863def FreshBool(prefix="b", ctx=None):
1864 """Return a fresh Boolean constant in the given context using the given prefix.
1865
1866 If `ctx=None`, then the global context is used.
1867
1868 >>> b1 = FreshBool()
1869 >>> b2 = FreshBool()
1870 >>> eq(b1, b2)
1871 False
1872 """
1873 ctx = _get_ctx(ctx)
1874 return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1875
1876
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.

◆ FreshConst()

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

Definition at line 1526 of file z3py.py.

1526def FreshConst(sort, prefix="c"):
1527 """Create a fresh constant of a specified sort"""
1528 if z3_debug():
1529 _z3_assert(is_sort(sort), f"Z3 sort expected, got {type(sort)}")
1530 ctx = _get_ctx(sort.ctx)
1531 return _to_expr_ref(Z3_mk_fresh_const(ctx.ref(), prefix, sort.ast), ctx)
1532
1533

◆ FreshFunction()

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

Definition at line 926 of file z3py.py.

926def FreshFunction(*sig):
927 """Create a new fresh Z3 uninterpreted function with the given sorts.
928 """
929 sig = _get_args(sig)
930 if z3_debug():
931 _z3_assert(len(sig) > 0, "At least two arguments expected")
932 arity = len(sig) - 1
933 rng = sig[arity]
934 if z3_debug():
935 _z3_assert(is_sort(rng), "Z3 sort expected")
936 dom = (z3.Sort * arity)()
937 for i in range(arity):
938 if z3_debug():
939 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
940 dom[i] = sig[i].ast
941 ctx = rng.ctx
942 return FuncDeclRef(Z3_mk_fresh_func_decl(ctx.ref(), "f", arity, dom, rng.ast), ctx)
943
944
Z3_func_decl Z3_API Z3_mk_fresh_func_decl(Z3_context c, Z3_string prefix, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a fresh constant or function.

◆ FreshInt()

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

3391def FreshInt(prefix="x", ctx=None):
3392 """Return a fresh integer constant in the given context using the given prefix.
3393
3394 >>> x = FreshInt()
3395 >>> y = FreshInt()
3396 >>> eq(x, y)
3397 False
3398 >>> x.sort()
3399 Int
3400 """
3401 ctx = _get_ctx(ctx)
3402 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
3403
3404

◆ FreshReal()

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

3448def FreshReal(prefix="b", ctx=None):
3449 """Return a fresh real constant in the given context using the given prefix.
3450
3451 >>> x = FreshReal()
3452 >>> y = FreshReal()
3453 >>> eq(x, y)
3454 False
3455 >>> x.sort()
3456 Real
3457 """
3458 ctx = _get_ctx(ctx)
3459 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
3460
3461

◆ Full()

Full (   s)
Create the regular expression that accepts the universal language
>>> e = Full(ReSort(SeqSort(IntSort())))
>>> print(e)
Full(ReSort(Seq(Int)))
>>> e1 = Full(ReSort(StringSort()))
>>> print(e1)
Full(ReSort(String))

Definition at line 11293 of file z3py.py.

11293def Full(s):
11294 """Create the regular expression that accepts the universal language
11295 >>> e = Full(ReSort(SeqSort(IntSort())))
11296 >>> print(e)
11297 Full(ReSort(Seq(Int)))
11298 >>> e1 = Full(ReSort(StringSort()))
11299 >>> print(e1)
11300 Full(ReSort(String))
11301 """
11302 if isinstance(s, ReSortRef):
11303 return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
11304 raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
11305
11306
11307
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.

◆ FullSet()

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

Definition at line 5058 of file z3py.py.

5058def FullSet(s):
5059 """Create the full set
5060 >>> FullSet(IntSort())
5061 K(Int, True)
5062 """
5063 ctx = s.ctx
5064 return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
5065
5066
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.

◆ Function()

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

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

◆ get_as_array_func()

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

Definition at line 6873 of file z3py.py.

6873def get_as_array_func(n):
6874 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6875 if z3_debug():
6876 _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
6877 return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
6878
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.

Referenced by ModelRef.get_interp().

◆ get_ctx()

Context get_ctx (   ctx)

Definition at line 277 of file z3py.py.

277def get_ctx(ctx) -> Context:
278 return _get_ctx(ctx)
279
280

◆ get_default_fp_sort()

get_default_fp_sort (   ctx = None)

Definition at line 9610 of file z3py.py.

9610def get_default_fp_sort(ctx=None):
9611 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9612
9613

◆ get_default_rounding_mode()

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

Definition at line 9577 of file z3py.py.

9577def get_default_rounding_mode(ctx=None):
9578 """Retrieves the global default rounding mode."""
9579 global _dflt_rounding_mode
9580 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9581 return RTZ(ctx)
9582 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9583 return RTN(ctx)
9584 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9585 return RTP(ctx)
9586 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9587 return RNE(ctx)
9588 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9589 return RNA(ctx)
9590
9591

◆ get_full_version()

get_full_version ( )

Definition at line 109 of file z3py.py.

109def get_full_version():
110 return Z3_get_full_version()
111
112
Z3_string Z3_API Z3_get_full_version(void)
Return a string that fully describes the version of Z3 in use.

◆ get_map_func()

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

4810def get_map_func(a):
4811 """Return the function declaration associated with a Z3 map array expression.
4812
4813 >>> f = Function('f', IntSort(), IntSort())
4814 >>> b = Array('b', IntSort(), IntSort())
4815 >>> a = Map(f, b)
4816 >>> eq(f, get_map_func(a))
4817 True
4818 >>> get_map_func(a)
4819 f
4820 >>> get_map_func(a)(0)
4821 f(0)
4822 """
4823 if z3_debug():
4824 _z3_assert(is_map(a), "Z3 array map expression expected.")
4825 return FuncDeclRef(
4827 a.ctx_ref(),
4828 Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0),
4829 ),
4830 ctx=a.ctx,
4831 )
4832
4833
Z3_func_decl Z3_API Z3_to_func_decl(Z3_context c, Z3_ast a)
Convert an AST into a FUNC_DECL_AST. This is just type casting.
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.

◆ get_param()

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

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

Definition at line 317 of file z3py.py.

317def get_param(name):
318 """Return the value of a Z3 global (or module) parameter
319
320 >>> get_param('nlsat.reorder')
321 'true'
322 """
323 ptr = (ctypes.c_char_p * 1)()
324 if Z3_global_param_get(str(name), ptr):
325 r = z3core._to_pystr(ptr[0])
326 return r
327 raise Z3Exception("failed to retrieve value for '%s'" % name)
328
bool Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value)
Get a global (or module) parameter.

◆ get_var_index()

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

1397def get_var_index(a):
1398 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1399
1400 >>> x = Int('x')
1401 >>> y = Int('y')
1402 >>> is_var(x)
1403 False
1404 >>> is_const(x)
1405 True
1406 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1407 >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1408 >>> q = ForAll([x, y], f(x, y) == x + y)
1409 >>> q.body()
1410 f(Var(1), Var(0)) == Var(1) + Var(0)
1411 >>> b = q.body()
1412 >>> b.arg(0)
1413 f(Var(1), Var(0))
1414 >>> v1 = b.arg(0).arg(0)
1415 >>> v2 = b.arg(0).arg(1)
1416 >>> v1
1417 Var(1)
1418 >>> v2
1419 Var(0)
1420 >>> get_var_index(v1)
1421 1
1422 >>> get_var_index(v2)
1423 0
1424 """
1425 if z3_debug():
1426 _z3_assert(is_var(a), "Z3 bound variable expected")
1427 return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
1428
1429
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.

◆ get_version()

get_version ( )

Definition at line 100 of file z3py.py.

100def get_version():
101 major = ctypes.c_uint(0)
102 minor = ctypes.c_uint(0)
103 build = ctypes.c_uint(0)
104 rev = ctypes.c_uint(0)
105 Z3_get_version(major, minor, build, rev)
106 return (major.value, minor.value, build.value, rev.value)
107
108
void Z3_API Z3_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.

◆ get_version_string()

get_version_string ( )

Definition at line 91 of file z3py.py.

91def get_version_string():
92 major = ctypes.c_uint(0)
93 minor = ctypes.c_uint(0)
94 build = ctypes.c_uint(0)
95 rev = ctypes.c_uint(0)
96 Z3_get_version(major, minor, build, rev)
97 return "%s.%s.%s" % (major.value, minor.value, build.value)
98
99

◆ help_simplify()

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

Definition at line 9083 of file z3py.py.

9083def help_simplify():
9084 """Return a string describing all options available for Z3 `simplify` procedure."""
9085 print(Z3_simplify_get_help(main_ctx().ref()))
9086
9087
Z3_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.

◆ If()

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

1443def If(a, b, c, ctx=None):
1444 """Create a Z3 if-then-else expression.
1445
1446 >>> x = Int('x')
1447 >>> y = Int('y')
1448 >>> max = If(x > y, x, y)
1449 >>> max
1450 If(x > y, x, y)
1451 >>> simplify(max)
1452 If(x <= y, y, x)
1453 """
1454 if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1455 return Cond(a, b, c, ctx)
1456 else:
1457 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1458 s = BoolSort(ctx)
1459 a = s.cast(a)
1460 b, c = _coerce_exprs(b, c, ctx)
1461 if z3_debug():
1462 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1463 return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1464
1465
Z3_ast Z3_API Z3_mk_ite(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Create an AST node representing an if-then-else: ite(t1, t2, t3).

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

◆ Implies()

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

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

Definition at line 1877 of file z3py.py.

1877def Implies(a, b, ctx=None):
1878 """Create a Z3 implies expression.
1879
1880 >>> p, q = Bools('p q')
1881 >>> Implies(p, q)
1882 Implies(p, q)
1883 """
1884 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1885 s = BoolSort(ctx)
1886 a = s.cast(a)
1887 b = s.cast(b)
1888 return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1889
1890
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.

◆ IndexOf()

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

Definition at line 11377 of file z3py.py.

11377def IndexOf(s, substr, offset=None):
11378 """Retrieve the index of substring within a string starting at a specified offset.
11379 >>> simplify(IndexOf("abcabc", "bc", 0))
11380 1
11381 >>> simplify(IndexOf("abcabc", "bc", 2))
11382 4
11383 """
11384 if offset is None:
11385 offset = IntVal(0)
11386 ctx = None
11387 if is_expr(offset):
11388 ctx = offset.ctx
11389 ctx = _get_ctx2(s, substr, ctx)
11390 s = _coerce_seq(s, ctx)
11391 substr = _coerce_seq(substr, ctx)
11392 if _is_int(offset):
11393 offset = IntVal(offset, ctx)
11394 return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
11395
11396
Z3_ast Z3_API Z3_mk_seq_index(Z3_context c, Z3_ast s, Z3_ast substr, Z3_ast offset)
Return index of the first occurrence of substr in s starting from offset offset. If s does not contai...

◆ InRe()

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

11516def InRe(s, re):
11517 """Create regular expression membership test
11518 >>> re = Union(Re("a"),Re("b"))
11519 >>> print (simplify(InRe("a", re)))
11520 True
11521 >>> print (simplify(InRe("b", re)))
11522 True
11523 >>> print (simplify(InRe("c", re)))
11524 False
11525 """
11526 s = _coerce_seq(s, re.ctx)
11527 return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
11528
11529
Z3_ast Z3_API Z3_mk_seq_in_re(Z3_context c, Z3_ast seq, Z3_ast re)
Check if seq is in the language generated by the regular expression re.

◆ Int()

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

3352def Int(name, ctx=None):
3353 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3354
3355 >>> x = Int('x')
3356 >>> is_int(x)
3357 True
3358 >>> is_int(x + 1)
3359 True
3360 """
3361 ctx = _get_ctx(ctx)
3362 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
3363
3364

Referenced by Ints(), and IntVector().

◆ Int2BV()

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

Definition at line 4107 of file z3py.py.

4107def Int2BV(a, num_bits):
4108 """Return the z3 expression Int2BV(a, num_bits).
4109 It is a bit-vector of width num_bits and represents the
4110 modulo of a by 2^num_bits
4111 """
4112 ctx = a.ctx
4113 return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
4114
4115
Z3_ast Z3_API Z3_mk_int2bv(Z3_context c, unsigned n, Z3_ast t1)
Create an n bit bit-vector from the integer argument t1.

◆ Intersect()

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

Definition at line 11550 of file z3py.py.

11550def Intersect(*args):
11551 """Create intersection of regular expressions.
11552 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
11553 """
11554 args = _get_args(args)
11555 sz = len(args)
11556 if z3_debug():
11557 _z3_assert(sz > 0, "At least one argument expected.")
11558 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11559 if sz == 1:
11560 return args[0]
11561 ctx = args[0].ctx
11562 v = (Ast * sz)()
11563 for i in range(sz):
11564 v[i] = args[i].as_ast()
11565 return ReRef(Z3_mk_re_intersect(ctx.ref(), sz, v), ctx)
11566
11567
Z3_ast Z3_API Z3_mk_re_intersect(Z3_context c, unsigned n, Z3_ast const args[])
Create the intersection of the regular languages.

◆ Ints()

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

3365def Ints(names, ctx=None):
3366 """Return a tuple of Integer constants.
3367
3368 >>> x, y, z = Ints('x y z')
3369 >>> Sum(x, y, z)
3370 x + y + z
3371 """
3372 ctx = _get_ctx(ctx)
3373 if isinstance(names, str):
3374 names = names.split(" ")
3375 return [Int(name, ctx) for name in names]
3376
3377

◆ IntSort()

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

3246def IntSort(ctx=None):
3247 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3248
3249 >>> IntSort()
3250 Int
3251 >>> x = Const('x', IntSort())
3252 >>> is_int(x)
3253 True
3254 >>> x.sort() == IntSort()
3255 True
3256 >>> x.sort() == BoolSort()
3257 False
3258 """
3259 ctx = _get_ctx(ctx)
3260 return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
3261
3262
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.

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

◆ IntToStr()

IntToStr (   s)
Convert integer expression to string

Definition at line 11458 of file z3py.py.

11458def IntToStr(s):
11459 """Convert integer expression to string"""
11460 if not is_expr(s):
11461 s = _py2expr(s)
11462 return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
11463
11464
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.

◆ IntVal()

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

3292def IntVal(val, ctx=None):
3293 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3294
3295 >>> IntVal(1)
3296 1
3297 >>> IntVal("100")
3298 100
3299 """
3300 ctx = _get_ctx(ctx)
3301 return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
3302
3303

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

◆ IntVector()

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

3378def IntVector(prefix, sz, ctx=None):
3379 """Return a list of integer constants of size `sz`.
3380
3381 >>> X = IntVector('x', 3)
3382 >>> X
3383 [x__0, x__1, x__2]
3384 >>> Sum(X)
3385 x__0 + x__1 + x__2
3386 """
3387 ctx = _get_ctx(ctx)
3388 return [Int("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3389
3390

◆ is_add()

bool is_add ( Any  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 2894 of file z3py.py.

2894def is_add(a : Any) -> bool:
2895 """Return `True` if `a` is an expression of the form b + c.
2896
2897 >>> x, y = Ints('x y')
2898 >>> is_add(x + y)
2899 True
2900 >>> is_add(x - y)
2901 False
2902 """
2903 return is_app_of(a, Z3_OP_ADD)
2904
2905

◆ is_algebraic_value()

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

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

Definition at line 2880 of file z3py.py.

2880def is_algebraic_value(a):
2881 """Return `True` if `a` is an algebraic value of sort Real.
2882
2883 >>> is_algebraic_value(RealVal("3/5"))
2884 False
2885 >>> n = simplify(Sqrt(2))
2886 >>> n
2887 1.4142135623?
2888 >>> is_algebraic_value(n)
2889 True
2890 """
2891 return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2892
2893

◆ is_and()

bool is_and ( Any  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 1713 of file z3py.py.

1713def is_and(a : Any) -> bool:
1714 """Return `True` if `a` is a Z3 and expression.
1715
1716 >>> p, q = Bools('p q')
1717 >>> is_and(And(p, q))
1718 True
1719 >>> is_and(Or(p, q))
1720 False
1721 """
1722 return is_app_of(a, Z3_OP_AND)
1723
1724

◆ is_app()

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

1327def is_app(a):
1328 """Return `True` if `a` is a Z3 function application.
1329
1330 Note that, constants are function applications with 0 arguments.
1331
1332 >>> a = Int('a')
1333 >>> is_app(a)
1334 True
1335 >>> is_app(a + 1)
1336 True
1337 >>> is_app(IntSort())
1338 False
1339 >>> is_app(1)
1340 False
1341 >>> is_app(IntVal(1))
1342 True
1343 >>> x = Int('x')
1344 >>> is_app(ForAll(x, x >= 0))
1345 False
1346 """
1347 if not isinstance(a, ExprRef):
1348 return False
1349 k = _ast_kind(a.ctx, a)
1350 return k == Z3_NUMERAL_AST or k == Z3_APP_AST
1351
1352

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

◆ is_app_of()

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

1430def is_app_of(a, k):
1431 """Return `True` if `a` is an application of the given kind `k`.
1432
1433 >>> x = Int('x')
1434 >>> n = x + 1
1435 >>> is_app_of(n, Z3_OP_ADD)
1436 True
1437 >>> is_app_of(n, Z3_OP_MUL)
1438 False
1439 """
1440 return is_app(a) and a.kind() == k
1441
1442

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

◆ is_arith()

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

2767def is_arith(a):
2768 """Return `True` if `a` is an arithmetical expression.
2769
2770 >>> x = Int('x')
2771 >>> is_arith(x)
2772 True
2773 >>> is_arith(x + 1)
2774 True
2775 >>> is_arith(1)
2776 False
2777 >>> is_arith(IntVal(1))
2778 True
2779 >>> y = Real('y')
2780 >>> is_arith(y)
2781 True
2782 >>> is_arith(y + 1)
2783 True
2784 """
2785 return isinstance(a, ArithRef)
2786
2787

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

◆ is_arith_sort()

bool is_arith_sort ( Any  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 2466 of file z3py.py.

2466def is_arith_sort(s : Any) -> bool:
2467 """Return `True` if s is an arithmetical sort (type).
2468
2469 >>> is_arith_sort(IntSort())
2470 True
2471 >>> is_arith_sort(RealSort())
2472 True
2473 >>> is_arith_sort(BoolSort())
2474 False
2475 >>> n = Int('x') + 1
2476 >>> is_arith_sort(n.sort())
2477 True
2478 """
2479 return isinstance(s, ArithSortRef)
2480
2481

Referenced by ArithSortRef.subsort().

◆ is_array()

bool is_array ( Any  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 4745 of file z3py.py.

4745def is_array(a : Any) -> bool:
4746 """Return `True` if `a` is a Z3 array expression.
4747
4748 >>> a = Array('a', IntSort(), IntSort())
4749 >>> is_array(a)
4750 True
4751 >>> is_array(Store(a, 0, 1))
4752 True
4753 >>> is_array(a[0])
4754 False
4755 """
4756 return isinstance(a, ArrayRef)
4757
4758

Referenced by Ext(), and Map().

◆ is_array_sort()

is_array_sort (   a)

Definition at line 4741 of file z3py.py.

4741def is_array_sort(a):
4742 return Z3_get_sort_kind(a.ctx.ref(), Z3_get_sort(a.ctx.ref(), a.ast)) == Z3_ARRAY_SORT
4743
4744

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

◆ is_as_array()

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

Definition at line 6868 of file z3py.py.

6868def is_as_array(n):
6869 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6870 return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6871
6872
bool Z3_API Z3_is_as_array(Z3_context c, Z3_ast a)
The (_ as-array f) AST node is a construct for assigning interpretations for arrays in Z3....

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

◆ is_ast()

bool is_ast ( Any  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 465 of file z3py.py.

465def is_ast(a : Any) -> bool:
466 """Return `True` if `a` is an AST node.
467
468 >>> is_ast(10)
469 False
470 >>> is_ast(IntVal(10))
471 True
472 >>> is_ast(Int('x'))
473 True
474 >>> is_ast(BoolSort())
475 True
476 >>> is_ast(Function('f', IntSort(), IntSort()))
477 True
478 >>> is_ast("x")
479 False
480 >>> is_ast(Solver())
481 False
482 """
483 return isinstance(a, AstRef)
484
485

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

◆ is_bool()

bool is_bool ( Any  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 1663 of file z3py.py.

1663def is_bool(a : Any) -> bool:
1664 """Return `True` if `a` is a Z3 Boolean expression.
1665
1666 >>> p = Bool('p')
1667 >>> is_bool(p)
1668 True
1669 >>> q = Bool('q')
1670 >>> is_bool(And(p, q))
1671 True
1672 >>> x = Real('x')
1673 >>> is_bool(x)
1674 False
1675 >>> is_bool(x == 0)
1676 True
1677 """
1678 return isinstance(a, BoolRef)
1679
1680

Referenced by _mk_quantifier().

◆ is_bv()

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

4055def is_bv(a):
4056 """Return `True` if `a` is a Z3 bit-vector expression.
4057
4058 >>> b = BitVec('b', 32)
4059 >>> is_bv(b)
4060 True
4061 >>> is_bv(b + 10)
4062 True
4063 >>> is_bv(Int('x'))
4064 False
4065 """
4066 return isinstance(a, BitVecRef)
4067
4068

Referenced by _check_bv_args(), BV2Int(), BVRedAnd(), BVRedOr(), BVSNegNoOverflow(), Concat(), Extract(), is_bv_value(), RepeatBitVec(), SignExt(), and ZeroExt().

◆ is_bv_sort()

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

3582def is_bv_sort(s):
3583 """Return True if `s` is a Z3 bit-vector sort.
3584
3585 >>> is_bv_sort(BitVecSort(32))
3586 True
3587 >>> is_bv_sort(IntSort())
3588 False
3589 """
3590 return isinstance(s, BitVecSortRef)
3591
3592

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

◆ is_bv_value()

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

4069def is_bv_value(a):
4070 """Return `True` if `a` is a Z3 bit-vector numeral value.
4071
4072 >>> b = BitVec('b', 32)
4073 >>> is_bv_value(b)
4074 False
4075 >>> b = BitVecVal(10, 32)
4076 >>> b
4077 10
4078 >>> is_bv_value(b)
4079 True
4080 """
4081 return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
4082
4083

◆ is_const()

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

1353def is_const(a):
1354 """Return `True` if `a` is Z3 constant/variable expression.
1355
1356 >>> a = Int('a')
1357 >>> is_const(a)
1358 True
1359 >>> is_const(a + 1)
1360 False
1361 >>> is_const(1)
1362 False
1363 >>> is_const(IntVal(1))
1364 True
1365 >>> x = Int('x')
1366 >>> is_const(ForAll(x, x >= 0))
1367 False
1368 """
1369 return is_app(a) and a.num_args() == 0
1370
1371

Referenced by ModelRef.__getitem__(), _mk_quantifier(), Solver.assert_and_track(), and ModelRef.get_interp().

◆ is_const_array()

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

4759def is_const_array(a):
4760 """Return `True` if `a` is a Z3 constant array.
4761
4762 >>> a = K(IntSort(), 10)
4763 >>> is_const_array(a)
4764 True
4765 >>> a = Array('a', IntSort(), IntSort())
4766 >>> is_const_array(a)
4767 False
4768 """
4769 return is_app_of(a, Z3_OP_CONST_ARRAY)
4770
4771

◆ is_default()

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

4801def is_default(a):
4802 """Return `True` if `a` is a Z3 default array expression.
4803 >>> d = Default(K(IntSort(), 10))
4804 >>> is_default(d)
4805 True
4806 """
4807 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4808
4809

◆ is_distinct()

bool is_distinct ( Any  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 1771 of file z3py.py.

1771def is_distinct(a : Any) -> bool:
1772 """Return `True` if `a` is a Z3 distinct expression.
1773
1774 >>> x, y, z = Ints('x y z')
1775 >>> is_distinct(x == y)
1776 False
1777 >>> is_distinct(Distinct(x, y, z))
1778 True
1779 """
1780 return is_app_of(a, Z3_OP_DISTINCT)
1781
1782

◆ is_div()

bool is_div ( Any  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 2930 of file z3py.py.

2930def is_div(a : Any) -> bool:
2931 """Return `True` if `a` is an expression of the form b / c.
2932
2933 >>> x, y = Reals('x y')
2934 >>> is_div(x / y)
2935 True
2936 >>> is_div(x + y)
2937 False
2938 >>> x, y = Ints('x y')
2939 >>> is_div(x / y)
2940 False
2941 >>> is_idiv(x / y)
2942 True
2943 """
2944 return is_app_of(a, Z3_OP_DIV)
2945
2946

◆ is_eq()

bool is_eq ( Any  a)
Return `True` if `a` is a Z3 equality expression.

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

Definition at line 1761 of file z3py.py.

1761def is_eq(a : Any) -> bool:
1762 """Return `True` if `a` is a Z3 equality expression.
1763
1764 >>> x, y = Ints('x y')
1765 >>> is_eq(x == y)
1766 True
1767 """
1768 return is_app_of(a, Z3_OP_EQ)
1769
1770

Referenced by AstRef.__bool__().

◆ is_expr()

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

1304def is_expr(a):
1305 """Return `True` if `a` is a Z3 expression.
1306
1307 >>> a = Int('a')
1308 >>> is_expr(a)
1309 True
1310 >>> is_expr(a + 1)
1311 True
1312 >>> is_expr(IntSort())
1313 False
1314 >>> is_expr(1)
1315 False
1316 >>> is_expr(IntVal(1))
1317 True
1318 >>> x = Int('x')
1319 >>> is_expr(ForAll(x, x >= 0))
1320 True
1321 >>> is_expr(FPVal(1.0))
1322 True
1323 """
1324 return isinstance(a, ExprRef)
1325
1326

Referenced by _coerce_expr_list(), _coerce_expr_merge(), _coerce_exprs(), _mk_quantifier(), _py2expr(), SortRef.cast(), ArithSortRef.cast(), BitVecSortRef.cast(), Cbrt(), Concat(), is_var(), K(), MultiPattern(), Sqrt(), and ModelRef.update_value().

◆ is_false()

bool is_false ( Any  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 1699 of file z3py.py.

1699def is_false(a : Any) -> bool:
1700 """Return `True` if `a` is the Z3 false expression.
1701
1702 >>> p = Bool('p')
1703 >>> is_false(p)
1704 False
1705 >>> is_false(False)
1706 False
1707 >>> is_false(BoolVal(False))
1708 True
1709 """
1710 return is_app_of(a, Z3_OP_FALSE)
1711
1712

Referenced by AstRef.__bool__(), and BoolRef.py_value().

◆ is_finite_domain()

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

7961def is_finite_domain(a):
7962 """Return `True` if `a` is a Z3 finite-domain expression.
7963
7964 >>> s = FiniteDomainSort('S', 100)
7965 >>> b = Const('b', s)
7966 >>> is_finite_domain(b)
7967 True
7968 >>> is_finite_domain(Int('x'))
7969 False
7970 """
7971 return isinstance(a, FiniteDomainRef)
7972
7973

◆ is_finite_domain_sort()

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

7938def is_finite_domain_sort(s):
7939 """Return True if `s` is a Z3 finite-domain sort.
7940
7941 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7942 True
7943 >>> is_finite_domain_sort(IntSort())
7944 False
7945 """
7946 return isinstance(s, FiniteDomainSortRef)
7947
7948

◆ is_finite_domain_value()

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

8015def is_finite_domain_value(a):
8016 """Return `True` if `a` is a Z3 finite-domain value.
8017
8018 >>> s = FiniteDomainSort('S', 100)
8019 >>> b = Const('b', s)
8020 >>> is_finite_domain_value(b)
8021 False
8022 >>> b = FiniteDomainVal(10, s)
8023 >>> b
8024 10
8025 >>> is_finite_domain_value(b)
8026 True
8027 """
8028 return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
8029
8030

◆ is_fp()

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

10169def is_fp(a):
10170 """Return `True` if `a` is a Z3 floating-point expression.
10171
10172 >>> b = FP('b', FPSort(8, 24))
10173 >>> is_fp(b)
10174 True
10175 >>> is_fp(b + 1.0)
10176 True
10177 >>> is_fp(Int('x'))
10178 False
10179 """
10180 return isinstance(a, FPRef)
10181
10182

◆ is_fp_sort()

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

9743def is_fp_sort(s):
9744 """Return True if `s` is a Z3 floating-point sort.
9745
9746 >>> is_fp_sort(FPSort(8, 24))
9747 True
9748 >>> is_fp_sort(IntSort())
9749 False
9750 """
9751 return isinstance(s, FPSortRef)
9752
9753

◆ is_fp_value()

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

10183def is_fp_value(a):
10184 """Return `True` if `a` is a Z3 floating-point numeral value.
10185
10186 >>> b = FP('b', FPSort(8, 24))
10187 >>> is_fp_value(b)
10188 False
10189 >>> b = FPVal(1.0, FPSort(8, 24))
10190 >>> b
10191 1
10192 >>> is_fp_value(b)
10193 True
10194 """
10195 return is_fp(a) and _is_numeral(a.ctx, a.ast)
10196
10197

◆ is_fprm()

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

10003def is_fprm(a):
10004 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
10005
10006 >>> rm = RNE()
10007 >>> is_fprm(rm)
10008 True
10009 >>> rm = 1.0
10010 >>> is_fprm(rm)
10011 False
10012 """
10013 return isinstance(a, FPRMRef)
10014
10015

◆ is_fprm_sort()

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

9754def is_fprm_sort(s):
9755 """Return True if `s` is a Z3 floating-point rounding mode sort.
9756
9757 >>> is_fprm_sort(FPSort(8, 24))
9758 False
9759 >>> is_fprm_sort(RNE().sort())
9760 True
9761 """
9762 return isinstance(s, FPRMSortRef)
9763
9764# FP Expressions
9765
9766

◆ is_fprm_value()

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

Definition at line 10016 of file z3py.py.

10016def is_fprm_value(a):
10017 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
10018 return is_fprm(a) and _is_numeral(a.ctx, a.ast)
10019
10020# FP Numerals
10021
10022

◆ is_func_decl()

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

890def is_func_decl(a):
891 """Return `True` if `a` is a Z3 function declaration.
892
893 >>> f = Function('f', IntSort(), IntSort())
894 >>> is_func_decl(f)
895 True
896 >>> x = Real('x')
897 >>> is_func_decl(x)
898 False
899 """
900 return isinstance(a, FuncDeclRef)
901
902

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

◆ is_ge()

bool is_ge ( Any  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 2995 of file z3py.py.

2995def is_ge(a : Any) -> bool:
2996 """Return `True` if `a` is an expression of the form b >= c.
2997
2998 >>> x, y = Ints('x y')
2999 >>> is_ge(x >= y)
3000 True
3001 >>> is_ge(x == y)
3002 False
3003 """
3004 return is_app_of(a, Z3_OP_GE)
3005
3006

◆ is_gt()

bool is_gt ( Any  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 3007 of file z3py.py.

3007def is_gt(a : Any) -> bool:
3008 """Return `True` if `a` is an expression of the form b > c.
3009
3010 >>> x, y = Ints('x y')
3011 >>> is_gt(x > y)
3012 True
3013 >>> is_gt(x == y)
3014 False
3015 """
3016 return is_app_of(a, Z3_OP_GT)
3017
3018

◆ is_idiv()

bool is_idiv ( Any  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 2947 of file z3py.py.

2947def is_idiv(a : Any) -> bool:
2948 """Return `True` if `a` is an expression of the form b div c.
2949
2950 >>> x, y = Ints('x y')
2951 >>> is_idiv(x / y)
2952 True
2953 >>> is_idiv(x + y)
2954 False
2955 """
2956 return is_app_of(a, Z3_OP_IDIV)
2957
2958

◆ is_implies()

bool is_implies ( Any  a)
Return `True` if `a` is a Z3 implication expression.

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

Definition at line 1737 of file z3py.py.

1737def is_implies(a : Any) -> bool:
1738 """Return `True` if `a` is a Z3 implication expression.
1739
1740 >>> p, q = Bools('p q')
1741 >>> is_implies(Implies(p, q))
1742 True
1743 >>> is_implies(And(p, q))
1744 False
1745 """
1746 return is_app_of(a, Z3_OP_IMPLIES)
1747
1748

◆ is_int()

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

2788def is_int(a) -> bool:
2789 """Return `True` if `a` is an integer expression.
2790
2791 >>> x = Int('x')
2792 >>> is_int(x + 1)
2793 True
2794 >>> is_int(1)
2795 False
2796 >>> is_int(IntVal(1))
2797 True
2798 >>> y = Real('y')
2799 >>> is_int(y)
2800 False
2801 >>> is_int(y + 1)
2802 False
2803 """
2804 return is_arith(a) and a.is_int()
2805
2806

◆ is_int_value()

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

2834def is_int_value(a):
2835 """Return `True` if `a` is an integer value of sort Int.
2836
2837 >>> is_int_value(IntVal(1))
2838 True
2839 >>> is_int_value(1)
2840 False
2841 >>> is_int_value(Int('x'))
2842 False
2843 >>> n = Int('x') + 1
2844 >>> n
2845 x + 1
2846 >>> n.arg(1)
2847 1
2848 >>> is_int_value(n.arg(1))
2849 True
2850 >>> is_int_value(RealVal("1/3"))
2851 False
2852 >>> is_int_value(RealVal(1))
2853 False
2854 """
2855 return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
2856
2857

◆ is_is_int()

bool is_is_int ( Any  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 3019 of file z3py.py.

3019def is_is_int(a : Any) -> bool:
3020 """Return `True` if `a` is an expression of the form IsInt(b).
3021
3022 >>> x = Real('x')
3023 >>> is_is_int(IsInt(x))
3024 True
3025 >>> is_is_int(x)
3026 False
3027 """
3028 return is_app_of(a, Z3_OP_IS_INT)
3029
3030

◆ is_K()

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

4772def is_K(a):
4773 """Return `True` if `a` is a Z3 constant array.
4774
4775 >>> a = K(IntSort(), 10)
4776 >>> is_K(a)
4777 True
4778 >>> a = Array('a', IntSort(), IntSort())
4779 >>> is_K(a)
4780 False
4781 """
4782 return is_app_of(a, Z3_OP_CONST_ARRAY)
4783
4784

◆ is_le()

bool is_le ( Any  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 2971 of file z3py.py.

2971def is_le(a : Any) -> bool:
2972 """Return `True` if `a` is an expression of the form b <= c.
2973
2974 >>> x, y = Ints('x y')
2975 >>> is_le(x <= y)
2976 True
2977 >>> is_le(x < y)
2978 False
2979 """
2980 return is_app_of(a, Z3_OP_LE)
2981
2982

◆ is_lt()

bool is_lt ( Any  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 2983 of file z3py.py.

2983def is_lt(a : Any) -> bool:
2984 """Return `True` if `a` is an expression of the form b < c.
2985
2986 >>> x, y = Ints('x y')
2987 >>> is_lt(x < y)
2988 True
2989 >>> is_lt(x == y)
2990 False
2991 """
2992 return is_app_of(a, Z3_OP_LT)
2993
2994

◆ is_map()

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

4785def is_map(a):
4786 """Return `True` if `a` is a Z3 map array expression.
4787
4788 >>> f = Function('f', IntSort(), IntSort())
4789 >>> b = Array('b', IntSort(), IntSort())
4790 >>> a = Map(f, b)
4791 >>> a
4792 Map(f, b)
4793 >>> is_map(a)
4794 True
4795 >>> is_map(b)
4796 False
4797 """
4798 return is_app_of(a, Z3_OP_ARRAY_MAP)
4799
4800

Referenced by get_map_func().

◆ is_mod()

bool is_mod ( Any  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 2959 of file z3py.py.

2959def is_mod(a : Any) -> bool:
2960 """Return `True` if `a` is an expression of the form b % c.
2961
2962 >>> x, y = Ints('x y')
2963 >>> is_mod(x % y)
2964 True
2965 >>> is_mod(x + y)
2966 False
2967 """
2968 return is_app_of(a, Z3_OP_MOD)
2969
2970

◆ is_mul()

bool is_mul ( Any  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 2906 of file z3py.py.

2906def is_mul(a : Any) -> bool:
2907 """Return `True` if `a` is an expression of the form b * c.
2908
2909 >>> x, y = Ints('x y')
2910 >>> is_mul(x * y)
2911 True
2912 >>> is_mul(x - y)
2913 False
2914 """
2915 return is_app_of(a, Z3_OP_MUL)
2916
2917

◆ is_not()

bool is_not ( Any  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 1749 of file z3py.py.

1749def is_not(a : Any) -> bool:
1750 """Return `True` if `a` is a Z3 not expression.
1751
1752 >>> p = Bool('p')
1753 >>> is_not(p)
1754 False
1755 >>> is_not(Not(p))
1756 True
1757 """
1758 return is_app_of(a, Z3_OP_NOT)
1759
1760

Referenced by mk_not().

◆ is_or()

bool is_or ( Any  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 1725 of file z3py.py.

1725def is_or(a : Any) -> bool:
1726 """Return `True` if `a` is a Z3 or expression.
1727
1728 >>> p, q = Bools('p q')
1729 >>> is_or(Or(p, q))
1730 True
1731 >>> is_or(And(p, q))
1732 False
1733 """
1734 return is_app_of(a, Z3_OP_OR)
1735
1736

◆ is_pattern()

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

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

Definition at line 2025 of file z3py.py.

2025def is_pattern(a):
2026 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
2027
2028 >>> f = Function('f', IntSort(), IntSort())
2029 >>> x = Int('x')
2030 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
2031 >>> q
2032 ForAll(x, f(x) == 0)
2033 >>> q.num_patterns()
2034 1
2035 >>> is_pattern(q.pattern(0))
2036 True
2037 >>> q.pattern(0)
2038 f(Var(0))
2039 """
2040 return isinstance(a, PatternRef)
2041
2042

Referenced by _mk_quantifier(), and _to_pattern().

◆ is_probe()

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

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

Definition at line 8924 of file z3py.py.

8924def is_probe(p):
8925 """Return `True` if `p` is a Z3 probe.
8926
8927 >>> is_probe(Int('x'))
8928 False
8929 >>> is_probe(Probe('memory'))
8930 True
8931 """
8932 return isinstance(p, Probe)
8933
8934

Referenced by _ctx_from_ast_arg_list(), _has_probe(), and Not().

◆ is_quantifier()

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

2275def is_quantifier(a):
2276 """Return `True` if `a` is a Z3 quantifier.
2277
2278 >>> f = Function('f', IntSort(), IntSort())
2279 >>> x = Int('x')
2280 >>> q = ForAll(x, f(x) == 0)
2281 >>> is_quantifier(q)
2282 True
2283 >>> is_quantifier(f(x))
2284 False
2285 """
2286 return isinstance(a, QuantifierRef)
2287
2288

◆ is_rational_value()

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

2858def is_rational_value(a):
2859 """Return `True` if `a` is rational value of sort Real.
2860
2861 >>> is_rational_value(RealVal(1))
2862 True
2863 >>> is_rational_value(RealVal("3/5"))
2864 True
2865 >>> is_rational_value(IntVal(1))
2866 False
2867 >>> is_rational_value(1)
2868 False
2869 >>> n = Real('x') + 1
2870 >>> n.arg(1)
2871 1
2872 >>> is_rational_value(n.arg(1))
2873 True
2874 >>> is_rational_value(Real('x'))
2875 False
2876 """
2877 return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2878
2879

◆ is_re()

is_re (   s)

Definition at line 11512 of file z3py.py.

11512def is_re(s):
11513 return isinstance(s, ReRef)
11514
11515

Referenced by Concat().

◆ is_real()

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

2807def is_real(a):
2808 """Return `True` if `a` is a real expression.
2809
2810 >>> x = Int('x')
2811 >>> is_real(x + 1)
2812 False
2813 >>> y = Real('y')
2814 >>> is_real(y)
2815 True
2816 >>> is_real(y + 1)
2817 True
2818 >>> is_real(1)
2819 False
2820 >>> is_real(RealVal(1))
2821 True
2822 """
2823 return is_arith(a) and a.is_real()
2824
2825

◆ is_select()

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

5013def is_select(a):
5014 """Return `True` if `a` is a Z3 array select application.
5015
5016 >>> a = Array('a', IntSort(), IntSort())
5017 >>> is_select(a)
5018 False
5019 >>> i = Int('i')
5020 >>> is_select(a[i])
5021 True
5022 """
5023 return is_app_of(a, Z3_OP_SELECT)
5024
5025

◆ is_seq()

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

11194def is_seq(a):
11195 """Return `True` if `a` is a Z3 sequence expression.
11196 >>> print (is_seq(Unit(IntVal(0))))
11197 True
11198 >>> print (is_seq(StringVal("abc")))
11199 True
11200 """
11201 return isinstance(a, SeqRef)
11202
11203

Referenced by Concat(), and Extract().

◆ is_sort()

bool is_sort ( Any  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 665 of file z3py.py.

665def is_sort(s : Any) -> bool:
666 """Return `True` if `s` is a Z3 sort.
667
668 >>> is_sort(IntSort())
669 True
670 >>> is_sort(Int('x'))
671 False
672 >>> is_expr(Int('x'))
673 True
674 """
675 return isinstance(s, SortRef)
676
677

Referenced by _valid_accessor(), ArraySort(), CreateDatatypes(), FreshConst(), FreshFunction(), Function(), K(), RecFunction(), and Var().

◆ is_store()

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

5026def is_store(a):
5027 """Return `True` if `a` is a Z3 array store application.
5028
5029 >>> a = Array('a', IntSort(), IntSort())
5030 >>> is_store(a)
5031 False
5032 >>> is_store(Store(a, 0, 1))
5033 True
5034 """
5035 return is_app_of(a, Z3_OP_STORE)
5036

◆ is_string()

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

Definition at line 11204 of file z3py.py.

11204def is_string(a: Any) -> bool:
11205 """Return `True` if `a` is a Z3 string expression.
11206 >>> print (is_string(StringVal("ab")))
11207 True
11208 """
11209 return isinstance(a, SeqRef) and a.is_string()
11210
11211

◆ is_string_value()

bool is_string_value ( Any  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 11212 of file z3py.py.

11212def is_string_value(a: Any) -> bool:
11213 """return 'True' if 'a' is a Z3 string constant expression.
11214 >>> print (is_string_value(StringVal("a")))
11215 True
11216 >>> print (is_string_value(StringVal("a") + StringVal("b")))
11217 False
11218 """
11219 return isinstance(a, SeqRef) and a.is_string_value()
11220

◆ is_sub()

bool is_sub ( Any  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 2918 of file z3py.py.

2918def is_sub(a : Any) -> bool:
2919 """Return `True` if `a` is an expression of the form b - c.
2920
2921 >>> x, y = Ints('x y')
2922 >>> is_sub(x - y)
2923 True
2924 >>> is_sub(x + y)
2925 False
2926 """
2927 return is_app_of(a, Z3_OP_SUB)
2928
2929

◆ is_to_int()

bool is_to_int ( Any  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 3046 of file z3py.py.

3046def is_to_int(a : Any) -> bool:
3047 """Return `True` if `a` is an expression of the form ToInt(b).
3048
3049 >>> x = Real('x')
3050 >>> n = ToInt(x)
3051 >>> n
3052 ToInt(x)
3053 >>> is_to_int(n)
3054 True
3055 >>> is_to_int(x)
3056 False
3057 """
3058 return is_app_of(a, Z3_OP_TO_INT)
3059
3060

◆ is_to_real()

bool is_to_real ( Any  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 3031 of file z3py.py.

3031def is_to_real(a : Any) -> bool:
3032 """Return `True` if `a` is an expression of the form ToReal(b).
3033
3034 >>> x = Int('x')
3035 >>> n = ToReal(x)
3036 >>> n
3037 ToReal(x)
3038 >>> is_to_real(n)
3039 True
3040 >>> is_to_real(x)
3041 False
3042 """
3043 return is_app_of(a, Z3_OP_TO_REAL)
3044
3045

◆ is_true()

bool is_true ( Any  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 1681 of file z3py.py.

1681def is_true(a : Any) -> bool:
1682 """Return `True` if `a` is the Z3 true expression.
1683
1684 >>> p = Bool('p')
1685 >>> is_true(p)
1686 False
1687 >>> is_true(simplify(p == p))
1688 True
1689 >>> x = Real('x')
1690 >>> is_true(x == 0)
1691 False
1692 >>> # True is a Python Boolean expression
1693 >>> is_true(True)
1694 False
1695 """
1696 return is_app_of(a, Z3_OP_TRUE)
1697
1698

Referenced by AstRef.__bool__(), and BoolRef.py_value().

◆ is_var()

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

1372def is_var(a):
1373 """Return `True` if `a` is variable.
1374
1375 Z3 uses de-Bruijn indices for representing bound variables in
1376 quantifiers.
1377
1378 >>> x = Int('x')
1379 >>> is_var(x)
1380 False
1381 >>> is_const(x)
1382 True
1383 >>> f = Function('f', IntSort(), IntSort())
1384 >>> # Z3 replaces x with bound variables when ForAll is executed.
1385 >>> q = ForAll(x, f(x) == x)
1386 >>> b = q.body()
1387 >>> b
1388 f(Var(0)) == Var(0)
1389 >>> b.arg(1)
1390 Var(0)
1391 >>> is_var(b.arg(1))
1392 True
1393 """
1394 return is_expr(a) and _ast_kind(a.ctx, a) == Z3_VAR_AST
1395
1396

Referenced by get_var_index().

◆ IsInt()

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

3500def IsInt(a):
3501 """ Return the Z3 predicate IsInt(a).
3502
3503 >>> x = Real('x')
3504 >>> IsInt(x + "1/2")
3505 IsInt(x + 1/2)
3506 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3507 [x = 1/2]
3508 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3509 no solution
3510 """
3511 if z3_debug():
3512 _z3_assert(a.is_real(), "Z3 real expression expected.")
3513 ctx = a.ctx
3514 return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
3515
3516
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.

◆ IsMember()

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

Definition at line 5136 of file z3py.py.

5136def IsMember(e, s):
5137 """ Check if e is a member of set s
5138 >>> a = Const('a', SetSort(IntSort()))
5139 >>> IsMember(1, a)
5140 a[1]
5141 """
5142 ctx = _ctx_from_ast_arg_list([s, e])
5143 e = _py2expr(e, ctx)
5144 return BoolRef(Z3_mk_set_member(ctx.ref(), e.as_ast(), s.as_ast()), ctx)
5145
5146
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.

◆ IsSubset()

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

Definition at line 5147 of file z3py.py.

5147def IsSubset(a, b):
5148 """ Check if a is a subset of b
5149 >>> a = Const('a', SetSort(IntSort()))
5150 >>> b = Const('b', SetSort(IntSort()))
5151 >>> IsSubset(a, b)
5152 subset(a, b)
5153 """
5154 ctx = _ctx_from_ast_arg_list([a, b])
5155 return BoolRef(Z3_mk_set_subset(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5156
5157
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.

◆ K()

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

4980def K(dom, v):
4981 """Return a Z3 constant array expression.
4982
4983 >>> a = K(IntSort(), 10)
4984 >>> a
4985 K(Int, 10)
4986 >>> a.sort()
4987 Array(Int, Int)
4988 >>> i = Int('i')
4989 >>> a[i]
4990 K(Int, 10)[i]
4991 >>> simplify(a[i])
4992 10
4993 """
4994 if z3_debug():
4995 _z3_assert(is_sort(dom), "Z3 sort expected")
4996 ctx = dom.ctx
4997 if not is_expr(v):
4998 v = _py2expr(v, ctx)
4999 return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
5000
5001
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.

Referenced by ModelRef.get_interp().

◆ Lambda()

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

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

Definition at line 2363 of file z3py.py.

2363def Lambda(vs, body):
2364 """Create a Z3 lambda expression.
2365
2366 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2367 >>> mem0 = Array('mem0', IntSort(), IntSort())
2368 >>> lo, hi, e, i = Ints('lo hi e i')
2369 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2370 >>> mem1
2371 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2372 """
2373 ctx = body.ctx
2374 if is_app(vs):
2375 vs = [vs]
2376 num_vars = len(vs)
2377 _vs = (Ast * num_vars)()
2378 for i in range(num_vars):
2379 # TODO: Check if is constant
2380 _vs[i] = vs[i].as_ast()
2381 return QuantifierRef(Z3_mk_lambda_const(ctx.ref(), num_vars, _vs, body.as_ast()), ctx)
2382
Z3_ast Z3_API Z3_mk_lambda_const(Z3_context c, unsigned num_bound, Z3_app const bound[], Z3_ast body)
Create a lambda expression using a list of constants that form the set of bound variables.

◆ LastIndexOf()

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

Definition at line 11397 of file z3py.py.

11397def LastIndexOf(s, substr):
11398 """Retrieve the last index of substring within a string"""
11399 ctx = None
11400 ctx = _get_ctx2(s, substr, ctx)
11401 s = _coerce_seq(s, ctx)
11402 substr = _coerce_seq(substr, ctx)
11403 return ArithRef(Z3_mk_seq_last_index(s.ctx_ref(), s.as_ast(), substr.as_ast()), s.ctx)
11404
11405
Z3_ast Z3_API Z3_mk_seq_last_index(Z3_context c, Z3_ast s, Z3_ast substr)
Return index of the last occurrence of substr in s. If s does not contain substr, then the value is -...

◆ Length()

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

Definition at line 11406 of file z3py.py.

11406def Length(s):
11407 """Obtain the length of a sequence 's'
11408 >>> l = Length(StringVal("abc"))
11409 >>> simplify(l)
11410 3
11411 """
11412 s = _coerce_seq(s)
11413 return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
11414
Z3_ast Z3_API Z3_mk_seq_length(Z3_context c, Z3_ast s)
Return the length of the sequence s.

◆ LinearOrder()

LinearOrder (   a,
  index 
)

Definition at line 11668 of file z3py.py.

11668def LinearOrder(a, index):
11669 return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11670
11671
Z3_func_decl Z3_API Z3_mk_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a linear ordering relation over signature a. The relation is identified by the index id.

◆ Loop()

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

Definition at line 11618 of file z3py.py.

11618def Loop(re, lo, hi=0):
11619 """Create the regular expression accepting between a lower and upper bound repetitions
11620 >>> re = Loop(Re("a"), 1, 3)
11621 >>> print(simplify(InRe("aa", re)))
11622 True
11623 >>> print(simplify(InRe("aaaa", re)))
11624 False
11625 >>> print(simplify(InRe("", re)))
11626 False
11627 """
11628 if z3_debug():
11629 _z3_assert(is_expr(re), "expression expected")
11630 return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
11631
11632
Z3_ast Z3_API Z3_mk_re_loop(Z3_context c, Z3_ast r, unsigned lo, unsigned hi)
Create a regular expression loop. The supplied regular expression r is repeated between lo and hi tim...

◆ LShR()

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

4433def LShR(a, b):
4434 """Create the Z3 expression logical right shift.
4435
4436 Use the operator >> for the arithmetical right shift.
4437
4438 >>> x, y = BitVecs('x y', 32)
4439 >>> LShR(x, y)
4440 LShR(x, y)
4441 >>> (x >> y).sexpr()
4442 '(bvashr x y)'
4443 >>> LShR(x, y).sexpr()
4444 '(bvlshr x y)'
4445 >>> BitVecVal(4, 3)
4446 4
4447 >>> BitVecVal(4, 3).as_signed_long()
4448 -4
4449 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4450 -2
4451 >>> simplify(BitVecVal(4, 3) >> 1)
4452 6
4453 >>> simplify(LShR(BitVecVal(4, 3), 1))
4454 2
4455 >>> simplify(BitVecVal(2, 3) >> 1)
4456 1
4457 >>> simplify(LShR(BitVecVal(2, 3), 1))
4458 1
4459 """
4460 _check_bv_args(a, b)
4461 a, b = _coerce_exprs(a, b)
4462 return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4463
4464
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.

◆ main_ctx()

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

249def main_ctx() -> Context:
250 """Return a reference to the global Z3 context.
251
252 >>> x = Real('x')
253 >>> x.ctx == main_ctx()
254 True
255 >>> c = Context()
256 >>> c == main_ctx()
257 False
258 >>> x2 = Real('x', c)
259 >>> x2.ctx == c
260 True
261 >>> eq(x, x2)
262 False
263 """
264 global _main_ctx
265 if _main_ctx is None:
266 _main_ctx = Context()
267 return _main_ctx
268
269

Referenced by _get_ctx().

◆ Map()

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

4957def Map(f, *args):
4958 """Return a Z3 map array expression.
4959
4960 >>> f = Function('f', IntSort(), IntSort(), IntSort())
4961 >>> a1 = Array('a1', IntSort(), IntSort())
4962 >>> a2 = Array('a2', IntSort(), IntSort())
4963 >>> b = Map(f, a1, a2)
4964 >>> b
4965 Map(f, a1, a2)
4966 >>> prove(b[0] == f(a1[0], a2[0]))
4967 proved
4968 """
4969 args = _get_args(args)
4970 if z3_debug():
4971 _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
4972 _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
4973 _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
4974 _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
4975 _args, sz = _to_ast_array(args)
4976 ctx = f.ctx
4977 return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
4978
4979
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.

◆ mk_not()

mk_not (   a)

Definition at line 1926 of file z3py.py.

1926def mk_not(a):
1927 if is_not(a):
1928 return a.arg(0)
1929 else:
1930 return Not(a)
1931
1932

◆ Model()

Model (   ctx = None,
  eval = {} 
)

Definition at line 6860 of file z3py.py.

6860def Model(ctx=None, eval = {}):
6861 ctx = _get_ctx(ctx)
6862 mdl = ModelRef(Z3_mk_model(ctx.ref()), ctx)
6863 for k, v in eval.items():
6864 mdl.update_value(k, v)
6865 return mdl
6866
6867
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.

◆ MultiPattern()

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

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

Definition at line 2043 of file z3py.py.

2043def MultiPattern(*args):
2044 """Create a Z3 multi-pattern using the given expressions `*args`
2045
2046 >>> f = Function('f', IntSort(), IntSort())
2047 >>> g = Function('g', IntSort(), IntSort())
2048 >>> x = Int('x')
2049 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
2050 >>> q
2051 ForAll(x, f(x) != g(x))
2052 >>> q.num_patterns()
2053 1
2054 >>> is_pattern(q.pattern(0))
2055 True
2056 >>> q.pattern(0)
2057 MultiPattern(f(Var(0)), g(Var(0)))
2058 """
2059 if z3_debug():
2060 _z3_assert(len(args) > 0, "At least one argument expected")
2061 _z3_assert(all([is_expr(a) for a in args]), "Z3 expressions expected")
2062 ctx = args[0].ctx
2063 args, sz = _to_ast_array(args)
2064 return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
2065
2066
Z3_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[])
Create a pattern for quantifier instantiation.

Referenced by _to_pattern().

◆ Not()

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

1907def Not(a, ctx=None):
1908 """Create a Z3 not expression or probe.
1909
1910 >>> p = Bool('p')
1911 >>> Not(Not(p))
1912 Not(Not(p))
1913 >>> simplify(Not(Not(p)))
1914 p
1915 """
1916 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1917 if is_probe(a):
1918 # Not is also used to build probes
1919 return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1920 else:
1921 s = BoolSort(ctx)
1922 a = s.cast(a)
1923 return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1924
1925
Z3_probe Z3_API Z3_probe_not(Z3_context x, Z3_probe p)
Return a probe that evaluates to "true" when p does not evaluate to true.
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).

Referenced by BoolRef.__invert__(), and mk_not().

◆ on_clause_eh()

on_clause_eh (   ctx,
  p,
  n,
  dep,
  clause 
)

Definition at line 11708 of file z3py.py.

11708def on_clause_eh(ctx, p, n, dep, clause):
11709 onc = _my_hacky_class
11710 p = _to_expr_ref(to_Ast(p), onc.ctx)
11711 clause = AstVector(to_AstVectorObj(clause), onc.ctx)
11712 deps = [dep[i] for i in range(n)]
11713 onc.on_clause(p, deps, clause)
11714

◆ open_log()

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

Definition at line 122 of file z3py.py.

122def open_log(fname):
123 """Log interaction to a file. This function must be invoked immediately after init(). """
124 Z3_open_log(fname)
125
126
bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.

◆ Option()

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

11583def Option(re):
11584 """Create the regular expression that optionally accepts the argument.
11585 >>> re = Option(Re("a"))
11586 >>> print(simplify(InRe("a", re)))
11587 True
11588 >>> print(simplify(InRe("", re)))
11589 True
11590 >>> print(simplify(InRe("aa", re)))
11591 False
11592 """
11593 if z3_debug():
11594 _z3_assert(is_expr(re), "expression expected")
11595 return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
11596
11597
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].

◆ Or()

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

1974def Or(*args):
1975 """Create a Z3 or-expression or or-probe.
1976
1977 >>> p, q, r = Bools('p q r')
1978 >>> Or(p, q, r)
1979 Or(p, q, r)
1980 >>> P = BoolVector('p', 5)
1981 >>> Or(P)
1982 Or(p__0, p__1, p__2, p__3, p__4)
1983 """
1984 last_arg = None
1985 if len(args) > 0:
1986 last_arg = args[len(args) - 1]
1987 if isinstance(last_arg, Context):
1988 ctx = args[len(args) - 1]
1989 args = args[:len(args) - 1]
1990 elif len(args) == 1 and isinstance(args[0], AstVector):
1991 ctx = args[0].ctx
1992 args = [a for a in args[0]]
1993 else:
1994 ctx = None
1995 args = _get_args(args)
1996 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1997 if z3_debug():
1998 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1999 if _has_probe(args):
2000 return _probe_or(args, ctx)
2001 else:
2002 args = _coerce_expr_list(args, ctx)
2003 _args, sz = _to_ast_array(args)
2004 return BoolRef(Z3_mk_or(ctx.ref(), sz, _args), ctx)
2005
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].

Referenced by BoolRef.__or__().

◆ OrElse()

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

8617def OrElse(*ts, **ks):
8618 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8619
8620 >>> x = Int('x')
8621 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
8622 >>> # Tactic split-clause fails if there is no clause in the given goal.
8623 >>> t(x == 0)
8624 [[x == 0]]
8625 >>> t(Or(x == 0, x == 1))
8626 [[x == 0], [x == 1]]
8627 """
8628 if z3_debug():
8629 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8630 ctx = ks.get("ctx", None)
8631 num = len(ts)
8632 r = ts[0]
8633 for i in range(num - 1):
8634 r = _or_else(r, ts[i + 1], ctx)
8635 return r
8636
8637

◆ ParAndThen()

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

Definition at line 8673 of file z3py.py.

8673def ParAndThen(t1, t2, ctx=None):
8674 """Alias for ParThen(t1, t2, ctx)."""
8675 return ParThen(t1, t2, ctx)
8676
8677

◆ ParOr()

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

8638def ParOr(*ts, **ks):
8639 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8640
8641 >>> x = Int('x')
8642 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
8643 >>> t(x + 1 == 2)
8644 [[x == 1]]
8645 """
8646 if z3_debug():
8647 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8648 ctx = _get_ctx(ks.get("ctx", None))
8649 ts = [_to_tactic(t, ctx) for t in ts]
8650 sz = len(ts)
8651 _args = (TacticObj * sz)()
8652 for i in range(sz):
8653 _args[i] = ts[i].tactic
8654 return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
8655
8656
Z3_tactic Z3_API Z3_tactic_par_or(Z3_context c, unsigned num, Z3_tactic const ts[])
Return a tactic that applies the given tactics in parallel.

◆ parse_smt2_file()

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

9553def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
9554 """Parse a file in SMT 2.0 format using the given sorts and decls.
9555
9556 This function is similar to parse_smt2_string().
9557 """
9558 ctx = _get_ctx(ctx)
9559 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9560 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9561 return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9562
9563
Z3_ast_vector Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Similar to Z3_parse_smtlib2_string, but reads the benchmark from a file.

◆ parse_smt2_string()

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

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

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

Definition at line 9532 of file z3py.py.

9532def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
9533 """Parse a string in SMT 2.0 format using the given sorts and decls.
9534
9535 The arguments sorts and decls are Python dictionaries used to initialize
9536 the symbol table used for the SMT 2.0 parser.
9537
9538 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9539 [x > 0, x < 10]
9540 >>> x, y = Ints('x y')
9541 >>> f = Function('f', IntSort(), IntSort())
9542 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
9543 [x + f(y) > 0]
9544 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
9545 [a > 0]
9546 """
9547 ctx = _get_ctx(ctx)
9548 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9549 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9550 return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9551
9552
Z3_ast_vector Z3_API Z3_parse_smtlib2_string(Z3_context c, Z3_string str, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Parse the given string using the SMT-LIB2 parser.

◆ ParThen()

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

8657def ParThen(t1, t2, ctx=None):
8658 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8659 The subgoals are processed in parallel.
8660
8661 >>> x, y = Ints('x y')
8662 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
8663 >>> t(And(Or(x == 1, x == 2), y == x + 1))
8664 [[x == 1, y == 2], [x == 2, y == 3]]
8665 """
8666 t1 = _to_tactic(t1, ctx)
8667 t2 = _to_tactic(t2, ctx)
8668 if z3_debug():
8669 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8670 return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8671
8672
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....

◆ PartialOrder()

PartialOrder (   a,
  index 
)

Definition at line 11664 of file z3py.py.

11664def PartialOrder(a, index):
11665 return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx)
11666
11667
Z3_func_decl Z3_API Z3_mk_partial_order(Z3_context c, Z3_sort a, unsigned id)
create a partial ordering relation over signature a and index id.

◆ PbEq()

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

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

Definition at line 9309 of file z3py.py.

9309def PbEq(args, k, ctx=None):
9310 """Create a Pseudo-Boolean equality k constraint.
9311
9312 >>> a, b, c = Bools('a b c')
9313 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
9314 """
9315 _z3_check_cint_overflow(k, "k")
9316 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9317 return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
9318
9319
Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.

◆ PbGe()

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

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

Definition at line 9298 of file z3py.py.

9298def PbGe(args, k):
9299 """Create a Pseudo-Boolean inequality k constraint.
9300
9301 >>> a, b, c = Bools('a b c')
9302 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
9303 """
9304 _z3_check_cint_overflow(k, "k")
9305 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9306 return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
9307
9308
Z3_ast Z3_API Z3_mk_pbge(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.

◆ PbLe()

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

9287def PbLe(args, k):
9288 """Create a Pseudo-Boolean inequality k constraint.
9289
9290 >>> a, b, c = Bools('a b c')
9291 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
9292 """
9293 _z3_check_cint_overflow(k, "k")
9294 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9295 return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
9296
9297
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.

◆ PiecewiseLinearOrder()

PiecewiseLinearOrder (   a,
  index 
)

Definition at line 11676 of file z3py.py.

11676def PiecewiseLinearOrder(a, index):
11677 return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11678
11679
Z3_func_decl Z3_API Z3_mk_piecewise_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a piecewise linear ordering relation over signature a and index id.

◆ Plus()

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

11568def Plus(re):
11569 """Create the regular expression accepting one or more repetitions of argument.
11570 >>> re = Plus(Re("a"))
11571 >>> print(simplify(InRe("aa", re)))
11572 True
11573 >>> print(simplify(InRe("ab", re)))
11574 False
11575 >>> print(simplify(InRe("", re)))
11576 False
11577 """
11578 if z3_debug():
11579 _z3_assert(is_expr(re), "expression expected")
11580 return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
11581
11582
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.

◆ PrefixOf()

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

11313def PrefixOf(a, b):
11314 """Check if 'a' is a prefix of 'b'
11315 >>> s1 = PrefixOf("ab", "abc")
11316 >>> simplify(s1)
11317 True
11318 >>> s2 = PrefixOf("bc", "abc")
11319 >>> simplify(s2)
11320 False
11321 """
11322 ctx = _get_ctx2(a, b)
11323 a = _coerce_seq(a, ctx)
11324 b = _coerce_seq(b, ctx)
11325 return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11326
11327
Z3_ast Z3_API Z3_mk_seq_prefix(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if prefix is a prefix of s.

◆ probe_description()

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

>>> d = probe_description('memory')

Definition at line 8953 of file z3py.py.

8953def probe_description(name, ctx=None):
8954 """Return a short description for the probe named `name`.
8955
8956 >>> d = probe_description('memory')
8957 """
8958 ctx = _get_ctx(ctx)
8959 return Z3_probe_get_descr(ctx.ref(), name)
8960
8961
Z3_string Z3_API Z3_probe_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the probe with the given name.

◆ probes()

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

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

Definition at line 8942 of file z3py.py.

8942def probes(ctx=None):
8943 """Return a list of all available probes in Z3.
8944
8945 >>> l = probes()
8946 >>> l.count('memory') == 1
8947 True
8948 """
8949 ctx = _get_ctx(ctx)
8950 return [Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref()))]
8951
8952
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.
Z3_string Z3_API Z3_get_probe_name(Z3_context c, unsigned i)
Return the name of the i probe.

◆ Product()

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

9194def Product(*args):
9195 """Create the product of the Z3 expressions.
9196
9197 >>> a, b, c = Ints('a b c')
9198 >>> Product(a, b, c)
9199 a*b*c
9200 >>> Product([a, b, c])
9201 a*b*c
9202 >>> A = IntVector('a', 5)
9203 >>> Product(A)
9204 a__0*a__1*a__2*a__3*a__4
9205 """
9206 args = _get_args(args)
9207 if len(args) == 0:
9208 return 1
9209 ctx = _ctx_from_ast_arg_list(args)
9210 if ctx is None:
9211 return _reduce(lambda a, b: a * b, args, 1)
9212 args = _coerce_expr_list(args, ctx)
9213 if is_bv(args[0]):
9214 return _reduce(lambda a, b: a * b, args, 1)
9215 else:
9216 _args, sz = _to_ast_array(args)
9217 return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
9218
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].

◆ PropagateFunction()

PropagateFunction (   name,
sig 
)
Create a function that gets tracked by user propagator.
   Every term headed by this function symbol is tracked.
   If a term is fixed and the fixed callback is registered a
   callback is invoked that the term headed by this function is fixed.

Definition at line 11873 of file z3py.py.

11873def PropagateFunction(name, *sig):
11874 """Create a function that gets tracked by user propagator.
11875 Every term headed by this function symbol is tracked.
11876 If a term is fixed and the fixed callback is registered a
11877 callback is invoked that the term headed by this function is fixed.
11878 """
11879 sig = _get_args(sig)
11880 if z3_debug():
11881 _z3_assert(len(sig) > 0, "At least two arguments expected")
11882 arity = len(sig) - 1
11883 rng = sig[arity]
11884 if z3_debug():
11885 _z3_assert(is_sort(rng), "Z3 sort expected")
11886 dom = (Sort * arity)()
11887 for i in range(arity):
11888 if z3_debug():
11889 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
11890 dom[i] = sig[i].ast
11891 ctx = rng.ctx
11892 return FuncDeclRef(Z3_solver_propagate_declare(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
11893
11894
11895
Z3_func_decl Z3_API Z3_solver_propagate_declare(Z3_context c, Z3_symbol name, unsigned n, Z3_sort *domain, Z3_sort range)

◆ prove()

prove (   claim,
  show = False,
**  keywords 
)
Try to prove the given claim.

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

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

Definition at line 9381 of file z3py.py.

9381def prove(claim, show=False, **keywords):
9382 """Try to prove the given claim.
9383
9384 This is a simple function for creating demonstrations. It tries to prove
9385 `claim` by showing the negation is unsatisfiable.
9386
9387 >>> p, q = Bools('p q')
9388 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
9389 proved
9390 """
9391 if z3_debug():
9392 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9393 s = Solver()
9394 s.set(**keywords)
9395 s.add(Not(claim))
9396 if show:
9397 print(s)
9398 r = s.check()
9399 if r == unsat:
9400 print("proved")
9401 elif r == unknown:
9402 print("failed to prove")
9403 print(s.model())
9404 else:
9405 print("counterexample")
9406 print(s.model())
9407
9408

◆ Q()

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

3339def Q(a, b, ctx=None):
3340 """Return a Z3 rational a/b.
3341
3342 If `ctx=None`, then the global context is used.
3343
3344 >>> Q(3,5)
3345 3/5
3346 >>> Q(3,5).sort()
3347 Real
3348 """
3349 return simplify(RatVal(a, b, ctx=ctx))
3350
3351

◆ Range()

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

Definition at line 11633 of file z3py.py.

11633def Range(lo, hi, ctx=None):
11634 """Create the range regular expression over two sequences of length 1
11635 >>> range = Range("a","z")
11636 >>> print(simplify(InRe("b", range)))
11637 True
11638 >>> print(simplify(InRe("bb", range)))
11639 False
11640 """
11641 lo = _coerce_seq(lo, ctx)
11642 hi = _coerce_seq(hi, ctx)
11643 if z3_debug():
11644 _z3_assert(is_expr(lo), "expression expected")
11645 _z3_assert(is_expr(hi), "expression expected")
11646 return ReRef(Z3_mk_re_range(lo.ctx_ref(), lo.ast, hi.ast), lo.ctx)
11647
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.

◆ RatVal()

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

3323def RatVal(a, b, ctx=None):
3324 """Return a Z3 rational a/b.
3325
3326 If `ctx=None`, then the global context is used.
3327
3328 >>> RatVal(3,5)
3329 3/5
3330 >>> RatVal(3,5).sort()
3331 Real
3332 """
3333 if z3_debug():
3334 _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
3335 _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
3336 return simplify(RealVal(a, ctx) / RealVal(b, ctx))
3337
3338

Referenced by Q().

◆ Re()

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

11477def Re(s, ctx=None):
11478 """The regular expression that accepts sequence 's'
11479 >>> s1 = Re("ab")
11480 >>> s2 = Re(StringVal("ab"))
11481 >>> s3 = Re(Unit(BoolVal(True)))
11482 """
11483 s = _coerce_seq(s, ctx)
11484 return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
11485
11486
11487# Regular expressions
11488
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.

◆ Real()

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

3405def Real(name, ctx=None):
3406 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3407
3408 >>> x = Real('x')
3409 >>> is_real(x)
3410 True
3411 >>> is_real(x + 1)
3412 True
3413 """
3414 ctx = _get_ctx(ctx)
3415 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
3416
3417

Referenced by Reals(), and RealVector().

◆ Reals()

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

3418def Reals(names, ctx=None):
3419 """Return a tuple of real constants.
3420
3421 >>> x, y, z = Reals('x y z')
3422 >>> Sum(x, y, z)
3423 x + y + z
3424 >>> Sum(x, y, z).sort()
3425 Real
3426 """
3427 ctx = _get_ctx(ctx)
3428 if isinstance(names, str):
3429 names = names.split(" ")
3430 return [Real(name, ctx) for name in names]
3431
3432

◆ RealSort()

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

3263def RealSort(ctx=None):
3264 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3265
3266 >>> RealSort()
3267 Real
3268 >>> x = Const('x', RealSort())
3269 >>> is_real(x)
3270 True
3271 >>> is_int(x)
3272 False
3273 >>> x.sort() == RealSort()
3274 True
3275 """
3276 ctx = _get_ctx(ctx)
3277 return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
3278
3279
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.

Referenced by FreshReal(), Real(), RealVal(), and RealVar().

◆ RealVal()

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

3304def RealVal(val, ctx=None):
3305 """Return a Z3 real value.
3306
3307 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3308 If `ctx=None`, then the global context is used.
3309
3310 >>> RealVal(1)
3311 1
3312 >>> RealVal(1).sort()
3313 Real
3314 >>> RealVal("3/5")
3315 3/5
3316 >>> RealVal("1.5")
3317 3/2
3318 """
3319 ctx = _get_ctx(ctx)
3320 return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), RealSort(ctx).ast), ctx)
3321
3322

Referenced by _coerce_exprs(), _py2expr(), Cbrt(), RatVal(), Sqrt(), and ToReal().

◆ RealVar()

ExprRef RealVar ( int  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 1549 of file z3py.py.

1549def RealVar(idx: int, ctx=None) -> ExprRef:
1550 """
1551 Create a real free variable. Free variables are used to create quantified formulas.
1552 They are also used to create polynomials.
1553
1554 >>> RealVar(0)
1555 Var(0)
1556 """
1557 return Var(idx, RealSort(ctx))
1558

Referenced by RealVarVector().

◆ RealVarVector()

RealVarVector ( int  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 1559 of file z3py.py.

1559def RealVarVector(n: int, ctx= None):
1560 """
1561 Create a list of Real free variables.
1562 The variables have ids: 0, 1, ..., n-1
1563
1564 >>> x0, x1, x2, x3 = RealVarVector(4)
1565 >>> x2
1566 Var(2)
1567 """
1568 return [RealVar(i, ctx) for i in range(n)]
1569

◆ RealVector()

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

3433def RealVector(prefix, sz, ctx=None):
3434 """Return a list of real constants of size `sz`.
3435
3436 >>> X = RealVector('x', 3)
3437 >>> X
3438 [x__0, x__1, x__2]
3439 >>> Sum(X)
3440 x__0 + x__1 + x__2
3441 >>> Sum(X).sort()
3442 Real
3443 """
3444 ctx = _get_ctx(ctx)
3445 return [Real("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3446
3447

◆ RecAddDefinition()

RecAddDefinition (   f,
  args,
  body 
)
Set the body of a recursive function.
   Recursive definitions can be simplified if they are applied to ground
   arguments.
>>> ctx = Context()
>>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
>>> n = Int('n', ctx)
>>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
>>> simplify(fac(5))
120
>>> s = Solver(ctx=ctx)
>>> s.add(fac(n) < 3)
>>> s.check()
sat
>>> s.model().eval(fac(5))
120

Definition at line 967 of file z3py.py.

967def RecAddDefinition(f, args, body):
968 """Set the body of a recursive function.
969 Recursive definitions can be simplified if they are applied to ground
970 arguments.
971 >>> ctx = Context()
972 >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
973 >>> n = Int('n', ctx)
974 >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
975 >>> simplify(fac(5))
976 120
977 >>> s = Solver(ctx=ctx)
978 >>> s.add(fac(n) < 3)
979 >>> s.check()
980 sat
981 >>> s.model().eval(fac(5))
982 120
983 """
984 if is_app(args):
985 args = [args]
986 ctx = body.ctx
987 args = _get_args(args)
988 n = len(args)
989 _args = (Ast * n)()
990 for i in range(n):
991 _args[i] = args[i].ast
992 Z3_add_rec_def(ctx.ref(), f.ast, n, _args, body.ast)
993
void Z3_API Z3_add_rec_def(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast args[], Z3_ast body)
Define the body of a recursive function.

◆ RecFunction()

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

Definition at line 949 of file z3py.py.

949def RecFunction(name, *sig):
950 """Create a new Z3 recursive with the given sorts."""
951 sig = _get_args(sig)
952 if z3_debug():
953 _z3_assert(len(sig) > 0, "At least two arguments expected")
954 arity = len(sig) - 1
955 rng = sig[arity]
956 if z3_debug():
957 _z3_assert(is_sort(rng), "Z3 sort expected")
958 dom = (Sort * arity)()
959 for i in range(arity):
960 if z3_debug():
961 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
962 dom[i] = sig[i].ast
963 ctx = rng.ctx
964 return FuncDeclRef(Z3_mk_rec_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
965
966
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a recursive function.

◆ Repeat()

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

8706def Repeat(t, max=4294967295, ctx=None):
8707 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8708 or the maximum number of iterations `max` is reached.
8709
8710 >>> x, y = Ints('x y')
8711 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
8712 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
8713 >>> r = t(c)
8714 >>> for subgoal in r: print(subgoal)
8715 [x == 0, y == 0, x > y]
8716 [x == 0, y == 1, x > y]
8717 [x == 1, y == 0, x > y]
8718 [x == 1, y == 1, x > y]
8719 >>> t = Then(t, Tactic('propagate-values'))
8720 >>> t(c)
8721 [[x == 1, y == 0]]
8722 """
8723 t = _to_tactic(t, ctx)
8724 return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
8725
8726
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...

◆ RepeatBitVec()

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

4555def RepeatBitVec(n, a):
4556 """Return an expression representing `n` copies of `a`.
4557
4558 >>> x = BitVec('x', 8)
4559 >>> n = RepeatBitVec(4, x)
4560 >>> n
4561 RepeatBitVec(4, x)
4562 >>> n.size()
4563 32
4564 >>> v0 = BitVecVal(10, 4)
4565 >>> print("%.x" % v0.as_long())
4566 a
4567 >>> v = simplify(RepeatBitVec(4, v0))
4568 >>> v.size()
4569 16
4570 >>> print("%.x" % v.as_long())
4571 aaaa
4572 """
4573 if z3_debug():
4574 _z3_assert(_is_int(n), "First argument must be an integer")
4575 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4576 return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
4577
4578
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.

◆ Replace()

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

11362def Replace(s, src, dst):
11363 """Replace the first occurrence of 'src' by 'dst' in 's'
11364 >>> r = Replace("aaa", "a", "b")
11365 >>> simplify(r)
11366 "baa"
11367 """
11368 ctx = _get_ctx2(dst, s)
11369 if ctx is None and is_expr(src):
11370 ctx = src.ctx
11371 src = _coerce_seq(src, ctx)
11372 dst = _coerce_seq(dst, ctx)
11373 s = _coerce_seq(s, ctx)
11374 return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
11375
11376
Z3_ast Z3_API Z3_mk_seq_replace(Z3_context c, Z3_ast s, Z3_ast src, Z3_ast dst)
Replace the first occurrence of src with dst in s.

◆ reset_params()

None reset_params ( )
Reset all global (or module) parameters.

Definition at line 305 of file z3py.py.

305def reset_params() -> None:
306 """Reset all global (or module) parameters.
307 """
309
310
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()

ReSort (   s)

Definition at line 11496 of file z3py.py.

11496def ReSort(s):
11497 if is_ast(s):
11498 return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
11499 if s is None or isinstance(s, Context):
11500 ctx = _get_ctx(s)
11501 return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
11502 raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
11503
11504
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort seq)
Create a regular expression sort out of a sequence sort.
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for unicode strings.

◆ RNA()

RNA (   ctx = None)

Definition at line 9968 of file z3py.py.

9968def RNA(ctx=None):
9969 ctx = _get_ctx(ctx)
9970 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
9971
9972
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()

RNE (   ctx = None)

Definition at line 9958 of file z3py.py.

9958def RNE(ctx=None):
9959 ctx = _get_ctx(ctx)
9960 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
9961
9962
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.

◆ RotateLeft()

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

4465def RotateLeft(a, b):
4466 """Return an expression representing `a` rotated to the left `b` times.
4467
4468 >>> a, b = BitVecs('a b', 16)
4469 >>> RotateLeft(a, b)
4470 RotateLeft(a, b)
4471 >>> simplify(RotateLeft(a, 0))
4472 a
4473 >>> simplify(RotateLeft(a, 16))
4474 a
4475 """
4476 _check_bv_args(a, b)
4477 a, b = _coerce_exprs(a, b)
4478 return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4479
4480
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()

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

4481def RotateRight(a, b):
4482 """Return an expression representing `a` rotated to the right `b` times.
4483
4484 >>> a, b = BitVecs('a b', 16)
4485 >>> RotateRight(a, b)
4486 RotateRight(a, b)
4487 >>> simplify(RotateRight(a, 0))
4488 a
4489 >>> simplify(RotateRight(a, 16))
4490 a
4491 """
4492 _check_bv_args(a, b)
4493 a, b = _coerce_exprs(a, b)
4494 return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4495
4496
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.

◆ RoundNearestTiesToAway()

RoundNearestTiesToAway (   ctx = None)

Definition at line 9963 of file z3py.py.

9963def RoundNearestTiesToAway(ctx=None):
9964 ctx = _get_ctx(ctx)
9965 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
9966
9967

◆ RoundNearestTiesToEven()

RoundNearestTiesToEven (   ctx = None)

Definition at line 9953 of file z3py.py.

9953def RoundNearestTiesToEven(ctx=None):
9954 ctx = _get_ctx(ctx)
9955 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
9956
9957

◆ RoundTowardNegative()

RoundTowardNegative (   ctx = None)

Definition at line 9983 of file z3py.py.

9983def RoundTowardNegative(ctx=None):
9984 ctx = _get_ctx(ctx)
9985 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
9986
9987
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()

RoundTowardPositive (   ctx = None)

Definition at line 9973 of file z3py.py.

9973def RoundTowardPositive(ctx=None):
9974 ctx = _get_ctx(ctx)
9975 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
9976
9977
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()

RoundTowardZero (   ctx = None)

Definition at line 9993 of file z3py.py.

9993def RoundTowardZero(ctx=None):
9994 ctx = _get_ctx(ctx)
9995 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
9996
9997
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.

◆ RTN()

RTN (   ctx = None)

Definition at line 9988 of file z3py.py.

9988def RTN(ctx=None):
9989 ctx = _get_ctx(ctx)
9990 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
9991
9992

◆ RTP()

RTP (   ctx = None)

Definition at line 9978 of file z3py.py.

9978def RTP(ctx=None):
9979 ctx = _get_ctx(ctx)
9980 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
9981
9982

◆ RTZ()

RTZ (   ctx = None)

Definition at line 9998 of file z3py.py.

9998def RTZ(ctx=None):
9999 ctx = _get_ctx(ctx)
10000 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10001
10002

◆ Select()

Select (   a,
args 
)
Return a Z3 select array expression.

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

Definition at line 4941 of file z3py.py.

4941def Select(a, *args):
4942 """Return a Z3 select array expression.
4943
4944 >>> a = Array('a', IntSort(), IntSort())
4945 >>> i = Int('i')
4946 >>> Select(a, i)
4947 a[i]
4948 >>> eq(Select(a, i), a[i])
4949 True
4950 """
4951 args = _get_args(args)
4952 if z3_debug():
4953 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4954 return a[args]
4955
4956

◆ SeqFoldLeft()

SeqFoldLeft (   f,
  a,
  s 
)

Definition at line 11429 of file z3py.py.

11429def SeqFoldLeft(f, a, s):
11430 ctx = _get_ctx2(f, s)
11431 s = _coerce_seq(s, ctx)
11432 a = _py2expr(a)
11433 return _to_expr_ref(Z3_mk_seq_foldl(s.ctx_ref(), f.as_ast(), a.as_ast(), s.as_ast()), ctx)
11434
Z3_ast Z3_API Z3_mk_seq_foldl(Z3_context c, Z3_ast f, Z3_ast a, Z3_ast s)
Create a fold of the function f over the sequence s with accumulator a.

◆ SeqFoldLeftI()

SeqFoldLeftI (   f,
  i,
  a,
  s 
)

Definition at line 11435 of file z3py.py.

11435def SeqFoldLeftI(f, i, a, s):
11436 ctx = _get_ctx2(f, s)
11437 s = _coerce_seq(s, ctx)
11438 a = _py2expr(a)
11439 i = _py2expr(i)
11440 return _to_expr_ref(Z3_mk_seq_foldli(s.ctx_ref(), f.as_ast(), i.as_ast(), a.as_ast(), s.as_ast()), ctx)
11441
Z3_ast Z3_API Z3_mk_seq_foldli(Z3_context c, Z3_ast f, Z3_ast i, Z3_ast a, Z3_ast s)
Create a fold with index tracking of the function f over the sequence s with accumulator a starting a...

◆ SeqMap()

SeqMap (   f,
  s 
)
Map function 'f' over sequence 's'

Definition at line 11415 of file z3py.py.

11415def SeqMap(f, s):
11416 """Map function 'f' over sequence 's'"""
11417 ctx = _get_ctx2(f, s)
11418 s = _coerce_seq(s, ctx)
11419 return _to_expr_ref(Z3_mk_seq_map(s.ctx_ref(), f.as_ast(), s.as_ast()), ctx)
11420
Z3_ast Z3_API Z3_mk_seq_map(Z3_context c, Z3_ast f, Z3_ast s)
Create a map of the function f over the sequence s.

◆ SeqMapI()

SeqMapI (   f,
  i,
  s 
)
Map function 'f' over sequence 's' at index 'i'

Definition at line 11421 of file z3py.py.

11421def SeqMapI(f, i, s):
11422 """Map function 'f' over sequence 's' at index 'i'"""
11423 ctx = _get_ctx2(f, s)
11424 s = _coerce_seq(s, ctx)
11425 if not is_expr(i):
11426 i = _py2expr(i)
11427 return _to_expr_ref(Z3_mk_seq_mapi(s.ctx_ref(), f.as_ast(), i.as_ast(), s.as_ast()), ctx)
11428
Z3_ast Z3_API Z3_mk_seq_mapi(Z3_context c, Z3_ast f, Z3_ast i, Z3_ast s)
Create a map of the function f over the sequence s starting at index i.

◆ SeqSort()

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

Definition at line 11062 of file z3py.py.

11062def SeqSort(s):
11063 """Create a sequence sort over elements provided in the argument
11064 >>> s = SeqSort(IntSort())
11065 >>> s == Unit(IntVal(1)).sort()
11066 True
11067 """
11068 return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
11069
11070
Z3_sort Z3_API Z3_mk_seq_sort(Z3_context c, Z3_sort s)
Create a sequence sort out of the sort for the elements.

◆ set_default_fp_sort()

set_default_fp_sort (   ebits,
  sbits,
  ctx = None 
)

Definition at line 9614 of file z3py.py.

9614def set_default_fp_sort(ebits, sbits, ctx=None):
9615 global _dflt_fpsort_ebits
9616 global _dflt_fpsort_sbits
9617 _dflt_fpsort_ebits = ebits
9618 _dflt_fpsort_sbits = sbits
9619
9620

◆ set_default_rounding_mode()

set_default_rounding_mode (   rm,
  ctx = None 
)

Definition at line 9601 of file z3py.py.

9601def set_default_rounding_mode(rm, ctx=None):
9602 global _dflt_rounding_mode
9603 if is_fprm_value(rm):
9604 _dflt_rounding_mode = rm.kind()
9605 else:
9606 _z3_assert(_dflt_rounding_mode in _ROUNDING_MODES, "illegal rounding mode")
9607 _dflt_rounding_mode = rm
9608
9609

◆ set_option()

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

Definition at line 311 of file z3py.py.

311def set_option(*args, **kws):
312 """Alias for 'set_param' for backward compatibility.
313 """
314 return set_param(*args, **kws)
315
316

◆ set_param()

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

>>> set_param(precision=10)

Definition at line 281 of file z3py.py.

281def set_param(*args, **kws):
282 """Set Z3 global (or module) parameters.
283
284 >>> set_param(precision=10)
285 """
286 if z3_debug():
287 _z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
288 new_kws = {}
289 for k in kws:
290 v = kws[k]
291 if not set_pp_option(k, v):
292 new_kws[k] = v
293 for key in new_kws:
294 value = new_kws[key]
295 Z3_global_param_set(str(key).upper(), _to_param_value(value))
296 prev = None
297 for a in args:
298 if prev is None:
299 prev = a
300 else:
301 Z3_global_param_set(str(prev), _to_param_value(a))
302 prev = None
303
304
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value)
Set a global (or module) parameter. This setting is shared by all Z3 contexts.

Referenced by set_option().

◆ SetAdd()

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

Definition at line 5093 of file z3py.py.

5093def SetAdd(s, e):
5094 """ Add element e to set s
5095 >>> a = Const('a', SetSort(IntSort()))
5096 >>> SetAdd(a, 1)
5097 Store(a, 1, True)
5098 """
5099 ctx = _ctx_from_ast_arg_list([s, e])
5100 e = _py2expr(e, ctx)
5101 return ArrayRef(Z3_mk_set_add(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5102
5103
Z3_ast Z3_API Z3_mk_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.

◆ SetComplement()

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

Definition at line 5115 of file z3py.py.

5115def SetComplement(s):
5116 """ The complement of set s
5117 >>> a = Const('a', SetSort(IntSort()))
5118 >>> SetComplement(a)
5119 complement(a)
5120 """
5121 ctx = s.ctx
5122 return ArrayRef(Z3_mk_set_complement(ctx.ref(), s.as_ast()), ctx)
5123
5124
Z3_ast Z3_API Z3_mk_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.

◆ SetDel()

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

Definition at line 5104 of file z3py.py.

5104def SetDel(s, e):
5105 """ Remove element e to set s
5106 >>> a = Const('a', SetSort(IntSort()))
5107 >>> SetDel(a, 1)
5108 Store(a, 1, False)
5109 """
5110 ctx = _ctx_from_ast_arg_list([s, e])
5111 e = _py2expr(e, ctx)
5112 return ArrayRef(Z3_mk_set_del(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5113
5114
Z3_ast Z3_API Z3_mk_set_del(Z3_context c, Z3_ast set, Z3_ast elem)
Remove an element to a set.

◆ SetDifference()

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

Definition at line 5125 of file z3py.py.

5125def SetDifference(a, b):
5126 """ The set difference of a and b
5127 >>> a = Const('a', SetSort(IntSort()))
5128 >>> b = Const('b', SetSort(IntSort()))
5129 >>> SetDifference(a, b)
5130 setminus(a, b)
5131 """
5132 ctx = _ctx_from_ast_arg_list([a, b])
5133 return ArrayRef(Z3_mk_set_difference(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5134
5135
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.

◆ SetIntersect()

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

Definition at line 5080 of file z3py.py.

5080def SetIntersect(*args):
5081 """ Take the union of sets
5082 >>> a = Const('a', SetSort(IntSort()))
5083 >>> b = Const('b', SetSort(IntSort()))
5084 >>> SetIntersect(a, b)
5085 intersection(a, b)
5086 """
5087 args = _get_args(args)
5088 ctx = _ctx_from_ast_arg_list(args)
5089 _args, sz = _to_ast_array(args)
5090 return ArrayRef(Z3_mk_set_intersect(ctx.ref(), sz, _args), ctx)
5091
5092
Z3_ast Z3_API Z3_mk_set_intersect(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the intersection of a list of sets.

◆ SetSort()

SetSort (   s)

Sets.

 Create a set sort over element sort s

Definition at line 5044 of file z3py.py.

5044def SetSort(s):
5045 """ Create a set sort over element sort s"""
5046 return ArraySort(s, BoolSort())
5047
5048

◆ SetUnion()

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

Definition at line 5067 of file z3py.py.

5067def SetUnion(*args):
5068 """ Take the union of sets
5069 >>> a = Const('a', SetSort(IntSort()))
5070 >>> b = Const('b', SetSort(IntSort()))
5071 >>> SetUnion(a, b)
5072 union(a, b)
5073 """
5074 args = _get_args(args)
5075 ctx = _ctx_from_ast_arg_list(args)
5076 _args, sz = _to_ast_array(args)
5077 return ArrayRef(Z3_mk_set_union(ctx.ref(), sz, _args), ctx)
5078
5079
Z3_ast Z3_API Z3_mk_set_union(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the union of a list of sets.

◆ SignExt()

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

4497def SignExt(n, a):
4498 """Return a bit-vector expression with `n` extra sign-bits.
4499
4500 >>> x = BitVec('x', 16)
4501 >>> n = SignExt(8, x)
4502 >>> n.size()
4503 24
4504 >>> n
4505 SignExt(8, x)
4506 >>> n.sort()
4507 BitVec(24)
4508 >>> v0 = BitVecVal(2, 2)
4509 >>> v0
4510 2
4511 >>> v0.size()
4512 2
4513 >>> v = simplify(SignExt(6, v0))
4514 >>> v
4515 254
4516 >>> v.size()
4517 8
4518 >>> print("%.x" % v.as_long())
4519 fe
4520 """
4521 if z3_debug():
4522 _z3_assert(_is_int(n), "First argument must be an integer")
4523 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4524 return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4525
4526
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,...

◆ SimpleSolver()

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

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

Definition at line 7633 of file z3py.py.

7633def SimpleSolver(ctx=None, logFile=None):
7634 """Return a simple general purpose solver with limited amount of preprocessing.
7635
7636 >>> s = SimpleSolver()
7637 >>> x = Int('x')
7638 >>> s.add(x > 0)
7639 >>> s.check()
7640 sat
7641 """
7642 ctx = _get_ctx(ctx)
7643 return Solver(Z3_mk_simple_solver(ctx.ref()), ctx, logFile)
7644
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.

◆ simplify()

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

9058def simplify(a, *arguments, **keywords):
9059 """Simplify the expression `a` using the given options.
9060
9061 This function has many options. Use `help_simplify` to obtain the complete list.
9062
9063 >>> x = Int('x')
9064 >>> y = Int('y')
9065 >>> simplify(x + 1 + y + x + 1)
9066 2 + 2*x + y
9067 >>> simplify((x + 1)*(y + 1), som=True)
9068 1 + x + y + x*y
9069 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
9070 And(Not(x == y), Not(x == 1), Not(y == 1))
9071 >>> simplify(And(x == 0, y == 1), elim_and=True)
9072 Not(Or(Not(x == 0), Not(y == 1)))
9073 """
9074 if z3_debug():
9075 _z3_assert(is_expr(a), "Z3 expression expected")
9076 if len(arguments) > 0 or len(keywords) > 0:
9077 p = args2params(arguments, keywords, a.ctx)
9078 return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
9079 else:
9080 return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
9081
9082
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.

Referenced by Q(), and RatVal().

◆ simplify_param_descrs()

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

Definition at line 9088 of file z3py.py.

9088def simplify_param_descrs():
9089 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
9090 return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
9091
9092
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.

◆ solve()

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

9320def solve(*args, **keywords):
9321 """Solve the constraints `*args`.
9322
9323 This is a simple function for creating demonstrations. It creates a solver,
9324 configure it using the options in `keywords`, adds the constraints
9325 in `args`, and invokes check.
9326
9327 >>> a = Int('a')
9328 >>> solve(a > 0, a < 2)
9329 [a = 1]
9330 """
9331 show = keywords.pop("show", False)
9332 s = Solver()
9333 s.set(**keywords)
9334 s.add(*args)
9335 if show:
9336 print(s)
9337 r = s.check()
9338 if r == unsat:
9339 print("no solution")
9340 elif r == unknown:
9341 print("failed to solve")
9342 try:
9343 print(s.model())
9344 except Z3Exception:
9345 return
9346 else:
9347 print(s.model())
9348
9349

◆ solve_using()

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

9350def solve_using(s, *args, **keywords):
9351 """Solve the constraints `*args` using solver `s`.
9352
9353 This is a simple function for creating demonstrations. It is similar to `solve`,
9354 but it uses the given solver `s`.
9355 It configures solver `s` using the options in `keywords`, adds the constraints
9356 in `args`, and invokes check.
9357 """
9358 show = keywords.pop("show", False)
9359 if z3_debug():
9360 _z3_assert(isinstance(s, Solver), "Solver object expected")
9361 s.set(**keywords)
9362 s.add(*args)
9363 if show:
9364 print("Problem:")
9365 print(s)
9366 r = s.check()
9367 if r == unsat:
9368 print("no solution")
9369 elif r == unknown:
9370 print("failed to solve")
9371 try:
9372 print(s.model())
9373 except Z3Exception:
9374 return
9375 else:
9376 if show:
9377 print("Solution:")
9378 print(s.model())
9379
9380

◆ SolverFor()

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

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

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

Definition at line 7612 of file z3py.py.

7612def SolverFor(logic, ctx=None, logFile=None):
7613 """Create a solver customized for the given logic.
7614
7615 The parameter `logic` is a string. It should be contains
7616 the name of a SMT-LIB logic.
7617 See http://www.smtlib.org/ for the name of all available logics.
7618
7619 >>> s = SolverFor("QF_LIA")
7620 >>> x = Int('x')
7621 >>> s.add(x > 0)
7622 >>> s.add(x < 2)
7623 >>> s.check()
7624 sat
7625 >>> s.model()
7626 [x = 1]
7627 """
7628 ctx = _get_ctx(ctx)
7629 logic = to_symbol(logic)
7630 return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx, logFile)
7631
7632
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...

◆ Sqrt()

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

3517def Sqrt(a, ctx=None):
3518 """ Return a Z3 expression which represents the square root of a.
3519
3520 >>> x = Real('x')
3521 >>> Sqrt(x)
3522 x**(1/2)
3523 """
3524 if not is_expr(a):
3525 ctx = _get_ctx(ctx)
3526 a = RealVal(a, ctx)
3527 return a ** "1/2"
3528
3529

◆ SRem()

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

4412def SRem(a, b):
4413 """Create the Z3 expression signed remainder.
4414
4415 Use the operator % for signed modulus, and URem() for unsigned remainder.
4416
4417 >>> x = BitVec('x', 32)
4418 >>> y = BitVec('y', 32)
4419 >>> SRem(x, y)
4420 SRem(x, y)
4421 >>> SRem(x, y).sort()
4422 BitVec(32)
4423 >>> (x % y).sexpr()
4424 '(bvsmod x y)'
4425 >>> SRem(x, y).sexpr()
4426 '(bvsrem x y)'
4427 """
4428 _check_bv_args(a, b)
4429 a, b = _coerce_exprs(a, b)
4430 return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4431
4432
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).

◆ Star()

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

11603def Star(re):
11604 """Create the regular expression accepting zero or more repetitions of argument.
11605 >>> re = Star(Re("a"))
11606 >>> print(simplify(InRe("aa", re)))
11607 True
11608 >>> print(simplify(InRe("ab", re)))
11609 False
11610 >>> print(simplify(InRe("", re)))
11611 True
11612 """
11613 if z3_debug():
11614 _z3_assert(is_expr(re), "expression expected")
11615 return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
11616
11617
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.

◆ Store()

Store (   a,
args 
)
Return a Z3 store array expression.

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

Definition at line 4924 of file z3py.py.

4924def Store(a, *args):
4925 """Return a Z3 store array expression.
4926
4927 >>> a = Array('a', IntSort(), IntSort())
4928 >>> i, v = Ints('i v')
4929 >>> s = Store(a, i, v)
4930 >>> s.sort()
4931 Array(Int, Int)
4932 >>> prove(s[i] == v)
4933 proved
4934 >>> j = Int('j')
4935 >>> prove(Implies(i != j, s[j] == a[j]))
4936 proved
4937 """
4938 return Update(a, args)
4939
4940

Referenced by ModelRef.get_interp().

◆ StrFromCode()

StrFromCode (   c)
Convert code to a string

Definition at line 11471 of file z3py.py.

11471def StrFromCode(c):
11472 """Convert code to a string"""
11473 if not is_expr(c):
11474 c = _py2expr(c)
11475 return SeqRef(Z3_mk_string_from_code(c.ctx_ref(), c.as_ast()), c.ctx)
11476
Z3_ast Z3_API Z3_mk_string_from_code(Z3_context c, Z3_ast a)
Code to string conversion.

◆ String()

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

11228def String(name, ctx=None):
11229 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
11230
11231 >>> x = String('x')
11232 """
11233 ctx = _get_ctx(ctx)
11234 return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
11235
11236

◆ Strings()

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

Definition at line 11237 of file z3py.py.

11237def Strings(names, ctx=None):
11238 """Return a tuple of String constants. """
11239 ctx = _get_ctx(ctx)
11240 if isinstance(names, str):
11241 names = names.split(" ")
11242 return [String(name, ctx) for name in names]
11243
11244

◆ StringSort()

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

Definition at line 11043 of file z3py.py.

11043def StringSort(ctx=None):
11044 """Create a string sort
11045 >>> s = StringSort()
11046 >>> print(s)
11047 String
11048 """
11049 ctx = _get_ctx(ctx)
11050 return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
11051

◆ StringVal()

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

Definition at line 11221 of file z3py.py.

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

Referenced by _coerce_exprs(), _py2expr(), and Extract().

◆ StrToCode()

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

Definition at line 11465 of file z3py.py.

11465def StrToCode(s):
11466 """Convert a unit length string to integer code"""
11467 if not is_expr(s):
11468 s = _py2expr(s)
11469 return ArithRef(Z3_mk_string_to_code(s.ctx_ref(), s.as_ast()), s.ctx)
11470
Z3_ast Z3_API Z3_mk_string_to_code(Z3_context c, Z3_ast a)
String to code conversion.

◆ StrToInt()

StrToInt (   s)
Convert string expression to integer
>>> a = StrToInt("1")
>>> simplify(1 == a)
True
>>> b = StrToInt("2")
>>> simplify(1 == b)
False
>>> c = StrToInt(IntToStr(2))
>>> simplify(1 == c)
False

Definition at line 11442 of file z3py.py.

11442def StrToInt(s):
11443 """Convert string expression to integer
11444 >>> a = StrToInt("1")
11445 >>> simplify(1 == a)
11446 True
11447 >>> b = StrToInt("2")
11448 >>> simplify(1 == b)
11449 False
11450 >>> c = StrToInt(IntToStr(2))
11451 >>> simplify(1 == c)
11452 False
11453 """
11454 s = _coerce_seq(s)
11455 return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
11456
11457
Z3_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.

◆ SubSeq()

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

This is a convenience function that redirects to Extract(s, offset, length).

>>> s = StringVal("hello world")
>>> SubSeq(s, 0, 5)  # Extract "hello"  
str.substr("hello world", 0, 5)
>>> simplify(SubSeq(StringVal("testing"), 2, 4))
"stin"

Definition at line 11259 of file z3py.py.

11259def SubSeq(s, offset, length):
11260 """Extract substring or subsequence starting at offset.
11261
11262 This is a convenience function that redirects to Extract(s, offset, length).
11263
11264 >>> s = StringVal("hello world")
11265 >>> SubSeq(s, 0, 5) # Extract "hello"
11266 str.substr("hello world", 0, 5)
11267 >>> simplify(SubSeq(StringVal("testing"), 2, 4))
11268 "stin"
11269 """
11270 return Extract(s, offset, length)
11271
11272

◆ substitute()

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

9093def substitute(t, *m):
9094 """Apply substitution m on t, m is a list of pairs of the form (from, to).
9095 Every occurrence in t of from is replaced with to.
9096
9097 >>> x = Int('x')
9098 >>> y = Int('y')
9099 >>> substitute(x + 1, (x, y + 1))
9100 y + 1 + 1
9101 >>> f = Function('f', IntSort(), IntSort())
9102 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
9103 1 + 1
9104 """
9105 if isinstance(m, tuple):
9106 m1 = _get_args(m)
9107 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9108 m = m1
9109 if z3_debug():
9110 _z3_assert(is_expr(t), "Z3 expression expected")
9111 _z3_assert(
9112 all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) for p in m]),
9113 "Z3 invalid substitution, expression pairs expected.")
9114 _z3_assert(
9115 all([p[0].sort().eq(p[1].sort()) for p in m]),
9116 'Z3 invalid substitution, mismatching "from" and "to" sorts.')
9117 num = len(m)
9118 _from = (Ast * num)()
9119 _to = (Ast * num)()
9120 for i in range(num):
9121 _from[i] = m[i][0].as_ast()
9122 _to[i] = m[i][1].as_ast()
9123 return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9124
9125
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....

◆ substitute_funs()

substitute_funs (   t,
m 
)
Apply substitution m on t, m is a list of pairs of a function and expression (from, to)
Every occurrence in to of the function from is replaced with the expression to.
The expression to can have free variables, that refer to the arguments of from.
For examples, see 

Definition at line 9146 of file z3py.py.

9146def substitute_funs(t, *m):
9147 """Apply substitution m on t, m is a list of pairs of a function and expression (from, to)
9148 Every occurrence in to of the function from is replaced with the expression to.
9149 The expression to can have free variables, that refer to the arguments of from.
9150 For examples, see
9151 """
9152 if isinstance(m, tuple):
9153 m1 = _get_args(m)
9154 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9155 m = m1
9156 if z3_debug():
9157 _z3_assert(is_expr(t), "Z3 expression expected")
9158 _z3_assert(all([isinstance(p, tuple) and is_func_decl(p[0]) and is_expr(p[1]) for p in m]), "Z3 invalid substitution, function pairs expected.")
9159 num = len(m)
9160 _from = (FuncDecl * num)()
9161 _to = (Ast * num)()
9162 for i in range(num):
9163 _from[i] = m[i][0].as_func_decl()
9164 _to[i] = m[i][1].as_ast()
9165 return _to_expr_ref(Z3_substitute_funs(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9166
9167
Z3_ast Z3_API Z3_substitute_funs(Z3_context c, Z3_ast a, unsigned num_funs, Z3_func_decl const from[], Z3_ast const to[])
Substitute functions in from with new expressions in to.

◆ substitute_vars()

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

9126def substitute_vars(t, *m):
9127 """Substitute the free variables in t with the expression in m.
9128
9129 >>> v0 = Var(0, IntSort())
9130 >>> v1 = Var(1, IntSort())
9131 >>> x = Int('x')
9132 >>> f = Function('f', IntSort(), IntSort(), IntSort())
9133 >>> # replace v0 with x+1 and v1 with x
9134 >>> substitute_vars(f(v0, v1), x + 1, x)
9135 f(x + 1, x)
9136 """
9137 if z3_debug():
9138 _z3_assert(is_expr(t), "Z3 expression expected")
9139 _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
9140 num = len(m)
9141 _to = (Ast * num)()
9142 for i in range(num):
9143 _to[i] = m[i].as_ast()
9144 return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
9145
Z3_ast Z3_API Z3_substitute_vars(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const to[])
Substitute the variables in a with the expressions in to. For every i smaller than num_exprs,...

◆ SubString()

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

This is a convenience function that redirects to Extract(s, offset, length).

>>> s = StringVal("hello world") 
>>> SubString(s, 6, 5)  # Extract "world"
str.substr("hello world", 6, 5)
>>> simplify(SubString(StringVal("hello"), 1, 3))
"ell"

Definition at line 11245 of file z3py.py.

11245def SubString(s, offset, length):
11246 """Extract substring or subsequence starting at offset.
11247
11248 This is a convenience function that redirects to Extract(s, offset, length).
11249
11250 >>> s = StringVal("hello world")
11251 >>> SubString(s, 6, 5) # Extract "world"
11252 str.substr("hello world", 6, 5)
11253 >>> simplify(SubString(StringVal("hello"), 1, 3))
11254 "ell"
11255 """
11256 return Extract(s, offset, length)
11257
11258

◆ SuffixOf()

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

11328def SuffixOf(a, b):
11329 """Check if 'a' is a suffix of 'b'
11330 >>> s1 = SuffixOf("ab", "abc")
11331 >>> simplify(s1)
11332 False
11333 >>> s2 = SuffixOf("bc", "abc")
11334 >>> simplify(s2)
11335 True
11336 """
11337 ctx = _get_ctx2(a, b)
11338 a = _coerce_seq(a, ctx)
11339 b = _coerce_seq(b, ctx)
11340 return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11341
11342
Z3_ast Z3_API Z3_mk_seq_suffix(Z3_context c, Z3_ast suffix, Z3_ast s)
Check if suffix is a suffix of s.

◆ Sum()

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

9168def Sum(*args):
9169 """Create the sum of the Z3 expressions.
9170
9171 >>> a, b, c = Ints('a b c')
9172 >>> Sum(a, b, c)
9173 a + b + c
9174 >>> Sum([a, b, c])
9175 a + b + c
9176 >>> A = IntVector('a', 5)
9177 >>> Sum(A)
9178 a__0 + a__1 + a__2 + a__3 + a__4
9179 """
9180 args = _get_args(args)
9181 if len(args) == 0:
9182 return 0
9183 ctx = _ctx_from_ast_arg_list(args)
9184 if ctx is None:
9185 return _reduce(lambda a, b: a + b, args, 0)
9186 args = _coerce_expr_list(args, ctx)
9187 if is_bv(args[0]):
9188 return _reduce(lambda a, b: a + b, args, 0)
9189 else:
9190 _args, sz = _to_ast_array(args)
9191 return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
9192
9193
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].

◆ tactic_description()

tactic_description (   name,
  ctx = None 
)
Return a short description for the tactic named `name`.

>>> d = tactic_description('simplify')

Definition at line 8747 of file z3py.py.

8747def tactic_description(name, ctx=None):
8748 """Return a short description for the tactic named `name`.
8749
8750 >>> d = tactic_description('simplify')
8751 """
8752 ctx = _get_ctx(ctx)
8753 return Z3_tactic_get_descr(ctx.ref(), name)
8754
8755
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()

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

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

Definition at line 8736 of file z3py.py.

8736def tactics(ctx=None):
8737 """Return a list of all available tactics in Z3.
8738
8739 >>> l = tactics()
8740 >>> l.count('simplify') == 1
8741 True
8742 """
8743 ctx = _get_ctx(ctx)
8744 return [Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref()))]
8745
8746
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.
Z3_string Z3_API Z3_get_tactic_name(Z3_context c, unsigned i)
Return the name of the idx tactic.

◆ Then()

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

8604def Then(*ts, **ks):
8605 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8606
8607 >>> x, y = Ints('x y')
8608 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
8609 >>> t(And(x == 0, y > x + 1))
8610 [[Not(y <= 1)]]
8611 >>> t(And(x == 0, y > x + 1)).as_expr()
8612 Not(y <= 1)
8613 """
8614 return AndThen(*ts, **ks)
8615
8616

◆ to_Ast()

to_Ast (   ptr)

Definition at line 11687 of file z3py.py.

11687def to_Ast(ptr,):
11688 ast = Ast(ptr)
11689 super(ctypes.c_void_p, ast).__init__(ptr)
11690 return ast
11691

◆ to_AstVectorObj()

to_AstVectorObj (   ptr)

Definition at line 11697 of file z3py.py.

11697def to_AstVectorObj(ptr,):
11698 v = AstVectorObj(ptr)
11699 super(ctypes.c_void_p, v).__init__(ptr)
11700 return v
11701
11702# NB. my-hacky-class only works for a single instance of OnClause
11703# it should be replaced with a proper correlation between OnClause
11704# and object references that can be passed over the FFI.
11705# for UserPropagator we use a global dictionary, which isn't great code.
11706

◆ to_ContextObj()

to_ContextObj (   ptr)

Definition at line 11692 of file z3py.py.

11692def to_ContextObj(ptr,):
11693 ctx = ContextObj(ptr)
11694 super(ctypes.c_void_p, ctx).__init__(ptr)
11695 return ctx
11696

◆ to_symbol()

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

Definition at line 132 of file z3py.py.

132def to_symbol(s, ctx = None):
133 """Convert an integer or string into a Z3 symbol."""
134 if _is_int(s):
135 return Z3_mk_int_symbol(_get_ctx(ctx).ref(), s)
136 else:
137 return Z3_mk_string_symbol(_get_ctx(ctx).ref(), s)
138
139
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.

Referenced by _mk_quantifier(), Array(), BitVec(), Bool(), Const(), CreateDatatypes(), DatatypeSort(), DeclareSort(), DeclareTypeVar(), EnumSort(), Function(), ParamDescrsRef.get_documentation(), ParamDescrsRef.get_kind(), Int(), Real(), RecFunction(), and ParamsRef.set().

◆ ToInt()

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

3482def ToInt(a):
3483 """ Return the Z3 expression ToInt(a).
3484
3485 >>> x = Real('x')
3486 >>> x.sort()
3487 Real
3488 >>> n = ToInt(x)
3489 >>> n
3490 ToInt(x)
3491 >>> n.sort()
3492 Int
3493 """
3494 if z3_debug():
3495 _z3_assert(a.is_real(), "Z3 real expression expected.")
3496 ctx = a.ctx
3497 return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
3498
3499
Z3_ast Z3_API Z3_mk_real2int(Z3_context c, Z3_ast t1)
Coerce a real to an integer.

◆ ToReal()

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

3462def ToReal(a):
3463 """ Return the Z3 expression ToReal(a).
3464
3465 >>> x = Int('x')
3466 >>> x.sort()
3467 Int
3468 >>> n = ToReal(x)
3469 >>> n
3470 ToReal(x)
3471 >>> n.sort()
3472 Real
3473 """
3474 ctx = a.ctx
3475 if isinstance(a, BoolRef):
3476 return If(a, RealVal(1, ctx), RealVal(0, ctx))
3477 if z3_debug():
3478 _z3_assert(a.is_int(), "Z3 integer expression expected.")
3479 return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
3480
3481
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.

◆ TransitiveClosure()

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

Definition at line 11680 of file z3py.py.

11680def TransitiveClosure(f):
11681 """Given a binary relation R, such that the two arguments have the same sort
11682 create the transitive closure relation R+.
11683 The transitive closure R+ is a new relation.
11684 """
11685 return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
11686
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.

◆ TreeOrder()

TreeOrder (   a,
  index 
)

Definition at line 11672 of file z3py.py.

11672def TreeOrder(a, index):
11673 return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx)
11674
11675
Z3_func_decl Z3_API Z3_mk_tree_order(Z3_context c, Z3_sort a, unsigned id)
create a tree ordering relation over signature a identified using index id.

◆ TryFor()

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

8727def TryFor(t, ms, ctx=None):
8728 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8729
8730 If `t` does not terminate in `ms` milliseconds, then it fails.
8731 """
8732 t = _to_tactic(t, ctx)
8733 return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
8734
8735
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...

◆ TupleSort()

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

Definition at line 5510 of file z3py.py.

5510def TupleSort(name, sorts, ctx=None):
5511 """Create a named tuple sort base on a set of underlying sorts
5512 Example:
5513 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5514 """
5515 tuple = Datatype(name, ctx)
5516 projects = [("project%d" % i, sorts[i]) for i in range(len(sorts))]
5517 tuple.declare(name, *projects)
5518 tuple = tuple.create()
5519 return tuple, tuple.constructor(0), [tuple.accessor(0, i) for i in range(len(sorts))]
5520
5521

◆ UDiv()

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

4370def UDiv(a, b):
4371 """Create the Z3 expression (unsigned) division `self / other`.
4372
4373 Use the operator / for signed division.
4374
4375 >>> x = BitVec('x', 32)
4376 >>> y = BitVec('y', 32)
4377 >>> UDiv(x, y)
4378 UDiv(x, y)
4379 >>> UDiv(x, y).sort()
4380 BitVec(32)
4381 >>> (x / y).sexpr()
4382 '(bvsdiv x y)'
4383 >>> UDiv(x, y).sexpr()
4384 '(bvudiv x y)'
4385 """
4386 _check_bv_args(a, b)
4387 a, b = _coerce_exprs(a, b)
4388 return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4389
4390
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.

◆ UGE()

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

4334def UGE(a, b):
4335 """Create the Z3 expression (unsigned) `other >= self`.
4336
4337 Use the operator >= for signed greater than or equal to.
4338
4339 >>> x, y = BitVecs('x y', 32)
4340 >>> UGE(x, y)
4341 UGE(x, y)
4342 >>> (x >= y).sexpr()
4343 '(bvsge x y)'
4344 >>> UGE(x, y).sexpr()
4345 '(bvuge x y)'
4346 """
4347 _check_bv_args(a, b)
4348 a, b = _coerce_exprs(a, b)
4349 return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4350
4351
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.

◆ UGT()

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

4352def UGT(a, b):
4353 """Create the Z3 expression (unsigned) `other > self`.
4354
4355 Use the operator > for signed greater than.
4356
4357 >>> x, y = BitVecs('x y', 32)
4358 >>> UGT(x, y)
4359 UGT(x, y)
4360 >>> (x > y).sexpr()
4361 '(bvsgt x y)'
4362 >>> UGT(x, y).sexpr()
4363 '(bvugt x y)'
4364 """
4365 _check_bv_args(a, b)
4366 a, b = _coerce_exprs(a, b)
4367 return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4368
4369
Z3_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.

◆ ULE()

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

4298def ULE(a, b):
4299 """Create the Z3 expression (unsigned) `other <= self`.
4300
4301 Use the operator <= for signed less than or equal to.
4302
4303 >>> x, y = BitVecs('x y', 32)
4304 >>> ULE(x, y)
4305 ULE(x, y)
4306 >>> (x <= y).sexpr()
4307 '(bvsle x y)'
4308 >>> ULE(x, y).sexpr()
4309 '(bvule x y)'
4310 """
4311 _check_bv_args(a, b)
4312 a, b = _coerce_exprs(a, b)
4313 return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4314
4315
Z3_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.

◆ ULT()

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

4316def ULT(a, b):
4317 """Create the Z3 expression (unsigned) `other < self`.
4318
4319 Use the operator < for signed less than.
4320
4321 >>> x, y = BitVecs('x y', 32)
4322 >>> ULT(x, y)
4323 ULT(x, y)
4324 >>> (x < y).sexpr()
4325 '(bvslt x y)'
4326 >>> ULT(x, y).sexpr()
4327 '(bvult x y)'
4328 """
4329 _check_bv_args(a, b)
4330 a, b = _coerce_exprs(a, b)
4331 return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4332
4333
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.

◆ Union()

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

Definition at line 11530 of file z3py.py.

11530def Union(*args):
11531 """Create union of regular expressions.
11532 >>> re = Union(Re("a"), Re("b"), Re("c"))
11533 >>> print (simplify(InRe("d", re)))
11534 False
11535 """
11536 args = _get_args(args)
11537 sz = len(args)
11538 if z3_debug():
11539 _z3_assert(sz > 0, "At least one argument expected.")
11540 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11541 if sz == 1:
11542 return args[0]
11543 ctx = args[0].ctx
11544 v = (Ast * sz)()
11545 for i in range(sz):
11546 v[i] = args[i].as_ast()
11547 return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
11548
11549
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.

◆ Unit()

Unit (   a)
Create a singleton sequence

Definition at line 11308 of file z3py.py.

11308def Unit(a):
11309 """Create a singleton sequence"""
11310 return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
11311
11312
Z3_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.

◆ Update()

Update (   a,
args 
)
Return a Z3 store array expression.

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

Definition at line 4881 of file z3py.py.

4881def Update(a, *args):
4882 """Return a Z3 store array expression.
4883
4884 >>> a = Array('a', IntSort(), IntSort())
4885 >>> i, v = Ints('i v')
4886 >>> s = Update(a, i, v)
4887 >>> s.sort()
4888 Array(Int, Int)
4889 >>> prove(s[i] == v)
4890 proved
4891 >>> j = Int('j')
4892 >>> prove(Implies(i != j, s[j] == a[j]))
4893 proved
4894 """
4895 if z3_debug():
4896 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4897 args = _get_args(args)
4898 ctx = a.ctx
4899 if len(args) <= 1:
4900 raise Z3Exception("array update requires index and value arguments")
4901 if len(args) == 2:
4902 i = args[0]
4903 v = args[1]
4904 i = a.sort().domain().cast(i)
4905 v = a.sort().range().cast(v)
4906 return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4907 v = a.sort().range().cast(args[-1])
4908 idxs = [a.sort().domain_n(i).cast(args[i]) for i in range(len(args)-1)]
4909 _args, sz = _to_ast_array(idxs)
4910 return _to_expr_ref(Z3_mk_store_n(ctx.ref(), a.as_ast(), sz, _args, v.as_ast()), ctx)
4911
4912
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
Z3_ast Z3_API Z3_mk_store_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs, Z3_ast v)
n-ary Array update.

Referenced by Store().

◆ URem()

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

4391def URem(a, b):
4392 """Create the Z3 expression (unsigned) remainder `self % other`.
4393
4394 Use the operator % for signed modulus, and SRem() for signed remainder.
4395
4396 >>> x = BitVec('x', 32)
4397 >>> y = BitVec('y', 32)
4398 >>> URem(x, y)
4399 URem(x, y)
4400 >>> URem(x, y).sort()
4401 BitVec(32)
4402 >>> (x % y).sexpr()
4403 '(bvsmod x y)'
4404 >>> URem(x, y).sexpr()
4405 '(bvurem x y)'
4406 """
4407 _check_bv_args(a, b)
4408 a, b = _coerce_exprs(a, b)
4409 return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4410
4411
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.

◆ user_prop_binding()

user_prop_binding (   ctx,
  cb,
  q_ref,
  inst_ref 
)

Definition at line 11850 of file z3py.py.

11850def user_prop_binding(ctx, cb, q_ref, inst_ref):
11851 prop = _prop_closures.get(ctx)
11852 old_cb = prop.cb
11853 prop.cb = cb
11854 q = _to_expr_ref(to_Ast(q_ref), prop.ctx())
11855 inst = _to_expr_ref(to_Ast(inst_ref), prop.ctx())
11856 r = prop.binding(q, inst)
11857 prop.cb = old_cb
11858 return r
11859
11860

◆ user_prop_created()

user_prop_created (   ctx,
  cb,
  id 
)

Definition at line 11808 of file z3py.py.

11808def user_prop_created(ctx, cb, id):
11809 prop = _prop_closures.get(ctx)
11810 old_cb = prop.cb
11811 prop.cb = cb
11812 id = _to_expr_ref(to_Ast(id), prop.ctx())
11813 prop.created(id)
11814 prop.cb = old_cb
11815
11816

◆ user_prop_decide()

user_prop_decide (   ctx,
  cb,
  t_ref,
  idx,
  phase 
)

Definition at line 11842 of file z3py.py.

11842def user_prop_decide(ctx, cb, t_ref, idx, phase):
11843 prop = _prop_closures.get(ctx)
11844 old_cb = prop.cb
11845 prop.cb = cb
11846 t = _to_expr_ref(to_Ast(t_ref), prop.ctx())
11847 prop.decide(t, idx, phase)
11848 prop.cb = old_cb
11849

◆ user_prop_diseq()

user_prop_diseq (   ctx,
  cb,
  x,
  y 
)

Definition at line 11833 of file z3py.py.

11833def user_prop_diseq(ctx, cb, x, y):
11834 prop = _prop_closures.get(ctx)
11835 old_cb = prop.cb
11836 prop.cb = cb
11837 x = _to_expr_ref(to_Ast(x), prop.ctx())
11838 y = _to_expr_ref(to_Ast(y), prop.ctx())
11839 prop.diseq(x, y)
11840 prop.cb = old_cb
11841

◆ user_prop_eq()

user_prop_eq (   ctx,
  cb,
  x,
  y 
)

Definition at line 11824 of file z3py.py.

11824def user_prop_eq(ctx, cb, x, y):
11825 prop = _prop_closures.get(ctx)
11826 old_cb = prop.cb
11827 prop.cb = cb
11828 x = _to_expr_ref(to_Ast(x), prop.ctx())
11829 y = _to_expr_ref(to_Ast(y), prop.ctx())
11830 prop.eq(x, y)
11831 prop.cb = old_cb
11832

◆ user_prop_final()

user_prop_final (   ctx,
  cb 
)

Definition at line 11817 of file z3py.py.

11817def user_prop_final(ctx, cb):
11818 prop = _prop_closures.get(ctx)
11819 old_cb = prop.cb
11820 prop.cb = cb
11821 prop.final()
11822 prop.cb = old_cb
11823

◆ user_prop_fixed()

user_prop_fixed (   ctx,
  cb,
  id,
  value 
)

Definition at line 11799 of file z3py.py.

11799def user_prop_fixed(ctx, cb, id, value):
11800 prop = _prop_closures.get(ctx)
11801 old_cb = prop.cb
11802 prop.cb = cb
11803 id = _to_expr_ref(to_Ast(id), prop.ctx())
11804 value = _to_expr_ref(to_Ast(value), prop.ctx())
11805 prop.fixed(id, value)
11806 prop.cb = old_cb
11807

◆ user_prop_fresh()

user_prop_fresh (   ctx,
  _new_ctx 
)

Definition at line 11785 of file z3py.py.

11785def user_prop_fresh(ctx, _new_ctx):
11786 _prop_closures.set_threaded()
11787 prop = _prop_closures.get(ctx)
11788 nctx = Context()
11789 Z3_del_context(nctx.ctx)
11790 new_ctx = to_ContextObj(_new_ctx)
11791 nctx.ctx = new_ctx
11792 nctx.eh = Z3_set_error_handler(new_ctx, z3_error_handler)
11793 nctx.owner = False
11794 new_prop = prop.fresh(nctx)
11795 _prop_closures.set(new_prop.id, new_prop)
11796 return new_prop.id
11797
11798
void Z3_API Z3_del_context(Z3_context c)
Delete the given logical context.
void Z3_API Z3_set_error_handler(Z3_context c, Z3_error_handler h)
Register a Z3 error handler.

◆ user_prop_pop()

user_prop_pop (   ctx,
  cb,
  num_scopes 
)

Definition at line 11779 of file z3py.py.

11779def user_prop_pop(ctx, cb, num_scopes):
11780 prop = _prop_closures.get(ctx)
11781 prop.cb = cb
11782 prop.pop(num_scopes)
11783
11784

◆ user_prop_push()

user_prop_push (   ctx,
  cb 
)

Definition at line 11773 of file z3py.py.

11773def user_prop_push(ctx, cb):
11774 prop = _prop_closures.get(ctx)
11775 prop.cb = cb
11776 prop.push()
11777
11778

◆ Var()

ExprRef Var ( int  idx,
SortRef  s 
)
Create a Z3 free variable. Free variables are used to create quantified formulas.
A free variable with index n is bound when it occurs within the scope of n+1 quantified
declarations.

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

Definition at line 1534 of file z3py.py.

1534def Var(idx : int, s : SortRef) -> ExprRef:
1535 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1536 A free variable with index n is bound when it occurs within the scope of n+1 quantified
1537 declarations.
1538
1539 >>> Var(0, IntSort())
1540 Var(0)
1541 >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1542 False
1543 """
1544 if z3_debug():
1545 _z3_assert(is_sort(s), "Z3 sort expected")
1546 return _to_expr_ref(Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1547
1548
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a variable.

Referenced by RealVar().

◆ When()

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

9021def When(p, t, ctx=None):
9022 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
9023 Otherwise, it returns the input goal unmodified.
9024
9025 >>> t = When(Probe('size') > 2, Tactic('simplify'))
9026 >>> x, y = Ints('x y')
9027 >>> g = Goal()
9028 >>> g.add(x > 0)
9029 >>> g.add(y > 0)
9030 >>> t(g)
9031 [[x > 0, y > 0]]
9032 >>> g.add(x == y + 1)
9033 >>> t(g)
9034 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9035 """
9036 p = _to_probe(p, ctx)
9037 t = _to_tactic(t, ctx)
9038 return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
9039
9040
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...

◆ With()

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

8678def With(t, *args, **keys):
8679 """Return a tactic that applies tactic `t` using the given configuration options.
8680
8681 >>> x, y = Ints('x y')
8682 >>> t = With(Tactic('simplify'), som=True)
8683 >>> t((x + 1)*(y + 2) == 0)
8684 [[2*x + y + x*y == -2]]
8685 """
8686 ctx = keys.pop("ctx", None)
8687 t = _to_tactic(t, ctx)
8688 p = args2params(args, keys, t.ctx)
8689 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8690
8691
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p)
Return a tactic that applies t using the given set of parameters.

◆ WithParams()

WithParams (   t,
  p 
)
Return a tactic that applies tactic `t` using the given configuration options.

>>> x, y = Ints('x y')
>>> p = ParamsRef()
>>> p.set("som", True)
>>> t = WithParams(Tactic('simplify'), p)
>>> t((x + 1)*(y + 2) == 0)
[[2*x + y + x*y == -2]]

Definition at line 8692 of file z3py.py.

8692def WithParams(t, p):
8693 """Return a tactic that applies tactic `t` using the given configuration options.
8694
8695 >>> x, y = Ints('x y')
8696 >>> p = ParamsRef()
8697 >>> p.set("som", True)
8698 >>> t = WithParams(Tactic('simplify'), p)
8699 >>> t((x + 1)*(y + 2) == 0)
8700 [[2*x + y + x*y == -2]]
8701 """
8702 t = _to_tactic(t, None)
8703 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8704
8705

◆ Xor()

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

1891def Xor(a, b, ctx=None):
1892 """Create a Z3 Xor expression.
1893
1894 >>> p, q = Bools('p q')
1895 >>> Xor(p, q)
1896 Xor(p, q)
1897 >>> simplify(Xor(p, q))
1898 Not(p == q)
1899 """
1900 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1901 s = BoolSort(ctx)
1902 a = s.cast(a)
1903 b = s.cast(b)
1904 return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1905
1906
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.

Referenced by BoolRef.__xor__().

◆ z3_debug()

z3_debug ( )

◆ z3_error_handler()

z3_error_handler (   c,
  e 
)

Definition at line 184 of file z3py.py.

184def z3_error_handler(c, e):
185 # Do nothing error handler, just avoid exit(0)
186 # The wrappers in z3core.py will raise a Z3Exception if an error is detected
187 return
188
189

◆ ZeroExt()

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

4527def ZeroExt(n, a):
4528 """Return a bit-vector expression with `n` extra zero-bits.
4529
4530 >>> x = BitVec('x', 16)
4531 >>> n = ZeroExt(8, x)
4532 >>> n.size()
4533 24
4534 >>> n
4535 ZeroExt(8, x)
4536 >>> n.sort()
4537 BitVec(24)
4538 >>> v0 = BitVecVal(2, 2)
4539 >>> v0
4540 2
4541 >>> v0.size()
4542 2
4543 >>> v = simplify(ZeroExt(6, v0))
4544 >>> v
4545 2
4546 >>> v.size()
4547 8
4548 """
4549 if z3_debug():
4550 _z3_assert(_is_int(n), "First argument must be an integer")
4551 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4552 return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4553
4554
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

◆ _dflt_fpsort_ebits

int _dflt_fpsort_ebits = 11
protected

Definition at line 9573 of file z3py.py.

◆ _dflt_fpsort_sbits

int _dflt_fpsort_sbits = 53
protected

Definition at line 9574 of file z3py.py.

◆ _dflt_rounding_mode

_dflt_rounding_mode = Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN
protected

Floating-Point Arithmetic.

Definition at line 9572 of file z3py.py.

◆ _main_ctx

_main_ctx = None
protected

Definition at line 246 of file z3py.py.

◆ _my_hacky_class

_my_hacky_class = None
protected

Definition at line 11707 of file z3py.py.

◆ _on_clause_eh

_on_clause_eh = Z3_on_clause_eh(on_clause_eh)
protected

Definition at line 11715 of file z3py.py.

◆ _on_model_eh

_on_model_eh = on_model_eh_type(_global_on_model)
protected

Definition at line 8077 of file z3py.py.

◆ _on_models

dict _on_models = {}
protected

Definition at line 8069 of file z3py.py.

◆ _prop_closures

_prop_closures = None
protected

Definition at line 11764 of file z3py.py.

◆ _ROUNDING_MODES

_ROUNDING_MODES
protected
Initial value:
1= frozenset({
2 Z3_OP_FPA_RM_TOWARD_ZERO,
3 Z3_OP_FPA_RM_TOWARD_NEGATIVE,
4 Z3_OP_FPA_RM_TOWARD_POSITIVE,
5 Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN,
6 Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY
7})

Definition at line 9592 of file z3py.py.

◆ _user_prop_binding

_user_prop_binding = Z3_on_binding_eh(user_prop_binding)
protected

Definition at line 11870 of file z3py.py.

◆ _user_prop_created

_user_prop_created = Z3_created_eh(user_prop_created)
protected

Definition at line 11865 of file z3py.py.

◆ _user_prop_decide

_user_prop_decide = Z3_decide_eh(user_prop_decide)
protected

Definition at line 11869 of file z3py.py.

◆ _user_prop_diseq

_user_prop_diseq = Z3_eq_eh(user_prop_diseq)
protected

Definition at line 11868 of file z3py.py.

◆ _user_prop_eq

_user_prop_eq = Z3_eq_eh(user_prop_eq)
protected

Definition at line 11867 of file z3py.py.

◆ _user_prop_final

_user_prop_final = Z3_final_eh(user_prop_final)
protected

Definition at line 11866 of file z3py.py.

◆ _user_prop_fixed

_user_prop_fixed = Z3_fixed_eh(user_prop_fixed)
protected

Definition at line 11864 of file z3py.py.

◆ _user_prop_fresh

_user_prop_fresh = Z3_fresh_eh(user_prop_fresh)
protected

Definition at line 11863 of file z3py.py.

◆ _user_prop_pop

_user_prop_pop = Z3_pop_eh(user_prop_pop)
protected

Definition at line 11862 of file z3py.py.

◆ _user_prop_push

_user_prop_push = Z3_push_eh(user_prop_push)
protected

Definition at line 11861 of file z3py.py.

◆ sat

Definition at line 7066 of file z3py.py.

◆ unknown

Definition at line 7068 of file z3py.py.

◆ unsat

Definition at line 7067 of file z3py.py.

◆ Z3_DEBUG

Z3_DEBUG = __debug__

Definition at line 67 of file z3py.py.